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