@ -58,7 +58,7 @@
# define portMPU_REGION_BASE_ADDRESS_REG ( *( ( volatile uint32_t * ) 0xe000ed9C ) )
# define portMPU_REGION_ATTRIBUTE_REG ( *( ( volatile uint32_t * ) 0xe000edA0 ) )
# define portMPU_CTRL_REG ( *( ( volatile uint32_t * ) 0xe000ed94 ) )
# define portEXPECTED_MPU_TYPE_VALUE ( 8UL << 8UL ) /* 8 regions, unified. */
# define portEXPECTED_MPU_TYPE_VALUE ( portTOTAL_NUM_REGIONS << 8UL )
# define portMPU_ENABLE ( 0x01UL )
# define portMPU_BACKGROUND_ENABLE ( 1UL << 2UL )
# define portPRIVILEGED_EXECUTION_START_ADDRESS ( 0UL )
@ -321,6 +321,7 @@ __asm void vPortSVCHandler( void )
# else
mrs r0 , psp
# endif
b prvSVCHandler
}
/*-----------------------------------------------------------*/
@ -345,12 +346,15 @@ __asm void prvRestoreContextOfFirstTask( void )
str r3 , [ r2 ] /* Disable MPU. */
ldr r2 , = 0xe000ed9c /* Region Base Address register. */
ldmia r1 ! , {
r4 - r11
} /* Read 4 sets of MPU registers. */
stmia r2 ! , {
r4 - r11
} /* Write 4 sets of MPU registers. */
ldmia r1 ! , { r4 - r11 } /* Read 4 sets of MPU registers [MPU Region # 4 - 7]. */
stmia r2 , { r4 - r11 } /* Write 4 sets of MPU registers [MPU Region # 4 - 7]. */
# if ( portTOTAL_NUM_REGIONS == 16 )
ldmia r1 ! , { r4 - r11 } /* Read 4 sets of MPU registers [MPU Region # 8 - 11]. */
stmia r2 , { r4 - r11 } /* Write 4 sets of MPU registers. [MPU Region # 8 - 11]. */
ldmia r1 ! , { r4 - r11 } /* Read 4 sets of MPU registers [MPU Region # 12 - 15]. */
stmia r2 , { r4 - r11 } /* Write 4 sets of MPU registers. [MPU Region # 12 - 15]. */
# endif /* portTOTAL_NUM_REGIONS == 16. */
ldr r2 , = 0xe000ed94 /* MPU_CTRL register. */
ldr r3 , [ r2 ] /* Read the value of MPU_CTRL. */
@ -358,9 +362,7 @@ __asm void prvRestoreContextOfFirstTask( void )
str r3 , [ r2 ] /* Enable MPU. */
dsb /* Force memory writes before continuing. */
ldmia r0 ! , {
r3 - r11 , r14
} /* Pop the registers that are not automatically saved on exception entry. */
ldmia r0 ! , { r3 - r11 , r14 } /* Pop the registers that are not automatically saved on exception entry. */
msr control , r3
msr psp , r0 /* Restore the task stack pointer. */
mov r0 , # 0
@ -549,19 +551,13 @@ __asm void xPortPendSVHandler( void )
tst r14 , # 0x10 /* Is the task using the FPU context? If so, push high vfp registers. */
it eq
vstmdbeq r0 ! , {
s16 - s31
}
vstmdbeq r0 ! , { s16 - s31 }
mrs r1 , control
stmdb r0 ! , {
r1 , r4 - r11 , r14
} /* Save the remaining registers. */
stmdb r0 ! , { r1 , r4 - r11 , r14 } /* Save the remaining registers. */
str r0 , [ r2 ] /* Save the new top of stack into the first member of the TCB. */
stmdb sp ! , {
r0 , r3
}
stmdb sp ! , { r0 , r3 }
mov r0 , # configMAX_SYSCALL_INTERRUPT_PRIORITY
msr basepri , r0
dsb
@ -569,9 +565,7 @@ __asm void xPortPendSVHandler( void )
bl vTaskSwitchContext
mov r0 , # 0
msr basepri , r0
ldmia sp ! , {
r0 , r3
}
ldmia sp ! , { r0 , r3 }
/* Restore the context. */
ldr r1 , [ r3 ]
ldr r0 , [ r1 ] /* The first item in the TCB is the task top of stack. */
@ -584,12 +578,15 @@ __asm void xPortPendSVHandler( void )
str r3 , [ r2 ] /* Disable MPU. */
ldr r2 , = 0xe000ed9c /* Region Base Address register. */
ldmia r1 ! , {
r4 - r11
} /* Read 4 sets of MPU registers. */
stmia r2 ! , {
r4 - r11
} /* Write 4 sets of MPU registers. */
ldmia r1 ! , { r4 - r11 } /* Read 4 sets of MPU registers [MPU Region # 4 - 7]. */
stmia r2 , { r4 - r11 } /* Write 4 sets of MPU registers [MPU Region # 4 - 7]. */
# if ( portTOTAL_NUM_REGIONS == 16 )
ldmia r1 ! , { r4 - r11 } /* Read 4 sets of MPU registers [MPU Region # 8 - 11]. */
stmia r2 , { r4 - r11 } /* Write 4 sets of MPU registers. [MPU Region # 8 - 11]. */
ldmia r1 ! , { r4 - r11 } /* Read 4 sets of MPU registers [MPU Region # 12 - 15]. */
stmia r2 , { r4 - r11 } /* Write 4 sets of MPU registers. [MPU Region # 12 - 15]. */
# endif /* portTOTAL_NUM_REGIONS == 16. */
ldr r2 , = 0xe000ed94 /* MPU_CTRL register. */
ldr r3 , [ r2 ] /* Read the value of MPU_CTRL. */
@ -597,16 +594,12 @@ __asm void xPortPendSVHandler( void )
str r3 , [ r2 ] /* Enable MPU. */
dsb /* Force memory writes before continuing. */
ldmia r0 ! , {
r3 - r11 , r14
} /* Pop the registers that are not automatically saved on exception entry. */
ldmia r0 ! , { r3 - r11 , r14 } /* Pop the registers that are not automatically saved on exception entry. */
msr control , r3
tst r14 , # 0x10 /* Is the task using the FPU context? If so, pop the high vfp registers too. */
it eq
vldmiaeq r0 ! , {
s16 - s31
}
vldmiaeq r0 ! , { s16 - s31 }
msr psp , r0
bx r14
@ -682,6 +675,12 @@ static void prvSetupMPU( void )
extern uint32_t __privileged_data_start__ ;
extern uint32_t __privileged_data_end__ ;
/* The only permitted number of regions are 8 or 16. */
configASSERT ( ( portTOTAL_NUM_REGIONS = = 8 ) | | ( portTOTAL_NUM_REGIONS = = 16 ) ) ;
/* Ensure that the configTOTAL_MPU_REGIONS is configured correctly. */
configASSERT ( portMPU_TYPE_REG = = portEXPECTED_MPU_TYPE_VALUE ) ;
/* Check the expected MPU is present. */
if ( portMPU_TYPE_REG = = portEXPECTED_MPU_TYPE_VALUE )
{