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