FreeRTOS

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

Previous topic - Next topic

tha

configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS

configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS ถูกใช้เฉพาะโดย FreeRTOS MPU.

ถ้า configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS ถูกเซ็ตเป็น 1 ดังนั้น the application writer ต้องจัดให้มี a header file ที่เรียกว่า "application_defined_privileged_functions.h", ซึ่งเป็นฟังชั่นที่ the application writer จำเป็นต้องปฏิบัติใน privileged mode สามารถถูกจัดให้มีใช้. โปรดทราบว่า, แม้จะมี a .h extension, the header file ควรบรรจุ the implementation of the C functions, ไม่ใช่เพียง the functions' prototypes

ฟังชั่นที่จัดให้มีใช้ใน "application_defined_privileged_functions.h" ต้องบันทึกและกู้คืน the processor's privilege state โดยใช้ the prvRaisePrivilege() function and portRESET_PRIVILEGE() macro ตามลำดับ. ตัวอย่างเช่น, ถ้า a library ที่จัดให้มี print function เข้าถึง RAM ที่อยู่ภายนอกการควบคุมของ the application writer, และดังนั้นไม่สามารถถูกจัดสรรให้กับ a memory ที่ป้องกัน user mode task, ดังนั้น the print function สามารถถูกห่อหุ้มใน a privileged function โดยใช้โค้ดต่อไปนี้:



เทคนิคนี้ควรใช้ในระหว่างการพัฒนาเท่านั้น ไม่ควรปรับใช้ เนื่องจากจะหลีกเลี่ยง the memory protection.

tha

configTOTAL_MPU_REGIONS

FreeRTOS MPU (Memory Protection Unit) ports สำหรับ ARM Cortex-M4 microcontrollers support devices ที่มี 16 MPU regions. เซ็ต configTOTAL_MPU_REGIONS เป็น 16 สำหรับ devices ที่มี 16 MPU regions. ถ้าทิ้งไว้ไม่กำหนด, มันจะมีค่าเริ่มต้นเป็น 8.

configTEX_S_C_B_FLASH

The TEX, Shareable (S), Cacheable (C) and Bufferable (B) bits กำหนด the memory type, และที่จำเป็น the cacheable and shareable properties(คุณสมบัติ) of an MPU region. configTEX_S_C_B_FLASH ยอมให้ application writers ข้ามผ่านค่าเริ่มต้นสำหรับ the for TEX, Shareable (S), Cacheable (C) and Bufferable (B) bits สำหรับ the MPU region ครอบคุม Flash. ถ้าทิ้งไว้ไม่กำหนด, มันจะมีค่าเริ่มต้นเป็น 0x07UL ซึ่งหมายความว่า TEX=000, S=1, C=1, B=1.

tha

configTEX_S_C_B_SRAM

The TEX, Shareable (S), Cacheable (C) and Bufferable (B) bits กำหนด the memory type, และที่จำเป็น the cacheable and shareable properties(คุณสมบัติ) of an MPU region. configTEX_S_C_B_SRAM ยอมให้ application writers ข้ามผ่านค่าเริ่มต้นสำหรับ the for TEX, Shareable (S), Cacheable (C) and Bufferable (B) bits สำหรับ the MPU region ครอบคุม RAM. ถ้าทิ้งไว้ไม่กำหนด, มันจะมีค่าเริ่มต้นเป็น 0x07UL ซึ่งหมายความว่า TEX=000, S=1, C=1, B=1.


tha

configENFORCE_SYSTEM_CALLS_FROM_KERNEL_ONLY

configENFORCE_SYSTEM_CALLS_FROM_KERNEL_ONLY สามารถถูกกำหนดให้เป็น 1 เพื่อป้องกัน any privilege escalations ที่กำเนิดมาจากภายนอกของ the kernel code (นอกเหนือจาก escalations ที่กระทำโดย the hardware เองเมื่อ an interrupt ถูกเข้าสู่). เมื่อ configENFORCE_SYSTEM_CALLS_FROM_KERNEL_ONLY ถูกเซ็ตเป็น 1 ใน FreeRTOSConfig.h, variables __syscalls_flash_start__ and __syscalls_flash_end__ จำเป็นต้องถูกนำเข้าจาก linker script เพื่อแสดง the start and end addresses of the system calls memory ตามลำดับ. ขอแนะนำให้กำหนดมันเป็น 1 เพื่อความปลอดภัยสูงสุด.

tha

secureconfigMAX_SECURE_CONTEXTS

ARMv8-M secure side ports เท่านั้น.

Tasks ที่เรียกใช้ secure functions จาก the non-secure side of an ARMv8-M MCU (ARM Cortex-M23, Cortex-M33 and Cortex-M55) มีสอง contexts – หนึ่งบน the non-secure side และหนึ่งบน the secure-side. ก่อน FreeRTOS v10.4.5, ARMv8-M secure-side ports ที่จัดสรร the structures ที่อ้างถึง secure-side contexts ในขณะทำงาน. จาก FreeRTOS V10.4.5 the structures จะได้รับการจัดสรรแบบคงที่ ณ compile time. secureconfigMAX_SECURE_CONTEXTS เซ็ตจำนวนของ statically allocated secure contexts. secureconfigMAX_SECURE_CONTEXTS ค่าเริ่มต้นเป็น 8 ถ้าทิ้งไว้ไม่กำหนด.  Applications ที่ใช้เฉพาะ FreeRTOS code บน the non-secure side of ARMv8-M microcontrollers, อย่างเช่นเหล่านั้นที่รัน third-party code บน the secure-side, ไม่ต้องการค่าคงที่นี้.

tha

INCLUDE Parameters

The macros ที่เริ่มด้วย 'INCLUDE' ยอมให้ส่วนประกอบเหล่านั้นของ the real time kernel ที่ไม่เป็นประโยชน์ต่อ your application ถูกเอาออกจาก your build. นี้ทำให้แน่ใจว่า the RTOS จะไม่ใช้ ROM or RAM ใดๆมากกว่าความจำเป็นสำหรับ your particular embedded application.

แต่ละ macro จะมีรูปแบบ ...

INCLUDE_FunctionName

... โดยที่ FunctionName แสดง the API function (หรือชุดของ functions) ที่สามารถมีทางเลือกให้ถูกเอาออกได้. เพื่อรวม the API function ตั้งค่า the macro เป็น 1, เพื่อเอาออก the function ตั้งค่า the macro เป็น 0. ตัวอย่างเช่น, เพื่อรวม the vTaskDelete() API function ใช้:

#define INCLUDE_vTaskDelete    1

เพื่อเอา vTaskDelete() ออกจาก your build ใช้:

#define INCLUDE_vTaskDelete    0

tha

https://www.freertos.org/Static_Vs_Dynamic_Memory_Allocation.html

Static Vs Dynamic Memory Allocation

Introduction

FreeRTOS versions ก่อนถึง V9.0.0 จัดสรร the memory ที่ใช้โดย the RTOS objects ที่แสดงรายการข้างล่างจาก the special FreeRTOS heap. FreeRTOS V9.0.0 และขึ้นไปให้ the application writer มีความสามารถจัดให้มี the memory ของพวกมันเองแทน, ยอมให้ the following objects มีทางเลือกถูกสร้างโดยไม่มี memory ใดๆถูกจัดสรรแบบไดนามิก:

     •  Tasks
     •  Software Timers
     •  Queues
     •  Event Groups
     •  Binary Semaphores
     •  Counting Semaphores
     •  Recursive Semaphores
     •  Mutexes

ไม่ว่าจะชอบมากกว่าที่จะใช้ static or dynamic memory allocation ขึ้นอยู่กับ the application, และความพึงพอใจของ the application writer. ทั้งสองวิธีมีข้อดีและข้อเสีย และทั้งสองวิธีสามารถถูกใช้ได้ภายในแอปพลิเคชัน RTOS เดียวกัน.

ตัวอย่าง Win32 อย่างง่ายที่อยู่ใน the FreeRTOS/Source/WIN32-MSVC-Static-Allocation-Only directory ของ the main FreeRTOS download สาธิตวิธีที่ a FreeRTOS application สามารถถูกสร้างโดยไม่มีการรวมใดๆของ the FreeRTOS heap implementations ใน a project.

tha

Creating an RTOS Object Using Dynamically Allocated RAM

การสร้าง RTOS objects แบบไดนามิกมีประโยชน์ในด้านความเรียบง่ายมากขึ้นและศักยภาพทำให้น้อยสุด the application's maximum RAM usage:

     •  function parameters ถูกต้องการน้อยลงเมื่อ an object ถูกสร้าง

     •  The memory allocation เกิดขึ้นโดยอัตโนมัติ, ภายใน the RTOS API functions.

     •  The application writer ไม่จำเป็นต้องกังวลเกี่ยวกับพวกมันเหล่านั้นด้วยการจัดสรรหน่วยความจำตัวพวกมันเอง

     •  The RAM ที่ใช้โดย an RTOS object สามารถถูกใช้ใหม่ถ้า the object ถูกลบ, มีศักยภาพในการลด the application's maximum RAM footprint.

     •  RTOS API functions ถูกจัดให้มี return information บนการใช้ heap, ยอมให้ the heap size ถูกจัดให้เหมาะสม.

     •  The memory allocation scheme ที่ใช้สามารถถูกเลือกให้เหมาะที่สุดกับ the application, ไม่ว่าจะเป็น heap_1.c เพื่อความเรียบง่ายและเชิงกำหนดมักจะ
         จำเป็นสำหรับ safety critical applications, heap_4.c สำหรับ fragmentation protection, heap_5.c เพื่อแบ่ง the heap ข้ามเป็นหลาย RAM
         regions, หรือ an allocation scheme ที่จัดให้มีโดย the application writer พวกเขาเหล่านั้น.

The following API functions, ซึ่งมีให้ใช้ประโยชน์ถ้า configSUPPORT_DYNAMIC_ALLOCATION ถูกเซ็ตเป็น 1 หรือถูกทิ้งไว้ไม่กำหนด, สร้าง RTOS objects โดยใช้ dynamically allocated RAM:

     •  xTaskCreate()
     •  xQueueCreate()
     •  xTimerCreate()
     •  xEventGroupCreate()
     •  xSemaphoreCreateBinary()
     •  xSemaphoreCreateCounting()
     •  xSemaphoreCreateMutex()
     •  xSemaphoreCreateRecursiveMutex()