]> git.sur5r.net Git - freertos/blob - Demo/ColdFire_MCF52221_CodeWarrior/sources/main.c
First working MCF52221 demo.
[freertos] / Demo / ColdFire_MCF52221_CodeWarrior / sources / main.c
1 /*\r
2         FreeRTOS.org V5.0.4 - Copyright (C) 2003-2008 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org is free software; you can redistribute it and/or modify\r
7         it under the terms of the GNU General Public License as published by\r
8         the Free Software Foundation; either version 2 of the License, or\r
9         (at your option) any later version.\r
10 \r
11         FreeRTOS.org is distributed in the hope that it will be useful,\r
12         but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14         GNU General Public License for more details.\r
15 \r
16         You should have received a copy of the GNU General Public License\r
17         along with FreeRTOS.org; if not, write to the Free Software\r
18         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19 \r
20         A special exception to the GPL can be applied should you wish to distribute\r
21         a combined work that includes FreeRTOS.org, without being obliged to provide\r
22         the source code for any proprietary components.  See the licensing section\r
23         of http://www.FreeRTOS.org for full details of how and when the exception\r
24         can be applied.\r
25 \r
26     ***************************************************************************\r
27     ***************************************************************************\r
28     *                                                                         *\r
29     * SAVE TIME AND MONEY!  We can port FreeRTOS.org to your own hardware,    *\r
30     * and even write all or part of your application on your behalf.          *\r
31     * See http://www.OpenRTOS.com for details of the services we provide to   *\r
32     * expedite your project.                                                  *\r
33     *                                                                         *\r
34     ***************************************************************************\r
35     ***************************************************************************\r
36 \r
37         Please ensure to read the configuration and relevant port sections of the\r
38         online documentation.\r
39 \r
40         http://www.FreeRTOS.org - Documentation, latest information, license and\r
41         contact details.\r
42 \r
43         http://www.SafeRTOS.com - A version that is certified for use in safety\r
44         critical systems.\r
45 \r
46         http://www.OpenRTOS.com - Commercial support, development, porting,\r
47         licensing and training services.\r
48 */\r
49 \r
50 \r
51 /*\r
52  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
53  * documentation provides more details of the standard demo application tasks.\r
54  * In addition to the standard demo tasks, the following tasks and tests are\r
55  * defined and/or created within this file:\r
56  *\r
57  * "Check" task -  This only executes every five seconds but has a high priority\r
58  * to ensure it gets processor time.  Its main function is to check that all the\r
59  * standard demo tasks are still operational.  While no errors have been\r
60  * discovered the check task will toggle an LED every 5 seconds - the toggle\r
61  * rate increasing to 500ms being a visual indication that at least one task has\r
62  * reported unexpected behaviour.\r
63  *\r
64  * "Reg test" tasks - These fill the registers with known values, then check\r
65  * that each register still contains its expected value.  Each task uses\r
66  * different values.  The tasks run with very low priority so get preempted very\r
67  * frequently.  A register containing an unexpected value is indicative of an\r
68  * error in the context switching mechanism.\r
69  *\r
70  */\r
71 \r
72 /* Standard includes. */\r
73 #include <stdio.h>\r
74 \r
75 /* Scheduler includes. */\r
76 #include "FreeRTOS.h"\r
77 #include "task.h"\r
78 #include "queue.h"\r
79 #include "semphr.h"\r
80 \r
81 /* Demo app includes. */\r
82 #include "BlockQ.h"\r
83 #include "death.h"\r
84 #include "crflash.h"\r
85 #include "partest.h"\r
86 #include "semtest.h"\r
87 #include "PollQ.h"\r
88 #include "GenQTest.h"\r
89 #include "QPeek.h"\r
90 #include "recmutex.h"\r
91 \r
92 /*-----------------------------------------------------------*/\r
93 \r
94 /* The time between cycles of the 'check' functionality - as described at the\r
95 top of this file. */\r
96 #define mainNO_ERROR_PERIOD                                     ( ( portTickType ) 5000 / portTICK_RATE_MS )\r
97 \r
98 /* The rate at which the LED controlled by the 'check' task will flash should an\r
99 error have been detected. */\r
100 #define mainERROR_PERIOD                                        ( ( portTickType ) 500 / portTICK_RATE_MS )\r
101 \r
102 /* The LED controlled by the 'check' task. */\r
103 #define mainCHECK_LED                                           ( 3 )\r
104 \r
105 /* ComTest constants - there is no free LED for the comtest tasks. */\r
106 #define mainCOM_TEST_BAUD_RATE                          ( ( unsigned portLONG ) 19200 )\r
107 #define mainCOM_TEST_LED                                        ( 5 )\r
108 \r
109 /* Task priorities. */\r
110 #define mainCOM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 2 )\r
111 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )\r
112 #define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )\r
113 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )\r
114 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )\r
115 #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
116 #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )\r
117 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )\r
118 #define mainWEB_TASK_PRIORITY                   ( tskIDLE_PRIORITY + 2 )\r
119 \r
120 /* Co-routines are used to flash the LEDs. */\r
121 #define mainNUM_FLASH_CO_ROUTINES                       ( 3 )\r
122 \r
123 /*\r
124  * Configure the hardware for the demo.\r
125  */\r
126 static void prvSetupHardware( void );\r
127 \r
128 /*\r
129  * Implements the 'check' task functionality as described at the top of this\r
130  * file.\r
131  */\r
132 static void prvCheckTask( void *pvParameters );\r
133 \r
134 /*-----------------------------------------------------------*/\r
135 \r
136 /* Counters used to detect errors within the reg test tasks. */\r
137 static volatile unsigned portLONG ulRegTest1Counter = 0x11111111, ulRegTest2Counter = 0x22222222;\r
138 \r
139 /*-----------------------------------------------------------*/\r
140 \r
141 int main( void )\r
142 {\r
143         /* Setup the hardware ready for this demo. */\r
144         prvSetupHardware();\r
145 \r
146         /* Start the standard demo tasks. */\r
147         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
148         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
149         vStartQueuePeekTasks();\r
150         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
151 \r
152         /* For demo purposes use some co-routines to flash the LEDs. */\r
153         vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );\r
154 \r
155         /* Create the check task. */\r
156         xTaskCreate( prvCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
157 \r
158         /* Start the scheduler. */\r
159         vTaskStartScheduler();\r
160 \r
161     /* Will only get here if there was insufficient memory to create the idle\r
162     task. */\r
163         for( ;; )\r
164         {\r
165         }\r
166 }\r
167 /*-----------------------------------------------------------*/\r
168 \r
169 static void prvCheckTask( void *pvParameters )\r
170 {\r
171 unsigned ulTicksToWait = mainNO_ERROR_PERIOD, ulError = 0, ulLastRegTest1Count = 0, ulLastRegTest2Count = 0;\r
172 portTickType xLastExecutionTime;\r
173 \r
174         ( void ) pvParameters;\r
175 \r
176         /* Initialise the variable used to control our iteration rate prior to\r
177         its first use. */\r
178         xLastExecutionTime = xTaskGetTickCount();\r
179 \r
180         for( ;; )\r
181         {\r
182                 /* Wait until it is time to run the tests again. */\r
183                 vTaskDelayUntil( &xLastExecutionTime, ulTicksToWait );\r
184 \r
185                 /* Has an error been found in any task? */\r
186                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
187                 {\r
188                         ulError |= 0x01UL;\r
189                 }\r
190 \r
191                 if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
192                 {\r
193                         ulError |= 0x02UL;\r
194                 }\r
195 \r
196                 if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
197                 {\r
198                         ulError |= 0x04UL;\r
199                 }\r
200 \r
201                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
202             {\r
203                 ulError |= 0x20UL;\r
204             }\r
205 \r
206                 /* If an error has been found then increase our cycle rate, and in so\r
207                 doing increase the rate at which the check task LED toggles. */\r
208                 if( ulError != 0 )\r
209                 {\r
210                 ulTicksToWait = mainERROR_PERIOD;\r
211                 }\r
212 \r
213                 /* Toggle the LED each itteration. */\r
214                 vParTestToggleLED( mainCHECK_LED );\r
215         }\r
216 }\r
217 /*-----------------------------------------------------------*/\r
218 \r
219 void prvSetupHardware( void )\r
220 {\r
221         portDISABLE_INTERRUPTS();\r
222 \r
223         /* Setup the port used to toggle LEDs. */\r
224         vParTestInitialise();\r
225 }\r
226 /*-----------------------------------------------------------*/\r
227 \r
228 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )\r
229 {\r
230         /* This will get called if a stack overflow is detected during the context\r
231         switch.  Set configCHECK_FOR_STACK_OVERFLOWS to 2 to also check for stack\r
232         problems within nested interrupts, but only do this for debug purposes as\r
233         it will increase the context switch time. */\r
234 \r
235         ( void ) pxTask;\r
236         ( void ) pcTaskName;\r
237 \r
238         for( ;; )\r
239         {\r
240         }\r
241 }\r
242 /*-----------------------------------------------------------*/\r
243 \r
244 void vApplicationIdleHook( void );\r
245 void vApplicationIdleHook( void )\r
246 {\r
247         /* The co-routines run in the idle task. */\r
248         vCoRoutineSchedule();\r
249 }\r
250 /*-----------------------------------------------------------*/\r
251 \r
252 void exit( int n )\r
253 {\r
254         /* To keep the linker happy only as the libraries have been removed from\r
255         the build. */\r
256         ( void ) n;\r
257         for( ;; ) {}\r
258 }\r
259 \r