2 FreeRTOS V4.6.1 - copyright (C) 2003-2006 Richard Barry.
\r
3 MCF5235 Port - Copyright (C) 2006 Christian Walter.
\r
5 This file is part of the FreeRTOS distribution.
\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
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
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
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
27 ***************************************************************************
\r
28 ***************************************************************************
\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
34 ***************************************************************************
\r
35 ***************************************************************************
\r
37 Please ensure to read the configuration and relevant port sections of the
\r
38 online documentation.
\r
40 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
43 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
46 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
47 licensing and training services.
\r
50 /* ------------------------ System includes ------------------------------- */
\r
56 /* ------------------------ FreeRTOS includes ----------------------------- */
\r
57 #include "FreeRTOS.h"
\r
60 /* ------------------------ LWIP includes --------------------------------- */
\r
61 #include "lwip/api.h"
\r
62 #include "lwip/tcpip.h"
\r
63 #include "lwip/memp.h"
\r
65 /* ------------------------ Project includes ------------------------------ */
\r
66 #include "mcf5xxx.h"
\r
67 #include "mcf523x.h"
\r
71 #include "integer.h"
\r
73 #include "semtest.h"
\r
75 #include "dynamic.h"
\r
78 /* ------------------------ Defines --------------------------------------- */
\r
79 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 38400 )
\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
91 /* Interval in which tasks are checked. */
\r
92 #define mainCHECK_PERIOD ( ( portTickType ) 2000 / portTICK_RATE_MS )
\r
94 /* Constants used by the vMemCheckTask() task. */
\r
95 #define mainCOUNT_INITIAL_VALUE ( ( unsigned portLONG ) 0 )
\r
96 #define mainNO_TASK ( 0 )
\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
103 /* ------------------------ Static variables ------------------------------ */
\r
104 xComPortHandle xSTDComPort = NULL;
\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
112 /* ------------------------ Implementation -------------------------------- */
\r
114 main( int argc, char *argv[] )
\r
116 asm volatile ( "move.w #0x2000, %sr\n\t" );
\r
118 xSTDComPort = xSerialPortInitMinimal( 38400, 8 );
\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
129 /* Start the webserver. */
\r
130 ( void )sys_thread_new( vBasicWEBServer, NULL, mainWEB_TASK_PRIORITY );
\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
138 /* Should never get here! */
\r
143 portTASK_FUNCTION( vErrorChecks, pvParameters )
\r
145 unsigned portLONG ulMemCheckTaskRunningCount;
\r
146 xTaskHandle xCreatedTask;
\r
148 /* The parameters are not used in this function. */
\r
149 ( void )pvParameters;
\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
159 xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );
\r
161 /* Delay until it is time to execute again. */
\r
162 vTaskDelay( mainCHECK_PERIOD );
\r
164 /* Delete the dynamically created task. */
\r
165 if( xCreatedTask != mainNO_TASK )
\r
167 vTaskDelete( xCreatedTask );
\r
170 if( prvCheckOtherTasksAreStillRunning( ulMemCheckTaskRunningCount ) != pdPASS )
\r
172 xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );
\r
176 xSerialPutChar( xSTDComPort, '.', portMAX_DELAY );
\r
182 prvCheckOtherTasksAreStillRunning( unsigned portLONG ulMemCheckTaskCount )
\r
184 portLONG lReturn = ( portLONG ) pdPASS;
\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
190 if( xAreIntegerMathsTaskStillRunning( ) != pdTRUE )
\r
192 lReturn = ( portLONG ) pdFAIL;
\r
195 if( xArePollingQueuesStillRunning( ) != pdTRUE )
\r
197 lReturn = ( portLONG ) pdFAIL;
\r
200 if( xAreSemaphoreTasksStillRunning( ) != pdTRUE )
\r
202 lReturn = ( portLONG ) pdFAIL;
\r
205 if( xAreDynamicPriorityTasksStillRunning( ) != pdTRUE )
\r
207 lReturn = ( portLONG ) pdFAIL;
\r
210 if( xAreBlockingQueuesStillRunning( ) != pdTRUE )
\r
212 lReturn = ( portLONG ) pdFAIL;
\r
215 if( ulMemCheckTaskCount == mainCOUNT_INITIAL_VALUE )
\r
217 /* The vMemCheckTask did not increment the counter - it must
\r
220 lReturn = ( portLONG ) pdFAIL;
\r
226 vMemCheckTask( void *pvParameters )
\r
228 unsigned portLONG *pulMemCheckTaskRunningCounter;
\r
229 void *pvMem1, *pvMem2, *pvMem3;
\r
230 static portLONG lErrorOccurred = pdFALSE;
\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
238 The task executes at the idle priority so does not require a delay.
\r
240 pulMemCheckTaskRunningCounter is incremented each cycle to indicate to the
\r
241 vErrorChecks() task that this task is still executing without error. */
\r
243 pulMemCheckTaskRunningCounter = ( unsigned portLONG * )pvParameters;
\r
247 if( lErrorOccurred == pdFALSE )
\r
249 /* We have never seen an error so increment the counter. */
\r
250 ( *pulMemCheckTaskRunningCounter )++;
\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
258 pvMem1 = pvPortMalloc( mainMEM_CHECK_SIZE_1 );
\r
259 if( pvMem1 == NULL )
\r
261 lErrorOccurred = pdTRUE;
\r
265 memset( pvMem1, 0xaa, mainMEM_CHECK_SIZE_1 );
\r
266 vPortFree( pvMem1 );
\r
271 /* Again - with a different size block. */
\r
272 vTaskSuspendAll( );
\r
274 pvMem2 = pvPortMalloc( mainMEM_CHECK_SIZE_2 );
\r
275 if( pvMem2 == NULL )
\r
277 lErrorOccurred = pdTRUE;
\r
281 memset( pvMem2, 0xaa, mainMEM_CHECK_SIZE_2 );
\r
282 vPortFree( pvMem2 );
\r
287 /* Again - with a different size block. */
\r
288 vTaskSuspendAll( );
\r
290 pvMem3 = pvPortMalloc( mainMEM_CHECK_SIZE_3 );
\r
291 if( pvMem3 == NULL )
\r
293 lErrorOccurred = pdTRUE;
\r
297 memset( pvMem3, 0xaa, mainMEM_CHECK_SIZE_3 );
\r
298 vPortFree( pvMem3 );
\r