]> begriffs open source - cmsis-freertos/blob - Demo/ColdFire_MCF52259_CodeWarrior/main.c
Update cmsis_os2.c
[cmsis-freertos] / Demo / ColdFire_MCF52259_CodeWarrior / main.c
1 /*
2     FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
3     All rights reserved
4
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6
7     This file is part of the FreeRTOS distribution.
8
9     FreeRTOS is free software; you can redistribute it and/or modify it under
10     the terms of the GNU General Public License (version 2) as published by the
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
12
13     ***************************************************************************
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<
16     >>!   obliged to provide the source code for proprietary components     !<<
17     >>!   outside of the FreeRTOS kernel.                                   !<<
18     ***************************************************************************
19
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following
23     link: http://www.freertos.org/a00114.html
24
25     ***************************************************************************
26      *                                                                       *
27      *    FreeRTOS provides completely free yet professionally developed,    *
28      *    robust, strictly quality controlled, supported, and cross          *
29      *    platform software that is more than just the market leader, it     *
30      *    is the industry's de facto standard.                               *
31      *                                                                       *
32      *    Help yourself get started quickly while simultaneously helping     *
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *
34      *    tutorial book, reference manual, or both:                          *
35      *    http://www.FreeRTOS.org/Documentation                              *
36      *                                                                       *
37     ***************************************************************************
38
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading
40     the FAQ page "My application does not run, what could be wrong?".  Have you
41     defined configASSERT()?
42
43     http://www.FreeRTOS.org/support - In return for receiving this top quality
44     embedded software for free we request you assist our global community by
45     participating in the support forum.
46
47     http://www.FreeRTOS.org/training - Investing in training allows your team to
48     be as productive as possible as early as possible.  Now you can receive
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50     Ltd, and the world's leading authority on the world's leading RTOS.
51
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.
55
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
58
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS
61     licenses offer ticketed support, indemnification and commercial middleware.
62
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64     engineered and independently SIL3 certified version for use in safety and
65     mission critical applications that require provable dependability.
66
67     1 tab == 4 spaces!
68 */
69
70
71 /*
72  * Creates all the demo application tasks, then starts the scheduler.  The WEB
73  * documentation provides more details of the standard demo application tasks.
74  * In addition to the standard demo tasks, the following tasks and tests are
75  * defined and/or created within this file:
76  *
77  * "Web server" - Very basic demonstration of the lwIP stack.  The WEB server
78  * simply generates a page that shows the current state of all the tasks within
79  * the system, including the high water mark of each task stack. The high water
80  * mark is displayed as the amount of stack that has never been used, so the
81  * closer the value is to zero the closer the task has come to overflowing its
82  * stack.  The IP address and net mask are set within FreeRTOSConfig.h.
83  *
84  * "Check" task -  This only executes every five seconds but has a high priority
85  * to ensure it gets processor time.  Its main function is to check that all the
86  * standard demo tasks are still operational.  While no errors have been
87  * discovered the check task will toggle an LED every 5 seconds - the toggle
88  * rate increasing to 500ms being a visual indication that at least one task has
89  * reported unexpected behaviour.
90  *
91  * "Reg test" tasks - These fill the registers with known values, then check
92  * that each register still contains its expected value.  Each task uses
93  * different values.  The tasks run with very low priority so get preempted very
94  * frequently.  A register containing an unexpected value is indicative of an
95  * error in the context switching mechanism.
96  *
97  */
98
99 /* Standard includes. */
100 #include <stdio.h>
101
102 /* Scheduler includes. */
103 #include "FreeRTOS.h"
104 #include "task.h"
105 #include "queue.h"
106 #include "semphr.h"
107
108 /* Demo app includes. */
109 #include "BlockQ.h"
110 #include "death.h"
111 #include "flash.h"
112 #include "partest.h"
113 #include "semtest.h"
114 #include "PollQ.h"
115 #include "GenQTest.h"
116 #include "QPeek.h"
117 #include "recmutex.h"
118
119 /*-----------------------------------------------------------*/
120
121 /* The time between cycles of the 'check' functionality - as described at the
122 top of this file. */
123 #define mainNO_ERROR_PERIOD                                     ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )
124
125 /* The rate at which the LED controlled by the 'check' task will flash should an
126 error have been detected. */
127 #define mainERROR_PERIOD                                        ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
128
129 /* The LED controlled by the 'check' task. */
130 #define mainCHECK_LED                                           ( 3 )
131
132 /* ComTest constants - there is no free LED for the comtest tasks. */
133 #define mainCOM_TEST_BAUD_RATE                          ( ( unsigned long ) 19200 )
134 #define mainCOM_TEST_LED                                        ( 5 )
135
136 /* Task priorities. */
137 #define mainCOM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 2 )
138 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )
139 #define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )
140 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )
141 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )
142 #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )
143 #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )
144 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )
145 #define mainWEB_TASK_PRIORITY                   ( tskIDLE_PRIORITY + 2 )
146
147 /*
148  * Configure the hardware for the demo.
149  */
150 static void prvSetupHardware( void );
151
152 /*
153  * Implements the 'check' task functionality as described at the top of this
154  * file.
155  */
156 static void prvCheckTask( void *pvParameters );
157
158 /*
159  * Implement the 'Reg test' functionality as described at the top of this file.
160  */
161 static void vRegTest1Task( void *pvParameters );
162 static void vRegTest2Task( void *pvParameters );
163
164 /*-----------------------------------------------------------*/
165
166 /* Counters used to detect errors within the reg test tasks. */
167 static volatile unsigned long ulRegTest1Counter = 0x11111111, ulRegTest2Counter = 0x22222222;
168
169 /*-----------------------------------------------------------*/
170
171 int main( void )
172 {
173 extern void vBasicWEBServer( void *pv );
174
175         /* Setup the hardware ready for this demo. */
176         prvSetupHardware();
177         ( void )sys_thread_new("HTTPD", vBasicWEBServer, NULL, 320, mainWEB_TASK_PRIORITY );
178
179         /* Start the standard demo tasks. */
180         vStartLEDFlashTasks( tskIDLE_PRIORITY );
181         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
182         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
183         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
184         vStartQueuePeekTasks();
185         vStartRecursiveMutexTasks();
186         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
187
188         /* Start the reg test tasks - defined in this file. */
189         xTaskCreate( vRegTest1Task, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest1Counter, tskIDLE_PRIORITY, NULL );
190         xTaskCreate( vRegTest2Task, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest2Counter, tskIDLE_PRIORITY, NULL );
191
192         /* Create the check task. */
193         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
194
195         /* The suicide tasks must be created last as they need to know how many
196         tasks were running prior to their creation in order to ascertain whether
197         or not the correct/expected number of tasks are running at any given time. */
198     vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
199
200         /* Start the scheduler. */
201         vTaskStartScheduler();
202
203     /* Will only get here if there was insufficient memory to create the idle
204     task. */
205         for( ;; )
206         {
207         }
208 }
209 /*-----------------------------------------------------------*/
210
211 static void prvCheckTask( void *pvParameters )
212 {
213 unsigned ulTicksToWait = mainNO_ERROR_PERIOD, ulError = 0, ulLastRegTest1Count = 0, ulLastRegTest2Count = 0;
214 TickType_t xLastExecutionTime;
215
216         ( void ) pvParameters;
217
218         /* Initialise the variable used to control our iteration rate prior to
219         its first use. */
220         xLastExecutionTime = xTaskGetTickCount();
221
222         for( ;; )
223         {
224                 /* Wait until it is time to run the tests again. */
225                 vTaskDelayUntil( &xLastExecutionTime, ulTicksToWait );
226
227                 /* Has an error been found in any task? */
228                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
229                 {
230                         ulError |= 0x01UL;
231                 }
232
233                 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
234                 {
235                         ulError |= 0x02UL;
236                 }
237
238                 if( xAreBlockingQueuesStillRunning() != pdTRUE )
239                 {
240                         ulError |= 0x04UL;
241                 }
242
243                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
244             {
245                 ulError |= 0x20UL;
246             }
247
248                 if( xArePollingQueuesStillRunning() != pdTRUE )
249             {
250                 ulError |= 0x40UL;
251             }
252
253                 if( xIsCreateTaskStillRunning() != pdTRUE )
254             {
255                 ulError |= 0x80UL;
256             }
257
258                 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
259             {
260                 ulError |= 0x200UL;
261             }
262
263                 if( ulLastRegTest1Count == ulRegTest1Counter )
264                 {
265                         ulError |= 0x1000UL;
266                 }
267
268                 if( ulLastRegTest2Count == ulRegTest2Counter )
269                 {
270                         ulError |= 0x1000UL;
271                 }
272
273                 ulLastRegTest1Count = ulRegTest1Counter;
274                 ulLastRegTest2Count = ulRegTest2Counter;
275
276                 /* If an error has been found then increase our cycle rate, and in so
277                 going increase the rate at which the check task LED toggles. */
278                 if( ulError != 0 )
279                 {
280                 ulTicksToWait = mainERROR_PERIOD;
281                 }
282
283                 /* Toggle the LED each iteration. */
284                 vParTestToggleLED( mainCHECK_LED );
285         }
286 }
287 /*-----------------------------------------------------------*/
288
289 void prvSetupHardware( void )
290 {
291         portDISABLE_INTERRUPTS();
292
293         /* Setup the port used to toggle LEDs. */
294         vParTestInitialise();
295 }
296 /*-----------------------------------------------------------*/
297
298 void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName )
299 {
300         /* This will get called if a stack overflow is detected during the context
301         switch.  Set configCHECK_FOR_STACK_OVERFLOWS to 2 to also check for stack
302         problems within nested interrupts, but only do this for debug purposes as
303         it will increase the context switch time. */
304
305         ( void ) pxTask;
306         ( void ) pcTaskName;
307
308         for( ;; )
309         {
310         }
311 }
312 /*-----------------------------------------------------------*/
313
314 static void vRegTest1Task( void *pvParameters )
315 {
316         /* Sanity check - did we receive the parameter expected? */
317         if( pvParameters != &ulRegTest1Counter )
318         {
319                 /* Change here so the check task can detect that an error occurred. */
320                 for( ;; )
321                 {
322                 }
323         }
324
325         /* Set all the registers to known values, then check that each retains its
326         expected value - as described at the top of this file.  If an error is
327         found then the loop counter will no longer be incremented allowing the check
328         task to recognise the error. */
329         asm volatile    (       "reg_test_1_start:                                              \n\t"
330                                                 "       moveq           #1, d0                                  \n\t"
331                                                 "       moveq           #2, d1                                  \n\t"
332                                                 "       moveq           #3, d2                                  \n\t"
333                                                 "       moveq           #4, d3                                  \n\t"
334                                                 "       moveq           #5, d4                                  \n\t"
335                                                 "       moveq           #6, d5                                  \n\t"
336                                                 "       moveq           #7, d6                                  \n\t"
337                                                 "       moveq           #8, d7                                  \n\t"
338                                                 "       move            #9, a0                                  \n\t"
339                                                 "       move            #10, a1                                 \n\t"
340                                                 "       move            #11, a2                                 \n\t"
341                                                 "       move            #12, a3                                 \n\t"
342                                                 "       move            #13, a4                                 \n\t"
343                                                 "       move            #14, a5                                 \n\t"
344                                                 "       move            #15, a6                                 \n\t"
345                                                 "                                                                               \n\t"
346                                                 "       cmpi.l          #1, d0                                  \n\t"
347                                                 "       bne                     reg_test_1_error                \n\t"
348                                                 "       cmpi.l          #2, d1                                  \n\t"
349                                                 "       bne                     reg_test_1_error                \n\t"
350                                                 "       cmpi.l          #3, d2                                  \n\t"
351                                                 "       bne                     reg_test_1_error                \n\t"
352                                                 "       cmpi.l          #4, d3                                  \n\t"
353                                                 "       bne                     reg_test_1_error                \n\t"
354                                                 "       cmpi.l          #5, d4                                  \n\t"
355                                                 "       bne                     reg_test_1_error                \n\t"
356                                                 "       cmpi.l          #6, d5                                  \n\t"
357                                                 "       bne                     reg_test_1_error                \n\t"
358                                                 "       cmpi.l          #7, d6                                  \n\t"
359                                                 "       bne                     reg_test_1_error                \n\t"
360                                                 "       cmpi.l          #8, d7                                  \n\t"
361                                                 "       bne                     reg_test_1_error                \n\t"
362                                                 "       move            a0, d0                                  \n\t"
363                                                 "       cmpi.l          #9, d0                                  \n\t"
364                                                 "       bne                     reg_test_1_error                \n\t"
365                                                 "       move            a1, d0                                  \n\t"
366                                                 "       cmpi.l          #10, d0                                 \n\t"
367                                                 "       bne                     reg_test_1_error                \n\t"
368                                                 "       move            a2, d0                                  \n\t"
369                                                 "       cmpi.l          #11, d0                                 \n\t"
370                                                 "       bne                     reg_test_1_error                \n\t"
371                                                 "       move            a3, d0                                  \n\t"
372                                                 "       cmpi.l          #12, d0                                 \n\t"
373                                                 "       bne                     reg_test_1_error                \n\t"
374                                                 "       move            a4, d0                                  \n\t"
375                                                 "       cmpi.l          #13, d0                                 \n\t"
376                                                 "       bne                     reg_test_1_error                \n\t"
377                                                 "       move            a5, d0                                  \n\t"
378                                                 "       cmpi.l          #14, d0                                 \n\t"
379                                                 "       bne                     reg_test_1_error                \n\t"
380                                                 "       move            a6, d0                                  \n\t"
381                                                 "       cmpi.l          #15, d0                                 \n\t"
382                                                 "       bne                     reg_test_1_error                \n\t"
383                                                 "       move            ulRegTest1Counter, d0   \n\t"
384                                                 "       addq            #1, d0                                  \n\t"
385                                                 "       move            d0, ulRegTest1Counter   \n\t"
386                                                 "       bra                     reg_test_1_start                \n\t"
387                                                 "reg_test_1_error:                                              \n\t"
388                                                 "       bra                     reg_test_1_error                \n\t"
389                                         );
390 }
391 /*-----------------------------------------------------------*/
392
393 static void vRegTest2Task( void *pvParameters )
394 {
395         /* Sanity check - did we receive the parameter expected? */
396         if( pvParameters != &ulRegTest2Counter )
397         {
398                 /* Change here so the check task can detect that an error occurred. */
399                 for( ;; )
400                 {
401                 }
402         }
403
404         /* Set all the registers to known values, then check that each retains its
405         expected value - as described at the top of this file.  If an error is
406         found then the loop counter will no longer be incremented allowing the check
407         task to recognise the error. */
408         asm volatile    (       "reg_test_2_start:                                              \n\t"
409                                                 "       moveq           #10, d0                                 \n\t"
410                                                 "       moveq           #20, d1                                 \n\t"
411                                                 "       moveq           #30, d2                                 \n\t"
412                                                 "       moveq           #40, d3                                 \n\t"
413                                                 "       moveq           #50, d4                                 \n\t"
414                                                 "       moveq           #60, d5                                 \n\t"
415                                                 "       moveq           #70, d6                                 \n\t"
416                                                 "       moveq           #80, d7                                 \n\t"
417                                                 "       move            #90, a0                                 \n\t"
418                                                 "       move            #100, a1                                \n\t"
419                                                 "       move            #110, a2                                \n\t"
420                                                 "       move            #120, a3                                \n\t"
421                                                 "       move            #130, a4                                \n\t"
422                                                 "       move            #140, a5                                \n\t"
423                                                 "       move            #150, a6                                \n\t"
424                                                 "                                                                               \n\t"
425                                                 "       cmpi.l          #10, d0                                 \n\t"
426                                                 "       bne                     reg_test_2_error                \n\t"
427                                                 "       cmpi.l          #20, d1                                 \n\t"
428                                                 "       bne                     reg_test_2_error                \n\t"
429                                                 "       cmpi.l          #30, d2                                 \n\t"
430                                                 "       bne                     reg_test_2_error                \n\t"
431                                                 "       cmpi.l          #40, d3                                 \n\t"
432                                                 "       bne                     reg_test_2_error                \n\t"
433                                                 "       cmpi.l          #50, d4                                 \n\t"
434                                                 "       bne                     reg_test_2_error                \n\t"
435                                                 "       cmpi.l          #60, d5                                 \n\t"
436                                                 "       bne                     reg_test_2_error                \n\t"
437                                                 "       cmpi.l          #70, d6                                 \n\t"
438                                                 "       bne                     reg_test_2_error                \n\t"
439                                                 "       cmpi.l          #80, d7                                 \n\t"
440                                                 "       bne                     reg_test_2_error                \n\t"
441                                                 "       move            a0, d0                                  \n\t"
442                                                 "       cmpi.l          #90, d0                                 \n\t"
443                                                 "       bne                     reg_test_2_error                \n\t"
444                                                 "       move            a1, d0                                  \n\t"
445                                                 "       cmpi.l          #100, d0                                \n\t"
446                                                 "       bne                     reg_test_2_error                \n\t"
447                                                 "       move            a2, d0                                  \n\t"
448                                                 "       cmpi.l          #110, d0                                \n\t"
449                                                 "       bne                     reg_test_2_error                \n\t"
450                                                 "       move            a3, d0                                  \n\t"
451                                                 "       cmpi.l          #120, d0                                \n\t"
452                                                 "       bne                     reg_test_2_error                \n\t"
453                                                 "       move            a4, d0                                  \n\t"
454                                                 "       cmpi.l          #130, d0                                \n\t"
455                                                 "       bne                     reg_test_2_error                \n\t"
456                                                 "       move            a5, d0                                  \n\t"
457                                                 "       cmpi.l          #140, d0                                \n\t"
458                                                 "       bne                     reg_test_2_error                \n\t"
459                                                 "       move            a6, d0                                  \n\t"
460                                                 "       cmpi.l          #150, d0                                \n\t"
461                                                 "       bne                     reg_test_2_error                \n\t"
462                                                 "       move            ulRegTest1Counter, d0   \n\t"
463                                                 "       addq            #1, d0                                  \n\t"
464                                                 "       move            d0, ulRegTest2Counter   \n\t"
465                                                 "       bra                     reg_test_2_start                \n\t"
466                                                 "reg_test_2_error:                                              \n\t"
467                                                 "       bra                     reg_test_2_error                \n\t"
468                                         );
469 }
470 /*-----------------------------------------------------------*/
471
472
473