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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [MicroBlaze/] [main.c] - Blame information for rev 867

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
 * Creates all the demo application tasks, then starts the scheduler.  The WEB
56
 * documentation provides more details of the standard demo application tasks.
57
 *
58
 * In addition to the standard tasks, main() creates two "Register Check"
59
 * tasks.  These tasks write known values into every general purpose register,
60
 * then check each register to ensure it still contains the expected (written)
61
 * value.  The register check tasks operate at the idle priority so will get
62
 * repeatedly preempted.  A register being found to contain an incorrect value
63
 * following such a preemption would be indicative of an error in the context
64
 * switch mechanism.
65
 *
66
 * Main.c also creates a task called "Check".  This only executes every three
67
 * seconds but has the highest priority so is guaranteed to get processor time.
68
 * Its main function is to check that all the other tasks are still operational.
69
 * Each task (other than the "flash" tasks) maintains a unique count that is
70
 * incremented each time the task successfully completes its function.  Should
71
 * any error occur within such a task the count is permanently halted.  The
72
 * check task inspects the count of each task to ensure it has changed since
73
 * the last time the check task executed.  If all the count variables have
74
 * changed all the tasks are still executing error free, and the check task
75
 * toggles the onboard LED.  Should any task contain an error at any time
76
 * the LED toggle rate will change from 3 seconds to 500ms.
77
 *
78
 */
79
 
80
/* Scheduler includes. */
81
#include "FreeRTOS.h"
82
#include "task.h"
83
 
84
/* Demo application includes. */
85
#include "partest.h"
86
#include "flash.h"
87
#include "comtest2.h"
88
#include "integer.h"
89
#include "semtest.h"
90
#include "BlockQ.h"
91
#include "dynamic.h"
92
#include "PollQ.h"
93
 
94
/* Hardware library includes. */
95
#include <xintc.h>
96
 
97
/* The rate at which the 'check' LED will flash when no errors have been
98
detected. */
99
#define mainNO_ERROR_CHECK_PERIOD       3000
100
 
101
/* The rate at which the 'check' LED will flash when an error has been
102
detected in one of the demo tasks. */
103
#define mainERROR_CHECK_PERIOD          500
104
 
105
/* Demo application task priorities. */
106
#define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )
107
#define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 3 )
108
#define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )
109
#define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )
110
#define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )
111
#define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )
112
 
113
/* Software cannot influence the BAUD rate used by the simple UART
114
implementation. */
115
#define mainBAUD_RATE                           0
116
 
117
/* The LED flashed by the 'check' task to indicate the system status. */
118
#define mainCHECK_TASK_LED                      3
119
 
120
/* The first LED flashed by the COM port test tasks.  LED mainCOM_TEST_LED + 1
121
will also be used. */
122
#define mainCOM_TEST_LED                        4
123
 
124
/* The register test task does not make any function calls so does not require
125
much stack at all. */
126
#define mainTINY_STACK                          70
127
 
128
/*
129
 * The task that executes at the highest priority and calls
130
 * prvCheckOtherTasksAreStillRunning().  See the description at the top
131
 * of the file.
132
 */
133
static void vErrorChecks( void *pvParameters );
134
 
135
/*
136
 * Checks that all the demo application tasks are still executing without error
137
 * - as described at the top of the file.
138
 */
139
static portBASE_TYPE prvCheckOtherTasksAreStillRunning( void );
140
 
141
/*
142
 * The register test task as described at the top of this file.
143
 */
144
static void vRegisterTest( void *pvParameters );
145
 
146
/*
147
 * Perform any necessary hardware configuration.
148
 */
149
static void prvSetupHardware( void );
150
 
151
/* Set to pdFAIL should an error be discovered in the register test tasks. */
152
static unsigned long ulRegisterTestStatus = pdPASS;
153
const unsigned long *pulStatusAddr = &ulRegisterTestStatus;
154
 
155
/*-----------------------------------------------------------*/
156
 
157
/*
158
 * Create all the demo tasks - then start the scheduler.
159
 */
160
int main (void)
161
{
162
        /* When re-starting a debug session (rather than cold booting) we want
163
        to ensure the installed interrupt handlers do not execute until after the
164
        scheduler has been started. */
165
        portDISABLE_INTERRUPTS();
166
 
167
        prvSetupHardware();
168
 
169
        /* Start the standard demo application tasks. */
170
        vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
171
        vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainBAUD_RATE, mainCOM_TEST_LED );
172
        vStartIntegerMathTasks( tskIDLE_PRIORITY );
173
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
174
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
175
        vStartDynamicPriorityTasks();
176
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
177
 
178
        /* Create two register check tasks - using a different parameter for each.
179
        The parameter is used to generate the known values written to the registers. */
180
        #if configUSE_PREEMPTION == 1
181
                xTaskCreate( vRegisterTest, "Reg1", mainTINY_STACK, ( void * ) 10, tskIDLE_PRIORITY, NULL );
182
                xTaskCreate( vRegisterTest, "Reg2", mainTINY_STACK, ( void * ) 20, tskIDLE_PRIORITY, NULL );
183
        #endif
184
 
185
        /* Create the 'check' task that is defined in this file. */
186
        xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
187
 
188
        /* Finally start the scheduler. */
189
        vTaskStartScheduler();
190
 
191
        /* Should not get here as the processor is now under control of the
192
        scheduler! */
193
 
194
        return 0;
195
}
196
/*-----------------------------------------------------------*/
197
 
198
static void vErrorChecks( void *pvParameters )
199
{
200
portTickType xDelayPeriod = mainNO_ERROR_CHECK_PERIOD;
201
 
202
        /* The parameters are not used. */
203
        ( void ) pvParameters;
204
 
205
        /* Cycle for ever, delaying then checking all the other tasks are still
206
        operating without error.  The delay period used will depend on whether
207
        or not an error has been discovered in one of the demo tasks. */
208
        for( ;; )
209
        {
210
                vTaskDelay( xDelayPeriod );
211
                if( !prvCheckOtherTasksAreStillRunning() )
212
                {
213
                        /* An error has been found.  Shorten the delay period to make
214
                        the LED flash faster. */
215
                        xDelayPeriod = mainERROR_CHECK_PERIOD;
216
                }
217
 
218
                vParTestToggleLED( mainCHECK_TASK_LED );
219
        }
220
}
221
/*-----------------------------------------------------------*/
222
 
223
static portBASE_TYPE prvCheckOtherTasksAreStillRunning( void )
224
{
225
static portBASE_TYPE xAllTestsPass = pdTRUE;
226
 
227
        /* Return pdFALSE if any demo application task set has encountered
228
        an error. */
229
 
230
        if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
231
        {
232
                xAllTestsPass = pdFALSE;
233
        }
234
 
235
        if( xAreComTestTasksStillRunning() != pdTRUE )
236
        {
237
                xAllTestsPass = pdFALSE;
238
        }
239
 
240
        if( xAreSemaphoreTasksStillRunning() != pdTRUE )
241
        {
242
                xAllTestsPass = pdFALSE;
243
        }
244
 
245
        if( xAreBlockingQueuesStillRunning() != pdTRUE )
246
        {
247
                xAllTestsPass = pdFAIL;
248
        }
249
 
250
        if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
251
        {
252
                xAllTestsPass = ( long ) pdFAIL;
253
        }
254
 
255
        if( xArePollingQueuesStillRunning() != pdTRUE )
256
        {
257
                xAllTestsPass = ( long ) pdFAIL;
258
        }
259
 
260
        /* Mutual exclusion on this variable is not necessary as we only read it. */
261
        if( ulRegisterTestStatus != pdPASS )
262
        {
263
                xAllTestsPass = pdFALSE;
264
        }
265
 
266
        return xAllTestsPass;
267
}
268
/*-----------------------------------------------------------*/
269
 
270
static void prvSetupHardware( void )
271
{
272
        /* Ensure the interrupt controller is enabled in order that subsequent
273
        code can successfully configure the peripherals. */
274
        XIntc_mMasterEnable( XPAR_OPB_INTC_0_BASEADDR );
275
 
276
        /* Initialise the GPIO used for the LED's. */
277
        vParTestInitialise();
278
}
279
/*-----------------------------------------------------------*/
280
 
281
static void vRegisterTest( void *pvParameters )
282
{
283
        for( ;; )
284
        {
285
                /* Fill the registers with their register number plus the offset
286
                (added) value.  The added value is passed in as a parameter so
287
                is contained in r5. */
288
                asm volatile (  "addi r3, r5, 3         \n\t" \
289
                                                "addi r4, r5, 4         \n\t" \
290
                                                "addi r6, r5, 6         \n\t" \
291
                                                "addi r7, r5, 7         \n\t" \
292
                                                "addi r8, r5, 8         \n\t" \
293
                                                "addi r9, r5, 9         \n\t" \
294
                                                "addi r10, r5, 10       \n\t" \
295
                                                "addi r11, r5, 11       \n\t" \
296
                                                "addi r12, r5, 12       \n\t" \
297
                                                "addi r16, r5, 16       \n\t" \
298
                                                "addi r17, r5, 17       \n\t" \
299
                                                "addi r18, r5, 18       \n\t" \
300
                                                "addi r19, r5, 19       \n\t" \
301
                                                "addi r20, r5, 20       \n\t" \
302
                                                "addi r21, r5, 21       \n\t" \
303
                                                "addi r22, r5, 22       \n\t" \
304
                                                "addi r23, r5, 23       \n\t" \
305
                                                "addi r24, r5, 24       \n\t" \
306
                                                "addi r25, r5, 25       \n\t" \
307
                                                "addi r26, r5, 26       \n\t" \
308
                                                "addi r27, r5, 27       \n\t" \
309
                                                "addi r28, r5, 28       \n\t" \
310
                                                "addi r29, r5, 29       \n\t" \
311
                                                "addi r30, r5, 30       \n\t" \
312
                                                "addi r31, r5, 31       \n\t"
313
                                        );
314
 
315
                /* Now read back the register values to ensure they are as we expect.
316
                This task will get preempted frequently so other tasks are likely to
317
                have executed since the register values were written. */
318
 
319
                /* r3 should contain r5 + 3.  Subtract 3 to leave r3 equal to r5. */
320
                asm volatile (  "addi r3, r3, -3 " );
321
 
322
                /* Compare r3 and r5.  If they are not equal then either r3 or r5
323
                contains the wrong value and *pulStatusAddr is to pdFAIL. */
324
                asm volatile (  "cmp r3, r3, r5                         \n\t" \
325
                                                "beqi r3, 12                            \n\t" \
326
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
327
                                                "sw     r0, r0, r3                              \n\t"
328
                                         );
329
 
330
                /* Repeat for all the other registers. */
331
                asm volatile (  "addi r4, r4, -4                        \n\t" \
332
                                                "cmp r4, r4, r5                         \n\t" \
333
                                                "beqi r4, 12                            \n\t" \
334
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
335
                                                "sw     r0, r0, r3                              \n\t" \
336
                                                "addi r6, r6, -6                        \n\t" \
337
                                                "cmp r6, r6, r5                         \n\t" \
338
                                                "beqi r6, 12                            \n\t" \
339
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
340
                                                "sw     r0, r0, r3                              \n\t" \
341
                                                "addi r7, r7, -7                        \n\t" \
342
                                                "cmp r7, r7, r5                         \n\t" \
343
                                                "beqi r7, 12                            \n\t" \
344
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
345
                                                "sw     r0, r0, r3                              \n\t" \
346
                                                "addi r8, r8, -8                        \n\t" \
347
                                                "cmp r8, r8, r5                         \n\t" \
348
                                                "beqi r8, 12                            \n\t" \
349
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
350
                                                "sw     r0, r0, r3                              \n\t" \
351
                                                "addi r9, r9, -9                        \n\t" \
352
                                                "cmp r9, r9, r5                         \n\t" \
353
                                                "beqi r9, 12                            \n\t" \
354
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
355
                                                "sw     r0, r0, r3                              \n\t" \
356
                                                "addi r10, r10, -10                     \n\t" \
357
                                                "cmp r10, r10, r5                       \n\t" \
358
                                                "beqi r10, 12                           \n\t" \
359
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
360
                                                "sw     r0, r0, r3                              \n\t" \
361
                                                "addi r11, r11, -11                     \n\t" \
362
                                                "cmp r11, r11, r5                       \n\t" \
363
                                                "beqi r11, 12                           \n\t" \
364
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
365
                                                "sw     r0, r0, r3                              \n\t" \
366
                                                "addi r12, r12, -12                     \n\t" \
367
                                                "cmp r12, r12, r5                       \n\t" \
368
                                                "beqi r12, 12                           \n\t" \
369
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
370
                                                "sw     r0, r0, r3                              \n\t" \
371
                                                "sw     r0, r0, r3                              \n\t" \
372
                                                "addi r16, r16, -16                     \n\t" \
373
                                                "cmp r16, r16, r5                       \n\t" \
374
                                                "beqi r16, 12                           \n\t" \
375
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
376
                                                "sw     r0, r0, r3                              \n\t" \
377
                                                "addi r17, r17, -17                     \n\t" \
378
                                                "cmp r17, r17, r5                       \n\t" \
379
                                                "beqi r17, 12                           \n\t" \
380
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
381
                                                "sw     r0, r0, r3                              \n\t" \
382
                                                "addi r18, r18, -18                     \n\t" \
383
                                                "cmp r18, r18, r5                       \n\t" \
384
                                                "beqi r18, 12                           \n\t" \
385
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
386
                                                "sw     r0, r0, r3                              \n\t" \
387
                                                "addi r19, r19, -19                     \n\t" \
388
                                                "cmp r19, r19, r5                       \n\t" \
389
                                                "beqi r19, 12                           \n\t" \
390
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
391
                                                "sw     r0, r0, r3                              \n\t" \
392
                                                "addi r20, r20, -20                     \n\t" \
393
                                                "cmp r20, r20, r5                       \n\t" \
394
                                                "beqi r20, 12                           \n\t" \
395
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
396
                                                "sw     r0, r0, r3                              \n\t" \
397
                                                "addi r21, r21, -21                     \n\t" \
398
                                                "cmp r21, r21, r5                       \n\t" \
399
                                                "beqi r21, 12                           \n\t" \
400
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
401
                                                "sw     r0, r0, r3                              \n\t" \
402
                                                "addi r22, r22, -22                     \n\t" \
403
                                                "cmp r22, r22, r5                       \n\t" \
404
                                                "beqi r22, 12                           \n\t" \
405
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
406
                                                "sw     r0, r0, r3                              \n\t" \
407
                                                "addi r23, r23, -23                     \n\t" \
408
                                                "cmp r23, r23, r5                       \n\t" \
409
                                                "beqi r23, 12                           \n\t" \
410
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
411
                                                "sw     r0, r0, r3                              \n\t" \
412
                                                "addi r24, r24, -24                     \n\t" \
413
                                                "cmp r24, r24, r5                       \n\t" \
414
                                                "beqi r24, 12                           \n\t" \
415
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
416
                                                "sw     r0, r0, r3                              \n\t" \
417
                                                "addi r25, r25, -25                     \n\t" \
418
                                                "cmp r25, r25, r5                       \n\t" \
419
                                                "beqi r25, 12                           \n\t" \
420
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
421
                                                "sw     r0, r0, r3                              \n\t" \
422
                                                "addi r26, r26, -26                     \n\t" \
423
                                                "cmp r26, r26, r5                       \n\t" \
424
                                                "beqi r26, 12                           \n\t" \
425
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
426
                                                "sw     r0, r0, r3                              \n\t" \
427
                                                "addi r27, r27, -27                     \n\t" \
428
                                                "cmp r27, r27, r5                       \n\t" \
429
                                                "beqi r27, 12                           \n\t" \
430
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
431
                                                "sw     r0, r0, r3                              \n\t" \
432
                                                "addi r28, r28, -28                     \n\t" \
433
                                                "cmp r28, r28, r5                       \n\t" \
434
                                                "beqi r28, 12                           \n\t" \
435
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
436
                                                "sw     r0, r0, r3                              \n\t" \
437
                                                "addi r29, r29, -29                     \n\t" \
438
                                                "cmp r29, r29, r5                       \n\t" \
439
                                                "beqi r29, 12                           \n\t" \
440
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
441
                                                "sw     r0, r0, r3                              \n\t" \
442
                                                "addi r30, r30, -30                     \n\t" \
443
                                                "cmp r30, r30, r5                       \n\t" \
444
                                                "beqi r30, 12                           \n\t" \
445
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
446
                                                "sw     r0, r0, r3                              \n\t" \
447
                                                "addi r31, r31, -31                     \n\t" \
448
                                                "cmp r31, r31, r5                       \n\t" \
449
                                                "beqi r31, 12                           \n\t" \
450
                                                "lwi r3, r0, pulStatusAddr      \n\t" \
451
                                                "sw     r0, r0, r3                              \n\t"
452
                                        );
453
        }
454
}
455
 
456
 
457
 

powered by: WebSVN 2.1.0

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