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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 577 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
        NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
56
        The processor MUST be in supervisor mode when vTaskStartScheduler is
57
        called.  The demo applications included in the FreeRTOS.org download switch
58
        to supervisor mode prior to main being called.  If you are not using one of
59
        these demo application projects then ensure Supervisor mode is used.
60
*/
61
 
62
/*
63
 * Creates all the demo application tasks, then starts the scheduler.  The WEB
64
 * documentation provides more details of the demo application tasks.
65
 *
66
 * A few tasks are created that are not part of the standard demo.  These are
67
 * the 'LCD' task, the 'LCD Message' task, a WEB server task and the 'Check'
68
 * task.
69
 *
70
 * The LCD task is the only task that accesses the LCD directly, so mutual
71
 * exclusion is ensured.  Any task wishing to display text sends the LCD task
72
 * a message containing a pointer to the string that should be displayed.
73
 * The LCD task itself just blocks on a queue waiting for such a message to
74
 * arrive - processing each in turn.
75
 *
76
 * The LCD Message task does nothing other than periodically send messages to
77
 * the LCD task.  The messages originating from the LCD Message task are
78
 * displayed on the top row of the LCD.
79
 *
80
 * The Check task only executes every three seconds but has the highest
81
 * priority so is guaranteed to get processor time.  Its main function is to
82
 * check that all the other tasks are still operational. Most tasks maintain
83
 * a unique count that is incremented each time the task successfully completes
84
 * a cycle of its function.  Should any error occur within such a task the
85
 * count is permanently halted.  The check task sets a bit in an error status
86
 * flag should it find any counter variable at a value that indicates an
87
 * error has occurred.  The error flag value is converted to a string and sent
88
 * to the LCD task for display on the bottom row on the LCD.
89
 */
90
 
91
/* Standard includes. */
92
#include <stdio.h>
93
 
94
/* Library includes. */
95
#include "91x_lib.h"
96
 
97
/* Scheduler includes. */
98
#include "FreeRTOS.h"
99
#include "task.h"
100
#include "queue.h"
101
 
102
/* Demo application includes. */
103
#include "lcd.h"
104
#include "flash.h"
105
#include "integer.h"
106
#include "PollQ.h"
107
#include "BlockQ.h"
108
#include "semtest.h"
109
#include "dynamic.h"
110
#include "partest.h"
111
#include "flop.h"
112
#include "comtest2.h"
113
#include "serial.h"
114
#include "GenQTest.h"
115
#include "QPeek.h"
116
 
117
#ifdef STACK_LWIP
118
        #include "BasicWEB.h"
119
        #include "sys.h"
120
#endif
121
 
122
/* Priorities for the demo application tasks. */
123
#define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )
124
#define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )
125
#define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )
126
#define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )
127
#define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )
128
#define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 3 )
129
#define mainLCD_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )
130
#define mainMSG_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )
131
#define mainGENERIC_QUEUE_PRIORITY      ( tskIDLE_PRIORITY )
132
 
133
/* Delays used by the various tasks defined in this file. */
134
#define mainCHECK_PERIOD                        ( ( portTickType ) 3000 / portTICK_RATE_MS  )
135
#define mainSTRING_WRITE_DELAY          ( 500 / portTICK_RATE_MS )
136
#define mainLCD_DELAY                           ( 20 / portTICK_RATE_MS )
137
 
138
/* Constants for the ComTest tasks. */
139
#define mainCOM_TEST_BAUD_RATE          ( ( unsigned long ) 115200 )
140
#define mainCOM_TEST_LED                        ( 3 )
141
 
142
/* The maximum number of messages that can be pending to be written to the LCD. */
143
#define mainLCD_QUEUE_LEN                       ( 6 )
144
 
145
/* Dimension the buffer used to write the error flag string. */
146
#define mainMAX_FLAG_STRING_LEN         ( 32 )
147
 
148
/* The structure that is passed on the LCD message queue. */
149
typedef struct
150
{
151
        char **ppcMessageToDisplay; /*<< Points to a char* pointing to the message to display. */
152
        portBASE_TYPE xRow;                             /*<< The row on which the message should be displayed. */
153
} xLCDMessage;
154
/*-----------------------------------------------------------*/
155
 
156
/*
157
 * The task that executes at the highest priority and calls
158
 * prvCheckOtherTasksAreStillRunning().  See the description at the top
159
 * of the file.
160
 */
161
static void vErrorChecks( void *pvParameters );
162
 
163
/*
164
 * Configure the processor clock and ports.
165
 */
166
static void prvSetupHardware( void );
167
 
168
/*
169
 * Checks that all the demo application tasks are still executing without error
170
 * - as described at the top of the file.  Called by vErrorChecks().
171
 */
172
static void prvCheckOtherTasksAreStillRunning( void );
173
 
174
#ifdef STACK_UIP
175
        /*
176
         * The WEB server task prototype.  The task is created in this file but defined
177
         * elsewhere.  STACK_UIP is defined when the uIP stack is used in preference
178
         * to the lwIP stack.
179
         */
180
        extern void vuIP_Task(void *pvParameters);
181
#endif
182
 
183
/*
184
 * The task that displays text on the LCD.
185
 */
186
static void prvLCDTask( void * pvParameters );
187
 
188
/*
189
 * The task that sends messages to be displayed on the top row of the LCD.
190
 */
191
static void prvLCDMessageTask( void * pvParameters );
192
 
193
/*-----------------------------------------------------------*/
194
 
195
/* The queue used to pass messages to the LCD task. */
196
static xQueueHandle xLCDQueue;
197
 
198
/* Error status flag. */
199
static unsigned long ulErrorFlags = 0;
200
 
201
/*-----------------------------------------------------------*/
202
 
203
/*
204
 * Starts all the other tasks, then starts the scheduler.
205
 */
206
void main( void )
207
{
208
        #ifdef DEBUG
209
                debug();
210
        #endif
211
 
212
        /* Setup any hardware that has not already been configured by the low
213
        level init routines. */
214
        prvSetupHardware();
215
        /* Create the queue used to send data to the LCD task. */
216
        xLCDQueue = xQueueCreate( mainLCD_QUEUE_LEN, sizeof( xLCDMessage ) );
217
 
218
        /* Start all the standard demo application tasks. */
219
        vStartIntegerMathTasks( tskIDLE_PRIORITY );
220
        vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
221
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
222
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
223
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
224
        vStartDynamicPriorityTasks();
225
        vStartMathTasks( tskIDLE_PRIORITY );
226
        vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
227
        vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
228
        vStartQueuePeekTasks();
229
 
230
        /* Start the tasks which are defined in this file. */
231
        xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
232
        xTaskCreate( prvLCDTask, "LCD", configMINIMAL_STACK_SIZE, ( void * ) &xLCDQueue, mainLCD_TASK_PRIORITY, NULL );
233
        xTaskCreate( prvLCDMessageTask, "MSG", configMINIMAL_STACK_SIZE, ( void * ) &xLCDQueue, mainMSG_TASK_PRIORITY, NULL );
234
 
235
        /* Start either the uIP TCP/IP stack or the lwIP TCP/IP stack. */
236
        #ifdef STACK_UIP
237
                /* Finally, create the WEB server task. */
238
                xTaskCreate( vuIP_Task, "uIP", configMINIMAL_STACK_SIZE * 3, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
239
        #endif
240
 
241
        #ifdef STACK_LWIP       
242
                /* Create the lwIP task.  This uses the lwIP RTOS abstraction layer.*/
243
                vlwIPInit();
244
                sys_set_state(  ( signed char * ) "httpd", lwipBASIC_SERVER_STACK_SIZE );
245
                sys_thread_new( vBasicWEBServer, ( void * ) NULL, basicwebWEBSERVER_PRIORITY );
246
                sys_set_default_state();
247
        #endif
248
 
249
        /* Start the scheduler.
250
 
251
        NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
252
        The processor MUST be in supervisor mode when vTaskStartScheduler is
253
        called.  The demo applications included in the FreeRTOS.org download switch
254
        to supervisor mode prior to main being called.  If you are not using one of
255
        these demo application projects then ensure Supervisor mode is used here. */
256
 
257
        vTaskStartScheduler();
258
 
259
        /* We should never get here as control is now taken by the scheduler. */
260
        for( ;; );
261
}
262
/*-----------------------------------------------------------*/
263
 
264
static void prvSetupHardware( void )
265
{
266
        /* Configuration taken from the ST code.
267
 
268
        Set Flash banks size & address */
269
        FMI_BankRemapConfig( 4, 2, 0, 0x80000 );
270
 
271
        /* FMI Waite States */
272
        FMI_Config( FMI_READ_WAIT_STATE_2, FMI_WRITE_WAIT_STATE_0, FMI_PWD_ENABLE, FMI_LVD_ENABLE, FMI_FREQ_HIGH );
273
 
274
        /* Configure the FPLL = 96MHz, and APB to 48MHz. */
275
        SCU_PCLKDivisorConfig( SCU_PCLK_Div2 );
276
        SCU_PLLFactorsConfig( 192, 25, 2 );
277
        SCU_PLLCmd( ENABLE );
278
        SCU_MCLKSourceConfig( SCU_MCLK_PLL );
279
 
280
        WDG_Cmd( DISABLE );
281
        VIC_DeInit();
282
 
283
        /* GPIO8 clock source enable, used by the LCD. */
284
        SCU_APBPeriphClockConfig(__GPIO8, ENABLE);
285
        GPIO_DeInit(GPIO8);
286
 
287
        /* GPIO 9 clock source enable, used by the LCD. */
288
        SCU_APBPeriphClockConfig(__GPIO9, ENABLE);
289
        GPIO_DeInit(GPIO9);
290
 
291
        /* Enable VIC clock */
292
        SCU_AHBPeriphClockConfig(__VIC, ENABLE);
293
        SCU_AHBPeriphReset(__VIC, DISABLE);
294
 
295
        /* Peripheral initialisation. */
296
        vParTestInitialise();
297
}
298
/*-----------------------------------------------------------*/
299
 
300
static void vErrorChecks( void *pvParameters )
301
{
302
static char cCheckVal[ mainMAX_FLAG_STRING_LEN ];
303
char *pcFlagString;
304
xLCDMessage xMessageToSend;
305
portTickType xLastWakeTime;
306
char *pcStringsToDisplay[] = {
307
                                                                        "Check status flag"
308
                                                                 };
309
 
310
        /* The parameters are not used in this task. */
311
        ( void ) pvParameters;
312
 
313
        pcFlagString = &cCheckVal[ 0 ];
314
 
315
        /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()
316
        functions correctly. */
317
        xLastWakeTime = xTaskGetTickCount();
318
 
319
        /* Cycle for ever, delaying then checking all the other tasks are still
320
        operating without error. */
321
        for( ;; )
322
        {
323
                /* Delay until it is time to execute again. */
324
                vTaskDelayUntil( &xLastWakeTime, mainCHECK_PERIOD );
325
 
326
                /* Check all the other tasks to see if the error flag needs updating. */
327
                prvCheckOtherTasksAreStillRunning();
328
 
329
                /* Create a string indicating the error flag status. */
330
                sprintf( cCheckVal, "equals 0x%x       ", ulErrorFlags );
331
                xMessageToSend.xRow = Line2;
332
 
333
                /* Send the first part of the message to the LCD task. */
334
                xMessageToSend.ppcMessageToDisplay = &pcStringsToDisplay[ 0 ];
335
                xQueueSend( xLCDQueue, ( void * ) &xMessageToSend, 0 );
336
                vTaskDelay( mainSTRING_WRITE_DELAY );
337
 
338
                /* Send the second part of the message to the LCD task. */
339
                xMessageToSend.ppcMessageToDisplay = &pcFlagString;
340
                xQueueSend( xLCDQueue, ( void * ) &xMessageToSend, 0 );
341
        }
342
}
343
/*-----------------------------------------------------------*/
344
 
345
static void prvCheckOtherTasksAreStillRunning( void )
346
{
347
        if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
348
        {
349
                ulErrorFlags |= 0x01;
350
        }
351
 
352
        if( xArePollingQueuesStillRunning() != pdTRUE )
353
        {
354
                ulErrorFlags |=  0x02;
355
        }
356
 
357
        if( xAreSemaphoreTasksStillRunning() != pdTRUE )
358
        {
359
                ulErrorFlags |= 0x04;
360
        }
361
 
362
        if( xAreBlockingQueuesStillRunning() != pdTRUE )
363
        {
364
                ulErrorFlags |= 0x08;
365
        }
366
 
367
        if( xAreComTestTasksStillRunning() != pdTRUE )
368
        {
369
                ulErrorFlags |= 0x10;
370
        }
371
 
372
        if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
373
        {
374
                ulErrorFlags |= 0x20;
375
        }
376
 
377
        if( xAreMathsTaskStillRunning() != pdTRUE )
378
        {
379
                ulErrorFlags |= 0x40;
380
        }
381
 
382
        if( xAreGenericQueueTasksStillRunning() != pdTRUE )
383
        {
384
                ulErrorFlags |= 0x80;
385
        }
386
 
387
        if( xAreQueuePeekTasksStillRunning() != pdTRUE )
388
        {
389
                ulErrorFlags |= 0x100;
390
        }
391
 
392
}
393
/*-----------------------------------------------------------*/
394
 
395
static void prvLCDMessageTask( void * pvParameters )
396
{
397
xQueueHandle *pxLCDQueue;
398
xLCDMessage xMessageToSend;
399
portBASE_TYPE xIndex = 0;
400
 
401
/* The strings that are written to the LCD. */
402
char *pcStringsToDisplay[] = {
403
                                                                        "IAR             ",
404
                                                                        "STR912          ",
405
                                                                        "Demo            ",
406
                                                                        "www.FreeRTOS.org",
407
                                                                        ""
408
                                                                };
409
 
410
 
411
        /* To test the parameter passing mechanism, the queue on which messages are
412
        posted is passed in as a parameter even though it is available as a file
413
        scope variable anyway. */
414
        pxLCDQueue = ( xQueueHandle * ) pvParameters;
415
 
416
        for( ;; )
417
        {
418
                /* Wait until it is time to move onto the next string. */
419
                vTaskDelay( mainSTRING_WRITE_DELAY );
420
 
421
                /* Configure the message object to send to the LCD task. */
422
                xMessageToSend.ppcMessageToDisplay = &pcStringsToDisplay[ xIndex ];
423
                xMessageToSend.xRow = Line1;
424
 
425
                /* Post the message to be displayed. */
426
                xQueueSend( *pxLCDQueue, ( void * ) &xMessageToSend, 0 );
427
 
428
                /* Move onto the next message, wrapping when necessary. */
429
                xIndex++;
430
                if( *( pcStringsToDisplay[ xIndex ] ) == 0x00 )
431
                {
432
                        xIndex = 0;
433
 
434
                        /* Delay longer before going back to the start of the messages. */
435
                        vTaskDelay( mainSTRING_WRITE_DELAY * 2 );
436
                }
437
        }
438
}
439
/*-----------------------------------------------------------*/
440
 
441
void prvLCDTask( void * pvParameters )
442
{
443
xQueueHandle *pxLCDQueue;
444
xLCDMessage xReceivedMessage;
445
char *pcString;
446
 
447
        /* To test the parameter passing mechanism, the queue on which messages are
448
        received is passed in as a parameter even though it is available as a file
449
        scope variable anyway. */
450
        pxLCDQueue = ( xQueueHandle * ) pvParameters;
451
 
452
        LCD_Init();
453
 
454
        for( ;; )
455
        {
456
                /* Wait for a message to arrive. */
457
                if( xQueueReceive( *pxLCDQueue, &xReceivedMessage, portMAX_DELAY ) )
458
                {
459
                        /* Where is the string we are going to display? */
460
                        pcString = *xReceivedMessage.ppcMessageToDisplay;
461
                        LCD_DisplayString(xReceivedMessage.xRow, pcString, BlackText);
462
 
463
                        /* The delay here is just to ensure the LCD task does not starve
464
                        out lower priority tasks as writing to the LCD can take a long
465
                        time. */
466
                        vTaskDelay( mainLCD_DELAY );
467
                }
468
        }
469
}
470
/*-----------------------------------------------------------*/

powered by: WebSVN 2.1.0

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