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