]> git.sur5r.net Git - freertos/blob - Source/portable/Softune/MB96340/port.c
Work in progress.
[freertos] / Source / portable / Softune / MB96340 / port.c
1 /*\r
2         FreeRTOS.org V4.7.1 - Copyright (C) 2003-2008 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org is free software; you can redistribute it and/or modify\r
7         it under the terms of the GNU General Public License as published by\r
8         the Free Software Foundation; either version 2 of the License, or\r
9         (at your option) any later version.\r
10 \r
11         FreeRTOS.org is distributed in the hope that it will be useful,\r
12         but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14         GNU General Public License for more details.\r
15 \r
16         You should have received a copy of the GNU General Public License\r
17         along with FreeRTOS.org; if not, write to the Free Software\r
18         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19 \r
20         A special exception to the GPL can be applied should you wish to distribute\r
21         a combined work that includes FreeRTOS.org, without being obliged to provide\r
22         the source code for any proprietary components.  See the licensing section\r
23         of http://www.FreeRTOS.org for full details of how and when the exception\r
24         can be applied.\r
25 \r
26         ***************************************************************************\r
27 \r
28         Please ensure to read the configuration and relevant port sections of the \r
29         online documentation.\r
30 \r
31         +++ http://www.FreeRTOS.org +++\r
32         Documentation, latest information, license and contact details.  \r
33 \r
34         +++ http://www.SafeRTOS.com +++\r
35         A version that is certified for use in safety critical systems.\r
36 \r
37         +++ http://www.OpenRTOS.com +++\r
38         Commercial support, development, porting, licensing and training services.\r
39 \r
40         ***************************************************************************\r
41 */\r
42 \r
43 #include "FreeRTOS.h"\r
44 #include "task.h"\r
45 #include "mb96348hs.h"\r
46 \r
47 /*-----------------------------------------------------------\r
48  * Implementation of functions defined in portable.h for the 16FX port.\r
49  *----------------------------------------------------------*/\r
50 \r
51 /* \r
52  * The below define should be same as the option selected by the Memory \r
53  * Model (Project->Setup Project->C Compiler->Catagory->Target Depend ) \r
54  */\r
55 #define configMEMMODEL portMEDIUM\r
56 \r
57 /*-----------------------------------------------------------*/\r
58 \r
59 /* \r
60  * Get current value of DPR and ADB registers \r
61  */\r
62 portSTACK_TYPE xGet_DPR_ADB_bank( void ); \r
63 \r
64 /* \r
65  * Get current value of DTB and PCB registers \r
66  */\r
67 portSTACK_TYPE xGet_DTB_PCB_bank( void );\r
68 \r
69 /* \r
70  * Get current register pointer \r
71  */ \r
72 portCHAR xGet_RP( void );           \r
73 \r
74 /*\r
75  * Sets up the periodic ISR used for the RTOS tick.  This uses RLT0, but\r
76  * can be done using any given RLT.\r
77  */\r
78 static void prvSetupRLT0Interrupt( void );\r
79 \r
80 /*-----------------------------------------------------------*/         \r
81 \r
82 /* \r
83  * We require the address of the pxCurrentTCB variable, but don't want to know\r
84  * any details of its type. \r
85  */\r
86 typedef void tskTCB;\r
87 extern volatile tskTCB * volatile pxCurrentTCB;\r
88 \r
89 /* Constants required to handle critical sections. */\r
90 #define portNO_CRITICAL_NESTING         ( ( unsigned portBASE_TYPE ) 0x1234 )\r
91 volatile unsigned portBASE_TYPE uxCriticalNesting = 9999UL;\r
92 \r
93 /*-----------------------------------------------------------*/\r
94 \r
95 /* \r
96  * Macro to save a task context to the task stack. This macro  copies the \r
97  * saved context (AH:AL, DPR:ADB, DTB:PCB , PC and PS) from  the   system \r
98  * stack to task stack pointed by user stack pointer ( USP  for SMALL and \r
99  * MEDIUM memory model amd USB:USP for COMPACT  and LARGE memory model ),\r
100  * then  it pushes the general purpose registers RW0-RW7  on  to the task \r
101  * stack. Finally the  resultant  stack  pointer  value is saved into the \r
102  * task  control  block  so  it  can  be retrieved the next time the task \r
103  * executes.\r
104  */\r
105  \r
106 #if( ( configMEMMODEL == portSMALL ) || ( configMEMMODEL == portMEDIUM ) )\r
107 \r
108         #define portSAVE_CONTEXT()                                                                                      \\r
109                         {       __asm(" POPW  A ");                                                                             \\r
110                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
111                                 __asm(" PUSHW  A ");                                                                    \\r
112                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
113                         __asm(" POPW  A ");                                                                             \\r
114                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
115                                 __asm(" PUSHW  A ");                                                                    \\r
116                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
117                                 __asm(" POPW  A ");                                                                             \\r
118                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
119                                 __asm(" PUSHW  A ");                                                                    \\r
120                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
121                                 __asm(" POPW  A ");                                                                             \\r
122                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
123                                 __asm(" PUSHW  A ");                                                                    \\r
124                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
125                                 __asm(" POPW  A ");                                                                             \\r
126                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
127                                 __asm(" PUSHW  A ");                                                                    \\r
128                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
129                                 __asm(" POPW  A ");                                                                             \\r
130                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
131                                 __asm(" PUSHW  A ");                                                                    \\r
132                                 __asm(" PUSHW (RW0,RW1,RW2,RW3,RW4,RW5,RW6,RW7) ");             \\r
133                                 __asm(" MOVW A, _pxCurrentTCB ");                                               \\r
134                                 __asm(" MOVW A, SP ");                                                                  \\r
135                                 __asm(" SWAPW ");                                                                               \\r
136                                 __asm(" MOVW @AL, AH ");                                                                \\r
137                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
138                         }\r
139 \r
140         /* \r
141          * Macro to restore a task context from the task stack.  This is effecti-\r
142          * vely the reverse of SAVE_CONTEXT(). First the stack pointer  value\r
143          * (USP for SMALL and MEDIUM memory model amd  USB:USP  for  COMPACT  and \r
144          * LARGE memory model ) is loaded from the task  control block.  Next the \r
145          * value of all the general purpose registers RW0-RW7 is retrieved. Fina-\r
146          * lly it copies of the context ( AH:AL,  DPR:ADB, DTB:PCB, PC and PS) of \r
147          * the task to be executed upon RETI from user stack to system stack.  \r
148          */\r
149  \r
150         #define portRESTORE_CONTEXT()                                                                           \\r
151                         {       __asm(" MOVW A, _pxCurrentTCB ");                                               \\r
152                                 __asm(" MOVW A, @A ");                                                                  \\r
153                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
154                                 __asm(" MOVW SP, A ");                                                                  \\r
155                                                                                                                                                 \\r
156                                 /* Load the saves uxCriticalNesting value into RW0. */  \\r
157                                 __asm(" POPW (RW0) ");                                                                  \\r
158                                                                                                                                                 \\r
159                                 /* Save the loaded value into the uxCriticalNesting variable. */ \\r
160                                 __asm(" MOVW _uxCriticalNesting, RW0 ");                                                                \\r
161                                                                                                                                                 \\r
162                                 __asm(" POPW (RW0,RW1,RW2,RW3,RW4,RW5,RW6,RW7) ");              \\r
163                                 __asm(" POPW  A ");                                                                             \\r
164                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
165                                 __asm(" PUSHW  A ");                                                                    \\r
166                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
167                                 __asm(" POPW  A ");                                                                             \\r
168                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
169                                 __asm(" PUSHW  A ");                                                                    \\r
170                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
171                                 __asm(" POPW  A ");                                                                             \\r
172                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
173                                 __asm(" PUSHW  A ");                                                                    \\r
174                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
175                                 __asm(" POPW  A ");                                                                             \\r
176                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
177                                 __asm(" PUSHW  A ");                                                                    \\r
178                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
179                                 __asm(" POPW  A ");                                                                             \\r
180                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
181                                 __asm(" PUSHW  A ");                                                                    \\r
182                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
183                                 __asm(" POPW  A ");                                                                             \\r
184                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
185                                 __asm(" PUSHW  A ");                                                                    \\r
186                         }\r
187                 \r
188 #elif (configMEMMODEL == portCOMPACT || configMEMMODEL == portLARGE)                    \r
189 \r
190         #define portSAVE_CONTEXT()                                                                                      \\r
191                         {       __asm(" POPW  A ");                                                                             \\r
192                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
193                                 __asm(" PUSHW  A ");                                                                    \\r
194                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
195                         __asm(" POPW  A ");                                                                             \\r
196                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
197                                 __asm(" PUSHW  A ");                                                                    \\r
198                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
199                                 __asm(" POPW  A ");                                                                             \\r
200                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
201                                 __asm(" PUSHW  A ");                                                                    \\r
202                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
203                                 __asm(" POPW  A ");                                                                             \\r
204                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
205                                 __asm(" PUSHW  A ");                                                                    \\r
206                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
207                                 __asm(" POPW  A ");                                                                             \\r
208                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
209                                 __asm(" PUSHW  A ");                                                                    \\r
210                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
211                                 __asm(" POPW  A ");                                                                             \\r
212                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
213                                 __asm(" PUSHW  A ");                                                                    \\r
214                                 __asm(" PUSHW (RW0,RW1,RW2,RW3,RW4,RW5,RW6,RW7) ");             \\r
215                                 __asm(" MOVL A, _pxCurrentTCB ");                                               \\r
216                                 __asm(" MOVL RL2, A ");                                                                 \\r
217                                 __asm(" MOVW A, SP ");                                                                  \\r
218                                 __asm(" MOVW @RL2+0, A ");                                                              \\r
219                                 __asm(" MOV A, USB ");                                                                  \\r
220                                 __asm(" MOV @RL2+2, A ");                                                               \\r
221                         }       \r
222             \r
223         #define portRESTORE_CONTEXT()                                                                           \\r
224                         {       __asm(" MOVL A, _pxCurrentTCB ");                                               \\r
225                                 __asm(" MOVL RL2, A ");                                                                 \\r
226                                 __asm(" MOVW A, @RL2+0 ");                                                              \\r
227                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
228                                 __asm(" MOVW SP, A ");                                                                  \\r
229                                 __asm(" MOV A, @RL2+2 ");                                                               \\r
230                                 __asm(" MOV USB, A ");                                                                  \\r
231                                 __asm(" POPW (RW0,RW1,RW2,RW3,RW4,RW5,RW6,RW7) ");              \\r
232                                 __asm(" POPW  A ");                                                                             \\r
233                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
234                                 __asm(" PUSHW  A ");                                                                    \\r
235                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
236                                 __asm(" POPW  A ");                                                                             \\r
237                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
238                                 __asm(" PUSHW  A ");                                                                    \\r
239                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
240                                 __asm(" POPW  A ");                                                                             \\r
241                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
242                                 __asm(" PUSHW  A ");                                                                    \\r
243                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
244                                 __asm(" POPW  A ");                                                                             \\r
245                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
246                                 __asm(" PUSHW  A ");                                                                    \\r
247                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
248                                 __asm(" POPW  A ");                                                                             \\r
249                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
250                                 __asm(" PUSHW  A ");                                                                    \\r
251                                 __asm(" AND  CCR,#H'DF ");                                                      \\r
252                                 __asm(" POPW  A ");                                                                             \\r
253                                 __asm(" OR   CCR,#H'20 ");                                                              \\r
254                                 __asm(" PUSHW  A ");                                                                    \\r
255                         }\r
256 #endif\r
257 \r
258 /*-----------------------------------------------------------*/ \r
259 \r
260 /* \r
261  * The below are the functions for getting the current value  of  DPR:ADB, \r
262  * DTB:PCB bank registers\r
263  */\r
264  \r
265 #pragma asm\r
266 \r
267         .GLOBAL    _xGet_DPR_ADB_bank\r
268         .GLOBAL    _xGet_DTB_PCB_bank\r
269         .GLOBAL    _xGet_RP\r
270         .SECTION   CODE, CODE, ALIGN=1\r
271 \r
272 _xGet_DPR_ADB_bank:\r
273 \r
274     MOV A, DPR\r
275     SWAP\r
276     MOV A, ADB\r
277     ORW A\r
278         #if configMEMMODEL == portMEDIUM || configMEMMODEL == portLARGE\r
279                 RETP\r
280         #elif configMEMMODEL == portSMALL || configMEMMODEL == portCOMPACT   \r
281                 RET\r
282         #endif \r
283 \r
284 \r
285 _xGet_DTB_PCB_bank:\r
286 \r
287     MOV A, DTB\r
288     SWAP\r
289     MOV A, PCB\r
290     ORW A\r
291         #if configMEMMODEL == portMEDIUM || configMEMMODEL == portLARGE\r
292                 RETP\r
293         #elif configMEMMODEL == portSMALL || configMEMMODEL == portCOMPACT   \r
294                 RET\r
295         #endif \r
296 \r
297 \r
298 _xGet_RP:\r
299 \r
300     PUSHW PS\r
301     POPW  A\r
302     SWAP\r
303     ANDW  A,#0x1f\r
304         #if configMEMMODEL == portMEDIUM || configMEMMODEL == portLARGE\r
305                 RETP\r
306         #elif configMEMMODEL == portSMALL || configMEMMODEL == portCOMPACT   \r
307                 RET\r
308         #endif \r
309 \r
310 \r
311 #pragma endasm\r
312 /*-----------------------------------------------------------*/\r
313 \r
314 /* \r
315  * Initialise the stack of a task to look exactly as if a call to \r
316  * portSAVE_CONTEXT had been called.\r
317  * \r
318  * See the header file portable.h.\r
319  */\r
320 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
321 {\r
322         /* Place a few bytes of known values on the bottom of the stack. \r
323         This is just useful for debugging. */\r
324         *pxTopOfStack = 0x1111;\r
325         pxTopOfStack--;\r
326         *pxTopOfStack = 0x2222;\r
327         pxTopOfStack--;\r
328         *pxTopOfStack = 0x3333;\r
329         pxTopOfStack--;\r
330 \r
331         /* Once the task is called the task  would  push  the  pointer to the\r
332         parameter on to the stack. Hence here the pointer would be copied first\r
333         to  the  stack.  In  case of COMPACT or LARGE memory model such pointer \r
334         would be 24 bit and in  case of SMALL or MEDIUM memory model such pointer \r
335         would be 16 bit */ \r
336         #if( ( configMEMMODEL == portCOMPACT ) || ( configMEMMODEL == portLARGE ) )\r
337         {\r
338                 *pxTopOfStack = ( portSTACK_TYPE ) ( ( unsigned portLONG ) ( pvParameters ) >> 16 );\r
339                 pxTopOfStack--;         \r
340         }\r
341         #endif\r
342 \r
343     *pxTopOfStack = ( portSTACK_TYPE ) ( pvParameters );\r
344     pxTopOfStack--;                  \r
345     \r
346     /* This is redundant push to the stack. This is required in order to introduce \r
347     an offset so that the task accesses a parameter correctly that is passed on to \r
348     the task stack. */\r
349         #if( ( configMEMMODEL == portMEDIUM ) || ( configMEMMODEL == portLARGE ) )\r
350         {\r
351                 *pxTopOfStack = ( xGet_DTB_PCB_bank() & 0xff00 ) | ( ( ( portLONG ) ( pxCode ) >> 16 ) & 0xff );      \r
352                 pxTopOfStack--;       \r
353         }\r
354         #endif\r
355 \r
356     /* This is redundant push to the stack. This is required in order to introduce \r
357     an offset so that the task accesses a parameter correctly that is passed on to \r
358     the task stack. */\r
359     *pxTopOfStack = ( portSTACK_TYPE ) ( pxCode );\r
360     pxTopOfStack--;       \r
361 \r
362     /* PS - User Mode, ILM=7, RB=0, Interrupts enabled,USP */\r
363     *pxTopOfStack = 0xE0C0;                                                     \r
364         pxTopOfStack--; \r
365 \r
366         /* PC */\r
367         *pxTopOfStack = ( portSTACK_TYPE ) ( pxCode );     \r
368     pxTopOfStack--;      \r
369     \r
370     /* DTB | PCB */\r
371         #if configMEMMODEL == portSMALL || configMEMMODEL == portCOMPACT\r
372         {\r
373                 *pxTopOfStack = xGet_DTB_PCB_bank();            \r
374                 pxTopOfStack--;\r
375         }\r
376         #endif\r
377 \r
378         /* DTB | PCB, in case of portMEDIUM or portLARGE memory model PCB would be used\r
379         along with PC to indicate the start address of the functiom */\r
380         #if( ( configMEMMODEL == portMEDIUM ) || ( configMEMMODEL == portLARGE ) )\r
381         {\r
382                 *pxTopOfStack = ( xGet_DTB_PCB_bank() & 0xff00 ) | ( ( ( portLONG ) ( pxCode ) >> 16 ) & 0xff );\r
383                 pxTopOfStack--;       \r
384         }\r
385         #endif\r
386 \r
387         /* DPR | ADB  */\r
388         *pxTopOfStack = xGet_DPR_ADB_bank();                            \r
389         pxTopOfStack--;\r
390     \r
391         /* AL */\r
392         *pxTopOfStack = ( portSTACK_TYPE ) 0x9999;              \r
393         pxTopOfStack--;\r
394 \r
395         /* AH */\r
396         *pxTopOfStack = ( portSTACK_TYPE ) 0xAAAA;              \r
397         pxTopOfStack--;\r
398         \r
399         /* Next the general purpose registers. */\r
400         *pxTopOfStack = ( portSTACK_TYPE ) 0x7777;      /* RW7 */\r
401         pxTopOfStack--;\r
402         *pxTopOfStack = ( portSTACK_TYPE ) 0x6666;      /* RW6 */\r
403         pxTopOfStack--;\r
404         *pxTopOfStack = ( portSTACK_TYPE ) 0x5555;      /* RW5 */\r
405         pxTopOfStack--;\r
406         *pxTopOfStack = ( portSTACK_TYPE ) 0x4444;      /* RW4 */\r
407         pxTopOfStack--;\r
408         *pxTopOfStack = ( portSTACK_TYPE ) 0x3333;      /* RW3 */\r
409         pxTopOfStack--;\r
410         *pxTopOfStack = ( portSTACK_TYPE ) 0x2222;      /* RW2 */\r
411         pxTopOfStack--;\r
412         *pxTopOfStack = ( portSTACK_TYPE ) 0x1111;      /* RW1 */\r
413         pxTopOfStack--;\r
414         *pxTopOfStack = ( portSTACK_TYPE ) 0x8888;      /* RW0 */\r
415         pxTopOfStack--;\r
416 \r
417         /* The task starts with its uxCriticalNesting variable set to 0, interrupts\r
418         being enabled. */\r
419         *pxTopOfStack = portNO_CRITICAL_NESTING;\r
420                 \r
421         return pxTopOfStack;\r
422 }\r
423 /*-----------------------------------------------------------*/\r
424 \r
425 static void prvSetupRLT0Interrupt( void )\r
426 {\r
427         /* set reload value = 34999+1, TICK Interrupt after 10 ms @ 56MHz of CLKP1 */\r
428         TMRLR0 = 0x88B7;    \r
429     \r
430     /* prescaler 1:16, reload, interrupt enable, count enable, trigger */\r
431     TMCSR0 = 0x041B;    \r
432 }\r
433 /*-----------------------------------------------------------*/\r
434 \r
435 portBASE_TYPE xPortStartScheduler( void )\r
436 {\r
437         /* Setup the hardware to generate the tick. */\r
438         prvSetupRLT0Interrupt();\r
439         \r
440         /* Restore the context of the first task that is going to run. */\r
441         portRESTORE_CONTEXT();\r
442 \r
443         /* Simulate a function call end as generated by the compiler.  We will now\r
444         jump to the start of the task the context of which we have just restored. */\r
445         \r
446         __asm(" reti ");\r
447 \r
448 \r
449         /* Should not get here. */\r
450         return pdTRUE;\r
451 }\r
452 /*-----------------------------------------------------------*/\r
453 \r
454 void vPortEndScheduler( void )\r
455 {\r
456         /* Not implemented - unlikely to ever be required as there is nothing to\r
457         return to. */\r
458 }\r
459 \r
460 /*-----------------------------------------------------------*/\r
461 \r
462 /* \r
463  * The interrupt service routine used depends on whether the pre-emptive\r
464  * scheduler is being used or not.\r
465  */\r
466 \r
467 #if configUSE_PREEMPTION == 1\r
468 \r
469         /* \r
470          * Tick ISR for preemptive scheduler.  We can use a __nosavereg attribute\r
471          * as the context would be saved by PortSAVE_CONTEXT().  The tick count \r
472          * is incremented after the context is saved. \r
473          */\r
474         __nosavereg __interrupt void prvRLT0_TICKISR( void )\r
475         {\r
476                 /* Disable interrupts so that portSAVE_CONTEXT() is not interrupted */\r
477                 __DI();\r
478                 \r
479                 /* Save the context of the interrupted task. */\r
480                 portSAVE_CONTEXT();\r
481                 \r
482                 /* Enable interrupts */\r
483                 __EI();\r
484                 \r
485                 /* Clear RLT0 interrupt flag */\r
486                 TMCSR0_UF = 0;      \r
487                 \r
488                 /* Increment the tick count then switch to the highest priority task\r
489                 that is ready to run. */\r
490                 vTaskIncrementTick();\r
491                 vTaskSwitchContext();\r
492 \r
493                 /* Disable interrupts so that portRESTORE_CONTEXT() is not interrupted */\r
494                 __DI();\r
495                 \r
496                 /* Restore the context of the new task. */\r
497                 portRESTORE_CONTEXT();\r
498                 \r
499                 /* Enable interrupts */\r
500                 __EI();\r
501         }\r
502 \r
503 #else\r
504 \r
505         /*\r
506          * Tick ISR for the cooperative scheduler.  All this does is increment the\r
507          * tick count.  We don't need to switch context, this can only be done by\r
508          * manual calls to taskYIELD();\r
509          */\r
510         __interrupt void prvRLT0_TICKISR( void )\r
511         {\r
512                 /* Clear RLT0 interrupt flag */\r
513                 TMCSR0_UF = 0;  \r
514                 \r
515                 vTaskIncrementTick();\r
516         }\r
517 \r
518 #endif\r
519 \r
520 /*-----------------------------------------------------------*/\r
521 \r
522 /*\r
523  * Manual context switch. We can use a __nosavereg attribute  as the context \r
524  * would be saved by PortSAVE_CONTEXT().  The context is switched and then \r
525  * the context of the new task is restored saved. \r
526  */\r
527 __nosavereg __interrupt void vPortYield( void )\r
528 {\r
529         /* Save the context of the interrupted task. */\r
530         portSAVE_CONTEXT();\r
531         \r
532         /* Switch to the highest priority task that is ready to run. */\r
533         vTaskSwitchContext();\r
534         \r
535         /* Restore the context of the new task. */\r
536         portRESTORE_CONTEXT();\r
537 }\r
538 /*-----------------------------------------------------------*/\r
539 \r
540 __nosavereg __interrupt void vPortYieldDelayed( void )\r
541 {    \r
542     /* Disable interrupts so that portSAVE_CONTEXT() is not interrupted */      \r
543         __DI();\r
544         \r
545         /* Save the context of the interrupted task. */\r
546         portSAVE_CONTEXT();\r
547         \r
548         /* Enable interrupts */\r
549         __EI();\r
550                                 \r
551         /* Clear delayed interrupt flag */\r
552     __asm (" CLRB  03A4H:0 ");\r
553         \r
554         /* Switch to the highest priority task that is ready to run. */\r
555         vTaskSwitchContext();\r
556         \r
557         /* Disable interrupts so that portSAVE_CONTEXT() is not interrupted */   \r
558         __DI();\r
559         \r
560         /* Restore the context of the new task. */\r
561         portRESTORE_CONTEXT();\r
562 \r
563         /* Enable interrupts */\r
564         __EI();\r
565 }       \r
566 /*-----------------------------------------------------------*/\r
567 \r
568 void vPortEnterCritical( void )\r
569 {\r
570         /* Disable interrupts */\r
571         portDISABLE_INTERRUPTS();\r
572 \r
573         /* Now interrupts are disabled uxCriticalNesting can be accessed\r
574          directly.  Increment uxCriticalNesting to keep a count of how many times\r
575          portENTER_CRITICAL() has been called. */\r
576         uxCriticalNesting++;\r
577 }\r
578 /*-----------------------------------------------------------*/\r
579 \r
580 void vPortExitCritical( void )\r
581 {\r
582         if( uxCriticalNesting > portNO_CRITICAL_NESTING )\r
583         {\r
584                 uxCriticalNesting--;\r
585                 if( uxCriticalNesting == portNO_CRITICAL_NESTING )\r
586                 {\r
587                         /* Enable all interrupt/exception. */\r
588                         portENABLE_INTERRUPTS();\r
589                 }\r
590         }\r
591 }\r
592 /*-----------------------------------------------------------*/\r