]> begriffs open source - cmsis-freertos/blob - Demo/ColdFire_MCF52259_CodeWarrior/main.c
Updated to FreeRTOS V10.0.1
[cmsis-freertos] / Demo / ColdFire_MCF52259_CodeWarrior / main.c
1 /*
2  * FreeRTOS Kernel V10.0.1
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * http://www.FreeRTOS.org
23  * http://aws.amazon.com/freertos
24  *
25  * 1 tab == 4 spaces!
26  */
27
28
29 /*
30  * Creates all the demo application tasks, then starts the scheduler.  The WEB
31  * documentation provides more details of the standard demo application tasks.
32  * In addition to the standard demo tasks, the following tasks and tests are
33  * defined and/or created within this file:
34  *
35  * "Web server" - Very basic demonstration of the lwIP stack.  The WEB server
36  * simply generates a page that shows the current state of all the tasks within
37  * the system, including the high water mark of each task stack. The high water
38  * mark is displayed as the amount of stack that has never been used, so the
39  * closer the value is to zero the closer the task has come to overflowing its
40  * stack.  The IP address and net mask are set within FreeRTOSConfig.h.
41  *
42  * "Check" task -  This only executes every five seconds but has a high priority
43  * to ensure it gets processor time.  Its main function is to check that all the
44  * standard demo tasks are still operational.  While no errors have been
45  * discovered the check task will toggle an LED every 5 seconds - the toggle
46  * rate increasing to 500ms being a visual indication that at least one task has
47  * reported unexpected behaviour.
48  *
49  * "Reg test" tasks - These fill the registers with known values, then check
50  * that each register still contains its expected value.  Each task uses
51  * different values.  The tasks run with very low priority so get preempted very
52  * frequently.  A register containing an unexpected value is indicative of an
53  * error in the context switching mechanism.
54  *
55  */
56
57 /* Standard includes. */
58 #include <stdio.h>
59
60 /* Scheduler includes. */
61 #include "FreeRTOS.h"
62 #include "task.h"
63 #include "queue.h"
64 #include "semphr.h"
65
66 /* Demo app includes. */
67 #include "BlockQ.h"
68 #include "death.h"
69 #include "flash.h"
70 #include "partest.h"
71 #include "semtest.h"
72 #include "PollQ.h"
73 #include "GenQTest.h"
74 #include "QPeek.h"
75 #include "recmutex.h"
76
77 /*-----------------------------------------------------------*/
78
79 /* The time between cycles of the 'check' functionality - as described at the
80 top of this file. */
81 #define mainNO_ERROR_PERIOD                                     ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )
82
83 /* The rate at which the LED controlled by the 'check' task will flash should an
84 error have been detected. */
85 #define mainERROR_PERIOD                                        ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
86
87 /* The LED controlled by the 'check' task. */
88 #define mainCHECK_LED                                           ( 3 )
89
90 /* ComTest constants - there is no free LED for the comtest tasks. */
91 #define mainCOM_TEST_BAUD_RATE                          ( ( unsigned long ) 19200 )
92 #define mainCOM_TEST_LED                                        ( 5 )
93
94 /* Task priorities. */
95 #define mainCOM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 2 )
96 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )
97 #define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )
98 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )
99 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )
100 #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )
101 #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )
102 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )
103 #define mainWEB_TASK_PRIORITY                   ( tskIDLE_PRIORITY + 2 )
104
105 /*
106  * Configure the hardware for the demo.
107  */
108 static void prvSetupHardware( void );
109
110 /*
111  * Implements the 'check' task functionality as described at the top of this
112  * file.
113  */
114 static void prvCheckTask( void *pvParameters );
115
116 /*
117  * Implement the 'Reg test' functionality as described at the top of this file.
118  */
119 static void vRegTest1Task( void *pvParameters );
120 static void vRegTest2Task( void *pvParameters );
121
122 /*-----------------------------------------------------------*/
123
124 /* Counters used to detect errors within the reg test tasks. */
125 static volatile unsigned long ulRegTest1Counter = 0x11111111, ulRegTest2Counter = 0x22222222;
126
127 /*-----------------------------------------------------------*/
128
129 int main( void )
130 {
131 extern void vBasicWEBServer( void *pv );
132
133         /* Setup the hardware ready for this demo. */
134         prvSetupHardware();
135         ( void )sys_thread_new("HTTPD", vBasicWEBServer, NULL, 320, mainWEB_TASK_PRIORITY );
136
137         /* Start the standard demo tasks. */
138         vStartLEDFlashTasks( tskIDLE_PRIORITY );
139         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
140         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
141         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
142         vStartQueuePeekTasks();
143         vStartRecursiveMutexTasks();
144         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
145
146         /* Start the reg test tasks - defined in this file. */
147         xTaskCreate( vRegTest1Task, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest1Counter, tskIDLE_PRIORITY, NULL );
148         xTaskCreate( vRegTest2Task, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest2Counter, tskIDLE_PRIORITY, NULL );
149
150         /* Create the check task. */
151         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
152
153         /* The suicide tasks must be created last as they need to know how many
154         tasks were running prior to their creation in order to ascertain whether
155         or not the correct/expected number of tasks are running at any given time. */
156     vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
157
158         /* Start the scheduler. */
159         vTaskStartScheduler();
160
161     /* Will only get here if there was insufficient memory to create the idle
162     task. */
163         for( ;; )
164         {
165         }
166 }
167 /*-----------------------------------------------------------*/
168
169 static void prvCheckTask( void *pvParameters )
170 {
171 unsigned ulTicksToWait = mainNO_ERROR_PERIOD, ulError = 0, ulLastRegTest1Count = 0, ulLastRegTest2Count = 0;
172 TickType_t xLastExecutionTime;
173
174         ( void ) pvParameters;
175
176         /* Initialise the variable used to control our iteration rate prior to
177         its first use. */
178         xLastExecutionTime = xTaskGetTickCount();
179
180         for( ;; )
181         {
182                 /* Wait until it is time to run the tests again. */
183                 vTaskDelayUntil( &xLastExecutionTime, ulTicksToWait );
184
185                 /* Has an error been found in any task? */
186                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
187                 {
188                         ulError |= 0x01UL;
189                 }
190
191                 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
192                 {
193                         ulError |= 0x02UL;
194                 }
195
196                 if( xAreBlockingQueuesStillRunning() != pdTRUE )
197                 {
198                         ulError |= 0x04UL;
199                 }
200
201                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
202             {
203                 ulError |= 0x20UL;
204             }
205
206                 if( xArePollingQueuesStillRunning() != pdTRUE )
207             {
208                 ulError |= 0x40UL;
209             }
210
211                 if( xIsCreateTaskStillRunning() != pdTRUE )
212             {
213                 ulError |= 0x80UL;
214             }
215
216                 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
217             {
218                 ulError |= 0x200UL;
219             }
220
221                 if( ulLastRegTest1Count == ulRegTest1Counter )
222                 {
223                         ulError |= 0x1000UL;
224                 }
225
226                 if( ulLastRegTest2Count == ulRegTest2Counter )
227                 {
228                         ulError |= 0x1000UL;
229                 }
230
231                 ulLastRegTest1Count = ulRegTest1Counter;
232                 ulLastRegTest2Count = ulRegTest2Counter;
233
234                 /* If an error has been found then increase our cycle rate, and in so
235                 going increase the rate at which the check task LED toggles. */
236                 if( ulError != 0 )
237                 {
238                 ulTicksToWait = mainERROR_PERIOD;
239                 }
240
241                 /* Toggle the LED each iteration. */
242                 vParTestToggleLED( mainCHECK_LED );
243         }
244 }
245 /*-----------------------------------------------------------*/
246
247 void prvSetupHardware( void )
248 {
249         portDISABLE_INTERRUPTS();
250
251         /* Setup the port used to toggle LEDs. */
252         vParTestInitialise();
253 }
254 /*-----------------------------------------------------------*/
255
256 void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName )
257 {
258         /* This will get called if a stack overflow is detected during the context
259         switch.  Set configCHECK_FOR_STACK_OVERFLOWS to 2 to also check for stack
260         problems within nested interrupts, but only do this for debug purposes as
261         it will increase the context switch time. */
262
263         ( void ) pxTask;
264         ( void ) pcTaskName;
265
266         for( ;; )
267         {
268         }
269 }
270 /*-----------------------------------------------------------*/
271
272 static void vRegTest1Task( void *pvParameters )
273 {
274         /* Sanity check - did we receive the parameter expected? */
275         if( pvParameters != &ulRegTest1Counter )
276         {
277                 /* Change here so the check task can detect that an error occurred. */
278                 for( ;; )
279                 {
280                 }
281         }
282
283         /* Set all the registers to known values, then check that each retains its
284         expected value - as described at the top of this file.  If an error is
285         found then the loop counter will no longer be incremented allowing the check
286         task to recognise the error. */
287         asm volatile    (       "reg_test_1_start:                                              \n\t"
288                                                 "       moveq           #1, d0                                  \n\t"
289                                                 "       moveq           #2, d1                                  \n\t"
290                                                 "       moveq           #3, d2                                  \n\t"
291                                                 "       moveq           #4, d3                                  \n\t"
292                                                 "       moveq           #5, d4                                  \n\t"
293                                                 "       moveq           #6, d5                                  \n\t"
294                                                 "       moveq           #7, d6                                  \n\t"
295                                                 "       moveq           #8, d7                                  \n\t"
296                                                 "       move            #9, a0                                  \n\t"
297                                                 "       move            #10, a1                                 \n\t"
298                                                 "       move            #11, a2                                 \n\t"
299                                                 "       move            #12, a3                                 \n\t"
300                                                 "       move            #13, a4                                 \n\t"
301                                                 "       move            #14, a5                                 \n\t"
302                                                 "       move            #15, a6                                 \n\t"
303                                                 "                                                                               \n\t"
304                                                 "       cmpi.l          #1, d0                                  \n\t"
305                                                 "       bne                     reg_test_1_error                \n\t"
306                                                 "       cmpi.l          #2, d1                                  \n\t"
307                                                 "       bne                     reg_test_1_error                \n\t"
308                                                 "       cmpi.l          #3, d2                                  \n\t"
309                                                 "       bne                     reg_test_1_error                \n\t"
310                                                 "       cmpi.l          #4, d3                                  \n\t"
311                                                 "       bne                     reg_test_1_error                \n\t"
312                                                 "       cmpi.l          #5, d4                                  \n\t"
313                                                 "       bne                     reg_test_1_error                \n\t"
314                                                 "       cmpi.l          #6, d5                                  \n\t"
315                                                 "       bne                     reg_test_1_error                \n\t"
316                                                 "       cmpi.l          #7, d6                                  \n\t"
317                                                 "       bne                     reg_test_1_error                \n\t"
318                                                 "       cmpi.l          #8, d7                                  \n\t"
319                                                 "       bne                     reg_test_1_error                \n\t"
320                                                 "       move            a0, d0                                  \n\t"
321                                                 "       cmpi.l          #9, d0                                  \n\t"
322                                                 "       bne                     reg_test_1_error                \n\t"
323                                                 "       move            a1, d0                                  \n\t"
324                                                 "       cmpi.l          #10, d0                                 \n\t"
325                                                 "       bne                     reg_test_1_error                \n\t"
326                                                 "       move            a2, d0                                  \n\t"
327                                                 "       cmpi.l          #11, d0                                 \n\t"
328                                                 "       bne                     reg_test_1_error                \n\t"
329                                                 "       move            a3, d0                                  \n\t"
330                                                 "       cmpi.l          #12, d0                                 \n\t"
331                                                 "       bne                     reg_test_1_error                \n\t"
332                                                 "       move            a4, d0                                  \n\t"
333                                                 "       cmpi.l          #13, d0                                 \n\t"
334                                                 "       bne                     reg_test_1_error                \n\t"
335                                                 "       move            a5, d0                                  \n\t"
336                                                 "       cmpi.l          #14, d0                                 \n\t"
337                                                 "       bne                     reg_test_1_error                \n\t"
338                                                 "       move            a6, d0                                  \n\t"
339                                                 "       cmpi.l          #15, d0                                 \n\t"
340                                                 "       bne                     reg_test_1_error                \n\t"
341                                                 "       move            ulRegTest1Counter, d0   \n\t"
342                                                 "       addq            #1, d0                                  \n\t"
343                                                 "       move            d0, ulRegTest1Counter   \n\t"
344                                                 "       bra                     reg_test_1_start                \n\t"
345                                                 "reg_test_1_error:                                              \n\t"
346                                                 "       bra                     reg_test_1_error                \n\t"
347                                         );
348 }
349 /*-----------------------------------------------------------*/
350
351 static void vRegTest2Task( void *pvParameters )
352 {
353         /* Sanity check - did we receive the parameter expected? */
354         if( pvParameters != &ulRegTest2Counter )
355         {
356                 /* Change here so the check task can detect that an error occurred. */
357                 for( ;; )
358                 {
359                 }
360         }
361
362         /* Set all the registers to known values, then check that each retains its
363         expected value - as described at the top of this file.  If an error is
364         found then the loop counter will no longer be incremented allowing the check
365         task to recognise the error. */
366         asm volatile    (       "reg_test_2_start:                                              \n\t"
367                                                 "       moveq           #10, d0                                 \n\t"
368                                                 "       moveq           #20, d1                                 \n\t"
369                                                 "       moveq           #30, d2                                 \n\t"
370                                                 "       moveq           #40, d3                                 \n\t"
371                                                 "       moveq           #50, d4                                 \n\t"
372                                                 "       moveq           #60, d5                                 \n\t"
373                                                 "       moveq           #70, d6                                 \n\t"
374                                                 "       moveq           #80, d7                                 \n\t"
375                                                 "       move            #90, a0                                 \n\t"
376                                                 "       move            #100, a1                                \n\t"
377                                                 "       move            #110, a2                                \n\t"
378                                                 "       move            #120, a3                                \n\t"
379                                                 "       move            #130, a4                                \n\t"
380                                                 "       move            #140, a5                                \n\t"
381                                                 "       move            #150, a6                                \n\t"
382                                                 "                                                                               \n\t"
383                                                 "       cmpi.l          #10, d0                                 \n\t"
384                                                 "       bne                     reg_test_2_error                \n\t"
385                                                 "       cmpi.l          #20, d1                                 \n\t"
386                                                 "       bne                     reg_test_2_error                \n\t"
387                                                 "       cmpi.l          #30, d2                                 \n\t"
388                                                 "       bne                     reg_test_2_error                \n\t"
389                                                 "       cmpi.l          #40, d3                                 \n\t"
390                                                 "       bne                     reg_test_2_error                \n\t"
391                                                 "       cmpi.l          #50, d4                                 \n\t"
392                                                 "       bne                     reg_test_2_error                \n\t"
393                                                 "       cmpi.l          #60, d5                                 \n\t"
394                                                 "       bne                     reg_test_2_error                \n\t"
395                                                 "       cmpi.l          #70, d6                                 \n\t"
396                                                 "       bne                     reg_test_2_error                \n\t"
397                                                 "       cmpi.l          #80, d7                                 \n\t"
398                                                 "       bne                     reg_test_2_error                \n\t"
399                                                 "       move            a0, d0                                  \n\t"
400                                                 "       cmpi.l          #90, d0                                 \n\t"
401                                                 "       bne                     reg_test_2_error                \n\t"
402                                                 "       move            a1, d0                                  \n\t"
403                                                 "       cmpi.l          #100, d0                                \n\t"
404                                                 "       bne                     reg_test_2_error                \n\t"
405                                                 "       move            a2, d0                                  \n\t"
406                                                 "       cmpi.l          #110, d0                                \n\t"
407                                                 "       bne                     reg_test_2_error                \n\t"
408                                                 "       move            a3, d0                                  \n\t"
409                                                 "       cmpi.l          #120, d0                                \n\t"
410                                                 "       bne                     reg_test_2_error                \n\t"
411                                                 "       move            a4, d0                                  \n\t"
412                                                 "       cmpi.l          #130, d0                                \n\t"
413                                                 "       bne                     reg_test_2_error                \n\t"
414                                                 "       move            a5, d0                                  \n\t"
415                                                 "       cmpi.l          #140, d0                                \n\t"
416                                                 "       bne                     reg_test_2_error                \n\t"
417                                                 "       move            a6, d0                                  \n\t"
418                                                 "       cmpi.l          #150, d0                                \n\t"
419                                                 "       bne                     reg_test_2_error                \n\t"
420                                                 "       move            ulRegTest1Counter, d0   \n\t"
421                                                 "       addq            #1, d0                                  \n\t"
422                                                 "       move            d0, ulRegTest2Counter   \n\t"
423                                                 "       bra                     reg_test_2_start                \n\t"
424                                                 "reg_test_2_error:                                              \n\t"
425                                                 "       bra                     reg_test_2_error                \n\t"
426                                         );
427 }
428 /*-----------------------------------------------------------*/
429
430
431