AFP resource consumption on micro-controllers
Reducing resource consumption
Famouso and AFP provide several possibilities to reduce the resource consumption which is important for resource constrained embedded systems like micro-controllers.
Many proposals assume that you know how to configure AFP. See How to configure AFP and Changing AFP configuration used in the Abstract Network Layer on this topic.
- Choose the most simple sufficient configuration! Supporting less features results in less code and less RAM usage.
- The configuration creating the least overhead is famouso::mw::afp::Disable which can be used to disable the AFP fragmentation and/or AFP defragmentation support completely.
- The most simple configuration is famouso::mw::afp::DefaultConfig. Note that you can only use it if there are neither duplicates nor reordering and multiple events cannot arise concurrently.
- If you only subscribe for one subject, you can set
multiple_subjects = false
even in the Abstract Network Layer. This reduces overhead significantly ifevent_seq = false
. Be aware of the fact that concurrent reassembly of events from multiple subjects will result in undefined behaviour.// famouso layer stack configuration typedef famouso::mw::nl::CANNL<can, ccpClient, etagClient> nl; struct afp_cfg : nl::AFP_Config { enum { multiple_subjects = false }; }; typedef famouso::mw::anl::AbstractNetworkLayer< nl, afp_cfg, afp_cfg > anl;
- If you do not need to support events longer than 255 bytes, you can instruct AFP to use smaller data types with the following AFP config line:
typedef afp::MinimalSizeProp SizeProperties;
- Adjust the values of the config options:
- concurrent_events (if
event_seq
ormultiple_subjects
set) - old_event_ids (if
event_seq
set) - max_fragments (if
duplicates
set)
- concurrent_events (if
- Define a custom
Allocator
policy. You can reduce the size of the memory pool to save RAM or a different special allocator. E.g. ifmultiple_subjects = event_seq = duplicates = reordering = FEC = false
you can use object::OneBlockAllocator. - You may disable overflow_error_checking.
Reducing resource consumption in general for release versions:
- Define the preprocessor symbol LOGGING_DISABLE when invoking the compiler to disable logging globally.
- Define the preprocessor symbol NDEBUG to disable all run-time assertions.
Resource consumption examples
The following table illustrates the Flash and RAM resource consumption of some simple AFP configurations on an AVR at90can128 micro-controller build with avr-g++ 4.4.3
. The values include the famouso middleware and a CAN driver. The source is located in the directory tst/approved/AFP/avr-size
.
Node type | Max. event size (Bytes) | AFP | Section text (Bytes) | Section data (Bytes) | Section bss (Bytes) | Filename |
---|---|---|---|---|---|---|
publisher | 8 | none | 2594 | 28 | 38 | can-pub-no-afp |
255 | ANL | 3604 | 28 | 38 | can-pub-anl | |
255 | Application Layer | 3060 | 28 | 38 | can-pub-al | |
subscriber | 8 | none | 2640 | 28 | 38 | can-sub-no-afp |
255 | ANL | 4092 | 28 | 347 | can-sub-anl | |
255 | Application Layer | 3386 | 28 | 301 | can-sub-al |