Efficient coding for small real-time systems.

Written by Ian on Wednesday 03/01/07

Writing software for microcontrollers in real-time systems is totally different to coding for a desktop PC. It might feel the same, the high-level language might be the same, even the compiler - but the constraints on what you can do are totally different. Here are a list of 20 hints and tips that can help you write efficient (and working) real-time code:

Global variables, and use of goto are not sackable offences

Use Q-format fractional binary numbers in place of floats/doubles

Do a condition check when posting to a mailbox to prevent overflows

Don't use the register keyword unless you really need it.

Use the volatile keyword when approbriate

Avoid printf and sprintf - these are q uite time consuming

Avoid large arrays initialised to zero (if required, malloc them and initialise manuallyto zero at program start).