]> begriffs open source - freertos/blob - portable/IAR/ARM_CM4F_MPU/port.c
Fix portSWITCH_TO_USER_MODE() on Armv7-M MPU ports (#803)
[freertos] / portable / IAR / ARM_CM4F_MPU / port.c
1 /*
2  * FreeRTOS Kernel <DEVELOPMENT BRANCH>
3  * Copyright (C) 2021 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * SPDX-License-Identifier: MIT
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy of
8  * this software and associated documentation files (the "Software"), to deal in
9  * the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11  * the Software, and to permit persons to whom the Software is furnished to do so,
12  * subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * https://www.FreeRTOS.org
25  * https://github.com/FreeRTOS
26  *
27  */
28
29 /*-----------------------------------------------------------
30 * Implementation of functions defined in portable.h for the ARM CM4F MPU port.
31 *----------------------------------------------------------*/
32
33 /* IAR includes. */
34 #include <intrinsics.h>
35
36 /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
37  * all the API functions to use the MPU wrappers.  That should only be done when
38  * task.h is included from an application file. */
39 #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
40
41 /* Scheduler includes. */
42 #include "FreeRTOS.h"
43 #include "task.h"
44
45 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
46
47 #ifndef __ARMVFP__
48     #error This port can only be used when the project options are configured to enable hardware floating point support.
49 #endif
50
51 #if ( configMAX_SYSCALL_INTERRUPT_PRIORITY == 0 )
52     #error configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0.  See http: /*www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
53 #endif
54
55 #ifndef configSYSTICK_CLOCK_HZ
56     #define configSYSTICK_CLOCK_HZ      configCPU_CLOCK_HZ
57     /* Ensure the SysTick is clocked at the same frequency as the core. */
58     #define portNVIC_SYSTICK_CLK_BIT    ( 1UL << 2UL )
59 #else
60
61 /* The way the SysTick is clocked is not modified in case it is not the same
62  * as the core. */
63     #define portNVIC_SYSTICK_CLK_BIT    ( 0 )
64 #endif
65
66 #ifndef configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS
67     #warning "configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS is not defined. We recommend defining it to 0 in FreeRTOSConfig.h for better security."
68     #define configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS    1
69 #endif
70
71 /* Constants required to manipulate the core.  Registers first... */
72 #define portNVIC_SYSTICK_CTRL_REG                 ( *( ( volatile uint32_t * ) 0xe000e010 ) )
73 #define portNVIC_SYSTICK_LOAD_REG                 ( *( ( volatile uint32_t * ) 0xe000e014 ) )
74 #define portNVIC_SYSTICK_CURRENT_VALUE_REG        ( *( ( volatile uint32_t * ) 0xe000e018 ) )
75 #define portNVIC_SHPR3_REG                        ( *( ( volatile uint32_t * ) 0xe000ed20 ) )
76 #define portNVIC_SHPR2_REG                        ( *( ( volatile uint32_t * ) 0xe000ed1c ) )
77 #define portNVIC_SYS_CTRL_STATE_REG               ( *( ( volatile uint32_t * ) 0xe000ed24 ) )
78 #define portNVIC_MEM_FAULT_ENABLE                 ( 1UL << 16UL )
79
80 /* Constants required to access and manipulate the MPU. */
81 #define portMPU_TYPE_REG                          ( *( ( volatile uint32_t * ) 0xe000ed90 ) )
82 #define portMPU_REGION_BASE_ADDRESS_REG           ( *( ( volatile uint32_t * ) 0xe000ed9C ) )
83 #define portMPU_REGION_ATTRIBUTE_REG              ( *( ( volatile uint32_t * ) 0xe000edA0 ) )
84 #define portMPU_CTRL_REG                          ( *( ( volatile uint32_t * ) 0xe000ed94 ) )
85 #define portEXPECTED_MPU_TYPE_VALUE               ( configTOTAL_MPU_REGIONS << 8UL )
86 #define portMPU_ENABLE                            ( 0x01UL )
87 #define portMPU_BACKGROUND_ENABLE                 ( 1UL << 2UL )
88 #define portPRIVILEGED_EXECUTION_START_ADDRESS    ( 0UL )
89 #define portMPU_REGION_VALID                      ( 0x10UL )
90 #define portMPU_REGION_ENABLE                     ( 0x01UL )
91 #define portPERIPHERALS_START_ADDRESS             0x40000000UL
92 #define portPERIPHERALS_END_ADDRESS               0x5FFFFFFFUL
93
94 /* ...then bits in the registers. */
95 #define portNVIC_SYSTICK_INT_BIT                  ( 1UL << 1UL )
96 #define portNVIC_SYSTICK_ENABLE_BIT               ( 1UL << 0UL )
97 #define portNVIC_SYSTICK_COUNT_FLAG_BIT           ( 1UL << 16UL )
98 #define portNVIC_PENDSVCLEAR_BIT                  ( 1UL << 27UL )
99 #define portNVIC_PEND_SYSTICK_CLEAR_BIT           ( 1UL << 25UL )
100
101 /* Constants used to detect Cortex-M7 r0p0 and r0p1 cores, and ensure
102  * that a work around is active for errata 837070. */
103 #define portCPUID                                 ( *( ( volatile uint32_t * ) 0xE000ed00 ) )
104 #define portCORTEX_M7_r0p1_ID                     ( 0x410FC271UL )
105 #define portCORTEX_M7_r0p0_ID                     ( 0x410FC270UL )
106
107 #define portMIN_INTERRUPT_PRIORITY                ( 255UL )
108 #define portNVIC_PENDSV_PRI                       ( ( ( uint32_t ) portMIN_INTERRUPT_PRIORITY ) << 16UL )
109 #define portNVIC_SYSTICK_PRI                      ( ( ( uint32_t ) portMIN_INTERRUPT_PRIORITY ) << 24UL )
110 #define portNVIC_SVC_PRI                          ( ( ( uint32_t ) configMAX_SYSCALL_INTERRUPT_PRIORITY - 1UL ) << 24UL )
111
112 /* Constants required to check the validity of an interrupt priority. */
113 #define portFIRST_USER_INTERRUPT_NUMBER           ( 16 )
114 #define portNVIC_IP_REGISTERS_OFFSET_16           ( 0xE000E3F0 )
115 #define portAIRCR_REG                             ( *( ( volatile uint32_t * ) 0xE000ED0C ) )
116 #define portMAX_8_BIT_VALUE                       ( ( uint8_t ) 0xff )
117 #define portTOP_BIT_OF_BYTE                       ( ( uint8_t ) 0x80 )
118 #define portMAX_PRIGROUP_BITS                     ( ( uint8_t ) 7 )
119 #define portPRIORITY_GROUP_MASK                   ( 0x07UL << 8UL )
120 #define portPRIGROUP_SHIFT                        ( 8UL )
121
122 /* Masks off all bits but the VECTACTIVE bits in the ICSR register. */
123 #define portVECTACTIVE_MASK                       ( 0xFFUL )
124
125 /* Constants required to manipulate the VFP. */
126 #define portFPCCR                                 ( ( volatile uint32_t * ) 0xe000ef34 ) /* Floating point context control register. */
127 #define portASPEN_AND_LSPEN_BITS                  ( 0x3UL << 30UL )
128
129 /* Constants required to set up the initial stack. */
130 #define portINITIAL_XPSR                          ( 0x01000000 )
131 #define portINITIAL_EXC_RETURN                    ( 0xfffffffd )
132 #define portINITIAL_CONTROL_IF_UNPRIVILEGED       ( 0x03 )
133 #define portINITIAL_CONTROL_IF_PRIVILEGED         ( 0x02 )
134
135 /* Constants used during system call enter and exit. */
136 #define portPSR_STACK_PADDING_MASK                ( 1UL << 9UL )
137 #define portEXC_RETURN_STACK_FRAME_TYPE_MASK      ( 1UL << 4UL )
138
139 /* Offsets in the stack to the parameters when inside the SVC handler. */
140 #define portOFFSET_TO_LR                          ( 5 )
141 #define portOFFSET_TO_PC                          ( 6 )
142 #define portOFFSET_TO_PSR                         ( 7 )
143
144 /* The systick is a 24-bit counter. */
145 #define portMAX_24_BIT_NUMBER                     ( 0xffffffUL )
146
147 /* A fiddle factor to estimate the number of SysTick counts that would have
148  * occurred while the SysTick counter is stopped during tickless idle
149  * calculations. */
150 #define portMISSED_COUNTS_FACTOR                  ( 45UL )
151
152 /* For strict compliance with the Cortex-M spec the task start address should
153  * have bit-0 clear, as it is loaded into the PC on exit from an ISR. */
154 #define portSTART_ADDRESS_MASK                    ( ( StackType_t ) 0xfffffffeUL )
155
156 /* Does addr lie within [start, end] address range? */
157 #define portIS_ADDRESS_WITHIN_RANGE( addr, start, end ) \
158     ( ( ( addr ) >= ( start ) ) && ( ( addr ) <= ( end ) ) )
159
160 /* Is the access request satisfied by the available permissions? */
161 #define portIS_AUTHORIZED( accessRequest, permissions ) \
162     ( ( ( permissions ) & ( accessRequest ) ) == accessRequest )
163
164 /* Max value that fits in a uint32_t type. */
165 #define portUINT32_MAX    ( ~( ( uint32_t ) 0 ) )
166
167 /* Check if adding a and b will result in overflow. */
168 #define portADD_UINT32_WILL_OVERFLOW( a, b )    ( ( a ) > ( portUINT32_MAX - ( b ) ) )
169 /*-----------------------------------------------------------*/
170
171 /*
172  * Configure a number of standard MPU regions that are used by all tasks.
173  */
174 static void prvSetupMPU( void ) PRIVILEGED_FUNCTION;
175
176 /*
177  * Return the smallest MPU region size that a given number of bytes will fit
178  * into.  The region size is returned as the value that should be programmed
179  * into the region attribute register for that region.
180  */
181 static uint32_t prvGetMPURegionSizeSetting( uint32_t ulActualSizeInBytes ) PRIVILEGED_FUNCTION;
182
183 /*
184  * Setup the timer to generate the tick interrupts.  The implementation in this
185  * file is weak to allow application writers to change the timer used to
186  * generate the tick interrupt.
187  */
188 void vPortSetupTimerInterrupt( void );
189
190 /*
191  * Exception handlers.
192  */
193 void xPortSysTickHandler( void ) PRIVILEGED_FUNCTION;
194
195 /*
196  * Start first task is a separate function so it can be tested in isolation.
197  */
198 extern void vPortStartFirstTask( void ) PRIVILEGED_FUNCTION;
199
200 /*
201  * Turn the VFP on.
202  */
203 extern void vPortEnableVFP( void );
204
205 /*
206  * The C portion of the SVC handler.
207  */
208 void vPortSVCHandler_C( uint32_t * pulParam ) PRIVILEGED_FUNCTION;
209
210 /*
211  * Called from the SVC handler used to start the scheduler.
212  */
213 extern void vPortRestoreContextOfFirstTask( void ) PRIVILEGED_FUNCTION;
214
215 /**
216  * @brief Enter critical section.
217  */
218 #if ( configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS == 1 )
219     void vPortEnterCritical( void ) FREERTOS_SYSTEM_CALL;
220 #else
221     void vPortEnterCritical( void ) PRIVILEGED_FUNCTION;
222 #endif
223
224 /**
225  * @brief Exit from critical section.
226  */
227 #if ( configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS == 1 )
228     void vPortExitCritical( void ) FREERTOS_SYSTEM_CALL;
229 #else
230     void vPortExitCritical( void ) PRIVILEGED_FUNCTION;
231 #endif
232
233 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
234
235 /**
236  * @brief Sets up the system call stack so that upon returning from
237  * SVC, the system call stack is used.
238  *
239  * It is used for the system calls with up to 4 parameters.
240  *
241  * @param pulTaskStack The current SP when the SVC was raised.
242  * @param ulLR The value of Link Register (EXC_RETURN) in the SVC handler.
243  */
244     void vSystemCallEnter( uint32_t * pulTaskStack,
245                            uint32_t ulLR ) PRIVILEGED_FUNCTION;
246
247 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
248
249 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
250
251 /**
252  * @brief Sets up the system call stack so that upon returning from
253  * SVC, the system call stack is used.
254  *
255  * It is used for the system calls with 5 parameters.
256  *
257  * @param pulTaskStack The current SP when the SVC was raised.
258  * @param ulLR The value of Link Register (EXC_RETURN) in the SVC handler.
259  */
260     void vSystemCallEnter_1( uint32_t * pulTaskStack,
261                              uint32_t ulLR ) PRIVILEGED_FUNCTION;
262
263 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
264
265 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
266
267 /**
268  * @brief Sets up the task stack so that upon returning from
269  * SVC, the task stack is used again.
270  *
271  * @param pulSystemCallStack The current SP when the SVC was raised.
272  * @param ulLR The value of Link Register (EXC_RETURN) in the SVC handler.
273  */
274     void vSystemCallExit( uint32_t * pulSystemCallStack,
275                           uint32_t ulLR ) PRIVILEGED_FUNCTION;
276
277 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
278
279 /**
280  * @brief Checks whether or not the calling task is privileged.
281  *
282  * @return pdTRUE if the calling task is privileged, pdFALSE otherwise.
283  */
284 BaseType_t xPortIsTaskPrivileged( void ) PRIVILEGED_FUNCTION;
285
286 /**
287  * @brief Make a task unprivileged.
288  */
289 void vPortSwitchToUserMode( void );
290
291 /*-----------------------------------------------------------*/
292
293 /* Each task maintains its own interrupt status in the critical nesting
294  * variable. */
295 static UBaseType_t uxCriticalNesting = 0xaaaaaaaa;
296
297 /*
298  * Used by the portASSERT_IF_INTERRUPT_PRIORITY_INVALID() macro to ensure
299  * FreeRTOS API functions are not called from interrupts that have been assigned
300  * a priority above configMAX_SYSCALL_INTERRUPT_PRIORITY.
301  */
302 #if ( configASSERT_DEFINED == 1 )
303     static uint8_t ucMaxSysCallPriority = 0;
304     static uint32_t ulMaxPRIGROUPValue = 0;
305     static const volatile uint8_t * const pcInterruptPriorityRegisters = ( const volatile uint8_t * const ) portNVIC_IP_REGISTERS_OFFSET_16;
306 #endif /* configASSERT_DEFINED */
307
308 /*-----------------------------------------------------------*/
309
310 /*
311  * See header file for description.
312  */
313 StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
314                                      TaskFunction_t pxCode,
315                                      void * pvParameters,
316                                      BaseType_t xRunPrivileged,
317                                      xMPU_SETTINGS * xMPUSettings )
318 {
319     if( xRunPrivileged == pdTRUE )
320     {
321         xMPUSettings->ulTaskFlags |= portTASK_IS_PRIVILEGED_FLAG;
322         xMPUSettings->ulContext[ 0 ] = portINITIAL_CONTROL_IF_PRIVILEGED;
323     }
324     else
325     {
326         xMPUSettings->ulTaskFlags &= ( ~( portTASK_IS_PRIVILEGED_FLAG ) );
327         xMPUSettings->ulContext[ 0 ] = portINITIAL_CONTROL_IF_UNPRIVILEGED;
328     }
329
330     xMPUSettings->ulContext[ 1 ] = 0x04040404;                                        /* r4. */
331     xMPUSettings->ulContext[ 2 ] = 0x05050505;                                        /* r5. */
332     xMPUSettings->ulContext[ 3 ] = 0x06060606;                                        /* r6. */
333     xMPUSettings->ulContext[ 4 ] = 0x07070707;                                        /* r7. */
334     xMPUSettings->ulContext[ 5 ] = 0x08080808;                                        /* r8. */
335     xMPUSettings->ulContext[ 6 ] = 0x09090909;                                        /* r9. */
336     xMPUSettings->ulContext[ 7 ] = 0x10101010;                                        /* r10. */
337     xMPUSettings->ulContext[ 8 ] = 0x11111111;                                        /* r11. */
338     xMPUSettings->ulContext[ 9 ] = portINITIAL_EXC_RETURN;                            /* EXC_RETURN. */
339
340     xMPUSettings->ulContext[ 10 ] = ( uint32_t ) ( pxTopOfStack - 8 );                /* PSP with the hardware saved stack. */
341     xMPUSettings->ulContext[ 11 ] = ( uint32_t ) pvParameters;                        /* r0. */
342     xMPUSettings->ulContext[ 12 ] = 0x01010101;                                       /* r1. */
343     xMPUSettings->ulContext[ 13 ] = 0x02020202;                                       /* r2. */
344     xMPUSettings->ulContext[ 14 ] = 0x03030303;                                       /* r3. */
345     xMPUSettings->ulContext[ 15 ] = 0x12121212;                                       /* r12. */
346     xMPUSettings->ulContext[ 16 ] = 0;                                                /* LR. */
347     xMPUSettings->ulContext[ 17 ] = ( ( uint32_t ) pxCode ) & portSTART_ADDRESS_MASK; /* PC. */
348     xMPUSettings->ulContext[ 18 ] = portINITIAL_XPSR;                                 /* xPSR. */
349
350     #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
351     {
352         /* Ensure that the system call stack is double word aligned. */
353         xMPUSettings->xSystemCallStackInfo.pulSystemCallStack = &( xMPUSettings->xSystemCallStackInfo.ulSystemCallStackBuffer[ configSYSTEM_CALL_STACK_SIZE - 1 ] );
354         xMPUSettings->xSystemCallStackInfo.pulSystemCallStack = ( uint32_t * ) ( ( uint32_t ) ( xMPUSettings->xSystemCallStackInfo.pulSystemCallStack ) &
355                                                                                  ( uint32_t ) ( ~( portBYTE_ALIGNMENT_MASK ) ) );
356
357         /* This is not NULL only for the duration of a system call. */
358         xMPUSettings->xSystemCallStackInfo.pulTaskStack = NULL;
359     }
360     #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
361
362     return &( xMPUSettings->ulContext[ 19 ] );
363 }
364 /*-----------------------------------------------------------*/
365
366 void vPortSVCHandler_C( uint32_t * pulParam ) /* PRIVILEGED_FUNCTION */
367 {
368     uint8_t ucSVCNumber;
369     uint32_t ulPC;
370
371     #if ( configENFORCE_SYSTEM_CALLS_FROM_KERNEL_ONLY == 1 )
372         extern uint32_t __syscalls_flash_start__[];
373         extern uint32_t __syscalls_flash_end__[];
374     #endif /* #if( configENFORCE_SYSTEM_CALLS_FROM_KERNEL_ONLY == 1 ) */
375
376     /* The stack contains: r0, r1, r2, r3, r12, LR, PC and xPSR. The first
377      * argument (r0) is pulParam[ 0 ]. */
378     ulPC = pulParam[ portOFFSET_TO_PC ];
379     ucSVCNumber = ( ( uint8_t * ) ulPC )[ -2 ];
380
381     switch( ucSVCNumber )
382     {
383         case portSVC_START_SCHEDULER:
384             portNVIC_SHPR2_REG |= portNVIC_SVC_PRI;
385             vPortRestoreContextOfFirstTask();
386             break;
387
388         case portSVC_YIELD:
389             portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;
390
391             /* Barriers are normally not required
392              * but do ensure the code is completely
393              * within the specified behaviour for the
394              * architecture. */
395             __asm volatile ( "dsb" ::: "memory" );
396             __asm volatile ( "isb" );
397
398             break;
399
400             #if ( configENFORCE_SYSTEM_CALLS_FROM_KERNEL_ONLY == 1 )
401                 case portSVC_RAISE_PRIVILEGE: /* Only raise the privilege, if the
402                                                * svc was raised from any of the
403                                                * system calls. */
404
405                     if( ( ulPC >= ( uint32_t ) __syscalls_flash_start__ ) &&
406                         ( ulPC <= ( uint32_t ) __syscalls_flash_end__ ) )
407                     {
408                         __asm volatile
409                         (
410                             "   mrs r1, control     \n" /* Obtain current control value. */
411                             "   bic r1, r1, #1      \n" /* Set privilege bit. */
412                             "   msr control, r1     \n" /* Write back new control value. */
413                             ::: "r1", "memory"
414                         );
415                     }
416
417                     break;
418             #else /* if ( configENFORCE_SYSTEM_CALLS_FROM_KERNEL_ONLY == 1 ) */
419                 case portSVC_RAISE_PRIVILEGE:
420                     __asm volatile
421                     (
422                         "   mrs r1, control     \n" /* Obtain current control value. */
423                         "   bic r1, r1, #1      \n" /* Set privilege bit. */
424                         "   msr control, r1     \n" /* Write back new control value. */
425                         ::: "r1", "memory"
426                     );
427                     break;
428                     #endif /* #if( configENFORCE_SYSTEM_CALLS_FROM_KERNEL_ONLY == 1 ) */
429
430                 default: /* Unknown SVC call. */
431                     break;
432     }
433 }
434 /*-----------------------------------------------------------*/
435
436 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
437
438     void vSystemCallEnter( uint32_t * pulTaskStack,
439                            uint32_t ulLR ) /* PRIVILEGED_FUNCTION */
440     {
441         extern TaskHandle_t pxCurrentTCB;
442         xMPU_SETTINGS * pxMpuSettings;
443         uint32_t * pulSystemCallStack;
444         uint32_t ulStackFrameSize, ulSystemCallLocation, i;
445
446         #if defined( __ARMCC_VERSION )
447
448             /* Declaration when these variable are defined in code instead of being
449              * exported from linker scripts. */
450             extern uint32_t * __syscalls_flash_start__;
451             extern uint32_t * __syscalls_flash_end__;
452         #else
453             /* Declaration when these variable are exported from linker scripts. */
454             extern uint32_t __syscalls_flash_start__[];
455             extern uint32_t __syscalls_flash_end__[];
456         #endif /* #if defined( __ARMCC_VERSION ) */
457
458         ulSystemCallLocation = pulTaskStack[ portOFFSET_TO_PC ];
459
460         /* If the request did not come from the system call section, do nothing. */
461         if( ( ulSystemCallLocation >= ( uint32_t ) __syscalls_flash_start__ ) &&
462             ( ulSystemCallLocation <= ( uint32_t ) __syscalls_flash_end__ ) )
463         {
464             pxMpuSettings = xTaskGetMPUSettings( pxCurrentTCB );
465             pulSystemCallStack = pxMpuSettings->xSystemCallStackInfo.pulSystemCallStack;
466
467             /* This is not NULL only for the duration of the system call. */
468             configASSERT( pxMpuSettings->xSystemCallStackInfo.pulTaskStack == NULL );
469
470             if( ( ulLR & portEXC_RETURN_STACK_FRAME_TYPE_MASK ) == 0UL )
471             {
472                 /* Extended frame i.e. FPU in use. */
473                 ulStackFrameSize = 26;
474                 __asm volatile (
475                     " vpush {s0}         \n" /* Trigger lazy stacking. */
476                     " vpop  {s0}         \n" /* Nullify the affect of the above instruction. */
477                     ::: "memory"
478                     );
479             }
480             else
481             {
482                 /* Standard frame i.e. FPU not in use. */
483                 ulStackFrameSize = 8;
484             }
485
486             /* Make space on the system call stack for the stack frame. */
487             pulSystemCallStack = pulSystemCallStack - ulStackFrameSize;
488
489             /* Copy the stack frame. */
490             for( i = 0; i < ulStackFrameSize; i++ )
491             {
492                 pulSystemCallStack[ i ] = pulTaskStack[ i ];
493             }
494
495             /* Use the pulSystemCallStack in thread mode. */
496             __asm volatile ( "msr psp, %0" : : "r" ( pulSystemCallStack ) );
497
498             /* Raise the privilege for the duration of the system call. */
499             __asm volatile (
500                 " mrs r1, control     \n" /* Obtain current control value. */
501                 " bic r1, #1          \n" /* Clear nPRIV bit. */
502                 " msr control, r1     \n" /* Write back new control value. */
503                 ::: "r1", "memory"
504                 );
505
506             /* Remember the location where we should copy the stack frame when we exit from
507              * the system call. */
508             pxMpuSettings->xSystemCallStackInfo.pulTaskStack = pulTaskStack + ulStackFrameSize;
509
510             /* Store the value of the Link Register before the SVC was raised. We need to
511              * restore it when we exit from the system call. */
512             pxMpuSettings->xSystemCallStackInfo.ulLinkRegisterAtSystemCallEntry = pulTaskStack[ portOFFSET_TO_LR ];
513
514             /* Record if the hardware used padding to force the stack pointer
515              * to be double word aligned. */
516             if( ( pulTaskStack[ portOFFSET_TO_PSR ] & portPSR_STACK_PADDING_MASK ) == portPSR_STACK_PADDING_MASK )
517             {
518                 pxMpuSettings->ulTaskFlags |= portSTACK_FRAME_HAS_PADDING_FLAG;
519             }
520             else
521             {
522                 pxMpuSettings->ulTaskFlags &= ( ~portSTACK_FRAME_HAS_PADDING_FLAG );
523             }
524
525             /* We ensure in pxPortInitialiseStack that the system call stack is
526              * double word aligned and therefore, there is no need of padding.
527              * Clear the bit[9] of stacked xPSR. */
528             pulSystemCallStack[ portOFFSET_TO_PSR ] &= ( ~portPSR_STACK_PADDING_MASK );
529         }
530     }
531
532 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
533 /*-----------------------------------------------------------*/
534
535 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
536
537     void vSystemCallEnter_1( uint32_t * pulTaskStack,
538                              uint32_t ulLR ) /* PRIVILEGED_FUNCTION */
539     {
540         extern TaskHandle_t pxCurrentTCB;
541         xMPU_SETTINGS * pxMpuSettings;
542         uint32_t * pulSystemCallStack;
543         uint32_t ulStackFrameSize, ulSystemCallLocation, i;
544
545         #if defined( __ARMCC_VERSION )
546
547             /* Declaration when these variable are defined in code instead of being
548              * exported from linker scripts. */
549             extern uint32_t * __syscalls_flash_start__;
550             extern uint32_t * __syscalls_flash_end__;
551         #else
552             /* Declaration when these variable are exported from linker scripts. */
553             extern uint32_t __syscalls_flash_start__[];
554             extern uint32_t __syscalls_flash_end__[];
555         #endif /* #if defined( __ARMCC_VERSION ) */
556
557         ulSystemCallLocation = pulTaskStack[ portOFFSET_TO_PC ];
558
559         /* If the request did not come from the system call section, do nothing. */
560         if( ( ulSystemCallLocation >= ( uint32_t ) __syscalls_flash_start__ ) &&
561             ( ulSystemCallLocation <= ( uint32_t ) __syscalls_flash_end__ ) )
562         {
563             pxMpuSettings = xTaskGetMPUSettings( pxCurrentTCB );
564             pulSystemCallStack = pxMpuSettings->xSystemCallStackInfo.pulSystemCallStack;
565
566             /* This is not NULL only for the duration of the system call. */
567             configASSERT( pxMpuSettings->xSystemCallStackInfo.pulTaskStack == NULL );
568
569             if( ( ulLR & portEXC_RETURN_STACK_FRAME_TYPE_MASK ) == 0UL )
570             {
571                 /* Extended frame i.e. FPU in use. */
572                 ulStackFrameSize = 26;
573                 __asm volatile (
574                     " vpush {s0}         \n" /* Trigger lazy stacking. */
575                     " vpop  {s0}         \n" /* Nullify the affect of the above instruction. */
576                     ::: "memory"
577                     );
578             }
579             else
580             {
581                 /* Standard frame i.e. FPU not in use. */
582                 ulStackFrameSize = 8;
583             }
584
585             /* Make space on the system call stack for the stack frame and
586              * the parameter passed on the stack. We only need to copy one
587              * parameter but we still reserve 2 spaces to keep the stack
588              * double word aligned. */
589             pulSystemCallStack = pulSystemCallStack - ulStackFrameSize - 2UL;
590
591             /* Copy the stack frame. */
592             for( i = 0; i < ulStackFrameSize; i++ )
593             {
594                 pulSystemCallStack[ i ] = pulTaskStack[ i ];
595             }
596
597             /* Copy the parameter which is passed the stack. */
598             if( ( pulTaskStack[ portOFFSET_TO_PSR ] & portPSR_STACK_PADDING_MASK ) == portPSR_STACK_PADDING_MASK )
599             {
600                 pulSystemCallStack[ ulStackFrameSize ] = pulTaskStack[ ulStackFrameSize + 1 ];
601
602                 /* Record if the hardware used padding to force the stack pointer
603                  * to be double word aligned. */
604                 pxMpuSettings->ulTaskFlags |= portSTACK_FRAME_HAS_PADDING_FLAG;
605             }
606             else
607             {
608                 pulSystemCallStack[ ulStackFrameSize ] = pulTaskStack[ ulStackFrameSize ];
609
610                 /* Record if the hardware used padding to force the stack pointer
611                  * to be double word aligned. */
612                 pxMpuSettings->ulTaskFlags &= ( ~portSTACK_FRAME_HAS_PADDING_FLAG );
613             }
614
615             /* Use the pulSystemCallStack in thread mode. */
616             __asm volatile ( "msr psp, %0" : : "r" ( pulSystemCallStack ) );
617
618             /* Raise the privilege for the duration of the system call. */
619             __asm volatile (
620                 " mrs r1, control     \n" /* Obtain current control value. */
621                 " bic r1, #1          \n" /* Clear nPRIV bit. */
622                 " msr control, r1     \n" /* Write back new control value. */
623                 ::: "r1", "memory"
624                 );
625
626             /* Remember the location where we should copy the stack frame when we exit from
627              * the system call. */
628             pxMpuSettings->xSystemCallStackInfo.pulTaskStack = pulTaskStack + ulStackFrameSize;
629
630             /* Store the value of the Link Register before the SVC was raised. We need to
631              * restore it when we exit from the system call. */
632             pxMpuSettings->xSystemCallStackInfo.ulLinkRegisterAtSystemCallEntry = pulTaskStack[ portOFFSET_TO_LR ];
633
634             /* We ensure in pxPortInitialiseStack that the system call stack is
635              * double word aligned and therefore, there is no need of padding.
636              * Clear the bit[9] of stacked xPSR. */
637             pulSystemCallStack[ portOFFSET_TO_PSR ] &= ( ~portPSR_STACK_PADDING_MASK );
638         }
639     }
640
641 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
642 /*-----------------------------------------------------------*/
643
644 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
645
646     void vSystemCallExit( uint32_t * pulSystemCallStack,
647                           uint32_t ulLR ) /* PRIVILEGED_FUNCTION */
648     {
649         extern TaskHandle_t pxCurrentTCB;
650         xMPU_SETTINGS * pxMpuSettings;
651         uint32_t * pulTaskStack;
652         uint32_t ulStackFrameSize, ulSystemCallLocation, i;
653
654         #if defined( __ARMCC_VERSION )
655
656             /* Declaration when these variable are defined in code instead of being
657              * exported from linker scripts. */
658             extern uint32_t * __syscalls_flash_start__;
659             extern uint32_t * __syscalls_flash_end__;
660         #else
661             /* Declaration when these variable are exported from linker scripts. */
662             extern uint32_t __syscalls_flash_start__[];
663             extern uint32_t __syscalls_flash_end__[];
664         #endif /* #if defined( __ARMCC_VERSION ) */
665
666         ulSystemCallLocation = pulSystemCallStack[ portOFFSET_TO_PC ];
667
668         /* If the request did not come from the system call section, do nothing. */
669         if( ( ulSystemCallLocation >= ( uint32_t ) __syscalls_flash_start__ ) &&
670             ( ulSystemCallLocation <= ( uint32_t ) __syscalls_flash_end__ ) )
671         {
672             pxMpuSettings = xTaskGetMPUSettings( pxCurrentTCB );
673             pulTaskStack = pxMpuSettings->xSystemCallStackInfo.pulTaskStack;
674
675             if( ( ulLR & portEXC_RETURN_STACK_FRAME_TYPE_MASK ) == 0UL )
676             {
677                 /* Extended frame i.e. FPU in use. */
678                 ulStackFrameSize = 26;
679                 __asm volatile (
680                     " vpush {s0}         \n" /* Trigger lazy stacking. */
681                     " vpop  {s0}         \n" /* Nullify the affect of the above instruction. */
682                     ::: "memory"
683                     );
684             }
685             else
686             {
687                 /* Standard frame i.e. FPU not in use. */
688                 ulStackFrameSize = 8;
689             }
690
691             /* Make space on the task stack for the stack frame. */
692             pulTaskStack = pulTaskStack - ulStackFrameSize;
693
694             /* Copy the stack frame. */
695             for( i = 0; i < ulStackFrameSize; i++ )
696             {
697                 pulTaskStack[ i ] = pulSystemCallStack[ i ];
698             }
699
700             /* Use the pulTaskStack in thread mode. */
701             __asm volatile ( "msr psp, %0" : : "r" ( pulTaskStack ) );
702
703             /* Drop the privilege before returning to the thread mode. */
704             __asm volatile (
705                 " mrs r1, control     \n" /* Obtain current control value. */
706                 " orr r1, #1          \n" /* Set nPRIV bit. */
707                 " msr control, r1     \n" /* Write back new control value. */
708                 ::: "r1", "memory"
709                 );
710
711             /* Restore the stacked link register to what it was at the time of
712              * system call entry. */
713             pulTaskStack[ portOFFSET_TO_LR ] = pxMpuSettings->xSystemCallStackInfo.ulLinkRegisterAtSystemCallEntry;
714
715             /* If the hardware used padding to force the stack pointer
716              * to be double word aligned, set the stacked xPSR bit[9],
717              * otherwise clear it. */
718             if( ( pxMpuSettings->ulTaskFlags & portSTACK_FRAME_HAS_PADDING_FLAG ) == portSTACK_FRAME_HAS_PADDING_FLAG )
719             {
720                 pulTaskStack[ portOFFSET_TO_PSR ] |= portPSR_STACK_PADDING_MASK;
721             }
722             else
723             {
724                 pulTaskStack[ portOFFSET_TO_PSR ] &= ( ~portPSR_STACK_PADDING_MASK );
725             }
726
727             /* This is not NULL only for the duration of the system call. */
728             pxMpuSettings->xSystemCallStackInfo.pulTaskStack = NULL;
729         }
730     }
731
732 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
733 /*-----------------------------------------------------------*/
734
735 BaseType_t xPortIsTaskPrivileged( void ) /* PRIVILEGED_FUNCTION */
736 {
737     BaseType_t xTaskIsPrivileged = pdFALSE;
738     const xMPU_SETTINGS * xTaskMpuSettings = xTaskGetMPUSettings( NULL ); /* Calling task's MPU settings. */
739
740     if( ( xTaskMpuSettings->ulTaskFlags & portTASK_IS_PRIVILEGED_FLAG ) == portTASK_IS_PRIVILEGED_FLAG )
741     {
742         xTaskIsPrivileged = pdTRUE;
743     }
744
745     return xTaskIsPrivileged;
746 }
747 /*-----------------------------------------------------------*/
748
749 void vPortSwitchToUserMode( void )
750 {
751     /* Load the current task's MPU settings from its TCB. */
752     xMPU_SETTINGS * xTaskMpuSettings = xTaskGetMPUSettings( NULL );
753
754     /* Mark the task as unprivileged. */
755     xTaskMpuSettings->ulTaskFlags &= ( ~( portTASK_IS_PRIVILEGED_FLAG ) );
756
757     /* Lower the processor's privilege level. */
758     vResetPrivilege();
759 }
760 /*-----------------------------------------------------------*/
761
762 /*
763  * See header file for description.
764  */
765 BaseType_t xPortStartScheduler( void )
766 {
767     /* Errata 837070 workaround must only be enabled on Cortex-M7 r0p0
768      * and r0p1 cores. */
769     #if ( configENABLE_ERRATA_837070_WORKAROUND == 1 )
770         configASSERT( ( portCPUID == portCORTEX_M7_r0p1_ID ) || ( portCPUID == portCORTEX_M7_r0p0_ID ) );
771     #else
772
773         /* When using this port on a Cortex-M7 r0p0 or r0p1 core, define
774          * configENABLE_ERRATA_837070_WORKAROUND to 1 in your
775          * FreeRTOSConfig.h. */
776         configASSERT( portCPUID != portCORTEX_M7_r0p1_ID );
777         configASSERT( portCPUID != portCORTEX_M7_r0p0_ID );
778     #endif
779
780     #if ( configASSERT_DEFINED == 1 )
781     {
782         volatile uint8_t ucOriginalPriority;
783         volatile uint32_t ulImplementedPrioBits = 0;
784         volatile uint8_t * const pucFirstUserPriorityRegister = ( volatile uint8_t * const ) ( portNVIC_IP_REGISTERS_OFFSET_16 + portFIRST_USER_INTERRUPT_NUMBER );
785         volatile uint8_t ucMaxPriorityValue;
786
787         /* Determine the maximum priority from which ISR safe FreeRTOS API
788          * functions can be called.  ISR safe functions are those that end in
789          * "FromISR".  FreeRTOS maintains separate thread and ISR API functions to
790          * ensure interrupt entry is as fast and simple as possible.
791          *
792          * Save the interrupt priority value that is about to be clobbered. */
793         ucOriginalPriority = *pucFirstUserPriorityRegister;
794
795         /* Determine the number of priority bits available.  First write to all
796          * possible bits. */
797         *pucFirstUserPriorityRegister = portMAX_8_BIT_VALUE;
798
799         /* Read the value back to see how many bits stuck. */
800         ucMaxPriorityValue = *pucFirstUserPriorityRegister;
801
802         /* Use the same mask on the maximum system call priority. */
803         ucMaxSysCallPriority = configMAX_SYSCALL_INTERRUPT_PRIORITY & ucMaxPriorityValue;
804
805         /* Check that the maximum system call priority is nonzero after
806          * accounting for the number of priority bits supported by the
807          * hardware. A priority of 0 is invalid because setting the BASEPRI
808          * register to 0 unmasks all interrupts, and interrupts with priority 0
809          * cannot be masked using BASEPRI.
810          * See https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
811         configASSERT( ucMaxSysCallPriority );
812
813         /* Check that the bits not implemented in hardware are zero in
814          * configMAX_SYSCALL_INTERRUPT_PRIORITY. */
815         configASSERT( ( configMAX_SYSCALL_INTERRUPT_PRIORITY & ( uint8_t ) ( ~( uint32_t ) ucMaxPriorityValue ) ) == 0U );
816
817         /* Calculate the maximum acceptable priority group value for the number
818          * of bits read back. */
819
820         while( ( ucMaxPriorityValue & portTOP_BIT_OF_BYTE ) == portTOP_BIT_OF_BYTE )
821         {
822             ulImplementedPrioBits++;
823             ucMaxPriorityValue <<= ( uint8_t ) 0x01;
824         }
825
826         if( ulImplementedPrioBits == 8 )
827         {
828             /* When the hardware implements 8 priority bits, there is no way for
829              * the software to configure PRIGROUP to not have sub-priorities. As
830              * a result, the least significant bit is always used for sub-priority
831              * and there are 128 preemption priorities and 2 sub-priorities.
832              *
833              * This may cause some confusion in some cases - for example, if
834              * configMAX_SYSCALL_INTERRUPT_PRIORITY is set to 5, both 5 and 4
835              * priority interrupts will be masked in Critical Sections as those
836              * are at the same preemption priority. This may appear confusing as
837              * 4 is higher (numerically lower) priority than
838              * configMAX_SYSCALL_INTERRUPT_PRIORITY and therefore, should not
839              * have been masked. Instead, if we set configMAX_SYSCALL_INTERRUPT_PRIORITY
840              * to 4, this confusion does not happen and the behaviour remains the same.
841              *
842              * The following assert ensures that the sub-priority bit in the
843              * configMAX_SYSCALL_INTERRUPT_PRIORITY is clear to avoid the above mentioned
844              * confusion. */
845             configASSERT( ( configMAX_SYSCALL_INTERRUPT_PRIORITY & 0x1U ) == 0U );
846             ulMaxPRIGROUPValue = 0;
847         }
848         else
849         {
850             ulMaxPRIGROUPValue = portMAX_PRIGROUP_BITS - ulImplementedPrioBits;
851         }
852
853         /* Shift the priority group value back to its position within the AIRCR
854          * register. */
855         ulMaxPRIGROUPValue <<= portPRIGROUP_SHIFT;
856         ulMaxPRIGROUPValue &= portPRIORITY_GROUP_MASK;
857
858         /* Restore the clobbered interrupt priority register to its original
859          * value. */
860         *pucFirstUserPriorityRegister = ucOriginalPriority;
861     }
862     #endif /* configASSERT_DEFINED */
863
864     /* Make PendSV and SysTick the lowest priority interrupts. */
865     portNVIC_SHPR3_REG |= portNVIC_PENDSV_PRI;
866     portNVIC_SHPR3_REG |= portNVIC_SYSTICK_PRI;
867
868     /* Configure the regions in the MPU that are common to all tasks. */
869     prvSetupMPU();
870
871     /* Start the timer that generates the tick ISR.  Interrupts are disabled
872      * here already. */
873     vPortSetupTimerInterrupt();
874
875     /* Initialise the critical nesting count ready for the first task. */
876     uxCriticalNesting = 0;
877
878     /* Ensure the VFP is enabled - it should be anyway. */
879     vPortEnableVFP();
880
881     /* Lazy save always. */
882     *( portFPCCR ) |= portASPEN_AND_LSPEN_BITS;
883
884     /* Start the first task. */
885     vPortStartFirstTask();
886
887     /* Should not get here! */
888     return 0;
889 }
890 /*-----------------------------------------------------------*/
891
892 void vPortEndScheduler( void )
893 {
894     /* Not implemented in ports where there is nothing to return to.
895      * Artificially force an assert. */
896     configASSERT( uxCriticalNesting == 1000UL );
897 }
898 /*-----------------------------------------------------------*/
899
900 void vPortEnterCritical( void )
901 {
902     #if ( configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS == 1 )
903         if( portIS_PRIVILEGED() == pdFALSE )
904         {
905             portRAISE_PRIVILEGE();
906             portMEMORY_BARRIER();
907
908             portDISABLE_INTERRUPTS();
909             uxCriticalNesting++;
910
911             /* This is not the interrupt safe version of the enter critical function so
912              * assert() if it is being called from an interrupt context.  Only API
913              * functions that end in "FromISR" can be used in an interrupt.  Only assert if
914              * the critical nesting count is 1 to protect against recursive calls if the
915              * assert function also uses a critical section. */
916             if( uxCriticalNesting == 1 )
917             {
918                 configASSERT( ( portNVIC_INT_CTRL_REG & portVECTACTIVE_MASK ) == 0 );
919             }
920
921             portMEMORY_BARRIER();
922
923             portRESET_PRIVILEGE();
924             portMEMORY_BARRIER();
925         }
926         else
927         {
928             portDISABLE_INTERRUPTS();
929             uxCriticalNesting++;
930
931             /* This is not the interrupt safe version of the enter critical function so
932              * assert() if it is being called from an interrupt context.  Only API
933              * functions that end in "FromISR" can be used in an interrupt.  Only assert if
934              * the critical nesting count is 1 to protect against recursive calls if the
935              * assert function also uses a critical section. */
936             if( uxCriticalNesting == 1 )
937             {
938                 configASSERT( ( portNVIC_INT_CTRL_REG & portVECTACTIVE_MASK ) == 0 );
939             }
940         }
941     #else /* if ( configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS == 1 ) */
942         portDISABLE_INTERRUPTS();
943         uxCriticalNesting++;
944
945         /* This is not the interrupt safe version of the enter critical function so
946          * assert() if it is being called from an interrupt context.  Only API
947          * functions that end in "FromISR" can be used in an interrupt.  Only assert if
948          * the critical nesting count is 1 to protect against recursive calls if the
949          * assert function also uses a critical section. */
950         if( uxCriticalNesting == 1 )
951         {
952             configASSERT( ( portNVIC_INT_CTRL_REG & portVECTACTIVE_MASK ) == 0 );
953         }
954     #endif /* if ( configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS == 1 ) */
955 }
956 /*-----------------------------------------------------------*/
957
958 void vPortExitCritical( void )
959 {
960     #if ( configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS == 1 )
961         if( portIS_PRIVILEGED() == pdFALSE )
962         {
963             portRAISE_PRIVILEGE();
964             portMEMORY_BARRIER();
965
966             configASSERT( uxCriticalNesting );
967             uxCriticalNesting--;
968
969             if( uxCriticalNesting == 0 )
970             {
971                 portENABLE_INTERRUPTS();
972             }
973
974             portMEMORY_BARRIER();
975
976             portRESET_PRIVILEGE();
977             portMEMORY_BARRIER();
978         }
979         else
980         {
981             configASSERT( uxCriticalNesting );
982             uxCriticalNesting--;
983
984             if( uxCriticalNesting == 0 )
985             {
986                 portENABLE_INTERRUPTS();
987             }
988         }
989     #else /* if ( configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS == 1 ) */
990         configASSERT( uxCriticalNesting );
991         uxCriticalNesting--;
992
993         if( uxCriticalNesting == 0 )
994         {
995             portENABLE_INTERRUPTS();
996         }
997     #endif /* if ( configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS == 1 ) */
998 }
999 /*-----------------------------------------------------------*/
1000
1001 void xPortSysTickHandler( void )
1002 {
1003     /* The SysTick runs at the lowest interrupt priority, so when this interrupt
1004      * executes all interrupts must be unmasked.  There is therefore no need to
1005      * save and then restore the interrupt mask value as its value is already
1006      * known. */
1007     portDISABLE_INTERRUPTS();
1008     traceISR_ENTER();
1009     {
1010         /* Increment the RTOS tick. */
1011         if( xTaskIncrementTick() != pdFALSE )
1012         {
1013             traceISR_EXIT_TO_SCHEDULER();
1014
1015             /* A context switch is required.  Context switching is performed in
1016              * the PendSV interrupt.  Pend the PendSV interrupt. */
1017             portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;
1018         }
1019         else
1020         {
1021             traceISR_EXIT();
1022         }
1023     }
1024     portENABLE_INTERRUPTS();
1025 }
1026 /*-----------------------------------------------------------*/
1027
1028 /*
1029  * Setup the systick timer to generate the tick interrupts at the required
1030  * frequency.
1031  */
1032 __weak void vPortSetupTimerInterrupt( void )
1033 {
1034     /* Stop and clear the SysTick. */
1035     portNVIC_SYSTICK_CTRL_REG = 0UL;
1036     portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
1037
1038     /* Configure SysTick to interrupt at the requested rate. */
1039     portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;
1040     portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT );
1041 }
1042 /*-----------------------------------------------------------*/
1043
1044 static void prvSetupMPU( void )
1045 {
1046     extern uint32_t __privileged_functions_start__[];
1047     extern uint32_t __privileged_functions_end__[];
1048     extern uint32_t __FLASH_segment_start__[];
1049     extern uint32_t __FLASH_segment_end__[];
1050     extern uint32_t __privileged_data_start__[];
1051     extern uint32_t __privileged_data_end__[];
1052
1053     /* The only permitted number of regions are 8 or 16. */
1054     configASSERT( ( configTOTAL_MPU_REGIONS == 8 ) || ( configTOTAL_MPU_REGIONS == 16 ) );
1055
1056     /* Ensure that the configTOTAL_MPU_REGIONS is configured correctly. */
1057     configASSERT( portMPU_TYPE_REG == portEXPECTED_MPU_TYPE_VALUE );
1058
1059     /* Check the expected MPU is present. */
1060     if( portMPU_TYPE_REG == portEXPECTED_MPU_TYPE_VALUE )
1061     {
1062         /* First setup the unprivileged flash for unprivileged read only access. */
1063         portMPU_REGION_BASE_ADDRESS_REG = ( ( uint32_t ) __FLASH_segment_start__ ) | /* Base address. */
1064                                           ( portMPU_REGION_VALID ) |
1065                                           ( portUNPRIVILEGED_FLASH_REGION );
1066
1067         portMPU_REGION_ATTRIBUTE_REG = ( portMPU_REGION_READ_ONLY ) |
1068                                        ( ( configTEX_S_C_B_FLASH & portMPU_RASR_TEX_S_C_B_MASK ) << portMPU_RASR_TEX_S_C_B_LOCATION ) |
1069                                        ( prvGetMPURegionSizeSetting( ( uint32_t ) __FLASH_segment_end__ - ( uint32_t ) __FLASH_segment_start__ ) ) |
1070                                        ( portMPU_REGION_ENABLE );
1071
1072         /* Setup the privileged flash for privileged only access.  This is where
1073          * the kernel code is placed. */
1074         portMPU_REGION_BASE_ADDRESS_REG = ( ( uint32_t ) __privileged_functions_start__ ) | /* Base address. */
1075                                           ( portMPU_REGION_VALID ) |
1076                                           ( portPRIVILEGED_FLASH_REGION );
1077
1078         portMPU_REGION_ATTRIBUTE_REG = ( portMPU_REGION_PRIVILEGED_READ_ONLY ) |
1079                                        ( ( configTEX_S_C_B_FLASH & portMPU_RASR_TEX_S_C_B_MASK ) << portMPU_RASR_TEX_S_C_B_LOCATION ) |
1080                                        ( prvGetMPURegionSizeSetting( ( uint32_t ) __privileged_functions_end__ - ( uint32_t ) __privileged_functions_start__ ) ) |
1081                                        ( portMPU_REGION_ENABLE );
1082
1083         /* Setup the privileged data RAM region.  This is where the kernel data
1084          * is placed. */
1085         portMPU_REGION_BASE_ADDRESS_REG = ( ( uint32_t ) __privileged_data_start__ ) | /* Base address. */
1086                                           ( portMPU_REGION_VALID ) |
1087                                           ( portPRIVILEGED_RAM_REGION );
1088
1089         portMPU_REGION_ATTRIBUTE_REG = ( portMPU_REGION_PRIVILEGED_READ_WRITE ) |
1090                                        ( portMPU_REGION_EXECUTE_NEVER ) |
1091                                        ( ( configTEX_S_C_B_SRAM & portMPU_RASR_TEX_S_C_B_MASK ) << portMPU_RASR_TEX_S_C_B_LOCATION ) |
1092                                        prvGetMPURegionSizeSetting( ( uint32_t ) __privileged_data_end__ - ( uint32_t ) __privileged_data_start__ ) |
1093                                        ( portMPU_REGION_ENABLE );
1094
1095         /* By default allow everything to access the general peripherals.  The
1096          * system peripherals and registers are protected. */
1097         portMPU_REGION_BASE_ADDRESS_REG = ( portPERIPHERALS_START_ADDRESS ) |
1098                                           ( portMPU_REGION_VALID ) |
1099                                           ( portGENERAL_PERIPHERALS_REGION );
1100
1101         portMPU_REGION_ATTRIBUTE_REG = ( portMPU_REGION_READ_WRITE | portMPU_REGION_EXECUTE_NEVER ) |
1102                                        ( prvGetMPURegionSizeSetting( portPERIPHERALS_END_ADDRESS - portPERIPHERALS_START_ADDRESS ) ) |
1103                                        ( portMPU_REGION_ENABLE );
1104
1105         /* Enable the memory fault exception. */
1106         portNVIC_SYS_CTRL_STATE_REG |= portNVIC_MEM_FAULT_ENABLE;
1107
1108         /* Enable the MPU with the background region configured. */
1109         portMPU_CTRL_REG |= ( portMPU_ENABLE | portMPU_BACKGROUND_ENABLE );
1110     }
1111 }
1112 /*-----------------------------------------------------------*/
1113
1114 static uint32_t prvGetMPURegionSizeSetting( uint32_t ulActualSizeInBytes )
1115 {
1116     uint32_t ulRegionSize, ulReturnValue = 4;
1117
1118     /* 32 is the smallest region size, 31 is the largest valid value for
1119      * ulReturnValue. */
1120     for( ulRegionSize = 32UL; ulReturnValue < 31UL; ( ulRegionSize <<= 1UL ) )
1121     {
1122         if( ulActualSizeInBytes <= ulRegionSize )
1123         {
1124             break;
1125         }
1126         else
1127         {
1128             ulReturnValue++;
1129         }
1130     }
1131
1132     /* Shift the code by one before returning so it can be written directly
1133      * into the the correct bit position of the attribute register. */
1134     return( ulReturnValue << 1UL );
1135 }
1136 /*-----------------------------------------------------------*/
1137
1138 void vPortStoreTaskMPUSettings( xMPU_SETTINGS * xMPUSettings,
1139                                 const struct xMEMORY_REGION * const xRegions,
1140                                 StackType_t * pxBottomOfStack,
1141                                 uint32_t ulStackDepth )
1142 {
1143     extern uint32_t __SRAM_segment_start__[];
1144     extern uint32_t __SRAM_segment_end__[];
1145     extern uint32_t __privileged_data_start__[];
1146     extern uint32_t __privileged_data_end__[];
1147     int32_t lIndex;
1148     uint32_t ul;
1149
1150     if( xRegions == NULL )
1151     {
1152         /* No MPU regions are specified so allow access to all RAM. */
1153         xMPUSettings->xRegion[ 0 ].ulRegionBaseAddress =
1154             ( ( uint32_t ) __SRAM_segment_start__ ) | /* Base address. */
1155             ( portMPU_REGION_VALID ) |
1156             ( portSTACK_REGION );                     /* Region number. */
1157
1158         xMPUSettings->xRegion[ 0 ].ulRegionAttribute =
1159             ( portMPU_REGION_READ_WRITE ) |
1160             ( portMPU_REGION_EXECUTE_NEVER ) |
1161             ( ( configTEX_S_C_B_SRAM & portMPU_RASR_TEX_S_C_B_MASK ) << portMPU_RASR_TEX_S_C_B_LOCATION ) |
1162             ( prvGetMPURegionSizeSetting( ( uint32_t ) __SRAM_segment_end__ - ( uint32_t ) __SRAM_segment_start__ ) ) |
1163             ( portMPU_REGION_ENABLE );
1164
1165         xMPUSettings->xRegionSettings[ 0 ].ulRegionStartAddress = ( uint32_t ) __SRAM_segment_start__;
1166         xMPUSettings->xRegionSettings[ 0 ].ulRegionEndAddress = ( uint32_t ) __SRAM_segment_end__;
1167         xMPUSettings->xRegionSettings[ 0 ].ulRegionPermissions = ( tskMPU_READ_PERMISSION |
1168                                                                    tskMPU_WRITE_PERMISSION );
1169
1170         /* Invalidate user configurable regions. */
1171         for( ul = 1UL; ul <= portNUM_CONFIGURABLE_REGIONS; ul++ )
1172         {
1173             xMPUSettings->xRegion[ ul ].ulRegionBaseAddress = ( ( ul - 1UL ) | portMPU_REGION_VALID );
1174             xMPUSettings->xRegion[ ul ].ulRegionAttribute = 0UL;
1175             xMPUSettings->xRegionSettings[ ul ].ulRegionStartAddress = 0UL;
1176             xMPUSettings->xRegionSettings[ ul ].ulRegionEndAddress = 0UL;
1177             xMPUSettings->xRegionSettings[ ul ].ulRegionPermissions = 0UL;
1178         }
1179     }
1180     else
1181     {
1182         /* This function is called automatically when the task is created - in
1183          * which case the stack region parameters will be valid.  At all other
1184          * times the stack parameters will not be valid and it is assumed that the
1185          * stack region has already been configured. */
1186         if( ulStackDepth > 0 )
1187         {
1188             /* Define the region that allows access to the stack. */
1189             xMPUSettings->xRegion[ 0 ].ulRegionBaseAddress =
1190                 ( ( uint32_t ) pxBottomOfStack ) |
1191                 ( portMPU_REGION_VALID ) |
1192                 ( portSTACK_REGION ); /* Region number. */
1193
1194             xMPUSettings->xRegion[ 0 ].ulRegionAttribute =
1195                 ( portMPU_REGION_READ_WRITE ) |
1196                 ( portMPU_REGION_EXECUTE_NEVER ) |
1197                 ( prvGetMPURegionSizeSetting( ulStackDepth * ( uint32_t ) sizeof( StackType_t ) ) ) |
1198                 ( ( configTEX_S_C_B_SRAM & portMPU_RASR_TEX_S_C_B_MASK ) << portMPU_RASR_TEX_S_C_B_LOCATION ) |
1199                 ( portMPU_REGION_ENABLE );
1200
1201             xMPUSettings->xRegionSettings[ 0 ].ulRegionStartAddress = ( uint32_t ) pxBottomOfStack;
1202             xMPUSettings->xRegionSettings[ 0 ].ulRegionEndAddress = ( uint32_t ) ( ( uint32_t ) ( pxBottomOfStack ) +
1203                                                                                    ( ulStackDepth * ( uint32_t ) sizeof( StackType_t ) ) - 1UL );
1204             xMPUSettings->xRegionSettings[ 0 ].ulRegionPermissions = ( tskMPU_READ_PERMISSION |
1205                                                                        tskMPU_WRITE_PERMISSION );
1206         }
1207
1208         lIndex = 0;
1209
1210         for( ul = 1UL; ul <= portNUM_CONFIGURABLE_REGIONS; ul++ )
1211         {
1212             if( ( xRegions[ lIndex ] ).ulLengthInBytes > 0UL )
1213             {
1214                 /* Translate the generic region definition contained in
1215                  * xRegions into the CM4 specific MPU settings that are then
1216                  * stored in xMPUSettings. */
1217                 xMPUSettings->xRegion[ ul ].ulRegionBaseAddress =
1218                     ( ( uint32_t ) xRegions[ lIndex ].pvBaseAddress ) |
1219                     ( portMPU_REGION_VALID ) |
1220                     ( ul - 1UL ); /* Region number. */
1221
1222                 xMPUSettings->xRegion[ ul ].ulRegionAttribute =
1223                     ( prvGetMPURegionSizeSetting( xRegions[ lIndex ].ulLengthInBytes ) ) |
1224                     ( xRegions[ lIndex ].ulParameters ) |
1225                     ( portMPU_REGION_ENABLE );
1226
1227                 xMPUSettings->xRegionSettings[ ul ].ulRegionStartAddress = ( uint32_t ) xRegions[ lIndex ].pvBaseAddress;
1228                 xMPUSettings->xRegionSettings[ ul ].ulRegionEndAddress = ( uint32_t ) ( ( uint32_t ) xRegions[ lIndex ].pvBaseAddress + xRegions[ lIndex ].ulLengthInBytes - 1UL );
1229                 xMPUSettings->xRegionSettings[ ul ].ulRegionPermissions = 0UL;
1230
1231                 if( ( ( xRegions[ lIndex ].ulParameters & portMPU_REGION_READ_ONLY ) == portMPU_REGION_READ_ONLY ) ||
1232                     ( ( xRegions[ lIndex ].ulParameters & portMPU_REGION_PRIVILEGED_READ_WRITE_UNPRIV_READ_ONLY ) == portMPU_REGION_PRIVILEGED_READ_WRITE_UNPRIV_READ_ONLY ) )
1233                 {
1234                     xMPUSettings->xRegionSettings[ ul ].ulRegionPermissions = tskMPU_READ_PERMISSION;
1235                 }
1236
1237                 if( ( xRegions[ lIndex ].ulParameters & portMPU_REGION_READ_WRITE ) == portMPU_REGION_READ_WRITE )
1238                 {
1239                     xMPUSettings->xRegionSettings[ ul ].ulRegionPermissions = ( tskMPU_READ_PERMISSION | tskMPU_WRITE_PERMISSION );
1240                 }
1241             }
1242             else
1243             {
1244                 /* Invalidate the region. */
1245                 xMPUSettings->xRegion[ ul ].ulRegionBaseAddress = ( ( ul - 1UL ) | portMPU_REGION_VALID );
1246                 xMPUSettings->xRegion[ ul ].ulRegionAttribute = 0UL;
1247                 xMPUSettings->xRegionSettings[ ul ].ulRegionStartAddress = 0UL;
1248                 xMPUSettings->xRegionSettings[ ul ].ulRegionEndAddress = 0UL;
1249                 xMPUSettings->xRegionSettings[ ul ].ulRegionPermissions = 0UL;
1250             }
1251
1252             lIndex++;
1253         }
1254     }
1255 }
1256 /*-----------------------------------------------------------*/
1257
1258 BaseType_t xPortIsAuthorizedToAccessBuffer( const void * pvBuffer,
1259                                             uint32_t ulBufferLength,
1260                                             uint32_t ulAccessRequested ) /* PRIVILEGED_FUNCTION */
1261
1262 {
1263     uint32_t i, ulBufferStartAddress, ulBufferEndAddress;
1264     BaseType_t xAccessGranted = pdFALSE;
1265     const xMPU_SETTINGS * xTaskMpuSettings = xTaskGetMPUSettings( NULL ); /* Calling task's MPU settings. */
1266
1267     if( ( xTaskMpuSettings->ulTaskFlags & portTASK_IS_PRIVILEGED_FLAG ) == portTASK_IS_PRIVILEGED_FLAG )
1268     {
1269         xAccessGranted = pdTRUE;
1270     }
1271     else
1272     {
1273         if( portADD_UINT32_WILL_OVERFLOW( ( ( uint32_t ) pvBuffer ), ( ulBufferLength - 1UL ) ) == pdFALSE )
1274         {
1275             ulBufferStartAddress = ( uint32_t ) pvBuffer;
1276             ulBufferEndAddress = ( ( ( uint32_t ) pvBuffer ) + ulBufferLength - 1UL );
1277
1278             for( i = 0; i < portTOTAL_NUM_REGIONS_IN_TCB; i++ )
1279             {
1280                 if( portIS_ADDRESS_WITHIN_RANGE( ulBufferStartAddress,
1281                                                  xTaskMpuSettings->xRegionSettings[ i ].ulRegionStartAddress,
1282                                                  xTaskMpuSettings->xRegionSettings[ i ].ulRegionEndAddress ) &&
1283                     portIS_ADDRESS_WITHIN_RANGE( ulBufferEndAddress,
1284                                                  xTaskMpuSettings->xRegionSettings[ i ].ulRegionStartAddress,
1285                                                  xTaskMpuSettings->xRegionSettings[ i ].ulRegionEndAddress ) &&
1286                     portIS_AUTHORIZED( ulAccessRequested, xTaskMpuSettings->xRegionSettings[ i ].ulRegionPermissions ) )
1287                 {
1288                     xAccessGranted = pdTRUE;
1289                     break;
1290                 }
1291             }
1292         }
1293     }
1294
1295     return xAccessGranted;
1296 }
1297 /*-----------------------------------------------------------*/
1298
1299
1300 #if ( configASSERT_DEFINED == 1 )
1301
1302     void vPortValidateInterruptPriority( void )
1303     {
1304         uint32_t ulCurrentInterrupt;
1305         uint8_t ucCurrentPriority;
1306
1307         /* Obtain the number of the currently executing interrupt. */
1308         __asm volatile ( "mrs %0, ipsr" : "=r" ( ulCurrentInterrupt )::"memory" );
1309
1310         /* Is the interrupt number a user defined interrupt? */
1311         if( ulCurrentInterrupt >= portFIRST_USER_INTERRUPT_NUMBER )
1312         {
1313             /* Look up the interrupt's priority. */
1314             ucCurrentPriority = pcInterruptPriorityRegisters[ ulCurrentInterrupt ];
1315
1316             /* The following assertion will fail if a service routine (ISR) for
1317              * an interrupt that has been assigned a priority above
1318              * configMAX_SYSCALL_INTERRUPT_PRIORITY calls an ISR safe FreeRTOS API
1319              * function.  ISR safe FreeRTOS API functions must *only* be called
1320              * from interrupts that have been assigned a priority at or below
1321              * configMAX_SYSCALL_INTERRUPT_PRIORITY.
1322              *
1323              * Numerically low interrupt priority numbers represent logically high
1324              * interrupt priorities, therefore the priority of the interrupt must
1325              * be set to a value equal to or numerically *higher* than
1326              * configMAX_SYSCALL_INTERRUPT_PRIORITY.
1327              *
1328              * Interrupts that  use the FreeRTOS API must not be left at their
1329              * default priority of  zero as that is the highest possible priority,
1330              * which is guaranteed to be above configMAX_SYSCALL_INTERRUPT_PRIORITY,
1331              * and  therefore also guaranteed to be invalid.
1332              *
1333              * FreeRTOS maintains separate thread and ISR API functions to ensure
1334              * interrupt entry is as fast and simple as possible.
1335              *
1336              * The following links provide detailed information:
1337              * https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html
1338              * https://www.FreeRTOS.org/FAQHelp.html */
1339             configASSERT( ucCurrentPriority >= ucMaxSysCallPriority );
1340         }
1341
1342         /* Priority grouping:  The interrupt controller (NVIC) allows the bits
1343          * that define each interrupt's priority to be split between bits that
1344          * define the interrupt's pre-emption priority bits and bits that define
1345          * the interrupt's sub-priority.  For simplicity all bits must be defined
1346          * to be pre-emption priority bits.  The following assertion will fail if
1347          * this is not the case (if some bits represent a sub-priority).
1348          *
1349          * If the application only uses CMSIS libraries for interrupt
1350          * configuration then the correct setting can be achieved on all Cortex-M
1351          * devices by calling NVIC_SetPriorityGrouping( 0 ); before starting the
1352          * scheduler.  Note however that some vendor specific peripheral libraries
1353          * assume a non-zero priority group setting, in which cases using a value
1354          * of zero will result in unpredictable behaviour. */
1355         configASSERT( ( portAIRCR_REG & portPRIORITY_GROUP_MASK ) <= ulMaxPRIGROUPValue );
1356     }
1357
1358 #endif /* configASSERT_DEFINED */
1359 /*-----------------------------------------------------------*/
1360
1361 #if ( ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) )
1362
1363     void vPortGrantAccessToKernelObject( TaskHandle_t xInternalTaskHandle,
1364                                          int32_t lInternalIndexOfKernelObject ) /* PRIVILEGED_FUNCTION */
1365     {
1366         uint32_t ulAccessControlListEntryIndex, ulAccessControlListEntryBit;
1367         xMPU_SETTINGS * xTaskMpuSettings;
1368
1369         ulAccessControlListEntryIndex = ( ( uint32_t ) lInternalIndexOfKernelObject / portACL_ENTRY_SIZE_BITS );
1370         ulAccessControlListEntryBit = ( ( uint32_t ) lInternalIndexOfKernelObject % portACL_ENTRY_SIZE_BITS );
1371
1372         xTaskMpuSettings = xTaskGetMPUSettings( xInternalTaskHandle );
1373
1374         xTaskMpuSettings->ulAccessControlList[ ulAccessControlListEntryIndex ] |= ( 1U << ulAccessControlListEntryBit );
1375     }
1376
1377 #endif /* #if ( ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) ) */
1378 /*-----------------------------------------------------------*/
1379
1380 #if ( ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) )
1381
1382     void vPortRevokeAccessToKernelObject( TaskHandle_t xInternalTaskHandle,
1383                                           int32_t lInternalIndexOfKernelObject ) /* PRIVILEGED_FUNCTION */
1384     {
1385         uint32_t ulAccessControlListEntryIndex, ulAccessControlListEntryBit;
1386         xMPU_SETTINGS * xTaskMpuSettings;
1387
1388         ulAccessControlListEntryIndex = ( ( uint32_t ) lInternalIndexOfKernelObject / portACL_ENTRY_SIZE_BITS );
1389         ulAccessControlListEntryBit = ( ( uint32_t ) lInternalIndexOfKernelObject % portACL_ENTRY_SIZE_BITS );
1390
1391         xTaskMpuSettings = xTaskGetMPUSettings( xInternalTaskHandle );
1392
1393         xTaskMpuSettings->ulAccessControlList[ ulAccessControlListEntryIndex ] &= ~( 1U << ulAccessControlListEntryBit );
1394     }
1395
1396 #endif /* #if ( ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) ) */
1397 /*-----------------------------------------------------------*/
1398
1399 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
1400
1401     #if ( configENABLE_ACCESS_CONTROL_LIST == 1 )
1402
1403         BaseType_t xPortIsAuthorizedToAccessKernelObject( int32_t lInternalIndexOfKernelObject ) /* PRIVILEGED_FUNCTION */
1404         {
1405             uint32_t ulAccessControlListEntryIndex, ulAccessControlListEntryBit;
1406             BaseType_t xAccessGranted = pdFALSE;
1407             const xMPU_SETTINGS * xTaskMpuSettings = xTaskGetMPUSettings( NULL ); /* Calling task's MPU settings. */
1408
1409             ulAccessControlListEntryIndex = ( ( uint32_t ) lInternalIndexOfKernelObject / portACL_ENTRY_SIZE_BITS );
1410             ulAccessControlListEntryBit = ( ( uint32_t ) lInternalIndexOfKernelObject % portACL_ENTRY_SIZE_BITS );
1411
1412             if( ( xTaskMpuSettings->ulTaskFlags & portTASK_IS_PRIVILEGED_FLAG ) == portTASK_IS_PRIVILEGED_FLAG )
1413             {
1414                 xAccessGranted = pdTRUE;
1415             }
1416             else
1417             {
1418                 if( ( xTaskMpuSettings->ulAccessControlList[ ulAccessControlListEntryIndex ] & ( 1U << ulAccessControlListEntryBit ) ) != 0 )
1419                 {
1420                     xAccessGranted = pdTRUE;
1421                 }
1422             }
1423
1424             return xAccessGranted;
1425         }
1426
1427     #else /* #if ( configENABLE_ACCESS_CONTROL_LIST == 1 ) */
1428
1429         BaseType_t xPortIsAuthorizedToAccessKernelObject( int32_t lInternalIndexOfKernelObject ) /* PRIVILEGED_FUNCTION */
1430         {
1431             ( void ) lInternalIndexOfKernelObject;
1432
1433             /* If Access Control List feature is not used, all the tasks have
1434              * access to all the kernel objects. */
1435             return pdTRUE;
1436         }
1437
1438     #endif /* #if ( configENABLE_ACCESS_CONTROL_LIST == 1 ) */
1439
1440 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
1441 /*-----------------------------------------------------------*/