FreeRTOS API FreeRTOS-MPU Specific

Started by tha, February 04, 2022, 06:26:18 AM

Previous topic - Next topic

tha

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

xTaskCreateRestricted
[FreeRTOS-MPU Specific]

task. h

BaseType_t xTaskCreateRestricted(
                            TaskParameters_t *pxTaskDefinition,
                            TaskHandle_t *pxCreatedTask );


สร้าง a new Memory Protection Unit (MPU) restricted task และเพิ่มมันไปยังรายการของ tasks ที่พร้อมที่จะรัน.

xTaskCreateRestricted() ถูกมุ่งหมายสำหรับใช้กับ FreeRTOS-MPU, the demo applications ซึ่งบรรจุตัวอย่างที่ครอบคลุมและจัดทำเป็นเอกสารของ xTaskCreateRestricted() ที่กำลังถูกใช้.

Parameters:

     pxTaskDefinition      ตัวชี้ไปยัง a structure ที่กำหนด the task. The structure ถูกอธิบายในหน้านี้.

     pxCreatedTask         ใช้ส่งผ่านกลับ a handle ซึ่ง the created task สามารถถูกอ้างอิง.

Returns:

     pdPASS ถ้า the task ถูกสร้างสำเร็จและเพิ่มไปยัง a ready list, ถ้าเป็นอย่างอื่น an error code ที่กำหนดใน the file projdefs.h

tha

Tasks ที่รวม MPU support ต้องการ parameters เพื่อสร้างมากยิ่งกว่าเหล่านั้นที่ไม่. การส่งผ่านพารามิเตอร์แต่ละตัวไปยัง xTaskCreateRestricted() แต่ละรายการจะไม่สะดวก ดังนั้นแทนด้วย the structure TaskParameters_t ถูกใช้เพื่ออนุญาตให้ค่าพารามิเตอร์ถูกกำหนดแบบคงที่ในเวลาคอมไพล์ The structure ถูกกำหนดใน task.h เป็น:



tha

ต่อไปนี้คือคำอธิบายของแต่ละ structure member:

    •  pvTaskCode to uxPriority

       สมาชิกเหล่านี้เหมือนกันทุกประการกับ the parameters to xTaskCreate() ของ the same name.  โดยเฉพาะอย่างยิ่ง uxPriority
       ถูกใช้เพื่อเซ็ตทั้ง the priority of the task และ the mode ซึ่ง the task จะปฏิบัติ. ตัวอย่างเช่น, เพื่อสร้าง a User mode task ที่
       priority 2 เซ็ตง่ายๆ uxPriority เป็น 2, เพื่อสร้าง a Privileged mode task ที่ priority 2 เซ็ต uxPriority เป็น                       
       ( 2 | portPRIVILEGE_BIT ).

tha

     •  puxStackBuffer

         แต่ละครั้งที่ a task ถูกสวิทช์ใน the MPU จะถูกกำหนดค่าใหม่แบบไดนามิคเเพื่อกำหนด a region ที่จัดให้มี the task อ่านและ
         เขียนเข้าถึงไปยัง stack ของตัวเอง. MPU regions ต้องเป็นไปตามข้อจำกัดจำนวนหนึ่ง - โดยเฉพาะอย่างยิ่ง, ขนาดและการจัด
         ตำแหน่งของแต่ละ region ทั้งคู่ต้องเท่ากับค่ากำลังสองเดียวกัน.

         Standard FreeRTOS ports ใช้ pvPortMalloc() เพื่อจัดสรร a new stacks แต่ละครั้งที่ a task ถูกสร้าง. การจัดให้มี a
         pvPortMalloc() implementation ที่ดูแล the MPU data alignment requirements จะเป็นไปได้ แต่จะซับซ้อนและไม่มี
         ประสิทธิภาพในการใช้ RAM ด้วย เพื่อขจัดความจำเป็นสำหรับความซับซ้อนนี้  FreeRTOS-MPU ยอมให้ stacks ถูกประกาศแบบคงที่
         ที่เวลาคอมไพล์. นี้ยอมให้ the alignment ถูกจัดการโดยใช้ compiler extensions และ RAM usage efficiency ถูกจัดการโดย
         the linker. ตัวอย่างเช่น, ถ้าใช้ GCC a stack สามารถถูกประกาศและจัดวางตำแหน่งอย่างถูกต้องโดยใช้โค้ดต่อไปนี้:

                 char cTaskStack[ 1024 ] __attribute__((aligned(1024));

         puxStackBuffer ปกติจะถูกเซ็ตเป็น the address of the statically declared stack. อีกทางเลือกหนึ่ง puxStackBuffer
         สามารถถูกเซ็ตเป็น NULL - ซึ่งในกรณีนี้ pvPortMallocAligned() จะถูกเรียกเพื่อจัดสรร the task stack และมันเป็น the
         application writers responsibility ต้องจัดให้มี an implementation of pvPortMallocAligned() ที่ตรงตาม the
         alignment requirements of the MPU.

tha

     •  xMemoryRegions

         xRegions เป็น an array of MemoryRegion_t structures, ซึ่งแต่ละส่วนจะกำหนด a single user definable memory
         region สำหรับใช้โดย the task ที่กำลังถูกสร้าง. The ARM Cortex-M3 FreeRTOS-MPU port กำหนด
         portNUM_CONFIGURABLE_REGIONS เป็น 3.

         The pvBaseAddress and ulLengthInBytes members เป็นการอธิบายตัวเองเป็น the start of the memory region และ
         the length of the memory region ตามลำดับ. ulParameters กำหนดวิธีที่ the task ถูกยอมให้เข้าถึง the memory
         region และสามารถใช้ the bitwise OR ของค่าต่อไปนี้:

                portMPU_REGION_READ_WRITE
                portMPU_REGION_PRIVILEGED_READ_ONLY
                portMPU_REGION_READ_ONLY
                portMPU_REGION_PRIVILEGED_READ_WRITE
                portMPU_REGION_CACHEABLE_BUFFERABLE
                portMPU_REGION_EXECUTE_NEVER

         ตัวอย่างการใช้งาน (โปรดอ้างอิงถึงแอปพลิเคชันสาธิต FreeRTOS-MPU สำหรับตัวอย่างที่สมบูรณ์และครอบคลุมยิ่งขึ้น):

(ตัวอย่างโค้ดดูในลิ้งค์เอานะครับ)

tha

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

vTaskAllocateMPURegions
[FreeRTOS-MPU Specific]

task. h

void vTaskAllocateMPURegions(
               TaskHandle_t xTaskToModify,
               const MemoryRegion_t * const xRegions );


Memory regions ถูกกำหนดให้กับ a restricted task เมื่อ the task ถูกสร้างโดยใช้การเรียก xTaskCreateRestricted(). The regions ดังนั้นสามารถถูกแก้ไขหรือกำหนดใหม่ ณ เวลารันโดยใช้ vTaskAllocateMPURegions().

vTaskAllocateMPURegions() ถูกมุ่งหมายสำหรับใช้กับ FreeRTOS-MPU, the demo applications ซึ่งบรรจุตัวอย่างของ vTaskAllocateMPURegions() ที่กำลังถูกใช้.

Parameters:

     xTask          The handle of the task ที่กำลังถูกอัฟเดต.

     xRegions     ตัวชี้ไปยัง an array of MemoryRegion_t structures, ซึ่งแต่ละตัวบรรจุ a single new memory region
                           definitions. The array ควรถูกกำหนดขนาดโดยใช้ the constant
                           portNUM_CONFIGURABLE_REGIONS, ซึ่งบน the ARM Cortex-M3 ถูกเซ็ตเป็น 3.

tha

MemoryRegion_t ถูกกำหนดใน task.h เป็น:

typedef struct xMEMORY_REGION
{
    void *pvBaseAddress;
    unsigned long ulLengthInBytes;
    unsigned long ulParameters;
} MemoryRegion_t;


The pvBaseAddress and ulLengthInBytes members เป็นการอธิบายตัวเองเป็น the start of the memory region และ the length of the memory region ตามลำดับ. สิ่งสำคัญคือต้องสังเกตว่า MPU regions ต้องเป็นไปตามข้อจำกัดหลายประการ โดยเฉพาะอย่างยิ่ง ขนาดและการจัดตำแหน่งของแต่ละ region ทั้งคู่จะต้องเท่ากับค่ากำลังสองเดียวกัน.

ulParameters กำหนดวิธีที่ the task ถูกยอมให้เข้าถึง the memory region และสามารถใช้ the bitwise OR ของค่าต่อไปนี้:

    portMPU_REGION_READ_WRITE
    portMPU_REGION_PRIVILEGED_READ_ONLY
    portMPU_REGION_READ_ONLY
    portMPU_REGION_PRIVILEGED_READ_WRITE
    portMPU_REGION_CACHEABLE_BUFFERABLE
    portMPU_REGION_EXECUTE_NEVER

ตัวอย่างการใช้งาน (โปรดอ้างอิงถึงแอปพลิเคชันสาธิต FreeRTOS-MPU สำหรับตัวอย่างที่สมบูรณ์และครอบคลุมยิ่งขึ้น):

(ตัวอย่างโค้ดดูในลิ้งค์เอานะครับ)