ChibiOS/RT code follows well define style conventions that must be followed in order to have code accepted in the distribution.
Simply because we believe that a good product must be consistent, it is not acceptable to have different modules following different styles.
Only C89 constructs can be used, things like // or
inline are C99 and must be avoided. Non standard constructs like anonymous structures or unions must be avoided in the portable code but can be used in the compiler-specific code, for example in the ports code.
The only exception is “static inline”, which is acceptable in RT but not in HAL nor NIL.
ChibiOS follows the K&R style indentation style with few modifications:
elsestatement goes to the line after the closing
switchbefore the expression opening
returnstatement must not be surrounded by
ifndefare not recommended, use
casestatement are indented to the same level of the
An Eclipse style file is available in order to quickly reformat code.
|chibios.xml||16.0 KiB||2015/07/21 10:06|
The use of empty lines varies:
/* Comment about the block1.*/ Block1 statements... /* Comment about the block2.*/ Block2 statements... /* Comment about the block3.*/ Block3 statements...
Of course there are rules about comments.
Please use the following general Doxygen template:
/** * @brief A brief description, one sentence, one line. * @details A detailed description of the functionality, it can span over * multiple lines, can be omitted. * @pre Prerequisites about the use of the functionality, there can be * more than one "pre" tags, can be omitted. * @post Postrequisites about the use of the functionality, there can be * more than one "post" tags, can be omitted. * @note There can be one or more notes, can be omitted. * * @param[in] p1 description of parameter one * @param[out] p2 description of parameter two * @param[in,out] p3 description of parameter three * @return Description of the returned value, must be omitted if * a function returns void. * @retval VALUE1 description of the special returned value one, can be * omitted. * @retval VALUE2 description of the special returned value two, can be * omitted. * * @api|@notapi|@special|@init|@sclass|@iclass|@xclass|@isr */
The preferred style of comment are the following, note:
/* This is a single line comment.*/ /* This is a very long comment that necessarily has to span over multiple lines.*/