![Segger embOS-MPU Скачать руководство пользователя страница 49](http://html1.mh-extra.com/html/segger/embos-mpu/embos-mpu_manual_1233804049.webp)
49
CHAPTER 9
Cache maintenance
9.5.1 Modifying memory attributes of default task regions
A newly created unprivileged task has per default access to the following memory regions
only with the memory attribute
OS_ARM_CACHEMODE_STRONGLY_ORDERED
:
Region
Permissions
Attributes
ROM
OS_MPU_READONLY
,
OS_MPU_EXECUTION_ALLOWED
OS_ARM_CACHEMODE_STRONGLY_ORDERED
RAM
OS_MPU_READONLY
,
OS_MPU_EXECUTION_ALLOWED
OS_ARM_CACHEMODE_STRONGLY_ORDERED
Task
stack
OS_MPU_READWRITE
,
OS_MPU_EXECUTION_ALLOWED
OS_ARM_CACHEMODE_STRONGLY_ORDERED
The default memory attributes can be changed by adding additional regions with different
memory attributes.
Memory regions with higher index have priority over regions which were defined earlier.
Example:
void
HPTask(
void
) {
//
// Switch cache settings for RAM region to write back
//
OS_MPU_AddRegion(&TCBHP, RAM_START_ADDR, RAM_SIZE, OS_MPU_READONLY,
OS_ARM_CACHEMODE_WRITE_BACK_ALLOC);
OS_MPU_SwitchToUnprivState();
while
(
1
) {
DoSomething()
OS_TASK_Delay(
10
),
}
}
9.6 Cache maintenance
When a task context is extended with
OS_MPU_ExtendTaskContext()
, embOS saves and
restores the MPU and cache settings for that task with every context switch. Since the RTOS
itself or another task will run with different cache settings, the instruction and data caches
need to be cleaned and invalidated. Please be aware that cache maintenance operations
take some time, which also increases the context switch time. The actual context switch
time depends on many factors, e.g. the number of cache lines that must be written back to
the memory. Since embOS manages the cache settings during task switches, please note
that caches may not be enabled or disabled during the application’s execution.
9.7 Changing memory attributes for privileged tasks
While
OS_MPU_AddRegion()
can be used to change e.g. cache settings for unprivileged
tasks, no embOS API exists to set cache settings for privileged tasks. Privileged tasks may
program the MPU directly and must then use
OS_MPU_ExtendTaskContext()
to save and
restore the MPU register contents during context switches. Please note the MPU is not
enabled before this task was scheduled once since the MPU is disabled/enabled by the
extented task context and must not be enabled by the user application.
Example:
void
PrivTask(
void
) {
OS_MPU_ExtendTaskContext();
SetMPURegsiter();
// Program MPU/cache settings
OS_Delay(
1
);
// Force a re-schedule which enables the MPU
while
(
1
) {
embOS-MPU for Cortex-M and IAR
© 2010-2020 SEGGER Microcontroller GmbH
Содержание embOS-MPU
Страница 4: ...4 embOS MPU for Cortex M and IAR 2010 2020 SEGGER Microcontroller GmbH ...
Страница 6: ...6 embOS MPU for Cortex M and IAR 2010 2020 SEGGER Microcontroller GmbH ...
Страница 21: ...Chapter 4 CPU and compiler specifics embOS MPU for Cortex M and IAR 2010 2020 SEGGER Microcontroller GmbH ...
Страница 44: ...Chapter 8 VFP support embOS MPU for Cortex M and IAR 2010 2020 SEGGER Microcontroller GmbH ...