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