According to a research institution’s statistics, currently the highest market share in the global RTOS market is FreeRTOS. Of course, we do not know the specific method of the statistics, but FreeRTOS is indeed very active.
Here I would like to ask everyone, do you have many friends or colleagues around you who use FreeRTOS?
Next, I will share with you the FreeRTOS coding standards and specifications.
FreeRTOS Coding Standards
The kernel version before FreeRTOS V11.0 complies with the MISRA C:2004 coding standard. However, the latest FreeRTOS kernel follows the MISRA C:2012 coding standard.
What is the MISRA C:2012 coding standard? You can refer to my previous article: MISRA C: What is the 2012 standard?.
MISRA C is a C language development standard proposed by the Motor Industry Software Reliability Association (MISRA). Its purpose is to enhance the safety and portability of embedded systems, and there is also a corresponding standard MISRA C++ for C++ language.
Because FreeRTOS uses various different compilers for building, including relatively advanced compilers, FreeRTOS does not use C99 or other standards, but adopts the more stringent MISRA C coding standard.
Since the kernel version before FreeRTOS V11.0 adopts the MISRA C:2004 coding standard, there may be some deviations from the MISRA standard when using the PC-Lint tool for static code analysis.
FreeRTOS Coding Specifications
Different RTOS have different naming conventions. Generally speaking, if a company has higher requirements for code quality, there will be internal coding specifications.
Below are some common coding specifications for FreeRTOS.
1. Variables
uint8_t type variables are prefixed with uc, where “u” indicates “unsigned” and “c” indicates “char”.
uint16_t type variables are prefixed with us, where “u” indicates “unsigned” and “s” indicates “short”.
uint32_t type variables are prefixed with ul, where “u” indicates “unsigned” and “l” indicates “long”.
static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
static uint32_t ulTotalRunTime = 0UL;
size_t type variables are prefixed with x, for example:
static size_t xFreeBytesRemaining = 0U;
However, size_t is actually mostly defined as “unsigned int”, so size_t type variables may also have the prefix ux.
Enumeration variables are prefixed with e.
Pointer variables are prefixed with p.
2. Functions
Static or private functions are prefixed with prv.
static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
API functions with a return type of void are prefixed with v.
void vApplicationTickHook( void );
3. Macro Definitions
Macros are usually prefixed with the file defining the macro, and the prefix is in lowercase.
For example, defined in FreeRTOSConfig.h.
#define configUSE_PREEMPTION 1
Except for the prefix, the rest of the macro definitions are written in uppercase letters and use underscores to separate words.
4. Data Types
Mainly use stdint.h types and RTOS’s own typedef, but there are a few exceptions.
5. Indentation
Use four space characters for indentation.
6. Comments
Comments are usually made using /* */ and should not exceed column 80.
Due to time constraints, I only share some main content here. For more coding specifications, you still need to read the source code to understand.
In fact, you will find that although the coding specifications between different RTOS are different, each RTOS will strictly follow its own coding specifications, which not only facilitates its own upgrades and maintenance, but also makes it easier for users to read the source code.
Recommended Reading
Communication Expert Reveals: The Large-Scale Explosion of BP Machines in Lebanon
Why Use RC Connection Between PCB Ground and Metal Shell?
10 Classic Circuit Examples of Operational Amplifiers
[Follow] Check Out Previous Highlights
▼
IIC Shenzhen International Integrated Circuit Exhibition and Seminar👇