Coding Conventions


This section indicates the coding conventions used in the sample applications and modules included as source code.

File Organization

A typical sample application source code file is organized as follows:


Module Variables

By convention, the variables of a module are grouped into a structure declared globally at the beginning of the file.

This convention has several advantages:

  • It reduces name collision with variables from other modules.
  • It allows a developer to watch all the variables at once during debug by watching a single structure.
  • It allows different functions to easily access the same variables without requiring pointers to be passed between functions.

    If different tasks access the same variables, make sure to protect the access to the variables, for example through a mutex.

  • The stack space does not need to change when variables are added/removed, since modules variables are statically allocated rather than allocated from a task's stack.
  • This structure can include the declaration of the stack space for different tasks, which need to be done globally.

Kernel header

The "kernel header" is a set of bytes pre-pended to the binary image of your application. It needs to be present for your application to start running. All sample application files contain the code to install a kernel header. You can reuse that code when creating your own applications.

Miscellaneous Conventions

  • 4 spaces are used for indentation. Tabs are never used.
  • Source code is written to not exceed a width of 80 columns.
  • Selected functions are commented using Doxygen syntax.