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

Subversion Repositories openrisc

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

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
 * "Web server" - Very basic demonstration of the lwIP stack.  The WEB server
62
 * simply generates a page that shows the current state of all the tasks within
63
 * the system, including the high water mark of each task stack. The high water
64
 * mark is displayed as the amount of stack that has never been used, so the
65
 * closer the value is to zero the closer the task has come to overflowing its
66
 * stack.  The IP address and net mask are set within FreeRTOSConfig.h.
67
 *
68
 * "Check" task -  This only executes every five seconds but has a high priority
69
 * to ensure it gets processor time.  Its main function is to check that all the
70
 * standard demo tasks are still operational.  While no errors have been
71
 * discovered the check task will toggle an LED every 5 seconds - the toggle
72
 * rate increasing to 500ms being a visual indication that at least one task has
73
 * reported unexpected behaviour.
74
 *
75
 * "Reg test" tasks - These fill the registers with known values, then check
76
 * that each register still contains its expected value.  Each task uses
77
 * different values.  The tasks run with very low priority so get preempted very
78
 * frequently.  A register containing an unexpected value is indicative of an
79
 * error in the context switching mechanism.
80
 *
81
 */
82
 
83
/* Standard includes. */
84
#include <stdio.h>
85
 
86
/* Scheduler includes. */
87
#include "FreeRTOS.h"
88
#include "task.h"
89
#include "queue.h"
90
#include "semphr.h"
91
 
92
/* Demo app includes. */
93
#include "BlockQ.h"
94
#include "death.h"
95
#include "flash.h"
96
#include "partest.h"
97
#include "semtest.h"
98
#include "PollQ.h"
99
#include "GenQTest.h"
100
#include "QPeek.h"
101
#include "recmutex.h"
102
 
103
/*-----------------------------------------------------------*/
104
 
105
/* The time between cycles of the 'check' functionality - as described at the
106
top of this file. */
107
#define mainNO_ERROR_PERIOD                                     ( ( portTickType ) 5000 / portTICK_RATE_MS )
108
 
109
/* The rate at which the LED controlled by the 'check' task will flash should an
110
error have been detected. */
111
#define mainERROR_PERIOD                                        ( ( portTickType ) 500 / portTICK_RATE_MS )
112
 
113
/* The LED controlled by the 'check' task. */
114
#define mainCHECK_LED                                           ( 3 )
115
 
116
/* ComTest constants - there is no free LED for the comtest tasks. */
117
#define mainCOM_TEST_BAUD_RATE                          ( ( unsigned portLONG ) 19200 )
118
#define mainCOM_TEST_LED                                        ( 5 )
119
 
120
/* Task priorities. */
121
#define mainCOM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 2 )
122
#define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )
123
#define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )
124
#define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )
125
#define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )
126
#define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )
127
#define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )
128
#define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )
129
#define mainWEB_TASK_PRIORITY                   ( tskIDLE_PRIORITY + 2 )
130
 
131
/*
132
 * Configure the hardware for the demo.
133
 */
134
static void prvSetupHardware( void );
135
 
136
/*
137
 * Implements the 'check' task functionality as described at the top of this
138
 * file.
139
 */
140
static void prvCheckTask( void *pvParameters );
141
 
142
/*
143
 * Implement the 'Reg test' functionality as described at the top of this file.
144
 */
145
static void vRegTest1Task( void *pvParameters );
146
static void vRegTest2Task( void *pvParameters );
147
 
148
/*-----------------------------------------------------------*/
149
 
150
/* Counters used to detect errors within the reg test tasks. */
151
static volatile unsigned portLONG ulRegTest1Counter = 0x11111111, ulRegTest2Counter = 0x22222222;
152
 
153
/*-----------------------------------------------------------*/
154
 
155
int main( void )
156
{
157
extern void vBasicWEBServer( void *pv );
158
 
159
        /* Setup the hardware ready for this demo. */
160
        prvSetupHardware();
161
        ( void )sys_thread_new("HTTPD", vBasicWEBServer, NULL, 320, mainWEB_TASK_PRIORITY );
162
 
163
        /* Start the standard demo tasks. */
164
        vStartLEDFlashTasks( tskIDLE_PRIORITY );
165
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
166
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
167
        vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
168
        vStartQueuePeekTasks();
169
        vStartRecursiveMutexTasks();
170
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
171
 
172
        /* Start the reg test tasks - defined in this file. */
173
        xTaskCreate( vRegTest1Task, ( signed portCHAR * ) "Reg1", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest1Counter, tskIDLE_PRIORITY, NULL );
174
        xTaskCreate( vRegTest2Task, ( signed portCHAR * ) "Reg2", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest2Counter, tskIDLE_PRIORITY, NULL );
175
 
176
        /* Create the check task. */
177
        xTaskCreate( prvCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
178
 
179
        /* The suicide tasks must be created last as they need to know how many
180
        tasks were running prior to their creation in order to ascertain whether
181
        or not the correct/expected number of tasks are running at any given time. */
182
    vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
183
 
184
        /* Start the scheduler. */
185
        vTaskStartScheduler();
186
 
187
    /* Will only get here if there was insufficient memory to create the idle
188
    task. */
189
        for( ;; )
190
        {
191
        }
192
}
193
/*-----------------------------------------------------------*/
194
 
195
static void prvCheckTask( void *pvParameters )
196
{
197
unsigned ulTicksToWait = mainNO_ERROR_PERIOD, ulError = 0, ulLastRegTest1Count = 0, ulLastRegTest2Count = 0;
198
portTickType xLastExecutionTime;
199
 
200
        ( void ) pvParameters;
201
 
202
        /* Initialise the variable used to control our iteration rate prior to
203
        its first use. */
204
        xLastExecutionTime = xTaskGetTickCount();
205
 
206
        for( ;; )
207
        {
208
                /* Wait until it is time to run the tests again. */
209
                vTaskDelayUntil( &xLastExecutionTime, ulTicksToWait );
210
 
211
                /* Has an error been found in any task? */
212
                if( xAreGenericQueueTasksStillRunning() != pdTRUE )
213
                {
214
                        ulError |= 0x01UL;
215
                }
216
 
217
                if( xAreQueuePeekTasksStillRunning() != pdTRUE )
218
                {
219
                        ulError |= 0x02UL;
220
                }
221
 
222
                if( xAreBlockingQueuesStillRunning() != pdTRUE )
223
                {
224
                        ulError |= 0x04UL;
225
                }
226
 
227
                if( xAreSemaphoreTasksStillRunning() != pdTRUE )
228
            {
229
                ulError |= 0x20UL;
230
            }
231
 
232
                if( xArePollingQueuesStillRunning() != pdTRUE )
233
            {
234
                ulError |= 0x40UL;
235
            }
236
 
237
                if( xIsCreateTaskStillRunning() != pdTRUE )
238
            {
239
                ulError |= 0x80UL;
240
            }
241
 
242
                if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
243
            {
244
                ulError |= 0x200UL;
245
            }
246
 
247
                if( ulLastRegTest1Count == ulRegTest1Counter )
248
                {
249
                        ulError |= 0x1000UL;
250
                }
251
 
252
                if( ulLastRegTest2Count == ulRegTest2Counter )
253
                {
254
                        ulError |= 0x1000UL;
255
                }
256
 
257
                ulLastRegTest1Count = ulRegTest1Counter;
258
                ulLastRegTest2Count = ulRegTest2Counter;
259
 
260
                /* If an error has been found then increase our cycle rate, and in so
261
                going increase the rate at which the check task LED toggles. */
262
                if( ulError != 0 )
263
                {
264
                ulTicksToWait = mainERROR_PERIOD;
265
                }
266
 
267
                /* Toggle the LED each itteration. */
268
                vParTestToggleLED( mainCHECK_LED );
269
        }
270
}
271
/*-----------------------------------------------------------*/
272
 
273
void prvSetupHardware( void )
274
{
275
        portDISABLE_INTERRUPTS();
276
 
277
        /* Setup the port used to toggle LEDs. */
278
        vParTestInitialise();
279
}
280
/*-----------------------------------------------------------*/
281
 
282
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )
283
{
284
        /* This will get called if a stack overflow is detected during the context
285
        switch.  Set configCHECK_FOR_STACK_OVERFLOWS to 2 to also check for stack
286
        problems within nested interrupts, but only do this for debug purposes as
287
        it will increase the context switch time. */
288
 
289
        ( void ) pxTask;
290
        ( void ) pcTaskName;
291
 
292
        for( ;; )
293
        {
294
        }
295
}
296
/*-----------------------------------------------------------*/
297
 
298
static void vRegTest1Task( void *pvParameters )
299
{
300
        /* Sanity check - did we receive the parameter expected? */
301
        if( pvParameters != &ulRegTest1Counter )
302
        {
303
                /* Change here so the check task can detect that an error occurred. */
304
                for( ;; )
305
                {
306
                }
307
        }
308
 
309
        /* Set all the registers to known values, then check that each retains its
310
        expected value - as described at the top of this file.  If an error is
311
        found then the loop counter will no longer be incremented allowing the check
312
        task to recognise the error. */
313
        asm volatile    (       "reg_test_1_start:                                              \n\t"
314
                                                "       moveq           #1, d0                                  \n\t"
315
                                                "       moveq           #2, d1                                  \n\t"
316
                                                "       moveq           #3, d2                                  \n\t"
317
                                                "       moveq           #4, d3                                  \n\t"
318
                                                "       moveq           #5, d4                                  \n\t"
319
                                                "       moveq           #6, d5                                  \n\t"
320
                                                "       moveq           #7, d6                                  \n\t"
321
                                                "       moveq           #8, d7                                  \n\t"
322
                                                "       move            #9, a0                                  \n\t"
323
                                                "       move            #10, a1                                 \n\t"
324
                                                "       move            #11, a2                                 \n\t"
325
                                                "       move            #12, a3                                 \n\t"
326
                                                "       move            #13, a4                                 \n\t"
327
                                                "       move            #14, a5                                 \n\t"
328
                                                "       move            #15, a6                                 \n\t"
329
                                                "                                                                               \n\t"
330
                                                "       cmpi.l          #1, d0                                  \n\t"
331
                                                "       bne                     reg_test_1_error                \n\t"
332
                                                "       cmpi.l          #2, d1                                  \n\t"
333
                                                "       bne                     reg_test_1_error                \n\t"
334
                                                "       cmpi.l          #3, d2                                  \n\t"
335
                                                "       bne                     reg_test_1_error                \n\t"
336
                                                "       cmpi.l          #4, d3                                  \n\t"
337
                                                "       bne                     reg_test_1_error                \n\t"
338
                                                "       cmpi.l          #5, d4                                  \n\t"
339
                                                "       bne                     reg_test_1_error                \n\t"
340
                                                "       cmpi.l          #6, d5                                  \n\t"
341
                                                "       bne                     reg_test_1_error                \n\t"
342
                                                "       cmpi.l          #7, d6                                  \n\t"
343
                                                "       bne                     reg_test_1_error                \n\t"
344
                                                "       cmpi.l          #8, d7                                  \n\t"
345
                                                "       bne                     reg_test_1_error                \n\t"
346
                                                "       move            a0, d0                                  \n\t"
347
                                                "       cmpi.l          #9, d0                                  \n\t"
348
                                                "       bne                     reg_test_1_error                \n\t"
349
                                                "       move            a1, d0                                  \n\t"
350
                                                "       cmpi.l          #10, d0                                 \n\t"
351
                                                "       bne                     reg_test_1_error                \n\t"
352
                                                "       move            a2, d0                                  \n\t"
353
                                                "       cmpi.l          #11, d0                                 \n\t"
354
                                                "       bne                     reg_test_1_error                \n\t"
355
                                                "       move            a3, d0                                  \n\t"
356
                                                "       cmpi.l          #12, d0                                 \n\t"
357
                                                "       bne                     reg_test_1_error                \n\t"
358
                                                "       move            a4, d0                                  \n\t"
359
                                                "       cmpi.l          #13, d0                                 \n\t"
360
                                                "       bne                     reg_test_1_error                \n\t"
361
                                                "       move            a5, d0                                  \n\t"
362
                                                "       cmpi.l          #14, d0                                 \n\t"
363
                                                "       bne                     reg_test_1_error                \n\t"
364
                                                "       move            a6, d0                                  \n\t"
365
                                                "       cmpi.l          #15, d0                                 \n\t"
366
                                                "       bne                     reg_test_1_error                \n\t"
367
                                                "       move            ulRegTest1Counter, d0   \n\t"
368
                                                "       addq            #1, d0                                  \n\t"
369
                                                "       move            d0, ulRegTest1Counter   \n\t"
370
                                                "       bra                     reg_test_1_start                \n\t"
371
                                                "reg_test_1_error:                                              \n\t"
372
                                                "       bra                     reg_test_1_error                \n\t"
373
                                        );
374
}
375
/*-----------------------------------------------------------*/
376
 
377
static void vRegTest2Task( void *pvParameters )
378
{
379
        /* Sanity check - did we receive the parameter expected? */
380
        if( pvParameters != &ulRegTest2Counter )
381
        {
382
                /* Change here so the check task can detect that an error occurred. */
383
                for( ;; )
384
                {
385
                }
386
        }
387
 
388
        /* Set all the registers to known values, then check that each retains its
389
        expected value - as described at the top of this file.  If an error is
390
        found then the loop counter will no longer be incremented allowing the check
391
        task to recognise the error. */
392
        asm volatile    (       "reg_test_2_start:                                              \n\t"
393
                                                "       moveq           #10, d0                                 \n\t"
394
                                                "       moveq           #20, d1                                 \n\t"
395
                                                "       moveq           #30, d2                                 \n\t"
396
                                                "       moveq           #40, d3                                 \n\t"
397
                                                "       moveq           #50, d4                                 \n\t"
398
                                                "       moveq           #60, d5                                 \n\t"
399
                                                "       moveq           #70, d6                                 \n\t"
400
                                                "       moveq           #80, d7                                 \n\t"
401
                                                "       move            #90, a0                                 \n\t"
402
                                                "       move            #100, a1                                \n\t"
403
                                                "       move            #110, a2                                \n\t"
404
                                                "       move            #120, a3                                \n\t"
405
                                                "       move            #130, a4                                \n\t"
406
                                                "       move            #140, a5                                \n\t"
407
                                                "       move            #150, a6                                \n\t"
408
                                                "                                                                               \n\t"
409
                                                "       cmpi.l          #10, d0                                 \n\t"
410
                                                "       bne                     reg_test_2_error                \n\t"
411
                                                "       cmpi.l          #20, d1                                 \n\t"
412
                                                "       bne                     reg_test_2_error                \n\t"
413
                                                "       cmpi.l          #30, d2                                 \n\t"
414
                                                "       bne                     reg_test_2_error                \n\t"
415
                                                "       cmpi.l          #40, d3                                 \n\t"
416
                                                "       bne                     reg_test_2_error                \n\t"
417
                                                "       cmpi.l          #50, d4                                 \n\t"
418
                                                "       bne                     reg_test_2_error                \n\t"
419
                                                "       cmpi.l          #60, d5                                 \n\t"
420
                                                "       bne                     reg_test_2_error                \n\t"
421
                                                "       cmpi.l          #70, d6                                 \n\t"
422
                                                "       bne                     reg_test_2_error                \n\t"
423
                                                "       cmpi.l          #80, d7                                 \n\t"
424
                                                "       bne                     reg_test_2_error                \n\t"
425
                                                "       move            a0, d0                                  \n\t"
426
                                                "       cmpi.l          #90, d0                                 \n\t"
427
                                                "       bne                     reg_test_2_error                \n\t"
428
                                                "       move            a1, d0                                  \n\t"
429
                                                "       cmpi.l          #100, d0                                \n\t"
430
                                                "       bne                     reg_test_2_error                \n\t"
431
                                                "       move            a2, d0                                  \n\t"
432
                                                "       cmpi.l          #110, d0                                \n\t"
433
                                                "       bne                     reg_test_2_error                \n\t"
434
                                                "       move            a3, d0                                  \n\t"
435
                                                "       cmpi.l          #120, d0                                \n\t"
436
                                                "       bne                     reg_test_2_error                \n\t"
437
                                                "       move            a4, d0                                  \n\t"
438
                                                "       cmpi.l          #130, d0                                \n\t"
439
                                                "       bne                     reg_test_2_error                \n\t"
440
                                                "       move            a5, d0                                  \n\t"
441
                                                "       cmpi.l          #140, d0                                \n\t"
442
                                                "       bne                     reg_test_2_error                \n\t"
443
                                                "       move            a6, d0                                  \n\t"
444
                                                "       cmpi.l          #150, d0                                \n\t"
445
                                                "       bne                     reg_test_2_error                \n\t"
446
                                                "       move            ulRegTest1Counter, d0   \n\t"
447
                                                "       addq            #1, d0                                  \n\t"
448
                                                "       move            d0, ulRegTest2Counter   \n\t"
449
                                                "       bra                     reg_test_2_start                \n\t"
450
                                                "reg_test_2_error:                                              \n\t"
451
                                                "       bra                     reg_test_2_error                \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.