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