STM32F1 CMSIS RTX RTOS

Started by tha, August 02, 2021, 08:34:26 AM

Previous topic - Next topic

tha

เปรียบเทียบกับ the classic Keil RTX version, the CMSIS-RTOS RTX library ถูกเพิ่มเติมด้วย the CMSIS API interface module (source file rt_cmsis.c) ซึ่งจัดให้มีใช้ the function translation. The header file cmsis_os.h จัดให้มี the API ไปยัง the CMSIS-RTOS RTX สำหรับ the user application. อ้างอิงถึง Create an RTX Project สำหรับข้อมูลที่มากขึ้น.

CMSIS-RTOS RTX มีหลายตัวเลือกที่ถูกกำหนดค่าด้วย the RTX_Conf_CM.c file. อ้างอิงถึง Configure RTX สำหรับข้อมูลที่มากขึ้น.

คุณสมบัติของ the CMSIS-RTOS RTX implementation:

     •   จัดให้มี the complete functions ระบุสำหรับ a CMSIS-RTOS ด้วยข้อยกเว้นของ the function osWait.
     •   Interrupt Service Routines (ISR) อาจเรียกบาง CMSIS-RTOS RTX functions.
     •   การกำหนดค่าตัวเลือกสำหรับ Thread Stack. อ้างอิงถึง Thread Configuration สำหรับข้อมูลที่มากขึ้น.
     •   Fully deterministic context switching and deadlock avoidance. Refer to Priority Inversion on Resource
         Sharing
for more information.
     •  Optional Round-Robin Thread switching with configurable time-slices. Refer to Thread Configuration
          for more information.

ส่วนต่อไปนี้ให้รายละเอียดเพิ่มเติม:

     •   Theory of Operation : จัดให้มี general information เกี่ยวกับ the operation of CMSIS-RTOS RTX.
     •   Directory Structure and File Overview : อธิบาย the directories and files ที่ให้มาเป็นส่วนหนึ่งของ CMSIS-
          RTOS RTX.
     •   Technical Data : รายการ hardware requirements และ limitations อย่างเช่นจำนวนของ concurrent threads.
     •   MISRA-C:2004 Compliance Exceptions : อธิบายการละเมิด the MISRA standard.
     •   Create an RTX Project : จัดให้มี instructions สำหรับการเขียนและการดีบัก applications ด้วย CMSIS-RTOS
          RTX.
     •   Configure RTX : อธิบาย configuration parameters of CMSIS-RTOS RTX.
     •   RTX Tutorial : เป็นการสอนเชิงลึกที่สามารถถูกใช้กับ hardware ใดๆเพื่อได้รับความเข้าใจที่ดีขึ้นของแนวคิดและการใช้งาน
          หลายกรณีของ a real-time operating system.
     •   Building the RTX Library : อธิบายวิธีการสร้าง CMSIS-RTOS RTX library ของคุณเอง.

tha

https://arm-software.github.io/CMSIS_5/RTOS/html/theory.html

Theory of Operation

ส่วนนี้อธิบายวิธีที่ CMSIS-RTOS RTX จัดการทรัพยากรของ the target system. หลายแง่มุมของ the CMSIS-RTOS RTX kernel สามารถถูกกำหนดค่า. ข้อมูลเกี่ยวกับการกำหนดค่าตัวเลือกถูกกล่าวถึงตามที่ใช้ประโยชน์ได้.

Settings for osFeature_xxx in cmsis_os.h

CMSIS-RTOS RTX ใช้ต่อไปนี้ #defines.



RTX Kernel Timer Tick and Thread Management

โดยค่าเริ่มต้น, CMSIS-RTOS RTX ใช้ the Cortex-M SysTick timer เพื่อสร้าง periodic interrupts สำหรับ the RTX kernel timer tick. CMSIS-RTOS จัดให้มี Timer Management functions และหลาย CMSIS-RTOS functions มี a timeout parameter. periodic RTX kernel timer tick interrupt นี้ถูกใช้เพื่อหา the required time interval. CMSIS-RTOS RTX จัดให้มี configuration options สำหรับ a alternative timer และ tick-less operation อีกด้วย. อ้างอิงถึง to RTX Kernel Tick Timer Configuration สำหรับข้อมูลที่มากขึ้น.

เพื่อจัดการ timeout และ time delays สำหรับ threads, the CMSIS-RTOS RTX thread management ถูกควบคุมโดย the RTX kernel timer tick interrupt. The thread context สวิทช์ตัวมันเองถูกจัดให้มีใช้ใน the HAL_CMx.x hardware abstraction layer source files. The thread context บรรจุทุก CPU registers (R0 - R12), the return address (LR), the program counter (PC), และ the processor status register (xPSR). สำหรับ the Cortex-M4 FPU และ Cortex-M7 FPU the floating point status และ registers (S0 - S32, FPSCR) ก็เป็นส่วนหนึ่งของ the thread context.

เมื่อ a thread switch เกิดขึ้น:

     •   the thread context ของ the current running thread ถูกเก็บบน the local stack ของ thread นี้.
     •   the stack pointer ถูกสวิทช์ไปยัง the next running thread.
     •   the thread context ของ next running thread นี้ถูกกู้คืนและ thread นี้สตาร์ทเพื่อรัน

Note
     •   สำหรับ Cortex-M0, Cortex-M3, Cortex-M4, and Cortex-M7 the thread context ต้องการ 64 bytes บน the local
          stack.
     •   สำหรับ Cortex-M4 FPU and Cortex-M7 FPU the thread context ต้องการ 200 bytes บน the local stack. สำหรับ
          devices ที่มี Cortex-M4 FPU และ Cortex-M7 FPU the default stack space ควรถูกเพิ่มขึ้นเป็นอย่างน้อย 300 bytes.

แต่ละ thread ถูกจัดให้มีพร้อมด้วย an separate stack ที่ถือ the thread context และ stack space สำหรับ automatic variables และ return addresses สำหรับ function ที่เรียก nesting. The stack sizes ของ the RTX threads สามารถกำหนดค่าได้อย่างยืดหยุ่นดังอธิบายใน the section Thread Configuration. RTX เสนอแม้แต่ a configurable checking สำหรับ stack overflows. อ้างอิงถึง Stack Overflow Checking สำหรับข้อมูลที่มากขึ้น.

tha

CMSIS-RTOS RTX Threads

ที่ startup time, the CMSIS-RTOS RTX สร้าง the following threads:

     •   main : the 'main' function ของ the application code ถูกสตาร์ทดั่ง thread ที่มี the osPriorityNormal.
     •   os_idle_demon : thread นี้ปฏิบัติเมื่อไม่มี thread อื่นอยู่ใน RUNNING state. The code ของ thread นั้นถูกจัดให้มีใน the
         RTX_Conf_CM.c file และถูกใช้โดยทั่วไปเพื่อใส่ the system ลงใน a power-saving mode.
     •   osTimerThread : thread นี้ปฏิบัติ the Timer Management callback functions. thread นี้สามารถถูกปิดการใช้งาน;
         อ้างอิงถึง User Timer Management สำหรับ configuration options.

Priority Inversion on Resource Sharing

The CMSIS-RTOS RTX ใช้ a priority-based preemptive scheduler ซึ่งแน่ใจว่าจากทุก the threads ที่อยู่ใน the READY state, the thread ที่มี the highest priority ได้รับการปฏิบัติและกลายเป็น the RUNNING thread. เนื่องจาก threads แชร์ทรัพยากร, events ที่อยู่นอกเหนือการควบคุมของ the RTX scheduler สามารถป้องกันไม่ให้ the highest priority thread ทำงานเมื่อมันควร. หากเกิดเหตุการณ์นี้, a critical deadline อาจถูกพลาดไป, เป็นเหตุให้ the system ล้มเหลว. Priority inversion เป็นเงื่อนไขของ a scenario ซึ่ง the highest-priority ready task ล้มเหลวในการทำงานเมื่อมันควร.

Threads โดยทั่วไปแชร์ resources เพื่อสื่อสารและประมวลผล data โดยการใช้ the CMSIS-RTOS Mutexes. ที่เวลาใดๆ, สอง threads หรือมากกว่าแชร์ a resource, อย่างเช่น a memory buffer หรือ a serial port, หนึ่งของมันอาจมี a higher priority. มันถูกคาดหมายว่า the higher-priority thread ทำงานทันทีที่มันอยู่ใน the READY state. อย่างไรก็ตาม, ถ้า the lower-priority thread กำลังใช้ a shared resource ของ a higher-priority thread, higher-priority thread นี้ต้องคอยจนกระทั่ง the lower-priority thread ปลดปล่อย the shared resource.

เพื่อป้องกัน priority inversions, the CMSIS-RTOS RTX จัดให้มีใช้ a priority inheritance method สำหรับ the Mutexes. A lower-priority thread จะรับช่วง the priority ของ higher-priority thread ใดๆที่กำลังรออยู่ด้วย osMutexWait บน a shared resource. ในระหว่างเวลา the higher-priority thread อยู่ใน WAITING state, the lower-priority thread ทำงานที่ the same priority ของ a higher-priority pending thread. เมื่อ the lower-priority thread หยุดเพื่อแชร์ a resource ด้วย osMutexRelease, the original priority ถูกกำหนดให้ thread นี้อีกครั้ง.

Function calls from Interrupt Service Routines (ISR)

The following CMSIS-RTOS functions สามารถถูกเรียกจาก threads and Interrupt Service Routines (ISR):

     •   osKernelRunning
     •   osSignalSet
     •   osSemaphoreRelease
     •   osPoolAlloc, osPoolCAlloc, osPoolFree
     •   osMessagePut, osMessageGet
     •   osMailAlloc, osMailCAlloc, osMailGet, osMailPut, osMailFree


Functions ที่ไม่สามารถถูกเรียกจาก an ISR กำลังตรวจสอบ the interrupt status และส่งคืน the status code osErrorISR ในกรณีที่พวกมันไม่ถูกเรียกจาก an ISR context.


tha

https://arm-software.github.io/CMSIS_5/RTOS/html/dirstructfiles.html

Directory Structure and File Overview

The following section จัดให้มีภาพรวมของ the directory structure และ the files ที่เกี่ยวข้องสำหรับ the user's for CMSIS-RTOS RTX.

CMSIS-RTOS RTX Directory Structure

The CMSIS-RTOS RTX ถูกส่งใน source code และหลายตัวอย่างถูกจัดให้มี.



CMSIS-RTOS RTX Library Files

The CMSIS-RTOS RTX Library มีให้ใช้ประโยชน์การคอมไพล์ล่วงหน้าสำหรับ ARMCC, GCC, and IAR C/C++ Compilers และรองรับทุก Cortex-M processor ที่แตกต่างกันในทุก configuration.

(ดูในลิ้งค์เอานะครับ)

Configuration File RTX_Conf_CM.c

(ดูในลิ้งค์เอานะครับ)

tha

https://arm-software.github.io/CMSIS_5/RTOS/html/technicalData.html

Technical Data

ส่วนนี้แสดงรายการ the technical data of CMSIS-RTOS RTX.
(ดูในลิ้งค์เอานะครับ)

Note
     •   ไม่จำกัดหมายความว่า the RTX kernel ไม่ได้กำหนดข้อจำกัดใดๆเกี่ยวกับจำนวน อย่างไรก็ตาม, the available system
          memory resources จะจำกัดจำนวนรายการที่คุณสามารถสร้างได้.
     •   RAM requirements ขึ้นอยู่กับจำนวนของ concurrently running threads.
     •   The code and RAM size ถูกคำนวณสำหรับ ARMCC Compiler เมื่อใช้ the MicroLib runtime library.

osWait

The generic wait function osWait ยังไม่ได้รองรับโดย CMSIS-RTOS RTX.

tha

https://arm-software.github.io/CMSIS_5/RTOS/html/misraCompliance.html

MISRA-C:2004 Compliance Exceptions

CMSIS-RTOS RTX พยายามให้เป็น MISRA-C compliant มากที่สุดเท่าที่สามารถเป็นได้. อย่างไรก็ตาม, มีการละเมิดบางอย่างเพื่อให้ง่าย the overall code logic และเพื่อสร้าง more efficient code.

CMSIS-RTOS RTX สร้าง the following notes, warnings and infos สำหรับ MISRA-C:2004 rules:
(ดูในลิ้งค์เอานะครับ)

CMSIS-RTOS RTX ละเมิด the following MISRA-C:2004 rules:
(ดูในลิ้งค์เอานะครับ)

tha

https://arm-software.github.io/CMSIS_5/RTOS/html/using.html

Create an RTX Project

Example projects ที่ใช้ CMSIS-RTOS RTX มีให้ประโยชน์สำหรับ various development boards. เพื่อทำให้ได้ใช้ตัวอย่างเหล่านี้, คุณจำเป็นต้องติดตั้ง a Device Family Pack ใน ?Vision และใช้ Pack Installer เพื่อเปิด a CMSIS-RTOS Blinky project. ถ้าคุณต้องการสตาร์ท a CMSIS-RTOS RTX ตั้งแต่เริ่มต้น ให้ทำตามขั้นตอนเหล่านี้:

     •   สร้าง a new project และเลือก a device.
     •   ใน the Manage Run-Time Environment window ที่เปิด, เลือก CMSIS::CORE and CMSIS::RTOS
          (API)::Keil RTX
. ถ้า the Validation Output ต้องการ components อื่นถูกแสดง, ลองใช้ the
          Resolve button:

     •   คลิก OK. ใน the Project window, คุณจะเห็น the files ที่ถูกเพิ่มโดยอัตโนมัติไปยัง project ของคุณ, อย่าง
          เช่น RTX_Conf_CM.c และ the system และ startup files:

     •   คุณสามารถเพิ่ม template files ไปยัง the project โดย right-clicking บน Source Group 1 และเลือก Add
          New Item to 'Source Group 1'
. ใน the new window, คลิกบน User Code Template. บน the right-
          hand side คุณจะเห็น all available template files สำหรับ CMSIS-RTOS RTX:

     •   สุดท้าย, กำหนดค่า RTX ไปยัง the application's needs โดยใช้ the RTX_Conf_CM.c file.

tha

Define and Reference Object Definitions

ด้วย #define osObjectsExternal objects ถูกกำหนดเป็น external symbols. นี้ยอมให้สร้าง a consistent header file ที่ถูกใช้ตลอดทั้ง a project. ถ้าคุณกำลังใช้ the CMSIS-RTOS 'main' function user code template, อย่าง a header file (called osObjects.h) จะถูกเพิ่มโดยอัตโนมัติไปยัง the project:



header file นี้กำหนดทุก objects เมื่อถูกรวมใน a C/C++ source file. เมื่อ #define osObjectsExternal ถูกแสดงก่อน the header file, the objects ถูกกำหนดเป็น external symbols. A single consistent header file สามารถดังนั้นถูกใช้ตลอดทั้ง the whole project.