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 ------------------------------- */
38 /* ------------------------ FreeRTOS includes ----------------------------- */
42 /* ------------------------ Demo application includes --------------------- */
54 /* ------------------------ Defines --------------------------------------- */
55 /* Constants for the ComTest tasks. */
56 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 38400 )
57 #define mainCOM_TEST_LED ( -1 )
59 /* Priorities for the demo application tasks. */
60 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
61 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
62 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
63 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
64 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
65 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
67 /* Interval in which tasks are checked. */
68 #define mainCHECK_PERIOD ( ( portTickType ) 2000 / portTICK_RATE_MS )
70 /* Constants used by the vMemCheckTask() task. */
71 #define mainCOUNT_INITIAL_VALUE ( ( unsigned portLONG ) 0 )
72 #define mainNO_TASK ( 0 )
74 /* The size of the memory blocks allocated by the vMemCheckTask() task. */
75 #define mainMEM_CHECK_SIZE_1 ( ( size_t ) 51 )
76 #define mainMEM_CHECK_SIZE_2 ( ( size_t ) 52 )
77 #define mainMEM_CHECK_SIZE_3 ( ( size_t ) 151 )
79 /* ------------------------ Static variables ------------------------------ */
80 xComPortHandle xSTDComPort = NULL;
82 /* ------------------------ Static functions ------------------------------ */
83 static portTASK_FUNCTION( vErrorChecks, pvParameters );
84 static portLONG prvCheckOtherTasksAreStillRunning( unsigned portLONG
85 ulMemCheckTaskCount );
86 static portTASK_FUNCTION( vMemCheckTask, pvParameters );
88 /* ------------------------ Implementation -------------------------------- */
90 main( int argc, char *argv[] )
92 asm volatile ( "move.w #0x2000, %sr\n\t" );
94 xSTDComPort = xSerialPortInitMinimal( 38400, 8 );
96 /* Start the demo/test application tasks. */
97 vStartIntegerMathTasks( tskIDLE_PRIORITY );
98 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
99 vStartMathTasks( tskIDLE_PRIORITY );
100 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
101 vStartDynamicPriorityTasks( );
102 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
104 /* Start the check task - which is defined in this file. */
105 xTaskCreate( vErrorChecks, ( signed portCHAR * )"Check", 512, NULL,
106 mainCHECK_TASK_PRIORITY, NULL );
108 /* Now all the tasks have been started - start the scheduler. */
109 vTaskStartScheduler( );
111 /* Should never get here! */
118 portTASK_FUNCTION( vErrorChecks, pvParameters )
120 unsigned portLONG ulMemCheckTaskRunningCount;
121 xTaskHandle xCreatedTask;
123 /* The parameters are not used in this function. */
124 ( void )pvParameters;
126 xSerialPortInitMinimal( mainCOM_TEST_BAUD_RATE, 8 );
130 ulMemCheckTaskRunningCount = mainCOUNT_INITIAL_VALUE;
131 xCreatedTask = mainNO_TASK;
134 ( vMemCheckTask, ( signed portCHAR * )"MEM_CHECK",
135 configMINIMAL_STACK_SIZE, ( void * )&ulMemCheckTaskRunningCount,
136 tskIDLE_PRIORITY, &xCreatedTask ) != pdPASS )
138 xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );
141 /* Delay until it is time to execute again. */
142 vTaskDelay( mainCHECK_PERIOD );
144 /* Delete the dynamically created task. */
145 if( xCreatedTask != mainNO_TASK )
147 vTaskDelete( xCreatedTask );
150 if( prvCheckOtherTasksAreStillRunning( ulMemCheckTaskRunningCount ) !=
153 xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );
157 xSerialPutChar( xSTDComPort, '.', portMAX_DELAY );
163 prvCheckOtherTasksAreStillRunning( unsigned portLONG ulMemCheckTaskCount )
165 portLONG lReturn = ( portLONG ) pdPASS;
167 /* Check all the demo tasks (other than the flash tasks) to ensure
168 * that they are all still running, and that none of them have detected
172 if( xAreIntegerMathsTaskStillRunning( ) != pdTRUE )
174 lReturn = ( portLONG ) pdFAIL;
177 if( xArePollingQueuesStillRunning( ) != pdTRUE )
179 lReturn = ( portLONG ) pdFAIL;
182 if( xAreMathsTaskStillRunning( ) != pdTRUE )
184 lReturn = ( portLONG ) pdFAIL;
187 if( xAreSemaphoreTasksStillRunning( ) != pdTRUE )
189 lReturn = ( portLONG ) pdFAIL;
192 if( xAreDynamicPriorityTasksStillRunning( ) != pdTRUE )
194 lReturn = ( portLONG ) pdFAIL;
197 if( xAreBlockingQueuesStillRunning( ) != pdTRUE )
199 lReturn = ( portLONG ) pdFAIL;
201 if( ulMemCheckTaskCount == mainCOUNT_INITIAL_VALUE )
203 // The vMemCheckTask did not increment the counter - it must
205 lReturn = ( portLONG ) pdFAIL;
211 vMemCheckTask( void *pvParameters )
213 unsigned portLONG *pulMemCheckTaskRunningCounter;
214 void *pvMem1, *pvMem2, *pvMem3;
215 static portLONG lErrorOccurred = pdFALSE;
217 /* This task is dynamically created then deleted during each cycle of the
218 vErrorChecks task to check the operation of the memory allocator. Each time
219 the task is created memory is allocated for the stack and TCB. Each time
220 the task is deleted this memory is returned to the heap. This task itself
221 exercises the allocator by allocating and freeing blocks.
223 The task executes at the idle priority so does not require a delay.
225 pulMemCheckTaskRunningCounter is incremented each cycle to indicate to the
226 vErrorChecks() task that this task is still executing without error. */
228 pulMemCheckTaskRunningCounter = ( unsigned portLONG * )pvParameters;
232 if( lErrorOccurred == pdFALSE )
234 /* We have never seen an error so increment the counter. */
235 ( *pulMemCheckTaskRunningCounter )++;
238 /* Allocate some memory - just to give the allocator some extra
239 exercise. This has to be in a critical section to ensure the
240 task does not get deleted while it has memory allocated. */
243 pvMem1 = pvPortMalloc( mainMEM_CHECK_SIZE_1 );
246 lErrorOccurred = pdTRUE;
250 memset( pvMem1, 0xaa, mainMEM_CHECK_SIZE_1 );
256 /* Again - with a different size block. */
259 pvMem2 = pvPortMalloc( mainMEM_CHECK_SIZE_2 );
262 lErrorOccurred = pdTRUE;
266 memset( pvMem2, 0xaa, mainMEM_CHECK_SIZE_2 );
272 /* Again - with a different size block. */
275 pvMem3 = pvPortMalloc( mainMEM_CHECK_SIZE_3 );
278 lErrorOccurred = pdTRUE;
282 memset( pvMem3, 0xaa, mainMEM_CHECK_SIZE_3 );
291 vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
296 vParTestToggleLED( unsigned portBASE_TYPE uxLED )