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