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