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! We can port FreeRTOS.org to your own hardware, *
\r
31 * and even write all or part of your application on your behalf. *
\r
32 * See http://www.OpenRTOS.com for details of the services we provide to *
\r
33 * expedite your project. *
\r
35 ***************************************************************************
\r
36 ***************************************************************************
\r
38 Please ensure to read the configuration and relevant port sections of the
\r
39 online documentation.
\r
41 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
44 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
47 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
48 licensing and training services.
\r
51 /* ------------------------ System includes ------------------------------- */
\r
57 /* ------------------------ FreeRTOS includes ----------------------------- */
\r
58 #include "FreeRTOS.h"
\r
61 /* ------------------------ LWIP includes --------------------------------- */
\r
62 #include "lwip/api.h"
\r
63 #include "lwip/tcpip.h"
\r
64 #include "lwip/memp.h"
\r
66 /* ------------------------ Project includes ------------------------------ */
\r
67 #include "mcf5xxx.h"
\r
68 #include "mcf523x.h"
\r
72 #include "integer.h"
\r
74 #include "semtest.h"
\r
76 #include "dynamic.h"
\r
79 /* ------------------------ Defines --------------------------------------- */
\r
80 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 38400 )
\r
82 /* Priorities for the demo application tasks. */
\r
83 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
84 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
85 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
86 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
87 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
88 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
89 #define mainWEB_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
90 #define STACK_DEFAULT ( 1024 )
\r
92 /* Interval in which tasks are checked. */
\r
93 #define mainCHECK_PERIOD ( ( portTickType ) 2000 / portTICK_RATE_MS )
\r
95 /* Constants used by the vMemCheckTask() task. */
\r
96 #define mainCOUNT_INITIAL_VALUE ( ( unsigned portLONG ) 0 )
\r
97 #define mainNO_TASK ( 0 )
\r
99 /* The size of the memory blocks allocated by the vMemCheckTask() task. */
\r
100 #define mainMEM_CHECK_SIZE_1 ( ( size_t ) 51 )
\r
101 #define mainMEM_CHECK_SIZE_2 ( ( size_t ) 52 )
\r
102 #define mainMEM_CHECK_SIZE_3 ( ( size_t ) 151 )
\r
104 /* ------------------------ Static variables ------------------------------ */
\r
105 xComPortHandle xSTDComPort = NULL;
\r
107 /* ------------------------ Static functions ------------------------------ */
\r
108 static portTASK_FUNCTION( vErrorChecks, pvParameters );
\r
109 static portLONG prvCheckOtherTasksAreStillRunning( unsigned portLONG
\r
110 ulMemCheckTaskCount );
\r
111 static portTASK_FUNCTION( vMemCheckTask, pvParameters );
\r
113 /* ------------------------ Implementation -------------------------------- */
\r
115 main( int argc, char *argv[] )
\r
117 asm volatile ( "move.w #0x2000, %sr\n\t" );
\r
119 xSTDComPort = xSerialPortInitMinimal( 38400, 8 );
\r
122 /* Start the demo/test application tasks. */
\r
123 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
124 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
125 //vStartMathTasks( tskIDLE_PRIORITY );
\r
126 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
127 vStartDynamicPriorityTasks( );
\r
128 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
130 /* Start the webserver. */
\r
131 ( void )sys_thread_new( vBasicWEBServer, NULL, mainWEB_TASK_PRIORITY );
\r
133 /* Start the check task - which is defined in this file. */
\r
134 xTaskCreate( vErrorChecks, ( signed portCHAR * )"Check", 512, NULL,
\r
135 mainCHECK_TASK_PRIORITY, NULL );
\r
136 /* Now all the tasks have been started - start the scheduler. */
\r
137 vTaskStartScheduler( );
\r
139 /* Should never get here! */
\r
144 portTASK_FUNCTION( vErrorChecks, pvParameters )
\r
146 unsigned portLONG ulMemCheckTaskRunningCount;
\r
147 xTaskHandle xCreatedTask;
\r
149 /* The parameters are not used in this function. */
\r
150 ( void )pvParameters;
\r
154 ulMemCheckTaskRunningCount = mainCOUNT_INITIAL_VALUE;
\r
155 xCreatedTask = mainNO_TASK;
\r
156 if( xTaskCreate( vMemCheckTask, ( signed portCHAR * )"MEM",
\r
157 configMINIMAL_STACK_SIZE, ( void * )&ulMemCheckTaskRunningCount,
\r
158 tskIDLE_PRIORITY, &xCreatedTask ) != pdPASS )
\r
160 xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );
\r
162 /* Delay until it is time to execute again. */
\r
163 vTaskDelay( mainCHECK_PERIOD );
\r
165 /* Delete the dynamically created task. */
\r
166 if( xCreatedTask != mainNO_TASK )
\r
168 vTaskDelete( xCreatedTask );
\r
171 if( prvCheckOtherTasksAreStillRunning( ulMemCheckTaskRunningCount ) != pdPASS )
\r
173 xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );
\r
177 xSerialPutChar( xSTDComPort, '.', portMAX_DELAY );
\r
183 prvCheckOtherTasksAreStillRunning( unsigned portLONG ulMemCheckTaskCount )
\r
185 portLONG lReturn = ( portLONG ) pdPASS;
\r
187 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
188 * that they are all still running, and that none of them have detected
\r
191 if( xAreIntegerMathsTaskStillRunning( ) != pdTRUE )
\r
193 lReturn = ( portLONG ) pdFAIL;
\r
196 if( xArePollingQueuesStillRunning( ) != pdTRUE )
\r
198 lReturn = ( portLONG ) pdFAIL;
\r
201 if( xAreSemaphoreTasksStillRunning( ) != pdTRUE )
\r
203 lReturn = ( portLONG ) pdFAIL;
\r
206 if( xAreDynamicPriorityTasksStillRunning( ) != pdTRUE )
\r
208 lReturn = ( portLONG ) pdFAIL;
\r
211 if( xAreBlockingQueuesStillRunning( ) != pdTRUE )
\r
213 lReturn = ( portLONG ) pdFAIL;
\r
216 if( ulMemCheckTaskCount == mainCOUNT_INITIAL_VALUE )
\r
218 /* The vMemCheckTask did not increment the counter - it must
\r
221 lReturn = ( portLONG ) pdFAIL;
\r
227 vMemCheckTask( void *pvParameters )
\r
229 unsigned portLONG *pulMemCheckTaskRunningCounter;
\r
230 void *pvMem1, *pvMem2, *pvMem3;
\r
231 static portLONG lErrorOccurred = pdFALSE;
\r
233 /* This task is dynamically created then deleted during each cycle of the
\r
234 vErrorChecks task to check the operation of the memory allocator. Each time
\r
235 the task is created memory is allocated for the stack and TCB. Each time
\r
236 the task is deleted this memory is returned to the heap. This task itself
\r
237 exercises the allocator by allocating and freeing blocks.
\r
239 The task executes at the idle priority so does not require a delay.
\r
241 pulMemCheckTaskRunningCounter is incremented each cycle to indicate to the
\r
242 vErrorChecks() task that this task is still executing without error. */
\r
244 pulMemCheckTaskRunningCounter = ( unsigned portLONG * )pvParameters;
\r
248 if( lErrorOccurred == pdFALSE )
\r
250 /* We have never seen an error so increment the counter. */
\r
251 ( *pulMemCheckTaskRunningCounter )++;
\r
254 /* Allocate some memory - just to give the allocator some extra
\r
255 exercise. This has to be in a critical section to ensure the
\r
256 task does not get deleted while it has memory allocated. */
\r
257 vTaskSuspendAll( );
\r
259 pvMem1 = pvPortMalloc( mainMEM_CHECK_SIZE_1 );
\r
260 if( pvMem1 == NULL )
\r
262 lErrorOccurred = pdTRUE;
\r
266 memset( pvMem1, 0xaa, mainMEM_CHECK_SIZE_1 );
\r
267 vPortFree( pvMem1 );
\r
272 /* Again - with a different size block. */
\r
273 vTaskSuspendAll( );
\r
275 pvMem2 = pvPortMalloc( mainMEM_CHECK_SIZE_2 );
\r
276 if( pvMem2 == NULL )
\r
278 lErrorOccurred = pdTRUE;
\r
282 memset( pvMem2, 0xaa, mainMEM_CHECK_SIZE_2 );
\r
283 vPortFree( pvMem2 );
\r
288 /* Again - with a different size block. */
\r
289 vTaskSuspendAll( );
\r
291 pvMem3 = pvPortMalloc( mainMEM_CHECK_SIZE_3 );
\r
292 if( pvMem3 == NULL )
\r
294 lErrorOccurred = pdTRUE;
\r
298 memset( pvMem3, 0xaa, mainMEM_CHECK_SIZE_3 );
\r
299 vPortFree( pvMem3 );
\r