下载 FreeRTOS
 

出色的 RTOS & 嵌入式软件

内核
最新资讯
简化任何设备的身份验证云连接。
利用 CoAP 设计节能型云连接 IoT 解决方案。
11.0.0 版 FreeRTOS 内核简介:
FreeRTOS 路线图和代码贡献流程。
使用 FreeRTOS 实现 OPC-UA over TSN。

vTaskAllocateMPURegions
[FreeRTOS-MPU 特定]

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

调用 xTaskCreateRestricted() 创建任务时, 将内存区域分配给受限制的任务。 然后,可以 在运行时使用 vTaskAllocateMPURegions() 修改或重新定义区域。

vTaskAllocateMPURegions() 旨在与 FreeRTOS-MPU 配合使用, 其演示应用程序包含 正在使用的 vTaskAllocateMPURegions() 示例。

参数:
xTask 
正在更新的任务的句柄。
xRegions 指向 MemoryRegion_t 结构体数组的指针, 每个结构体都包含一个新的内存区域定义。 应使用常量 portNUM_configurable_region 确定数组的大小, 在 ARM Cortex-M3 上,该常量设置为 3。

MemoryRegion_t 在 task.h 中定义为:



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


PvBaseAddress 和 ulLengthInBytes 成员分别作为 内存区域的开始和内存区域的长度。 必须指出,MPU 必须满足一些约束条件, 特别是每个区域的大小和对齐方式必须都等于两个值的同底数幂。

ulParameters 定义任务 并且可以采用以下值中的 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 演示应用程序 了解更完整、更全面的示例):

/* Define an array that the task will both read from and write to. Make sure the size and alignment are appropriate for an MPU region (note this uses GCC syntax). */ static unsigned char ucOneKByte[ 1024 ] __attribute__((align( 1024 ))); /* Define an array of MemoryRegion_t structures that configures an MPU region allowing read/write access for 1024 bytes starting at the beginning of the ucOneKByte array. The other two of the maximum 3 definable regions are unused so set to zero. */ static const MemoryRegion_t xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] = { /* Base address Length Parameters */ { ucOneKByte, 1024, portMPU_REGION_READ_WRITE }, { 0, 0, 0 }, { 0, 0, 0 } }; void vATask( void *pvParameters ) { /* This task was created such that it has access to certain regions of memory as defined by the MPU configuration. At some point it is desired that these MPU regions are replaced with that defined in the xAltRegions const struct above. Use a call to vTaskAllocateMPURegions() for this purpose. NULL is used as the task handle to indicate that this function should modify the MPU regions of the calling task. */ vTaskAllocateMPURegions( NULL, xAltRegions ); /* Now the task can continue its function, but from this point on can only access its stack and the ucOneKByte array (unless any other statically defined or shared regions have been declared elsewhere). */ }





Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.