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