]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/RVDS/ARM_CA9/port.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Source / portable / RVDS / 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 #ifndef configCLEAR_TICK_INTERRUPT\r
77         #define configCLEAR_TICK_INTERRUPT()\r
78 #endif\r
79 \r
80 /* The number of bits to shift for an interrupt priority is dependent on the\r
81 number of bits implemented by the interrupt controller. */\r
82 #if configUNIQUE_INTERRUPT_PRIORITIES == 16\r
83         #define portPRIORITY_SHIFT 4\r
84         #define portMAX_BINARY_POINT_VALUE      3\r
85 #elif configUNIQUE_INTERRUPT_PRIORITIES == 32\r
86         #define portPRIORITY_SHIFT 3\r
87         #define portMAX_BINARY_POINT_VALUE      2\r
88 #elif configUNIQUE_INTERRUPT_PRIORITIES == 64\r
89         #define portPRIORITY_SHIFT 2\r
90         #define portMAX_BINARY_POINT_VALUE      1\r
91 #elif configUNIQUE_INTERRUPT_PRIORITIES == 128\r
92         #define portPRIORITY_SHIFT 1\r
93         #define portMAX_BINARY_POINT_VALUE      0\r
94 #elif configUNIQUE_INTERRUPT_PRIORITIES == 256\r
95         #define portPRIORITY_SHIFT 0\r
96         #define portMAX_BINARY_POINT_VALUE      0\r
97 #else\r
98         #error Invalid configUNIQUE_INTERRUPT_PRIORITIES setting.  configUNIQUE_INTERRUPT_PRIORITIES must be set to the number of unique priorities implemented by the target hardware\r
99 #endif\r
100 \r
101 /* A critical section is exited when the critical section nesting count reaches\r
102 this value. */\r
103 #define portNO_CRITICAL_NESTING                 ( ( uint32_t ) 0 )\r
104 \r
105 /* In all GICs 255 can be written to the priority mask register to unmask all\r
106 (but the lowest) interrupt priority. */\r
107 #define portUNMASK_VALUE                                ( 0xFFUL )\r
108 \r
109 /* Tasks are not created with a floating point context, but can be given a\r
110 floating point context after they have been created.  A variable is stored as\r
111 part of the tasks context that holds portNO_FLOATING_POINT_CONTEXT if the task\r
112 does not have an FPU context, or any other value if the task does have an FPU\r
113 context. */\r
114 #define portNO_FLOATING_POINT_CONTEXT   ( ( StackType_t ) 0 )\r
115 \r
116 /* Interrupt controller access addresses. */\r
117 #define portICCPMR_PRIORITY_MASK_OFFSET                 ( 0x04 )\r
118 #define portICCIAR_INTERRUPT_ACKNOWLEDGE_OFFSET ( 0x0C )\r
119 #define portICCEOIR_END_OF_INTERRUPT_OFFSET     ( 0x10 )\r
120 #define portICCBPR_BINARY_POINT_OFFSET                  ( 0x08 )\r
121 #define portICCRPR_RUNNING_PRIORITY_OFFSET              ( 0x14 )\r
122 #define portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS          ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET )\r
123 #define portICCPMR_PRIORITY_MASK_REGISTER                                       ( *( ( volatile uint32_t * ) ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCPMR_PRIORITY_MASK_OFFSET ) ) )\r
124 #define portICCIAR_INTERRUPT_ACKNOWLEDGE_REGISTER_ADDRESS       ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCIAR_INTERRUPT_ACKNOWLEDGE_OFFSET )\r
125 #define portICCEOIR_END_OF_INTERRUPT_REGISTER_ADDRESS           ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCEOIR_END_OF_INTERRUPT_OFFSET )\r
126 #define portICCPMR_PRIORITY_MASK_REGISTER_ADDRESS                       ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCPMR_PRIORITY_MASK_OFFSET )\r
127 #define portICCBPR_BINARY_POINT_REGISTER                                        ( *( ( const volatile uint32_t * ) ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCBPR_BINARY_POINT_OFFSET ) ) )\r
128 #define portICCRPR_RUNNING_PRIORITY_REGISTER                            ( *( ( const volatile uint32_t * ) ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCRPR_RUNNING_PRIORITY_OFFSET ) ) )\r
129 \r
130 /* Used by portASSERT_IF_INTERRUPT_PRIORITY_INVALID() when ensuring the binary\r
131 point is zero. */\r
132 #define portBINARY_POINT_BITS                   ( ( uint8_t ) 0x03 )\r
133 \r
134 /* Constants required to setup the initial task context. */\r
135 #define portINITIAL_SPSR                                ( ( StackType_t ) 0x1f ) /* System mode, ARM mode, interrupts enabled. */\r
136 #define portTHUMB_MODE_BIT                              ( ( StackType_t ) 0x20 )\r
137 #define portTHUMB_MODE_ADDRESS                  ( 0x01UL )\r
138 \r
139 /* Masks all bits in the APSR other than the mode bits. */\r
140 #define portAPSR_MODE_BITS_MASK                 ( 0x1F )\r
141 \r
142 /* The value of the mode bits in the APSR when the CPU is executing in user\r
143 mode. */\r
144 #define portAPSR_USER_MODE                              ( 0x10 )\r
145 \r
146 /* Macro to unmask all interrupt priorities. */\r
147 #define portCLEAR_INTERRUPT_MASK()                                                                                      \\r
148 {                                                                                                                                                       \\r
149         __disable_irq();                                                                                                                \\r
150         portICCPMR_PRIORITY_MASK_REGISTER = portUNMASK_VALUE;                                   \\r
151         __asm(  "DSB            \n"                                                                                                     \\r
152                         "ISB            \n" );                                                                                          \\r
153         __enable_irq();                                                                                                                 \\r
154 }\r
155 \r
156 /*-----------------------------------------------------------*/\r
157 \r
158 /*\r
159  * Starts the first task executing.  This function is necessarily written in\r
160  * assembly code so is implemented in portASM.s.\r
161  */\r
162 extern void vPortRestoreTaskContext( void );\r
163 \r
164 /*\r
165  * Used to catch tasks that attempt to return from their implementing function.\r
166  */\r
167 static void prvTaskExitError( void );\r
168 \r
169 /*-----------------------------------------------------------*/\r
170 \r
171 /* A variable is used to keep track of the critical section nesting.  This\r
172 variable has to be stored as part of the task context and must be initialised to\r
173 a non zero value to ensure interrupts don't inadvertently become unmasked before\r
174 the scheduler starts.  As it is stored as part of the task context it will\r
175 automatically be set to 0 when the first task is started. */\r
176 volatile uint32_t ulCriticalNesting = 9999UL;\r
177 \r
178 /* Used to pass constants into the ASM code.  The address at which variables are\r
179 placed is the constant value so indirect loads in the asm code are not\r
180 required. */\r
181 uint32_t ulICCIAR __attribute__( ( at( portICCIAR_INTERRUPT_ACKNOWLEDGE_REGISTER_ADDRESS ) ) );\r
182 uint32_t ulICCEOIR __attribute__( ( at( portICCEOIR_END_OF_INTERRUPT_REGISTER_ADDRESS ) ) );\r
183 uint32_t ulICCPMR __attribute__( ( at( portICCPMR_PRIORITY_MASK_REGISTER_ADDRESS ) ) );\r
184 uint32_t ulAsmAPIPriorityMask __attribute__( ( at( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) ) );\r
185 \r
186 /* Saved as part of the task context.  If ulPortTaskHasFPUContext is non-zero then\r
187 a floating point context must be saved and restored for the task. */\r
188 uint32_t ulPortTaskHasFPUContext = pdFALSE;\r
189 \r
190 /* Set to 1 to pend a context switch from an ISR. */\r
191 uint32_t ulPortYieldRequired = pdFALSE;\r
192 \r
193 /* Counts the interrupt nesting depth.  A context switch is only performed if\r
194 if the nesting depth is 0. */\r
195 uint32_t ulPortInterruptNesting = 0UL;\r
196 \r
197 /*-----------------------------------------------------------*/\r
198 \r
199 /*\r
200  * See header file for description.\r
201  */\r
202 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
203 {\r
204         /* Setup the initial stack of the task.  The stack is set exactly as\r
205         expected by the portRESTORE_CONTEXT() macro.\r
206 \r
207         The fist real value on the stack is the status register, which is set for\r
208         system mode, with interrupts enabled.  A few NULLs are added first to ensure\r
209         GDB does not try decoding a non-existent return address. */\r
210         *pxTopOfStack = NULL;\r
211         pxTopOfStack--;\r
212         *pxTopOfStack = NULL;\r
213         pxTopOfStack--;\r
214         *pxTopOfStack = NULL;\r
215         pxTopOfStack--;\r
216         *pxTopOfStack = ( StackType_t ) portINITIAL_SPSR;\r
217 \r
218         if( ( ( uint32_t ) pxCode & portTHUMB_MODE_ADDRESS ) != 0x00UL )\r
219         {\r
220                 /* The task will start in THUMB mode. */\r
221                 *pxTopOfStack |= portTHUMB_MODE_BIT;\r
222         }\r
223 \r
224         pxTopOfStack--;\r
225 \r
226         /* Next the return address, which in this case is the start of the task. */\r
227         *pxTopOfStack = ( StackType_t ) pxCode;\r
228         pxTopOfStack--;\r
229 \r
230         /* Next all the registers other than the stack pointer. */\r
231         *pxTopOfStack = ( StackType_t ) prvTaskExitError;       /* R14 */\r
232         pxTopOfStack--;\r
233         *pxTopOfStack = ( StackType_t ) 0x12121212;     /* R12 */\r
234         pxTopOfStack--;\r
235         *pxTopOfStack = ( StackType_t ) 0x11111111;     /* R11 */\r
236         pxTopOfStack--;\r
237         *pxTopOfStack = ( StackType_t ) 0x10101010;     /* R10 */\r
238         pxTopOfStack--;\r
239         *pxTopOfStack = ( StackType_t ) 0x09090909;     /* R9 */\r
240         pxTopOfStack--;\r
241         *pxTopOfStack = ( StackType_t ) 0x08080808;     /* R8 */\r
242         pxTopOfStack--;\r
243         *pxTopOfStack = ( StackType_t ) 0x07070707;     /* R7 */\r
244         pxTopOfStack--;\r
245         *pxTopOfStack = ( StackType_t ) 0x06060606;     /* R6 */\r
246         pxTopOfStack--;\r
247         *pxTopOfStack = ( StackType_t ) 0x05050505;     /* R5 */\r
248         pxTopOfStack--;\r
249         *pxTopOfStack = ( StackType_t ) 0x04040404;     /* R4 */\r
250         pxTopOfStack--;\r
251         *pxTopOfStack = ( StackType_t ) 0x03030303;     /* R3 */\r
252         pxTopOfStack--;\r
253         *pxTopOfStack = ( StackType_t ) 0x02020202;     /* R2 */\r
254         pxTopOfStack--;\r
255         *pxTopOfStack = ( StackType_t ) 0x01010101;     /* R1 */\r
256         pxTopOfStack--;\r
257         *pxTopOfStack = ( StackType_t ) pvParameters; /* R0 */\r
258         pxTopOfStack--;\r
259 \r
260         /* The task will start with a critical nesting count of 0 as interrupts are\r
261         enabled. */\r
262         *pxTopOfStack = portNO_CRITICAL_NESTING;\r
263         pxTopOfStack--;\r
264 \r
265         /* The task will start without a floating point context.  A task that uses\r
266         the floating point hardware must call vPortTaskUsesFPU() before executing\r
267         any floating point instructions. */\r
268         *pxTopOfStack = portNO_FLOATING_POINT_CONTEXT;\r
269 \r
270         return pxTopOfStack;\r
271 }\r
272 /*-----------------------------------------------------------*/\r
273 \r
274 static void prvTaskExitError( void )\r
275 {\r
276         /* A function that implements a task must not exit or attempt to return to\r
277         its caller as there is nothing to return to.  If a task wants to exit it\r
278         should instead call vTaskDelete( NULL ).\r
279 \r
280         Artificially force an assert() to be triggered if configASSERT() is\r
281         defined, then stop here so application writers can catch the error. */\r
282         configASSERT( ulPortInterruptNesting == ~0UL );\r
283         portDISABLE_INTERRUPTS();\r
284         for( ;; );\r
285 }\r
286 /*-----------------------------------------------------------*/\r
287 \r
288 BaseType_t xPortStartScheduler( void )\r
289 {\r
290 uint32_t ulAPSR;\r
291 \r
292         /* Only continue if the CPU is not in User mode.  The CPU must be in a\r
293         Privileged mode for the scheduler to start. */\r
294         __asm( "MRS ulAPSR, APSR" );\r
295         ulAPSR &= portAPSR_MODE_BITS_MASK;\r
296         configASSERT( ulAPSR != portAPSR_USER_MODE );\r
297 \r
298         if( ulAPSR != portAPSR_USER_MODE )\r
299         {\r
300                 /* Only continue if the binary point value is set to its lowest possible\r
301                 setting.  See the comments in vPortValidateInterruptPriority() below for\r
302                 more information. */\r
303                 configASSERT( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE );\r
304 \r
305                 if( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE )\r
306                 {\r
307                         /* Start the timer that generates the tick ISR. */\r
308                         configSETUP_TICK_INTERRUPT();\r
309 \r
310                         __enable_irq();\r
311                         vPortRestoreTaskContext();\r
312                 }\r
313         }\r
314 \r
315         /* Will only get here if vTaskStartScheduler() was called with the CPU in\r
316         a non-privileged mode or the binary point register was not set to its lowest\r
317         possible value. */\r
318         return 0;\r
319 }\r
320 /*-----------------------------------------------------------*/\r
321 \r
322 void vPortEndScheduler( void )\r
323 {\r
324         /* Not implemented in ports where there is nothing to return to.\r
325         Artificially force an assert. */\r
326         configASSERT( ulCriticalNesting == 1000UL );\r
327 }\r
328 /*-----------------------------------------------------------*/\r
329 \r
330 void vPortEnterCritical( void )\r
331 {\r
332         /* Disable interrupts as per portDISABLE_INTERRUPTS();  */\r
333         ulPortSetInterruptMask();\r
334 \r
335         /* Now interrupts are disabled ulCriticalNesting can be accessed\r
336         directly.  Increment ulCriticalNesting to keep a count of how many times\r
337         portENTER_CRITICAL() has been called. */\r
338         ulCriticalNesting++;\r
339 \r
340         /* This is not the interrupt safe version of the enter critical function so\r
341         assert() if it is being called from an interrupt context.  Only API\r
342         functions that end in "FromISR" can be used in an interrupt.  Only assert if\r
343         the critical nesting count is 1 to protect against recursive calls if the\r
344         assert function also uses a critical section. */\r
345         if( ulCriticalNesting == 1 )\r
346         {\r
347                 configASSERT( ulPortInterruptNesting == 0 );\r
348         }\r
349 }\r
350 /*-----------------------------------------------------------*/\r
351 \r
352 void vPortExitCritical( void )\r
353 {\r
354         if( ulCriticalNesting > portNO_CRITICAL_NESTING )\r
355         {\r
356                 /* Decrement the nesting count as the critical section is being\r
357                 exited. */\r
358                 ulCriticalNesting--;\r
359 \r
360                 /* If the nesting level has reached zero then all interrupt\r
361                 priorities must be re-enabled. */\r
362                 if( ulCriticalNesting == portNO_CRITICAL_NESTING )\r
363                 {\r
364                         /* Critical nesting has reached zero so all interrupt priorities\r
365                         should be unmasked. */\r
366                         portCLEAR_INTERRUPT_MASK();\r
367                 }\r
368         }\r
369 }\r
370 /*-----------------------------------------------------------*/\r
371 \r
372 void FreeRTOS_Tick_Handler( void )\r
373 {\r
374         /* Set interrupt mask before altering scheduler structures.   The tick\r
375         handler runs at the lowest priority, so interrupts cannot already be masked,\r
376         so there is no need to save and restore the current mask value. */\r
377         __disable_irq();\r
378         portICCPMR_PRIORITY_MASK_REGISTER = ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );\r
379         __asm(  "DSB            \n"\r
380                         "ISB            \n" );\r
381         __enable_irq();\r
382 \r
383         /* Increment the RTOS tick. */\r
384         if( xTaskIncrementTick() != pdFALSE )\r
385         {\r
386                 ulPortYieldRequired = pdTRUE;\r
387         }\r
388 \r
389         /* Ensure all interrupt priorities are active again. */\r
390         portCLEAR_INTERRUPT_MASK();\r
391         configCLEAR_TICK_INTERRUPT();\r
392 }\r
393 /*-----------------------------------------------------------*/\r
394 \r
395 void vPortTaskUsesFPU( void )\r
396 {\r
397 uint32_t ulInitialFPSCR = 0;\r
398 \r
399         /* A task is registering the fact that it needs an FPU context.  Set the\r
400         FPU flag (which is saved as part of the task context). */\r
401         ulPortTaskHasFPUContext = pdTRUE;\r
402 \r
403         /* Initialise the floating point status register. */\r
404         __asm( "FMXR    FPSCR, ulInitialFPSCR" );\r
405 }\r
406 /*-----------------------------------------------------------*/\r
407 \r
408 void vPortClearInterruptMask( uint32_t ulNewMaskValue )\r
409 {\r
410         if( ulNewMaskValue == pdFALSE )\r
411         {\r
412                 portCLEAR_INTERRUPT_MASK();\r
413         }\r
414 }\r
415 /*-----------------------------------------------------------*/\r
416 \r
417 uint32_t ulPortSetInterruptMask( void )\r
418 {\r
419 uint32_t ulReturn;\r
420 \r
421         __disable_irq();\r
422         if( portICCPMR_PRIORITY_MASK_REGISTER == ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) )\r
423         {\r
424                 /* Interrupts were already masked. */\r
425                 ulReturn = pdTRUE;\r
426         }\r
427         else\r
428         {\r
429                 ulReturn = pdFALSE;\r
430                 portICCPMR_PRIORITY_MASK_REGISTER = ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );\r
431                 __asm(  "DSB            \n"\r
432                                 "ISB            \n" );\r
433         }\r
434         __enable_irq();\r
435 \r
436         return ulReturn;\r
437 }\r
438 /*-----------------------------------------------------------*/\r
439 \r
440 #if( configASSERT_DEFINED == 1 )\r
441 \r
442         void vPortValidateInterruptPriority( void )\r
443         {\r
444                 /* The following assertion will fail if a service routine (ISR) for\r
445                 an interrupt that has been assigned a priority above\r
446                 configMAX_SYSCALL_INTERRUPT_PRIORITY calls an ISR safe FreeRTOS API\r
447                 function.  ISR safe FreeRTOS API functions must *only* be called\r
448                 from interrupts that have been assigned a priority at or below\r
449                 configMAX_SYSCALL_INTERRUPT_PRIORITY.\r
450 \r
451                 Numerically low interrupt priority numbers represent logically high\r
452                 interrupt priorities, therefore the priority of the interrupt must\r
453                 be set to a value equal to or numerically *higher* than\r
454                 configMAX_SYSCALL_INTERRUPT_PRIORITY.\r
455 \r
456                 FreeRTOS maintains separate thread and ISR API functions to ensure\r
457                 interrupt entry is as fast and simple as possible.\r
458 \r
459                 The following links provide detailed information:\r
460                 http://www.freertos.org/RTOS-Cortex-M3-M4.html\r
461                 http://www.freertos.org/FAQHelp.html */\r
462                 configASSERT( portICCRPR_RUNNING_PRIORITY_REGISTER >= ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) );\r
463 \r
464                 /* Priority grouping:  The interrupt controller (GIC) allows the bits\r
465                 that define each interrupt's priority to be split between bits that\r
466                 define the interrupt's pre-emption priority bits and bits that define\r
467                 the interrupt's sub-priority.  For simplicity all bits must be defined\r
468                 to be pre-emption priority bits.  The following assertion will fail if\r
469                 this is not the case (if some bits represent a sub-priority).\r
470 \r
471                 The priority grouping is configured by the GIC's binary point register\r
472                 (ICCBPR).  Writting 0 to ICCBPR will ensure it is set to its lowest\r
473                 possible value (which may be above 0). */\r
474                 configASSERT( portICCBPR_BINARY_POINT_REGISTER <= portMAX_BINARY_POINT_VALUE );\r
475         }\r
476 \r
477 #endif /* configASSERT_DEFINED */\r
478 \r
479 \r
480 \r
481 \r