]> git.sur5r.net Git - freertos/blob - Demo/ColdFire_MCF5282_Eclipse/RTOSDemo/main.c
Add serial test code (not yet complete).
[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 "blocktim.h"\r
80 #include "flash.h"\r
81 #include "partest.h"\r
82 #include "semtest.h"\r
83 #include "PollQ.h"\r
84 #include "GenQTest.h"\r
85 #include "QPeek.h"\r
86 #include "recmutex.h"\r
87 #include "IntQueue.h"\r
88 #include "comtest2.h"\r
89 \r
90 /*-----------------------------------------------------------*/\r
91 \r
92 /* The time between cycles of the 'check' functionality (defined within the\r
93 tick hook. */\r
94 #define mainNO_ERROR_PERIOD                                     ( ( portTickType ) 5000 / portTICK_RATE_MS )\r
95 \r
96 /* The rate at which the LED controlled by the 'check' task will flash when an\r
97 error has been detected. */\r
98 #define mainERROR_PERIOD                                        ( 500 )\r
99 \r
100 /* The LED controlled by the 'check' task. */\r
101 #define mainCHECK_LED                                           ( 3 )\r
102 \r
103 /* Contest constants - there is no free LED for the comtest. */\r
104 #define mainCOM_TEST_BAUD_RATE  ( ( unsigned portLONG ) 115200 )\r
105 #define mainCOM_TEST_LED                ( 5 )\r
106 \r
107 /* Task priorities. */\r
108 #define mainCOM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 2 )\r
109 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )\r
110 #define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )\r
111 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )\r
112 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )\r
113 #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )\r
114 #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )\r
115 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )\r
116 \r
117 /*\r
118  * Configure the hardware for the demo.\r
119  */\r
120 static void prvSetupHardware( void );\r
121 \r
122 /*\r
123  * Implements the 'check' task functionality as described at the top of this\r
124  * file.\r
125  */\r
126 static void prvCheckTask( void *pvParameters );\r
127 \r
128 \r
129 /*-----------------------------------------------------------*/\r
130 \r
131 int main( void )\r
132 {\r
133         prvSetupHardware();\r
134 \r
135         /* Start the standard demo tasks. */\r
136         vStartLEDFlashTasks( tskIDLE_PRIORITY );\r
137         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
138         vCreateBlockTimeTasks();\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 \r
147         /* Create the check task. */\r
148         xTaskCreate( prvCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
149 \r
150         /* The suicide tasks must be created last as they need to know how many\r
151         tasks were running prior to their creation in order to ascertain whether\r
152         or not the correct/expected number of tasks are running at any given time. */\r
153     vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
154 \r
155         /* Start the scheduler. */\r
156         vTaskStartScheduler();\r
157 \r
158     /* Will only get here if there was insufficient memory to create the idle\r
159     task. */\r
160         for( ;; );\r
161 }\r
162 /*-----------------------------------------------------------*/\r
163 \r
164 static void prvCheckTask( void *pvParameters )\r
165 {\r
166 unsigned ulTicksToWait = mainNO_ERROR_PERIOD, ulError = 0;\r
167 portTickType xLastExecutionTime;\r
168 \r
169         ( void ) pvParameters;\r
170 \r
171         /* Initialise the variable used to control our iteration rate prior to\r
172         its first use. */\r
173         xLastExecutionTime = xTaskGetTickCount();\r
174 \r
175         for( ;; )\r
176         {\r
177                 /* Wait until it is time to run the tests again. */\r
178                 vTaskDelayUntil( &xLastExecutionTime, ulTicksToWait );\r
179 \r
180                 /* Has an error been found in any task? */\r
181                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
182                 {\r
183                         ulError |= 0x01UL;\r
184                 }\r
185                 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
186                 {\r
187                         ulError |= 0x02UL;\r
188                 }\r
189                 else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
190                 {\r
191                         ulError |= 0x04UL;\r
192                 }\r
193                 else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
194                 {\r
195                         ulError |= 0x10UL;\r
196                 }\r
197             else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
198             {\r
199                 ulError |= 0x20UL;\r
200             }\r
201             else if( xArePollingQueuesStillRunning() != pdTRUE )\r
202             {\r
203                 ulError |= 0x40UL;\r
204             }\r
205             else if( xIsCreateTaskStillRunning() != pdTRUE )\r
206             {\r
207                 ulError |= 0x80UL;\r
208             }\r
209             else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
210             {\r
211                 ulError |= 0x100UL;\r
212             }\r
213             else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
214             {\r
215                 ulError |= 0x200UL;\r
216             }\r
217             else if( xAreComTestTasksStillRunning() != pdTRUE )\r
218                 {\r
219                 ulError |= 0x400UL;\r
220                 }\r
221 \r
222                 if( ulError != 0 )\r
223                 {\r
224                 ulTicksToWait = mainERROR_PERIOD;\r
225                 }\r
226 \r
227                 vParTestToggleLED( mainCHECK_LED );\r
228         }\r
229 }\r
230 /*-----------------------------------------------------------*/\r
231 \r
232 void prvSetupHardware( void )\r
233 {\r
234         /* Multiply 8Mhz reference crystal by 8 to achieve system clock of 64Mhz. */\r
235         MCF_CLOCK_SYNCR = MCF_CLOCK_SYNCR_MFD( 2 );\r
236 \r
237         /* Wait for PLL to lock. */\r
238         while( !( MCF_CLOCK_SYNSR & MCF_CLOCK_SYNSR_LOCK ) )\r
239         {\r
240                 __asm__ volatile ( "NOP" );\r
241         }\r
242 \r
243         vParTestInitialise();\r
244 }\r
245 /*-----------------------------------------------------------*/\r
246 \r
247 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )\r
248 {\r
249         ( void ) pxTask;\r
250         ( void ) pcTaskName;\r
251 \r
252         for( ;; );\r
253 }\r
254 \r
255 \r