RTX5 | 配置文件RTX_Config.h(一)
文章目錄
- 一、前言
- 二、System Configuration(系統(tǒng)設(shè)置)
- 2.1、Global Dynamic memory size(內(nèi)存池的大小)
- 2.2、Kernel Tick Frequency[Hz](內(nèi)核滴答時鐘的頻率)
- 2.3、Round-Robin Thread switching(時間片輪轉(zhuǎn)調(diào)度)
- 2.4、ISR FIFO Queue(中斷回調(diào)請求FIFO隊列)
- 2.5、Object Memory usage counters(對象內(nèi)存使用計數(shù)器)
 
一、前言
使用RTX5開發(fā)項目之前,一定要先把RTX5系統(tǒng)配置文件RTX_Config.h弄明白。在學(xué)習(xí)RTX5的配置文件后,我認(rèn)為RTX5的系統(tǒng)配置文件比FreeRTOS與ucosIII的系統(tǒng)配置文件都要簡單。我在STM32F103與STM32H743都移植了RTX5,配置文件使用默認(rèn)配置也能正常工作(FreeRTOS在移植后需要認(rèn)真配置中斷相關(guān)的配置,不然會讓中斷回調(diào)函數(shù)卡死整個RTOS系統(tǒng))。在RTX5上都變得簡單,System Configuration使用默認(rèn)配置也能正常體驗RTX5系統(tǒng)。
 FreeRTOS | STM32H7串口中斷調(diào)用FreeRTOS API,導(dǎo)致程序卡死
RTX_Congig.h包含以下內(nèi)容:
二、System Configuration(系統(tǒng)設(shè)置)
 以下摘自官方手冊:
The system configuration covers system-wide settings for the global memory pool, tick frequency, ISR event buffer and round-robin thread switching.
總的來說,System Configuration用于配置內(nèi)存池,滴答定時器的頻率,中斷回調(diào)函數(shù)ISR的事件Buffer,時間片輪轉(zhuǎn)調(diào)度。
 
2.1、Global Dynamic memory size(內(nèi)存池的大小)
 內(nèi)存池的大小默認(rèn)值是32768個字節(jié),相當(dāng)于32K的RAM內(nèi)存。每一款單片機都有RAM內(nèi)存,只是大小或數(shù)量不一樣而已。以STM32F103為例子,在《STM32F10xx參考手冊》上查到STM32F103的系統(tǒng)架構(gòu)。從系統(tǒng)架構(gòu)看來STM32F103只有一個SRAM,這個SRAM的大小62K。當(dāng)RTX5的內(nèi)存池大小是默認(rèn)的32K時,表示RTX5將占用STM32F103上RAM內(nèi)存的一半以上。此外,也可以通過Keil查看當(dāng)前工程分配RAM的大小。
 
 
STM32H743屬于Cortex-M7內(nèi)核,擁有相當(dāng)充裕的RAM內(nèi)存。在STM32H743上運行RTX5系統(tǒng),必須將內(nèi)存池分配在128KB的DTCM(緊密耦合內(nèi)存)上,因為CPU在DTCM內(nèi)存讀寫數(shù)據(jù)的速度等于CPU的主頻(480M),其他的SRAM內(nèi)存讀寫數(shù)據(jù)的速度僅僅只有200M(當(dāng)然,配置Cache后的讀寫速度也能提升至480M,但是操作比較麻煩)。在Keil上很方便將默認(rèn)內(nèi)存設(shè)置為128KB的DTCM(如下圖所示),使用STM32CubeIDE的話,默認(rèn)內(nèi)存一開始就是128KB的DTCM了(就是不用管的意思)。
 
 
2.2、Kernel Tick Frequency[Hz](內(nèi)核滴答時鐘的頻率)
 摘自官方文檔:
Defines base time unit for delays and timeouts in Hz. Default: 1000Hz = 1ms period
總的來說,就是提供時間基準(zhǔn)給osDelay( )與osDelayUntil( ),還有超時計算。Kernel Tick Frequency頻率越高就更占用CPU的資源,一般項目直接使用1000Hz即可。
2.3、Round-Robin Thread switching(時間片輪轉(zhuǎn)調(diào)度)
 摘自官方文檔:
RTX5 may be configured to use round-robin multitasking thread switching. Round-robin allows quasi-parallel execution of several threads of the same priority. Threads are not really executed concurrently, but are scheduled where the available CPU time is divided into time slices and RTX5 assigns a time slice to each thread. Because the time slice is typically short (only a few milliseconds), it appears as though threads execute simultaneously.
總的來說,就是RTX5也提供時間片輪轉(zhuǎn)調(diào)度的功能。有了這個功能后,系統(tǒng)就允許有兩個以上的線程使用同一個優(yōu)先級。為同一個優(yōu)先級下的線程劃分時間片進(jìn)行調(diào)度,時間片的長度可以通過Round-Robin Timeout設(shè)置(5等于5個Tick)。關(guān)于時間片輪轉(zhuǎn)調(diào)度的詳細(xì)資料可以查看《安富萊_STM32-V7開發(fā)板ThreadX內(nèi)核教程(V0.6)》第13章,還有《嵌入式實時操作系統(tǒng)uC/OS-III》第7.3章節(jié)。
時間片輪轉(zhuǎn)調(diào)度適用于不要求任務(wù)實時響應(yīng)的情況。我的實際項目都是工業(yè)控制機器人控制,對實時性都有要求。所以,一般我都會禁止時間片輪轉(zhuǎn)調(diào)度功能,取消勾選Round-Robin Thread switching這個選項。我的項目都是使用搶占式的方式進(jìn)行調(diào)度(各個線程的優(yōu)先級不一樣)。
2.4、ISR FIFO Queue(中斷回調(diào)請求FIFO隊列)
 摘自官方文檔:
The RTX functions (Calls from Interrupt Service Routines), when called from and interrupt handler, store the request type and optional parameter to the ISR FIFO queue buffer to be processed later, after the interrupt handler exits.
 The scheduler is activated immediately after the IRQ handler has finished its execution to process the requests stored to the FIFO queue buffer. The required size of this buffer depends on the number of functions that are called within the interrupt handler. An insufficient queue size will be caught by osRtxErrorNotify with error code osRtxErrorISRQueueOverflow.
總的來說,RTX5能緩存Cortex-M內(nèi)核的中斷回調(diào)函數(shù)ISR的請求與參數(shù)。針對這個功能我是這樣測試的,在串口中斷回調(diào)函數(shù)里打了一個斷點,讓程序卡死在串口中斷回調(diào)函數(shù)里。接著,繼續(xù)通過串口助手往單片機發(fā)送字符,再一次觸發(fā)串口中斷回調(diào)函數(shù)。(相當(dāng)于觸發(fā)了兩次串口中斷,但CPU卡在第一次串口中斷上,導(dǎo)致第二次串口中斷無法正常執(zhí)行)。
 
 
2.5、Object Memory usage counters(對象內(nèi)存使用計數(shù)器)
摘自官方文檔:
Object memory usage counters help to evaluate the maximum memory pool requirements for each object type, just like stack watermarking does for threads. The initial setup starts with a global memory pool for all object types. Consecutive runs of the application with object memory usage counters enabled, help to introduce object specific memory pools for each object type. Normally, this is required for applications that require a functional safety certification as global memory pools are not allowed in this case.
總得來說,就是在系統(tǒng)運行的過程中,計算線程,消息隊列等對象的生存情況。上面英文的最后一句話很重要,中文意思:對于需要安全性認(rèn)真的應(yīng)用程序來說,這個功能是必需的。勾選這個選項后,通過DEBUG模式下的RTX RTOS調(diào)試窗口可以看到Object Memory Usage Counter選項。當(dāng)前的程序只創(chuàng)建了4個線程與3個消息隊列,在這個Counter上能看到。其中Start線程會在程序啟動后的5S時間將線程退出,所以Free等于1了。
 
總結(jié)
以上是生活随笔為你收集整理的RTX5 | 配置文件RTX_Config.h(一)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: Java学习之IDEA2020安装
- 下一篇: access 文本转换数字_LabVIE
