]> git.sur5r.net Git - freertos/blob - Demo/MCF5235_GCC/demo.c
Add PIC24, dsPIC and Coldfire files.
[freertos] / Demo / MCF5235_GCC / demo.c
1 /*
2     FreeRTOS V4.1.0 - Copyright (C) 2003-2006 Richard Barry.
3     MCF5235 Port - Copyright (C) 2006 Christian Walter.
4
5     This file is part of the FreeRTOS distribution.
6
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.
11
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.
16
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
20
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
25     can be applied.
26
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     ***************************************************************************
32 */
33
34 /* ------------------------ System includes ------------------------------- */
35 #include <stdlib.h>
36 #include <string.h>
37
38 /* ------------------------ FreeRTOS includes ----------------------------- */
39 #include "FreeRTOS.h"
40 #include "task.h"
41
42 /* ------------------------ Demo application includes --------------------- */
43 #include "partest.h"
44 #include "flash.h"
45 #include "integer.h"
46 #include "PollQ.h"
47 #include "comtest2.h"
48 #include "semtest.h"
49 #include "flop.h"
50 #include "dynamic.h"
51 #include "BlockQ.h"
52 #include "serial.h"
53
54 /* ------------------------ Defines --------------------------------------- */
55 /* Constants for the ComTest tasks. */
56 #define mainCOM_TEST_BAUD_RATE  ( ( unsigned portLONG ) 38400 )
57 #define mainCOM_TEST_LED        ( -1 )
58
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 )
66
67 /* Interval in which tasks are checked. */
68 #define mainCHECK_PERIOD            ( ( portTickType ) 2000 / portTICK_RATE_MS  )
69
70 /* Constants used by the vMemCheckTask() task. */
71 #define mainCOUNT_INITIAL_VALUE     ( ( unsigned portLONG ) 0 )
72 #define mainNO_TASK                 ( 0 )
73
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 )
78
79 /* ------------------------ Static variables ------------------------------ */
80 xComPortHandle  xSTDComPort = NULL;
81
82 /* ------------------------ Static functions ------------------------------ */
83 static          portTASK_FUNCTION( vErrorChecks, pvParameters );
84 static portLONG prvCheckOtherTasksAreStillRunning( unsigned portLONG
85                                                    ulMemCheckTaskCount );
86 static          portTASK_FUNCTION( vMemCheckTask, pvParameters );
87
88 /* ------------------------ Implementation -------------------------------- */
89 int
90 main( int argc, char *argv[] )
91 {
92     asm volatile    ( "move.w  #0x2000, %sr\n\t" );
93
94     xSTDComPort = xSerialPortInitMinimal( 38400, 8 );
95
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 );
103
104     /* Start the check task - which is defined in this file. */
105     xTaskCreate( vErrorChecks, ( signed portCHAR * )"Check", 512, NULL,
106                  mainCHECK_TASK_PRIORITY, NULL );
107
108     /* Now all the tasks have been started - start the scheduler. */
109     vTaskStartScheduler(  );
110
111     /* Should never get here! */
112     return 0;
113 }
114
115
116
117 static
118 portTASK_FUNCTION( vErrorChecks, pvParameters )
119 {
120     unsigned portLONG ulMemCheckTaskRunningCount;
121     xTaskHandle     xCreatedTask;
122
123     /* The parameters are not used in this function. */
124     ( void )pvParameters;
125
126     xSerialPortInitMinimal( mainCOM_TEST_BAUD_RATE, 8 );
127
128     for( ;; )
129     {
130         ulMemCheckTaskRunningCount = mainCOUNT_INITIAL_VALUE;
131         xCreatedTask = mainNO_TASK;
132
133         if( xTaskCreate
134             ( vMemCheckTask, ( signed portCHAR * )"MEM_CHECK",
135               configMINIMAL_STACK_SIZE, ( void * )&ulMemCheckTaskRunningCount,
136               tskIDLE_PRIORITY, &xCreatedTask ) != pdPASS )
137         {
138             xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );
139         }
140
141         /* Delay until it is time to execute again. */
142         vTaskDelay( mainCHECK_PERIOD );
143
144         /* Delete the dynamically created task. */
145         if( xCreatedTask != mainNO_TASK )
146         {
147             vTaskDelete( xCreatedTask );
148         }
149
150         if( prvCheckOtherTasksAreStillRunning( ulMemCheckTaskRunningCount ) !=
151             pdPASS )
152         {
153             xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );
154         }
155         else
156         {
157             xSerialPutChar( xSTDComPort, '.', portMAX_DELAY );
158         }
159     }
160 }
161
162 static portLONG
163 prvCheckOtherTasksAreStillRunning( unsigned portLONG ulMemCheckTaskCount )
164 {
165     portLONG        lReturn = ( portLONG ) pdPASS;
166
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
169      * an error.
170      */
171
172     if( xAreIntegerMathsTaskStillRunning(  ) != pdTRUE )
173     {
174         lReturn = ( portLONG ) pdFAIL;
175     }
176
177     if( xArePollingQueuesStillRunning(  ) != pdTRUE )
178     {
179         lReturn = ( portLONG ) pdFAIL;
180     }
181
182     if( xAreMathsTaskStillRunning(  ) != pdTRUE )
183     {
184         lReturn = ( portLONG ) pdFAIL;
185     }
186
187     if( xAreSemaphoreTasksStillRunning(  ) != pdTRUE )
188     {
189         lReturn = ( portLONG ) pdFAIL;
190     }
191
192     if( xAreDynamicPriorityTasksStillRunning(  ) != pdTRUE )
193     {
194         lReturn = ( portLONG ) pdFAIL;
195     }
196
197     if( xAreBlockingQueuesStillRunning(  ) != pdTRUE )
198     {
199         lReturn = ( portLONG ) pdFAIL;
200     }
201     if( ulMemCheckTaskCount == mainCOUNT_INITIAL_VALUE )
202     {
203         // The vMemCheckTask did not increment the counter - it must
204         // have failed.
205         lReturn = ( portLONG ) pdFAIL;
206     }
207     return lReturn;
208 }
209
210 static void
211 vMemCheckTask( void *pvParameters )
212 {
213     unsigned portLONG *pulMemCheckTaskRunningCounter;
214     void           *pvMem1, *pvMem2, *pvMem3;
215     static portLONG lErrorOccurred = pdFALSE;
216
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.
222
223        The task executes at the idle priority so does not require a delay.
224
225        pulMemCheckTaskRunningCounter is incremented each cycle to indicate to the
226        vErrorChecks() task that this task is still executing without error. */
227
228     pulMemCheckTaskRunningCounter = ( unsigned portLONG * )pvParameters;
229
230     for( ;; )
231     {
232         if( lErrorOccurred == pdFALSE )
233         {
234             /* We have never seen an error so increment the counter. */
235             ( *pulMemCheckTaskRunningCounter )++;
236         }
237
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. */
241         vTaskSuspendAll(  );
242         {
243             pvMem1 = pvPortMalloc( mainMEM_CHECK_SIZE_1 );
244             if( pvMem1 == NULL )
245             {
246                 lErrorOccurred = pdTRUE;
247             }
248             else
249             {
250                 memset( pvMem1, 0xaa, mainMEM_CHECK_SIZE_1 );
251                 vPortFree( pvMem1 );
252             }
253         }
254         xTaskResumeAll(  );
255
256         /* Again - with a different size block. */
257         vTaskSuspendAll(  );
258         {
259             pvMem2 = pvPortMalloc( mainMEM_CHECK_SIZE_2 );
260             if( pvMem2 == NULL )
261             {
262                 lErrorOccurred = pdTRUE;
263             }
264             else
265             {
266                 memset( pvMem2, 0xaa, mainMEM_CHECK_SIZE_2 );
267                 vPortFree( pvMem2 );
268             }
269         }
270         xTaskResumeAll(  );
271
272         /* Again - with a different size block. */
273         vTaskSuspendAll(  );
274         {
275             pvMem3 = pvPortMalloc( mainMEM_CHECK_SIZE_3 );
276             if( pvMem3 == NULL )
277             {
278                 lErrorOccurred = pdTRUE;
279             }
280             else
281             {
282                 memset( pvMem3, 0xaa, mainMEM_CHECK_SIZE_3 );
283                 vPortFree( pvMem3 );
284             }
285         }
286         xTaskResumeAll(  );
287     }
288 }
289
290 void
291 vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
292 {
293 }
294
295 void
296 vParTestToggleLED( unsigned portBASE_TYPE uxLED )
297 {
298 }