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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [ColdFire_MCF5282_Eclipse/] [RTOSDemo/] [main.c] - Blame information for rev 797

Go to most recent revision | 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 "death.h"
88
#include "integer.h"
89
#include "flash.h"
90
#include "partest.h"
91
#include "semtest.h"
92
#include "PollQ.h"
93
#include "GenQTest.h"
94
#include "QPeek.h"
95
#include "recmutex.h"
96
#include "IntQueue.h"
97
#include "comtest2.h"
98
 
99
/*-----------------------------------------------------------*/
100
 
101
/* The time between cycles of the 'check' functionality - as described at the
102
top of this file. */
103
#define mainNO_ERROR_PERIOD                                     ( ( portTickType ) 5000 / portTICK_RATE_MS )
104
 
105
/* The rate at which the LED controlled by the 'check' task will flash should an
106
error have been detected. */
107
#define mainERROR_PERIOD                                        ( ( portTickType ) 500 / portTICK_RATE_MS )
108
 
109
/* The LED controlled by the 'check' task. */
110
#define mainCHECK_LED                                           ( 3 )
111
 
112
/* ComTest constants - there is no free LED for the comtest tasks. */
113
#define mainCOM_TEST_BAUD_RATE                          ( ( unsigned portLONG ) 19200 )
114
#define mainCOM_TEST_LED                                        ( 5 )
115
 
116
/* Task priorities. */
117
#define mainCOM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 2 )
118
#define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )
119
#define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )
120
#define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )
121
#define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )
122
#define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )
123
#define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )
124
#define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )
125
 
126
/*
127
 * Configure the hardware for the demo.
128
 */
129
static void prvSetupHardware( void );
130
 
131
/*
132
 * Implements the 'check' task functionality as described at the top of this
133
 * file.
134
 */
135
static void prvCheckTask( void *pvParameters );
136
 
137
/*
138
 * Implement the 'Reg test' functionality as described at the top of this file.
139
 */
140
static void vRegTest1Task( void *pvParameters );
141
static void vRegTest2Task( void *pvParameters );
142
 
143
/*-----------------------------------------------------------*/
144
 
145
/* Counters used to detect errors within the reg test tasks. */
146
static volatile unsigned portLONG ulRegTest1Counter = 0x11111111, ulRegTest2Counter = 0x22222222;
147
 
148
/*-----------------------------------------------------------*/
149
 
150
int main( void )
151
{
152
        /* Setup the hardware ready for this demo. */
153
        prvSetupHardware();
154
 
155
        /* Start the standard demo tasks. */
156
        vStartLEDFlashTasks( tskIDLE_PRIORITY );
157
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
158
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
159
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
160
        vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
161
        vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
162
        vStartQueuePeekTasks();
163
        vStartRecursiveMutexTasks();
164
        vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
165
        vStartInterruptQueueTasks();
166
 
167
        /* Start the reg test tasks - defined in this file. */
168
        xTaskCreate( vRegTest1Task, ( signed portCHAR * ) "Reg1", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest1Counter, tskIDLE_PRIORITY, NULL );
169
        xTaskCreate( vRegTest2Task, ( signed portCHAR * ) "Reg2", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest2Counter, tskIDLE_PRIORITY, NULL );
170
 
171
        /* Create the check task. */
172
        xTaskCreate( prvCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
173
 
174
        /* The suicide tasks must be created last as they need to know how many
175
        tasks were running prior to their creation in order to ascertain whether
176
        or not the correct/expected number of tasks are running at any given time. */
177
    vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
178
 
179
        /* Start the scheduler. */
180
        vTaskStartScheduler();
181
 
182
    /* Will only get here if there was insufficient memory to create the idle
183
    task. */
184
        for( ;; );
185
}
186
/*-----------------------------------------------------------*/
187
 
188
static void prvCheckTask( void *pvParameters )
189
{
190
unsigned ulTicksToWait = mainNO_ERROR_PERIOD, ulError = 0, ulLastRegTest1Count = 0, ulLastRegTest2Count = 0;
191
portTickType xLastExecutionTime;
192
 
193
        ( void ) pvParameters;
194
 
195
        /* Initialise the variable used to control our iteration rate prior to
196
        its first use. */
197
        xLastExecutionTime = xTaskGetTickCount();
198
 
199
        for( ;; )
200
        {
201
                /* Wait until it is time to run the tests again. */
202
                vTaskDelayUntil( &xLastExecutionTime, ulTicksToWait );
203
 
204
                /* Has an error been found in any task? */
205
                if( xAreGenericQueueTasksStillRunning() != pdTRUE )
206
                {
207
                        ulError |= 0x01UL;
208
                }
209
 
210
                if( xAreQueuePeekTasksStillRunning() != pdTRUE )
211
                {
212
                        ulError |= 0x02UL;
213
                }
214
 
215
                if( xAreBlockingQueuesStillRunning() != pdTRUE )
216
                {
217
                        ulError |= 0x04UL;
218
                }
219
 
220
                if( xAreSemaphoreTasksStillRunning() != pdTRUE )
221
            {
222
                ulError |= 0x20UL;
223
            }
224
 
225
                if( xArePollingQueuesStillRunning() != pdTRUE )
226
            {
227
                ulError |= 0x40UL;
228
            }
229
 
230
                if( xIsCreateTaskStillRunning() != pdTRUE )
231
            {
232
                ulError |= 0x80UL;
233
            }
234
 
235
                if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
236
            {
237
                ulError |= 0x100UL;
238
            }
239
 
240
                if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
241
            {
242
                ulError |= 0x200UL;
243
            }
244
 
245
                if( xAreComTestTasksStillRunning() != pdTRUE )
246
                {
247
                ulError |= 0x400UL;
248
                }
249
 
250
                if( xAreIntQueueTasksStillRunning() != pdTRUE )
251
            {
252
                ulError |= 0x800UL;
253
            }
254
 
255
                if( ulLastRegTest1Count == ulRegTest1Counter )
256
                {
257
                        ulError |= 0x1000UL;
258
                }
259
 
260
                if( ulLastRegTest2Count == ulRegTest2Counter )
261
                {
262
                        ulError |= 0x1000UL;
263
                }
264
 
265
                ulLastRegTest1Count = ulRegTest1Counter;
266
                ulLastRegTest2Count = ulRegTest2Counter;
267
 
268
                /* If an error has been found then increase our cycle rate, and in so
269
                going increase the rate at which the check task LED toggles. */
270
                if( ulError != 0 )
271
                {
272
                ulTicksToWait = mainERROR_PERIOD;
273
                }
274
 
275
                /* Toggle the LED each itteration. */
276
                vParTestToggleLED( mainCHECK_LED );
277
        }
278
}
279
/*-----------------------------------------------------------*/
280
 
281
void prvSetupHardware( void )
282
{
283
extern void mcf5xxx_wr_cacr( unsigned portLONG );
284
 
285
        portDISABLE_INTERRUPTS();
286
 
287
        /* Enable the cache. */
288
        mcf5xxx_wr_cacr( MCF5XXX_CACR_CENB | MCF5XXX_CACR_CINV | MCF5XXX_CACR_DISD | MCF5XXX_CACR_CEIB | MCF5XXX_CACR_CLNF_00 );
289
        asm volatile( "NOP" ); /* As per errata. */
290
 
291
        /* Multiply 8Mhz reference crystal by 8 to achieve system clock of 64Mhz. */
292
        MCF_CLOCK_SYNCR = MCF_CLOCK_SYNCR_MFD( 2 );
293
 
294
        /* Wait for PLL to lock. */
295
        while( !( MCF_CLOCK_SYNSR & MCF_CLOCK_SYNSR_LOCK ) )
296
        {
297
                __asm__ volatile ( "NOP" );
298
        }
299
 
300
        /* Setup the port used to toggle LEDs. */
301
        vParTestInitialise();
302
}
303
/*-----------------------------------------------------------*/
304
 
305
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )
306
{
307
        /* This will get called if a stack overflow is detected during the context
308
        switch.  Set configCHECK_FOR_STACK_OVERFLOWS to 2 to also check for stack
309
        problems within nested interrupts, but only do this for debug purposes as
310
        it will increase the context switch time. */
311
 
312
        ( void ) pxTask;
313
        ( void ) pcTaskName;
314
 
315
        for( ;; );
316
}
317
/*-----------------------------------------------------------*/
318
 
319
static void vRegTest1Task( void *pvParameters )
320
{
321
        /* Sanity check - did we receive the parameter expected? */
322
        if( pvParameters != &ulRegTest1Counter )
323
        {
324
                /* Change here so the check task can detect that an error occurred. */
325
                for( ;; );
326
        }
327
 
328
        /* Set all the registers to known values, then check that each retains its
329
        expected value - as described at the top of this file.  If an error is
330
        found then the loop counter will no longer be incremented allowing the check
331
        task to recognise the error. */
332
        asm volatile    (       "reg_test_1_start:                                              \n\t"
333
                                                "       moveq           #1, %d0                                 \n\t"
334
                                                "       moveq           #2, %d1                                 \n\t"
335
                                                "       moveq           #3, %d2                                 \n\t"
336
                                                "       moveq           #4, %d3                                 \n\t"
337
                                                "       moveq           #5, %d4                                 \n\t"
338
                                                "       moveq           #6, %d5                                 \n\t"
339
                                                "       moveq           #7, %d6                                 \n\t"
340
                                                "       moveq           #8, %d7                                 \n\t"
341
                                                "       move            #9, %a0                                 \n\t"
342
                                                "       move            #10, %a1                                \n\t"
343
                                                "       move            #11, %a2                                \n\t"
344
                                                "       move            #12, %a3                                \n\t"
345
                                                "       move            #13, %a4                                \n\t"
346
                                                "       move            #14, %a5                                \n\t"
347
                                                "       move            #15, %a6                                \n\t"
348
                                                "                                                                               \n\t"
349
                                                "       cmpi.l          #1, %d0                                 \n\t"
350
                                                "       bne                     reg_test_1_error                \n\t"
351
                                                "       cmpi.l          #2, %d1                                 \n\t"
352
                                                "       bne                     reg_test_1_error                \n\t"
353
                                                "       cmpi.l          #3, %d2                                 \n\t"
354
                                                "       bne                     reg_test_1_error                \n\t"
355
                                                "       cmpi.l          #4, %d3                                 \n\t"
356
                                                "       bne                     reg_test_1_error                \n\t"
357
                                                "       cmpi.l          #5, %d4                                 \n\t"
358
                                                "       bne                     reg_test_1_error                \n\t"
359
                                                "       cmpi.l          #6, %d5                                 \n\t"
360
                                                "       bne                     reg_test_1_error                \n\t"
361
                                                "       cmpi.l          #7, %d6                                 \n\t"
362
                                                "       bne                     reg_test_1_error                \n\t"
363
                                                "       cmpi.l          #8, %d7                                 \n\t"
364
                                                "       bne                     reg_test_1_error                \n\t"
365
                                                "       move            %a0, %d0                                \n\t"
366
                                                "       cmpi.l          #9, %d0                                 \n\t"
367
                                                "       bne                     reg_test_1_error                \n\t"
368
                                                "       move            %a1, %d0                                \n\t"
369
                                                "       cmpi.l          #10, %d0                                \n\t"
370
                                                "       bne                     reg_test_1_error                \n\t"
371
                                                "       move            %a2, %d0                                \n\t"
372
                                                "       cmpi.l          #11, %d0                                \n\t"
373
                                                "       bne                     reg_test_1_error                \n\t"
374
                                                "       move            %a3, %d0                                \n\t"
375
                                                "       cmpi.l          #12, %d0                                \n\t"
376
                                                "       bne                     reg_test_1_error                \n\t"
377
                                                "       move            %a4, %d0                                \n\t"
378
                                                "       cmpi.l          #13, %d0                                \n\t"
379
                                                "       bne                     reg_test_1_error                \n\t"
380
                                                "       move            %a5, %d0                                \n\t"
381
                                                "       cmpi.l          #14, %d0                                \n\t"
382
                                                "       bne                     reg_test_1_error                \n\t"
383
                                                "       move            %a6, %d0                                \n\t"
384
                                                "       cmpi.l          #15, %d0                                \n\t"
385
                                                "       bne                     reg_test_1_error                \n\t"
386
                                                "       movel           ulRegTest1Counter, %d0  \n\t"
387
                                                "       addql           #1, %d0                                 \n\t"
388
                                                "       movel           %d0, ulRegTest1Counter  \n\t"
389
                                                "       bra                     reg_test_1_start                \n\t"
390
                                                "reg_test_1_error:                                              \n\t"
391
                                                "       bra                     reg_test_1_error                \n\t"
392
                                        );
393
}
394
/*-----------------------------------------------------------*/
395
 
396
static void vRegTest2Task( void *pvParameters )
397
{
398
        /* Sanity check - did we receive the parameter expected? */
399
        if( pvParameters != &ulRegTest2Counter )
400
        {
401
                /* Change here so the check task can detect that an error occurred. */
402
                for( ;; );
403
        }
404
 
405
        /* Set all the registers to known values, then check that each retains its
406
        expected value - as described at the top of this file.  If an error is
407
        found then the loop counter will no longer be incremented allowing the check
408
        task to recognise the error. */
409
        asm volatile    (       "reg_test_2_start:                                              \n\t"
410
                                                "       moveq           #10, %d0                                \n\t"
411
                                                "       moveq           #20, %d1                                \n\t"
412
                                                "       moveq           #30, %d2                                \n\t"
413
                                                "       moveq           #40, %d3                                \n\t"
414
                                                "       moveq           #50, %d4                                \n\t"
415
                                                "       moveq           #60, %d5                                \n\t"
416
                                                "       moveq           #70, %d6                                \n\t"
417
                                                "       moveq           #80, %d7                                \n\t"
418
                                                "       move            #90, %a0                                \n\t"
419
                                                "       move            #100, %a1                               \n\t"
420
                                                "       move            #110, %a2                               \n\t"
421
                                                "       move            #120, %a3                               \n\t"
422
                                                "       move            #130, %a4                               \n\t"
423
                                                "       move            #140, %a5                               \n\t"
424
                                                "       move            #150, %a6                               \n\t"
425
                                                "                                                                               \n\t"
426
                                                "       cmpi.l          #10, %d0                                \n\t"
427
                                                "       bne                     reg_test_2_error                \n\t"
428
                                                "       cmpi.l          #20, %d1                                \n\t"
429
                                                "       bne                     reg_test_2_error                \n\t"
430
                                                "       cmpi.l          #30, %d2                                \n\t"
431
                                                "       bne                     reg_test_2_error                \n\t"
432
                                                "       cmpi.l          #40, %d3                                \n\t"
433
                                                "       bne                     reg_test_2_error                \n\t"
434
                                                "       cmpi.l          #50, %d4                                \n\t"
435
                                                "       bne                     reg_test_2_error                \n\t"
436
                                                "       cmpi.l          #60, %d5                                \n\t"
437
                                                "       bne                     reg_test_2_error                \n\t"
438
                                                "       cmpi.l          #70, %d6                                \n\t"
439
                                                "       bne                     reg_test_2_error                \n\t"
440
                                                "       cmpi.l          #80, %d7                                \n\t"
441
                                                "       bne                     reg_test_2_error                \n\t"
442
                                                "       move            %a0, %d0                                \n\t"
443
                                                "       cmpi.l          #90, %d0                                \n\t"
444
                                                "       bne                     reg_test_2_error                \n\t"
445
                                                "       move            %a1, %d0                                \n\t"
446
                                                "       cmpi.l          #100, %d0                               \n\t"
447
                                                "       bne                     reg_test_2_error                \n\t"
448
                                                "       move            %a2, %d0                                \n\t"
449
                                                "       cmpi.l          #110, %d0                               \n\t"
450
                                                "       bne                     reg_test_2_error                \n\t"
451
                                                "       move            %a3, %d0                                \n\t"
452
                                                "       cmpi.l          #120, %d0                               \n\t"
453
                                                "       bne                     reg_test_2_error                \n\t"
454
                                                "       move            %a4, %d0                                \n\t"
455
                                                "       cmpi.l          #130, %d0                               \n\t"
456
                                                "       bne                     reg_test_2_error                \n\t"
457
                                                "       move            %a5, %d0                                \n\t"
458
                                                "       cmpi.l          #140, %d0                               \n\t"
459
                                                "       bne                     reg_test_2_error                \n\t"
460
                                                "       move            %a6, %d0                                \n\t"
461
                                                "       cmpi.l          #150, %d0                               \n\t"
462
                                                "       bne                     reg_test_2_error                \n\t"
463
                                                "       movel           ulRegTest1Counter, %d0  \n\t"
464
                                                "       addql           #1, %d0                                 \n\t"
465
                                                "       movel           %d0, ulRegTest2Counter  \n\t"
466
                                                "       bra                     reg_test_2_start                \n\t"
467
                                                "reg_test_2_error:                                              \n\t"
468
                                                "       bra                     reg_test_2_error                \n\t"
469
                                        );
470
}
471
/*-----------------------------------------------------------*/
472
 

powered by: WebSVN 2.1.0

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