]> git.sur5r.net Git - freertos/blob - Demo/ColdFire_MCF5282_Eclipse/RTOSDemo/main.c
Tidy up.
[freertos] / Demo / ColdFire_MCF5282_Eclipse / RTOSDemo / main.c
1 /*\r
2         FreeRTOS.org V5.0.3 - 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 then being a visual indication that at least one\r
62  * task has reported unexpected behaviour.\r
63  *\r
64  */\r
65 \r
66 /* Standard includes. */\r
67 #include <stdio.h>\r
68 \r
69 /* Scheduler includes. */\r
70 #include "FreeRTOS.h"\r
71 #include "task.h"\r
72 #include "queue.h"\r
73 #include "semphr.h"\r
74 \r
75 /* Demo app includes. */\r
76 #include "BlockQ.h"\r
77 #include "death.h"\r
78 #include "integer.h"\r
79 #include "flash.h"\r
80 #include "partest.h"\r
81 #include "semtest.h"\r
82 #include "PollQ.h"\r
83 #include "GenQTest.h"\r
84 #include "QPeek.h"\r
85 #include "recmutex.h"\r
86 #include "IntQueue.h"\r
87 #include "comtest2.h"\r
88 \r
89 /*-----------------------------------------------------------*/\r
90 \r
91 /* The time between cycles of the 'check' functionality (defined within the\r
92 tick hook. */\r
93 #define mainNO_ERROR_PERIOD                                     ( ( portTickType ) 5000 / portTICK_RATE_MS )\r
94 \r
95 /* The rate at which the LED controlled by the 'check' task will flash when an\r
96 error has been detected. */\r
97 #define mainERROR_PERIOD                                        ( 500 )\r
98 \r
99 /* The LED controlled by the 'check' task. */\r
100 #define mainCHECK_LED                                           ( 3 )\r
101 \r
102 /* Contest constants - there is no free LED for the comtest. */\r
103 #define mainCOM_TEST_BAUD_RATE                          ( ( unsigned portLONG ) 19200 )\r
104 #define mainCOM_TEST_LED                                        ( 5 )\r
105 \r
106 /* Task priorities. */\r
107 #define mainCOM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 2 )\r
108 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )\r
109 #define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )\r
110 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )\r
111 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )\r
112 #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )\r
113 #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )\r
114 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )\r
115 \r
116 /*\r
117  * Configure the hardware for the demo.\r
118  */\r
119 static void prvSetupHardware( void );\r
120 \r
121 /*\r
122  * Implements the 'check' task functionality as described at the top of this\r
123  * file.\r
124  */\r
125 static void prvCheckTask( void *pvParameters );\r
126 static void vRegTest1Task( void *pvParameters );\r
127 static void vRegTest2Task( void *pvParameters );\r
128 \r
129 /*-----------------------------------------------------------*/\r
130 static volatile unsigned portLONG ulRegTest1Counter = 0, ulRegTest2Counter = 0;\r
131 \r
132 int main( void )\r
133 {\r
134         prvSetupHardware();\r
135 \r
136         /* Start the standard demo tasks. */\r
137         vStartLEDFlashTasks( tskIDLE_PRIORITY );\r
138         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
139         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
140         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
141         vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
142         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
143         vStartQueuePeekTasks();\r
144         vStartRecursiveMutexTasks();\r
145         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
146         vStartInterruptQueueTasks();\r
147 \r
148         xTaskCreate( vRegTest1Task, ( signed portCHAR * ) "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
149         xTaskCreate( vRegTest2Task, ( signed portCHAR * ) "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
150 \r
151         /* Create the check task. */\r
152         xTaskCreate( prvCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
153 \r
154         /* The suicide tasks must be created last as they need to know how many\r
155         tasks were running prior to their creation in order to ascertain whether\r
156         or not the correct/expected number of tasks are running at any given time. */\r
157     vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
158 \r
159         /* Start the scheduler. */\r
160         vTaskStartScheduler();\r
161 \r
162     /* Will only get here if there was insufficient memory to create the idle\r
163     task. */\r
164         for( ;; );\r
165 }\r
166 /*-----------------------------------------------------------*/\r
167 \r
168 static void prvCheckTask( void *pvParameters )\r
169 {\r
170 unsigned ulTicksToWait = mainNO_ERROR_PERIOD, ulError = 0, ulLastRegTest1Count = 0, ulLastRegTest2Count = 0;\r
171 portTickType xLastExecutionTime;\r
172 \r
173         ( void ) pvParameters;\r
174 \r
175         /* Initialise the variable used to control our iteration rate prior to\r
176         its first use. */\r
177         xLastExecutionTime = xTaskGetTickCount();\r
178 \r
179         for( ;; )\r
180         {\r
181                 /* Wait until it is time to run the tests again. */\r
182                 vTaskDelayUntil( &xLastExecutionTime, ulTicksToWait );\r
183 \r
184                 /* Has an error been found in any task? */\r
185                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
186                 {\r
187                         ulError |= 0x01UL;\r
188                 }\r
189 \r
190                 if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
191                 {\r
192                         ulError |= 0x02UL;\r
193                 }\r
194 \r
195                 if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
196                 {\r
197                         ulError |= 0x04UL;\r
198                 }\r
199 \r
200                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
201             {\r
202                 ulError |= 0x20UL;\r
203             }\r
204 \r
205                 if( xArePollingQueuesStillRunning() != pdTRUE )\r
206             {\r
207                 ulError |= 0x40UL;\r
208             }\r
209 \r
210                 if( xIsCreateTaskStillRunning() != pdTRUE )\r
211             {\r
212                 ulError |= 0x80UL;\r
213             }\r
214 \r
215                 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
216             {\r
217                 ulError |= 0x100UL;\r
218             }\r
219 \r
220                 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
221             {\r
222                 ulError |= 0x200UL;\r
223             }\r
224 \r
225                 if( xAreComTestTasksStillRunning() != pdTRUE )\r
226                 {\r
227                 ulError |= 0x400UL;\r
228                 }\r
229 \r
230                 if( xAreIntQueueTasksStillRunning() != pdTRUE )\r
231             {\r
232                 ulError |= 0x800UL;\r
233             }\r
234 \r
235                 if( ulLastRegTest1Count == ulRegTest1Counter )\r
236                 {\r
237                         ulError |= 0x1000UL;\r
238                 }\r
239 \r
240                 if( ulLastRegTest2Count == ulRegTest2Counter )\r
241                 {\r
242                         ulError |= 0x1000UL;\r
243                 }\r
244 \r
245                 ulLastRegTest1Count = ulRegTest1Counter;\r
246                 ulLastRegTest2Count = ulRegTest2Counter;\r
247 \r
248                 if( ulError != 0 )\r
249                 {\r
250                 ulTicksToWait = mainERROR_PERIOD;\r
251                 }\r
252 \r
253                 vParTestToggleLED( mainCHECK_LED );\r
254         }\r
255 }\r
256 /*-----------------------------------------------------------*/\r
257 \r
258 void prvSetupHardware( void )\r
259 {\r
260 extern void mcf5xxx_wr_cacr( unsigned portLONG );\r
261 \r
262         /* Enable the cache. */\r
263         mcf5xxx_wr_cacr( MCF5XXX_CACR_CENB | MCF5XXX_CACR_CINV | MCF5XXX_CACR_DISD | MCF5XXX_CACR_CEIB | MCF5XXX_CACR_CLNF_00 );\r
264 \r
265         /* Multiply 8Mhz reference crystal by 8 to achieve system clock of 64Mhz. */\r
266         MCF_CLOCK_SYNCR = MCF_CLOCK_SYNCR_MFD( 2 );\r
267 \r
268         /* Wait for PLL to lock. */\r
269         while( !( MCF_CLOCK_SYNSR & MCF_CLOCK_SYNSR_LOCK ) )\r
270         {\r
271                 __asm__ volatile ( "NOP" );\r
272         }\r
273 \r
274         vParTestInitialise();\r
275 }\r
276 /*-----------------------------------------------------------*/\r
277 \r
278 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )\r
279 {\r
280         ( void ) pxTask;\r
281         ( void ) pcTaskName;\r
282 \r
283         for( ;; );\r
284 }\r
285 /*-----------------------------------------------------------*/\r
286 \r
287 static void vRegTest1Task( void *pvParameters )\r
288 {\r
289         ( void ) pvParameters;\r
290 \r
291         asm volatile    (       "reg_test_1_start:                                              \n\t"\r
292                                                 "       moveq           #1, %d0                                 \n\t"\r
293                                                 "       moveq           #2, %d1                                 \n\t"\r
294                                                 "       moveq           #3, %d2                                 \n\t"\r
295                                                 "       moveq           #4, %d3                                 \n\t"\r
296                                                 "       moveq           #5, %d4                                 \n\t"\r
297                                                 "       moveq           #6, %d5                                 \n\t"\r
298                                                 "       moveq           #7, %d6                                 \n\t"\r
299                                                 "       moveq           #8, %d7                                 \n\t"\r
300                                                 "       move            #9, %a0                                 \n\t"\r
301                                                 "       move            #10, %a1                                        \n\t"\r
302                                                 "       move            #11, %a2                                \n\t"\r
303                                                 "       move            #12, %a3                                \n\t"\r
304                                                 "       move            #13, %a4                                \n\t"\r
305                                                 "       move            #14, %a5                                \n\t"\r
306                                                 "       move            #15, %a6                                \n\t"\r
307                                                 "                                                                               \n\t"\r
308                                                 "       cmpi.l          #1, %d0                                 \n\t"\r
309                                                 "       bne                     reg_test_1_error                \n\t"\r
310                                                 "       cmpi.l          #2, %d1                                 \n\t"\r
311                                                 "       bne                     reg_test_1_error                \n\t"\r
312                                                 "       cmpi.l          #3, %d2                                 \n\t"\r
313                                                 "       bne                     reg_test_1_error                \n\t"\r
314                                                 "       cmpi.l          #4, %d3                                 \n\t"\r
315                                                 "       bne                     reg_test_1_error                \n\t"\r
316                                                 "       cmpi.l          #5, %d4                                 \n\t"\r
317                                                 "       bne                     reg_test_1_error                \n\t"\r
318                                                 "       cmpi.l          #6, %d5                                 \n\t"\r
319                                                 "       bne                     reg_test_1_error                \n\t"\r
320                                                 "       cmpi.l          #7, %d6                                 \n\t"\r
321                                                 "       bne                     reg_test_1_error                \n\t"\r
322                                                 "       cmpi.l          #8, %d7                                 \n\t"\r
323                                                 "       bne                     reg_test_1_error                \n\t"\r
324                                                 "       move            %a0, %d0                                \n\t"\r
325                                                 "       cmpi.l          #9, %d0                                 \n\t"\r
326                                                 "       bne                     reg_test_1_error                \n\t"\r
327                                                 "       move            %a1, %d0                                \n\t"\r
328                                                 "       cmpi.l          #10, %d0                                        \n\t"\r
329                                                 "       bne                     reg_test_1_error                \n\t"\r
330                                                 "       move            %a2, %d0                                \n\t"\r
331                                                 "       cmpi.l          #11, %d0                                        \n\t"\r
332                                                 "       bne                     reg_test_1_error                \n\t"\r
333                                                 "       move            %a3, %d0                                \n\t"\r
334                                                 "       cmpi.l          #12, %d0                                        \n\t"\r
335                                                 "       bne                     reg_test_1_error                \n\t"\r
336                                                 "       move            %a4, %d0                                \n\t"\r
337                                                 "       cmpi.l          #13, %d0                                        \n\t"\r
338                                                 "       bne                     reg_test_1_error                \n\t"\r
339                                                 "       move            %a5, %d0                                \n\t"\r
340                                                 "       cmpi.l          #14, %d0                                        \n\t"\r
341                                                 "       bne                     reg_test_1_error                \n\t"\r
342                                                 "       move            %a6, %d0                                \n\t"\r
343                                                 "       cmpi.l          #15, %d0                                        \n\t"\r
344                                                 "       bne                     reg_test_1_error                \n\t"\r
345                                                 "       movel           ulRegTest1Counter, %d0  \n\t"\r
346                                                 "       addql           #1, %d0                                 \n\t"\r
347                                                 "       movel           %d0, ulRegTest1Counter  \n\t"\r
348                                                 "       bra                     reg_test_1_start                \n\t"\r
349                                                 "reg_test_1_error:                                              \n\t"\r
350                                                 "       bra                     reg_test_1_error                \n\t"\r
351                                         );\r
352 }\r
353 /*-----------------------------------------------------------*/\r
354 \r
355 static void vRegTest2Task( void *pvParameters )\r
356 {\r
357         ( void ) pvParameters;\r
358 \r
359         asm volatile    (       "reg_test_2_start:                                              \n\t"\r
360                                                 "       moveq           #10, %d0                                        \n\t"\r
361                                                 "       moveq           #20, %d1                                        \n\t"\r
362                                                 "       moveq           #30, %d2                                        \n\t"\r
363                                                 "       moveq           #40, %d3                                        \n\t"\r
364                                                 "       moveq           #50, %d4                                        \n\t"\r
365                                                 "       moveq           #60, %d5                                        \n\t"\r
366                                                 "       moveq           #70, %d6                                        \n\t"\r
367                                                 "       moveq           #80, %d7                                        \n\t"\r
368                                                 "       move            #90, %a0                                        \n\t"\r
369                                                 "       move            #100, %a1                                       \n\t"\r
370                                                 "       move            #110, %a2                               \n\t"\r
371                                                 "       move            #120, %a3                               \n\t"\r
372                                                 "       move            #130, %a4                               \n\t"\r
373                                                 "       move            #140, %a5                               \n\t"\r
374                                                 "       move            #150, %a6                               \n\t"\r
375                                                 "                                                                               \n\t"\r
376                                                 "       cmpi.l          #10, %d0                                        \n\t"\r
377                                                 "       bne                     reg_test_2_error                \n\t"\r
378                                                 "       cmpi.l          #20, %d1                                        \n\t"\r
379                                                 "       bne                     reg_test_2_error                \n\t"\r
380                                                 "       cmpi.l          #30, %d2                                        \n\t"\r
381                                                 "       bne                     reg_test_2_error                \n\t"\r
382                                                 "       cmpi.l          #40, %d3                                        \n\t"\r
383                                                 "       bne                     reg_test_2_error                \n\t"\r
384                                                 "       cmpi.l          #50, %d4                                        \n\t"\r
385                                                 "       bne                     reg_test_2_error                \n\t"\r
386                                                 "       cmpi.l          #60, %d5                                        \n\t"\r
387                                                 "       bne                     reg_test_2_error                \n\t"\r
388                                                 "       cmpi.l          #70, %d6                                        \n\t"\r
389                                                 "       bne                     reg_test_2_error                \n\t"\r
390                                                 "       cmpi.l          #80, %d7                                        \n\t"\r
391                                                 "       bne                     reg_test_2_error                \n\t"\r
392                                                 "       move            %a0, %d0                                \n\t"\r
393                                                 "       cmpi.l          #90, %d0                                        \n\t"\r
394                                                 "       bne                     reg_test_2_error                \n\t"\r
395                                                 "       move            %a1, %d0                                \n\t"\r
396                                                 "       cmpi.l          #100, %d0                                       \n\t"\r
397                                                 "       bne                     reg_test_2_error                \n\t"\r
398                                                 "       move            %a2, %d0                                \n\t"\r
399                                                 "       cmpi.l          #110, %d0                                       \n\t"\r
400                                                 "       bne                     reg_test_2_error                \n\t"\r
401                                                 "       move            %a3, %d0                                \n\t"\r
402                                                 "       cmpi.l          #120, %d0                                       \n\t"\r
403                                                 "       bne                     reg_test_2_error                \n\t"\r
404                                                 "       move            %a4, %d0                                \n\t"\r
405                                                 "       cmpi.l          #130, %d0                                       \n\t"\r
406                                                 "       bne                     reg_test_2_error                \n\t"\r
407                                                 "       move            %a5, %d0                                \n\t"\r
408                                                 "       cmpi.l          #140, %d0                                       \n\t"\r
409                                                 "       bne                     reg_test_2_error                \n\t"\r
410                                                 "       move            %a6, %d0                                \n\t"\r
411                                                 "       cmpi.l          #150, %d0                                       \n\t"\r
412                                                 "       bne                     reg_test_2_error                \n\t"\r
413                                                 "       movel           ulRegTest1Counter, %d0  \n\t"\r
414                                                 "       addql           #1, %d0                                 \n\t"\r
415                                                 "       movel           %d0, ulRegTest2Counter  \n\t"\r
416                                                 "       bra                     reg_test_2_start                \n\t"\r
417                                                 "reg_test_2_error:                                              \n\t"\r
418                                                 "       bra                     reg_test_2_error                \n\t"\r
419                                         );\r
420 }\r
421 /*-----------------------------------------------------------*/\r
422 \r