User Tools

Site Tools


codingstandard:index

This is an old revision of the document!


Coding standard for C

Indentation

Doxygen

Main principles

All functions/variables/files/macros/typedefs/structs/unions etc should be documented. The main rule is that everything in the .h file is documented and everything in the .c file is documented (except for the things already documented in the .h) file. Function prototypes and other declarations are documented and not imports and implementations.

The use of redundant information and excessive tag usage should be avoided. See the following example of the documentation for a file:

/**
 * @brief This is a brief description
 *
 * @details This is a detailed description of what this file does. This
 * can be multi-line and multi-sentance.
 *
 * @file driver.c
 */

Using the correct settings for Doxygen the same can be accomplished using:

/**
 * This is a brief description.
 *
 * This is a detailed description of what this file does. This
 * can be multi-line and multi-sentance.
 *
 * @file
 */

Dox files

There's a couple of special files used to set everything up:

  • config.dox - holds the Doxygen configuration
  • mainpage.dox - hold the main page for the doxygen documentation
  • groups.dox - holds the definitions of the groups used

Grouping

A group is detailed in the groups.dox file and is documented using:

/**
 * @defgroup drivers
 * 
 * This is a brief description of the drivers group.
 *
 * This is a detailed description of what the driver
 * group does etc..
 */

Any tag can then be added to the group by using the ingroup tag:

/**
 * This documents a file.
 *
 * Detailed description of file. This can be multi-line
 * and multi-sentance.
 *
 * @file
 * @ingroup hal
 */
...

/**
 * Main task for LEDs.
 *
 * This task is responsible for driving the LEDs and lighting
 * them according to the scheme that is currently set.
 *
 * @param[in] param The parameters for the task
 *
 * @ingroup tasks
 */
void ledTask(void *param);

/**
 * Keeps track of number of blinks.
 *
 * @ingroup variables
 */
uint32_t nbrOfBlinks;

Files

The file header should follow this template:

/*
Insert license text here.
*/

/**
 * This is the brief description.
 *
 * This is the detailed description. It is multi-line
 * and multi-sentance.
 *
 * @file
 * @ingroup drivers
 */

Functions

Functions should be documented according to the following:

/**
 * This is the brief description.
 *
 * This is the detailed description. It can be multi-line and
 * multi-sentance.
 *
 * @param[in]  param1 Pass data into the function
 * @param[out] param2 Pass buffer to put return data into
 *
 * @return Description of the return (omitted if void)
 * @ingroup group
 */ 

Structs/typedef/unions

Macros

Coding standard for Python

What ever works ;-)

codingstandard/index.1337358340.txt.gz · Last modified: 2015-07-15 16:30 (external edit)