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