]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/GCC/TriCore_1782/port.c
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Source / portable / GCC / TriCore_1782 / port.c
1 /*\r
2     FreeRTOS V9.0.0rc2 - Copyright (C) 2016 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     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /* Standard includes. */\r
71 #include <stdlib.h>\r
72 #include <string.h>\r
73 \r
74 /* TriCore specific includes. */\r
75 #include <tc1782.h>\r
76 #include <machine/intrinsics.h>\r
77 #include <machine/cint.h>\r
78 #include <machine/wdtcon.h>\r
79 \r
80 /* Kernel includes. */\r
81 #include "FreeRTOS.h"\r
82 #include "task.h"\r
83 #include "list.h"\r
84 \r
85 #if configCHECK_FOR_STACK_OVERFLOW > 0\r
86         #error "Stack checking cannot be used with this port, as, unlike most ports, the pxTopOfStack member of the TCB is consumed CSA.  CSA starvation, loosely equivalent to stack overflow, will result in a trap exception."\r
87         /* The stack pointer is accessible using portCSA_TO_ADDRESS( portCSA_TO_ADDRESS( pxCurrentTCB->pxTopOfStack )[ 0 ] )[ 2 ]; */\r
88 #endif /* configCHECK_FOR_STACK_OVERFLOW */\r
89 \r
90 \r
91 /*-----------------------------------------------------------*/\r
92 \r
93 /* System register Definitions. */\r
94 #define portSYSTEM_PROGRAM_STATUS_WORD                                  ( 0x000008FFUL ) /* Supervisor Mode, MPU Register Set 0 and Call Depth Counting disabled. */\r
95 #define portINITIAL_PRIVILEGED_PROGRAM_STATUS_WORD              ( 0x000014FFUL ) /* IO Level 1, MPU Register Set 1 and Call Depth Counting disabled. */\r
96 #define portINITIAL_UNPRIVILEGED_PROGRAM_STATUS_WORD    ( 0x000010FFUL ) /* IO Level 0, MPU Register Set 1 and Call Depth Counting disabled. */\r
97 #define portINITIAL_PCXI_UPPER_CONTEXT_WORD                             ( 0x00C00000UL ) /* The lower 20 bits identify the CSA address. */\r
98 #define portINITIAL_SYSCON                                                              ( 0x00000000UL ) /* MPU Disable. */\r
99 \r
100 /* CSA manipulation macros. */\r
101 #define portCSA_FCX_MASK                                        ( 0x000FFFFFUL )\r
102 \r
103 /* OS Interrupt and Trap mechanisms. */\r
104 #define portRESTORE_PSW_MASK                            ( ~( 0x000000FFUL ) )\r
105 #define portSYSCALL_TRAP                                        ( 6 )\r
106 \r
107 /* Each CSA contains 16 words of data. */\r
108 #define portNUM_WORDS_IN_CSA                            ( 16 )\r
109 \r
110 /* The interrupt enable bit in the PCP_SRC register. */\r
111 #define portENABLE_CPU_INTERRUPT                        ( 1U << 12U )\r
112 /*-----------------------------------------------------------*/\r
113 \r
114 /*\r
115  * Perform any hardware configuration necessary to generate the tick interrupt.\r
116  */\r
117 static void prvSystemTickHandler( int ) __attribute__((longcall));\r
118 static void prvSetupTimerInterrupt( void );\r
119 \r
120 /*\r
121  * Trap handler for yields.\r
122  */\r
123 static void prvTrapYield( int iTrapIdentification );\r
124 \r
125 /*\r
126  * Priority 1 interrupt handler for yields pended from an interrupt.\r
127  */\r
128 static void prvInterruptYield( int iTrapIdentification );\r
129 \r
130 /*-----------------------------------------------------------*/\r
131 \r
132 /* This reference is required by the save/restore context macros. */\r
133 extern volatile uint32_t *pxCurrentTCB;\r
134 \r
135 /* Precalculate the compare match value at compile time. */\r
136 static const uint32_t ulCompareMatchValue = ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ );\r
137 \r
138 /*-----------------------------------------------------------*/\r
139 \r
140 StackType_t *pxPortInitialiseStack( StackType_t * pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
141 {\r
142 uint32_t *pulUpperCSA = NULL;\r
143 uint32_t *pulLowerCSA = NULL;\r
144 \r
145         /* 16 Address Registers (4 Address registers are global), 16 Data\r
146         Registers, and 3 System Registers.\r
147 \r
148         There are 3 registers that track the CSAs.\r
149                 FCX points to the head of globally free set of CSAs.\r
150                 PCX for the task needs to point to Lower->Upper->NULL arrangement.\r
151                 LCX points to the last free CSA so that corrective action can be taken.\r
152 \r
153         Need two CSAs to store the context of a task.\r
154                 The upper context contains D8-D15, A10-A15, PSW and PCXI->NULL.\r
155                 The lower context contains D0-D7, A2-A7, A11 and PCXI->UpperContext.\r
156                 The pxCurrentTCB->pxTopOfStack points to the Lower Context RSLCX matching the initial BISR.\r
157                 The Lower Context points to the Upper Context ready for the return from the interrupt handler.\r
158 \r
159          The Real stack pointer for the task is stored in the A10 which is restored\r
160          with the upper context. */\r
161 \r
162         /* Have to disable interrupts here because the CSAs are going to be\r
163         manipulated. */\r
164         portENTER_CRITICAL();\r
165         {\r
166                 /* DSync to ensure that buffering is not a problem. */\r
167                 _dsync();\r
168 \r
169                 /* Consume two free CSAs. */\r
170                 pulLowerCSA = portCSA_TO_ADDRESS( _mfcr( $FCX ) );\r
171                 if( NULL != pulLowerCSA )\r
172                 {\r
173                         /* The Lower Links to the Upper. */\r
174                         pulUpperCSA = portCSA_TO_ADDRESS( pulLowerCSA[ 0 ] );\r
175                 }\r
176 \r
177                 /* Check that we have successfully reserved two CSAs. */\r
178                 if( ( NULL != pulLowerCSA ) && ( NULL != pulUpperCSA ) )\r
179                 {\r
180                         /* Remove the two consumed CSAs from the free CSA list. */\r
181                         _disable();\r
182                         _dsync();\r
183                         _mtcr( $FCX, pulUpperCSA[ 0 ] );\r
184                         _isync();\r
185                         _enable();\r
186                 }\r
187                 else\r
188                 {\r
189                         /* Simply trigger a context list depletion trap. */\r
190                         _svlcx();\r
191                 }\r
192         }\r
193         portEXIT_CRITICAL();\r
194 \r
195         /* Clear the upper CSA. */\r
196         memset( pulUpperCSA, 0, portNUM_WORDS_IN_CSA * sizeof( uint32_t ) );\r
197 \r
198         /* Upper Context. */\r
199         pulUpperCSA[ 2 ] = ( uint32_t )pxTopOfStack;            /* A10; Stack Return aka Stack Pointer */\r
200         pulUpperCSA[ 1 ] = portSYSTEM_PROGRAM_STATUS_WORD;              /* PSW  */\r
201 \r
202         /* Clear the lower CSA. */\r
203         memset( pulLowerCSA, 0, portNUM_WORDS_IN_CSA * sizeof( uint32_t ) );\r
204 \r
205         /* Lower Context. */\r
206         pulLowerCSA[ 8 ] = ( uint32_t ) pvParameters;           /* A4;  Address Type Parameter Register */\r
207         pulLowerCSA[ 1 ] = ( uint32_t ) pxCode;                 /* A11; Return Address aka RA */\r
208 \r
209         /* PCXI pointing to the Upper context. */\r
210         pulLowerCSA[ 0 ] = ( portINITIAL_PCXI_UPPER_CONTEXT_WORD | ( uint32_t ) portADDRESS_TO_CSA( pulUpperCSA ) );\r
211 \r
212         /* Save the link to the CSA in the top of stack. */\r
213         pxTopOfStack = (uint32_t * ) portADDRESS_TO_CSA( pulLowerCSA );\r
214 \r
215         /* DSync to ensure that buffering is not a problem. */\r
216         _dsync();\r
217 \r
218         return pxTopOfStack;\r
219 }\r
220 /*-----------------------------------------------------------*/\r
221 \r
222 int32_t xPortStartScheduler( void )\r
223 {\r
224 extern void vTrapInstallHandlers( void );\r
225 uint32_t ulMFCR = 0UL;\r
226 uint32_t *pulUpperCSA = NULL;\r
227 uint32_t *pulLowerCSA = NULL;\r
228 \r
229         /* Interrupts at or below configMAX_SYSCALL_INTERRUPT_PRIORITY are disable\r
230         when this function is called. */\r
231 \r
232         /* Set-up the timer interrupt. */\r
233         prvSetupTimerInterrupt();\r
234 \r
235         /* Install the Trap Handlers. */\r
236         vTrapInstallHandlers();\r
237 \r
238         /* Install the Syscall Handler for yield calls. */\r
239         if( 0 == _install_trap_handler( portSYSCALL_TRAP, prvTrapYield ) )\r
240         {\r
241                 /* Failed to install the yield handler, force an assert. */\r
242                 configASSERT( ( ( volatile void * ) NULL ) );\r
243         }\r
244 \r
245         /* Enable then install the priority 1 interrupt for pending context\r
246         switches from an ISR.  See mod_SRC in the TriCore manual. */\r
247         CPU_SRC0.reg =  ( portENABLE_CPU_INTERRUPT ) | ( configKERNEL_YIELD_PRIORITY );\r
248         if( 0 == _install_int_handler( configKERNEL_YIELD_PRIORITY, prvInterruptYield, 0 ) )\r
249         {\r
250                 /* Failed to install the yield handler, force an assert. */\r
251                 configASSERT( ( ( volatile void * ) NULL ) );\r
252         }\r
253 \r
254         _disable();\r
255 \r
256         /* Load the initial SYSCON. */\r
257         _mtcr( $SYSCON, portINITIAL_SYSCON );\r
258         _isync();\r
259 \r
260         /* ENDINIT has already been applied in the 'cstart.c' code. */\r
261 \r
262         /* Clear the PSW.CDC to enable the use of an RFE without it generating an\r
263         exception because this code is not genuinely in an exception. */\r
264         ulMFCR = _mfcr( $PSW );\r
265         ulMFCR &= portRESTORE_PSW_MASK;\r
266         _dsync();\r
267         _mtcr( $PSW, ulMFCR );\r
268         _isync();\r
269 \r
270         /* Finally, perform the equivalent of a portRESTORE_CONTEXT() */\r
271         pulLowerCSA = portCSA_TO_ADDRESS( ( *pxCurrentTCB ) );\r
272         pulUpperCSA = portCSA_TO_ADDRESS( pulLowerCSA[0] );\r
273         _dsync();\r
274         _mtcr( $PCXI, *pxCurrentTCB );\r
275         _isync();\r
276         _nop();\r
277         _rslcx();\r
278         _nop();\r
279 \r
280         /* Return to the first task selected to execute. */\r
281         __asm volatile( "rfe" );\r
282 \r
283         /* Will not get here. */\r
284         return 0;\r
285 }\r
286 /*-----------------------------------------------------------*/\r
287 \r
288 static void prvSetupTimerInterrupt( void )\r
289 {\r
290         /* Set-up the clock divider. */\r
291         unlock_wdtcon();\r
292         {\r
293                 /* Wait until access to Endint protected register is enabled. */\r
294                 while( 0 != ( WDT_CON0.reg & 0x1UL ) );\r
295 \r
296                 /* RMC == 1 so STM Clock == FPI */\r
297                 STM_CLC.reg = ( 1UL << 8 );\r
298         }\r
299         lock_wdtcon();\r
300 \r
301     /* Determine how many bits are used without changing other bits in the CMCON register. */\r
302         STM_CMCON.reg &= ~( 0x1fUL );\r
303         STM_CMCON.reg |= ( 0x1fUL - __CLZ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) );\r
304 \r
305         /* Take into account the current time so a tick doesn't happen immediately. */\r
306         STM_CMP0.reg = ulCompareMatchValue + STM_TIM0.reg;\r
307 \r
308         if( 0 != _install_int_handler( configKERNEL_INTERRUPT_PRIORITY, prvSystemTickHandler, 0 ) )\r
309         {\r
310                 /* Set-up the interrupt. */\r
311                 STM_SRC0.reg = ( configKERNEL_INTERRUPT_PRIORITY | 0x00005000UL );\r
312 \r
313                 /* Enable the Interrupt. */\r
314                 STM_ISRR.reg &= ~( 0x03UL );\r
315                 STM_ISRR.reg |= 0x1UL;\r
316                 STM_ISRR.reg &= ~( 0x07UL );\r
317                 STM_ICR.reg |= 0x1UL;\r
318         }\r
319         else\r
320         {\r
321                 /* Failed to install the Tick Interrupt. */\r
322                 configASSERT( ( ( volatile void * ) NULL ) );\r
323         }\r
324 }\r
325 /*-----------------------------------------------------------*/\r
326 \r
327 static void prvSystemTickHandler( int iArg )\r
328 {\r
329 uint32_t ulSavedInterruptMask;\r
330 uint32_t *pxUpperCSA = NULL;\r
331 uint32_t xUpperCSA = 0UL;\r
332 extern volatile uint32_t *pxCurrentTCB;\r
333 int32_t lYieldRequired;\r
334 \r
335         /* Just to avoid compiler warnings about unused parameters. */\r
336         ( void ) iArg;\r
337 \r
338         /* Clear the interrupt source. */\r
339         STM_ISRR.reg = 1UL;\r
340 \r
341         /* Reload the Compare Match register for X ticks into the future.\r
342 \r
343         If critical section or interrupt nesting budgets are exceeded, then\r
344         it is possible that the calculated next compare match value is in the\r
345         past.  If this occurs (unlikely), it is possible that the resulting\r
346         time slippage will exceed a single tick period.  Any adverse effect of\r
347         this is time bounded by the fact that only the first n bits of the 56 bit\r
348         STM timer are being used for a compare match, so another compare match\r
349         will occur after an overflow in just those n bits (not the entire 56 bits).\r
350         As an example, if the peripheral clock is 75MHz, and the tick rate is 1KHz,\r
351         a missed tick could result in the next tick interrupt occurring within a\r
352         time that is 1.7 times the desired period.  The fact that this is greater\r
353         than a single tick period is an effect of using a timer that cannot be\r
354         automatically reset, in hardware, by the occurrence of a tick interrupt.\r
355         Changing the tick source to a timer that has an automatic reset on compare\r
356         match (such as a GPTA timer) will reduce the maximum possible additional\r
357         period to exactly 1 times the desired period. */\r
358         STM_CMP0.reg += ulCompareMatchValue;\r
359 \r
360         /* Kernel API calls require Critical Sections. */\r
361         ulSavedInterruptMask = portSET_INTERRUPT_MASK_FROM_ISR();\r
362         {\r
363                 /* Increment the Tick. */\r
364                 lYieldRequired = xTaskIncrementTick();\r
365         }\r
366         portCLEAR_INTERRUPT_MASK_FROM_ISR( ulSavedInterruptMask );\r
367 \r
368         if( lYieldRequired != pdFALSE )\r
369         {\r
370                 /* Save the context of a task.\r
371                 The upper context is automatically saved when entering a trap or interrupt.\r
372                 Need to save the lower context as well and copy the PCXI CSA ID into\r
373                 pxCurrentTCB->pxTopOfStack. Only Lower Context CSA IDs may be saved to the\r
374                 TCB of a task.\r
375 \r
376                 Call vTaskSwitchContext to select the next task, note that this changes the\r
377                 value of pxCurrentTCB so that it needs to be reloaded.\r
378 \r
379                 Call vPortSetMPURegisterSetOne to change the MPU mapping for the task\r
380                 that has just been switched in.\r
381 \r
382                 Load the context of the task.\r
383                 Need to restore the lower context by loading the CSA from\r
384                 pxCurrentTCB->pxTopOfStack into PCXI (effectively changing the call stack).\r
385                 In the Interrupt handler post-amble, RSLCX will restore the lower context\r
386                 of the task. RFE will restore the upper context of the task, jump to the\r
387                 return address and restore the previous state of interrupts being\r
388                 enabled/disabled. */\r
389                 _disable();\r
390                 _dsync();\r
391                 xUpperCSA = _mfcr( $PCXI );\r
392                 pxUpperCSA = portCSA_TO_ADDRESS( xUpperCSA );\r
393                 *pxCurrentTCB = pxUpperCSA[ 0 ];\r
394                 vTaskSwitchContext();\r
395                 pxUpperCSA[ 0 ] = *pxCurrentTCB;\r
396                 CPU_SRC0.bits.SETR = 0;\r
397                 _isync();\r
398         }\r
399 }\r
400 /*-----------------------------------------------------------*/\r
401 \r
402 /*\r
403  * When a task is deleted, it is yielded permanently until the IDLE task\r
404  * has an opportunity to reclaim the memory that that task was using.\r
405  * Typically, the memory used by a task is the TCB and Stack but in the\r
406  * TriCore this includes the CSAs that were consumed as part of the Call\r
407  * Stack. These CSAs can only be returned to the Globally Free Pool when\r
408  * they are not part of the current Call Stack, hence, delaying the\r
409  * reclamation until the IDLE task is freeing the task's other resources.\r
410  * This function uses the head of the linked list of CSAs (from when the\r
411  * task yielded for the last time) and finds the tail (the very bottom of\r
412  * the call stack) and inserts this list at the head of the Free list,\r
413  * attaching the existing Free List to the tail of the reclaimed call stack.\r
414  *\r
415  * NOTE: the IDLE task needs processing time to complete this function\r
416  * and in heavily loaded systems, the Free CSAs may be consumed faster\r
417  * than they can be freed assuming that tasks are being spawned and\r
418  * deleted frequently.\r
419  */\r
420 void vPortReclaimCSA( uint32_t *pxTCB )\r
421 {\r
422 uint32_t pxHeadCSA, pxTailCSA, pxFreeCSA;\r
423 uint32_t *pulNextCSA;\r
424 \r
425         /* A pointer to the first CSA in the list of CSAs consumed by the task is\r
426         stored in the first element of the tasks TCB structure (where the stack\r
427         pointer would be on a traditional stack based architecture). */\r
428         pxHeadCSA = ( *pxTCB ) & portCSA_FCX_MASK;\r
429 \r
430         /* Mask off everything in the CSA link field other than the address.  If\r
431         the     address is NULL, then the CSA is not linking anywhere and there is\r
432         nothing to do. */\r
433         pxTailCSA = pxHeadCSA;\r
434 \r
435         /* Convert the link value to contain just a raw address and store this\r
436         in a local variable. */\r
437         pulNextCSA = portCSA_TO_ADDRESS( pxTailCSA );\r
438 \r
439         /* Iterate over the CSAs that were consumed as part of the task.  The\r
440         first field in the CSA is the pointer to then next CSA.  Mask off\r
441         everything in the pointer to the next CSA, other than the link address.\r
442         If this is NULL, then the CSA currently being pointed to is the last in\r
443         the chain. */\r
444         while( 0UL != ( pulNextCSA[ 0 ] & portCSA_FCX_MASK ) )\r
445         {\r
446                 /* Clear all bits of the pointer to the next in the chain, other\r
447                 than the address bits themselves. */\r
448                 pulNextCSA[ 0 ] = pulNextCSA[ 0 ] & portCSA_FCX_MASK;\r
449 \r
450                 /* Move the pointer to point to the next CSA in the list. */\r
451                 pxTailCSA = pulNextCSA[ 0 ];\r
452 \r
453                 /* Update the local pointer to the CSA. */\r
454                 pulNextCSA = portCSA_TO_ADDRESS( pxTailCSA );\r
455         }\r
456 \r
457         _disable();\r
458         {\r
459                 /* Look up the current free CSA head. */\r
460                 _dsync();\r
461                 pxFreeCSA = _mfcr( $FCX );\r
462 \r
463                 /* Join the current Free onto the Tail of what is being reclaimed. */\r
464                 portCSA_TO_ADDRESS( pxTailCSA )[ 0 ] = pxFreeCSA;\r
465 \r
466                 /* Move the head of the reclaimed into the Free. */\r
467                 _dsync();\r
468                 _mtcr( $FCX, pxHeadCSA );\r
469                 _isync();\r
470         }\r
471         _enable();\r
472 }\r
473 /*-----------------------------------------------------------*/\r
474 \r
475 void vPortEndScheduler( void )\r
476 {\r
477         /* Nothing to do. Unlikely to want to end. */\r
478 }\r
479 /*-----------------------------------------------------------*/\r
480 \r
481 static void prvTrapYield( int iTrapIdentification )\r
482 {\r
483 uint32_t *pxUpperCSA = NULL;\r
484 uint32_t xUpperCSA = 0UL;\r
485 extern volatile uint32_t *pxCurrentTCB;\r
486 \r
487         switch( iTrapIdentification )\r
488         {\r
489                 case portSYSCALL_TASK_YIELD:\r
490                         /* Save the context of a task.\r
491                         The upper context is automatically saved when entering a trap or interrupt.\r
492                         Need to save the lower context as well and copy the PCXI CSA ID into\r
493                         pxCurrentTCB->pxTopOfStack. Only Lower Context CSA IDs may be saved to the\r
494                         TCB of a task.\r
495 \r
496                         Call vTaskSwitchContext to select the next task, note that this changes the\r
497                         value of pxCurrentTCB so that it needs to be reloaded.\r
498 \r
499                         Call vPortSetMPURegisterSetOne to change the MPU mapping for the task\r
500                         that has just been switched in.\r
501 \r
502                         Load the context of the task.\r
503                         Need to restore the lower context by loading the CSA from\r
504                         pxCurrentTCB->pxTopOfStack into PCXI (effectively changing the call stack).\r
505                         In the Interrupt handler post-amble, RSLCX will restore the lower context\r
506                         of the task. RFE will restore the upper context of the task, jump to the\r
507                         return address and restore the previous state of interrupts being\r
508                         enabled/disabled. */\r
509                         _disable();\r
510                         _dsync();\r
511                         xUpperCSA = _mfcr( $PCXI );\r
512                         pxUpperCSA = portCSA_TO_ADDRESS( xUpperCSA );\r
513                         *pxCurrentTCB = pxUpperCSA[ 0 ];\r
514                         vTaskSwitchContext();\r
515                         pxUpperCSA[ 0 ] = *pxCurrentTCB;\r
516                         CPU_SRC0.bits.SETR = 0;\r
517                         _isync();\r
518                         break;\r
519 \r
520                 default:\r
521                         /* Unimplemented trap called. */\r
522                         configASSERT( ( ( volatile void * ) NULL ) );\r
523                         break;\r
524         }\r
525 }\r
526 /*-----------------------------------------------------------*/\r
527 \r
528 static void prvInterruptYield( int iId )\r
529 {\r
530 uint32_t *pxUpperCSA = NULL;\r
531 uint32_t xUpperCSA = 0UL;\r
532 extern volatile uint32_t *pxCurrentTCB;\r
533 \r
534         /* Just to remove compiler warnings. */\r
535         ( void ) iId;\r
536 \r
537         /* Save the context of a task.\r
538         The upper context is automatically saved when entering a trap or interrupt.\r
539         Need to save the lower context as well and copy the PCXI CSA ID into\r
540         pxCurrentTCB->pxTopOfStack. Only Lower Context CSA IDs may be saved to the\r
541         TCB of a task.\r
542 \r
543         Call vTaskSwitchContext to select the next task, note that this changes the\r
544         value of pxCurrentTCB so that it needs to be reloaded.\r
545 \r
546         Call vPortSetMPURegisterSetOne to change the MPU mapping for the task\r
547         that has just been switched in.\r
548 \r
549         Load the context of the task.\r
550         Need to restore the lower context by loading the CSA from\r
551         pxCurrentTCB->pxTopOfStack into PCXI (effectively changing the call stack).\r
552         In the Interrupt handler post-amble, RSLCX will restore the lower context\r
553         of the task. RFE will restore the upper context of the task, jump to the\r
554         return address and restore the previous state of interrupts being\r
555         enabled/disabled. */\r
556         _disable();\r
557         _dsync();\r
558         xUpperCSA = _mfcr( $PCXI );\r
559         pxUpperCSA = portCSA_TO_ADDRESS( xUpperCSA );\r
560         *pxCurrentTCB = pxUpperCSA[ 0 ];\r
561         vTaskSwitchContext();\r
562         pxUpperCSA[ 0 ] = *pxCurrentTCB;\r
563         CPU_SRC0.bits.SETR = 0;\r
564         _isync();\r
565 }\r
566 /*-----------------------------------------------------------*/\r
567 \r
568 uint32_t uxPortSetInterruptMaskFromISR( void )\r
569 {\r
570 uint32_t uxReturn = 0UL;\r
571 \r
572         _disable();\r
573         uxReturn = _mfcr( $ICR );\r
574         _mtcr( $ICR, ( ( uxReturn & ~portCCPN_MASK ) | configMAX_SYSCALL_INTERRUPT_PRIORITY ) );\r
575         _isync();\r
576         _enable();\r
577 \r
578         /* Return just the interrupt mask bits. */\r
579         return ( uxReturn & portCCPN_MASK );\r
580 }\r
581 /*-----------------------------------------------------------*/\r
582 \r
583 \r