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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [MB91460_Softune/] [SRC/] [main.c] - Blame information for rev 866

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 584 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 demo application tasks.
58
 *
59
 * In addition to the standard demo tasks, the follow demo specific tasks are
60
 * create:
61
 *
62
 * The "Check" task.  This only executes every three seconds but has the highest
63
 * priority so is guaranteed to get processor time.  Its main function is to
64
 * check that all the other tasks are still operational.  Most tasks maintain
65
 * a unique count that is incremented each time the task successfully completes
66
 * its function.  Should any error occur within such a task the count is
67
 * permanently halted.  The check task inspects the count of each task to ensure
68
 * it has changed since the last time the check task executed.  If all the count
69
 * variables have changed all the tasks are still executing error free, and the
70
 * check task toggles the onboard LED.  Should any task contain an error at any time
71
 * the LED toggle rate will change from 3 seconds to 500ms.
72
 *
73
 * The "Register Check" tasks.  These tasks fill the CPU registers with known
74
 * values, then check that each register still contains the expected value 0 the
75
 * discovery of an unexpected value being indicative of an error in the RTOS
76
 * context switch mechanism.  The register check tasks operate at low priority
77
 * so are switched in and out frequently.
78
 *
79
 * The "Trace Utility" task.  This can be used to obtain trace and debug
80
 * information via UART5.
81
 */
82
 
83
 
84
/* Hardware specific includes. */
85
#include "mb91467d.h"
86
#include "vectors.h"
87
#include "watchdog.h"
88
 
89
/* Scheduler includes. */
90
#include "FreeRTOS.h"
91
#include "task.h"
92
 
93
/* Demo app includes. */
94
#include "flash.h"
95
#include "integer.h"
96
#include "comtest2.h"
97
#include "semtest.h"
98
#include "BlockQ.h"
99
#include "dynamic.h"
100
#include "flop.h"
101
#include "GenQTest.h"
102
#include "QPeek.h"
103
#include "blocktim.h"
104
#include "death.h"
105
#include "taskutility.h"
106
#include "partest.h"
107
#include "crflash.h"
108
 
109
/* Demo task priorities. */
110
#define mainWATCHDOG_TASK_PRIORITY              ( tskIDLE_PRIORITY + 5 )
111
#define mainCHECK_TASK_PRIORITY                 ( tskIDLE_PRIORITY + 4 )
112
#define mainUTILITY_TASK_PRIORITY               ( tskIDLE_PRIORITY )
113
#define mainSEM_TEST_PRIORITY                   ( tskIDLE_PRIORITY + 3 )
114
#define mainCOM_TEST_PRIORITY                   ( tskIDLE_PRIORITY + 2 )
115
#define mainQUEUE_BLOCK_PRIORITY                ( tskIDLE_PRIORITY + 2 )
116
#define mainDEATH_PRIORITY                              ( tskIDLE_PRIORITY + 1 )
117
#define mainLED_TASK_PRIORITY                   ( tskIDLE_PRIORITY + 1 )
118
#define mainGENERIC_QUEUE_PRIORITY              ( tskIDLE_PRIORITY )
119
 
120
/* Baud rate used by the COM test tasks. */
121
#define mainCOM_TEST_BAUD_RATE                  ( ( unsigned portLONG ) 19200 )
122
 
123
/* The frequency at which the 'Check' tasks executes.  See the comments at the
124
top of the page.  When the system is operating error free the 'Check' task
125
toggles an LED every three seconds.  If an error is discovered in any task the
126
rate is increased to 500 milliseconds.  [in this case the '*' characters on the
127
LCD represent LEDs]*/
128
#define mainNO_ERROR_CHECK_DELAY                ( ( portTickType ) 3000 / portTICK_RATE_MS  )
129
#define mainERROR_CHECK_DELAY                   ( ( portTickType ) 500 / portTICK_RATE_MS  )
130
 
131
/* The total number of LEDs available. */
132
#define mainNO_CO_ROUTINE_LEDs  ( 8 )
133
 
134
/* The first LED used by the comtest tasks. */
135
#define mainCOM_TEST_LED                ( 0x05 )
136
 
137
/* The LED used by the check task. */
138
#define mainCHECK_TEST_LED              ( 0x07 )
139
 
140
/* The number of interrupt levels to use. */
141
#define mainINTERRUPT_LEVELS    ( 31 )
142
 
143
/* The number of 'flash' co-routines to create - each toggles a different LED. */
144
#define mainNUM_FLASH_CO_ROUTINES       ( 8 )
145
 
146
/*---------------------------------------------------------------------------*/
147
 
148
/*
149
 * The function that implements the Check task.  See the comments at the head
150
 * of the page for implementation details.
151
 */
152
static void prvErrorChecks( void *pvParameters );
153
 
154
/*
155
 * Called by the Check task.  Returns pdPASS if all the other tasks are found
156
 * to be operating without error - otherwise returns pdFAIL.
157
 */
158
static portSHORT prvCheckOtherTasksAreStillRunning( void );
159
 
160
/*
161
 * Setup the microcontroller as used by this demo.
162
 */
163
static void prvSetupHardware( void );
164
 
165
/*
166
 * Tasks that test the context switch mechanism by filling the CPU registers
167
 * with known values then checking that each register contains the value
168
 * expected.  Each of the two tasks use different values, and as low priority
169
 * tasks, get swapped in and out regularly.
170
 */
171
static void vFirstRegisterTestTask( void *pvParameters );
172
static void vSecondRegisterTestTask( void *pvParameters );
173
 
174
/*---------------------------------------------------------------------------*/
175
 
176
/* The variable that is set to true should an error be found in one of the
177
register test tasks. */
178
unsigned portLONG ulRegTestError = pdFALSE;
179
 
180
/*---------------------------------------------------------------------------*/
181
 
182
/* Start all the demo application tasks, then start the scheduler. */
183
void main(void)
184
{
185
        /* Initialise the hardware ready for the demo. */
186
        prvSetupHardware();
187
 
188
        /* Start the standard demo application tasks. */
189
        vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
190
        vStartIntegerMathTasks( tskIDLE_PRIORITY );
191
        vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
192
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
193
        vStartBlockingQueueTasks ( mainQUEUE_BLOCK_PRIORITY );
194
        vStartDynamicPriorityTasks();
195
        vStartMathTasks( tskIDLE_PRIORITY );
196
        vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
197
        vStartQueuePeekTasks();
198
        vCreateBlockTimeTasks();
199
        vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
200
 
201
        /* Start the 'Check' task which is defined in this file. */
202
        xTaskCreate( prvErrorChecks, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
203
 
204
        /* Start the 'Register Test' tasks as described at the top of this file. */
205
        xTaskCreate( vFirstRegisterTestTask, ( signed portCHAR * ) "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
206
        xTaskCreate( vSecondRegisterTestTask, ( signed portCHAR * ) "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
207
 
208
        /* Start the task that write trace information to the UART. */
209
        vUtilityStartTraceTask( mainUTILITY_TASK_PRIORITY );
210
 
211
        /* If we are going to service the watchdog from within a task, then create
212
        the task here. */
213
        #if WATCHDOG == WTC_IN_TASK     
214
                vStartWatchdogTask( mainWATCHDOG_TASK_PRIORITY );
215
        #endif          
216
 
217
        /* The suicide tasks must be started last as they record the number of other
218
        tasks that exist within the system.  The value is then used to ensure at run
219
        time the number of tasks that exists is within expected bounds. */
220
        vCreateSuicidalTasks( mainDEATH_PRIORITY );
221
 
222
        /* Now start the scheduler.  Following this call the created tasks should
223
        be executing. */
224
        vTaskStartScheduler( );
225
 
226
        /* vTaskStartScheduler() will only return if an error occurs while the
227
        idle task is being created. */
228
        for( ;; );
229
}
230
/*-----------------------------------------------------------*/
231
 
232
static void prvErrorChecks( void *pvParameters )
233
{
234
portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY, xLastExecutionTime;
235
 
236
        /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
237
        works correctly. */
238
        xLastExecutionTime = xTaskGetTickCount();
239
 
240
        /* Cycle for ever, delaying then checking all the other tasks are still
241
        operating without error. */
242
        for( ;; )
243
        {
244
                /* Wait until it is time to check again.  The time we wait here depends
245
                on whether an error has been detected or not.  When an error is
246
                detected the time is shortened resulting in a faster LED flash rate. */
247
                /* Perform this check every mainCHECK_DELAY milliseconds. */
248
                vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );
249
 
250
                /* See if the other tasks are all ok. */
251
                if( prvCheckOtherTasksAreStillRunning() != pdPASS )
252
                {
253
                        /* An error occurred in one of the tasks so shorten the delay
254
                        period - which has the effect of increasing the frequency of the
255
                        LED toggle. */
256
                        xDelayPeriod = mainERROR_CHECK_DELAY;
257
                }
258
 
259
                /* Flash! */
260
                vParTestToggleLED( mainCHECK_TEST_LED );
261
        }
262
}
263
/*-----------------------------------------------------------*/
264
 
265
static portSHORT prvCheckOtherTasksAreStillRunning( void )
266
{
267
portBASE_TYPE lReturn = pdPASS;
268
 
269
        /* The demo tasks maintain a count that increments every cycle of the task
270
        provided that the task has never encountered an error.  This function
271
        checks the counts maintained by the tasks to ensure they are still being
272
        incremented.  A count remaining at the same value between calls therefore
273
        indicates that an error has been detected. */
274
 
275
        if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
276
        {
277
                lReturn = pdFAIL;
278
        }
279
 
280
        if( xAreComTestTasksStillRunning() != pdTRUE )
281
        {
282
                lReturn = pdFAIL;
283
        }
284
 
285
        if( xAreSemaphoreTasksStillRunning() != pdTRUE )
286
        {
287
                lReturn = pdFAIL;
288
        }
289
 
290
        if( xAreBlockingQueuesStillRunning() != pdTRUE )
291
        {
292
                lReturn = pdFAIL;
293
        }
294
 
295
        if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
296
        {
297
                lReturn = pdFAIL;
298
        }
299
 
300
        if( xAreMathsTaskStillRunning() != pdTRUE )
301
        {
302
                lReturn = pdFAIL;
303
        }
304
 
305
        if( xIsCreateTaskStillRunning() != pdTRUE )
306
        {
307
                lReturn = pdFAIL;
308
        }
309
 
310
        if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
311
        {
312
                lReturn = pdFAIL;
313
        }
314
 
315
        if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
316
        {
317
                lReturn = pdFAIL;
318
        }
319
 
320
        if ( xAreQueuePeekTasksStillRunning() != pdTRUE )
321
        {
322
                lReturn = pdFAIL;
323
        }
324
 
325
        /* Have the register test tasks found any errors? */
326
        if( ulRegTestError != pdFALSE )
327
        {
328
                lReturn = pdFAIL;
329
        }
330
 
331
        return lReturn;
332
}
333
/*-----------------------------------------------------------*/
334
 
335
static void prvSetupHardware( void )
336
{
337
        /* Allow all interrupt levels. */
338
        __set_il( mainINTERRUPT_LEVELS );
339
 
340
        /* Initialise interrupts. */
341
        InitIrqLevels();
342
 
343
        /* Initialise the ports used by the LEDs. */
344
        vParTestInitialise();
345
 
346
        /* If we are going to use the watchdog, then initialise it now. */
347
        #if WATCHDOG != WTC_NONE        
348
                InitWatchdog();
349
        #endif
350
}
351
/*-----------------------------------------------------------*/
352
 
353
/* Idle hook function. */
354
#if configUSE_IDLE_HOOK == 1
355
        void vApplicationIdleHook( void )
356
        {
357
                /* Are we using the idle task to kick the watchdog?  See watchdog.h
358
                for watchdog kicking options. Note this is for demonstration only
359
                and is not a suggested method of servicing the watchdog in a real
360
                application. */
361
                #if WATCHDOG == WTC_IN_IDLE
362
                        Kick_Watchdog();
363
                #endif
364
 
365
                vCoRoutineSchedule();
366
        }
367
#else
368
        #if WATCHDOG == WTC_IN_IDLE
369
                #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.
370
        #endif
371
#endif
372
 
373
/*-----------------------------------------------------------*/
374
 
375
/* Tick hook function. */
376
#if configUSE_TICK_HOOK == 1
377
        void vApplicationTickHook( void )
378
        {
379
                /* Are we using the tick to kick the watchdog?  See watchdog.h
380
                for watchdog kicking options.  Note this is for demonstration
381
                only and is not a suggested method of servicing the watchdog in
382
                a real application. */
383
                #if WATCHDOG == WTC_IN_TICK
384
                        Kick_Watchdog();
385
                #endif
386
        }
387
#else
388
        #if WATCHDOG == WTC_IN_TICK
389
                #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.
390
        #endif
391
#endif
392
/*-----------------------------------------------------------*/
393
 
394
static void vFirstRegisterTestTask( void *pvParameters )
395
{
396
extern volatile unsigned portLONG ulCriticalNesting;
397
 
398
        /* Fills the registers with known values (different to the values
399
        used in vSecondRegisterTestTask()), then checks that the registers still
400
        all contain the expected value.  This is done to test the context save
401
        and restore mechanism as this task is swapped onto and off of the CPU. */
402
 
403
        for( ;; )
404
        {
405
                #pragma asm
406
                        ;Load known values into each register.
407
                        LDI     #0x11111111, R0
408
                        LDI     #0x22222222, R1
409
                        LDI     #0x33333333, R2
410
                        LDI #0x44444444, R3
411
                        LDI     #0x55555555, R4
412
                        LDI     #0x66666666, R5
413
                        LDI     #0x77777777, R6
414
                        LDI     #0x88888888, R7
415
                        LDI     #0x99999999, R8
416
                        LDI     #0xaaaaaaaa, R9
417
                        LDI     #0xbbbbbbbb, R10
418
                        LDI     #0xcccccccc, R11
419
                        LDI     #0xdddddddd, R12
420
 
421
                        ;Check each register still contains the expected value.
422
                        LDI #0x11111111, R13
423
                        CMP R13, R0
424
                        BNE First_Set_Error
425
 
426
                        LDI #0x22222222, R13
427
                        CMP R13, R1
428
                        BNE First_Set_Error
429
 
430
                        LDI #0x33333333, R13
431
                        CMP R13, R2
432
                        BNE First_Set_Error
433
 
434
                        LDI #0x44444444, R13
435
                        CMP R13, R3
436
                        BNE First_Set_Error
437
 
438
                        LDI #0x55555555, R13
439
                        CMP R13, R4
440
                        BNE First_Set_Error
441
 
442
                        LDI #0x66666666, R13
443
                        CMP R13, R5
444
                        BNE First_Set_Error
445
 
446
                        LDI #0x77777777, R13
447
                        CMP R13, R6
448
                        BNE First_Set_Error
449
 
450
                        LDI #0x88888888, R13
451
                        CMP R13, R7
452
                        BNE First_Set_Error
453
 
454
                        LDI #0x99999999, R13
455
                        CMP R13, R8
456
                        BNE First_Set_Error
457
 
458
                        LDI #0xaaaaaaaa, R13
459
                        CMP R13, R9
460
                        BNE First_Set_Error
461
 
462
                        LDI #0xbbbbbbbb, R13
463
                        CMP R13, R10
464
                        BNE First_Set_Error
465
 
466
                        LDI #0xcccccccc, R13
467
                        CMP R13, R11
468
                        BNE First_Set_Error
469
 
470
                        LDI #0xdddddddd, R13
471
                        CMP R13, R12
472
                        BNE First_Set_Error
473
 
474
                        BRA First_Start_Next_Loop
475
 
476
                First_Set_Error:
477
 
478
                        ; Latch that an error has occurred.
479
                        LDI #_ulRegTestError, R0                        
480
                        LDI #0x00000001, R1
481
                        ST R1, @R0
482
 
483
 
484
                First_Start_Next_Loop:
485
 
486
 
487
                #pragma endasm
488
        }
489
}
490
/*-----------------------------------------------------------*/
491
 
492
static void vSecondRegisterTestTask( void *pvParameters )
493
{
494
extern volatile unsigned portLONG ulCriticalNesting;
495
 
496
        /* Fills the registers with known values (different to the values
497
        used in vFirstRegisterTestTask()), then checks that the registers still
498
        all contain the expected value.  This is done to test the context save
499
        and restore mechanism as this task is swapped onto and off of the CPU. */
500
 
501
        for( ;; )
502
        {
503
                #pragma asm
504
                        ;Load known values into each register.
505
                        LDI     #0x11111111, R1
506
                        LDI     #0x22222222, R2
507
                        INT #40H
508
                        LDI     #0x33333333, R3
509
                        LDI #0x44444444, R4
510
                        LDI     #0x55555555, R5
511
                        LDI     #0x66666666, R6
512
                        LDI     #0x77777777, R7
513
                        LDI     #0x88888888, R8
514
                        LDI     #0x99999999, R9
515
                        INT #40H
516
                        LDI     #0xaaaaaaaa, R10
517
                        LDI     #0xbbbbbbbb, R11
518
                        LDI     #0xcccccccc, R12
519
                        LDI     #0xdddddddd, R0
520
 
521
                        ;Check each register still contains the expected value.
522
                        LDI #0x11111111, R13
523
                        CMP R13, R1
524
                        BNE Second_Set_Error
525
 
526
                        LDI #0x22222222, R13
527
                        CMP R13, R2
528
                        BNE Second_Set_Error
529
 
530
                        LDI #0x33333333, R13
531
                        CMP R13, R3
532
                        BNE Second_Set_Error
533
 
534
                        LDI #0x44444444, R13
535
                        CMP R13, R4
536
                        BNE Second_Set_Error
537
 
538
                        LDI #0x55555555, R13
539
                        CMP R13, R5
540
                        BNE Second_Set_Error
541
 
542
                        INT #40H
543
 
544
                        LDI #0x66666666, R13
545
                        CMP R13, R6
546
                        BNE Second_Set_Error
547
 
548
                        LDI #0x77777777, R13
549
                        CMP R13, R7
550
                        BNE Second_Set_Error
551
 
552
                        LDI #0x88888888, R13
553
                        CMP R13, R8
554
                        BNE Second_Set_Error
555
 
556
                        LDI #0x99999999, R13
557
                        CMP R13, R9
558
                        BNE Second_Set_Error
559
 
560
                        INT #40H
561
 
562
                        LDI #0xaaaaaaaa, R13
563
                        CMP R13, R10
564
                        BNE Second_Set_Error
565
 
566
                        LDI #0xbbbbbbbb, R13
567
                        CMP R13, R11
568
                        BNE Second_Set_Error
569
 
570
                        LDI #0xcccccccc, R13
571
                        CMP R13, R12
572
                        BNE Second_Set_Error
573
 
574
                        LDI #0xdddddddd, R13
575
                        CMP R13, R0
576
                        BNE Second_Set_Error
577
 
578
                        BRA Second_Start_Next_Loop
579
 
580
                Second_Set_Error:
581
 
582
                        ; Latch that an error has occurred.
583
                        LDI #_ulRegTestError, R0                        
584
                        LDI #0x00000001, R1
585
                        ST R1, @R0
586
 
587
 
588
                Second_Start_Next_Loop:
589
 
590
 
591
                #pragma endasm
592
        }
593
}
594
/*-----------------------------------------------------------*/
595
 
596
 

powered by: WebSVN 2.1.0

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