Skip to content

Commit

Permalink
Remove un-neccsary #if 1, and then re-order the MPU Regions to make t…
Browse files Browse the repository at this point in the history
…he diff better. Fix incorrect comment in portasm.c, fix an incorrect variable name in the port.c file
  • Loading branch information
Skptak committed Mar 1, 2024
1 parent 1541593 commit 7ba1e3e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
22 changes: 11 additions & 11 deletions portable/GCC/ARM_CM23_NTZ/non_secure/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,14 @@ static void prvTaskExitError( void );
#if ( configENABLE_MPU == 1 )

/**
* @brief Extract MPU region's access permissions from the Region Base Address
* Register (RBAR) value.
* @brief Extract MPU region's access permissions from the Region Attribute and Size
* Register (RASR) value.
*
* @param ulRBARValue RBAR value for the MPU region.
* @param ulRASRValue RASR value for the MPU region.
*
* @return uint32_t Access permissions.
*/
static uint32_t prvGetRegionAccessPermissions( uint32_t ulRBARValue ) PRIVILEGED_FUNCTION;
static uint32_t prvGetRegionAccessPermissions( uint32_t ulRASRValue ) PRIVILEGED_FUNCTION;
#endif /* configENABLE_MPU */

#if ( configENABLE_MPU == 1 )
Expand Down Expand Up @@ -832,16 +832,16 @@ static void prvTaskExitError( void )
/*-----------------------------------------------------------*/

#if ( configENABLE_MPU == 1 )
static uint32_t prvGetRegionAccessPermissions( uint32_t ulRBARValue ) /* PRIVILEGED_FUNCTION */
static uint32_t prvGetRegionAccessPermissions( uint32_t ulRASRValue ) /* PRIVILEGED_FUNCTION */
{
uint32_t ulAccessPermissions = 0;

if( ( ulRBARValue & portMPU_RASR_ACCESS_PERMISSIONS_MASK ) == portMPU_REGION_READ_ONLY )
if( ( ulRASRValue & portMPU_RASR_ACCESS_PERMISSIONS_MASK ) == portMPU_REGION_READ_ONLY )
{
ulAccessPermissions = tskMPU_READ_PERMISSION;
}

if( ( ulRBARValue & portMPU_RASR_ACCESS_PERMISSIONS_MASK ) == portMPU_REGION_READ_WRITE )
if( ( ulRASRValue & portMPU_RASR_ACCESS_PERMISSIONS_MASK ) == portMPU_REGION_READ_WRITE )
{
ulAccessPermissions = ( tskMPU_READ_PERMISSION | tskMPU_WRITE_PERMISSION );
}
Expand Down Expand Up @@ -1785,7 +1785,7 @@ void vPortEndScheduler( void ) /* PRIVILEGED_FUNCTION */
void vPortStoreTaskMPUSettings( xMPU_SETTINGS * xMPUSettings,
const struct xMEMORY_REGION * const xRegions,
StackType_t * pxBottomOfStack,
uint32_t ulStackDepth )
configSTACK_DEPTH_TYPE uxStackDepth )
{
#if defined( __ARMCC_VERSION )

Expand All @@ -1801,7 +1801,7 @@ void vPortEndScheduler( void ) /* PRIVILEGED_FUNCTION */
extern uint32_t __SRAM_segment_end__[];
extern uint32_t __privileged_sram_start__[];
extern uint32_t __privileged_sram_end__[];
#endif /* if defined( __ARMCC_VERSION ) */
#endif /* defined( __ARMCC_VERSION ) */

int32_t lIndex;
uint32_t ul;
Expand Down Expand Up @@ -1835,7 +1835,7 @@ void vPortEndScheduler( void ) /* PRIVILEGED_FUNCTION */
* which case the stack region parameters will be valid. At all other
* times the stack parameters will not be valid and it is assumed that the
* stack region has already been configured. */
if( ulStackDepth > 0 )
if( uxStackDepth > 0 )
{
/* Define the region that allows access to the stack. */
xMPUSettings->xRegionsSettings[ 0 ].ulRBAR =
Expand All @@ -1846,7 +1846,7 @@ void vPortEndScheduler( void ) /* PRIVILEGED_FUNCTION */
xMPUSettings->xRegionsSettings[ 0 ].ulRASR =
( portMPU_REGION_READ_WRITE ) |
( portMPU_REGION_EXECUTE_NEVER ) |
( prvGetMPURegionSizeSetting( ulStackDepth * ( uint32_t ) sizeof( StackType_t ) ) ) |
( prvGetMPURegionSizeSetting( uxStackDepth * ( uint32_t ) sizeof( StackType_t ) ) ) |
( ( configTEX_S_C_B_SRAM & portMPU_RASR_TEX_S_C_B_MASK ) << portMPU_RASR_TEX_S_C_B_LOCATION ) |
( portMPU_REGION_ENABLE );

Expand Down
20 changes: 9 additions & 11 deletions portable/GCC/ARM_CM23_NTZ/non_secure/portasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,12 @@
" str r5, [r2] \n" /* r2 = 0xe000ed9c [Location of RBAR]. */
" str r6, [r3] \n" /* r3 = 0xe000eda0 [Location of RASR]. */
" \n"
#if 1
" ldr r1, =0xe000ed94 \n" /* MPU_CTRL register. */
" ldr r2, [r1] \n" /* Read the value of MPU_CTRL. */
" movs r3, #1 \n" /* r3 = 1. */
" orrs r2, r3 \n" /* r2 = r2 | r3 i.e. Set the bit 0 in r2. */
" str r2, [r1] \n" /* Enable MPU. */
" dsb \n" /* Force memory writes before continuing. */
#endif
" \n"
" restore_context_first_task: \n"
" ldr r2, =pxCurrentTCB \n" /* r2 = &pxCurrentTCB. */
Expand Down Expand Up @@ -334,11 +332,11 @@ void vClearInterruptMask( __attribute__( ( unused ) ) uint32_t ulMask ) /* __att
" \n"
" program_mpu: \n"
" dmb \n" /* Complete outstanding transfers before disabling MPU. */
" ldr r1, =0xe000ed94 \n" /* MPU_CTRL register. */
" ldr r2, [r1] \n" /* Read the value of MPU_CTRL. */
" movs r3, #0x1 \n"
" bics r2, r2, r3 \n" /* r2 = r2 & ~1 i.e. Clear the bit 0 in r2. */
" str r2, [r1] \n" /* Disable MPU */
" ldr r1, =0xe000ed94 \n" /* r1 = 0xe000ed94 [Location of MPU_CTRL]. */
" ldr r2, [r1] \n" /* Read the value of MPU_CTRL. */
" movs r3, #0x1 \n" /* r3 = 1. */
" bics r2, r3 \n" /* r2 = r2 & ~1 i.e. Clear the bit 0 in r2. */
" str r2, [r1] \n" /* Disable MPU */
" \n"
" ldr r2, =0xe000ed9c \n" /* r2 = 0xe000ed9c [Location of RBAR]. */
" ldr r3, =0xe000eda0 \n" /* r3 = 0xe000eda0 [Location of RASR]. */
Expand All @@ -364,8 +362,8 @@ void vClearInterruptMask( __attribute__( ( unused ) ) uint32_t ulMask ) /* __att
" str r6, [r3] \n" /* r3 = 0xe000eda0 [Location of RASR]. */
" \n"
" ldr r2, [r1] \n" /* Read the value of MPU_CTRL. */
" movs r3, #0x1 \n"
" orrs r2, r2, r3 \n" /* r2 = r2 & ~1 i.e. Clear the bit 0 in r2. */
" movs r3, #1 \n" /* r3 = 1. */
" orrs r2, r3 \n" /* r2 = r2 | r3 i.e. Set the bit 0 in r2. */
" str r2, [r1] \n" /* Enable MPU. */
" dsb \n" /* Force memory writes before continuing. */
" \n"
Expand Down Expand Up @@ -493,10 +491,10 @@ void vClearInterruptMask( __attribute__( ( unused ) ) uint32_t ulMask ) /* __att
" ldr r3, [r0, #24] \n"
" subs r3, #2 \n"
" ldrb r2, [r3, #0] \n"
" ldr r3, =%0 \n"
" ldr r3, =%0 \n"
" cmp r2, r3 \n"
" blt system_call_enter \n"
" ldr r3, =%1 \n"
" ldr r3, =%1 \n"
" cmp r2, r3 \n"
" beq system_call_exit \n"
" b vPortSVCHandler_C \n"
Expand Down
3 changes: 2 additions & 1 deletion portable/GCC/ARM_CM23_NTZ/non_secure/portmacrocommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P
/* MPU regions. */
#define portPRIVILEGED_FLASH_REGION ( 6UL )
#define portUNPRIVILEGED_FLASH_REGION ( 5UL )
#define portLAST_CONFIGURABLE_REGION ( 3UL )
#define portUNPRIVILEGED_SYSCALLS_REGION ( 2UL )
#define portPRIVILEGED_RAM_REGION ( 7UL )
#define portSTACK_REGION ( 4UL )
#define portFIRST_CONFIGURABLE_REGION ( 0UL )
#define portLAST_CONFIGURABLE_REGION ( 3UL )
#define portNUM_CONFIGURABLE_REGIONS ( ( portLAST_CONFIGURABLE_REGION - portFIRST_CONFIGURABLE_REGION ) + 1 )
#define portTOTAL_NUM_REGIONS ( portNUM_CONFIGURABLE_REGIONS + 1 ) /* Plus one to make space for the stack region. */

Expand Down

0 comments on commit 7ba1e3e

Please sign in to comment.