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 |
|
|
/* Standard includes. */
|
55 |
|
|
#include <stdlib.h>
|
56 |
|
|
|
57 |
|
|
/* Scheduler includes. */
|
58 |
|
|
#include "FreeRTOS.h"
|
59 |
|
|
#include "task.h"
|
60 |
|
|
|
61 |
|
|
/* Critical nesting should be initialised to a non zero value so interrupts don't
|
62 |
|
|
accidentally get enabled before the scheduler is started. */
|
63 |
|
|
#define portINITIAL_CRITICAL_NESTING (( portSTACK_TYPE ) 10)
|
64 |
|
|
|
65 |
|
|
/* The PSW value assigned to tasks when they start to run for the first time. */
|
66 |
|
|
#define portPSW (( portSTACK_TYPE ) 0x00000000)
|
67 |
|
|
|
68 |
|
|
/* We require the address of the pxCurrentTCB variable, but don't want to know
|
69 |
|
|
any details of its type. */
|
70 |
|
|
typedef void tskTCB;
|
71 |
|
|
extern volatile tskTCB * volatile pxCurrentTCB;
|
72 |
|
|
|
73 |
|
|
/* Keeps track of the nesting level of critical sections. */
|
74 |
|
|
volatile portSTACK_TYPE usCriticalNesting = portINITIAL_CRITICAL_NESTING;
|
75 |
|
|
/*-----------------------------------------------------------*/
|
76 |
|
|
|
77 |
|
|
/* Sets up the timer to generate the tick interrupt. */
|
78 |
|
|
static void prvSetupTimerInterrupt( void );
|
79 |
|
|
|
80 |
|
|
/*-----------------------------------------------------------*/
|
81 |
|
|
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
|
82 |
|
|
{
|
83 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) pxCode; /* Task function start address */
|
84 |
|
|
pxTopOfStack--;
|
85 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) pxCode; /* Task function start address */
|
86 |
|
|
pxTopOfStack--;
|
87 |
|
|
*pxTopOfStack = portPSW; /* Initial PSW value */
|
88 |
|
|
pxTopOfStack--;
|
89 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x20202020; /* Initial Value of R20 */
|
90 |
|
|
pxTopOfStack--;
|
91 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x21212121; /* Initial Value of R21 */
|
92 |
|
|
pxTopOfStack--;
|
93 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x22222222; /* Initial Value of R22 */
|
94 |
|
|
pxTopOfStack--;
|
95 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x23232323; /* Initial Value of R23 */
|
96 |
|
|
pxTopOfStack--;
|
97 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x24242424; /* Initial Value of R24 */
|
98 |
|
|
pxTopOfStack--;
|
99 |
|
|
#if (__DATA_MODEL__ == 0) || (__DATA_MODEL__ == 1)
|
100 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x25252525; /* Initial Value of R25 */
|
101 |
|
|
pxTopOfStack--;
|
102 |
|
|
#endif /* configDATA_MODE */
|
103 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x26262626; /* Initial Value of R26 */
|
104 |
|
|
pxTopOfStack--;
|
105 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x27272727; /* Initial Value of R27 */
|
106 |
|
|
pxTopOfStack--;
|
107 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x28282828; /* Initial Value of R28 */
|
108 |
|
|
pxTopOfStack--;
|
109 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x29292929; /* Initial Value of R29 */
|
110 |
|
|
pxTopOfStack--;
|
111 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x30303030; /* Initial Value of R30 */
|
112 |
|
|
pxTopOfStack--;
|
113 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x19191919; /* Initial Value of R19 */
|
114 |
|
|
pxTopOfStack--;
|
115 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x18181818; /* Initial Value of R18 */
|
116 |
|
|
pxTopOfStack--;
|
117 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x17171717; /* Initial Value of R17 */
|
118 |
|
|
pxTopOfStack--;
|
119 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x16161616; /* Initial Value of R16 */
|
120 |
|
|
pxTopOfStack--;
|
121 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x15151515; /* Initial Value of R15 */
|
122 |
|
|
pxTopOfStack--;
|
123 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x14141414; /* Initial Value of R14 */
|
124 |
|
|
pxTopOfStack--;
|
125 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x13131313; /* Initial Value of R13 */
|
126 |
|
|
pxTopOfStack--;
|
127 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x12121212; /* Initial Value of R12 */
|
128 |
|
|
pxTopOfStack--;
|
129 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x11111111; /* Initial Value of R11 */
|
130 |
|
|
pxTopOfStack--;
|
131 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x10101010; /* Initial Value of R10 */
|
132 |
|
|
pxTopOfStack--;
|
133 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x99999999; /* Initial Value of R09 */
|
134 |
|
|
pxTopOfStack--;
|
135 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x88888888; /* Initial Value of R08 */
|
136 |
|
|
pxTopOfStack--;
|
137 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x77777777; /* Initial Value of R07 */
|
138 |
|
|
pxTopOfStack--;
|
139 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x66666666; /* Initial Value of R06 */
|
140 |
|
|
pxTopOfStack--;
|
141 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x55555555; /* Initial Value of R05 */
|
142 |
|
|
pxTopOfStack--;
|
143 |
|
|
#if __DATA_MODEL__ == 0 || __DATA_MODEL__ == 1
|
144 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x44444444; /* Initial Value of R04 */
|
145 |
|
|
pxTopOfStack--;
|
146 |
|
|
#endif /* configDATA_MODE */
|
147 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x22222222; /* Initial Value of R02 */
|
148 |
|
|
pxTopOfStack--;
|
149 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) pvParameters; /* R1 is expected to hold the function parameter*/
|
150 |
|
|
pxTopOfStack--;
|
151 |
|
|
*pxTopOfStack = ( portSTACK_TYPE ) portNO_CRITICAL_SECTION_NESTING;
|
152 |
|
|
|
153 |
|
|
/*
|
154 |
|
|
* Return a pointer to the top of the stack we have generated so this can
|
155 |
|
|
* be stored in the task control block for the task.
|
156 |
|
|
*/
|
157 |
|
|
return pxTopOfStack;
|
158 |
|
|
}
|
159 |
|
|
/*-----------------------------------------------------------*/
|
160 |
|
|
|
161 |
|
|
portBASE_TYPE xPortStartScheduler( void )
|
162 |
|
|
{
|
163 |
|
|
/* Setup the hardware to generate the tick. Interrupts are disabled when
|
164 |
|
|
this function is called. */
|
165 |
|
|
prvSetupTimerInterrupt();
|
166 |
|
|
|
167 |
|
|
/* Restore the context of the first task that is going to run. */
|
168 |
|
|
vPortStart();
|
169 |
|
|
|
170 |
|
|
/* Should not get here as the tasks are now running! */
|
171 |
|
|
return pdTRUE;
|
172 |
|
|
}
|
173 |
|
|
/*-----------------------------------------------------------*/
|
174 |
|
|
|
175 |
|
|
void vPortEndScheduler( void )
|
176 |
|
|
{
|
177 |
|
|
/* It is unlikely that the V850ES/Fx3 port will get stopped. If required simply
|
178 |
|
|
disable the tick interrupt here. */
|
179 |
|
|
}
|
180 |
|
|
/*-----------------------------------------------------------*/
|
181 |
|
|
|
182 |
|
|
/*
|
183 |
|
|
* Hardware initialisation to generate the RTOS tick. This uses
|
184 |
|
|
*/
|
185 |
|
|
static void prvSetupTimerInterrupt( void )
|
186 |
|
|
{
|
187 |
|
|
TM0CE = 0; /* TMM0 operation disable */
|
188 |
|
|
TM0EQMK0 = 1; /* INTTM0EQ0 interrupt disable */
|
189 |
|
|
TM0EQIF0 = 0; /* clear INTTM0EQ0 interrupt flag */
|
190 |
|
|
|
191 |
|
|
#ifdef __IAR_V850ES_Fx3__
|
192 |
|
|
{
|
193 |
|
|
TM0CMP0 = (((configCPU_CLOCK_HZ / configTICK_RATE_HZ) / 2)-1); /* divided by 2 because peripherals only run at CPU_CLOCK/2 */
|
194 |
|
|
}
|
195 |
|
|
#else
|
196 |
|
|
{
|
197 |
|
|
TM0CMP0 = (configCPU_CLOCK_HZ / configTICK_RATE_HZ);
|
198 |
|
|
}
|
199 |
|
|
#endif
|
200 |
|
|
|
201 |
|
|
TM0EQIC0 &= 0xF8;
|
202 |
|
|
TM0CTL0 = 0x00;
|
203 |
|
|
TM0EQIF0 = 0; /* clear INTTM0EQ0 interrupt flag */
|
204 |
|
|
TM0EQMK0 = 0; /* INTTM0EQ0 interrupt enable */
|
205 |
|
|
TM0CE = 1; /* TMM0 operation enable */
|
206 |
|
|
}
|
207 |
|
|
/*-----------------------------------------------------------*/
|
208 |
|
|
|
209 |
|
|
|