OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

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

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
 * Creates all the demo application tasks, then starts the scheduler.  The WEB
56
 * documentation provides more details of the standard demo application tasks.
57
 * In addition to the standard demo tasks, the following tasks and tests are
58
 * defined and/or created within this file:
59
 *
60
 * "LCD" task - the LCD task is a 'gatekeeper' task.  It is the only task that
61
 * is permitted to access the display directly.  Other tasks wishing to write a
62
 * message to the LCD send the message on a queue to the LCD task instead of
63
 * accessing the LCD themselves.  The LCD task just blocks on the queue waiting
64
 * for messages - waking and displaying the messages as they arrive.
65
 *
66
 * "Check" hook -  This only executes every five seconds from the tick hook.
67
 * Its main function is to check that all the standard demo tasks are still
68
 * operational.  Should any unexpected behaviour within a demo task be discovered
69
 * the tick hook will write an error to the LCD (via the LCD task).  If all the
70
 * demo tasks are executing with their expected behaviour then the check task
71
 * writes PASS to the LCD (again via the LCD task), as described above.
72
 *
73
 * "uIP" task -  This is the task that handles the uIP stack.  All TCP/IP
74
 * processing is performed in this task.
75
 */
76
 
77
/* Scheduler includes. */
78
#include "FreeRTOS.h"
79
#include "task.h"
80
#include "queue.h"
81
#include "semphr.h"
82
 
83
/* Demo app includes. */
84
#include "BlockQ.h"
85
#include "death.h"
86
#include "blocktim.h"
87
#include "LCD/portlcd.h"
88
#include "flash.h"
89
#include "partest.h"
90
#include "GenQTest.h"
91
#include "QPeek.h"
92
#include "dynamic.h"
93
 
94
/* Demo application definitions. */
95
#define mainQUEUE_SIZE                                          ( 3 )
96
#define mainCHECK_DELAY                                         ( ( portTickType ) 5000 / portTICK_RATE_MS )
97
#define mainBASIC_WEB_STACK_SIZE            ( configMINIMAL_STACK_SIZE * 6 )
98
 
99
/* Task priorities. */
100
#define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )
101
#define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )
102
#define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )
103
#define mainFLASH_PRIORITY                  ( tskIDLE_PRIORITY + 2 )
104
#define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )
105
#define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY ) 
106
 
107
/* Constants to setup the PLL. */
108
#define mainPLL_MUL                     ( ( unsigned portLONG ) ( 8 - 1 ) )
109
#define mainPLL_DIV                     ( ( unsigned portLONG ) 0x0000 )
110
#define mainCPU_CLK_DIV         ( ( unsigned portLONG ) 0x0003 )
111
#define mainPLL_ENABLE          ( ( unsigned portLONG ) 0x0001 )
112
#define mainPLL_CONNECT         ( ( ( unsigned portLONG ) 0x0002 ) | mainPLL_ENABLE )
113
#define mainPLL_FEED_BYTE1      ( ( unsigned portLONG ) 0xaa )
114
#define mainPLL_FEED_BYTE2      ( ( unsigned portLONG ) 0x55 )
115
#define mainPLL_LOCK            ( ( unsigned portLONG ) 0x4000000 )
116
#define mainPLL_CONNECTED       ( ( unsigned portLONG ) 0x2000000 )
117
#define mainOSC_ENABLE          ( ( unsigned portLONG ) 0x20 )
118
#define mainOSC_STAT            ( ( unsigned portLONG ) 0x40 )
119
#define mainOSC_SELECT          ( ( unsigned portLONG ) 0x01 )
120
 
121
/* Constants to setup the MAM. */
122
#define mainMAM_TIM_3           ( ( unsigned portCHAR ) 0x03 )
123
#define mainMAM_MODE_FULL       ( ( unsigned portCHAR ) 0x02 )
124
 
125
/*
126
 * The task that handles the uIP stack.  All TCP/IP processing is performed in
127
 * this task.
128
 */
129
extern void vuIP_Task( void *pvParameters );
130
 
131
/*
132
 * The LCD is written two by more than one task so is controlled by a
133
 * 'gatekeeper' task.  This is the only task that is actually permitted to
134
 * access the LCD directly.  Other tasks wanting to display a message send
135
 * the message to the gatekeeper.
136
 */
137
static void vLCDTask( void *pvParameters );
138
 
139
/* Configure the hardware as required by the demo. */
140
static void prvSetupHardware( void );
141
 
142
/* The queue used to send messages to the LCD task. */
143
xQueueHandle xLCDQueue;
144
 
145
/*-----------------------------------------------------------*/
146
 
147
int main( void )
148
{
149
        prvSetupHardware();
150
 
151
        /* Create the queue used by the LCD task.  Messages for display on the LCD
152
        are received via this queue. */
153
        xLCDQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( xLCDMessage ) );
154
 
155
        /* Create the uIP task.  This uses the lwIP RTOS abstraction layer.*/
156
    xTaskCreate( vuIP_Task, ( signed portCHAR * ) "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
157
 
158
        /* Start the standard demo tasks. */
159
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
160
    vCreateBlockTimeTasks();
161
    vStartLEDFlashTasks( mainFLASH_PRIORITY );
162
    vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
163
    vStartQueuePeekTasks();
164
    vStartDynamicPriorityTasks();
165
 
166
        /* Start the tasks defined within this file/specific to this demo. */
167
        xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
168
 
169
        /* Start the scheduler. */
170
        vTaskStartScheduler();
171
 
172
    /* Will only get here if there was insufficient memory to create the idle
173
    task. */
174
        return 0;
175
}
176
/*-----------------------------------------------------------*/
177
 
178
void vApplicationTickHook( void )
179
{
180
unsigned portBASE_TYPE uxColumn = 0;
181
static xLCDMessage xMessage = { 0, "PASS" };
182
static unsigned portLONG ulTicksSinceLastDisplay = 0;
183
static portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
184
 
185
        /* Called from every tick interrupt.  Have enough ticks passed to make it
186
        time to perform our health status check again? */
187
        ulTicksSinceLastDisplay++;
188
        if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )
189
        {
190
                ulTicksSinceLastDisplay = 0;
191
 
192
                /* Has an error been found in any task? */
193
 
194
        if( xAreBlockingQueuesStillRunning() != pdTRUE )
195
                {
196
                        xMessage.pcMessage = "ERROR - BLOCKQ";
197
                }
198
 
199
                if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
200
                {
201
                        xMessage.pcMessage = "ERROR - BLOCKTIM";
202
                }
203
 
204
                if( xAreGenericQueueTasksStillRunning() != pdTRUE )
205
                {
206
                        xMessage.pcMessage = "ERROR - GENQ";
207
                }
208
 
209
                if( xAreQueuePeekTasksStillRunning() != pdTRUE )
210
                {
211
                        xMessage.pcMessage = "ERROR - PEEKQ";
212
                }
213
 
214
                if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
215
                {
216
                        xMessage.pcMessage = "ERROR - DYNAMIC";
217
                }
218
 
219
        xMessage.xColumn++;
220
 
221
                /* Send the message to the LCD gatekeeper for display. */
222
                xHigherPriorityTaskWoken = pdFALSE;
223
                xQueueSendToBackFromISR( xLCDQueue, &xMessage, &xHigherPriorityTaskWoken );
224
        }
225
}
226
/*-----------------------------------------------------------*/
227
 
228
void vLCDTask( void *pvParameters )
229
{
230
xLCDMessage xMessage;
231
 
232
        /* Initialise the LCD and display a startup message. */
233
        LCD_init();
234
        LCD_cur_off();
235
    LCD_cls();
236
    LCD_gotoxy( 1, 1 );
237
    LCD_puts( "www.FreeRTOS.org" );
238
 
239
        for( ;; )
240
        {
241
                /* Wait for a message to arrive that requires displaying. */
242
                while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
243
 
244
                /* Display the message.  Print each message to a different position. */
245
                LCD_cls();
246
                LCD_gotoxy( ( xMessage.xColumn & 0x07 ) + 1, ( xMessage.xColumn & 0x01 ) + 1 );
247
                LCD_puts( xMessage.pcMessage );
248
        }
249
 
250
}
251
/*-----------------------------------------------------------*/
252
 
253
static void prvSetupHardware( void )
254
{
255
        #ifdef RUN_FROM_RAM
256
                /* Remap the interrupt vectors to RAM if we are are running from RAM. */
257
                SCB_MEMMAP = 2;
258
        #endif
259
 
260
        /* Disable the PLL. */
261
        PLLCON = 0;
262
        PLLFEED = mainPLL_FEED_BYTE1;
263
        PLLFEED = mainPLL_FEED_BYTE2;
264
 
265
        /* Configure clock source. */
266
        SCS |= mainOSC_ENABLE;
267
        while( !( SCS & mainOSC_STAT ) );
268
        CLKSRCSEL = mainOSC_SELECT;
269
 
270
        /* Setup the PLL to multiply the XTAL input by 4. */
271
        PLLCFG = ( mainPLL_MUL | mainPLL_DIV );
272
        PLLFEED = mainPLL_FEED_BYTE1;
273
        PLLFEED = mainPLL_FEED_BYTE2;
274
 
275
        /* Turn on and wait for the PLL to lock... */
276
        PLLCON = mainPLL_ENABLE;
277
        PLLFEED = mainPLL_FEED_BYTE1;
278
        PLLFEED = mainPLL_FEED_BYTE2;
279
        CCLKCFG = mainCPU_CLK_DIV;
280
        while( !( PLLSTAT & mainPLL_LOCK ) );
281
 
282
        /* Connecting the clock. */
283
        PLLCON = mainPLL_CONNECT;
284
        PLLFEED = mainPLL_FEED_BYTE1;
285
        PLLFEED = mainPLL_FEED_BYTE2;
286
        while( !( PLLSTAT & mainPLL_CONNECTED ) );
287
 
288
        /*
289
        This code is commented out as the MAM does not work on the original revision
290
        LPC2368 chips.  If using Rev B chips then you can increase the speed though
291
        the use of the MAM.
292
 
293
        Setup and turn on the MAM.  Three cycle access is used due to the fast
294
        PLL used.  It is possible faster overall performance could be obtained by
295
        tuning the MAM and PLL settings.
296
        MAMCR = 0;
297
        MAMTIM = mainMAM_TIM_3;
298
        MAMCR = mainMAM_MODE_FULL;
299
        */
300
 
301
        /* Setup the led's on the MCB2300 board */
302
        vParTestInitialise();
303
}
304
 
305
 
306
 
307
 
308
 
309
 
310
 

powered by: WebSVN 2.1.0

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