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