EMBEDDED SYSTEMS & MICROCONTROLLERS · PAGE 84
C Coding Style for Firmware
Readable code is safer code.
Choose clear names, one task per function, and constants instead of magic numbers. Use fixed-width integer types so a variable has the same size on every chip.
Keep hardware access in a few driver files, and logic elsewhere. Short functions with comments about why, not what, make later changes safer.
EXAMPLE
#define LED_PIN 3 #define BLINK_MS 500 void led_toggle(void); /* driver: hides how the pin works */