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 |
|
|
/*-----------------------------------------------------------
|
55 |
|
|
* Implementation of functions defined in portable.h for the SH2A port.
|
56 |
|
|
*----------------------------------------------------------*/
|
57 |
|
|
|
58 |
|
|
/* Scheduler includes. */
|
59 |
|
|
#include "FreeRTOS.h"
|
60 |
|
|
#include "task.h"
|
61 |
|
|
|
62 |
|
|
/* Library includes. */
|
63 |
|
|
#include "string.h"
|
64 |
|
|
|
65 |
|
|
/*-----------------------------------------------------------*/
|
66 |
|
|
|
67 |
|
|
/* The SR assigned to a newly created task. The only important thing in this
|
68 |
|
|
value is for all interrupts to be enabled. */
|
69 |
|
|
#define portINITIAL_SR ( 0UL )
|
70 |
|
|
|
71 |
|
|
/* Dimensions the array into which the floating point context is saved.
|
72 |
|
|
Allocate enough space for FPR0 to FPR15, FPUL and FPSCR, each of which is 4
|
73 |
|
|
bytes big. If this number is changed then the 72 in portasm.src also needs
|
74 |
|
|
changing. */
|
75 |
|
|
#define portFLOP_REGISTERS_TO_STORE ( 18 )
|
76 |
|
|
#define portFLOP_STORAGE_SIZE ( portFLOP_REGISTERS_TO_STORE * 4 )
|
77 |
|
|
|
78 |
|
|
/*-----------------------------------------------------------*/
|
79 |
|
|
|
80 |
|
|
/*
|
81 |
|
|
* The TRAPA handler used to force a context switch.
|
82 |
|
|
*/
|
83 |
|
|
void vPortYield( void );
|
84 |
|
|
|
85 |
|
|
/*
|
86 |
|
|
* Function to start the first task executing - defined in portasm.src.
|
87 |
|
|
*/
|
88 |
|
|
extern void vPortStartFirstTask( void );
|
89 |
|
|
|
90 |
|
|
/*
|
91 |
|
|
* Obtains the current GBR value - defined in portasm.src.
|
92 |
|
|
*/
|
93 |
|
|
extern unsigned long ulPortGetGBR( void );
|
94 |
|
|
|
95 |
|
|
/*-----------------------------------------------------------*/
|
96 |
|
|
|
97 |
|
|
/*
|
98 |
|
|
* See header file for description.
|
99 |
|
|
*/
|
100 |
|
|
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
|
101 |
|
|
{
|
102 |
|
|
/* Mark the end of the stack - used for debugging only and can be removed. */
|
103 |
|
|
*pxTopOfStack = 0x11111111UL;
|
104 |
|
|
pxTopOfStack--;
|
105 |
|
|
*pxTopOfStack = 0x22222222UL;
|
106 |
|
|
pxTopOfStack--;
|
107 |
|
|
*pxTopOfStack = 0x33333333UL;
|
108 |
|
|
pxTopOfStack--;
|
109 |
|
|
|
110 |
|
|
/* SR. */
|
111 |
|
|
*pxTopOfStack = portINITIAL_SR;
|
112 |
|
|
pxTopOfStack--;
|
113 |
|
|
|
114 |
|
|
/* PC. */
|
115 |
|
|
*pxTopOfStack = ( unsigned long ) pxCode;
|
116 |
|
|
pxTopOfStack--;
|
117 |
|
|
|
118 |
|
|
/* PR. */
|
119 |
|
|
*pxTopOfStack = 15;
|
120 |
|
|
pxTopOfStack--;
|
121 |
|
|
|
122 |
|
|
/* 14. */
|
123 |
|
|
*pxTopOfStack = 14;
|
124 |
|
|
pxTopOfStack--;
|
125 |
|
|
|
126 |
|
|
/* R13. */
|
127 |
|
|
*pxTopOfStack = 13;
|
128 |
|
|
pxTopOfStack--;
|
129 |
|
|
|
130 |
|
|
/* R12. */
|
131 |
|
|
*pxTopOfStack = 12;
|
132 |
|
|
pxTopOfStack--;
|
133 |
|
|
|
134 |
|
|
/* R11. */
|
135 |
|
|
*pxTopOfStack = 11;
|
136 |
|
|
pxTopOfStack--;
|
137 |
|
|
|
138 |
|
|
/* R10. */
|
139 |
|
|
*pxTopOfStack = 10;
|
140 |
|
|
pxTopOfStack--;
|
141 |
|
|
|
142 |
|
|
/* R9. */
|
143 |
|
|
*pxTopOfStack = 9;
|
144 |
|
|
pxTopOfStack--;
|
145 |
|
|
|
146 |
|
|
/* R8. */
|
147 |
|
|
*pxTopOfStack = 8;
|
148 |
|
|
pxTopOfStack--;
|
149 |
|
|
|
150 |
|
|
/* R7. */
|
151 |
|
|
*pxTopOfStack = 7;
|
152 |
|
|
pxTopOfStack--;
|
153 |
|
|
|
154 |
|
|
/* R6. */
|
155 |
|
|
*pxTopOfStack = 6;
|
156 |
|
|
pxTopOfStack--;
|
157 |
|
|
|
158 |
|
|
/* R5. */
|
159 |
|
|
*pxTopOfStack = 5;
|
160 |
|
|
pxTopOfStack--;
|
161 |
|
|
|
162 |
|
|
/* R4. */
|
163 |
|
|
*pxTopOfStack = ( unsigned long ) pvParameters;
|
164 |
|
|
pxTopOfStack--;
|
165 |
|
|
|
166 |
|
|
/* R3. */
|
167 |
|
|
*pxTopOfStack = 3;
|
168 |
|
|
pxTopOfStack--;
|
169 |
|
|
|
170 |
|
|
/* R2. */
|
171 |
|
|
*pxTopOfStack = 2;
|
172 |
|
|
pxTopOfStack--;
|
173 |
|
|
|
174 |
|
|
/* R1. */
|
175 |
|
|
*pxTopOfStack = 1;
|
176 |
|
|
pxTopOfStack--;
|
177 |
|
|
|
178 |
|
|
/* R0 */
|
179 |
|
|
*pxTopOfStack = 0;
|
180 |
|
|
pxTopOfStack--;
|
181 |
|
|
|
182 |
|
|
/* MACL. */
|
183 |
|
|
*pxTopOfStack = 16;
|
184 |
|
|
pxTopOfStack--;
|
185 |
|
|
|
186 |
|
|
/* MACH. */
|
187 |
|
|
*pxTopOfStack = 17;
|
188 |
|
|
pxTopOfStack--;
|
189 |
|
|
|
190 |
|
|
/* GBR. */
|
191 |
|
|
*pxTopOfStack = ulPortGetGBR();
|
192 |
|
|
|
193 |
|
|
/* GBR = global base register.
|
194 |
|
|
VBR = vector base register.
|
195 |
|
|
TBR = jump table base register.
|
196 |
|
|
R15 is the stack pointer. */
|
197 |
|
|
|
198 |
|
|
return pxTopOfStack;
|
199 |
|
|
}
|
200 |
|
|
/*-----------------------------------------------------------*/
|
201 |
|
|
|
202 |
|
|
portBASE_TYPE xPortStartScheduler( void )
|
203 |
|
|
{
|
204 |
|
|
extern void vApplicationSetupTimerInterrupt( void );
|
205 |
|
|
|
206 |
|
|
/* Call an application function to set up the timer that will generate the
|
207 |
|
|
tick interrupt. This way the application can decide which peripheral to
|
208 |
|
|
use. A demo application is provided to show a suitable example. */
|
209 |
|
|
vApplicationSetupTimerInterrupt();
|
210 |
|
|
|
211 |
|
|
/* Start the first task. This will only restore the standard registers and
|
212 |
|
|
not the flop registers. This does not really matter though because the only
|
213 |
|
|
flop register that is initialised to a particular value is fpscr, and it is
|
214 |
|
|
only initialised to the current value, which will still be the current value
|
215 |
|
|
when the first task starts executing. */
|
216 |
|
|
trapa( portSTART_SCHEDULER_TRAP_NO );
|
217 |
|
|
|
218 |
|
|
/* Should not get here. */
|
219 |
|
|
return pdFAIL;
|
220 |
|
|
}
|
221 |
|
|
/*-----------------------------------------------------------*/
|
222 |
|
|
|
223 |
|
|
void vPortEndScheduler( void )
|
224 |
|
|
{
|
225 |
|
|
/* Not implemented as there is nothing to return to. */
|
226 |
|
|
}
|
227 |
|
|
/*-----------------------------------------------------------*/
|
228 |
|
|
|
229 |
|
|
void vPortYield( void )
|
230 |
|
|
{
|
231 |
|
|
long lInterruptMask;
|
232 |
|
|
|
233 |
|
|
/* Ensure the yield trap runs at the same priority as the other interrupts
|
234 |
|
|
that can cause a context switch. */
|
235 |
|
|
lInterruptMask = get_imask();
|
236 |
|
|
|
237 |
|
|
/* taskYIELD() can only be called from a task, not an interrupt, so the
|
238 |
|
|
current interrupt mask can only be 0 or portKERNEL_INTERRUPT_PRIORITY and
|
239 |
|
|
the mask can be set without risk of accidentally lowering the mask value. */
|
240 |
|
|
set_imask( portKERNEL_INTERRUPT_PRIORITY );
|
241 |
|
|
|
242 |
|
|
trapa( portYIELD_TRAP_NO );
|
243 |
|
|
|
244 |
|
|
/* Restore the interrupt mask to whatever it was previously (when the
|
245 |
|
|
function was entered). */
|
246 |
|
|
set_imask( ( int ) lInterruptMask );
|
247 |
|
|
}
|
248 |
|
|
/*-----------------------------------------------------------*/
|
249 |
|
|
|
250 |
|
|
portBASE_TYPE xPortUsesFloatingPoint( xTaskHandle xTask )
|
251 |
|
|
{
|
252 |
|
|
unsigned long *pulFlopBuffer;
|
253 |
|
|
portBASE_TYPE xReturn;
|
254 |
|
|
extern void * volatile pxCurrentTCB;
|
255 |
|
|
|
256 |
|
|
/* This function tells the kernel that the task referenced by xTask is
|
257 |
|
|
going to use the floating point registers and therefore requires the
|
258 |
|
|
floating point registers saved as part of its context. */
|
259 |
|
|
|
260 |
|
|
/* Passing NULL as xTask is used to indicate that the calling task is the
|
261 |
|
|
subject task - so pxCurrentTCB is the task handle. */
|
262 |
|
|
if( xTask == NULL )
|
263 |
|
|
{
|
264 |
|
|
xTask = ( xTaskHandle ) pxCurrentTCB;
|
265 |
|
|
}
|
266 |
|
|
|
267 |
|
|
/* Allocate a buffer large enough to hold all the flop registers. */
|
268 |
|
|
pulFlopBuffer = ( unsigned long * ) pvPortMalloc( portFLOP_STORAGE_SIZE );
|
269 |
|
|
|
270 |
|
|
if( pulFlopBuffer != NULL )
|
271 |
|
|
{
|
272 |
|
|
/* Start with the registers in a benign state. */
|
273 |
|
|
memset( ( void * ) pulFlopBuffer, 0x00, portFLOP_STORAGE_SIZE );
|
274 |
|
|
|
275 |
|
|
/* The first thing to get saved in the buffer is the FPSCR value -
|
276 |
|
|
initialise this to the current FPSCR value. */
|
277 |
|
|
*pulFlopBuffer = get_fpscr();
|
278 |
|
|
|
279 |
|
|
/* Use the task tag to point to the flop buffer. Pass pointer to just
|
280 |
|
|
above the buffer because the flop save routine uses a pre-decrement. */
|
281 |
|
|
vTaskSetApplicationTaskTag( xTask, ( void * ) ( pulFlopBuffer + portFLOP_REGISTERS_TO_STORE ) );
|
282 |
|
|
xReturn = pdPASS;
|
283 |
|
|
}
|
284 |
|
|
else
|
285 |
|
|
{
|
286 |
|
|
xReturn = pdFAIL;
|
287 |
|
|
}
|
288 |
|
|
|
289 |
|
|
return xReturn;
|
290 |
|
|
}
|
291 |
|
|
/*-----------------------------------------------------------*/
|
292 |
|
|
|
293 |
|
|
|