2 FreeRTOS V4.1.0 - copyright (C) 2003-2006 Richard Barry.
3 MCF5235 Port - Copyright (C) 2006 Christian Walter.
5 This file is part of the FreeRTOS distribution.
7 FreeRTOS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 FreeRTOS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with FreeRTOS; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 A special exception to the GPL can be applied should you wish to distribute
22 a combined work that includes FreeRTOS, without being obliged to provide
23 the source code for any proprietary components. See the licensing section
24 of http://www.FreeRTOS.org for full details of how and when the exception
27 ***************************************************************************
28 See http://www.FreeRTOS.org for documentation, latest information, license
29 and contact details. Please ensure to read the configuration and relevant
30 port sections of the online documentation.
31 ***************************************************************************
34 /* ------------------------ System includes ------------------------------- */
40 /* ------------------------ FreeRTOS includes ----------------------------- */
44 /* ------------------------ LWIP includes --------------------------------- */
46 #include "lwip/tcpip.h"
47 #include "lwip/memp.h"
49 /* ------------------------ Project includes ------------------------------ */
62 /* ------------------------ Defines --------------------------------------- */
63 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 38400 )
65 /* Priorities for the demo application tasks. */
66 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
67 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
68 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
69 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
70 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
71 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
72 #define mainWEB_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
73 #define STACK_DEFAULT ( 1024 )
75 /* Interval in which tasks are checked. */
76 #define mainCHECK_PERIOD ( ( portTickType ) 2000 / portTICK_RATE_MS )
78 /* Constants used by the vMemCheckTask() task. */
79 #define mainCOUNT_INITIAL_VALUE ( ( unsigned portLONG ) 0 )
80 #define mainNO_TASK ( 0 )
82 /* The size of the memory blocks allocated by the vMemCheckTask() task. */
83 #define mainMEM_CHECK_SIZE_1 ( ( size_t ) 51 )
84 #define mainMEM_CHECK_SIZE_2 ( ( size_t ) 52 )
85 #define mainMEM_CHECK_SIZE_3 ( ( size_t ) 151 )
87 /* ------------------------ Static variables ------------------------------ */
88 xComPortHandle xSTDComPort = NULL;
90 /* ------------------------ Static functions ------------------------------ */
91 static portTASK_FUNCTION( vErrorChecks, pvParameters );
92 static portLONG prvCheckOtherTasksAreStillRunning( unsigned portLONG
93 ulMemCheckTaskCount );
94 static portTASK_FUNCTION( vMemCheckTask, pvParameters );
96 /* ------------------------ Implementation -------------------------------- */
98 main( int argc, char *argv[] )
100 asm volatile ( "move.w #0x2000, %sr\n\t" );
102 xSTDComPort = xSerialPortInitMinimal( 38400, 8 );
105 /* Start the demo/test application tasks. */
106 vStartIntegerMathTasks( tskIDLE_PRIORITY );
107 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
108 //vStartMathTasks( tskIDLE_PRIORITY );
109 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
110 vStartDynamicPriorityTasks( );
111 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
113 /* Start the webserver. */
114 ( void )sys_thread_new( vBasicWEBServer, NULL, mainWEB_TASK_PRIORITY );
116 /* Start the check task - which is defined in this file. */
117 xTaskCreate( vErrorChecks, ( signed portCHAR * )"Check", 512, NULL,
118 mainCHECK_TASK_PRIORITY, NULL );
119 /* Now all the tasks have been started - start the scheduler. */
120 vTaskStartScheduler( );
122 /* Should never get here! */
127 portTASK_FUNCTION( vErrorChecks, pvParameters )
129 unsigned portLONG ulMemCheckTaskRunningCount;
130 xTaskHandle xCreatedTask;
132 /* The parameters are not used in this function. */
133 ( void )pvParameters;
137 ulMemCheckTaskRunningCount = mainCOUNT_INITIAL_VALUE;
138 xCreatedTask = mainNO_TASK;
139 if( xTaskCreate( vMemCheckTask, ( signed portCHAR * )"MEM",
140 configMINIMAL_STACK_SIZE, ( void * )&ulMemCheckTaskRunningCount,
141 tskIDLE_PRIORITY, &xCreatedTask ) != pdPASS )
143 xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );
145 /* Delay until it is time to execute again. */
146 vTaskDelay( mainCHECK_PERIOD );
148 /* Delete the dynamically created task. */
149 if( xCreatedTask != mainNO_TASK )
151 vTaskDelete( xCreatedTask );
154 if( prvCheckOtherTasksAreStillRunning( ulMemCheckTaskRunningCount ) != pdPASS )
156 xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );
160 xSerialPutChar( xSTDComPort, '.', portMAX_DELAY );
166 prvCheckOtherTasksAreStillRunning( unsigned portLONG ulMemCheckTaskCount )
168 portLONG lReturn = ( portLONG ) pdPASS;
170 /* Check all the demo tasks (other than the flash tasks) to ensure
171 * that they are all still running, and that none of them have detected
174 if( xAreIntegerMathsTaskStillRunning( ) != pdTRUE )
176 lReturn = ( portLONG ) pdFAIL;
179 if( xArePollingQueuesStillRunning( ) != pdTRUE )
181 lReturn = ( portLONG ) pdFAIL;
184 if( xAreSemaphoreTasksStillRunning( ) != pdTRUE )
186 lReturn = ( portLONG ) pdFAIL;
189 if( xAreDynamicPriorityTasksStillRunning( ) != pdTRUE )
191 lReturn = ( portLONG ) pdFAIL;
194 if( xAreBlockingQueuesStillRunning( ) != pdTRUE )
196 lReturn = ( portLONG ) pdFAIL;
199 if( ulMemCheckTaskCount == mainCOUNT_INITIAL_VALUE )
201 /* The vMemCheckTask did not increment the counter - it must
204 lReturn = ( portLONG ) pdFAIL;
210 vMemCheckTask( void *pvParameters )
212 unsigned portLONG *pulMemCheckTaskRunningCounter;
213 void *pvMem1, *pvMem2, *pvMem3;
214 static portLONG lErrorOccurred = pdFALSE;
216 /* This task is dynamically created then deleted during each cycle of the
217 vErrorChecks task to check the operation of the memory allocator. Each time
218 the task is created memory is allocated for the stack and TCB. Each time
219 the task is deleted this memory is returned to the heap. This task itself
220 exercises the allocator by allocating and freeing blocks.
222 The task executes at the idle priority so does not require a delay.
224 pulMemCheckTaskRunningCounter is incremented each cycle to indicate to the
225 vErrorChecks() task that this task is still executing without error. */
227 pulMemCheckTaskRunningCounter = ( unsigned portLONG * )pvParameters;
231 if( lErrorOccurred == pdFALSE )
233 /* We have never seen an error so increment the counter. */
234 ( *pulMemCheckTaskRunningCounter )++;
237 /* Allocate some memory - just to give the allocator some extra
238 exercise. This has to be in a critical section to ensure the
239 task does not get deleted while it has memory allocated. */
242 pvMem1 = pvPortMalloc( mainMEM_CHECK_SIZE_1 );
245 lErrorOccurred = pdTRUE;
249 memset( pvMem1, 0xaa, mainMEM_CHECK_SIZE_1 );
255 /* Again - with a different size block. */
258 pvMem2 = pvPortMalloc( mainMEM_CHECK_SIZE_2 );
261 lErrorOccurred = pdTRUE;
265 memset( pvMem2, 0xaa, mainMEM_CHECK_SIZE_2 );
271 /* Again - with a different size block. */
274 pvMem3 = pvPortMalloc( mainMEM_CHECK_SIZE_3 );
277 lErrorOccurred = pdTRUE;
281 memset( pvMem3, 0xaa, mainMEM_CHECK_SIZE_3 );