RTX5 | 配置文件RTX_Config.h
文章目录
- 一、前言
- 二、System Configuration(系统设置)
- 2.1、Global Dynamic memory size(内存池的大小)
- 2.2、Kernel Tick Frequency[Hz](内核滴答时钟的频率)
- 2.3、Round-Robin Thread switching(时间片轮转调度)
- 2.4、ISR FIFO Queue(中断回调请求FIFO队列)
- 2.5、Object Memory usage counters(对象内存使用计数器)
- 三、Thread Configuration
- 3.1、Object specific Memory allocation(对象特定的内存分配)
- 3.1.1、Number of user Threads(用户线程的数量)
- 3.1.2、Number of user Threads with default Stack size(使用默认堆栈大小的用户线程的数量)
- 3.1.3、Total Stack size[bytes] for user Threads with user-provided Stack size(提供给用户线程的总堆栈大小)
- 3.2、Default Thread Stack size(线程的默认堆栈大小)
- 3.3、Idle Thread Stack size(空闲线程的堆栈大小)
- 3.4、Idle Thread TrustZone Module Identifier(空闲线程信任区域模块标识符)
- 3.5、Stack overrun checking (堆栈溢出检查)
- 3.6、Stack usage watermark(堆栈使用水印)
- 3.7、Processor mode for Thread execution(线程执行的处理器模式)
- 四、Timer Configuration (时钟配置)
- 4.1、Object specific Memory allocation(对象特定的内存分配)
- 4.2、Timer Thread Priority(软件定时器的优先级)
- 4.3、Timer Thread Stack size[bytes]
- 4.4、Timer Thread TrustZone Module Identifier
- 4.5、Timer Callback Queue entries(定时器回调消息队列)
- 五、Event Flags Configuration(事件标志配置)
- 5.1 Object-specific memory allocation(Event Flags 的对象特定内存分配)
- 六、Mutex Configuration
- 5.1 Object-specific Memory Allocation(互斥量 的对象特定内存分配)
- 七、Semaphore Configuration
- 八、Memory Pool Configuration
- 九、Message Queue Configuration
- 十、Event Recorder Configuration
一、前言
使用RTX5开发项目之前,一定要先把RTX5系统配置文件RTX_Config.h弄明白。
- RTX_Congig.h包含以下内容:
- System Configuration(非常重要)
- Thread Configuration(非常重要)
- Timer Configuration(简单)
- Event Flags Configuration(简单)
- Mutex Configuration(简单)
- Semaphore Configuration(简单)
- Memory Pool Configuration(简单)
- Event Record Configuration(跟RTX5内核没关系,调试工具)
二、System Configuration(系统设置)
Name | #define | Description |
---|---|---|
Global Dynamic Memory size [bytes] | OS_DYNAMIC_MEM_SIZE | Defines the combined global dynamic memory size for the Global Memory Pool. Default value is 4096. Value range is [0-1073741824] bytes, in multiples of 8 bytes.(为全局内存池(Global Memory Pool)定义全局动态内存大小。默认值是4096。值范围为[0-1073741824]字节,为8字节的倍数) |
Kernel Tick Frequency (Hz) | OS_TICK_FREQ | Defines base time unit for delays and timeouts in Hz. Default: 1000Hz = 1ms period.(系统节拍的频率,决定了时间片的最小计量单元,单位HZ。1000H=1ms的同期。) |
Round-Robin Thread switching | OS_ROBIN_ENABLE | Enables Round-Robin Thread switching.(选择是否使能循环调度) |
Round-Robin Timeout | OS_ROBIN_TIMEOUT | Defines how long a thread will execute before a thread switch. Default value is 5. Value range is [1-1000].(表示时间片的大小,单位是系统时钟节拍个数。默认值是5。取值范围为[1-1000].) |
ISR FIFO Queue | OS_ISR_FIFO_QUEUE | RTOS Functions called from ISR store requests to this buffer. Default value is 16 entries. Value range is [4-256] entries in multiples of 4.(表示ISR FIFO队列大小。中新服务程序中调用以isr_开头的函数时,会将请求类型存到此缓冲中。默以值是16个条目(entries)。值范围是[4-256],4的倍数。) |
Object Memory usage counters | OS_OBJ_MEM_USAGE | Enables object memory usage counters to evaluate the maximum memory pool requirements individually for each RTOS object type.(使能对象内存使用计数器,用于单独计算每个RTOS对象类型的最大内存池需求。) |
2.1、Global Dynamic memory size(内存池的大小)
内存池的大小默认值是32768个字节,相当于32K的RAM内存。
2.2、Kernel Tick Frequency[Hz](内核滴答时钟的频率)
总的来说,就是提供时间基准给osDelay( )
与osDelayUntil( )
,还有超时计算。 Kernel Tick Frequency
频率越高就更占用CPU
的资源,一般项目直接使用1000Hz
即可。
2.3、Round-Robin Thread switching(时间片轮转调度)
总的来说,就是RTX5也提供时间片轮转调度的功能。 有了这个功能后,系统就允许有两个以上的线程使用同一个优先级。为同一个优先级下的线程划分时间片进行调度,时间片的长度可以通过Round-Robin Timeout设置(5等于5个Tick)。
时间片轮转调度适用于不要求任务实时响应的情况。 我的实际项目都是工业控制机器人控制,对实时性都有要求。所以,一般我都会禁止时间片轮转调度功能,取消勾选Round-Robin Thread switching这个选项。我的项目都是使用抢占式的方式进行调度(各个线程的优先级不一样)。
2.4、ISR FIFO Queue(中断回调请求FIFO队列)
总的来说,RTX5能缓存Cortex-M内核的中断回调函数ISR的请求与参数。
2.5、Object Memory usage counters(对象内存使用计数器)
总得来说,就是在系统运行的过程中,计算线程,消息队列等对象的生存情况。 上面英文的最后一句话很重要,中文意思:对于需要安全性认真的应用程序来说,这个功能是必需的。勾选这个选项后,通过DEBUG模式下的RTX RTOS调试窗口可以看到Object Memory Usage Counter选项。
三、Thread Configuration
Option | #define | Description |
---|---|---|
Object specific Memory allocation | OS_THREAD_OBJ_MEM | Enables object specific memory allocation. See Object-specific Memory Pools.(是否启用对象特定内存分配。) |
Number of user Threads | OS_THREAD_NUM | Defines maximum number of user threads that can be active at the same time. Applies to user threads with system provided memory for control blocks. Default value is 1. Value range is [1-1000].(定义可以同时运行的最大用户线程数。适用于系统为控制块提供内存的用户线程。默认值是1。值范围是[1-1000]) |
Number of user Threads with default Stack size | OS_THREAD_DEF_STACK_NUM | Defines maximum number of user threads with default stack size and applies to user threads with 0 stack size specified. Value range is [0-1000].(定义使用默认堆栈大小的线程数,取0则表示所有线程都不使用默认大小而使用自定义堆栈大小。取值范围为0-1000]。) |
Total Stack size [bytes] for user Threads with user-provided Stack size | OS_THREAD_USER_STACK_SIZE | Defines the combined stack size for user threads with user-provided stack size. Default value is 0. Value range is [0-1073741824] Bytes, in multiples of 8.(用户自定义堆栈大小的用户线程的总堆栈大小字节)。默认值为0.值范国为0-1073741824]字节,为8的倍数。) |
Default Thread Stack size [bytes] | OS_STACK_SIZE | Defines stack size for threads with zero stack size specified. Default value is 200. Value range is [96-1073741824] Bytes, in multiples of 8.(默认线程堆栈的大小,用户未提供堆栈大小时使用此参数。默认值是200。值范国为96-1073741824]字节,为8的倍数。) |
Idle Thread Stack size [bytes] | OS_IDLE_THREAD_STACK_SIZE | Defines stack size for Idle thread. Default value is 200. Value range is [72-1073741824] bytes, in multiples of 8.(定义空闲线程的堆栈大小。默认值是200。值范国为[72-1073741824]字节,以8为倍数。) |
Idle Thread TrustZone Module ID | OS_IDLE_THREAD_TZ_MOD_ID | Defines the TrustZone Module ID the Idle Thread shall use. This needs to be set to a non-zero value if the Idle Thread need to call secure functions. Default value is 0.(定义空闲线程应该使用的TrustZone Module ID。如果空闲线程需要调用安全函数,则需要将该值设置为非零值。默认值为0.) |
Stack overrun checking | OS_STACK_CHECK | Enable stack overrun checks at thread switch.(启用线程切换处的堆栈溢出检查。) |
Stack usage watermark | OS_STACK_WATERMARK | Initialize thread stack with watermark pattern for analyzing stack usage. Enabling this option increases significantly the execution time of thread creation.(使用水印模式初始化线程堆栈,以分析堆栈使用情况。启用此选项会显著增加线程创建的执行时间。) |
Processor mode for Thread execution | OS_PRIVILEGE_MODE | Controls the processor mode. Default value is Privileged mode. Value range is [0=Unprivileged; 1=Privileged] mode.(选择处理器模式。默认值是特权模式。取值范围为[0=无特权;1=特权)模式。) |
3.1、Object specific Memory allocation(对象特定的内存分配)
Object specific Memory allocation为每一个RTX5的对象创建一个专用的固定大小的内存块,可以有效防止内存碎片化,并简化内存不足情况的处理。并且,在专用的内存里创建对象与删除对象的时间都是完全确定的。
默认的配置下,不勾选Object Specific Memory allocation。此时,当我们创建RTX5的对象时,会在全局内存池里申请一段内存。有线程对象,有消息队列对象,有信号量对象等等,按申请内存的时间顺序一个个放入Global Memory Pool(全局内存池)里。这种情况下,内存肯定会有一点乱。
3.1.1、Number of user Threads(用户线程的数量)
定义同一时间上最多可以运行多少个用户线程。实际测试一下,当前我的程序创建了4个线程。接着,我将Number of user Thread设置3,看看效果如何。
3.1.2、Number of user Threads with default Stack size(使用默认堆栈大小的用户线程的数量)
系统的默认是3072Byte。不建议使用默认的堆栈大小,每一个线程都应该有合适的内存大小。
3.1.3、Total Stack size[bytes] for user Threads with user-provided Stack size(提供给用户线程的总堆栈大小)
使用默认值0,应该是不设置的意思。(毕竟,我一直使用默认值0也能顺利创建多个线程)
3.2、Default Thread Stack size(线程的默认堆栈大小)
创建线程时不指定堆栈大小,就会使用Default Thread Stack Size的值来创建线程。
3.3、Idle Thread Stack size(空闲线程的堆栈大小)
看空闲线程的设计需要多大的内存,默认的空闲线程只需256KB。
3.4、Idle Thread TrustZone Module Identifier(空闲线程信任区域模块标识符)
Armv8-M/v8.1-M架构的单片机才有。
3.5、Stack overrun checking (堆栈溢出检查)
一定要勾选,堆栈真的很容易溢出。
3.6、Stack usage watermark(堆栈使用水印)
使用水印模式初始化线程堆栈以分析堆栈使用情况。 启用此选项会显着增加线程创建的执行时间。我觉得没必要勾选这一项,在DEBUG模式下,使用Keil的RTX RTOS也能看到堆栈的使用情况。
3.7、Processor mode for Thread execution(线程执行的处理器模式)
必须使用privileged mode,不然功能可能会受到限制:
四、Timer Configuration (时钟配置)
Name | #define | Description |
---|---|---|
Object specific Memory allocation | OS_TIMER_OBJ_MEM | Enables object specific memory allocation.(使能对象特定内存分配) |
Number of Timer objects | OS_TIMER_NUM | Defines maximum number of objects that can be active at the same time. Applies to objects with system provided memory for control blocks. Value range is [1-1000].(代表可以同时运行的最大用户定时器数。适用于系统为控制块提供内存的用户定时器。默认值是1。值范围是[1-1000].) |
Timer Thread Priority | OS_TIMER_THREAD_PRIO | Defines priority for timer thread. Default value is 40. Value range is [8-48], in multiples of 8. The numbers have the following priority correlation: 8=Low; 16=Below Normal; 24=Normal; 32=Above Normal; 40=High; 48=Realtime(表示定时器线程的优先级。默认值是40。取值范围为[8-48],取8的倍数。这些数字的优先级相关如下:8=低, 16=低于正常,24=正常, 32=高于正常, 40=高, 48=实时) |
Timer Thread Stack size [bytes] | OS_TIMER_THREAD_STACK_SIZE | Defines stack size for Timer thread. May be set to 0 when timers are not used. Default value is 200. Value range is [0-1073741824], in multiples of 8.(定义计时器线程的堆栈大小。当不使用计时器时,可以将其设置为0。默认值是200。取值范围为[0-1073741824],取8的倍数。) |
Timer Thread TrustZone Module ID | OS_TIMER_THREAD_TZ_MOD_ID | Defines the TrustZone Module ID the Timer Thread shall use. This needs to be set to a non-zero value if any Timer Callbacks need to call secure functions. Default value is 0.(定时器回调函数可以同时运行的最大数目。当不使用计时器时,可以将其设置为0。默认值是4。取值范围为[0-256]。) |
Timer Callback Queue entries | OS_TIMER_CB_QUEUE | Number of concurrent active timer callback functions. May be set to 0 when timers are not used. Default value is 4. Value range is [0-256].(定义空闲线程应该使用的TrustZone Module ID。如果空闲线程需要调用安全函数,则需要将该值设置为非零值。默认值为0.) |
从RTX_Config.h的配置与创建软件定时器的API函数可以得到以下信息:
- 软件定时器的优先级在RTX_Config.h上设置,且软件定时器的API函数不能设置定时器的优先级(线程的优先级由线程API函数设置的)。
- 同一个工程上,所有软件定时器的优先级只能一样了(每一个线程可以设置不同的优先级)。
- 同一个工程上,所有软件定时器的堆栈大小也只能一样了(每一个线程可以设置不同的堆栈大小)。
4.1、Object specific Memory allocation(对象特定的内存分配)
跟线程上的Object specific Memory allocation一样。
4.2、Timer Thread Priority(软件定时器的优先级)
软件定时器只支持6种优先级:
- Low
- Below Normal
- Normal
- Above Normal
- High
- Real Time
4.3、Timer Thread Stack size[bytes]
设置每一个软件定时器的堆栈大小。
4.4、Timer Thread TrustZone Module Identifier
特定的Cortex-M内核才有,STM32F407与STM32H743与STM32F103都没有这个功能。
4.5、Timer Callback Queue entries(定时器回调消息队列)
设置定时器并发回调函数的数量,设置0时,关闭此功能。
五、Event Flags Configuration(事件标志配置)
RTX5提供了几个参数来配置 事件标志(Event Flags) 功能。
Name | #define | Description |
---|---|---|
Object specific Memory allocation | OS_EVFLAGS_OBJ_MEM | Enables object specific memory allocation. See Object-specific Memory Pools.(启用对象特定的内存分配) |
Number of Event Flags objects | OS_EVFLAGS_NUM | Defines maximum number of objects that can be active at the same time. Applies to objects with system provided memory for control blocks. Value range is [1-1000].(定义同时活跃的最大事件标记数。适用于系统为控制块提供内存的控制块。取值范围为[1-1000]。) |
5.1 Object-specific memory allocation(Event Flags 的对象特定内存分配)
当使用对象特定内存时,所有 事件标记对象(Event object) 的内存池大小OS_EVFLAGS_NUM指定。
六、Mutex Configuration
RTX5提供了几个参数来配置互斥量(Mutex)功能。
Name | #define | Description |
---|---|---|
Object specific Memory allocation | OS_MUTEX_OBJ_MEM | Enables object specific memory allocation. See Object-specific Memory Pools.(启用特定于对象的内存分配。) |
Number of Mutex objects | OS_MUTEX_NUM | Defines maximum number of objects that can be active at the same time. Applies to objects with system provided memory for control blocks. Value range is [1-1000].(定义可以同时活动的对象的最大数量。应用于具有系统为控制块提供内存的对象。取值范围为[1 ~ 1000]。) |
5.1 Object-specific Memory Allocation(互斥量 的对象特定内存分配)
当使用对象特定内存时,所有 互斥量对象(Mutex object) 的内存池大小由 OS_MUTEX_NUM 指定。
七、Semaphore Configuration
八、Memory Pool Configuration
九、Message Queue Configuration