]> git.sur5r.net Git - freertos/blob - Demo/lwIP_MCF5235_GCC/demo.c
Update version numbers to V4.8.0
[freertos] / Demo / lwIP_MCF5235_GCC / demo.c
1 /*\r
2     FreeRTOS V4.6.1 - copyright (C) 2003-2006 Richard Barry.\r
3     MCF5235 Port - Copyright (C) 2006 Christian Walter.\r
4 \r
5     This file is part of the FreeRTOS distribution.\r
6 \r
7     FreeRTOS is free software; you can redistribute it and/or modify\r
8     it under the terms of the GNU General Public License as published by\r
9     the Free Software Foundation; either version 2 of the License, or\r
10     (at your option) any later version.\r
11 \r
12     FreeRTOS is distributed in the hope that it will be useful,\r
13     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15     GNU General Public License for more details.\r
16 \r
17     You should have received a copy of the GNU General Public License\r
18     along with FreeRTOS; if not, write to the Free Software\r
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
20 \r
21     A special exception to the GPL can be applied should you wish to distribute\r
22     a combined work that includes FreeRTOS, without being obliged to provide\r
23     the source code for any proprietary components.  See the licensing section\r
24     of http://www.FreeRTOS.org for full details of how and when the exception\r
25     can be applied.\r
26 \r
27         ***************************************************************************\r
28         ***************************************************************************\r
29         *                                                                                                                                                 *\r
30         * SAVE TIME AND MONEY!  Why not get us to quote to get FreeRTOS.org               *\r
31         * running on your hardware - or even write all or part of your application*\r
32         * for you?  See http://www.OpenRTOS.com for details.                                      *\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 /* ------------------------ System includes ------------------------------- */\r
51 #include <stdlib.h>\r
52 #include <stdio.h>\r
53 #include <string.h>\r
54 #include <assert.h>\r
55 \r
56 /* ------------------------ FreeRTOS includes ----------------------------- */\r
57 #include "FreeRTOS.h"\r
58 #include "task.h"\r
59 \r
60 /* ------------------------ LWIP includes --------------------------------- */\r
61 #include "lwip/api.h"\r
62 #include "lwip/tcpip.h"\r
63 #include "lwip/memp.h"\r
64 \r
65 /* ------------------------ Project includes ------------------------------ */\r
66 #include "mcf5xxx.h"\r
67 #include "mcf523x.h"\r
68 #include "serial.h"\r
69 \r
70 #include "web.h"\r
71 #include "integer.h"\r
72 #include "PollQ.h"\r
73 #include "semtest.h"\r
74 #include "BlockQ.h"\r
75 #include "dynamic.h"\r
76 #include "flop.h"\r
77 \r
78 /* ------------------------ Defines --------------------------------------- */\r
79 #define mainCOM_TEST_BAUD_RATE      ( ( unsigned portLONG ) 38400 )\r
80 \r
81 /* Priorities for the demo application tasks. */\r
82 #define mainLED_TASK_PRIORITY       ( tskIDLE_PRIORITY + 3 )\r
83 #define mainCOM_TEST_PRIORITY       ( tskIDLE_PRIORITY + 2 )\r
84 #define mainQUEUE_POLL_PRIORITY     ( tskIDLE_PRIORITY + 2 )\r
85 #define mainCHECK_TASK_PRIORITY     ( tskIDLE_PRIORITY + 4 )\r
86 #define mainSEM_TEST_PRIORITY       ( tskIDLE_PRIORITY + 1 )\r
87 #define mainBLOCK_Q_PRIORITY        ( tskIDLE_PRIORITY + 2 )\r
88 #define mainWEB_TASK_PRIORITY       ( tskIDLE_PRIORITY + 3 )\r
89 #define STACK_DEFAULT               ( 1024 )\r
90 \r
91 /* Interval in which tasks are checked. */\r
92 #define mainCHECK_PERIOD            ( ( portTickType ) 2000 / portTICK_RATE_MS  )\r
93 \r
94 /* Constants used by the vMemCheckTask() task. */\r
95 #define mainCOUNT_INITIAL_VALUE     ( ( unsigned portLONG ) 0 )\r
96 #define mainNO_TASK                 ( 0 )\r
97 \r
98 /* The size of the memory blocks allocated by the vMemCheckTask() task. */\r
99 #define mainMEM_CHECK_SIZE_1        ( ( size_t ) 51 )\r
100 #define mainMEM_CHECK_SIZE_2        ( ( size_t ) 52 )\r
101 #define mainMEM_CHECK_SIZE_3        ( ( size_t ) 151 )\r
102 \r
103 /* ------------------------ Static variables ------------------------------ */\r
104 xComPortHandle  xSTDComPort = NULL;\r
105 \r
106 /* ------------------------ Static functions ------------------------------ */\r
107 static          portTASK_FUNCTION( vErrorChecks, pvParameters );\r
108 static portLONG prvCheckOtherTasksAreStillRunning( unsigned portLONG\r
109                                                    ulMemCheckTaskCount );\r
110 static          portTASK_FUNCTION( vMemCheckTask, pvParameters );\r
111 \r
112 /* ------------------------ Implementation -------------------------------- */\r
113 int\r
114 main( int argc, char *argv[] )\r
115 {\r
116     asm volatile    ( "move.w  #0x2000, %sr\n\t" );\r
117 \r
118     xSTDComPort = xSerialPortInitMinimal( 38400, 8 );\r
119     vlwIPInit(  );\r
120 \r
121     /* Start the demo/test application tasks. */\r
122     vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
123     vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
124     //vStartMathTasks( tskIDLE_PRIORITY );\r
125     vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
126     vStartDynamicPriorityTasks(  );\r
127     vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
128 \r
129     /* Start the webserver. */\r
130     ( void )sys_thread_new( vBasicWEBServer, NULL, mainWEB_TASK_PRIORITY );\r
131 \r
132     /* Start the check task - which is defined in this file. */\r
133     xTaskCreate( vErrorChecks, ( signed portCHAR * )"Check", 512, NULL,\r
134                  mainCHECK_TASK_PRIORITY, NULL );\r
135         /* Now all the tasks have been started - start the scheduler. */\r
136     vTaskStartScheduler(  );\r
137 \r
138     /* Should never get here! */\r
139     return 0;\r
140 }\r
141 \r
142 static\r
143 portTASK_FUNCTION( vErrorChecks, pvParameters )\r
144 {\r
145     unsigned portLONG ulMemCheckTaskRunningCount;\r
146     xTaskHandle     xCreatedTask;\r
147 \r
148     /* The parameters are not used in this function. */\r
149     ( void )pvParameters;\r
150 \r
151     for( ;; )\r
152     {\r
153         ulMemCheckTaskRunningCount = mainCOUNT_INITIAL_VALUE;\r
154         xCreatedTask = mainNO_TASK;\r
155         if( xTaskCreate( vMemCheckTask, ( signed portCHAR * )"MEM",\r
156                          configMINIMAL_STACK_SIZE, ( void * )&ulMemCheckTaskRunningCount,\r
157                          tskIDLE_PRIORITY, &xCreatedTask ) != pdPASS )\r
158         {\r
159             xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );\r
160         }\r
161         /* Delay until it is time to execute again. */\r
162         vTaskDelay( mainCHECK_PERIOD );\r
163 \r
164         /* Delete the dynamically created task. */\r
165         if( xCreatedTask != mainNO_TASK )\r
166         {\r
167             vTaskDelete( xCreatedTask );\r
168         }\r
169 \r
170         if( prvCheckOtherTasksAreStillRunning( ulMemCheckTaskRunningCount ) != pdPASS )\r
171         {\r
172             xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );\r
173         }\r
174         else\r
175         {\r
176             xSerialPutChar( xSTDComPort, '.', portMAX_DELAY );\r
177         }\r
178     }\r
179 }\r
180 \r
181 static portLONG\r
182 prvCheckOtherTasksAreStillRunning( unsigned portLONG ulMemCheckTaskCount )\r
183 {\r
184     portLONG        lReturn = ( portLONG ) pdPASS;\r
185 \r
186     /* Check all the demo tasks (other than the flash tasks) to ensure\r
187      * that they are all still running, and that none of them have detected\r
188      * an error.\r
189      */\r
190     if( xAreIntegerMathsTaskStillRunning(  ) != pdTRUE )\r
191     {\r
192         lReturn = ( portLONG ) pdFAIL;\r
193     }\r
194 \r
195     if( xArePollingQueuesStillRunning(  ) != pdTRUE )\r
196     {\r
197         lReturn = ( portLONG ) pdFAIL;\r
198     }\r
199 \r
200     if( xAreSemaphoreTasksStillRunning(  ) != pdTRUE )\r
201     {\r
202         lReturn = ( portLONG ) pdFAIL;\r
203     }\r
204 \r
205     if( xAreDynamicPriorityTasksStillRunning(  ) != pdTRUE )\r
206     {\r
207         lReturn = ( portLONG ) pdFAIL;\r
208     }\r
209 \r
210     if( xAreBlockingQueuesStillRunning(  ) != pdTRUE )\r
211     {\r
212         lReturn = ( portLONG ) pdFAIL;\r
213     }\r
214 \r
215     if( ulMemCheckTaskCount == mainCOUNT_INITIAL_VALUE )\r
216     {\r
217         /* The vMemCheckTask did not increment the counter - it must\r
218          * have failed.\r
219          */\r
220         lReturn = ( portLONG ) pdFAIL;\r
221     }\r
222     return lReturn;\r
223 }\r
224 \r
225 static void\r
226 vMemCheckTask( void *pvParameters )\r
227 {\r
228     unsigned portLONG *pulMemCheckTaskRunningCounter;\r
229     void           *pvMem1, *pvMem2, *pvMem3;\r
230     static portLONG lErrorOccurred = pdFALSE;\r
231 \r
232     /* This task is dynamically created then deleted during each cycle of the\r
233        vErrorChecks task to check the operation of the memory allocator.  Each time\r
234        the task is created memory is allocated for the stack and TCB.  Each time\r
235        the task is deleted this memory is returned to the heap.  This task itself\r
236        exercises the allocator by allocating and freeing blocks.\r
237 \r
238        The task executes at the idle priority so does not require a delay.\r
239 \r
240        pulMemCheckTaskRunningCounter is incremented each cycle to indicate to the\r
241        vErrorChecks() task that this task is still executing without error. */\r
242 \r
243     pulMemCheckTaskRunningCounter = ( unsigned portLONG * )pvParameters;\r
244 \r
245     for( ;; )\r
246     {\r
247         if( lErrorOccurred == pdFALSE )\r
248         {\r
249             /* We have never seen an error so increment the counter. */\r
250             ( *pulMemCheckTaskRunningCounter )++;\r
251         }\r
252 \r
253         /* Allocate some memory - just to give the allocator some extra\r
254            exercise.  This has to be in a critical section to ensure the\r
255            task does not get deleted while it has memory allocated. */\r
256         vTaskSuspendAll(  );\r
257         {\r
258             pvMem1 = pvPortMalloc( mainMEM_CHECK_SIZE_1 );\r
259             if( pvMem1 == NULL )\r
260             {\r
261                 lErrorOccurred = pdTRUE;\r
262             }\r
263             else\r
264             {\r
265                 memset( pvMem1, 0xaa, mainMEM_CHECK_SIZE_1 );\r
266                 vPortFree( pvMem1 );\r
267             }\r
268         }\r
269         xTaskResumeAll(  );\r
270 \r
271         /* Again - with a different size block. */\r
272         vTaskSuspendAll(  );\r
273         {\r
274             pvMem2 = pvPortMalloc( mainMEM_CHECK_SIZE_2 );\r
275             if( pvMem2 == NULL )\r
276             {\r
277                 lErrorOccurred = pdTRUE;\r
278             }\r
279             else\r
280             {\r
281                 memset( pvMem2, 0xaa, mainMEM_CHECK_SIZE_2 );\r
282                 vPortFree( pvMem2 );\r
283             }\r
284         }\r
285         xTaskResumeAll(  );\r
286 \r
287         /* Again - with a different size block. */\r
288         vTaskSuspendAll(  );\r
289         {\r
290             pvMem3 = pvPortMalloc( mainMEM_CHECK_SIZE_3 );\r
291             if( pvMem3 == NULL )\r
292             {\r
293                 lErrorOccurred = pdTRUE;\r
294             }\r
295             else\r
296             {\r
297                 memset( pvMem3, 0xaa, mainMEM_CHECK_SIZE_3 );\r
298                 vPortFree( pvMem3 );\r
299             }\r
300         }\r
301         xTaskResumeAll(  );\r
302     }\r
303 }\r