]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/GCC/ARM_CA53_64_BIT/port.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Source / portable / GCC / ARM_CA53_64_BIT / port.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /* Standard includes. */\r
29 #include <stdlib.h>\r
30 \r
31 /* Scheduler includes. */\r
32 #include "FreeRTOS.h"\r
33 #include "task.h"\r
34 \r
35 #ifndef configINTERRUPT_CONTROLLER_BASE_ADDRESS\r
36         #error configINTERRUPT_CONTROLLER_BASE_ADDRESS must be defined.  See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\r
37 #endif\r
38 \r
39 #ifndef configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET\r
40         #error configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET must be defined.  See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\r
41 #endif\r
42 \r
43 #ifndef configUNIQUE_INTERRUPT_PRIORITIES\r
44         #error configUNIQUE_INTERRUPT_PRIORITIES must be defined.  See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\r
45 #endif\r
46 \r
47 #ifndef configSETUP_TICK_INTERRUPT\r
48         #error configSETUP_TICK_INTERRUPT() must be defined.  See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\r
49 #endif /* configSETUP_TICK_INTERRUPT */\r
50 \r
51 #ifndef configMAX_API_CALL_INTERRUPT_PRIORITY\r
52         #error configMAX_API_CALL_INTERRUPT_PRIORITY must be defined.  See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\r
53 #endif\r
54 \r
55 #if configMAX_API_CALL_INTERRUPT_PRIORITY == 0\r
56         #error configMAX_API_CALL_INTERRUPT_PRIORITY must not be set to 0\r
57 #endif\r
58 \r
59 #if configMAX_API_CALL_INTERRUPT_PRIORITY > configUNIQUE_INTERRUPT_PRIORITIES\r
60         #error configMAX_API_CALL_INTERRUPT_PRIORITY must be less than or equal to configUNIQUE_INTERRUPT_PRIORITIES as the lower the numeric priority value the higher the logical interrupt priority\r
61 #endif\r
62 \r
63 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1\r
64         /* Check the configuration. */\r
65         #if( configMAX_PRIORITIES > 32 )\r
66                 #error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32.  It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice.\r
67         #endif\r
68 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\r
69 \r
70 /* In case security extensions are implemented. */\r
71 #if configMAX_API_CALL_INTERRUPT_PRIORITY <= ( configUNIQUE_INTERRUPT_PRIORITIES / 2 )\r
72         #error configMAX_API_CALL_INTERRUPT_PRIORITY must be greater than ( configUNIQUE_INTERRUPT_PRIORITIES / 2 )\r
73 #endif\r
74 \r
75 /* Some vendor specific files default configCLEAR_TICK_INTERRUPT() in\r
76 portmacro.h. */\r
77 #ifndef configCLEAR_TICK_INTERRUPT\r
78         #define configCLEAR_TICK_INTERRUPT()\r
79 #endif\r
80 \r
81 /* A critical section is exited when the critical section nesting count reaches\r
82 this value. */\r
83 #define portNO_CRITICAL_NESTING                 ( ( size_t ) 0 )\r
84 \r
85 /* In all GICs 255 can be written to the priority mask register to unmask all\r
86 (but the lowest) interrupt priority. */\r
87 #define portUNMASK_VALUE                                ( 0xFFUL )\r
88 \r
89 /* Tasks are not created with a floating point context, but can be given a\r
90 floating point context after they have been created.  A variable is stored as\r
91 part of the tasks context that holds portNO_FLOATING_POINT_CONTEXT if the task\r
92 does not have an FPU context, or any other value if the task does have an FPU\r
93 context. */\r
94 #define portNO_FLOATING_POINT_CONTEXT   ( ( StackType_t ) 0 )\r
95 \r
96 /* Constants required to setup the initial task context. */\r
97 #define portSP_ELx                                              ( ( StackType_t ) 0x01 )\r
98 #define portSP_EL0                                              ( ( StackType_t ) 0x00 )\r
99 \r
100 #if defined( GUEST )\r
101         #define portEL1                                         ( ( StackType_t ) 0x04 )\r
102         #define portINITIAL_PSTATE                              ( portEL1 | portSP_EL0 )\r
103 #else\r
104         #define portEL3                                         ( ( StackType_t ) 0x0c )\r
105         /* At the time of writing, the BSP only supports EL3. */\r
106         #define portINITIAL_PSTATE                      ( portEL3 | portSP_EL0 )\r
107 #endif\r
108 \r
109 \r
110 /* Used by portASSERT_IF_INTERRUPT_PRIORITY_INVALID() when ensuring the binary\r
111 point is zero. */\r
112 #define portBINARY_POINT_BITS                   ( ( uint8_t ) 0x03 )\r
113 \r
114 /* Masks all bits in the APSR other than the mode bits. */\r
115 #define portAPSR_MODE_BITS_MASK                 ( 0x0C )\r
116 \r
117 /* The I bit in the DAIF bits. */\r
118 #define portDAIF_I                                              ( 0x80 )\r
119 \r
120 /* Macro to unmask all interrupt priorities. */\r
121 #define portCLEAR_INTERRUPT_MASK()                                                                      \\r
122 {                                                                                                                                       \\r
123         portDISABLE_INTERRUPTS();                                                                               \\r
124         portICCPMR_PRIORITY_MASK_REGISTER = portUNMASK_VALUE;                   \\r
125         __asm volatile (        "DSB SY         \n"                                                             \\r
126                                                 "ISB SY         \n" );                                                  \\r
127         portENABLE_INTERRUPTS();                                                                                \\r
128 }\r
129 \r
130 /* Hardware specifics used when sanity checking the configuration. */\r
131 #define portINTERRUPT_PRIORITY_REGISTER_OFFSET          0x400UL\r
132 #define portMAX_8_BIT_VALUE                                                     ( ( uint8_t ) 0xff )\r
133 #define portBIT_0_SET                                                           ( ( uint8_t ) 0x01 )\r
134 \r
135 /*-----------------------------------------------------------*/\r
136 \r
137 /*\r
138  * Starts the first task executing.  This function is necessarily written in\r
139  * assembly code so is implemented in portASM.s.\r
140  */\r
141 extern void vPortRestoreTaskContext( void );\r
142 \r
143 /*-----------------------------------------------------------*/\r
144 \r
145 /* A variable is used to keep track of the critical section nesting.  This\r
146 variable has to be stored as part of the task context and must be initialised to\r
147 a non zero value to ensure interrupts don't inadvertently become unmasked before\r
148 the scheduler starts.  As it is stored as part of the task context it will\r
149 automatically be set to 0 when the first task is started. */\r
150 volatile uint64_t ullCriticalNesting = 9999ULL;\r
151 \r
152 /* Saved as part of the task context.  If ullPortTaskHasFPUContext is non-zero\r
153 then floating point context must be saved and restored for the task. */\r
154 uint64_t ullPortTaskHasFPUContext = pdFALSE;\r
155 \r
156 /* Set to 1 to pend a context switch from an ISR. */\r
157 uint64_t ullPortYieldRequired = pdFALSE;\r
158 \r
159 /* Counts the interrupt nesting depth.  A context switch is only performed if\r
160 if the nesting depth is 0. */\r
161 uint64_t ullPortInterruptNesting = 0;\r
162 \r
163 /* Used in the ASM code. */\r
164 __attribute__(( used )) const uint64_t ullICCEOIR = portICCEOIR_END_OF_INTERRUPT_REGISTER_ADDRESS;\r
165 __attribute__(( used )) const uint64_t ullICCIAR = portICCIAR_INTERRUPT_ACKNOWLEDGE_REGISTER_ADDRESS;\r
166 __attribute__(( used )) const uint64_t ullICCPMR = portICCPMR_PRIORITY_MASK_REGISTER_ADDRESS;\r
167 __attribute__(( used )) const uint64_t ullMaxAPIPriorityMask = ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );\r
168 \r
169 /*-----------------------------------------------------------*/\r
170 \r
171 /*\r
172  * See header file for description.\r
173  */\r
174 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
175 {\r
176         /* Setup the initial stack of the task.  The stack is set exactly as\r
177         expected by the portRESTORE_CONTEXT() macro. */\r
178 \r
179         /* First all the general purpose registers. */\r
180         pxTopOfStack--;\r
181         *pxTopOfStack = 0x0101010101010101ULL;  /* R1 */\r
182         pxTopOfStack--;\r
183         *pxTopOfStack = ( StackType_t ) pvParameters; /* R0 */\r
184         pxTopOfStack--;\r
185         *pxTopOfStack = 0x0303030303030303ULL;  /* R3 */\r
186         pxTopOfStack--;\r
187         *pxTopOfStack = 0x0202020202020202ULL;  /* R2 */\r
188         pxTopOfStack--;\r
189         *pxTopOfStack = 0x0505050505050505ULL;  /* R5 */\r
190         pxTopOfStack--;\r
191         *pxTopOfStack = 0x0404040404040404ULL;  /* R4 */\r
192         pxTopOfStack--;\r
193         *pxTopOfStack = 0x0707070707070707ULL;  /* R7 */\r
194         pxTopOfStack--;\r
195         *pxTopOfStack = 0x0606060606060606ULL;  /* R6 */\r
196         pxTopOfStack--;\r
197         *pxTopOfStack = 0x0909090909090909ULL;  /* R9 */\r
198         pxTopOfStack--;\r
199         *pxTopOfStack = 0x0808080808080808ULL;  /* R8 */\r
200         pxTopOfStack--;\r
201         *pxTopOfStack = 0x1111111111111111ULL;  /* R11 */\r
202         pxTopOfStack--;\r
203         *pxTopOfStack = 0x1010101010101010ULL;  /* R10 */\r
204         pxTopOfStack--;\r
205         *pxTopOfStack = 0x1313131313131313ULL;  /* R13 */\r
206         pxTopOfStack--;\r
207         *pxTopOfStack = 0x1212121212121212ULL;  /* R12 */\r
208         pxTopOfStack--;\r
209         *pxTopOfStack = 0x1515151515151515ULL;  /* R15 */\r
210         pxTopOfStack--;\r
211         *pxTopOfStack = 0x1414141414141414ULL;  /* R14 */\r
212         pxTopOfStack--;\r
213         *pxTopOfStack = 0x1717171717171717ULL;  /* R17 */\r
214         pxTopOfStack--;\r
215         *pxTopOfStack = 0x1616161616161616ULL;  /* R16 */\r
216         pxTopOfStack--;\r
217         *pxTopOfStack = 0x1919191919191919ULL;  /* R19 */\r
218         pxTopOfStack--;\r
219         *pxTopOfStack = 0x1818181818181818ULL;  /* R18 */\r
220         pxTopOfStack--;\r
221         *pxTopOfStack = 0x2121212121212121ULL;  /* R21 */\r
222         pxTopOfStack--;\r
223         *pxTopOfStack = 0x2020202020202020ULL;  /* R20 */\r
224         pxTopOfStack--;\r
225         *pxTopOfStack = 0x2323232323232323ULL;  /* R23 */\r
226         pxTopOfStack--;\r
227         *pxTopOfStack = 0x2222222222222222ULL;  /* R22 */\r
228         pxTopOfStack--;\r
229         *pxTopOfStack = 0x2525252525252525ULL;  /* R25 */\r
230         pxTopOfStack--;\r
231         *pxTopOfStack = 0x2424242424242424ULL;  /* R24 */\r
232         pxTopOfStack--;\r
233         *pxTopOfStack = 0x2727272727272727ULL;  /* R27 */\r
234         pxTopOfStack--;\r
235         *pxTopOfStack = 0x2626262626262626ULL;  /* R26 */\r
236         pxTopOfStack--;\r
237         *pxTopOfStack = 0x2929292929292929ULL;  /* R29 */\r
238         pxTopOfStack--;\r
239         *pxTopOfStack = 0x2828282828282828ULL;  /* R28 */\r
240         pxTopOfStack--;\r
241         *pxTopOfStack = ( StackType_t ) 0x00;   /* XZR - has no effect, used so there are an even number of registers. */\r
242         pxTopOfStack--;\r
243         *pxTopOfStack = ( StackType_t ) 0x00;   /* R30 - procedure call link register. */\r
244         pxTopOfStack--;\r
245 \r
246         *pxTopOfStack = portINITIAL_PSTATE;\r
247         pxTopOfStack--;\r
248 \r
249         *pxTopOfStack = ( StackType_t ) pxCode; /* Exception return address. */\r
250         pxTopOfStack--;\r
251 \r
252         /* The task will start with a critical nesting count of 0 as interrupts are\r
253         enabled. */\r
254         *pxTopOfStack = portNO_CRITICAL_NESTING;\r
255         pxTopOfStack--;\r
256 \r
257         /* The task will start without a floating point context.  A task that uses\r
258         the floating point hardware must call vPortTaskUsesFPU() before executing\r
259         any floating point instructions. */\r
260         *pxTopOfStack = portNO_FLOATING_POINT_CONTEXT;\r
261 \r
262         return pxTopOfStack;\r
263 }\r
264 /*-----------------------------------------------------------*/\r
265 \r
266 BaseType_t xPortStartScheduler( void )\r
267 {\r
268 uint32_t ulAPSR;\r
269 \r
270         #if( configASSERT_DEFINED == 1 )\r
271         {\r
272                 volatile uint32_t ulOriginalPriority;\r
273                 volatile uint8_t * const pucFirstUserPriorityRegister = ( volatile uint8_t * const ) ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + portINTERRUPT_PRIORITY_REGISTER_OFFSET );\r
274                 volatile uint8_t ucMaxPriorityValue;\r
275 \r
276                 /* Determine how many priority bits are implemented in the GIC.\r
277 \r
278                 Save the interrupt priority value that is about to be clobbered. */\r
279                 ulOriginalPriority = *pucFirstUserPriorityRegister;\r
280 \r
281                 /* Determine the number of priority bits available.  First write to\r
282                 all possible bits. */\r
283                 *pucFirstUserPriorityRegister = portMAX_8_BIT_VALUE;\r
284 \r
285                 /* Read the value back to see how many bits stuck. */\r
286                 ucMaxPriorityValue = *pucFirstUserPriorityRegister;\r
287 \r
288                 /* Shift to the least significant bits. */\r
289                 while( ( ucMaxPriorityValue & portBIT_0_SET ) != portBIT_0_SET )\r
290                 {\r
291                         ucMaxPriorityValue >>= ( uint8_t ) 0x01;\r
292                 }\r
293 \r
294                 /* Sanity check configUNIQUE_INTERRUPT_PRIORITIES matches the read\r
295                 value. */\r
296 \r
297                 configASSERT( ucMaxPriorityValue >= portLOWEST_INTERRUPT_PRIORITY );\r
298 \r
299 \r
300                 /* Restore the clobbered interrupt priority register to its original\r
301                 value. */\r
302                 *pucFirstUserPriorityRegister = ulOriginalPriority;\r
303         }\r
304         #endif /* conifgASSERT_DEFINED */\r
305 \r
306 \r
307         /* At the time of writing, the BSP only supports EL3. */\r
308         __asm volatile ( "MRS %0, CurrentEL" : "=r" ( ulAPSR ) );\r
309         ulAPSR &= portAPSR_MODE_BITS_MASK;\r
310 \r
311 #if defined( GUEST )\r
312         #warning Building for execution as a guest under XEN. THIS IS NOT A FULLY TESTED PATH.\r
313         configASSERT( ulAPSR == portEL1 );\r
314         if( ulAPSR == portEL1 )\r
315 #else\r
316         configASSERT( ulAPSR == portEL3 );\r
317         if( ulAPSR == portEL3 )\r
318 #endif\r
319         {\r
320                 /* Only continue if the binary point value is set to its lowest possible\r
321                 setting.  See the comments in vPortValidateInterruptPriority() below for\r
322                 more information. */\r
323                 configASSERT( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE );\r
324 \r
325                 if( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE )\r
326                 {\r
327                         /* Interrupts are turned off in the CPU itself to ensure a tick does\r
328                         not execute     while the scheduler is being started.  Interrupts are\r
329                         automatically turned back on in the CPU when the first task starts\r
330                         executing. */\r
331                         portDISABLE_INTERRUPTS();\r
332 \r
333                         /* Start the timer that generates the tick ISR. */\r
334                         configSETUP_TICK_INTERRUPT();\r
335 \r
336                         /* Start the first task executing. */\r
337                         vPortRestoreTaskContext();\r
338                 }\r
339         }\r
340 \r
341         return 0;\r
342 }\r
343 /*-----------------------------------------------------------*/\r
344 \r
345 void vPortEndScheduler( void )\r
346 {\r
347         /* Not implemented in ports where there is nothing to return to.\r
348         Artificially force an assert. */\r
349         configASSERT( ullCriticalNesting == 1000ULL );\r
350 }\r
351 /*-----------------------------------------------------------*/\r
352 \r
353 void vPortEnterCritical( void )\r
354 {\r
355         /* Mask interrupts up to the max syscall interrupt priority. */\r
356         uxPortSetInterruptMask();\r
357 \r
358         /* Now interrupts are disabled ullCriticalNesting can be accessed\r
359         directly.  Increment ullCriticalNesting to keep a count of how many times\r
360         portENTER_CRITICAL() has been called. */\r
361         ullCriticalNesting++;\r
362 \r
363         /* This is not the interrupt safe version of the enter critical function so\r
364         assert() if it is being called from an interrupt context.  Only API\r
365         functions that end in "FromISR" can be used in an interrupt.  Only assert if\r
366         the critical nesting count is 1 to protect against recursive calls if the\r
367         assert function also uses a critical section. */\r
368         if( ullCriticalNesting == 1ULL )\r
369         {\r
370                 configASSERT( ullPortInterruptNesting == 0 );\r
371         }\r
372 }\r
373 /*-----------------------------------------------------------*/\r
374 \r
375 void vPortExitCritical( void )\r
376 {\r
377         if( ullCriticalNesting > portNO_CRITICAL_NESTING )\r
378         {\r
379                 /* Decrement the nesting count as the critical section is being\r
380                 exited. */\r
381                 ullCriticalNesting--;\r
382 \r
383                 /* If the nesting level has reached zero then all interrupt\r
384                 priorities must be re-enabled. */\r
385                 if( ullCriticalNesting == portNO_CRITICAL_NESTING )\r
386                 {\r
387                         /* Critical nesting has reached zero so all interrupt priorities\r
388                         should be unmasked. */\r
389                         portCLEAR_INTERRUPT_MASK();\r
390                 }\r
391         }\r
392 }\r
393 /*-----------------------------------------------------------*/\r
394 \r
395 void FreeRTOS_Tick_Handler( void )\r
396 {\r
397         /* Must be the lowest possible priority. */\r
398         #if !defined( QEMU )\r
399         {\r
400                 configASSERT( portICCRPR_RUNNING_PRIORITY_REGISTER == ( uint32_t ) ( portLOWEST_USABLE_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) );\r
401         }\r
402         #endif\r
403 \r
404         /* Interrupts should not be enabled before this point. */\r
405         #if( configASSERT_DEFINED == 1 )\r
406         {\r
407                 uint32_t ulMaskBits;\r
408 \r
409                 __asm volatile( "mrs %0, daif" : "=r"( ulMaskBits ) :: "memory" );\r
410                 configASSERT( ( ulMaskBits & portDAIF_I ) != 0 );\r
411         }\r
412         #endif /* configASSERT_DEFINED */\r
413 \r
414         /* Set interrupt mask before altering scheduler structures.   The tick\r
415         handler runs at the lowest priority, so interrupts cannot already be masked,\r
416         so there is no need to save and restore the current mask value.  It is\r
417         necessary to turn off interrupts in the CPU itself while the ICCPMR is being\r
418         updated. */\r
419         portICCPMR_PRIORITY_MASK_REGISTER = ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );\r
420         __asm volatile (        "dsb sy         \n"\r
421                                                 "isb sy         \n" ::: "memory" );\r
422 \r
423         /* Ok to enable interrupts after the interrupt source has been cleared. */\r
424         configCLEAR_TICK_INTERRUPT();\r
425         portENABLE_INTERRUPTS();\r
426 \r
427         /* Increment the RTOS tick. */\r
428         if( xTaskIncrementTick() != pdFALSE )\r
429         {\r
430                 ullPortYieldRequired = pdTRUE;\r
431         }\r
432 \r
433         /* Ensure all interrupt priorities are active again. */\r
434         portCLEAR_INTERRUPT_MASK();\r
435 }\r
436 /*-----------------------------------------------------------*/\r
437 \r
438 void vPortTaskUsesFPU( void )\r
439 {\r
440         /* A task is registering the fact that it needs an FPU context.  Set the\r
441         FPU flag (which is saved as part of the task context). */\r
442         ullPortTaskHasFPUContext = pdTRUE;\r
443 \r
444         /* Consider initialising the FPSR here - but probably not necessary in\r
445         AArch64. */\r
446 }\r
447 /*-----------------------------------------------------------*/\r
448 \r
449 void vPortClearInterruptMask( UBaseType_t uxNewMaskValue )\r
450 {\r
451         if( uxNewMaskValue == pdFALSE )\r
452         {\r
453                 portCLEAR_INTERRUPT_MASK();\r
454         }\r
455 }\r
456 /*-----------------------------------------------------------*/\r
457 \r
458 UBaseType_t uxPortSetInterruptMask( void )\r
459 {\r
460 uint32_t ulReturn;\r
461 \r
462         /* Interrupt in the CPU must be turned off while the ICCPMR is being\r
463         updated. */\r
464         portDISABLE_INTERRUPTS();\r
465         if( portICCPMR_PRIORITY_MASK_REGISTER == ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) )\r
466         {\r
467                 /* Interrupts were already masked. */\r
468                 ulReturn = pdTRUE;\r
469         }\r
470         else\r
471         {\r
472                 ulReturn = pdFALSE;\r
473                 portICCPMR_PRIORITY_MASK_REGISTER = ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );\r
474                 __asm volatile (        "dsb sy         \n"\r
475                                                         "isb sy         \n" ::: "memory" );\r
476         }\r
477         portENABLE_INTERRUPTS();\r
478 \r
479         return ulReturn;\r
480 }\r
481 /*-----------------------------------------------------------*/\r
482 \r
483 #if( configASSERT_DEFINED == 1 )\r
484 \r
485         void vPortValidateInterruptPriority( void )\r
486         {\r
487                 /* The following assertion will fail if a service routine (ISR) for\r
488                 an interrupt that has been assigned a priority above\r
489                 configMAX_SYSCALL_INTERRUPT_PRIORITY calls an ISR safe FreeRTOS API\r
490                 function.  ISR safe FreeRTOS API functions must *only* be called\r
491                 from interrupts that have been assigned a priority at or below\r
492                 configMAX_SYSCALL_INTERRUPT_PRIORITY.\r
493 \r
494                 Numerically low interrupt priority numbers represent logically high\r
495                 interrupt priorities, therefore the priority of the interrupt must\r
496                 be set to a value equal to or numerically *higher* than\r
497                 configMAX_SYSCALL_INTERRUPT_PRIORITY.\r
498 \r
499                 FreeRTOS maintains separate thread and ISR API functions to ensure\r
500                 interrupt entry is as fast and simple as possible. */\r
501                 configASSERT( portICCRPR_RUNNING_PRIORITY_REGISTER >= ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) );\r
502 \r
503                 /* Priority grouping:  The interrupt controller (GIC) allows the bits\r
504                 that define each interrupt's priority to be split between bits that\r
505                 define the interrupt's pre-emption priority bits and bits that define\r
506                 the interrupt's sub-priority.  For simplicity all bits must be defined\r
507                 to be pre-emption priority bits.  The following assertion will fail if\r
508                 this is not the case (if some bits represent a sub-priority).\r
509 \r
510                 The priority grouping is configured by the GIC's binary point register\r
511                 (ICCBPR).  Writting 0 to ICCBPR will ensure it is set to its lowest\r
512                 possible value (which may be above 0). */\r
513                 configASSERT( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE );\r
514         }\r
515 \r
516 #endif /* configASSERT_DEFINED */\r
517 /*-----------------------------------------------------------*/\r
518 \r