Skip to content

Commit 56a51ff

Browse files
committed
Formatting changes, move function declarations around to make the file flow a bit better
1 parent ec1332e commit 56a51ff

File tree

4 files changed

+246
-257
lines changed

4 files changed

+246
-257
lines changed

portable/GCC/ARM_CRx_MPU/port.c

Lines changed: 123 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -202,29 +202,29 @@ PRIVILEGED_FUNCTION static BaseType_t prvTaskCanAccessRegion(
202202
ulIndex--;
203203

204204
/* Next the General Purpose Registers */
205-
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x12121212; /* R12 */
205+
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x12121212; /* R12 */
206206
ulIndex--;
207-
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x11111111; /* R11 */
207+
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x11111111; /* R11 */
208208
ulIndex--;
209-
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x10101010; /* R10 */
209+
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x10101010; /* R10 */
210210
ulIndex--;
211-
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x09090909; /* R9 */
211+
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x09090909; /* R9 */
212212
ulIndex--;
213-
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x08080808; /* R8 */
213+
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x08080808; /* R8 */
214214
ulIndex--;
215-
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x07070707; /* R7 */
215+
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x07070707; /* R7 */
216216
ulIndex--;
217-
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x06060606; /* R6 */
217+
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x06060606; /* R6 */
218218
ulIndex--;
219-
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x05050505; /* R5 */
219+
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x05050505; /* R5 */
220220
ulIndex--;
221-
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x04040404; /* R4 */
221+
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x04040404; /* R4 */
222222
ulIndex--;
223-
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x03030303; /* R3 */
223+
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x03030303; /* R3 */
224224
ulIndex--;
225-
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x02020202; /* R2 */
225+
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x02020202; /* R2 */
226226
ulIndex--;
227-
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x01010101; /* R1 */
227+
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) 0x01010101; /* R1 */
228228
ulIndex--;
229229
xMPUSettings->ulContext[ ulIndex ] = ( StackType_t ) pvParameters; /* R0 */
230230
ulIndex--;
@@ -324,33 +324,7 @@ PRIVILEGED_FUNCTION static BaseType_t prvTaskCanAccessRegion(
324324
return ( &xMPUSettings->ulContext[ ulIndex ] );
325325
}
326326

327-
/*----------------------------------------------------------------------------*/
328-
329-
/* PRIVILEGED_FUNCTION */ static uint32_t prvGetMPURegionSizeSetting(
330-
uint32_t ulActualSizeInBytes
331-
)
332-
{
333-
uint32_t ulRegionSize, ulReturnValue = 4U;
334-
335-
/* 32 bytes is the smallest valid region for Cortex R4 and R5 CPUs */
336-
for( ulRegionSize = 0x20UL; ulReturnValue < 0x1FUL; ( ulRegionSize <<= 1UL ) )
337-
{
338-
if( ulActualSizeInBytes <= ulRegionSize )
339-
{
340-
break;
341-
}
342-
else
343-
{
344-
ulReturnValue++;
345-
}
346-
}
347-
348-
/* Shift the code by one before returning so it can be written directly
349-
* into the the correct bit position of the attribute register. */
350-
return ulReturnValue << 1UL;
351-
}
352-
353-
/*----------------------------------------------------------------------------*/
327+
/* ----------------------------------------------------------------------------------- */
354328

355329
/**
356330
* @brief Stores a FreeRTOS Task's MPU Settings in its TCB.
@@ -454,28 +428,116 @@ PRIVILEGED_FUNCTION static BaseType_t prvTaskCanAccessRegion(
454428
if( 0x0UL != ulStackDepth )
455429
{
456430
/* Define the region that allows access to the stack. */
457-
ulRegionStart = ( uint32_t ) pxBottomOfStack;
458-
ulRegionAttr = portMPU_PRIV_RW_USER_RW_NOEXEC |
459-
portMPU_NORMAL_OIWTNOWA_SHARED;
460-
ulRegionLen = prvGetMPURegionSizeSetting( ulStackDepth << 2UL );
461-
ulRegionLen |= portMPU_REGION_ENABLE;
431+
ulRegionStart = ( uint32_t ) pxBottomOfStack;
432+
ulRegionAttr = portMPU_PRIV_RW_USER_RW_NOEXEC |
433+
portMPU_NORMAL_OIWTNOWA_SHARED;
434+
ulRegionLen = prvGetMPURegionSizeSetting( ulStackDepth << 2UL );
435+
ulRegionLen |= portMPU_REGION_ENABLE;
462436

463-
/* MPU Regions must be aligned to a power of 2 equal to length */
464-
ulAlignment = 2UL << ( ulRegionLen >> 1UL );
465-
configASSERT( 0U == ( ulRegionStart % 2UL ) );
466-
configASSERT( 0U == ( ulRegionStart % ( ulAlignment ) ) );
437+
/* MPU Regions must be aligned to a power of 2 equal to length */
438+
ulAlignment = 2UL << ( ulRegionLen >> 1UL );
439+
configASSERT( 0U == ( ulRegionStart % 2UL ) );
440+
configASSERT( 0U == ( ulRegionStart % ( ulAlignment ) ) );
467441

468-
/* xRegion[portNUM_CONFIGURABLE_REGIONS] is the Task Stack */
469-
ulIndex = portNUM_CONFIGURABLE_REGIONS;
442+
/* xRegion[portNUM_CONFIGURABLE_REGIONS] is the Task Stack */
443+
ulIndex = portNUM_CONFIGURABLE_REGIONS;
470444

471-
xMPUSettings->xRegion[ ulIndex ].ulRegionBaseAddress = ulRegionStart;
472-
xMPUSettings->xRegion[ ulIndex ].ulRegionSize = ulRegionLen;
473-
xMPUSettings->xRegion[ ulIndex ].ulRegionAttribute = ulRegionAttr;
445+
xMPUSettings->xRegion[ ulIndex ].ulRegionBaseAddress = ulRegionStart;
446+
xMPUSettings->xRegion[ ulIndex ].ulRegionSize = ulRegionLen;
447+
xMPUSettings->xRegion[ ulIndex ].ulRegionAttribute = ulRegionAttr;
474448
}
475449
}
476450
}
477451

478-
/*----------------------------------------------------------------------------*/
452+
/* ----------------------------------------------------------------------------------- */
453+
454+
/**
455+
* @brief Determine if the FreeRTOS Task was created as a privileged task.
456+
*
457+
* @ingroup MPU Control
458+
* @ingroup Task Context
459+
*
460+
* @return pdTRUE if the Task was created as a privileged task.
461+
* pdFALSE if the task was not created as a privileged task.
462+
*
463+
*/
464+
/* PRIVILEGED_FUNCTION */ BaseType_t xPortIsTaskPrivileged( void )
465+
{
466+
BaseType_t xTaskIsPrivileged = pdFALSE;
467+
468+
/* Calling task's MPU settings. */
469+
const xMPU_SETTINGS * xTaskMpuSettings = xTaskGetMPUSettings( NULL );
470+
471+
if( ( xTaskMpuSettings->ulTaskFlags & portTASK_IS_PRIVILEGED_FLAG ) ==
472+
portTASK_IS_PRIVILEGED_FLAG )
473+
{
474+
xTaskIsPrivileged = pdTRUE;
475+
}
476+
477+
return xTaskIsPrivileged;
478+
}
479+
480+
/**
481+
* @brief Start the System Tick Timer, starting the FreeRTOS-Kernel.
482+
*
483+
* @ingroup Scheduler
484+
* @return BaseType_t This function is not meant to be returned from.
485+
* If it does return it returns pdFALSE to mark that the scheduler
486+
* could not be started.
487+
*/
488+
/* PRIVILEGED_FUNCTION */ BaseType_t xPortStartScheduler( void )
489+
{
490+
/* Start the timer that generates the tick ISR. */
491+
configSETUP_TICK_INTERRUPT();
492+
493+
/* Reset the critical section nesting count read to execute the first task. */
494+
ulCriticalNesting = 0UL;
495+
496+
/* Configure the regions in the MPU that are common to all tasks. */
497+
prvSetupMPU();
498+
499+
/* Mark the port specific scheduler running variable as true */
500+
prvPortSchedulerRunning = pdTRUE;
501+
502+
/* Load the context of the first task, starting the FreeRTOS-Scheduler's control. */
503+
vPortStartFirstTask();
504+
505+
/* Will only get here if vTaskStartScheduler() was called with the CPU in
506+
* a non-privileged mode or the binary point register was not set to its lowest
507+
* possible value. prvTaskExitError() is referenced to prevent a compiler
508+
* warning about it being defined but not referenced in the case that the user
509+
* defines their own exit address. */
510+
( void ) prvTaskExitError();
511+
return pdFALSE;
512+
}
513+
514+
/* ----------------------------------------------------------------------------------- */
515+
516+
/* PRIVILEGED_FUNCTION */ static uint32_t prvGetMPURegionSizeSetting(
517+
uint32_t ulActualSizeInBytes
518+
)
519+
{
520+
uint32_t ulRegionSize, ulReturnValue = 4U;
521+
522+
/* 32 bytes is the smallest valid region for Cortex R4 and R5 CPUs */
523+
for( ulRegionSize = 0x20UL; ulReturnValue < 0x1FUL; ( ulRegionSize <<= 1UL ) )
524+
{
525+
if( ulActualSizeInBytes <= ulRegionSize )
526+
{
527+
break;
528+
}
529+
else
530+
{
531+
ulReturnValue++;
532+
}
533+
}
534+
535+
/* Shift the code by one before returning so it can be written directly
536+
* into the the correct bit position of the attribute register. */
537+
return ulReturnValue << 1UL;
538+
}
539+
540+
/* ----------------------------------------------------------------------------------- */
479541

480542
/* PRIVILEGED_FUNCTION */ static void prvSetupMPU( void )
481543
{
@@ -616,7 +678,7 @@ PRIVILEGED_FUNCTION static BaseType_t prvTaskCanAccessRegion(
616678
return xAccessGranted;
617679
}
618680

619-
/* ------------------------------------------------------------------------- */
681+
/* ----------------------------------------------------------------------------------- */
620682

621683
/* PRIVILEGED_FUNCTION */ BaseType_t xPortIsAuthorizedToAccessBuffer(
622684
const void * pvBuffer,
@@ -665,67 +727,7 @@ PRIVILEGED_FUNCTION static BaseType_t prvTaskCanAccessRegion(
665727
return xAccessGranted;
666728
}
667729

668-
/*---------------------------------------------------------------------------*/
669-
670-
/**
671-
* @brief Determine if the FreeRTOS Task was created as a privileged task.
672-
*
673-
* @ingroup MPU Control
674-
* @ingroup Task Context
675-
*
676-
* @return pdTRUE if the Task was created as a privileged task.
677-
* pdFALSE if the task was not created as a privileged task.
678-
*
679-
*/
680-
/* PRIVILEGED_FUNCTION */ BaseType_t xPortIsTaskPrivileged( void )
681-
{
682-
BaseType_t xTaskIsPrivileged = pdFALSE;
683-
684-
/* Calling task's MPU settings. */
685-
const xMPU_SETTINGS * xTaskMpuSettings = xTaskGetMPUSettings( NULL );
686-
687-
if( ( xTaskMpuSettings->ulTaskFlags & portTASK_IS_PRIVILEGED_FLAG ) ==
688-
portTASK_IS_PRIVILEGED_FLAG )
689-
{
690-
xTaskIsPrivileged = pdTRUE;
691-
}
692-
693-
return xTaskIsPrivileged;
694-
}
695-
696-
/**
697-
* @brief Start the System Tick Timer, starting the FreeRTOS-Kernel.
698-
*
699-
* @ingroup Scheduler
700-
* @return BaseType_t This function is not meant to be returned from.
701-
* If it does return it returns pdFALSE to mark that the scheduler could not be started.
702-
*/
703-
/* PRIVILEGED_FUNCTION */ BaseType_t xPortStartScheduler( void )
704-
{
705-
/* Start the timer that generates the tick ISR. */
706-
configSETUP_TICK_INTERRUPT();
707-
708-
/* Reset the critical section nesting count read to execute the first task. */
709-
ulCriticalNesting = 0UL;
710-
711-
/* Configure the regions in the MPU that are common to all tasks. */
712-
prvSetupMPU();
713-
714-
/* Mark the port specific scheduler running variable as true */
715-
prvPortSchedulerRunning = pdTRUE;
716-
717-
/* Load the context of the first task, starting the FreeRTOS-Scheduler's control. */
718-
vPortStartFirstTask();
719-
720-
/* Will only get here if vTaskStartScheduler() was called with the CPU in
721-
* a non-privileged mode or the binary point register was not set to its lowest
722-
* possible value. prvTaskExitError() is referenced to prevent a compiler
723-
* warning about it being defined but not referenced in the case that the user
724-
* defines their own exit address. */
725-
( void ) prvTaskExitError();
726-
return pdFALSE;
727-
}
728-
/*---------------------------------------------------------------------------*/
730+
/* ----------------------------------------------------------------------------------- */
729731

730732
#if( configENABLE_ACCESS_CONTROL_LIST == 1 )
731733

@@ -747,7 +749,8 @@ PRIVILEGED_FUNCTION static BaseType_t prvTaskCanAccessRegion(
747749
}
748750
else
749751
{
750-
xTaskMpuSettings = xTaskGetMPUSettings( NULL ); /* Calling task's MPU settings. */
752+
/* Calling task's MPU settings. */
753+
xTaskMpuSettings = xTaskGetMPUSettings( NULL );
751754

752755
ulAccessControlListEntryIndex =
753756
( ( uint32_t ) lInternalIndexOfKernelObject / portACL_ENTRY_SIZE_BITS );
@@ -826,7 +829,7 @@ PRIVILEGED_FUNCTION static BaseType_t prvTaskCanAccessRegion(
826829

827830
#endif /* #if ( configENABLE_ACCESS_CONTROL_LIST == 1 ) */
828831

829-
/*---------------------------------------------------------------------------*/
832+
/* ----------------------------------------------------------------------------------- */
830833

831834
void prvTaskExitError( void )
832835
{
@@ -843,12 +846,8 @@ void prvTaskExitError( void )
843846
}
844847
}
845848

846-
/*---------------------------------------------------------------------------*/
849+
/* ----------------------------------------------------------------------------------- */
847850

848-
/**
849-
* @brief Function meant to end the FreeRTOS Scheduler, not implemented on this port.
850-
* @ingroup Scheduler
851-
*/
852851
void vPortEndScheduler( void )
853852
{
854853
prvPortSchedulerRunning = pdFALSE;
@@ -857,4 +856,4 @@ void vPortEndScheduler( void )
857856
configASSERT( prvPortSchedulerRunning );
858857
}
859858

860-
/*---------------------------------------------------------------------------*/
859+
/* ----------------------------------------------------------------------------------- */

portable/GCC/ARM_CRx_MPU/portASM.S

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
/* Load the first per-task MPU region into R5 */
122122
MOV R5, #portFIRST_CONFIGURABLE_REGION
123123
/* When creating a loop label in a macro it has to be a numeric label.
124-
* For (R5 = portFIRST_CONFIGURABLE_REGION ; R5 <= portNUM_CONFIGURABLE_REGIONS ; R5++ ) */
124+
* for( R5 = portFIRST_CONFIGURABLE_REGION ; R5 <= portNUM_CONFIGURABLE_REGIONS ; R5++ ) */
125125
123:
126126
/* Load values of struct MPU_REGION_REGISTERS into R2-R4 */
127127
LDMIA R1!, { R2-R4 }
@@ -217,7 +217,7 @@ FreeRTOS_SVC_Handler:
217217
/* Push R11-R12 for scratch space */
218218
PUSH { R11-R12 }
219219

220-
/* -------------------- Caller Flash Location Check -------------------- */
220+
/* ------------------------- Caller Flash Location Check ------------------------- */
221221

222222
/* The address of the caller will be in the Link Register (LR), it will
223223
* be the caller's Program Counter (PC). Check this address to ensure the
@@ -234,7 +234,7 @@ FreeRTOS_SVC_Handler:
234234
/* If the SVC was raised from outside FreeRTOS System Calls exit now */
235235
BGE SVC_Handler_Exit
236236

237-
/* ----------------------- Get Caller SVC Number ----------------------- */
237+
/* ---------------------------- Get Caller SVC Number ---------------------------- */
238238

239239
/* The SPSR will be the CPSR of the calling task, store it in R11 */
240240
MRS R11, SPSR
@@ -245,7 +245,7 @@ FreeRTOS_SVC_Handler:
245245
/* Not in Thumb Mode, the instruction 0x4 before holds the SVC numebr */
246246
LDRHEQ R11, [LR, #-0x4]
247247

248-
/* ---------------------------- SVC Routing ---------------------------- */
248+
/* --------------------------------- SVC Routing --------------------------------- */
249249

250250
/* Determine if the SVC number is below #NUM_SYSTEM_CALLS */
251251
CMP R11, #NUM_SYSTEM_CALLS

0 commit comments

Comments
 (0)