docs: Add more info to the internal design

This commit is contained in:
David Cermak
2021-03-18 08:14:34 +01:00
parent da15b3d423
commit a93cb68078
3 changed files with 53 additions and 4 deletions

View File

@ -2,11 +2,58 @@
## Design decisions ## 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()`) * Use exceptions (implement nothrow? possibly using `assert()`)
| exceptions off | exceptions on |
|----------------|---------------|
```
Difference is counted as <CURRENT> - <REFERENCE>, i.e. a positive number means that <CURRENT> is larger.
Total sizes of <CURRENT>: <REFERENCE> 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 <CURRENT>: <REFERENCE> 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) * 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 * Implements different devices with template specialization
* Specific device abstraction overrides methods, but does not use virtual function dispatch (modeled as `DCE<SpecificModule>`) - Specific device abstraction overrides methods, but does not use virtual function dispatch (modeled as `DCE<SpecificModule>`)
- 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 ## DCE collaboration model

View File

@ -7,7 +7,7 @@
#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS #ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
#define TRY_CATCH_RET_NULL(block) \ #define TRY_CATCH_RET_NULL(block) \
try { block } \ try { block \
} catch (std::bad_alloc& e) { \ } catch (std::bad_alloc& e) { \
ESP_LOGE(TAG, "Out of memory"); \ ESP_LOGE(TAG, "Out of memory"); \
return nullptr; \ return nullptr; \

View File

@ -11,6 +11,8 @@
struct PdpContext; struct PdpContext;
static const char *TAG = "modem_api";
std::shared_ptr<DTE> create_uart_dte(const esp_modem_dte_config *config) std::shared_ptr<DTE> create_uart_dte(const esp_modem_dte_config *config)
{ {
TRY_CATCH_RET_NULL( TRY_CATCH_RET_NULL(