]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTUS_APS3_GCC/Demo/main.c
Prepare for V7.2.0 release.
[freertos] / FreeRTOS / Demo / CORTUS_APS3_GCC / Demo / main.c
1 /*\r
2     FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd.\r
3         \r
4 \r
5     ***************************************************************************\r
6      *                                                                       *\r
7      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
8      *    Complete, revised, and edited pdf reference manuals are also       *\r
9      *    available.                                                         *\r
10      *                                                                       *\r
11      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
12      *    ensuring you get running as quickly as possible and with an        *\r
13      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
14      *    the FreeRTOS project to continue with its mission of providing     *\r
15      *    professional grade, cross platform, de facto standard solutions    *\r
16      *    for microcontrollers - completely free of charge!                  *\r
17      *                                                                       *\r
18      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
19      *                                                                       *\r
20      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
21      *                                                                       *\r
22     ***************************************************************************\r
23 \r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     >>>NOTE<<< The modification to the GPL is included to allow you to\r
31     distribute a combined work that includes FreeRTOS without being obliged to\r
32     provide the source code for proprietary components outside of the FreeRTOS\r
33     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
34     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
35     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public\r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43     \r
44     ***************************************************************************\r
45      *                                                                       *\r
46      *    Having a problem?  Start by reading the FAQ "My application does   *\r
47      *    not run, what could be wrong?                                      *\r
48      *                                                                       *\r
49      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
50      *                                                                       *\r
51     ***************************************************************************\r
52 \r
53     \r
54     http://www.FreeRTOS.org - Documentation, training, latest information, \r
55     license and contact details.\r
56     \r
57     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
58     including FreeRTOS+Trace - an indispensable productivity tool.\r
59 \r
60     Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
61     the code with commercial support, indemnification, and middleware, under \r
62     the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
63     provide a safety engineered and independently SIL3 certified version under \r
64     the SafeRTOS brand: http://www.SafeRTOS.com.\r
65 */\r
66 \r
67 /*\r
68  * Creates all the demo application tasks, then starts the scheduler.\r
69  *\r
70  * Main.c also creates a task called "Check".  This only executes every three\r
71  * seconds but has the highest priority so is guaranteed to get processor time.\r
72  * Its main function is to check that all the other tasks are still operational.\r
73  * Each task (other than the "flash" tasks) maintains a unique count that is\r
74  * incremented each time the task successfully completes its function.  Should\r
75  * any error occur within such a task the count is permanently halted.  The\r
76  * check task inspects the count of each task to ensure it has changed since\r
77  * the last time the check task executed.  If all the count variables have\r
78  * changed all the tasks are still executing error free, and the check task\r
79  * toggles the on board LED.  Should any task contain an error at any time\r
80  * the LED toggle rate will change from 3 seconds to 500ms.\r
81  *\r
82  * NOTE:  The demo application includes tasks that send and receive characters\r
83  * over the UART. The characters sent by one task are received by another -\r
84  * with an error condition being flagged should any characters be missed or\r
85  * received out of order. A loopback connector is required on the 9way D socket\r
86  * for this mechanism to operation (pins 2 and 3 the socket should be connected\r
87  * together - a paper clip is normally sufficient).\r
88  *\r
89  */\r
90 \r
91 /* Standard includes. */\r
92 #include <stdlib.h>\r
93 #include <string.h>\r
94 \r
95 /* Scheduler includes. */\r
96 #include "FreeRTOS.h"\r
97 #include "task.h"\r
98 \r
99 /* Demo application includes. */\r
100 #include "partest.h"\r
101 #include "flash.h"\r
102 #include "integer.h"\r
103 #include "PollQ.h"\r
104 #include "comtest2.h"\r
105 #include "semtest.h"\r
106 #include "flop.h"\r
107 #include "dynamic.h"\r
108 #include "BlockQ.h"\r
109 #include "serial.h"\r
110 #include "demoGpio.h"\r
111 #include "7seg.h"\r
112 #include "RegTest.h"\r
113 \r
114 /*-----------------------------------------------------------*/\r
115 \r
116 /* Constants for the ComTest tasks. */\r
117 #define mainCOM_TEST_BAUD_RATE  ( ( unsigned long ) 115200 )\r
118 #define mainCOM_TEST_LED                ( 5 )\r
119 \r
120 /* Priorities for the demo application tasks. */\r
121 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )\r
122 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
123 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
124 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
125 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
126 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
127 #define main7SEG_TASK_PRIORITY          ( tskIDLE_PRIORITY + 2 )\r
128 \r
129 /* The rate at which the on board LED will toggle when there is/is not an\r
130 error. */\r
131 #define mainNO_ERROR_FLASH_PERIOD       ( ( portTickType ) 3000 / portTICK_RATE_MS      )\r
132 #define mainERROR_FLASH_PERIOD          ( ( portTickType ) 500 / portTICK_RATE_MS  )\r
133 #define mainON_BOARD_LED_BIT            ( ( unsigned long ) 7 )\r
134 \r
135 /* The size of the memory blocks allocated by the vMemCheckTask() task. */\r
136 #define mainMEM_CHECK_SIZE_1            ( ( size_t ) 51 )\r
137 #define mainMEM_CHECK_SIZE_2            ( ( size_t ) 52 )\r
138 #define mainMEM_CHECK_SIZE_3            ( ( size_t ) 151 )\r
139 \r
140 /*-----------------------------------------------------------*/\r
141 \r
142 /*\r
143  * Checks that all the demo application tasks are still executing without error\r
144  * - as described at the top of the file.\r
145  */\r
146 static long prvCheckOtherTasksAreStillRunning( void );\r
147 \r
148 /*\r
149  * The task that executes at the highest priority and calls\r
150  * prvCheckOtherTasksAreStillRunning().  See the description at the top\r
151  * of the file.\r
152  */\r
153 static void vErrorChecks( void *pvParameters );\r
154 \r
155 /*\r
156  * Configure the processor for use with the Olimex demo board.  This includes\r
157  * setup for the I/O, system clock, and access timings.\r
158  */\r
159 static void prvSetupHardware( void );\r
160 \r
161 \r
162 /*-----------------------------------------------------------*/\r
163 \r
164 /*\r
165  * Starts all the other tasks, then starts the scheduler.\r
166  */\r
167 int main( void )\r
168 {\r
169         /* Setup the hardware for use with the Xilinx evaluation board. */\r
170         prvSetupHardware();\r
171 \r
172         /* Start the demo/test application tasks. */\r
173         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
174         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
175         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
176         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
177         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
178         vStartDynamicPriorityTasks();\r
179         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
180         vStart7SegTasks( main7SEG_TASK_PRIORITY );\r
181         vStartRegTestTasks();\r
182 \r
183         /* Start the check task - which is defined in this file. */\r
184         xTaskCreate( vErrorChecks, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
185 \r
186         /* Now all the tasks have been started - start the scheduler. */\r
187         vTaskStartScheduler();\r
188 \r
189         /* Should never reach here! */\r
190         for( ;; );\r
191 }\r
192 /*-----------------------------------------------------------*/\r
193 \r
194 static void vErrorChecks( void *pvParameters )\r
195 {\r
196 portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;\r
197 \r
198         /* Just to stop compiler warnings. */\r
199         ( void ) pvParameters;\r
200 \r
201         /* Cycle for ever, delaying then checking all the other tasks are still\r
202         operating without error.  If an error is detected then the delay period\r
203         is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so\r
204         the on board LED flash rate will increase. */\r
205 \r
206         for( ;; )\r
207         {\r
208                 /* Delay until it is time to execute again. */\r
209                 vTaskDelay( xDelayPeriod );\r
210 \r
211                 /* Check all the standard demo application tasks are executing without\r
212                 error.  */\r
213                 if( prvCheckOtherTasksAreStillRunning() != pdPASS )\r
214                 {\r
215                         /* An error has been detected in one of the tasks - flash faster. */\r
216                         xDelayPeriod = mainERROR_FLASH_PERIOD;\r
217                 }\r
218 \r
219                 /* The toggle rate of the LED depends on how long this task delays for.\r
220                 An error reduces the delay period and so increases the toggle rate. */\r
221                 vParTestToggleLED( mainON_BOARD_LED_BIT );\r
222         }\r
223 }\r
224 /*-----------------------------------------------------------*/\r
225 \r
226 static void prvSetupHardware( void )\r
227 {\r
228         /* Initialise LED outputs. */\r
229         vParTestInitialise();\r
230 }\r
231 /*-----------------------------------------------------------*/\r
232 \r
233 static long prvCheckOtherTasksAreStillRunning( void )\r
234 {\r
235 long lReturn = pdPASS;\r
236 \r
237         /* Check all the demo tasks (other than the flash tasks) to ensure\r
238         that they are all still running, and that none of them have detected\r
239         an error. */\r
240 \r
241         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
242         {\r
243                 lReturn = pdFAIL;\r
244         }\r
245 \r
246         if( xAreComTestTasksStillRunning() != pdTRUE )\r
247         {\r
248                 lReturn = pdFAIL;\r
249         }\r
250 \r
251         if( xArePollingQueuesStillRunning() != pdTRUE )\r
252         {\r
253                 lReturn = pdFAIL;\r
254         }\r
255 \r
256         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
257         {\r
258                 lReturn = pdFAIL;\r
259         }\r
260 \r
261         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
262         {\r
263                 lReturn = pdFAIL;\r
264         }\r
265 \r
266         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
267         {\r
268                 lReturn = pdFAIL;\r
269         }\r
270 \r
271         if( xAreRegTestTasksStillRunning() != pdTRUE )\r
272         {\r
273                 lReturn = pdFAIL;\r
274         }\r
275 \r
276         return lReturn;\r
277 }\r
278 /*-----------------------------------------------------------*/\r
279 \r
280 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )\r
281 {\r
282         /* This function will be called if a task overflows its stack.  Inspect\r
283         pxCurrentTCB to find the offending task if the overflow was sever enough\r
284         to corrupt the pcTaskName parameter. */\r
285         vParTestSetLED( 4, 1 );\r
286         for( ;; );\r
287 }\r
288 /*-----------------------------------------------------------*/\r
289 \r
290 void vApplicationMallocFailedHook( void )\r
291 {\r
292         /* This function will be called if a call to pvPortMalloc() fails to return\r
293         the requested memory.  pvPortMalloc() is called internally by the scheduler\r
294         whenever a task, queue or semaphore is created. */\r
295         vParTestSetLED( 4, 1 );\r
296         for( ;; );\r
297 }\r
298 /*-----------------------------------------------------------*/\r
299 \r
300 /* Provide an exit function to prevent a whole load of standard library functions\r
301 being brought into the build. */\r
302 void exit( int status )\r
303 {\r
304         for( ;; );\r
305 }\r
306 \r
307 \r