FreeRTOS 笔记

FreeRTOS 笔记

1. Support Port

FreeRTOS 当前已经支持20+编译器和 30+ 芯片结构。

`Port`: FreeRTOS 支持的编译器和处理器组合称之为一个 port。

2. File Structure

`FreeRTOSConfig.h`: 用户配置头文件

`FreeRTOS.h`: 对外头文件头文件

FreeRTOS

│ │

│ ├─Source Directory containing the FreeRTOS source files

| │

| ├─tasks.c FreeRTOS source file - always required

| ├─list.c FreeRTOS source file - always required

| ├─queue.c FreeRTOS source file - nearly always required

| ├─timers.c FreeRTOS source file - optional

| ├─event_groups.c FreeRTOS source file - optional

| └─croutine.c FreeRTOS source file - optional(rarely used now)

| │

| └─portable Directory containing all port specific source files

| │

| ├─MemMang Directory containing the 5 alternative heap allocation source files

| │

| ├─[compiler 1] Directory containing port files specific to compiler 1

| │ │

| │ ├─[architecture 1] Contains files for the compiler 1 architecture 1 port

| │ ├─[architecture 2] Contains files for the compiler 1 architecture 2 port

| │ └─[architecture 3] Contains files for the compiler 1 architecture 3 port

| │

| └─[compiler 2] Directory containing port files specific to compiler 2

| │

| ├─[architecture 1] Contains files for the compiler 2 architecture 1 port

| ├─[architecture 2] Contains files for the compiler 2 architecture 2 port

│ │

│ └─Demo Directory containing pre-configured and port specific FreeRTOS demo projects

FreeRTOS-Plus

├─Source Directory containing source code for some FreeRTOS+ ecosystem components

└─Demo Directory containing demo projects for FreeRTOS+ ecosystem components

2.1 Include Paths

用户使用时,必须包含以下头文件的路径:

FreeRTOS 核心头文件:FreeRTOS/Source/include.FreeRTOS 配置头文件:FreeRTOSConfig.h.目标 port 的头文件: FreeRTOS/Source/portable/[compiler]/[architecture].3. Data Types and Coding Style Guide

`portmacro.h` 中必须定义的数据类型 :

1. `TickType_t`:如果 configUSE_16_BIT_TICKS == 1,uint16_t ;如果 configUSE_16_BIT_TICKS == 0,uint32_t ;

2. `BaseType_t`:等于CPU位宽,或者地址总线宽度, 如32bit 的结构就是32bit

3.1 变量命名

前缀_变量名称,其中前缀包括:

‘c’ for char;‘s’ for int16_t (short);‘l’ for int32_t (long),;‘x’ for BaseType_t and any other non-standard types (structures, task handles, queue handles,etc.);'u' for unsigned;‘p’ for pointer;3.2 函数命名

函数的前缀标识其返回值,前缀同变量命名前缀,另外:

‘prv’ 表示 仅在该文件内部起作用,即 File scope (private) functions。3.3 格式(formatting)

1 tab = 4 spaces。(Tab键等于4个空格)3.4 宏命名

宏命名采用 前缀_大写字母格式,其中前缀表示 该宏定义的

宏定义前缀

Num

Prefix

Location of macro definition

Example

1

port

portable.h or portmacro.h

portMAX_DELAY

2

task

task.h

taskENTER_CRITICAL()

3

pd

projdefs.h

pdTRUE

4

config

FreeRTOSConfig.h

configUSE_PREEMPTION

5

err

projdefs.h

errQUEUE_FULL

通用宏

Num

Macro

Value

1

pdTRUE

1

2

pdFALSE

0

3

pdPASS

1

4

pdFAIL

0

相关推荐