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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [ColdFire_MCF52233_Eclipse/] [RTOSDemo/] [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
 * "uIP" task -  This is the task that handles the uIP stack.  All TCP/IP
62
 * processing is performed in this task.  It manages the WEB server functionality.
63
 *
64
 * "Check" task -  This only executes every five seconds but has a high priority
65
 * to ensure it gets processor time.  Its main function is to check that all the
66
 * standard demo tasks are still operational.  An error found in any task will be
67
 * latched in the ulErrorCode variable for display through the WEB server (the
68
 * error code is displayed at the foot of the table that contains information on
69
 * the state of each task).
70
 *
71
 * "Reg test" tasks - These fill the registers with known values, then check
72
 * that each register still contains its expected value.  Each task uses
73
 * different values.  The tasks run with very low priority so get preempted very
74
 * frequently.  A register containing an unexpected value is indicative of an
75
 * error in the context switching mechanism.
76
 *
77
 */
78
 
79
/* Standard includes. */
80
#include <stdio.h>
81
 
82
/* Scheduler includes. */
83
#include "FreeRTOS.h"
84
#include "task.h"
85
#include "queue.h"
86
#include "semphr.h"
87
 
88
/* Demo app includes. */
89
#include "BlockQ.h"
90
#include "death.h"
91
#include "blocktim.h"
92
#include "flash.h"
93
#include "partest.h"
94
#include "semtest.h"
95
#include "PollQ.h"
96
#include "GenQTest.h"
97
#include "QPeek.h"
98
#include "recmutex.h"
99
#include "IntQueue.h"
100
#include "comtest2.h"
101
 
102
/*-----------------------------------------------------------*/
103
 
104
/* The time between cycles of the 'check' functionality - as described at the
105
top of this file. */
106
#define mainCHECK_TASK_PERIOD                                   ( ( portTickType ) 5000 / portTICK_RATE_MS )
107
 
108
/* Task priorities. */
109
#define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )
110
#define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )
111
#define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )
112
#define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )
113
#define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )
114
 
115
/* The WEB server task uses more stack than most other tasks because of its
116
reliance on using sprintf(). */
117
#define mainBASIC_WEB_STACK_SIZE                        ( configMINIMAL_STACK_SIZE * 2 )
118
 
119
/*
120
 * Configure the hardware for the demo.
121
 */
122
static void prvSetupHardware( void );
123
 
124
/*
125
 * Implements the 'check' task functionality as described at the top of this
126
 * file.
127
 */
128
static void prvCheckTask( void *pvParameters );
129
 
130
/*
131
 * The task that implements the WEB server.
132
 */
133
extern void vuIP_Task( void *pvParameters );
134
 
135
/*
136
 * Implement the 'Reg test' functionality as described at the top of this file.
137
 */
138
static void vRegTest1Task( void *pvParameters );
139
static void vRegTest2Task( void *pvParameters );
140
 
141
/*-----------------------------------------------------------*/
142
 
143
/* Counters used to detect errors within the reg test tasks. */
144
static volatile unsigned portLONG ulRegTest1Counter = 0x11111111, ulRegTest2Counter = 0x22222222;
145
 
146
/* Any errors that the check task finds in any tasks are latched into
147
ulErrorCode, and then displayed via the WEB server. */
148
static unsigned portLONG ulErrorCode = 0UL;
149
 
150
/*-----------------------------------------------------------*/
151
 
152
int main( void )
153
{
154
        /* Setup the hardware ready for this demo. */
155
        prvSetupHardware();
156
 
157
        /* Create the WEB server task. */
158
        xTaskCreate( vuIP_Task, ( signed portCHAR * ) "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
159
 
160
        /* Start the standard demo tasks. */
161
        vStartLEDFlashTasks( tskIDLE_PRIORITY );
162
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
163
    vCreateBlockTimeTasks();
164
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
165
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
166
        vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
167
        vStartQueuePeekTasks();
168
    vStartRecursiveMutexTasks();
169
 
170
        /* Start the reg test tasks - defined in this file. */
171
        xTaskCreate( vRegTest1Task, ( signed portCHAR * ) "Reg1", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest1Counter, tskIDLE_PRIORITY, NULL );
172
        xTaskCreate( vRegTest2Task, ( signed portCHAR * ) "Reg2", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest2Counter, tskIDLE_PRIORITY, NULL );
173
 
174
        /* Create the check task. */
175
        xTaskCreate( prvCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
176
 
177
        /* Start the scheduler. */
178
        vTaskStartScheduler();
179
 
180
    /* Will only get here if there was insufficient heap to create the idle
181
    task. */
182
        for( ;; );
183
}
184
/*-----------------------------------------------------------*/
185
 
186
static void prvCheckTask( void *pvParameters )
187
{
188
unsigned ulLastRegTest1Count = 0, ulLastRegTest2Count = 0;
189
portTickType xLastExecutionTime;
190
 
191
        /* To prevent compiler warnings. */
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, mainCHECK_TASK_PERIOD );
202
 
203
                /* Has an error been found in any task? */
204
                if( xAreGenericQueueTasksStillRunning() != pdTRUE )
205
                {
206
                        ulErrorCode |= 0x01UL;
207
                }
208
 
209
                if( xAreQueuePeekTasksStillRunning() != pdTRUE )
210
                {
211
                        ulErrorCode |= 0x02UL;
212
                }
213
 
214
                if( xAreBlockingQueuesStillRunning() != pdTRUE )
215
                {
216
                        ulErrorCode |= 0x04UL;
217
                }
218
 
219
                if( xAreSemaphoreTasksStillRunning() != pdTRUE )
220
            {
221
                ulErrorCode |= 0x20UL;
222
            }
223
 
224
                if( xArePollingQueuesStillRunning() != pdTRUE )
225
            {
226
                ulErrorCode |= 0x40UL;
227
            }
228
 
229
                if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
230
                {
231
                        ulErrorCode |= 0x80UL;
232
                }
233
 
234
            if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
235
            {
236
                ulErrorCode |= 0x100UL;
237
            }
238
 
239
                if( ulLastRegTest1Count == ulRegTest1Counter )
240
                {
241
                        ulErrorCode |= 0x200UL;
242
                }
243
 
244
                if( ulLastRegTest2Count == ulRegTest2Counter )
245
                {
246
                        ulErrorCode |= 0x200UL;
247
                }
248
 
249
                /* Remember the reg test counts so a stall in their values can be
250
                detected next time around. */
251
                ulLastRegTest1Count = ulRegTest1Counter;
252
                ulLastRegTest2Count = ulRegTest2Counter;
253
        }
254
}
255
/*-----------------------------------------------------------*/
256
 
257
unsigned portLONG ulGetErrorCode( void )
258
{
259
        /* Returns the error code for display via the WEB server. */
260
        return ulErrorCode;
261
}
262
/*-----------------------------------------------------------*/
263
 
264
void prvSetupHardware( void )
265
{
266
__attribute__ ((section(".cfmconfig")))
267
static const unsigned long _cfm[6] = {
268
        0, /* KEY_UPPER 0x00000400 */
269
        0, /* KEY_LOWER 0x00000404 */
270
        0, /* CFMPROT 0x00000408 */
271
        0, /* CFMSACC 0x0000040C */
272
        0, /* CFMDACC 0x00000410 */
273
        0, /* CFMSEC 0x00000414 */
274
};
275
 
276
        /* Just to stop compiler warnings. */
277
        ( void ) _cfm;
278
 
279
        /* Ensure the watchdog is disabled. */
280
        MCF_SCM_CWCR = 0;
281
 
282
    /* Initialize IPSBAR (0x40000000). */
283
        asm volatile(
284
                "move.l  #0x40000000,%d0        \n"
285
                "andi.l  #0xC0000000,%d0        \n"
286
                "add.l   #0x1,%d0                       \n"
287
                "move.l  %d0,0x40000000         "
288
        );
289
 
290
    /* Initialize FLASHBAR (0x00) */
291
        asm volatile(
292
                "move.l  #0x00,%d0                      \n"
293
                "andi.l  #0xFFF80000,%d0        \n"
294
                "add.l   #0x41,%d0                      \n"
295
                "movec   %d0,%FLASHBAR          "
296
        );
297
 
298
        portDISABLE_INTERRUPTS();
299
 
300
        /* RAMBAR. */
301
        MCF_SCM_RAMBAR = MCF_SCM_RAMBAR_BA( RAMBAR_ADDRESS ) | MCF_SCM_RAMBAR_BDE;
302
 
303
        /* Multiply 25MHz crystal by 12 to get 60MHz clock. */
304
        MCF_CLOCK_SYNCR = MCF_CLOCK_SYNCR_MFD(4) | MCF_CLOCK_SYNCR_CLKSRC| MCF_CLOCK_SYNCR_PLLMODE | MCF_CLOCK_SYNCR_PLLEN ;
305
        while (!(MCF_CLOCK_SYNSR & MCF_CLOCK_SYNSR_LOCK))
306
        {
307
        }
308
 
309
        /* Setup the port used to toggle LEDs. */
310
        vParTestInitialise();
311
}
312
/*-----------------------------------------------------------*/
313
 
314
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )
315
{
316
        /* This will get called if a stack overflow is detected during the context
317
        switch.  Set configCHECK_FOR_STACK_OVERFLOWS to 2 to also check for stack
318
        problems within nested interrupts, but only do this for debug purposes as
319
        it will increase the context switch time. */
320
 
321
        ( void ) pxTask;
322
        ( void ) pcTaskName;
323
 
324
        for( ;; );
325
}
326
/*-----------------------------------------------------------*/
327
 
328
static void vRegTest1Task( void *pvParameters )
329
{
330
        /* Sanity check - did we receive the parameter expected? */
331
        if( pvParameters != &ulRegTest1Counter )
332
        {
333
                /* Change here so the check task can detect that an error occurred. */
334
                for( ;; );
335
        }
336
 
337
        /* Set all the registers to known values, then check that each retains its
338
        expected value - as described at the top of this file.  If an error is
339
        found then the loop counter will no longer be incremented allowing the check
340
        task to recognise the error. */
341
        asm volatile    (       "reg_test_1_start:                                              \n\t"
342
                                                "       moveq           #1, %d0                                 \n\t"
343
                                                "       moveq           #2, %d1                                 \n\t"
344
                                                "       moveq           #3, %d2                                 \n\t"
345
                                                "       moveq           #4, %d3                                 \n\t"
346
                                                "       moveq           #5, %d4                                 \n\t"
347
                                                "       moveq           #6, %d5                                 \n\t"
348
                                                "       moveq           #7, %d6                                 \n\t"
349
                                                "       moveq           #8, %d7                                 \n\t"
350
                                                "       move            #9, %a0                                 \n\t"
351
                                                "       move            #10, %a1                                \n\t"
352
                                                "       move            #11, %a2                                \n\t"
353
                                                "       move            #12, %a3                                \n\t"
354
                                                "       move            #13, %a4                                \n\t"
355
                                                "       move            #14, %a5                                \n\t"
356
                                                "       move            #15, %a6                                \n\t"
357
                                                "                                                                               \n\t"
358
                                                "       cmpi.l          #1, %d0                                 \n\t"
359
                                                "       bne                     reg_test_1_error                \n\t"
360
                                                "       cmpi.l          #2, %d1                                 \n\t"
361
                                                "       bne                     reg_test_1_error                \n\t"
362
                                                "       cmpi.l          #3, %d2                                 \n\t"
363
                                                "       bne                     reg_test_1_error                \n\t"
364
                                                "       cmpi.l          #4, %d3                                 \n\t"
365
                                                "       bne                     reg_test_1_error                \n\t"
366
                                                "       cmpi.l          #5, %d4                                 \n\t"
367
                                                "       bne                     reg_test_1_error                \n\t"
368
                                                "       cmpi.l          #6, %d5                                 \n\t"
369
                                                "       bne                     reg_test_1_error                \n\t"
370
                                                "       cmpi.l          #7, %d6                                 \n\t"
371
                                                "       bne                     reg_test_1_error                \n\t"
372
                                                "       cmpi.l          #8, %d7                                 \n\t"
373
                                                "       bne                     reg_test_1_error                \n\t"
374
                                                "       move            %a0, %d0                                \n\t"
375
                                                "       cmpi.l          #9, %d0                                 \n\t"
376
                                                "       bne                     reg_test_1_error                \n\t"
377
                                                "       move            %a1, %d0                                \n\t"
378
                                                "       cmpi.l          #10, %d0                                \n\t"
379
                                                "       bne                     reg_test_1_error                \n\t"
380
                                                "       move            %a2, %d0                                \n\t"
381
                                                "       cmpi.l          #11, %d0                                \n\t"
382
                                                "       bne                     reg_test_1_error                \n\t"
383
                                                "       move            %a3, %d0                                \n\t"
384
                                                "       cmpi.l          #12, %d0                                \n\t"
385
                                                "       bne                     reg_test_1_error                \n\t"
386
                                                "       move            %a4, %d0                                \n\t"
387
                                                "       cmpi.l          #13, %d0                                \n\t"
388
                                                "       bne                     reg_test_1_error                \n\t"
389
                                                "       move            %a5, %d0                                \n\t"
390
                                                "       cmpi.l          #14, %d0                                \n\t"
391
                                                "       bne                     reg_test_1_error                \n\t"
392
                                                "       move            %a6, %d0                                \n\t"
393
                                                "       cmpi.l          #15, %d0                                \n\t"
394
                                                "       bne                     reg_test_1_error                \n\t"
395
                                                "       movel           ulRegTest1Counter, %d0  \n\t"
396
                                                "       addql           #1, %d0                                 \n\t"
397
                                                "       movel           %d0, ulRegTest1Counter  \n\t"
398
                                                "       bra                     reg_test_1_start                \n\t"
399
                                                "reg_test_1_error:                                              \n\t"
400
                                                "       bra                     reg_test_1_error                \n\t"
401
                                        );
402
}
403
/*-----------------------------------------------------------*/
404
 
405
static void vRegTest2Task( void *pvParameters )
406
{
407
        /* Sanity check - did we receive the parameter expected? */
408
        if( pvParameters != &ulRegTest2Counter )
409
        {
410
                /* Change here so the check task can detect that an error occurred. */
411
                for( ;; );
412
        }
413
 
414
        /* Set all the registers to known values, then check that each retains its
415
        expected value - as described at the top of this file.  If an error is
416
        found then the loop counter will no longer be incremented allowing the check
417
        task to recognise the error. */
418
        asm volatile    (       "reg_test_2_start:                                              \n\t"
419
                                                "       moveq           #10, %d0                                \n\t"
420
                                                "       moveq           #20, %d1                                \n\t"
421
                                                "       moveq           #30, %d2                                \n\t"
422
                                                "       moveq           #40, %d3                                \n\t"
423
                                                "       moveq           #50, %d4                                \n\t"
424
                                                "       moveq           #60, %d5                                \n\t"
425
                                                "       moveq           #70, %d6                                \n\t"
426
                                                "       moveq           #80, %d7                                \n\t"
427
                                                "       move            #90, %a0                                \n\t"
428
                                                "       move            #100, %a1                               \n\t"
429
                                                "       move            #110, %a2                               \n\t"
430
                                                "       move            #120, %a3                               \n\t"
431
                                                "       move            #130, %a4                               \n\t"
432
                                                "       move            #140, %a5                               \n\t"
433
                                                "       move            #150, %a6                               \n\t"
434
                                                "                                                                               \n\t"
435
                                                "       cmpi.l          #10, %d0                                \n\t"
436
                                                "       bne                     reg_test_2_error                \n\t"
437
                                                "       cmpi.l          #20, %d1                                \n\t"
438
                                                "       bne                     reg_test_2_error                \n\t"
439
                                                "       cmpi.l          #30, %d2                                \n\t"
440
                                                "       bne                     reg_test_2_error                \n\t"
441
                                                "       cmpi.l          #40, %d3                                \n\t"
442
                                                "       bne                     reg_test_2_error                \n\t"
443
                                                "       cmpi.l          #50, %d4                                \n\t"
444
                                                "       bne                     reg_test_2_error                \n\t"
445
                                                "       cmpi.l          #60, %d5                                \n\t"
446
                                                "       bne                     reg_test_2_error                \n\t"
447
                                                "       cmpi.l          #70, %d6                                \n\t"
448
                                                "       bne                     reg_test_2_error                \n\t"
449
                                                "       cmpi.l          #80, %d7                                \n\t"
450
                                                "       bne                     reg_test_2_error                \n\t"
451
                                                "       move            %a0, %d0                                \n\t"
452
                                                "       cmpi.l          #90, %d0                                \n\t"
453
                                                "       bne                     reg_test_2_error                \n\t"
454
                                                "       move            %a1, %d0                                \n\t"
455
                                                "       cmpi.l          #100, %d0                               \n\t"
456
                                                "       bne                     reg_test_2_error                \n\t"
457
                                                "       move            %a2, %d0                                \n\t"
458
                                                "       cmpi.l          #110, %d0                               \n\t"
459
                                                "       bne                     reg_test_2_error                \n\t"
460
                                                "       move            %a3, %d0                                \n\t"
461
                                                "       cmpi.l          #120, %d0                               \n\t"
462
                                                "       bne                     reg_test_2_error                \n\t"
463
                                                "       move            %a4, %d0                                \n\t"
464
                                                "       cmpi.l          #130, %d0                               \n\t"
465
                                                "       bne                     reg_test_2_error                \n\t"
466
                                                "       move            %a5, %d0                                \n\t"
467
                                                "       cmpi.l          #140, %d0                               \n\t"
468
                                                "       bne                     reg_test_2_error                \n\t"
469
                                                "       move            %a6, %d0                                \n\t"
470
                                                "       cmpi.l          #150, %d0                               \n\t"
471
                                                "       bne                     reg_test_2_error                \n\t"
472
                                                "       movel           ulRegTest1Counter, %d0  \n\t"
473
                                                "       addql           #1, %d0                                 \n\t"
474
                                                "       movel           %d0, ulRegTest2Counter  \n\t"
475
                                                "       bra                     reg_test_2_start                \n\t"
476
                                                "reg_test_2_error:                                              \n\t"
477
                                                "       bra                     reg_test_2_error                \n\t"
478
                                        );
479
}
480
/*-----------------------------------------------------------*/
481
 

powered by: WebSVN 2.1.0

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