Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

Recently, some friends have been asking: when learning RTOS, should one choose µCOS or FreeRTOS?

In fact, similar questions are often asked by many, and there is no unified answer. Generally speaking, once you learn one RTOS, it becomes relatively easy to learn others.
Currently, both µCOS and FreeRTOS are suitable for beginners. µCOS has relatively standardized source code, making it easier to understand. FreeRTOS has a higher market share and more learning materials available.
Of course, both have their own characteristics. Today, I will share the coding standards of these two RTOS, taking uC/OS-III V3.08.02 and FreeRTOS V10.5.1 as examples.

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide Coding Standards Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

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

The uC/OS article clearly states adherence to the MISRA C:2012 standard and also supports PC-Lint static checking.

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

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.

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

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:

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide Configuration File Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

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

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

2. FreeRTOS

FreeRTOS configuration file is usually: FreeRTOSConfig.h

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide Headers Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

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.:

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

2. FreeRTOS

Includes RTOS version, copyright statement, open-source license statement, website, etc., similar to uC/OS.

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide Naming Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

The naming conventions for both RTOS differ significantly, but both adhere to conventional coding naming rules.

1. File Names

uC/OS uses the format 【os_ system file】, which appears more standardized (reflecting modular design).

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.)

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

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】.

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

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.

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

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:

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

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.

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide Comments Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

// /* */ 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:

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

Of course, the function comment information for FreeRTOS is described in detail in the manual.

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide Indentation Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

Both RTOS use the same indentation style, which is 4 spaces:

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

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.)

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide Abbreviations Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

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

How to Design EMC Surge Protection Circuits? From Principles to Selection
Essentials | MOSFET Protection Circuit Analysis
Essentials | What is the role of the C language enumeration end? It confuses experts.
Essentials | Why can’t crystal oscillators be placed at the edge of the PCB?
Essentials | The datasheet tells you: Why do LDO linear voltage regulators need parallel diodes?
Essentials | A very practical one-button power switch circuit, have you learned it?
Essentials | Why do we generally choose transistors instead of MOSFETs for microcontroller I/O port driving?
Essentials | How does a charger not output voltage when the battery is not connected?
Essentials | If the power supply is not good, overtime is inevitable! What factors need to be considered for a good power supply?
Essentials | Can the feedback resistors of DCDC voltage dividers be taken arbitrarily?
Essentials | Two current detection circuit design schemes
Essentials | Basic structure of power MOSFET: Super Junction Structure
Essentials | How wide should the traces be for 1A current during layout?
Essentials | PCB failure analysis technology and solutions
Essentials | Detailed explanation of nonlinearity in RF
Essentials | How to elegantly handle PCB silkscreen?
Essentials | What are the considerations for switch detection circuits in Germany?
Essentials | Comparison and analysis of various topologies of common switch power supplies
Essentials | How to implement short press and long press detection for buttons?
Essentials | I fell into a pit again! This time I lost to the CAN bus.
Essentials | After shipping 50k, I found that 1% of the products could not start…
Essentials | Through 6 example circuit analyses, detailed explanation of lightning surge protection
Essentials | It burned black as soon as it was powered on! Considerations for high current PCB design
Essentials | A comprehensive understanding of power filter design techniques
Essentials | Easy-to-understand UART protocol frame format
Essentials | Dynamically change DC-DC feedback resistors to adjust output voltage
Essentials | What is power ripple, and how to suppress it?
Essentials | How to choose inductors for DCDC buck switching power supplies?
Essentials | What is a PCB fan hole, and what are the requirements for PCB design regarding fan holes?

· END ·

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

Leave a Comment

×