FreeRTOS

Started by tha, October 08, 2021, 08:24:01 AM

Previous topic - Next topic

tha

configGENERATE_RUN_TIME_STATS

The Run Time Stats page อธิบายการใช้ของ parameter นี้.

configUSE_CO_ROUTINES

เซ็ตเป็น 1 เพื่อรวม co-routine functionality ใน the build, หรือ 0 เพื่อละเว้น co-routine functionality จาก the build. เพื่อรวม co-routines croutine.c ต้องถูกรวมใน the project.

configMAX_CO_ROUTINE_PRIORITIES

จำนวนของ priorities ที่มีให้ใช้ประโยชน์กับ the application co-routines. จำนวนเท่าใดก็ได้ของ co-routines สามารถแชร์ the same priority. Tasks ถูกจัดลำดับความสำคัญแยกต่างกัน - ดู configMAX_PRIORITIES.

tha

configUSE_TIMERS

เซ็ตเป็น 1 เพื่อรวม software timer functionality, หรือ 0 เพื่อละเว้น software timer functionality. ดู the FreeRTOS software timers page สำหรับการอธิบายเติม.

configTIMER_TASK_PRIORITY

เซ็ต the priority of the software timer service/daemon task. ดู the FreeRTOS software timers page สำหรับการอธิบายเติม.

configTIMER_QUEUE_LENGTH

เซ็ตความยาวของ the software timer command queue. ดู the FreeRTOS software timers page สำหรับการอธิบายเติม.

configTIMER_TASK_STACK_DEPTH

เซ็ต the stack depth ที่จัดสรรให้กับ the software timer service/daemon task. ดู the FreeRTOS software timers page สำหรับการอธิบายเติม.

tha

configKERNEL_INTERRUPT_PRIORITY
configMAX_SYSCALL_INTERRUPT_PRIORITY and
configMAX_API_CALL_INTERRUPT_PRIORITY


Ports ที่บรรจุ a configKERNEL_INTERRUPT_PRIORITY ตั้งค่า include ARM Cortex-M3, PIC24, dsPIC, PIC32, SuperH and RX600. Ports ที่บรรจุ a configMAX_SYSCALL_INTERRUPT_PRIORITY ตั้งค่า include PIC32, RX600, ARM Cortex-A and ARM Cortex-M ports.

ARM Cortex-M3 and ARM Cortex-M4 ผู้ใช้โปรดใช้หมายเหตุพิเศษในตอนท้ายของส่วนนี้!

configMAX_API_CALL_INTERRUPT_PRIORITY เป็นชื่อใหม่สำหรับ configMAX_SYSCALL_INTERRUPT_PRIORITY ที่ถูกใช้โดยพอร์ตที่ใหม่กว่าเท่านั้น ทั้งสองมีค่าเท่ากัน.

configKERNEL_INTERRUPT_PRIORITY ควรถูกเซ็ตไปยัง the lowest priority.

หมายเหตุในการสนทนาต่อไปนี้ที่เฉพาะ API functions ที่สิ้นสุดใน "FromISR" เท่านั้นสามารถถูกเรียกจากภายใน an interrupt service routine


tha

สำหรับ ports ที่จัดให้มีใช้เฉพาะ configKERNEL_INTERRUPT_PRIORITY
configKERNEL_INTERRUPT_PRIORITY เซ็ต the interrupt priority ที่ใช้โดย the RTOS kernel ของมันเอง. Interrupts ที่เรียก API functions ต้องปฏิบัติที่ priority นี้อีกด้วย. Interrupts ที่ไม่เรียก API functions สามารถปฏิบัติที่ higher priorities และดังนั้นไม่เคยมีการปฏิบัติของพวกมันถูกหน่วงเวลาโดย the RTOS kernel activity ภายในข้อจำกัดของ the hardware มันเอง).

สำหรับ ports ที่จัดให้มีใช้ทั้ง configKERNEL_INTERRUPT_PRIORITY and configMAX_SYSCALL_INTERRUPT_PRIORITY:
configKERNEL_INTERRUPT_PRIORITY เซ็ต the interrupt priority ที่ใช้โดย the RTOS kernel ของมันเอง.. configMAX_SYSCALL_INTERRUPT_PRIORITY เซ็ต the highest interrupt priority จากซึ่ง interrupt safe FreeRTOS API functions สามารถถูกเรียก.

tha

A full interrupt nesting model ถูกทำให้สำเร็จโดยการเซ็ต configMAX_SYSCALL_INTERRUPT_PRIORITY เหนือ (นั่นคือ, ที่ a higher priority level) กว่า configKERNEL_INTERRUPT_PRIORITY. นี้หมายความว่า the FreeRTOS kernel ไม่ปิดการใช้งาน interrupts อย่างสมบูรณ์, แม้ภายใน critical sections. นอกจากนี้, นี้ถูกทำให้สำเร็จโดยไม่มีข้อเสียของ a segmented kernel architecture. อย่างไรก็ตาม โปรดทราบว่า, certain microcontroller architectures จะ (ใน hardware) ปิดการใช้งาน interrupts เมื่อ a new interrupt ถูกยอมรับ - หมายความว่า interrupts ถูกปิดใช้งานอย่างหลีกเลี่ยงไม่ได้ในช่วงเวลาสั้น ๆ ระหว่าง the hardware ยอมรับ the interrupt, และ the FreeRTOS code จะเปิดการใช้งาน interrupts ใหม่.

Interrupts ที่ไม่เรียก API functions สามารถปฏิบัติที่ priorities เหนือ configMAX_SYSCALL_INTERRUPT_PRIORITY และดังนั้นไม่เคยถูกหน่วงเวลาโดย the RTOS kernel execution

ตัวอย่างเช่น ลองนึกภาพ a hypothetical microcontroller ที่มี 8 interrupt priority levels - 0 เป็น the lowest and 7 เป็น the highest (ดู the special note สำหรับ ARM Cortex-M3 users ในตอนท้ายของส่วนนี้). รูปภาพข้างล่างอธิบายอะไรสามารถและไม่สามารถถูกทำที่แต่ละ priority level หาก the two configuration constants ถูกเซ็ตเป็น 4 and 0 ดังแสดง:

                   

tha

พารามิเตอร์การกำหนดค่าเหล่านี้ช่วยให้การจัดการอินเตอร์รัปต์มีความยืดหยุ่นมาก:

     •  Interrupt handling 'tasks' สามารถถูกเขียนและจัดลำดับความสำคัญตาม task อื่นใดๆใน the system. มี tasks ที่ถูกปลุกโดย an interrupt. The
         interrupt service routine (ISR) มันเองควรถูกเขียนให้สั้นที่สุดเท่าที่มันสามารถเป็นได้ - มันเพียงแค่จับ the data จากนั้นปลุก the high priority handler
         task. The ISR จากนั้นรีเทิร์นโดยตรงลงใน the woken handler task - ดังนั้น interrupt processing จะต่อเนื่องทันเวลา ราวกับว่ามันทำทั้งหมดใน the ISR
         ของตัวเอง. ประโยชน์ของสิ่งนี้คือ interrupts ทั้งหมดยังคงเปิดใช้งานในขณะที่ the handler task ดำเนินการ

     •  Ports ที่จัดให้มีใช้ configMAX_SYSCALL_INTERRUPT_PRIORITY จะก้าวต่อไป - ยอมให้ a fully nested model ที่ interrupts ระหว่าง the RTOS
         kernel interrupt priority and configMAX_SYSCALL_INTERRUPT_PRIORITY สามารถซ้อนกันและทำการเรียก applicable API. Interrupts ที่มี
         priority เหนือ configMAX_SYSCALL_INTERRUPT_PRIORITY ไม่เคยถูกหน่วงเวลาโดย the RTOS kernel activity.

     •  ISR ที่ทำงานอยู่เหนือ the maximum syscall priority จะไม่เคยถูกปิดบังโดย the RTOS kernel ตัวเอง, ดังนั้นการตอบสนองของพวกมันจะไม่ถูกกระทบโดย
         the RTOS kernel functionality. นี้คือแนวคิดสำหรับ interrupts ที่ต้องการ very high temporal accuracy - ตัวอย่างเช่่น interrupts ที่กระทำา motor
         commutation. อย่างไรก็ตาม ISR ดังกล่าวไม่สามารถใช้ the FreeRTOS API functions.

tha

เพื่อใช้ประโยชน์โครงร่างนี้ your application design ต้องยึดมั่นตามกฎต่อไปนี้: interrupt ใดๆที่ใช้ the FreeRTOS API ต้องถูกเซ็ตเป็น the same priority เช่นเดียวกับ the RTOS kernel (ดังที่กำหนดค่าโดย the configKERNEL_INTERRUPT_PRIORITY macro), หรือที่หรือต่ำกว่า configMAX_SYSCALL_INTERRUPT_PRIORITY สำหรับ ports ที่รวมฟังชั่นนี้.

A special note for ARM Cortex-M3 and ARM Cortex-M4 users: โปรดอ่าน the page dedicated to interrupt priority settings on ARM Cortex-M devices.  อย่างน้อยที่สุด โปรดจำไว้ว่า ARM Cortex-M3 cores ใช้ตัวเลข priority numbers ที่ต่ำเพื่อแสดง HIGH priority interrupts, ซึ่งอาจดูเหมือนขัดกับสัญชาตญาณและลืมง่าย!  ถ้าคุณอยากกำหนด an interrupt เป็น a low priority อย่ากำหนดมันเป็น a priority 0 (หรือ low numeric value อื่นๆ) เนื่องจากนี้จะสามารถส่งผลให้ the interrupt จริงๆแล้วมี the highest priority ใน the system - และดังนั้นอาจทำให้ your system ขัดข้องถ้า priority นี้อยู่เหนือ configMAX_SYSCALL_INTERRUPT_PRIORITY.

The lowest priority on a ARM Cortex-M3 core จริงๆแล้วคือ 255 - อย่างไรก็ตาม different ARM Cortex-M3 vendors จัดให้มีใช้จำนวนที่แตกต่างกันของ priority bits และจัดหาให้ library functions ที่คาดว่า priorities ถูกระบุในวิธีที่แตกต่างกัน. ตัวอย่างเช่น, บน the STM32 the lowest priority คุณสามารถระบุใน an ST driver library call จริงๆแล้วคือ 15 - และ the highest priority คุณสามารถระบุคือ 0.

tha

configASSERT

ความหมายของ the configASSERT() macro เป็นเหมือนกับ the standard C assert() macro. การถือสิทธิ์(ยืนยัน)จะถูกทริกถ้า the parameter ทีส่งผ่านลงใน configASSERT() เป็นศูนย์.

configASSERT() ถูกเรียกทั่วทั้ง the FreeRTOS source files เพื่อตรวจสอบว่า the application กำลังใช้ FreeRTOS อย่างไร. ขอแนะนำอย่างยิ่งให้พัฒนา FreeRTOS applications ด้วยการกำหนด configASSERT().

The example definition (แสดงที่ด้านบนของ the file และจำลองแบบด้านล่าง) เรียก vAssertCalled(), ส่งผ่าน in the file name and line number ของ the triggering configASSERT() call (__FILE__ and __LINE__ เป็น standard macros ที่จัดให้มีโดย compilers ส่วนใหญ่). นี้เป็นเพียงสำหรับการสาธิตเท่านั้นเนื่องจาก as vAssertCalled() ไม่ใช่ a FreeRTOS function, configASSERT() สามารถถูกกำหนดเพื่อดำเนินการอะไรก็ได้ตาม the application writer เห็นสมควร.

เป็นเรื่องปกติที่จะกำหนด configASSERT() ในลักษณะที่จะป้องกันไม่ให้แอปพลิเคชันดำเนินการต่อไป. ด้วยเหตุผลสองประการ; การหยุด the application ในจุดที่ the assertion ยอมให้สาเหตุของการถือสิทธิ์ถูกดีบีก, และการดำเนินการผ่านการยืนยัน(ถือสิทธิ์)ที่ทริกเกอร์อาจส่งผลให้เกิดการขัดข้องอยู่ดี.

หมายเหตุ การกำหนด configASSERT() จะเพิ่มทั้ง the application code size และ execution time. เมื่อ the application มีเสถียรภาพค่าโสหุ้ยเพิ่มเติมสามารถเอาออกได้โดยการ commenting out ง่ายๆ the configASSERT() definition ใน FreeRTOSConfig.h.



ถ้ารัน FreeRTOS ภายใต้การควบคุมของ a debugger, ดังนั้น configASSERT() สามารถถูกกำหนดเพียงเพื่อปิดการใช้งาน interrupts และนั่งใน a loop, ดังสาธิตข้างล่าง. ที่จะมีผลของการหยุด the code บน the line ที่ล้มเหลว the assert test - การหยุดชั่วคราว the debugger ดังนั้นจะนำคุณไปยังบรรทัดที่ละเมิดทันที ดังนั้นคุณสามารถเห็นว่าทำใมมันถึงล้มเหลว.