]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/GCC/ARM_CA53_64_BIT/port.c
Add additional memory barriers into ARM GCC asm code to ensure no re-ordering across...
[freertos] / FreeRTOS / Source / portable / GCC / ARM_CA53_64_BIT / port.c
1 /*\r
2     FreeRTOS V9.0.1 - Copyright (C) 2017 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /* Standard includes. */\r
71 #include <stdlib.h>\r
72 \r
73 /* Scheduler includes. */\r
74 #include "FreeRTOS.h"\r
75 #include "task.h"\r
76 \r
77 #ifndef configINTERRUPT_CONTROLLER_BASE_ADDRESS\r
78         #error configINTERRUPT_CONTROLLER_BASE_ADDRESS must be defined.  See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\r
79 #endif\r
80 \r
81 #ifndef configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET\r
82         #error configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET must be defined.  See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\r
83 #endif\r
84 \r
85 #ifndef configUNIQUE_INTERRUPT_PRIORITIES\r
86         #error configUNIQUE_INTERRUPT_PRIORITIES must be defined.  See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\r
87 #endif\r
88 \r
89 #ifndef configSETUP_TICK_INTERRUPT\r
90         #error configSETUP_TICK_INTERRUPT() must be defined.  See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\r
91 #endif /* configSETUP_TICK_INTERRUPT */\r
92 \r
93 #ifndef configMAX_API_CALL_INTERRUPT_PRIORITY\r
94         #error configMAX_API_CALL_INTERRUPT_PRIORITY must be defined.  See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\r
95 #endif\r
96 \r
97 #if configMAX_API_CALL_INTERRUPT_PRIORITY == 0\r
98         #error configMAX_API_CALL_INTERRUPT_PRIORITY must not be set to 0\r
99 #endif\r
100 \r
101 #if configMAX_API_CALL_INTERRUPT_PRIORITY > configUNIQUE_INTERRUPT_PRIORITIES\r
102         #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
103 #endif\r
104 \r
105 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1\r
106         /* Check the configuration. */\r
107         #if( configMAX_PRIORITIES > 32 )\r
108                 #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
109         #endif\r
110 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\r
111 \r
112 /* In case security extensions are implemented. */\r
113 #if configMAX_API_CALL_INTERRUPT_PRIORITY <= ( configUNIQUE_INTERRUPT_PRIORITIES / 2 )\r
114         #error configMAX_API_CALL_INTERRUPT_PRIORITY must be greater than ( configUNIQUE_INTERRUPT_PRIORITIES / 2 )\r
115 #endif\r
116 \r
117 /* Some vendor specific files default configCLEAR_TICK_INTERRUPT() in\r
118 portmacro.h. */\r
119 #ifndef configCLEAR_TICK_INTERRUPT\r
120         #define configCLEAR_TICK_INTERRUPT()\r
121 #endif\r
122 \r
123 /* A critical section is exited when the critical section nesting count reaches\r
124 this value. */\r
125 #define portNO_CRITICAL_NESTING                 ( ( size_t ) 0 )\r
126 \r
127 /* In all GICs 255 can be written to the priority mask register to unmask all\r
128 (but the lowest) interrupt priority. */\r
129 #define portUNMASK_VALUE                                ( 0xFFUL )\r
130 \r
131 /* Tasks are not created with a floating point context, but can be given a\r
132 floating point context after they have been created.  A variable is stored as\r
133 part of the tasks context that holds portNO_FLOATING_POINT_CONTEXT if the task\r
134 does not have an FPU context, or any other value if the task does have an FPU\r
135 context. */\r
136 #define portNO_FLOATING_POINT_CONTEXT   ( ( StackType_t ) 0 )\r
137 \r
138 /* Constants required to setup the initial task context. */\r
139 #define portSP_ELx                                              ( ( StackType_t ) 0x01 )\r
140 #define portSP_EL0                                              ( ( StackType_t ) 0x00 )\r
141 \r
142 #if defined( GUEST )\r
143         #define portEL1                                         ( ( StackType_t ) 0x04 )\r
144         #define portINITIAL_PSTATE                              ( portEL1 | portSP_EL0 )\r
145 #else\r
146         #define portEL3                                         ( ( StackType_t ) 0x0c )\r
147         /* At the time of writing, the BSP only supports EL3. */\r
148         #define portINITIAL_PSTATE                      ( portEL3 | portSP_EL0 )\r
149 #endif\r
150 \r
151 \r
152 /* Used by portASSERT_IF_INTERRUPT_PRIORITY_INVALID() when ensuring the binary\r
153 point is zero. */\r
154 #define portBINARY_POINT_BITS                   ( ( uint8_t ) 0x03 )\r
155 \r
156 /* Masks all bits in the APSR other than the mode bits. */\r
157 #define portAPSR_MODE_BITS_MASK                 ( 0x0C )\r
158 \r
159 /* The I bit in the DAIF bits. */\r
160 #define portDAIF_I                                              ( 0x80 )\r
161 \r
162 /* Macro to unmask all interrupt priorities. */\r
163 #define portCLEAR_INTERRUPT_MASK()                                                                      \\r
164 {                                                                                                                                       \\r
165         portDISABLE_INTERRUPTS();                                                                               \\r
166         portICCPMR_PRIORITY_MASK_REGISTER = portUNMASK_VALUE;                   \\r
167         __asm volatile (        "DSB SY         \n"                                                             \\r
168                                                 "ISB SY         \n" );                                                  \\r
169         portENABLE_INTERRUPTS();                                                                                \\r
170 }\r
171 \r
172 /* Hardware specifics used when sanity checking the configuration. */\r
173 #define portINTERRUPT_PRIORITY_REGISTER_OFFSET          0x400UL\r
174 #define portMAX_8_BIT_VALUE                                                     ( ( uint8_t ) 0xff )\r
175 #define portBIT_0_SET                                                           ( ( uint8_t ) 0x01 )\r
176 \r
177 /*-----------------------------------------------------------*/\r
178 \r
179 /*\r
180  * Starts the first task executing.  This function is necessarily written in\r
181  * assembly code so is implemented in portASM.s.\r
182  */\r
183 extern void vPortRestoreTaskContext( void );\r
184 \r
185 /*-----------------------------------------------------------*/\r
186 \r
187 /* A variable is used to keep track of the critical section nesting.  This\r
188 variable has to be stored as part of the task context and must be initialised to\r
189 a non zero value to ensure interrupts don't inadvertently become unmasked before\r
190 the scheduler starts.  As it is stored as part of the task context it will\r
191 automatically be set to 0 when the first task is started. */\r
192 volatile uint64_t ullCriticalNesting = 9999ULL;\r
193 \r
194 /* Saved as part of the task context.  If ullPortTaskHasFPUContext is non-zero\r
195 then floating point context must be saved and restored for the task. */\r
196 uint64_t ullPortTaskHasFPUContext = pdFALSE;\r
197 \r
198 /* Set to 1 to pend a context switch from an ISR. */\r
199 uint64_t ullPortYieldRequired = pdFALSE;\r
200 \r
201 /* Counts the interrupt nesting depth.  A context switch is only performed if\r
202 if the nesting depth is 0. */\r
203 uint64_t ullPortInterruptNesting = 0;\r
204 \r
205 /* Used in the ASM code. */\r
206 __attribute__(( used )) const uint64_t ullICCEOIR = portICCEOIR_END_OF_INTERRUPT_REGISTER_ADDRESS;\r
207 __attribute__(( used )) const uint64_t ullICCIAR = portICCIAR_INTERRUPT_ACKNOWLEDGE_REGISTER_ADDRESS;\r
208 __attribute__(( used )) const uint64_t ullICCPMR = portICCPMR_PRIORITY_MASK_REGISTER_ADDRESS;\r
209 __attribute__(( used )) const uint64_t ullMaxAPIPriorityMask = ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );\r
210 \r
211 /*-----------------------------------------------------------*/\r
212 \r
213 /*\r
214  * See header file for description.\r
215  */\r
216 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
217 {\r
218         /* Setup the initial stack of the task.  The stack is set exactly as\r
219         expected by the portRESTORE_CONTEXT() macro. */\r
220 \r
221         /* First all the general purpose registers. */\r
222         pxTopOfStack--;\r
223         *pxTopOfStack = 0x0101010101010101ULL;  /* R1 */\r
224         pxTopOfStack--;\r
225         *pxTopOfStack = ( StackType_t ) pvParameters; /* R0 */\r
226         pxTopOfStack--;\r
227         *pxTopOfStack = 0x0303030303030303ULL;  /* R3 */\r
228         pxTopOfStack--;\r
229         *pxTopOfStack = 0x0202020202020202ULL;  /* R2 */\r
230         pxTopOfStack--;\r
231         *pxTopOfStack = 0x0505050505050505ULL;  /* R5 */\r
232         pxTopOfStack--;\r
233         *pxTopOfStack = 0x0404040404040404ULL;  /* R4 */\r
234         pxTopOfStack--;\r
235         *pxTopOfStack = 0x0707070707070707ULL;  /* R7 */\r
236         pxTopOfStack--;\r
237         *pxTopOfStack = 0x0606060606060606ULL;  /* R6 */\r
238         pxTopOfStack--;\r
239         *pxTopOfStack = 0x0909090909090909ULL;  /* R9 */\r
240         pxTopOfStack--;\r
241         *pxTopOfStack = 0x0808080808080808ULL;  /* R8 */\r
242         pxTopOfStack--;\r
243         *pxTopOfStack = 0x1111111111111111ULL;  /* R11 */\r
244         pxTopOfStack--;\r
245         *pxTopOfStack = 0x1010101010101010ULL;  /* R10 */\r
246         pxTopOfStack--;\r
247         *pxTopOfStack = 0x1313131313131313ULL;  /* R13 */\r
248         pxTopOfStack--;\r
249         *pxTopOfStack = 0x1212121212121212ULL;  /* R12 */\r
250         pxTopOfStack--;\r
251         *pxTopOfStack = 0x1515151515151515ULL;  /* R15 */\r
252         pxTopOfStack--;\r
253         *pxTopOfStack = 0x1414141414141414ULL;  /* R14 */\r
254         pxTopOfStack--;\r
255         *pxTopOfStack = 0x1717171717171717ULL;  /* R17 */\r
256         pxTopOfStack--;\r
257         *pxTopOfStack = 0x1616161616161616ULL;  /* R16 */\r
258         pxTopOfStack--;\r
259         *pxTopOfStack = 0x1919191919191919ULL;  /* R19 */\r
260         pxTopOfStack--;\r
261         *pxTopOfStack = 0x1818181818181818ULL;  /* R18 */\r
262         pxTopOfStack--;\r
263         *pxTopOfStack = 0x2121212121212121ULL;  /* R21 */\r
264         pxTopOfStack--;\r
265         *pxTopOfStack = 0x2020202020202020ULL;  /* R20 */\r
266         pxTopOfStack--;\r
267         *pxTopOfStack = 0x2323232323232323ULL;  /* R23 */\r
268         pxTopOfStack--;\r
269         *pxTopOfStack = 0x2222222222222222ULL;  /* R22 */\r
270         pxTopOfStack--;\r
271         *pxTopOfStack = 0x2525252525252525ULL;  /* R25 */\r
272         pxTopOfStack--;\r
273         *pxTopOfStack = 0x2424242424242424ULL;  /* R24 */\r
274         pxTopOfStack--;\r
275         *pxTopOfStack = 0x2727272727272727ULL;  /* R27 */\r
276         pxTopOfStack--;\r
277         *pxTopOfStack = 0x2626262626262626ULL;  /* R26 */\r
278         pxTopOfStack--;\r
279         *pxTopOfStack = 0x2929292929292929ULL;  /* R29 */\r
280         pxTopOfStack--;\r
281         *pxTopOfStack = 0x2828282828282828ULL;  /* R28 */\r
282         pxTopOfStack--;\r
283         *pxTopOfStack = ( StackType_t ) 0x00;   /* XZR - has no effect, used so there are an even number of registers. */\r
284         pxTopOfStack--;\r
285         *pxTopOfStack = ( StackType_t ) 0x00;   /* R30 - procedure call link register. */\r
286         pxTopOfStack--;\r
287 \r
288         *pxTopOfStack = portINITIAL_PSTATE;\r
289         pxTopOfStack--;\r
290 \r
291         *pxTopOfStack = ( StackType_t ) pxCode; /* Exception return address. */\r
292         pxTopOfStack--;\r
293 \r
294         /* The task will start with a critical nesting count of 0 as interrupts are\r
295         enabled. */\r
296         *pxTopOfStack = portNO_CRITICAL_NESTING;\r
297         pxTopOfStack--;\r
298 \r
299         /* The task will start without a floating point context.  A task that uses\r
300         the floating point hardware must call vPortTaskUsesFPU() before executing\r
301         any floating point instructions. */\r
302         *pxTopOfStack = portNO_FLOATING_POINT_CONTEXT;\r
303 \r
304         return pxTopOfStack;\r
305 }\r
306 /*-----------------------------------------------------------*/\r
307 \r
308 BaseType_t xPortStartScheduler( void )\r
309 {\r
310 uint32_t ulAPSR;\r
311 \r
312         #if( configASSERT_DEFINED == 1 )\r
313         {\r
314                 volatile uint32_t ulOriginalPriority;\r
315                 volatile uint8_t * const pucFirstUserPriorityRegister = ( volatile uint8_t * const ) ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + portINTERRUPT_PRIORITY_REGISTER_OFFSET );\r
316                 volatile uint8_t ucMaxPriorityValue;\r
317 \r
318                 /* Determine how many priority bits are implemented in the GIC.\r
319 \r
320                 Save the interrupt priority value that is about to be clobbered. */\r
321                 ulOriginalPriority = *pucFirstUserPriorityRegister;\r
322 \r
323                 /* Determine the number of priority bits available.  First write to\r
324                 all possible bits. */\r
325                 *pucFirstUserPriorityRegister = portMAX_8_BIT_VALUE;\r
326 \r
327                 /* Read the value back to see how many bits stuck. */\r
328                 ucMaxPriorityValue = *pucFirstUserPriorityRegister;\r
329 \r
330                 /* Shift to the least significant bits. */\r
331                 while( ( ucMaxPriorityValue & portBIT_0_SET ) != portBIT_0_SET )\r
332                 {\r
333                         ucMaxPriorityValue >>= ( uint8_t ) 0x01;\r
334                 }\r
335 \r
336                 /* Sanity check configUNIQUE_INTERRUPT_PRIORITIES matches the read\r
337                 value. */\r
338 \r
339                 configASSERT( ucMaxPriorityValue >= portLOWEST_INTERRUPT_PRIORITY );\r
340 \r
341 \r
342                 /* Restore the clobbered interrupt priority register to its original\r
343                 value. */\r
344                 *pucFirstUserPriorityRegister = ulOriginalPriority;\r
345         }\r
346         #endif /* conifgASSERT_DEFINED */\r
347 \r
348 \r
349         /* At the time of writing, the BSP only supports EL3. */\r
350         __asm volatile ( "MRS %0, CurrentEL" : "=r" ( ulAPSR ) );\r
351         ulAPSR &= portAPSR_MODE_BITS_MASK;\r
352 \r
353 #if defined( GUEST )\r
354         #warning Building for execution as a guest under XEN. THIS IS NOT A FULLY TESTED PATH.\r
355         configASSERT( ulAPSR == portEL1 );\r
356         if( ulAPSR == portEL1 )\r
357 #else\r
358         configASSERT( ulAPSR == portEL3 );\r
359         if( ulAPSR == portEL3 )\r
360 #endif\r
361         {\r
362                 /* Only continue if the binary point value is set to its lowest possible\r
363                 setting.  See the comments in vPortValidateInterruptPriority() below for\r
364                 more information. */\r
365                 configASSERT( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE );\r
366 \r
367                 if( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE )\r
368                 {\r
369                         /* Interrupts are turned off in the CPU itself to ensure a tick does\r
370                         not execute     while the scheduler is being started.  Interrupts are\r
371                         automatically turned back on in the CPU when the first task starts\r
372                         executing. */\r
373                         portDISABLE_INTERRUPTS();\r
374 \r
375                         /* Start the timer that generates the tick ISR. */\r
376                         configSETUP_TICK_INTERRUPT();\r
377 \r
378                         /* Start the first task executing. */\r
379                         vPortRestoreTaskContext();\r
380                 }\r
381         }\r
382 \r
383         return 0;\r
384 }\r
385 /*-----------------------------------------------------------*/\r
386 \r
387 void vPortEndScheduler( void )\r
388 {\r
389         /* Not implemented in ports where there is nothing to return to.\r
390         Artificially force an assert. */\r
391         configASSERT( ullCriticalNesting == 1000ULL );\r
392 }\r
393 /*-----------------------------------------------------------*/\r
394 \r
395 void vPortEnterCritical( void )\r
396 {\r
397         /* Mask interrupts up to the max syscall interrupt priority. */\r
398         uxPortSetInterruptMask();\r
399 \r
400         /* Now interrupts are disabled ullCriticalNesting can be accessed\r
401         directly.  Increment ullCriticalNesting to keep a count of how many times\r
402         portENTER_CRITICAL() has been called. */\r
403         ullCriticalNesting++;\r
404 \r
405         /* This is not the interrupt safe version of the enter critical function so\r
406         assert() if it is being called from an interrupt context.  Only API\r
407         functions that end in "FromISR" can be used in an interrupt.  Only assert if\r
408         the critical nesting count is 1 to protect against recursive calls if the\r
409         assert function also uses a critical section. */\r
410         if( ullCriticalNesting == 1ULL )\r
411         {\r
412                 configASSERT( ullPortInterruptNesting == 0 );\r
413         }\r
414 }\r
415 /*-----------------------------------------------------------*/\r
416 \r
417 void vPortExitCritical( void )\r
418 {\r
419         if( ullCriticalNesting > portNO_CRITICAL_NESTING )\r
420         {\r
421                 /* Decrement the nesting count as the critical section is being\r
422                 exited. */\r
423                 ullCriticalNesting--;\r
424 \r
425                 /* If the nesting level has reached zero then all interrupt\r
426                 priorities must be re-enabled. */\r
427                 if( ullCriticalNesting == portNO_CRITICAL_NESTING )\r
428                 {\r
429                         /* Critical nesting has reached zero so all interrupt priorities\r
430                         should be unmasked. */\r
431                         portCLEAR_INTERRUPT_MASK();\r
432                 }\r
433         }\r
434 }\r
435 /*-----------------------------------------------------------*/\r
436 \r
437 void FreeRTOS_Tick_Handler( void )\r
438 {\r
439         /* Must be the lowest possible priority. */\r
440         #if !defined( QEMU )\r
441         {\r
442                 configASSERT( portICCRPR_RUNNING_PRIORITY_REGISTER == ( uint32_t ) ( portLOWEST_USABLE_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) );\r
443         }\r
444         #endif\r
445 \r
446         /* Interrupts should not be enabled before this point. */\r
447         #if( configASSERT_DEFINED == 1 )\r
448         {\r
449                 uint32_t ulMaskBits;\r
450 \r
451                 __asm volatile( "mrs %0, daif" : "=r"( ulMaskBits ) :: "memory" );\r
452                 configASSERT( ( ulMaskBits & portDAIF_I ) != 0 );\r
453         }\r
454         #endif /* configASSERT_DEFINED */\r
455 \r
456         /* Set interrupt mask before altering scheduler structures.   The tick\r
457         handler runs at the lowest priority, so interrupts cannot already be masked,\r
458         so there is no need to save and restore the current mask value.  It is\r
459         necessary to turn off interrupts in the CPU itself while the ICCPMR is being\r
460         updated. */\r
461         portICCPMR_PRIORITY_MASK_REGISTER = ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );\r
462         __asm volatile (        "dsb sy         \n"\r
463                                                 "isb sy         \n" ::: "memory" );\r
464 \r
465         /* Ok to enable interrupts after the interrupt source has been cleared. */\r
466         configCLEAR_TICK_INTERRUPT();\r
467         portENABLE_INTERRUPTS();\r
468 \r
469         /* Increment the RTOS tick. */\r
470         if( xTaskIncrementTick() != pdFALSE )\r
471         {\r
472                 ullPortYieldRequired = pdTRUE;\r
473         }\r
474 \r
475         /* Ensure all interrupt priorities are active again. */\r
476         portCLEAR_INTERRUPT_MASK();\r
477 }\r
478 /*-----------------------------------------------------------*/\r
479 \r
480 void vPortTaskUsesFPU( void )\r
481 {\r
482         /* A task is registering the fact that it needs an FPU context.  Set the\r
483         FPU flag (which is saved as part of the task context). */\r
484         ullPortTaskHasFPUContext = pdTRUE;\r
485 \r
486         /* Consider initialising the FPSR here - but probably not necessary in\r
487         AArch64. */\r
488 }\r
489 /*-----------------------------------------------------------*/\r
490 \r
491 void vPortClearInterruptMask( UBaseType_t uxNewMaskValue )\r
492 {\r
493         if( uxNewMaskValue == pdFALSE )\r
494         {\r
495                 portCLEAR_INTERRUPT_MASK();\r
496         }\r
497 }\r
498 /*-----------------------------------------------------------*/\r
499 \r
500 UBaseType_t uxPortSetInterruptMask( void )\r
501 {\r
502 uint32_t ulReturn;\r
503 \r
504         /* Interrupt in the CPU must be turned off while the ICCPMR is being\r
505         updated. */\r
506         portDISABLE_INTERRUPTS();\r
507         if( portICCPMR_PRIORITY_MASK_REGISTER == ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) )\r
508         {\r
509                 /* Interrupts were already masked. */\r
510                 ulReturn = pdTRUE;\r
511         }\r
512         else\r
513         {\r
514                 ulReturn = pdFALSE;\r
515                 portICCPMR_PRIORITY_MASK_REGISTER = ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );\r
516                 __asm volatile (        "dsb sy         \n"\r
517                                                         "isb sy         \n" ::: "memory" );\r
518         }\r
519         portENABLE_INTERRUPTS();\r
520 \r
521         return ulReturn;\r
522 }\r
523 /*-----------------------------------------------------------*/\r
524 \r
525 #if( configASSERT_DEFINED == 1 )\r
526 \r
527         void vPortValidateInterruptPriority( void )\r
528         {\r
529                 /* The following assertion will fail if a service routine (ISR) for\r
530                 an interrupt that has been assigned a priority above\r
531                 configMAX_SYSCALL_INTERRUPT_PRIORITY calls an ISR safe FreeRTOS API\r
532                 function.  ISR safe FreeRTOS API functions must *only* be called\r
533                 from interrupts that have been assigned a priority at or below\r
534                 configMAX_SYSCALL_INTERRUPT_PRIORITY.\r
535 \r
536                 Numerically low interrupt priority numbers represent logically high\r
537                 interrupt priorities, therefore the priority of the interrupt must\r
538                 be set to a value equal to or numerically *higher* than\r
539                 configMAX_SYSCALL_INTERRUPT_PRIORITY.\r
540 \r
541                 FreeRTOS maintains separate thread and ISR API functions to ensure\r
542                 interrupt entry is as fast and simple as possible. */\r
543                 configASSERT( portICCRPR_RUNNING_PRIORITY_REGISTER >= ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) );\r
544 \r
545                 /* Priority grouping:  The interrupt controller (GIC) allows the bits\r
546                 that define each interrupt's priority to be split between bits that\r
547                 define the interrupt's pre-emption priority bits and bits that define\r
548                 the interrupt's sub-priority.  For simplicity all bits must be defined\r
549                 to be pre-emption priority bits.  The following assertion will fail if\r
550                 this is not the case (if some bits represent a sub-priority).\r
551 \r
552                 The priority grouping is configured by the GIC's binary point register\r
553                 (ICCBPR).  Writting 0 to ICCBPR will ensure it is set to its lowest\r
554                 possible value (which may be above 0). */\r
555                 configASSERT( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE );\r
556         }\r
557 \r
558 #endif /* configASSERT_DEFINED */\r
559 /*-----------------------------------------------------------*/\r
560 \r