2 FreeRTOS V4.1.0 - 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 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
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
37 /* ------------------------ System includes ------------------------------- */
\r
41 /* ------------------------ FreeRTOS includes ----------------------------- */
\r
42 #include "FreeRTOS.h"
\r
45 /* ------------------------ Demo application includes --------------------- */
\r
46 #include "partest.h"
\r
48 #include "integer.h"
\r
50 #include "comtest2.h"
\r
51 #include "semtest.h"
\r
53 #include "dynamic.h"
\r
57 /* ------------------------ Defines --------------------------------------- */
\r
58 /* Constants for the ComTest tasks. */
\r
59 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 38400 )
\r
60 #define mainCOM_TEST_LED ( -1 )
\r
62 /* Priorities for the demo application tasks. */
\r
63 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
64 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
65 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
66 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
67 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
68 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
70 /* Interval in which tasks are checked. */
\r
71 #define mainCHECK_PERIOD ( ( portTickType ) 2000 / portTICK_RATE_MS )
\r
73 /* Constants used by the vMemCheckTask() task. */
\r
74 #define mainCOUNT_INITIAL_VALUE ( ( unsigned portLONG ) 0 )
\r
75 #define mainNO_TASK ( 0 )
\r
77 /* The size of the memory blocks allocated by the vMemCheckTask() task. */
\r
78 #define mainMEM_CHECK_SIZE_1 ( ( size_t ) 51 )
\r
79 #define mainMEM_CHECK_SIZE_2 ( ( size_t ) 52 )
\r
80 #define mainMEM_CHECK_SIZE_3 ( ( size_t ) 151 )
\r
82 /* ------------------------ Static variables ------------------------------ */
\r
83 xComPortHandle xSTDComPort = NULL;
\r
85 /* ------------------------ Static functions ------------------------------ */
\r
86 static portTASK_FUNCTION( vErrorChecks, pvParameters );
\r
87 static portLONG prvCheckOtherTasksAreStillRunning( unsigned portLONG
\r
88 ulMemCheckTaskCount );
\r
89 static portTASK_FUNCTION( vMemCheckTask, pvParameters );
\r
91 /* ------------------------ Implementation -------------------------------- */
\r
93 main( int argc, char *argv[] )
\r
95 asm volatile ( "move.w #0x2000, %sr\n\t" );
\r
97 xSTDComPort = xSerialPortInitMinimal( 38400, 8 );
\r
99 /* Start the demo/test application tasks. */
\r
100 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
101 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
102 vStartMathTasks( tskIDLE_PRIORITY );
\r
103 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
104 vStartDynamicPriorityTasks( );
\r
105 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
107 /* Start the check task - which is defined in this file. */
\r
108 xTaskCreate( vErrorChecks, ( signed portCHAR * )"Check", 512, NULL,
\r
109 mainCHECK_TASK_PRIORITY, NULL );
\r
111 /* Now all the tasks have been started - start the scheduler. */
\r
112 vTaskStartScheduler( );
\r
114 /* Should never get here! */
\r
121 portTASK_FUNCTION( vErrorChecks, pvParameters )
\r
123 unsigned portLONG ulMemCheckTaskRunningCount;
\r
124 xTaskHandle xCreatedTask;
\r
126 /* The parameters are not used in this function. */
\r
127 ( void )pvParameters;
\r
129 xSerialPortInitMinimal( mainCOM_TEST_BAUD_RATE, 8 );
\r
133 ulMemCheckTaskRunningCount = mainCOUNT_INITIAL_VALUE;
\r
134 xCreatedTask = mainNO_TASK;
\r
137 ( vMemCheckTask, ( signed portCHAR * )"MEM_CHECK",
\r
138 configMINIMAL_STACK_SIZE, ( void * )&ulMemCheckTaskRunningCount,
\r
139 tskIDLE_PRIORITY, &xCreatedTask ) != pdPASS )
\r
141 xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );
\r
144 /* Delay until it is time to execute again. */
\r
145 vTaskDelay( mainCHECK_PERIOD );
\r
147 /* Delete the dynamically created task. */
\r
148 if( xCreatedTask != mainNO_TASK )
\r
150 vTaskDelete( xCreatedTask );
\r
153 if( prvCheckOtherTasksAreStillRunning( ulMemCheckTaskRunningCount ) !=
\r
156 xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );
\r
160 xSerialPutChar( xSTDComPort, '.', portMAX_DELAY );
\r
166 prvCheckOtherTasksAreStillRunning( unsigned portLONG ulMemCheckTaskCount )
\r
168 portLONG lReturn = ( portLONG ) pdPASS;
\r
170 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
171 * that they are all still running, and that none of them have detected
\r
175 if( xAreIntegerMathsTaskStillRunning( ) != pdTRUE )
\r
177 lReturn = ( portLONG ) pdFAIL;
\r
180 if( xArePollingQueuesStillRunning( ) != pdTRUE )
\r
182 lReturn = ( portLONG ) pdFAIL;
\r
185 if( xAreMathsTaskStillRunning( ) != pdTRUE )
\r
187 lReturn = ( portLONG ) pdFAIL;
\r
190 if( xAreSemaphoreTasksStillRunning( ) != pdTRUE )
\r
192 lReturn = ( portLONG ) pdFAIL;
\r
195 if( xAreDynamicPriorityTasksStillRunning( ) != pdTRUE )
\r
197 lReturn = ( portLONG ) pdFAIL;
\r
200 if( xAreBlockingQueuesStillRunning( ) != pdTRUE )
\r
202 lReturn = ( portLONG ) pdFAIL;
\r
204 if( ulMemCheckTaskCount == mainCOUNT_INITIAL_VALUE )
\r
206 // The vMemCheckTask did not increment the counter - it must
\r
208 lReturn = ( portLONG ) pdFAIL;
\r
214 vMemCheckTask( void *pvParameters )
\r
216 unsigned portLONG *pulMemCheckTaskRunningCounter;
\r
217 void *pvMem1, *pvMem2, *pvMem3;
\r
218 static portLONG lErrorOccurred = pdFALSE;
\r
220 /* This task is dynamically created then deleted during each cycle of the
\r
221 vErrorChecks task to check the operation of the memory allocator. Each time
\r
222 the task is created memory is allocated for the stack and TCB. Each time
\r
223 the task is deleted this memory is returned to the heap. This task itself
\r
224 exercises the allocator by allocating and freeing blocks.
\r
226 The task executes at the idle priority so does not require a delay.
\r
228 pulMemCheckTaskRunningCounter is incremented each cycle to indicate to the
\r
229 vErrorChecks() task that this task is still executing without error. */
\r
231 pulMemCheckTaskRunningCounter = ( unsigned portLONG * )pvParameters;
\r
235 if( lErrorOccurred == pdFALSE )
\r
237 /* We have never seen an error so increment the counter. */
\r
238 ( *pulMemCheckTaskRunningCounter )++;
\r
241 /* Allocate some memory - just to give the allocator some extra
\r
242 exercise. This has to be in a critical section to ensure the
\r
243 task does not get deleted while it has memory allocated. */
\r
244 vTaskSuspendAll( );
\r
246 pvMem1 = pvPortMalloc( mainMEM_CHECK_SIZE_1 );
\r
247 if( pvMem1 == NULL )
\r
249 lErrorOccurred = pdTRUE;
\r
253 memset( pvMem1, 0xaa, mainMEM_CHECK_SIZE_1 );
\r
254 vPortFree( pvMem1 );
\r
259 /* Again - with a different size block. */
\r
260 vTaskSuspendAll( );
\r
262 pvMem2 = pvPortMalloc( mainMEM_CHECK_SIZE_2 );
\r
263 if( pvMem2 == NULL )
\r
265 lErrorOccurred = pdTRUE;
\r
269 memset( pvMem2, 0xaa, mainMEM_CHECK_SIZE_2 );
\r
270 vPortFree( pvMem2 );
\r
275 /* Again - with a different size block. */
\r
276 vTaskSuspendAll( );
\r
278 pvMem3 = pvPortMalloc( mainMEM_CHECK_SIZE_3 );
\r
279 if( pvMem3 == NULL )
\r
281 lErrorOccurred = pdTRUE;
\r
285 memset( pvMem3, 0xaa, mainMEM_CHECK_SIZE_3 );
\r
286 vPortFree( pvMem3 );
\r
294 vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
\r
299 vParTestToggleLED( unsigned portBASE_TYPE uxLED )
\r