- Sections:
-
- A clear, consistent coding style improves readibility, reduces errors and improves maintainability. This page provides a concise guide to the C coding style used.
- An object-like programming approach is recommended. This means that the data and functionality of an object is encapsulated in an H and C file. A module name must be chosen that is the same or consistent with the filename. This module name must be prefixed to all function names, structures, defines, enumerations, etc.
- For example, see tmr.h : Polled software timers
- Template files have been created for consistent organisation of each C module. See template.h, template.c & template.S
- Doxygen is used to document each module. See Using Doxygen source documentation system.
- The ANSI C style is followed. 4 spaces must be used for each indentation level, not tabs. Braces must be used, even for single lines.
for(i=0; i<10; i++)
{
for(j=0; j<10; j++)
{
buffer[i][j] = 0;
}
}
- Functions
- Lower case letters with underscores separating words. The name must have the module name prefixed.
- Preprocessor #defines and Macros
- Capital letters with underscores separating words. The name must have the module name prefixed.
#define CRC16_CCITT_POLYNOMIAL 0x8408
#define ARRAY_LENGTH(array) (sizeof(array)/sizeof((array)[0]))
- Variables
- Lower case letters with underscores separating words. If the variable is declared outside function or structure scope, then it must have the module name prefixed.
- Typedef
- Lower case letters with underscores separating words. The name must have the module name prefixed. An "_t" suffix must be added to indicate that it is a typedef.
typedef u16_t pit_ticks_t;
- Structures
- Lower case letters with underscores separating words. The name must have the module name prefixed. An "_s" suffix must be added to indicate that it is a struct.
struct list_item_s
{
struct list_item_s *next_item;
struct list_item_s *previous_item;
};
- Standard types have been defined and should be used to keep code portable. See common.h : Common definitions
#include "common.h"
typedef struct
{
u8_t msg_type;
u8_t data[13];
u16_t crc;
} msg_t;