]> git.sur5r.net Git - freertos/blob - Demo/lwIP_MCF5235_GCC/demo.c
Update to V4.3.0 as described in http://www.FreeRTOS.org/History.txt
[freertos] / Demo / lwIP_MCF5235_GCC / demo.c
1 /*\r
2     FreeRTOS V4.1.0 - 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     See http://www.FreeRTOS.org for documentation, latest information, license\r
29     and contact details.  Please ensure to read the configuration and relevant\r
30     port sections of the online documentation.\r
31 \r
32         Also see http://www.SafeRTOS.com for an IEC 61508 compliant version along\r
33         with commercial development and support options.\r
34     ***************************************************************************\r
35 */\r
36 \r
37 /* ------------------------ System includes ------------------------------- */\r
38 #include <stdlib.h>\r
39 #include <stdio.h>\r
40 #include <string.h>\r
41 #include <assert.h>\r
42 \r
43 /* ------------------------ FreeRTOS includes ----------------------------- */\r
44 #include "FreeRTOS.h"\r
45 #include "task.h"\r
46 \r
47 /* ------------------------ LWIP includes --------------------------------- */\r
48 #include "lwip/api.h"\r
49 #include "lwip/tcpip.h"\r
50 #include "lwip/memp.h"\r
51 \r
52 /* ------------------------ Project includes ------------------------------ */\r
53 #include "mcf5xxx.h"\r
54 #include "mcf523x.h"\r
55 #include "serial.h"\r
56 \r
57 #include "web.h"\r
58 #include "integer.h"\r
59 #include "PollQ.h"\r
60 #include "semtest.h"\r
61 #include "BlockQ.h"\r
62 #include "dynamic.h"\r
63 #include "flop.h"\r
64 \r
65 /* ------------------------ Defines --------------------------------------- */\r
66 #define mainCOM_TEST_BAUD_RATE      ( ( unsigned portLONG ) 38400 )\r
67 \r
68 /* Priorities for the demo application tasks. */\r
69 #define mainLED_TASK_PRIORITY       ( tskIDLE_PRIORITY + 3 )\r
70 #define mainCOM_TEST_PRIORITY       ( tskIDLE_PRIORITY + 2 )\r
71 #define mainQUEUE_POLL_PRIORITY     ( tskIDLE_PRIORITY + 2 )\r
72 #define mainCHECK_TASK_PRIORITY     ( tskIDLE_PRIORITY + 4 )\r
73 #define mainSEM_TEST_PRIORITY       ( tskIDLE_PRIORITY + 1 )\r
74 #define mainBLOCK_Q_PRIORITY        ( tskIDLE_PRIORITY + 2 )\r
75 #define mainWEB_TASK_PRIORITY       ( tskIDLE_PRIORITY + 3 )\r
76 #define STACK_DEFAULT               ( 1024 )\r
77 \r
78 /* Interval in which tasks are checked. */\r
79 #define mainCHECK_PERIOD            ( ( portTickType ) 2000 / portTICK_RATE_MS  )\r
80 \r
81 /* Constants used by the vMemCheckTask() task. */\r
82 #define mainCOUNT_INITIAL_VALUE     ( ( unsigned portLONG ) 0 )\r
83 #define mainNO_TASK                 ( 0 )\r
84 \r
85 /* The size of the memory blocks allocated by the vMemCheckTask() task. */\r
86 #define mainMEM_CHECK_SIZE_1        ( ( size_t ) 51 )\r
87 #define mainMEM_CHECK_SIZE_2        ( ( size_t ) 52 )\r
88 #define mainMEM_CHECK_SIZE_3        ( ( size_t ) 151 )\r
89 \r
90 /* ------------------------ Static variables ------------------------------ */\r
91 xComPortHandle  xSTDComPort = NULL;\r
92 \r
93 /* ------------------------ Static functions ------------------------------ */\r
94 static          portTASK_FUNCTION( vErrorChecks, pvParameters );\r
95 static portLONG prvCheckOtherTasksAreStillRunning( unsigned portLONG\r
96                                                    ulMemCheckTaskCount );\r
97 static          portTASK_FUNCTION( vMemCheckTask, pvParameters );\r
98 \r
99 /* ------------------------ Implementation -------------------------------- */\r
100 int\r
101 main( int argc, char *argv[] )\r
102 {\r
103     asm volatile    ( "move.w  #0x2000, %sr\n\t" );\r
104 \r
105     xSTDComPort = xSerialPortInitMinimal( 38400, 8 );\r
106     vlwIPInit(  );\r
107 \r
108     /* Start the demo/test application tasks. */\r
109     vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
110     vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
111     //vStartMathTasks( tskIDLE_PRIORITY );\r
112     vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
113     vStartDynamicPriorityTasks(  );\r
114     vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
115 \r
116     /* Start the webserver. */\r
117     ( void )sys_thread_new( vBasicWEBServer, NULL, mainWEB_TASK_PRIORITY );\r
118 \r
119     /* Start the check task - which is defined in this file. */\r
120     xTaskCreate( vErrorChecks, ( signed portCHAR * )"Check", 512, NULL,\r
121                  mainCHECK_TASK_PRIORITY, NULL );\r
122         /* Now all the tasks have been started - start the scheduler. */\r
123     vTaskStartScheduler(  );\r
124 \r
125     /* Should never get here! */\r
126     return 0;\r
127 }\r
128 \r
129 static\r
130 portTASK_FUNCTION( vErrorChecks, pvParameters )\r
131 {\r
132     unsigned portLONG ulMemCheckTaskRunningCount;\r
133     xTaskHandle     xCreatedTask;\r
134 \r
135     /* The parameters are not used in this function. */\r
136     ( void )pvParameters;\r
137 \r
138     for( ;; )\r
139     {\r
140         ulMemCheckTaskRunningCount = mainCOUNT_INITIAL_VALUE;\r
141         xCreatedTask = mainNO_TASK;\r
142         if( xTaskCreate( vMemCheckTask, ( signed portCHAR * )"MEM",\r
143                          configMINIMAL_STACK_SIZE, ( void * )&ulMemCheckTaskRunningCount,\r
144                          tskIDLE_PRIORITY, &xCreatedTask ) != pdPASS )\r
145         {\r
146             xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );\r
147         }\r
148         /* Delay until it is time to execute again. */\r
149         vTaskDelay( mainCHECK_PERIOD );\r
150 \r
151         /* Delete the dynamically created task. */\r
152         if( xCreatedTask != mainNO_TASK )\r
153         {\r
154             vTaskDelete( xCreatedTask );\r
155         }\r
156 \r
157         if( prvCheckOtherTasksAreStillRunning( ulMemCheckTaskRunningCount ) != pdPASS )\r
158         {\r
159             xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );\r
160         }\r
161         else\r
162         {\r
163             xSerialPutChar( xSTDComPort, '.', portMAX_DELAY );\r
164         }\r
165     }\r
166 }\r
167 \r
168 static portLONG\r
169 prvCheckOtherTasksAreStillRunning( unsigned portLONG ulMemCheckTaskCount )\r
170 {\r
171     portLONG        lReturn = ( portLONG ) pdPASS;\r
172 \r
173     /* Check all the demo tasks (other than the flash tasks) to ensure\r
174      * that they are all still running, and that none of them have detected\r
175      * an error.\r
176      */\r
177     if( xAreIntegerMathsTaskStillRunning(  ) != pdTRUE )\r
178     {\r
179         lReturn = ( portLONG ) pdFAIL;\r
180     }\r
181 \r
182     if( xArePollingQueuesStillRunning(  ) != pdTRUE )\r
183     {\r
184         lReturn = ( portLONG ) pdFAIL;\r
185     }\r
186 \r
187     if( xAreSemaphoreTasksStillRunning(  ) != pdTRUE )\r
188     {\r
189         lReturn = ( portLONG ) pdFAIL;\r
190     }\r
191 \r
192     if( xAreDynamicPriorityTasksStillRunning(  ) != pdTRUE )\r
193     {\r
194         lReturn = ( portLONG ) pdFAIL;\r
195     }\r
196 \r
197     if( xAreBlockingQueuesStillRunning(  ) != pdTRUE )\r
198     {\r
199         lReturn = ( portLONG ) pdFAIL;\r
200     }\r
201 \r
202     if( ulMemCheckTaskCount == mainCOUNT_INITIAL_VALUE )\r
203     {\r
204         /* The vMemCheckTask did not increment the counter - it must\r
205          * have failed.\r
206          */\r
207         lReturn = ( portLONG ) pdFAIL;\r
208     }\r
209     return lReturn;\r
210 }\r
211 \r
212 static void\r
213 vMemCheckTask( void *pvParameters )\r
214 {\r
215     unsigned portLONG *pulMemCheckTaskRunningCounter;\r
216     void           *pvMem1, *pvMem2, *pvMem3;\r
217     static portLONG lErrorOccurred = pdFALSE;\r
218 \r
219     /* This task is dynamically created then deleted during each cycle of the\r
220        vErrorChecks task to check the operation of the memory allocator.  Each time\r
221        the task is created memory is allocated for the stack and TCB.  Each time\r
222        the task is deleted this memory is returned to the heap.  This task itself\r
223        exercises the allocator by allocating and freeing blocks.\r
224 \r
225        The task executes at the idle priority so does not require a delay.\r
226 \r
227        pulMemCheckTaskRunningCounter is incremented each cycle to indicate to the\r
228        vErrorChecks() task that this task is still executing without error. */\r
229 \r
230     pulMemCheckTaskRunningCounter = ( unsigned portLONG * )pvParameters;\r
231 \r
232     for( ;; )\r
233     {\r
234         if( lErrorOccurred == pdFALSE )\r
235         {\r
236             /* We have never seen an error so increment the counter. */\r
237             ( *pulMemCheckTaskRunningCounter )++;\r
238         }\r
239 \r
240         /* Allocate some memory - just to give the allocator some extra\r
241            exercise.  This has to be in a critical section to ensure the\r
242            task does not get deleted while it has memory allocated. */\r
243         vTaskSuspendAll(  );\r
244         {\r
245             pvMem1 = pvPortMalloc( mainMEM_CHECK_SIZE_1 );\r
246             if( pvMem1 == NULL )\r
247             {\r
248                 lErrorOccurred = pdTRUE;\r
249             }\r
250             else\r
251             {\r
252                 memset( pvMem1, 0xaa, mainMEM_CHECK_SIZE_1 );\r
253                 vPortFree( pvMem1 );\r
254             }\r
255         }\r
256         xTaskResumeAll(  );\r
257 \r
258         /* Again - with a different size block. */\r
259         vTaskSuspendAll(  );\r
260         {\r
261             pvMem2 = pvPortMalloc( mainMEM_CHECK_SIZE_2 );\r
262             if( pvMem2 == NULL )\r
263             {\r
264                 lErrorOccurred = pdTRUE;\r
265             }\r
266             else\r
267             {\r
268                 memset( pvMem2, 0xaa, mainMEM_CHECK_SIZE_2 );\r
269                 vPortFree( pvMem2 );\r
270             }\r
271         }\r
272         xTaskResumeAll(  );\r
273 \r
274         /* Again - with a different size block. */\r
275         vTaskSuspendAll(  );\r
276         {\r
277             pvMem3 = pvPortMalloc( mainMEM_CHECK_SIZE_3 );\r
278             if( pvMem3 == NULL )\r
279             {\r
280                 lErrorOccurred = pdTRUE;\r
281             }\r
282             else\r
283             {\r
284                 memset( pvMem3, 0xaa, mainMEM_CHECK_SIZE_3 );\r
285                 vPortFree( pvMem3 );\r
286             }\r
287         }\r
288         xTaskResumeAll(  );\r
289     }\r
290 }\r