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