From a93cb680785e9d7beafbc3e5de67077e2ca7ffa6 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Thu, 18 Mar 2021 08:14:34 +0100 Subject: [PATCH] docs: Add more info to the internal design --- esp_modem/docs/internal_desing.md | 53 ++++++++++++++++++-- esp_modem/private_include/exception_stub.hpp | 2 +- esp_modem/src/esp_modem_api.cpp | 2 + 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/esp_modem/docs/internal_desing.md b/esp_modem/docs/internal_desing.md index 25d48969f..d74afaf5c 100644 --- a/esp_modem/docs/internal_desing.md +++ b/esp_modem/docs/internal_desing.md @@ -2,11 +2,58 @@ ## Design decisions -* Use C++ (lambdas) wit C API +* Use C++ (lambdas, templates) with additional C API + + | esp-modem in C | esp-modem in C++ | + |----------------|---------------| +``` + +2282 + -3908 +``` + * Use exceptions (implement nothrow? possibly using `assert()`) -* Initializes and allocates in the constructor (might throw) + +| exceptions off | exceptions on | +|----------------|---------------| +``` +Difference is counted as - , i.e. a positive number means that is larger. +Total sizes of : Difference + DRAM .data size: 10996 bytes 10996 + DRAM .bss size: 12552 bytes 12488 +64 +Used static DRAM: 23548 bytes ( 157188 available, 13.0% used) 23484 +64 ( -64 available, +0 total) +Used static IRAM: 54145 bytes ( 76927 available, 41.3% used) 54093 +52 ( -52 available, +0 total) + Flash code: 603979 bytes 595551 +8428 + Flash rodata: 187772 bytes 177852 +9920 +Total image size:~ 869444 bytes (.bin may be padded larger) 850980 +18464 +``` +| exceptions on | RTTI on | +|----------------|---------------| +``` +Total sizes of : Difference + DRAM .data size: 10996 bytes 10996 + DRAM .bss size: 12552 bytes 12552 +Used static DRAM: 23548 bytes ( 157188 available, 13.0% used) 23548 ( +0 available, +0 total) +Used static IRAM: 54145 bytes ( 76927 available, 41.3% used) 54145 ( +0 available, +0 total) + Flash code: 605331 bytes 603979 +1352 + Flash rodata: 196788 bytes 187772 +9016 +Total image size:~ 879812 bytes (.bin may be padded larger) 869444 +10368 +``` +* Initializes and allocates in the constructor (might throw) + - easier code with exceptions ON, with exceptions OFF alloc/init failures are not treated as runtime error (program aborts) * Implements different devices with template specialization -* Specific device abstraction overrides methods, but does not use virtual function dispatch (modeled as `DCE`) + - Specific device abstraction overrides methods, but does not use virtual function dispatch (modeled as `DCE`) + - Use cases: Implement a minimal device (ModuleIf), add new AT commands (oOnly in compile time). + - Possibly use Module with DTE only (no DCE, no Netif) for sending AT commands without network + +Example: +``` +class SIM7600: public GenericModule { + using GenericModule::GenericModule; +public: + command_result get_module_name(std::string& name); // overrides, but is no virtual +}; +``` +method `get_module_name()` reimplements the *same* method in `GenericModule` ## DCE collaboration model diff --git a/esp_modem/private_include/exception_stub.hpp b/esp_modem/private_include/exception_stub.hpp index 6ea9e60dd..b8e231b88 100644 --- a/esp_modem/private_include/exception_stub.hpp +++ b/esp_modem/private_include/exception_stub.hpp @@ -7,7 +7,7 @@ #ifdef CONFIG_COMPILER_CXX_EXCEPTIONS #define TRY_CATCH_RET_NULL(block) \ - try { block } \ + try { block \ } catch (std::bad_alloc& e) { \ ESP_LOGE(TAG, "Out of memory"); \ return nullptr; \ diff --git a/esp_modem/src/esp_modem_api.cpp b/esp_modem/src/esp_modem_api.cpp index b492056e5..da774ad9b 100644 --- a/esp_modem/src/esp_modem_api.cpp +++ b/esp_modem/src/esp_modem_api.cpp @@ -11,6 +11,8 @@ struct PdpContext; +static const char *TAG = "modem_api"; + std::shared_ptr create_uart_dte(const esp_modem_dte_config *config) { TRY_CATCH_RET_NULL(