5353 * become unmasked before the scheduler starts. As it is stored as part of the
5454 * task context it will be set to 0 when the first task is started.
5555 */
56- PRIVILEGED_DATA volatile uint32_t ulCriticalNesting = 0xFFFF ;
56+ PRIVILEGED_DATA volatile UBaseType_t ulCriticalNesting = 0xFFFF ;
5757
5858/** @brief Set to 1 to pend a context switch from an ISR.
5959 * @ingroup Interrupt Management
6060 */
61- PRIVILEGED_DATA volatile uint32_t ulPortYieldRequired = pdFALSE ;
61+ PRIVILEGED_DATA volatile UBaseType_t ulPortYieldRequired = pdFALSE ;
6262
6363/**
6464 * @brief Interrupt nesting depth, used to count the number of interrupts to unwind.
6565 * @ingroup Interrupt Management
6666 */
67- PRIVILEGED_DATA volatile uint32_t ulPortInterruptNesting = 0UL ;
67+ PRIVILEGED_DATA volatile UBaseType_t ulPortInterruptNesting = 0UL ;
6868
6969/**
7070 * @brief Variable to track whether or not the scheduler has been started.
7171 * @ingroup Scheduler
72- * @note This variable is set to pdTRUE when the scheduler is started.
72+ * @note This is the port specific version of the Kernel's xSchedulerRunning
7373 */
7474PRIVILEGED_DATA static BaseType_t prvPortSchedulerRunning = pdFALSE ;
7575
76- /*---------------------------------------------------------------------------*/
76+ /* -------------------------- Private Function Declarations -------------------------- */
77+
78+ /**
79+ * @brief Determine if a FreeRTOS Task has been granted access to a memory region.
80+ *
81+ * @param xTaskMPURegion Pointer to a single set of MPU region registers.
82+ * @param ulRegionStart Base address of the memory region access is being requested.
83+ * @param ulRegionLength The length of the memory region that access is being requested.
84+ * @param ulAccessRequested The type of access being requested, either read or write.
85+ * @return BaseType_t pdTRUE if the task can access the region, pdFALSE otherwise
86+ *
87+ * @ingroup Task Context
88+ * @ingroup MPU Control
89+ */
90+ PRIVILEGED_FUNCTION static BaseType_t prvTaskCanAccessRegion (
91+ const xMPU_REGION_REGISTERS * xTaskMPURegion ,
92+ const uint32_t ulRegionStart ,
93+ const uint32_t ulRegionLength ,
94+ const uint32_t ulAccessRequested
95+ );
96+
97+ /**
98+ * @brief Determine smallest MPU Region Setting for a number of bytes.
99+ *
100+ * @ingroup MPU Control
101+ *
102+ * @param ulActualSizeInBytes Number of bytes to find a valid MPU region size for.
103+ * @return uint32_t The smallest MPU region size that can hold the requested bytes.
104+ */
105+ PRIVILEGED_FUNCTION static uint32_t prvGetMPURegionSizeSetting (
106+ uint32_t ulActualSizeInBytes
107+ );
108+
109+ /** @brief Set up a default MPU memory Map
110+ * @return PRIVILEGED_FUNCTION VOID
111+ * @ingroup MPU Control
112+ * @note This function shall be called before calling vPortStartFirstTask().
113+ * @note This function works by pulling variables from the linker script.
114+ * Ensure that the variables used in your linker script match up with the variable names
115+ * used at the start of this function.
116+ */
117+ PRIVILEGED_FUNCTION static void prvSetupMPU ( void );
118+
119+ /**
120+ * @brief Determine if a FreeRTOS Task has been granted access to a memory region.
121+ *
122+ * @param xTaskMPURegion Pointer to a single set of MPU region registers.
123+ * @param ulRegionStart Base address of the memory region access is being requested.
124+ * @param ulRegionLength The length of the memory region that access is being requested.
125+ * @param ulAccessRequested The type of access being requested, either read or write.
126+ * @return BaseType_t pdTRUE if the task can access the region, pdFALSE otherwise
127+ *
128+ * @ingroup Task Context
129+ * @ingroup MPU Control
130+ */
131+ PRIVILEGED_FUNCTION static BaseType_t prvTaskCanAccessRegion (
132+ const xMPU_REGION_REGISTERS * xTaskMPURegion ,
133+ const uint32_t ulRegionStart ,
134+ const uint32_t ulRegionLength ,
135+ const uint32_t ulAccessRequested
136+ );
137+
138+ /* ----------------------------------------------------------------------------------- */
77139
78140/**
79141 * @brief Set a FreeRTOS Task's initial context.
@@ -264,16 +326,7 @@ PRIVILEGED_DATA static BaseType_t prvPortSchedulerRunning = pdFALSE;
264326
265327/*----------------------------------------------------------------------------*/
266328
267-
268- /**
269- * @brief Determine smallest MPU Region Setting for a number of bytes.
270- *
271- * @ingroup MPU Control
272- *
273- * @param ulActualSizeInBytes Number of bytes to find a valid MPU region size for.
274- * @return uint32_t The smallest MPU region size that can hold the requested bytes.
275- */
276- PRIVILEGED_FUNCTION static uint32_t prvGetMPURegionSizeSetting (
329+ /* PRIVILEGED_FUNCTION */ static uint32_t prvGetMPURegionSizeSetting (
277330 uint32_t ulActualSizeInBytes
278331)
279332{
@@ -424,19 +477,10 @@ PRIVILEGED_FUNCTION static uint32_t prvGetMPURegionSizeSetting(
424477
425478/*----------------------------------------------------------------------------*/
426479
427- /** @brief Set up a default MPU memory Map
428- * @return PRIVILEGED_FUNCTION VOID
429- * @ingroup MPU Control
430- * @note This function shall be called before calling vPortStartFirstTask().
431- * @note This function works by pulling variables from the linker script.
432- * Ensure that the variables used in your linker script match up with the variable names
433- * used at the start of this function.
434- */
435- PRIVILEGED_FUNCTION static void prvSetupMPU ( void )
480+ /* PRIVILEGED_FUNCTION */ static void prvSetupMPU ( void )
436481{
437482#if defined( __ARMCC_VERSION )
438- /* Declaration when these variable are defined in code instead of being
439- * exported from linker scripts. */
483+ /* Declaration when these variable are defined in code. */
440484 /* Sections used for FLASH */
441485 extern uint32_t * __FLASH_segment_start__ ;
442486 extern uint32_t * __FLASH_segment_end__ ;
@@ -449,10 +493,6 @@ PRIVILEGED_FUNCTION static void prvSetupMPU( void )
449493 extern uint32_t * __privileged_data_start__ ;
450494 extern uint32_t * __privileged_data_end__ ;
451495
452- /* Sections used for system peripherals, such as UART */
453- extern uint32_t * __peripherals_start__ ;
454- extern uint32_t * __peripherals_end__ ;
455-
456496#else
457497 /* Declaration when these variable are exported from linker scripts. */
458498 /* Sections used for FLASH */
@@ -467,9 +507,6 @@ PRIVILEGED_FUNCTION static void prvSetupMPU( void )
467507 extern uint32_t __privileged_data_start__ [];
468508 extern uint32_t __privileged_data_end__ [];
469509
470- /* Sections used for system peripherals, such as UART */
471- extern uint32_t __peripherals_start__ [];
472- extern uint32_t __peripherals_end__ [];
473510#endif /* if defined( __ARMCC_VERSION ) */
474511 uint32_t ulRegionStart ;
475512 uint32_t ulRegionEnd ;
@@ -506,21 +543,7 @@ PRIVILEGED_FUNCTION static void prvSetupMPU( void )
506543 portMPU_PRIV_RO_USER_NA_EXEC | portMPU_NORMAL_OIWTNOWA_SHARED
507544 );
508545
509- /* MPU Region for Peripheral Usage */
510- ulRegionStart = ( uint32_t ) __peripherals_start__ ;
511- ulRegionEnd = ( uint32_t ) __peripherals_end__ ;
512- ulRegionLength = ulRegionEnd - ulRegionStart ;
513- ulRegionLength = prvGetMPURegionSizeSetting ( ulRegionLength );
514- ulRegionLength |= portMPU_REGION_ENABLE ;
515-
516- vMPUSetRegion (
517- portGENERAL_PERIPHERALS_REGION ,
518- ulRegionStart ,
519- ulRegionLength ,
520- portMPU_PRIV_RW_USER_RW_NOEXEC | portMPU_DEVICE_NONSHAREABLE
521- );
522-
523- /* Privileged Write and Read, Unprivileged no access, MPU Region for PRIVILEGED_DATA. */
546+ /* Privileged Write and Read Access for PRIVILEGED_DATA. */
524547 ulRegionStart = ( uint32_t ) __privileged_data_start__ ;
525548 ulRegionEnd = ( uint32_t ) __privileged_data_end__ ;
526549 ulRegionLength = ulRegionEnd - ulRegionStart ;
@@ -542,21 +565,9 @@ PRIVILEGED_FUNCTION static void prvSetupMPU( void )
542565 vMPUEnable ();
543566}
544567
545- /* ------------------------------------------------------------------------- */
568+ /* ----------------------------------------------------------------------------------- */
546569
547- /**
548- * @brief Determine if a FreeRTOS Task has been granted access to a memory region.
549- *
550- * @param xTaskMPURegion Pointer to a single set of MPU region registers.
551- * @param ulRegionStart Base address of the memory region access is being requested.
552- * @param ulRegionLength The length of the memory region that access is being requested.
553- * @param ulAccessRequested The type of access being requested, either read or write.
554- * @return BaseType_t pdTRUE if the task can access the region, pdFALSE otherwise
555- *
556- * @ingroup Task Context
557- * @ingroup MPU Control
558- */
559- PRIVILEGED_FUNCTION static BaseType_t prvTaskCanAccessRegion (
570+ /* PRIVILEGED_FUNCTION */ static BaseType_t prvTaskCanAccessRegion (
560571 const xMPU_REGION_REGISTERS * xTaskMPURegion ,
561572 const uint32_t ulRegionStart ,
562573 const uint32_t ulRegionLength ,
@@ -570,6 +581,10 @@ PRIVILEGED_FUNCTION static BaseType_t prvTaskCanAccessRegion(
570581 uint32_t ulTaskRegionLength = 2UL << ( xTaskMPURegion -> ulRegionSize >> 1UL );
571582 uint32_t ulTaskRegionEnd = xTaskMPURegion -> ulRegionBaseAddress + ulTaskRegionLength ;
572583
584+ /* Perform three different checks:
585+ * 1. Ensure region being accessed is after the start of an MPU Region
586+ * 2. Ensure region being accessed is before the end of the MPU Region
587+ * 3. Ensure region being accessed ends after the start of the MPU region */
573588 if ( ( ulRegionStart >= xTaskMPURegion -> ulRegionBaseAddress ) &&
574589 ( ulRegionEnd <= ulTaskRegionEnd ) && ( ulRegionEnd >= ulRegionStart ) )
575590 {
@@ -685,7 +700,7 @@ PRIVILEGED_FUNCTION static BaseType_t prvTaskCanAccessRegion(
685700 * @return BaseType_t This function is not meant to be returned from.
686701 * If it does return it returns pdFALSE to mark that the scheduler could not be started.
687702 */
688- BaseType_t xPortStartScheduler ( void )
703+ /* PRIVILEGED_FUNCTION */ BaseType_t xPortStartScheduler ( void )
689704{
690705 /* Start the timer that generates the tick ISR. */
691706 configSETUP_TICK_INTERRUPT ();
@@ -696,6 +711,7 @@ BaseType_t xPortStartScheduler( void )
696711 /* Configure the regions in the MPU that are common to all tasks. */
697712 prvSetupMPU ();
698713
714+ /* Mark the port specific scheduler running variable as true */
699715 prvPortSchedulerRunning = pdTRUE ;
700716
701717 /* Load the context of the first task, starting the FreeRTOS-Scheduler's control. */
0 commit comments