-
Notifications
You must be signed in to change notification settings - Fork 2k
Best Practice for RIOT Programming
Jean-Claude Wippler edited this page Oct 5, 2015
·
12 revisions
Some "Dos" and "Don'ts" for RIOT development:
- Use static memory. See also Static vs. Dynamic Memory.
- Select the priorities carefully.
- Minimize stack usage with
DEVELHELP
andCREATE_STACKTEST
. - Use threads to increase flexibility, modularity, and robustness by leveraging IPC.
- Don't use too many threads. Try not to use more than one thread per module. Don't create threads for one-time tasks.
- Don't use the POSIX wrapper if implementing something from scratch.
- Don't allocate big chunks of memory (for instance the IPC message queue) on the stack, but use rather static memory for that.
- Don't use enums for flags, because flags have a width in memory that is in most cases smaller than
sizeof(enum)
(most bitfields are 16 bits max, on most of our newer platforms,sizeof(enum)
is however 32 bits). This results in every assignment needed to be cast to eitheruint8_t
oruint16_t
. With macros you don't need to cast since they are typeless. Making the enum packed makes its width unpredictable in terms of alignment issues, when used in struct.