Recently, some friends have been asking: when learning RTOS, should one choose µCOS or FreeRTOS?
Coding Standards
Both uC/OS and FreeRTOS adhere to the MISRA C coding standards and support PC-Lint static checking, as stated in their official documentation.
Note:
The MISRA C standard refers to the automotive C language development standard.
1. uC/OS
2. FreeRTOS
FreeRTOS also clearly states that it adopts MISRA C coding standards but does not support standards after C99. It also supports PC-Lint static checking.
FreeRTOS contains a lot of explanations (comments) in the source code regarding code that may trigger exceptions in PC-Lint static checking, which is not present in uC/OS source code.
For example:

Configuration File
The configuration files (also known as “trimming” files) for both RTOS are somewhat similar and have been categorized.
However, the categorization and comments in uC/OS are more user-friendly and easier for beginners to understand.
1. uC/OS
The configuration file for uC/OS is usually: os_cfg.h
2. FreeRTOS
FreeRTOS configuration file is usually: FreeRTOSConfig.h

Headers
The contents of the headers for both RTOS are somewhat similar, just one is centered and the other is left-aligned.
1.uC/OS
Includes RTOS version, copyright statement, open-source license statement, etc.:
2. FreeRTOS
Includes RTOS version, copyright statement, open-source license statement, website, etc., similar to uC/OS.

Naming
The naming conventions for both RTOS differ significantly, but both adhere to conventional coding naming rules.
1. File Names
FreeRTOS is more straightforward, which may be due to a lack of long-term planning during naming, and to maintain compatibility, it has been used ever since. (This may lead to file name collisions.)

2. Macros
Both share similarities: uppercase letters separated by underscores, but there are some differences in prefixes.
For example, regarding “configuration files”: uC/OS starts with 【OS_CFG_】, while FreeRTOS starts with 【config】.
3. Data Types
The data types defined by uC/OS are relatively more common and suitable for beginners.
FreeRTOS defines data types that are more “systematic,” suitable for experienced users, and less friendly to beginners.
4. Function Names
Both are somewhat similar, with different prefixes, but both start with uppercase letters for distinction.
For example, the function name for creating tasks:
The prefix for FreeRTOS has the following description:
-
Static functions are prefixed with prv. For example: prvIdleTask function.
-
API functions are prefixed with their return type; void types are suffixed with v. For example: vTaskDelete function.
Comments
// /* */ is the two most common methods of commenting, but these two RTOS primarily use 【/* */】 comments.
The position of comments is also important, typically one line above the code line or at the end of the code line (after the code).
It should be noted that FreeRTOS does not have reliable comments on the functionality, parameters, return values, etc., of functions in the code.
Taking the “create task” function as an example:
Of course, the function comment information for FreeRTOS is described in detail in the manual.
Indentation
Both RTOS use the same indentation style, which is 4 spaces:
It should be noted that mixing tabs and spaces should be avoided, or else the code will be a mess. (This often happens with many beginners or junior engineers, making the code hard to look at.)
Abbreviations
Different fields have different ways of abbreviating words. In RTOS, there are also some common abbreviations, such as:
Abbreviation | Meaning |
Addr | Address |
Blk | Block |
Chk | Check |
Clr | Clear |
Cnt | Count |
Ctr | Counter |
Ctx | Context |
Cur | Current |
Del | Delete |
Dly | Delay |
Err | Error |
OS | Operating System |
CPU | Center Processing Unit |
That’s all for this article. The above only lists some typical coding styles; for more details, you can take time to study on your own.
Recommended Reading
· END ·
