1 |
577 |
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 |
|
|
* Creates all the demo application tasks, then starts the scheduler. The WEB
|
56 |
|
|
* documentation provides more details of the standard demo application tasks.
|
57 |
|
|
*
|
58 |
|
|
* A "Check" task is created in addition to the standard demo tasks. This
|
59 |
|
|
* only executes every three seconds but has a high priority to ensure it gets
|
60 |
|
|
* processor time. Its main function is to check that all the standard demo
|
61 |
|
|
* tasks are still operational. If everything is running as expected then the
|
62 |
|
|
* check task will toggle an LED every 3 seconds. An error being discovered in
|
63 |
|
|
* any task will cause the toggle rate to increase to 500ms.
|
64 |
|
|
*
|
65 |
|
|
*/
|
66 |
|
|
|
67 |
|
|
/* FreeRTOS includes. */
|
68 |
|
|
#include "FreeRTOS.h"
|
69 |
|
|
#include "task.h"
|
70 |
|
|
|
71 |
|
|
/* Standard demo includes. */
|
72 |
|
|
#include "BlockQ.h"
|
73 |
|
|
#include "blocktim.h"
|
74 |
|
|
#include "countsem.h"
|
75 |
|
|
#include "death.h"
|
76 |
|
|
#include "dynamic.h"
|
77 |
|
|
#include "GenQTest.h"
|
78 |
|
|
#include "integer.h"
|
79 |
|
|
#include "PollQ.h"
|
80 |
|
|
#include "QPeek.h"
|
81 |
|
|
#include "recmutex.h"
|
82 |
|
|
#include "semtest.h"
|
83 |
|
|
#include "ParTest.h"
|
84 |
|
|
#include "comtest2.h"
|
85 |
|
|
|
86 |
|
|
/* Standard includes. */
|
87 |
|
|
#include <stdio.h>
|
88 |
|
|
|
89 |
|
|
/* Atmel library includes. */
|
90 |
|
|
#include <pio/pio.h>
|
91 |
|
|
|
92 |
|
|
/* Priorities for the demo application tasks. */
|
93 |
|
|
#define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
94 |
|
|
#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 0 )
|
95 |
|
|
#define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
|
96 |
|
|
#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 0 )
|
97 |
|
|
#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
98 |
|
|
#define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
|
99 |
|
|
#define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
|
100 |
|
|
|
101 |
|
|
/* The period of the check task both in and out of the presense of an error. */
|
102 |
|
|
#define mainNO_ERROR_PERIOD ( 5000 / portTICK_RATE_MS )
|
103 |
|
|
#define mainERROR_PERIOD ( 500 / portTICK_RATE_MS );
|
104 |
|
|
|
105 |
|
|
/* Constants used by the ComTest task. */
|
106 |
|
|
#define mainCOM_TEST_BAUD_RATE ( 38400 )
|
107 |
|
|
#define mainCOM_TEST_LED ( LED_DS1 )
|
108 |
|
|
|
109 |
|
|
/*-----------------------------------------------------------*/
|
110 |
|
|
|
111 |
|
|
/* Simple hardware setup required by the demo. */
|
112 |
|
|
static void prvSetupHardware( void );
|
113 |
|
|
|
114 |
|
|
/* The check task as described at the top of this file. */
|
115 |
|
|
static void prvCheckTask( void *pvParameters );
|
116 |
|
|
|
117 |
|
|
/*-----------------------------------------------------------*/
|
118 |
|
|
int main()
|
119 |
|
|
{
|
120 |
|
|
/* Perform any hardware setup necessary to run the demo. */
|
121 |
|
|
prvSetupHardware();
|
122 |
|
|
|
123 |
|
|
/* First create the 'standard demo' tasks. These exist just to to
|
124 |
|
|
demonstrate API functions being used and test the kernel port. More
|
125 |
|
|
information is provided on the FreeRTOS.org WEB site. */
|
126 |
|
|
vStartIntegerMathTasks( tskIDLE_PRIORITY );
|
127 |
|
|
vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
|
128 |
|
|
vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
|
129 |
|
|
vStartDynamicPriorityTasks();
|
130 |
|
|
vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
|
131 |
|
|
vCreateBlockTimeTasks();
|
132 |
|
|
vStartCountingSemaphoreTasks();
|
133 |
|
|
vStartGenericQueueTasks( tskIDLE_PRIORITY );
|
134 |
|
|
vStartQueuePeekTasks();
|
135 |
|
|
vStartRecursiveMutexTasks();
|
136 |
|
|
vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
|
137 |
|
|
|
138 |
|
|
/* Create the check task - this is the task that checks all the other tasks
|
139 |
|
|
are executing as expected and without reporting any errors. */
|
140 |
|
|
xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );
|
141 |
|
|
|
142 |
|
|
/* The death demo tasks must be started last as the sanity checks performed
|
143 |
|
|
require knowledge of the number of other tasks in the system. */
|
144 |
|
|
vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
|
145 |
|
|
|
146 |
|
|
/* Start the scheduler. From this point on the execution will be under
|
147 |
|
|
the control of the kernel. */
|
148 |
|
|
vTaskStartScheduler();
|
149 |
|
|
|
150 |
|
|
/* Will only get here if there was insufficient heap availale for the
|
151 |
|
|
idle task to be created. */
|
152 |
|
|
for( ;; );
|
153 |
|
|
}
|
154 |
|
|
/*-----------------------------------------------------------*/
|
155 |
|
|
|
156 |
|
|
static void prvCheckTask( void * pvParameters )
|
157 |
|
|
{
|
158 |
|
|
portTickType xNextWakeTime, xPeriod = mainNO_ERROR_PERIOD;
|
159 |
|
|
static volatile unsigned long ulErrorCode = 0UL;
|
160 |
|
|
|
161 |
|
|
/* Just to remove the compiler warning. */
|
162 |
|
|
( void ) pvParameters;
|
163 |
|
|
|
164 |
|
|
/* Initialise xNextWakeTime prior to its first use. From this point on
|
165 |
|
|
the value of the variable is handled automatically by the kernel. */
|
166 |
|
|
xNextWakeTime = xTaskGetTickCount();
|
167 |
|
|
|
168 |
|
|
for( ;; )
|
169 |
|
|
{
|
170 |
|
|
/* Delay until it is time for this task to execute again. */
|
171 |
|
|
vTaskDelayUntil( &xNextWakeTime, xPeriod );
|
172 |
|
|
|
173 |
|
|
/* Check all the other tasks in the system - latch any reported errors
|
174 |
|
|
into the ulErrorCode variable. */
|
175 |
|
|
if( xAreBlockingQueuesStillRunning() != pdTRUE )
|
176 |
|
|
{
|
177 |
|
|
ulErrorCode |= 0x01UL;
|
178 |
|
|
}
|
179 |
|
|
|
180 |
|
|
if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
|
181 |
|
|
{
|
182 |
|
|
ulErrorCode |= 0x02UL;
|
183 |
|
|
}
|
184 |
|
|
|
185 |
|
|
if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
|
186 |
|
|
{
|
187 |
|
|
ulErrorCode |= 0x04UL;
|
188 |
|
|
}
|
189 |
|
|
|
190 |
|
|
if( xIsCreateTaskStillRunning() != pdTRUE )
|
191 |
|
|
{
|
192 |
|
|
ulErrorCode |= 0x08UL;
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
|
196 |
|
|
{
|
197 |
|
|
ulErrorCode |= 0x10UL;
|
198 |
|
|
}
|
199 |
|
|
|
200 |
|
|
if( xAreGenericQueueTasksStillRunning() != pdTRUE )
|
201 |
|
|
{
|
202 |
|
|
ulErrorCode |= 0x20UL;
|
203 |
|
|
}
|
204 |
|
|
|
205 |
|
|
if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
|
206 |
|
|
{
|
207 |
|
|
ulErrorCode |= 0x40UL;
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
if( xArePollingQueuesStillRunning() != pdTRUE )
|
211 |
|
|
{
|
212 |
|
|
ulErrorCode |= 0x80UL;
|
213 |
|
|
}
|
214 |
|
|
|
215 |
|
|
if( xAreQueuePeekTasksStillRunning() != pdTRUE )
|
216 |
|
|
{
|
217 |
|
|
ulErrorCode |= 0x100UL;
|
218 |
|
|
}
|
219 |
|
|
|
220 |
|
|
if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
|
221 |
|
|
{
|
222 |
|
|
ulErrorCode |= 0x200UL;
|
223 |
|
|
}
|
224 |
|
|
|
225 |
|
|
if( xAreSemaphoreTasksStillRunning() != pdTRUE )
|
226 |
|
|
{
|
227 |
|
|
ulErrorCode |= 0x400UL;
|
228 |
|
|
}
|
229 |
|
|
|
230 |
|
|
if( xAreComTestTasksStillRunning() != pdTRUE )
|
231 |
|
|
{
|
232 |
|
|
ulErrorCode |= 0x800UL;
|
233 |
|
|
}
|
234 |
|
|
|
235 |
|
|
/* Reduce the block period and in so doing increase the frequency at
|
236 |
|
|
which this task executes if any errors have been latched. The increased
|
237 |
|
|
frequency causes the LED toggle rate to increase and so gives some
|
238 |
|
|
visual feedback that an error has occurred. */
|
239 |
|
|
if( ulErrorCode != 0x00 )
|
240 |
|
|
{
|
241 |
|
|
xPeriod = mainERROR_PERIOD;
|
242 |
|
|
}
|
243 |
|
|
|
244 |
|
|
/* Finally toggle the LED. */
|
245 |
|
|
vParTestToggleLED( LED_POWER );
|
246 |
|
|
}
|
247 |
|
|
}
|
248 |
|
|
/*-----------------------------------------------------------*/
|
249 |
|
|
|
250 |
|
|
static void prvSetupHardware( void )
|
251 |
|
|
{
|
252 |
|
|
const Pin xPins[] = { PIN_USART0_RXD, PIN_USART0_TXD };
|
253 |
|
|
|
254 |
|
|
/* Setup the LED outputs. */
|
255 |
|
|
vParTestInitialise();
|
256 |
|
|
|
257 |
|
|
/* Setup the pins for the UART. */
|
258 |
|
|
PIO_Configure( xPins, PIO_LISTSIZE( xPins ) );
|
259 |
|
|
}
|