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