]> begriffs open source - freertos/blob - portable/GCC/ARM_CA9/port.c
Remove "1 tab == 4 spaces!" line from files that still contain it.
[freertos] / portable / GCC / ARM_CA9 / port.c
1 /*\r
2  * FreeRTOS Kernel <DEVELOPMENT BRANCH>\r
3  * Copyright (C) 2021 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  * https://www.FreeRTOS.org\r
23  * https://github.com/FreeRTOS\r
24  *\r
25  */\r
26 \r
27 /* Standard includes. */\r
28 #include <stdlib.h>\r
29 \r
30 /* Scheduler includes. */\r
31 #include "FreeRTOS.h"\r
32 #include "task.h"\r
33 \r
34 #ifndef configINTERRUPT_CONTROLLER_BASE_ADDRESS\r
35         #error configINTERRUPT_CONTROLLER_BASE_ADDRESS must be defined.  See https://www.FreeRTOS.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\r
36 #endif\r
37 \r
38 #ifndef configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET\r
39         #error configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET must be defined.  See https://www.FreeRTOS.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\r
40 #endif\r
41 \r
42 #ifndef configUNIQUE_INTERRUPT_PRIORITIES\r
43         #error configUNIQUE_INTERRUPT_PRIORITIES must be defined.  See https://www.FreeRTOS.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\r
44 #endif\r
45 \r
46 #ifndef configSETUP_TICK_INTERRUPT\r
47         #error configSETUP_TICK_INTERRUPT() must be defined.  See https://www.FreeRTOS.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\r
48 #endif /* configSETUP_TICK_INTERRUPT */\r
49 \r
50 #ifndef configMAX_API_CALL_INTERRUPT_PRIORITY\r
51         #error configMAX_API_CALL_INTERRUPT_PRIORITY must be defined.  See https://www.FreeRTOS.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\r
52 #endif\r
53 \r
54 #if configMAX_API_CALL_INTERRUPT_PRIORITY == 0\r
55         #error configMAX_API_CALL_INTERRUPT_PRIORITY must not be set to 0\r
56 #endif\r
57 \r
58 #if configMAX_API_CALL_INTERRUPT_PRIORITY > configUNIQUE_INTERRUPT_PRIORITIES\r
59         #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
60 #endif\r
61 \r
62 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1\r
63         /* Check the configuration. */\r
64         #if( configMAX_PRIORITIES > 32 )\r
65                 #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
66         #endif\r
67 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\r
68 \r
69 /* In case security extensions are implemented. */\r
70 #if configMAX_API_CALL_INTERRUPT_PRIORITY <= ( configUNIQUE_INTERRUPT_PRIORITIES / 2 )\r
71         #error configMAX_API_CALL_INTERRUPT_PRIORITY must be greater than ( configUNIQUE_INTERRUPT_PRIORITIES / 2 )\r
72 #endif\r
73 \r
74 /* Some vendor specific files default configCLEAR_TICK_INTERRUPT() in\r
75 portmacro.h. */\r
76 #ifndef configCLEAR_TICK_INTERRUPT\r
77         #define configCLEAR_TICK_INTERRUPT()\r
78 #endif\r
79 \r
80 /* A critical section is exited when the critical section nesting count reaches\r
81 this value. */\r
82 #define portNO_CRITICAL_NESTING                 ( ( uint32_t ) 0 )\r
83 \r
84 /* In all GICs 255 can be written to the priority mask register to unmask all\r
85 (but the lowest) interrupt priority. */\r
86 #define portUNMASK_VALUE                                ( 0xFFUL )\r
87 \r
88 /* Tasks are not created with a floating point context, but can be given a\r
89 floating point context after they have been created.  A variable is stored as\r
90 part of the tasks context that holds portNO_FLOATING_POINT_CONTEXT if the task\r
91 does not have an FPU context, or any other value if the task does have an FPU\r
92 context. */\r
93 #define portNO_FLOATING_POINT_CONTEXT   ( ( StackType_t ) 0 )\r
94 \r
95 /* Constants required to setup the initial task context. */\r
96 #define portINITIAL_SPSR                                ( ( StackType_t ) 0x1f ) /* System mode, ARM mode, IRQ enabled FIQ enabled. */\r
97 #define portTHUMB_MODE_BIT                              ( ( StackType_t ) 0x20 )\r
98 #define portINTERRUPT_ENABLE_BIT                ( 0x80UL )\r
99 #define portTHUMB_MODE_ADDRESS                  ( 0x01UL )\r
100 \r
101 /* Used by portASSERT_IF_INTERRUPT_PRIORITY_INVALID() when ensuring the binary\r
102 point is zero. */\r
103 #define portBINARY_POINT_BITS                   ( ( uint8_t ) 0x03 )\r
104 \r
105 /* Masks all bits in the APSR other than the mode bits. */\r
106 #define portAPSR_MODE_BITS_MASK                 ( 0x1F )\r
107 \r
108 /* The value of the mode bits in the APSR when the CPU is executing in user\r
109 mode. */\r
110 #define portAPSR_USER_MODE                              ( 0x10 )\r
111 \r
112 /* The critical section macros only mask interrupts up to an application\r
113 determined priority level.  Sometimes it is necessary to turn interrupt off in\r
114 the CPU itself before modifying certain hardware registers. */\r
115 #define portCPU_IRQ_DISABLE()                                                                           \\r
116         __asm volatile ( "CPSID i" ::: "memory" );                                              \\r
117         __asm volatile ( "DSB" );                                                                               \\r
118         __asm volatile ( "ISB" );\r
119 \r
120 #define portCPU_IRQ_ENABLE()                                                                            \\r
121         __asm volatile ( "CPSIE i" ::: "memory" );                                              \\r
122         __asm volatile ( "DSB" );                                                                               \\r
123         __asm volatile ( "ISB" );\r
124 \r
125 \r
126 /* Macro to unmask all interrupt priorities. */\r
127 #define portCLEAR_INTERRUPT_MASK()                                                                      \\r
128 {                                                                                                                                       \\r
129         portCPU_IRQ_DISABLE();                                                                                  \\r
130         portICCPMR_PRIORITY_MASK_REGISTER = portUNMASK_VALUE;                   \\r
131         __asm volatile (        "DSB            \n"                                                             \\r
132                                                 "ISB            \n" );                                                  \\r
133         portCPU_IRQ_ENABLE();                                                                                   \\r
134 }\r
135 \r
136 #define portINTERRUPT_PRIORITY_REGISTER_OFFSET          0x400UL\r
137 #define portMAX_8_BIT_VALUE                                                     ( ( uint8_t ) 0xff )\r
138 #define portBIT_0_SET                                                           ( ( uint8_t ) 0x01 )\r
139 \r
140 /* Let the user override the pre-loading of the initial LR with the address of\r
141 prvTaskExitError() in case it messes up unwinding of the stack in the\r
142 debugger. */\r
143 #ifdef configTASK_RETURN_ADDRESS\r
144         #define portTASK_RETURN_ADDRESS configTASK_RETURN_ADDRESS\r
145 #else\r
146         #define portTASK_RETURN_ADDRESS prvTaskExitError\r
147 #endif\r
148 \r
149 /* The space on the stack required to hold the FPU registers.  This is 32 64-bit\r
150 registers, plus a 32-bit status register. */\r
151 #define portFPU_REGISTER_WORDS  ( ( 32 * 2 ) + 1 )\r
152 \r
153 /*-----------------------------------------------------------*/\r
154 \r
155 /*\r
156  * Starts the first task executing.  This function is necessarily written in\r
157  * assembly code so is implemented in portASM.s.\r
158  */\r
159 extern void vPortRestoreTaskContext( void );\r
160 \r
161 /*\r
162  * Used to catch tasks that attempt to return from their implementing function.\r
163  */\r
164 static void prvTaskExitError( void );\r
165 \r
166 /*\r
167  * If the application provides an implementation of vApplicationIRQHandler(),\r
168  * then it will get called directly without saving the FPU registers on\r
169  * interrupt entry, and this weak implementation of\r
170  * vApplicationFPUSafeIRQHandler() is just provided to remove linkage errors -\r
171  * it should never actually get called so its implementation contains a\r
172  * call to configASSERT() that will always fail.\r
173  *\r
174  * If the application provides its own implementation of\r
175  * vApplicationFPUSafeIRQHandler() then the implementation of\r
176  * vApplicationIRQHandler() provided in portASM.S will save the FPU registers\r
177  * before calling it.\r
178  *\r
179  * Therefore, if the application writer wants FPU registers to be saved on\r
180  * interrupt entry their IRQ handler must be called\r
181  * vApplicationFPUSafeIRQHandler(), and if the application writer does not want\r
182  * FPU registers to be saved on interrupt entry their IRQ handler must be\r
183  * called vApplicationIRQHandler().\r
184  */\r
185 void vApplicationFPUSafeIRQHandler( uint32_t ulICCIAR ) __attribute__((weak) );\r
186 \r
187 /*-----------------------------------------------------------*/\r
188 \r
189 /* A variable is used to keep track of the critical section nesting.  This\r
190 variable has to be stored as part of the task context and must be initialised to\r
191 a non zero value to ensure interrupts don't inadvertently become unmasked before\r
192 the scheduler starts.  As it is stored as part of the task context it will\r
193 automatically be set to 0 when the first task is started. */\r
194 volatile uint32_t ulCriticalNesting = 9999UL;\r
195 \r
196 /* Saved as part of the task context.  If ulPortTaskHasFPUContext is non-zero then\r
197 a floating point context must be saved and restored for the task. */\r
198 volatile uint32_t ulPortTaskHasFPUContext = pdFALSE;\r
199 \r
200 /* Set to 1 to pend a context switch from an ISR. */\r
201 volatile uint32_t ulPortYieldRequired = pdFALSE;\r
202 \r
203 /* Counts the interrupt nesting depth.  A context switch is only performed if\r
204 if the nesting depth is 0. */\r
205 volatile uint32_t ulPortInterruptNesting = 0UL;\r
206 \r
207 /* Used in the asm file. */\r
208 __attribute__(( used )) const uint32_t ulICCIAR = portICCIAR_INTERRUPT_ACKNOWLEDGE_REGISTER_ADDRESS;\r
209 __attribute__(( used )) const uint32_t ulICCEOIR = portICCEOIR_END_OF_INTERRUPT_REGISTER_ADDRESS;\r
210 __attribute__(( used )) const uint32_t ulICCPMR = portICCPMR_PRIORITY_MASK_REGISTER_ADDRESS;\r
211 __attribute__(( used )) const uint32_t ulMaxAPIPriorityMask = ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );\r
212 \r
213 /*-----------------------------------------------------------*/\r
214 \r
215 /*\r
216  * See header file for description.\r
217  */\r
218 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
219 {\r
220         /* Setup the initial stack of the task.  The stack is set exactly as\r
221         expected by the portRESTORE_CONTEXT() macro.\r
222 \r
223         The fist real value on the stack is the status register, which is set for\r
224         system mode, with interrupts enabled.  A few NULLs are added first to ensure\r
225         GDB does not try decoding a non-existent return address. */\r
226         *pxTopOfStack = ( StackType_t ) NULL;\r
227         pxTopOfStack--;\r
228         *pxTopOfStack = ( StackType_t ) NULL;\r
229         pxTopOfStack--;\r
230         *pxTopOfStack = ( StackType_t ) NULL;\r
231         pxTopOfStack--;\r
232         *pxTopOfStack = ( StackType_t ) portINITIAL_SPSR;\r
233 \r
234         if( ( ( uint32_t ) pxCode & portTHUMB_MODE_ADDRESS ) != 0x00UL )\r
235         {\r
236                 /* The task will start in THUMB mode. */\r
237                 *pxTopOfStack |= portTHUMB_MODE_BIT;\r
238         }\r
239 \r
240         pxTopOfStack--;\r
241 \r
242         /* Next the return address, which in this case is the start of the task. */\r
243         *pxTopOfStack = ( StackType_t ) pxCode;\r
244         pxTopOfStack--;\r
245 \r
246         /* Next all the registers other than the stack pointer. */\r
247         *pxTopOfStack = ( StackType_t ) portTASK_RETURN_ADDRESS;        /* R14 */\r
248         pxTopOfStack--;\r
249         *pxTopOfStack = ( StackType_t ) 0x12121212;     /* R12 */\r
250         pxTopOfStack--;\r
251         *pxTopOfStack = ( StackType_t ) 0x11111111;     /* R11 */\r
252         pxTopOfStack--;\r
253         *pxTopOfStack = ( StackType_t ) 0x10101010;     /* R10 */\r
254         pxTopOfStack--;\r
255         *pxTopOfStack = ( StackType_t ) 0x09090909;     /* R9 */\r
256         pxTopOfStack--;\r
257         *pxTopOfStack = ( StackType_t ) 0x08080808;     /* R8 */\r
258         pxTopOfStack--;\r
259         *pxTopOfStack = ( StackType_t ) 0x07070707;     /* R7 */\r
260         pxTopOfStack--;\r
261         *pxTopOfStack = ( StackType_t ) 0x06060606;     /* R6 */\r
262         pxTopOfStack--;\r
263         *pxTopOfStack = ( StackType_t ) 0x05050505;     /* R5 */\r
264         pxTopOfStack--;\r
265         *pxTopOfStack = ( StackType_t ) 0x04040404;     /* R4 */\r
266         pxTopOfStack--;\r
267         *pxTopOfStack = ( StackType_t ) 0x03030303;     /* R3 */\r
268         pxTopOfStack--;\r
269         *pxTopOfStack = ( StackType_t ) 0x02020202;     /* R2 */\r
270         pxTopOfStack--;\r
271         *pxTopOfStack = ( StackType_t ) 0x01010101;     /* R1 */\r
272         pxTopOfStack--;\r
273         *pxTopOfStack = ( StackType_t ) pvParameters; /* R0 */\r
274         pxTopOfStack--;\r
275 \r
276         /* The task will start with a critical nesting count of 0 as interrupts are\r
277         enabled. */\r
278         *pxTopOfStack = portNO_CRITICAL_NESTING;\r
279 \r
280         #if( configUSE_TASK_FPU_SUPPORT == 1 )\r
281         {\r
282                 /* The task will start without a floating point context.  A task that\r
283                 uses the floating point hardware must call vPortTaskUsesFPU() before\r
284                 executing any floating point instructions. */\r
285                 pxTopOfStack--;\r
286                 *pxTopOfStack = portNO_FLOATING_POINT_CONTEXT;\r
287         }\r
288         #elif( configUSE_TASK_FPU_SUPPORT == 2 )\r
289         {\r
290                 /* The task will start with a floating point context.  Leave enough\r
291                 space for the registers - and ensure they are initialised to 0. */\r
292                 pxTopOfStack -= portFPU_REGISTER_WORDS;\r
293                 memset( pxTopOfStack, 0x00, portFPU_REGISTER_WORDS * sizeof( StackType_t ) );\r
294 \r
295                 pxTopOfStack--;\r
296                 *pxTopOfStack = pdTRUE;\r
297                 ulPortTaskHasFPUContext = pdTRUE;\r
298         }\r
299         #else\r
300         {\r
301                 #error Invalid configUSE_TASK_FPU_SUPPORT setting - configUSE_TASK_FPU_SUPPORT must be set to 1, 2, or left undefined.\r
302         }\r
303         #endif\r
304 \r
305         return pxTopOfStack;\r
306 }\r
307 /*-----------------------------------------------------------*/\r
308 \r
309 static void prvTaskExitError( void )\r
310 {\r
311         /* A function that implements a task must not exit or attempt to return to\r
312         its caller as there is nothing to return to.  If a task wants to exit it\r
313         should instead call vTaskDelete( NULL ).\r
314 \r
315         Artificially force an assert() to be triggered if configASSERT() is\r
316         defined, then stop here so application writers can catch the error. */\r
317         configASSERT( ulPortInterruptNesting == ~0UL );\r
318         portDISABLE_INTERRUPTS();\r
319         for( ;; );\r
320 }\r
321 /*-----------------------------------------------------------*/\r
322 \r
323 BaseType_t xPortStartScheduler( void )\r
324 {\r
325 uint32_t ulAPSR;\r
326 \r
327         #if( configASSERT_DEFINED == 1 )\r
328         {\r
329                 volatile uint32_t ulOriginalPriority;\r
330                 volatile uint8_t * const pucFirstUserPriorityRegister = ( volatile uint8_t * const ) ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + portINTERRUPT_PRIORITY_REGISTER_OFFSET );\r
331                 volatile uint8_t ucMaxPriorityValue;\r
332 \r
333                 /* Determine how many priority bits are implemented in the GIC.\r
334 \r
335                 Save the interrupt priority value that is about to be clobbered. */\r
336                 ulOriginalPriority = *pucFirstUserPriorityRegister;\r
337 \r
338                 /* Determine the number of priority bits available.  First write to\r
339                 all possible bits. */\r
340                 *pucFirstUserPriorityRegister = portMAX_8_BIT_VALUE;\r
341 \r
342                 /* Read the value back to see how many bits stuck. */\r
343                 ucMaxPriorityValue = *pucFirstUserPriorityRegister;\r
344 \r
345                 /* Shift to the least significant bits. */\r
346                 while( ( ucMaxPriorityValue & portBIT_0_SET ) != portBIT_0_SET )\r
347                 {\r
348                         ucMaxPriorityValue >>= ( uint8_t ) 0x01;\r
349                 }\r
350 \r
351                 /* Sanity check configUNIQUE_INTERRUPT_PRIORITIES matches the read\r
352                 value. */\r
353                 configASSERT( ucMaxPriorityValue == portLOWEST_INTERRUPT_PRIORITY );\r
354 \r
355                 /* Restore the clobbered interrupt priority register to its original\r
356                 value. */\r
357                 *pucFirstUserPriorityRegister = ulOriginalPriority;\r
358         }\r
359         #endif /* conifgASSERT_DEFINED */\r
360 \r
361 \r
362         /* Only continue if the CPU is not in User mode.  The CPU must be in a\r
363         Privileged mode for the scheduler to start. */\r
364         __asm volatile ( "MRS %0, APSR" : "=r" ( ulAPSR ) :: "memory" );\r
365         ulAPSR &= portAPSR_MODE_BITS_MASK;\r
366         configASSERT( ulAPSR != portAPSR_USER_MODE );\r
367 \r
368         if( ulAPSR != portAPSR_USER_MODE )\r
369         {\r
370                 /* Only continue if the binary point value is set to its lowest possible\r
371                 setting.  See the comments in vPortValidateInterruptPriority() below for\r
372                 more information. */\r
373                 configASSERT( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE );\r
374 \r
375                 if( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE )\r
376                 {\r
377                         /* Interrupts are turned off in the CPU itself to ensure tick does\r
378                         not execute     while the scheduler is being started.  Interrupts are\r
379                         automatically turned back on in the CPU when the first task starts\r
380                         executing. */\r
381                         portCPU_IRQ_DISABLE();\r
382 \r
383                         /* Start the timer that generates the tick ISR. */\r
384                         configSETUP_TICK_INTERRUPT();\r
385 \r
386                         /* Start the first task executing. */\r
387                         vPortRestoreTaskContext();\r
388                 }\r
389         }\r
390 \r
391         /* Will only get here if vTaskStartScheduler() was called with the CPU in\r
392         a non-privileged mode or the binary point register was not set to its lowest\r
393         possible value.  prvTaskExitError() is referenced to prevent a compiler\r
394         warning about it being defined but not referenced in the case that the user\r
395         defines their own exit address. */\r
396         ( void ) prvTaskExitError;\r
397         return 0;\r
398 }\r
399 /*-----------------------------------------------------------*/\r
400 \r
401 void vPortEndScheduler( void )\r
402 {\r
403         /* Not implemented in ports where there is nothing to return to.\r
404         Artificially force an assert. */\r
405         configASSERT( ulCriticalNesting == 1000UL );\r
406 }\r
407 /*-----------------------------------------------------------*/\r
408 \r
409 void vPortEnterCritical( void )\r
410 {\r
411         /* Mask interrupts up to the max syscall interrupt priority. */\r
412         ulPortSetInterruptMask();\r
413 \r
414         /* Now interrupts are disabled ulCriticalNesting can be accessed\r
415         directly.  Increment ulCriticalNesting to keep a count of how many times\r
416         portENTER_CRITICAL() has been called. */\r
417         ulCriticalNesting++;\r
418 \r
419         /* This is not the interrupt safe version of the enter critical function so\r
420         assert() if it is being called from an interrupt context.  Only API\r
421         functions that end in "FromISR" can be used in an interrupt.  Only assert if\r
422         the critical nesting count is 1 to protect against recursive calls if the\r
423         assert function also uses a critical section. */\r
424         if( ulCriticalNesting == 1 )\r
425         {\r
426                 configASSERT( ulPortInterruptNesting == 0 );\r
427         }\r
428 }\r
429 /*-----------------------------------------------------------*/\r
430 \r
431 void vPortExitCritical( void )\r
432 {\r
433         if( ulCriticalNesting > portNO_CRITICAL_NESTING )\r
434         {\r
435                 /* Decrement the nesting count as the critical section is being\r
436                 exited. */\r
437                 ulCriticalNesting--;\r
438 \r
439                 /* If the nesting level has reached zero then all interrupt\r
440                 priorities must be re-enabled. */\r
441                 if( ulCriticalNesting == portNO_CRITICAL_NESTING )\r
442                 {\r
443                         /* Critical nesting has reached zero so all interrupt priorities\r
444                         should be unmasked. */\r
445                         portCLEAR_INTERRUPT_MASK();\r
446                 }\r
447         }\r
448 }\r
449 /*-----------------------------------------------------------*/\r
450 \r
451 void FreeRTOS_Tick_Handler( void )\r
452 {\r
453         /* Set interrupt mask before altering scheduler structures.   The tick\r
454         handler runs at the lowest priority, so interrupts cannot already be masked,\r
455         so there is no need to save and restore the current mask value.  It is\r
456         necessary to turn off interrupts in the CPU itself while the ICCPMR is being\r
457         updated. */\r
458         portCPU_IRQ_DISABLE();\r
459         portICCPMR_PRIORITY_MASK_REGISTER = ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );\r
460         __asm volatile (        "dsb            \n"\r
461                                                 "isb            \n" ::: "memory" );\r
462         portCPU_IRQ_ENABLE();\r
463 \r
464         /* Increment the RTOS tick. */\r
465         if( xTaskIncrementTick() != pdFALSE )\r
466         {\r
467                 ulPortYieldRequired = pdTRUE;\r
468         }\r
469 \r
470         /* Ensure all interrupt priorities are active again. */\r
471         portCLEAR_INTERRUPT_MASK();\r
472         configCLEAR_TICK_INTERRUPT();\r
473 }\r
474 /*-----------------------------------------------------------*/\r
475 \r
476 #if( configUSE_TASK_FPU_SUPPORT != 2 )\r
477 \r
478         void vPortTaskUsesFPU( void )\r
479         {\r
480         uint32_t ulInitialFPSCR = 0;\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                 ulPortTaskHasFPUContext = pdTRUE;\r
485 \r
486                 /* Initialise the floating point status register. */\r
487                 __asm volatile ( "FMXR  FPSCR, %0" :: "r" (ulInitialFPSCR) : "memory" );\r
488         }\r
489 \r
490 #endif /* configUSE_TASK_FPU_SUPPORT */\r
491 /*-----------------------------------------------------------*/\r
492 \r
493 void vPortClearInterruptMask( uint32_t ulNewMaskValue )\r
494 {\r
495         if( ulNewMaskValue == pdFALSE )\r
496         {\r
497                 portCLEAR_INTERRUPT_MASK();\r
498         }\r
499 }\r
500 /*-----------------------------------------------------------*/\r
501 \r
502 uint32_t ulPortSetInterruptMask( void )\r
503 {\r
504 uint32_t ulReturn;\r
505 \r
506         /* Interrupt in the CPU must be turned off while the ICCPMR is being\r
507         updated. */\r
508         portCPU_IRQ_DISABLE();\r
509         if( portICCPMR_PRIORITY_MASK_REGISTER == ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) )\r
510         {\r
511                 /* Interrupts were already masked. */\r
512                 ulReturn = pdTRUE;\r
513         }\r
514         else\r
515         {\r
516                 ulReturn = pdFALSE;\r
517                 portICCPMR_PRIORITY_MASK_REGISTER = ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );\r
518                 __asm volatile (        "dsb            \n"\r
519                                                         "isb            \n" ::: "memory" );\r
520         }\r
521         portCPU_IRQ_ENABLE();\r
522 \r
523         return ulReturn;\r
524 }\r
525 /*-----------------------------------------------------------*/\r
526 \r
527 #if( configASSERT_DEFINED == 1 )\r
528 \r
529         void vPortValidateInterruptPriority( void )\r
530         {\r
531                 /* The following assertion will fail if a service routine (ISR) for\r
532                 an interrupt that has been assigned a priority above\r
533                 configMAX_SYSCALL_INTERRUPT_PRIORITY calls an ISR safe FreeRTOS API\r
534                 function.  ISR safe FreeRTOS API functions must *only* be called\r
535                 from interrupts that have been assigned a priority at or below\r
536                 configMAX_SYSCALL_INTERRUPT_PRIORITY.\r
537 \r
538                 Numerically low interrupt priority numbers represent logically high\r
539                 interrupt priorities, therefore the priority of the interrupt must\r
540                 be set to a value equal to or numerically *higher* than\r
541                 configMAX_SYSCALL_INTERRUPT_PRIORITY.\r
542 \r
543                 FreeRTOS maintains separate thread and ISR API functions to ensure\r
544                 interrupt entry is as fast and simple as possible. */\r
545                 configASSERT( portICCRPR_RUNNING_PRIORITY_REGISTER >= ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) );\r
546 \r
547                 /* Priority grouping:  The interrupt controller (GIC) allows the bits\r
548                 that define each interrupt's priority to be split between bits that\r
549                 define the interrupt's pre-emption priority bits and bits that define\r
550                 the interrupt's sub-priority.  For simplicity all bits must be defined\r
551                 to be pre-emption priority bits.  The following assertion will fail if\r
552                 this is not the case (if some bits represent a sub-priority).\r
553 \r
554                 The priority grouping is configured by the GIC's binary point register\r
555                 (ICCBPR).  Writting 0 to ICCBPR will ensure it is set to its lowest\r
556                 possible value (which may be above 0). */\r
557                 configASSERT( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE );\r
558         }\r
559 \r
560 #endif /* configASSERT_DEFINED */\r
561 /*-----------------------------------------------------------*/\r
562 \r
563 void vApplicationFPUSafeIRQHandler( uint32_t ulICCIAR )\r
564 {\r
565         ( void ) ulICCIAR;\r
566         configASSERT( ( volatile void * ) NULL );\r
567 }\r