2 FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
32 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
33 distribute a combined work that includes FreeRTOS without being obliged to
\r
34 provide the source code for proprietary components outside of the FreeRTOS
\r
35 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
36 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
37 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
38 more details. You should have received a copy of the GNU General Public
\r
39 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
40 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
41 by writing to Richard Barry, contact details for whom are available on the
\r
46 ***************************************************************************
\r
48 * Having a problem? Start by reading the FAQ "My application does *
\r
49 * not run, what could be wrong?" *
\r
51 * http://www.FreeRTOS.org/FAQHelp.html *
\r
53 ***************************************************************************
\r
56 http://www.FreeRTOS.org - Documentation, training, latest versions, license
\r
57 and contact details.
\r
59 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
60 including FreeRTOS+Trace - an indispensable productivity tool.
\r
62 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
63 the code with commercial support, indemnification, and middleware, under
\r
64 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
65 provide a safety engineered and independently SIL3 certified version under
\r
66 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
70 * Creates all the demo application tasks, then starts the scheduler.
\r
72 * Main.c also creates a task called "Check". This only executes every three
\r
73 * seconds but has the highest priority so is guaranteed to get processor time.
\r
74 * Its main function is to check that all the other tasks are still operational.
\r
75 * Each task (other than the "flash" tasks) maintains a unique count that is
\r
76 * incremented each time the task successfully completes its function. Should
\r
77 * any error occur within such a task the count is permanently halted. The
\r
78 * check task inspects the count of each task to ensure it has changed since
\r
79 * the last time the check task executed. If all the count variables have
\r
80 * changed all the tasks are still executing error free, and the check task
\r
81 * toggles the on board LED. Should any task contain an error at any time
\r
82 * the LED toggle rate will change from 3 seconds to 500ms.
\r
84 * NOTE: The demo application includes tasks that send and receive characters
\r
85 * over the UART. The characters sent by one task are received by another -
\r
86 * with an error condition being flagged should any characters be missed or
\r
87 * received out of order. A loopback connector is required on the 9way D socket
\r
88 * for this mechanism to operation (pins 2 and 3 the socket should be connected
\r
89 * together - a paper clip is normally sufficient).
\r
93 /* Standard includes. */
\r
97 /* Scheduler includes. */
\r
98 #include "FreeRTOS.h"
\r
101 /* Demo application includes. */
\r
102 #include "partest.h"
\r
104 #include "integer.h"
\r
106 #include "comtest2.h"
\r
107 #include "semtest.h"
\r
109 #include "dynamic.h"
\r
110 #include "BlockQ.h"
\r
111 #include "serial.h"
\r
112 #include "demoGpio.h"
\r
114 #include "RegTest.h"
\r
116 /*-----------------------------------------------------------*/
\r
118 /* Constants for the ComTest tasks. */
\r
119 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 115200 )
\r
120 #define mainCOM_TEST_LED ( 5 )
\r
122 /* Priorities for the demo application tasks. */
\r
123 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
124 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
125 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
126 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
127 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
128 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
129 #define main7SEG_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
131 /* The rate at which the on board LED will toggle when there is/is not an
\r
133 #define mainNO_ERROR_FLASH_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
134 #define mainERROR_FLASH_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
135 #define mainON_BOARD_LED_BIT ( ( unsigned long ) 7 )
\r
137 /* The size of the memory blocks allocated by the vMemCheckTask() task. */
\r
138 #define mainMEM_CHECK_SIZE_1 ( ( size_t ) 51 )
\r
139 #define mainMEM_CHECK_SIZE_2 ( ( size_t ) 52 )
\r
140 #define mainMEM_CHECK_SIZE_3 ( ( size_t ) 151 )
\r
142 /*-----------------------------------------------------------*/
\r
145 * Checks that all the demo application tasks are still executing without error
\r
146 * - as described at the top of the file.
\r
148 static long prvCheckOtherTasksAreStillRunning( void );
\r
151 * The task that executes at the highest priority and calls
\r
152 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
155 static void vErrorChecks( void *pvParameters );
\r
158 * Configure the processor for use with the Olimex demo board. This includes
\r
159 * setup for the I/O, system clock, and access timings.
\r
161 static void prvSetupHardware( void );
\r
164 /*-----------------------------------------------------------*/
\r
167 * Starts all the other tasks, then starts the scheduler.
\r
171 /* Setup the hardware for use with the Xilinx evaluation board. */
\r
172 prvSetupHardware();
\r
174 /* Start the demo/test application tasks. */
\r
175 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
176 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
177 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
178 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
179 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
180 vStartDynamicPriorityTasks();
\r
181 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
182 vStart7SegTasks( main7SEG_TASK_PRIORITY );
\r
183 vStartRegTestTasks();
\r
185 /* Start the check task - which is defined in this file. */
\r
186 xTaskCreate( vErrorChecks, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
188 /* Now all the tasks have been started - start the scheduler. */
\r
189 vTaskStartScheduler();
\r
191 /* Should never reach here! */
\r
194 /*-----------------------------------------------------------*/
\r
196 static void vErrorChecks( void *pvParameters )
\r
198 portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
\r
200 /* Just to stop compiler warnings. */
\r
201 ( void ) pvParameters;
\r
203 /* Cycle for ever, delaying then checking all the other tasks are still
\r
204 operating without error. If an error is detected then the delay period
\r
205 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
\r
206 the on board LED flash rate will increase. */
\r
210 /* Delay until it is time to execute again. */
\r
211 vTaskDelay( xDelayPeriod );
\r
213 /* Check all the standard demo application tasks are executing without
\r
215 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
217 /* An error has been detected in one of the tasks - flash faster. */
\r
218 xDelayPeriod = mainERROR_FLASH_PERIOD;
\r
221 /* The toggle rate of the LED depends on how long this task delays for.
\r
222 An error reduces the delay period and so increases the toggle rate. */
\r
223 vParTestToggleLED( mainON_BOARD_LED_BIT );
\r
226 /*-----------------------------------------------------------*/
\r
228 static void prvSetupHardware( void )
\r
230 /* Initialise LED outputs. */
\r
231 vParTestInitialise();
\r
233 /*-----------------------------------------------------------*/
\r
235 static long prvCheckOtherTasksAreStillRunning( void )
\r
237 long lReturn = pdPASS;
\r
239 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
240 that they are all still running, and that none of them have detected
\r
243 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
248 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
253 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
258 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
263 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
268 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
273 if( xAreRegTestTasksStillRunning() != pdTRUE )
\r
280 /*-----------------------------------------------------------*/
\r
282 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
\r
284 /* This function will be called if a task overflows its stack. Inspect
\r
285 pxCurrentTCB to find the offending task if the overflow was sever enough
\r
286 to corrupt the pcTaskName parameter. */
\r
287 vParTestSetLED( 4, 1 );
\r
290 /*-----------------------------------------------------------*/
\r
292 void vApplicationMallocFailedHook( void )
\r
294 /* This function will be called if a call to pvPortMalloc() fails to return
\r
295 the requested memory. pvPortMalloc() is called internally by the scheduler
\r
296 whenever a task, queue or semaphore is created. */
\r
297 vParTestSetLED( 4, 1 );
\r
300 /*-----------------------------------------------------------*/
\r
302 /* Provide an exit function to prevent a whole load of standard library functions
\r
303 being brought into the build. */
\r
304 void exit( int status )
\r