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