OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [ColdFire_MCF52221_CodeWarrior/] [sources/] [main.c] - Blame information for rev 578

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 jeremybenn
/*
2
    FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
3
 
4
    ***************************************************************************
5
    *                                                                         *
6
    * If you are:                                                             *
7
    *                                                                         *
8
    *    + New to FreeRTOS,                                                   *
9
    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *
10
    *    + Looking for basic training,                                        *
11
    *    + Wanting to improve your FreeRTOS skills and productivity           *
12
    *                                                                         *
13
    * then take a look at the FreeRTOS books - available as PDF or paperback  *
14
    *                                                                         *
15
    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *
16
    *                  http://www.FreeRTOS.org/Documentation                  *
17
    *                                                                         *
18
    * A pdf reference manual is also available.  Both are usually delivered   *
19
    * to your inbox within 20 minutes to two hours when purchased between 8am *
20
    * and 8pm GMT (although please allow up to 24 hours in case of            *
21
    * exceptional circumstances).  Thank you for your support!                *
22
    *                                                                         *
23
    ***************************************************************************
24
 
25
    This file is part of the FreeRTOS distribution.
26
 
27
    FreeRTOS is free software; you can redistribute it and/or modify it under
28
    the terms of the GNU General Public License (version 2) as published by the
29
    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
30
    ***NOTE*** The exception to the GPL is included to allow you to distribute
31
    a combined work that includes FreeRTOS without being obliged to provide the
32
    source code for proprietary components outside of the FreeRTOS kernel.
33
    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
34
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
36
    more details. You should have received a copy of the GNU General Public
37
    License and the FreeRTOS license exception along with FreeRTOS; if not it
38
    can be viewed here: http://www.freertos.org/a00114.html and also obtained
39
    by writing to Richard Barry, contact details for whom are available on the
40
    FreeRTOS WEB site.
41
 
42
    1 tab == 4 spaces!
43
 
44
    http://www.FreeRTOS.org - Documentation, latest information, license and
45
    contact details.
46
 
47
    http://www.SafeRTOS.com - A version that is certified for use in safety
48
    critical systems.
49
 
50
    http://www.OpenRTOS.com - Commercial support, development, porting,
51
    licensing and training services.
52
*/
53
 
54
 
55
/*
56
 * Creates all the demo application tasks, then starts the scheduler.  The WEB
57
 * documentation provides more details of the standard demo application tasks.
58
 * In addition to the standard demo tasks, the following tasks and tests are
59
 * defined and/or created within this file:
60
 *
61
 * "Check" task -  This only executes every five seconds but has a high priority
62
 * to ensure it gets processor time.  Its main function is to check that all the
63
 * standard demo tasks are still operational.  While no errors have been
64
 * discovered the check task will toggle an LED every 5 seconds - the toggle
65
 * rate increasing to 500ms being a visual indication that at least one task has
66
 * reported unexpected behaviour.
67
 *
68
 * "Reg test" tasks - These fill the registers with known values, then check
69
 * that each register still contains its expected value.  Each task uses
70
 * different values.  The tasks run with very low priority so get preempted very
71
 * frequently.  A register containing an unexpected value is indicative of an
72
 * error in the context switching mechanism.
73
 *
74
 */
75
 
76
/* Standard includes. */
77
#include <stdio.h>
78
 
79
/* Scheduler includes. */
80
#include "FreeRTOS.h"
81
#include "task.h"
82
#include "queue.h"
83
#include "semphr.h"
84
 
85
/* Demo app includes. */
86
#include "BlockQ.h"
87
#include "crflash.h"
88
#include "partest.h"
89
#include "semtest.h"
90
#include "GenQTest.h"
91
#include "QPeek.h"
92
#include "comtest2.h"
93
 
94
/*-----------------------------------------------------------*/
95
 
96
/* The time between cycles of the 'check' functionality - as described at the
97
top of this file. */
98
#define mainNO_ERROR_PERIOD                                     ( ( portTickType ) 5000 / portTICK_RATE_MS )
99
 
100
/* The rate at which the LED controlled by the 'check' task will flash should an
101
error have been detected. */
102
#define mainERROR_PERIOD                                        ( ( portTickType ) 500 / portTICK_RATE_MS )
103
 
104
/* The LED controlled by the 'check' task. */
105
#define mainCHECK_LED                                           ( 3 )
106
 
107
/* ComTest constants - there is no free LED for the comtest tasks. */
108
#define mainCOM_TEST_BAUD_RATE                          ( ( unsigned portLONG ) 19200 )
109
#define mainCOM_TEST_LED                                        ( 5 )
110
 
111
/* Task priorities. */
112
#define mainCOM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 2 )
113
#define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )
114
#define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )
115
#define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )
116
#define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )
117
 
118
/* Co-routines are used to flash the LEDs. */
119
#define mainNUM_FLASH_CO_ROUTINES                       ( 3 )
120
 
121
/* The baud rate used by the comtest tasks. */
122
#define mainBAUD_RATE                                           ( 38400 )
123
 
124
/* There is no spare LED for the comtest tasks, so this is set to an invalid
125
number. */
126
#define mainCOM_LED                                                     ( 4 )
127
 
128
/*
129
 * Configure the hardware for the demo.
130
 */
131
static void prvSetupHardware( void );
132
 
133
/*
134
 * Implements the 'check' task functionality as described at the top of this
135
 * file.
136
 */
137
static void prvCheckTask( void *pvParameters );
138
 
139
/*
140
 * Implement the 'Reg test' functionality as described at the top of this file.
141
 */
142
static void vRegTest1Task( void *pvParameters );
143
static void vRegTest2Task( void *pvParameters );
144
 
145
/*-----------------------------------------------------------*/
146
 
147
/* Counters used to detect errors within the reg test tasks. */
148
static volatile unsigned portLONG ulRegTest1Counter = 0x11111111, ulRegTest2Counter = 0x22222222;
149
 
150
/*-----------------------------------------------------------*/
151
 
152
int main( void )
153
{
154
        /* Setup the hardware ready for this demo. */
155
        prvSetupHardware();
156
 
157
        /* Start the standard demo tasks. */
158
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
159
        vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
160
        vStartQueuePeekTasks();
161
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
162
        vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainBAUD_RATE, mainCOM_LED );
163
 
164
        /* For demo purposes use some co-routines to flash the LEDs. */
165
        vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
166
 
167
        /* Create the check task. */
168
        xTaskCreate( prvCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
169
 
170
 
171
        /* Start the reg test tasks - defined in this file. */
172
        xTaskCreate( vRegTest1Task, ( signed portCHAR * ) "Reg1", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest1Counter, tskIDLE_PRIORITY, NULL );
173
        xTaskCreate( vRegTest2Task, ( signed portCHAR * ) "Reg2", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest2Counter, tskIDLE_PRIORITY, NULL );
174
 
175
        /* Start the scheduler. */
176
        vTaskStartScheduler();
177
 
178
    /* Will only get here if there was insufficient memory to create the idle
179
    task. */
180
        for( ;; )
181
        {
182
        }
183
}
184
/*-----------------------------------------------------------*/
185
 
186
static void prvCheckTask( void *pvParameters )
187
{
188
unsigned portLONG ulTicksToWait = mainNO_ERROR_PERIOD, ulError = 0, ulLastRegTest1Count = 0, ulLastRegTest2Count = 0;
189
portTickType xLastExecutionTime;
190
volatile unsigned portBASE_TYPE uxUnusedStack;
191
 
192
        ( void ) pvParameters;
193
 
194
        /* Initialise the variable used to control our iteration rate prior to
195
        its first use. */
196
        xLastExecutionTime = xTaskGetTickCount();
197
 
198
        for( ;; )
199
        {
200
                /* Wait until it is time to run the tests again. */
201
                vTaskDelayUntil( &xLastExecutionTime, ulTicksToWait );
202
 
203
                /* Has an error been found in any task? */
204
                if( xAreGenericQueueTasksStillRunning() != pdTRUE )
205
                {
206
                        ulError |= 0x01UL;
207
                }
208
 
209
                if( xAreQueuePeekTasksStillRunning() != pdTRUE )
210
                {
211
                        ulError |= 0x02UL;
212
                }
213
 
214
                if( xAreBlockingQueuesStillRunning() != pdTRUE )
215
                {
216
                        ulError |= 0x04UL;
217
                }
218
 
219
                if( xAreSemaphoreTasksStillRunning() != pdTRUE )
220
            {
221
                ulError |= 0x20UL;
222
            }
223
 
224
            if( xAreComTestTasksStillRunning() != pdTRUE )
225
            {
226
                ulError |= 0x40UL;
227
            }
228
 
229
                if( ulLastRegTest1Count == ulRegTest1Counter )
230
                {
231
                        ulError |= 0x1000UL;
232
                }
233
 
234
                if( ulLastRegTest2Count == ulRegTest2Counter )
235
                {
236
                        ulError |= 0x1000UL;
237
                }
238
 
239
                ulLastRegTest1Count = ulRegTest1Counter;
240
                ulLastRegTest2Count = ulRegTest2Counter;
241
 
242
                /* If an error has been found then increase our cycle rate, and in so
243
                doing increase the rate at which the check task LED toggles. */
244
                if( ulError != 0 )
245
                {
246
                ulTicksToWait = mainERROR_PERIOD;
247
                }
248
 
249
                /* Toggle the LED each itteration. */
250
                vParTestToggleLED( mainCHECK_LED );
251
 
252
                /* For demo only - how much unused stack does this task have? */
253
                uxUnusedStack = uxTaskGetStackHighWaterMark( NULL );
254
        }
255
}
256
/*-----------------------------------------------------------*/
257
 
258
void prvSetupHardware( void )
259
{
260
        portDISABLE_INTERRUPTS();
261
 
262
        /* Setup the port used to toggle LEDs. */
263
        vParTestInitialise();
264
}
265
/*-----------------------------------------------------------*/
266
 
267
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )
268
{
269
        /* This will get called if a stack overflow is detected during the context
270
        switch.  Set configCHECK_FOR_STACK_OVERFLOWS to 2 to also check for stack
271
        problems within nested interrupts, but only do this for debug purposes as
272
        it will increase the context switch time. */
273
 
274
        ( void ) pxTask;
275
        ( void ) pcTaskName;
276
 
277
        for( ;; )
278
        {
279
        }
280
}
281
/*-----------------------------------------------------------*/
282
 
283
void vApplicationIdleHook( void );
284
void vApplicationIdleHook( void )
285
{
286
        /* The co-routines run in the idle task. */
287
        vCoRoutineSchedule();
288
}
289
/*-----------------------------------------------------------*/
290
 
291
void exit( int n )
292
{
293
        /* To keep the linker happy only as the libraries have been removed from
294
        the build. */
295
        ( void ) n;
296
        for( ;; ) {}
297
}
298
/*-----------------------------------------------------------*/
299
 
300
static void vRegTest1Task( void *pvParameters )
301
{
302
        /* Sanity check - did we receive the parameter expected? */
303
        if( pvParameters != &ulRegTest1Counter )
304
        {
305
                /* Change here so the check task can detect that an error occurred. */
306
                for( ;; )
307
                {
308
                }
309
        }
310
 
311
        /* Set all the registers to known values, then check that each retains its
312
        expected value - as described at the top of this file.  If an error is
313
        found then the loop counter will no longer be incremented allowing the check
314
        task to recognise the error. */
315
        asm volatile    (       "reg_test_1_start:                                              \n\t"
316
                                                "       moveq           #1, d0                                  \n\t"
317
                                                "       moveq           #2, d1                                  \n\t"
318
                                                "       moveq           #3, d2                                  \n\t"
319
                                                "       moveq           #4, d3                                  \n\t"
320
                                                "       moveq           #5, d4                                  \n\t"
321
                                                "       moveq           #6, d5                                  \n\t"
322
                                                "       moveq           #7, d6                                  \n\t"
323
                                                "       moveq           #8, d7                                  \n\t"
324
                                                "       move            #9, a0                                  \n\t"
325
                                                "       move            #10, a1                                 \n\t"
326
                                                "       move            #11, a2                                 \n\t"
327
                                                "       move            #12, a3                                 \n\t"
328
                                                "       move            #13, a4                                 \n\t"
329
                                                "       move            #14, a5                                 \n\t"
330
                                                "       move            #15, a6                                 \n\t"
331
                                                "                                                                               \n\t"
332
                                                "       cmpi.l          #1, d0                                  \n\t"
333
                                                "       bne                     reg_test_1_error                \n\t"
334
                                                "       cmpi.l          #2, d1                                  \n\t"
335
                                                "       bne                     reg_test_1_error                \n\t"
336
                                                "       cmpi.l          #3, d2                                  \n\t"
337
                                                "       bne                     reg_test_1_error                \n\t"
338
                                                "       cmpi.l          #4, d3                                  \n\t"
339
                                                "       bne                     reg_test_1_error                \n\t"
340
                                                "       cmpi.l          #5, d4                                  \n\t"
341
                                                "       bne                     reg_test_1_error                \n\t"
342
                                                "       cmpi.l          #6, d5                                  \n\t"
343
                                                "       bne                     reg_test_1_error                \n\t"
344
                                                "       cmpi.l          #7, d6                                  \n\t"
345
                                                "       bne                     reg_test_1_error                \n\t"
346
                                                "       cmpi.l          #8, d7                                  \n\t"
347
                                                "       bne                     reg_test_1_error                \n\t"
348
                                                "       move            a0, d0                                  \n\t"
349
                                                "       cmpi.l          #9, d0                                  \n\t"
350
                                                "       bne                     reg_test_1_error                \n\t"
351
                                                "       move            a1, d0                                  \n\t"
352
                                                "       cmpi.l          #10, d0                                 \n\t"
353
                                                "       bne                     reg_test_1_error                \n\t"
354
                                                "       move            a2, d0                                  \n\t"
355
                                                "       cmpi.l          #11, d0                                 \n\t"
356
                                                "       bne                     reg_test_1_error                \n\t"
357
                                                "       move            a3, d0                                  \n\t"
358
                                                "       cmpi.l          #12, d0                                 \n\t"
359
                                                "       bne                     reg_test_1_error                \n\t"
360
                                                "       move            a4, d0                                  \n\t"
361
                                                "       cmpi.l          #13, d0                                 \n\t"
362
                                                "       bne                     reg_test_1_error                \n\t"
363
                                                "       move            a5, d0                                  \n\t"
364
                                                "       cmpi.l          #14, d0                                 \n\t"
365
                                                "       bne                     reg_test_1_error                \n\t"
366
                                                "       move            a6, d0                                  \n\t"
367
                                                "       cmpi.l          #15, d0                                 \n\t"
368
                                                "       bne                     reg_test_1_error                \n\t"
369
                                                "       move            ulRegTest1Counter, d0   \n\t"
370
                                                "       addq            #1, d0                                  \n\t"
371
                                                "       move            d0, ulRegTest1Counter   \n\t"
372
                                                "       bra                     reg_test_1_start                \n\t"
373
                                                "reg_test_1_error:                                              \n\t"
374
                                                "       bra                     reg_test_1_error                \n\t"
375
                                        );
376
}
377
/*-----------------------------------------------------------*/
378
 
379
static void vRegTest2Task( void *pvParameters )
380
{
381
        /* Sanity check - did we receive the parameter expected? */
382
        if( pvParameters != &ulRegTest2Counter )
383
        {
384
                /* Change here so the check task can detect that an error occurred. */
385
                for( ;; )
386
                {
387
                }
388
        }
389
 
390
        /* Set all the registers to known values, then check that each retains its
391
        expected value - as described at the top of this file.  If an error is
392
        found then the loop counter will no longer be incremented allowing the check
393
        task to recognise the error. */
394
        asm volatile    (       "reg_test_2_start:                                              \n\t"
395
                                                "       moveq           #10, d0                                 \n\t"
396
                                                "       moveq           #20, d1                                 \n\t"
397
                                                "       moveq           #30, d2                                 \n\t"
398
                                                "       moveq           #40, d3                                 \n\t"
399
                                                "       moveq           #50, d4                                 \n\t"
400
                                                "       moveq           #60, d5                                 \n\t"
401
                                                "       moveq           #70, d6                                 \n\t"
402
                                                "       moveq           #80, d7                                 \n\t"
403
                                                "       move            #90, a0                                 \n\t"
404
                                                "       move            #100, a1                                \n\t"
405
                                                "       move            #110, a2                                \n\t"
406
                                                "       move            #120, a3                                \n\t"
407
                                                "       move            #130, a4                                \n\t"
408
                                                "       move            #140, a5                                \n\t"
409
                                                "       move            #150, a6                                \n\t"
410
                                                "                                                                               \n\t"
411
                                                "       cmpi.l          #10, d0                                 \n\t"
412
                                                "       bne                     reg_test_2_error                \n\t"
413
                                                "       cmpi.l          #20, d1                                 \n\t"
414
                                                "       bne                     reg_test_2_error                \n\t"
415
                                                "       cmpi.l          #30, d2                                 \n\t"
416
                                                "       bne                     reg_test_2_error                \n\t"
417
                                                "       cmpi.l          #40, d3                                 \n\t"
418
                                                "       bne                     reg_test_2_error                \n\t"
419
                                                "       cmpi.l          #50, d4                                 \n\t"
420
                                                "       bne                     reg_test_2_error                \n\t"
421
                                                "       cmpi.l          #60, d5                                 \n\t"
422
                                                "       bne                     reg_test_2_error                \n\t"
423
                                                "       cmpi.l          #70, d6                                 \n\t"
424
                                                "       bne                     reg_test_2_error                \n\t"
425
                                                "       cmpi.l          #80, d7                                 \n\t"
426
                                                "       bne                     reg_test_2_error                \n\t"
427
                                                "       move            a0, d0                                  \n\t"
428
                                                "       cmpi.l          #90, d0                                 \n\t"
429
                                                "       bne                     reg_test_2_error                \n\t"
430
                                                "       move            a1, d0                                  \n\t"
431
                                                "       cmpi.l          #100, d0                                \n\t"
432
                                                "       bne                     reg_test_2_error                \n\t"
433
                                                "       move            a2, d0                                  \n\t"
434
                                                "       cmpi.l          #110, d0                                \n\t"
435
                                                "       bne                     reg_test_2_error                \n\t"
436
                                                "       move            a3, d0                                  \n\t"
437
                                                "       cmpi.l          #120, d0                                \n\t"
438
                                                "       bne                     reg_test_2_error                \n\t"
439
                                                "       move            a4, d0                                  \n\t"
440
                                                "       cmpi.l          #130, d0                                \n\t"
441
                                                "       bne                     reg_test_2_error                \n\t"
442
                                                "       move            a5, d0                                  \n\t"
443
                                                "       cmpi.l          #140, d0                                \n\t"
444
                                                "       bne                     reg_test_2_error                \n\t"
445
                                                "       move            a6, d0                                  \n\t"
446
                                                "       cmpi.l          #150, d0                                \n\t"
447
                                                "       bne                     reg_test_2_error                \n\t"
448
                                                "       move            ulRegTest1Counter, d0   \n\t"
449
                                                "       addq            #1, d0                                  \n\t"
450
                                                "       move            d0, ulRegTest2Counter   \n\t"
451
                                                "       bra                     reg_test_2_start                \n\t"
452
                                                "reg_test_2_error:                                              \n\t"
453
                                                "       bra                     reg_test_2_error                \n\t"
454
                                        );
455
}
456
/*-----------------------------------------------------------*/
457
 
458
 
459
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.