]> git.sur5r.net Git - freertos/blob - Demo/MCF5235_GCC/demo.c
Remove unnecessary use of portLONG, portCHAR and portSHORT.
[freertos] / Demo / MCF5235_GCC / demo.c
1 /*\r
2     FreeRTOS V4.6.1 - Copyright (C) 2003-2006 Richard Barry.\r
3     MCF5235 Port - Copyright (C) 2006 Christian Walter.\r
4 \r
5     This file is part of the FreeRTOS distribution.\r
6 \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
11 \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
16 \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
20 \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
25     can be applied.\r
26 \r
27     ***************************************************************************\r
28     ***************************************************************************\r
29     *                                                                         *\r
30     * Get the FreeRTOS eBook!  See http://www.FreeRTOS.org/Documentation      *\r
31         *                                                                         *\r
32         * This is a concise, step by step, 'hands on' guide that describes both   *\r
33         * general multitasking concepts and FreeRTOS specifics. It presents and   *\r
34         * explains numerous examples that are written using the FreeRTOS API.     *\r
35         * Full source code for all the examples is provided in an accompanying    *\r
36         * .zip file.                                                              *\r
37     *                                                                         *\r
38     ***************************************************************************\r
39     ***************************************************************************\r
40 \r
41         Please ensure to read the configuration and relevant port sections of the\r
42         online documentation.\r
43 \r
44         http://www.FreeRTOS.org - Documentation, latest information, license and \r
45         contact details.\r
46 \r
47         http://www.SafeRTOS.com - A version that is certified for use in safety \r
48         critical systems.\r
49 \r
50         http://www.OpenRTOS.com - Commercial support, development, porting, \r
51         licensing and training services.\r
52 */\r
53 \r
54 /* ------------------------ System includes ------------------------------- */\r
55 #include <stdlib.h>\r
56 #include <string.h>\r
57 \r
58 /* ------------------------ FreeRTOS includes ----------------------------- */\r
59 #include "FreeRTOS.h"\r
60 #include "task.h"\r
61 \r
62 /* ------------------------ Demo application includes --------------------- */\r
63 #include "partest.h"\r
64 #include "flash.h"\r
65 #include "integer.h"\r
66 #include "PollQ.h"\r
67 #include "comtest2.h"\r
68 #include "semtest.h"\r
69 #include "flop.h"\r
70 #include "dynamic.h"\r
71 #include "BlockQ.h"\r
72 #include "serial.h"\r
73 \r
74 /* ------------------------ Defines --------------------------------------- */\r
75 /* Constants for the ComTest tasks. */\r
76 #define mainCOM_TEST_BAUD_RATE  ( ( unsigned long ) 38400 )\r
77 #define mainCOM_TEST_LED        ( -1 )\r
78 \r
79 /* Priorities for the demo application tasks. */\r
80 #define mainLED_TASK_PRIORITY       ( tskIDLE_PRIORITY + 3 )\r
81 #define mainCOM_TEST_PRIORITY       ( tskIDLE_PRIORITY + 2 )\r
82 #define mainQUEUE_POLL_PRIORITY     ( tskIDLE_PRIORITY + 2 )\r
83 #define mainCHECK_TASK_PRIORITY     ( tskIDLE_PRIORITY + 4 )\r
84 #define mainSEM_TEST_PRIORITY       ( tskIDLE_PRIORITY + 1 )\r
85 #define mainBLOCK_Q_PRIORITY        ( tskIDLE_PRIORITY + 2 )\r
86 \r
87 /* Interval in which tasks are checked. */\r
88 #define mainCHECK_PERIOD            ( ( portTickType ) 2000 / portTICK_RATE_MS  )\r
89 \r
90 /* Constants used by the vMemCheckTask() task. */\r
91 #define mainCOUNT_INITIAL_VALUE     ( ( unsigned long ) 0 )\r
92 #define mainNO_TASK                 ( 0 )\r
93 \r
94 /* The size of the memory blocks allocated by the vMemCheckTask() task. */\r
95 #define mainMEM_CHECK_SIZE_1        ( ( size_t ) 51 )\r
96 #define mainMEM_CHECK_SIZE_2        ( ( size_t ) 52 )\r
97 #define mainMEM_CHECK_SIZE_3        ( ( size_t ) 151 )\r
98 \r
99 /* ------------------------ Static variables ------------------------------ */\r
100 xComPortHandle  xSTDComPort = NULL;\r
101 \r
102 /* ------------------------ Static functions ------------------------------ */\r
103 static          portTASK_FUNCTION( vErrorChecks, pvParameters );\r
104 static long prvCheckOtherTasksAreStillRunning( unsigned long\r
105                                                    ulMemCheckTaskCount );\r
106 static          portTASK_FUNCTION( vMemCheckTask, pvParameters );\r
107 \r
108 /* ------------------------ Implementation -------------------------------- */\r
109 int\r
110 main( int argc, char *argv[] )\r
111 {\r
112     asm volatile    ( "move.w  #0x2000, %sr\n\t" );\r
113 \r
114     xSTDComPort = xSerialPortInitMinimal( 38400, 8 );\r
115 \r
116     /* Start the demo/test application tasks. */\r
117     vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
118     vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
119     vStartMathTasks( tskIDLE_PRIORITY );\r
120     vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
121     vStartDynamicPriorityTasks(  );\r
122     vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
123 \r
124     /* Start the check task - which is defined in this file. */\r
125     xTaskCreate( vErrorChecks, ( signed char * )"Check", 512, NULL,\r
126                  mainCHECK_TASK_PRIORITY, NULL );\r
127 \r
128     /* Now all the tasks have been started - start the scheduler. */\r
129     vTaskStartScheduler(  );\r
130 \r
131     /* Should never get here! */\r
132     return 0;\r
133 }\r
134 \r
135 \r
136 \r
137 static\r
138 portTASK_FUNCTION( vErrorChecks, pvParameters )\r
139 {\r
140     unsigned long ulMemCheckTaskRunningCount;\r
141     xTaskHandle     xCreatedTask;\r
142 \r
143     /* The parameters are not used in this function. */\r
144     ( void )pvParameters;\r
145 \r
146     xSerialPortInitMinimal( mainCOM_TEST_BAUD_RATE, 8 );\r
147 \r
148     for( ;; )\r
149     {\r
150         ulMemCheckTaskRunningCount = mainCOUNT_INITIAL_VALUE;\r
151         xCreatedTask = mainNO_TASK;\r
152 \r
153         if( xTaskCreate\r
154             ( vMemCheckTask, ( signed char * )"MEM_CHECK",\r
155               configMINIMAL_STACK_SIZE, ( void * )&ulMemCheckTaskRunningCount,\r
156               tskIDLE_PRIORITY, &xCreatedTask ) != pdPASS )\r
157         {\r
158             xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );\r
159         }\r
160 \r
161         /* Delay until it is time to execute again. */\r
162         vTaskDelay( mainCHECK_PERIOD );\r
163 \r
164         /* Delete the dynamically created task. */\r
165         if( xCreatedTask != mainNO_TASK )\r
166         {\r
167             vTaskDelete( xCreatedTask );\r
168         }\r
169 \r
170         if( prvCheckOtherTasksAreStillRunning( ulMemCheckTaskRunningCount ) !=\r
171             pdPASS )\r
172         {\r
173             xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );\r
174         }\r
175         else\r
176         {\r
177             xSerialPutChar( xSTDComPort, '.', portMAX_DELAY );\r
178         }\r
179     }\r
180 }\r
181 \r
182 static long\r
183 prvCheckOtherTasksAreStillRunning( unsigned long ulMemCheckTaskCount )\r
184 {\r
185     long        lReturn = ( long ) pdPASS;\r
186 \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
189      * an error.\r
190      */\r
191 \r
192     if( xAreIntegerMathsTaskStillRunning(  ) != pdTRUE )\r
193     {\r
194         lReturn = ( long ) pdFAIL;\r
195     }\r
196 \r
197     if( xArePollingQueuesStillRunning(  ) != pdTRUE )\r
198     {\r
199         lReturn = ( long ) pdFAIL;\r
200     }\r
201 \r
202     if( xAreMathsTaskStillRunning(  ) != pdTRUE )\r
203     {\r
204         lReturn = ( long ) pdFAIL;\r
205     }\r
206 \r
207     if( xAreSemaphoreTasksStillRunning(  ) != pdTRUE )\r
208     {\r
209         lReturn = ( long ) pdFAIL;\r
210     }\r
211 \r
212     if( xAreDynamicPriorityTasksStillRunning(  ) != pdTRUE )\r
213     {\r
214         lReturn = ( long ) pdFAIL;\r
215     }\r
216 \r
217     if( xAreBlockingQueuesStillRunning(  ) != pdTRUE )\r
218     {\r
219         lReturn = ( long ) pdFAIL;\r
220     }\r
221     if( ulMemCheckTaskCount == mainCOUNT_INITIAL_VALUE )\r
222     {\r
223         // The vMemCheckTask did not increment the counter - it must\r
224         // have failed.\r
225         lReturn = ( long ) pdFAIL;\r
226     }\r
227     return lReturn;\r
228 }\r
229 \r
230 static void\r
231 vMemCheckTask( void *pvParameters )\r
232 {\r
233     unsigned long *pulMemCheckTaskRunningCounter;\r
234     void           *pvMem1, *pvMem2, *pvMem3;\r
235     static long lErrorOccurred = pdFALSE;\r
236 \r
237     /* This task is dynamically created then deleted during each cycle of the\r
238        vErrorChecks task to check the operation of the memory allocator.  Each time\r
239        the task is created memory is allocated for the stack and TCB.  Each time\r
240        the task is deleted this memory is returned to the heap.  This task itself\r
241        exercises the allocator by allocating and freeing blocks.\r
242 \r
243        The task executes at the idle priority so does not require a delay.\r
244 \r
245        pulMemCheckTaskRunningCounter is incremented each cycle to indicate to the\r
246        vErrorChecks() task that this task is still executing without error. */\r
247 \r
248     pulMemCheckTaskRunningCounter = ( unsigned long * )pvParameters;\r
249 \r
250     for( ;; )\r
251     {\r
252         if( lErrorOccurred == pdFALSE )\r
253         {\r
254             /* We have never seen an error so increment the counter. */\r
255             ( *pulMemCheckTaskRunningCounter )++;\r
256         }\r
257 \r
258         /* Allocate some memory - just to give the allocator some extra\r
259            exercise.  This has to be in a critical section to ensure the\r
260            task does not get deleted while it has memory allocated. */\r
261         vTaskSuspendAll(  );\r
262         {\r
263             pvMem1 = pvPortMalloc( mainMEM_CHECK_SIZE_1 );\r
264             if( pvMem1 == NULL )\r
265             {\r
266                 lErrorOccurred = pdTRUE;\r
267             }\r
268             else\r
269             {\r
270                 memset( pvMem1, 0xaa, mainMEM_CHECK_SIZE_1 );\r
271                 vPortFree( pvMem1 );\r
272             }\r
273         }\r
274         xTaskResumeAll(  );\r
275 \r
276         /* Again - with a different size block. */\r
277         vTaskSuspendAll(  );\r
278         {\r
279             pvMem2 = pvPortMalloc( mainMEM_CHECK_SIZE_2 );\r
280             if( pvMem2 == NULL )\r
281             {\r
282                 lErrorOccurred = pdTRUE;\r
283             }\r
284             else\r
285             {\r
286                 memset( pvMem2, 0xaa, mainMEM_CHECK_SIZE_2 );\r
287                 vPortFree( pvMem2 );\r
288             }\r
289         }\r
290         xTaskResumeAll(  );\r
291 \r
292         /* Again - with a different size block. */\r
293         vTaskSuspendAll(  );\r
294         {\r
295             pvMem3 = pvPortMalloc( mainMEM_CHECK_SIZE_3 );\r
296             if( pvMem3 == NULL )\r
297             {\r
298                 lErrorOccurred = pdTRUE;\r
299             }\r
300             else\r
301             {\r
302                 memset( pvMem3, 0xaa, mainMEM_CHECK_SIZE_3 );\r
303                 vPortFree( pvMem3 );\r
304             }\r
305         }\r
306         xTaskResumeAll(  );\r
307     }\r
308 }\r
309 \r
310 void\r
311 vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )\r
312 {\r
313 }\r
314 \r
315 void\r
316 vParTestToggleLED( unsigned portBASE_TYPE uxLED )\r
317 {\r
318 }\r