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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 585 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
/*
64
 * Program entry point.
65
 *
66
 * main() is responsible for setting up the microcontroller peripherals, then
67
 * starting the demo application tasks.  Once the tasks have been created the
68
 * scheduler is started and main() should never complete.
69
 *
70
 * The demo creates the three standard 'flash' tasks to provide some visual
71
 * feedback that the system and scheduler are still operating correctly.
72
 *
73
 * The HTTP server task operates at the highest priority so will always preempt
74
 * the flash or idle task on TCP/IP events.
75
 */
76
 
77
/* Standard includes. */
78
#include <stdlib.h>
79
 
80
/* Scheduler include files. */
81
#include "FreeRTOS.h"
82
#include "semphr.h"
83
#include "task.h"
84
 
85
/* Application includes. */
86
#include "i2c.h"
87
#include "HTTP_Serv.h"
88
#include "flash.h"
89
#include "partest.h"
90
#include "dynamic.h"
91
#include "semtest.h"
92
#include "PollQ.h"
93
#include "BlockQ.h"
94
#include "integer.h"
95
 
96
/*-----------------------------------------------------------*/
97
 
98
/* Constants to setup the PLL. */
99
#define mainPLL_MUL_4           ( ( unsigned char ) 0x0003 )
100
#define mainPLL_DIV_1           ( ( unsigned char ) 0x0000 )
101
#define mainPLL_ENABLE          ( ( unsigned char ) 0x0001 )
102
#define mainPLL_CONNECT         ( ( unsigned char ) 0x0003 )
103
#define mainPLL_FEED_BYTE1      ( ( unsigned char ) 0xaa )
104
#define mainPLL_FEED_BYTE2      ( ( unsigned char ) 0x55 )
105
#define mainPLL_LOCK            ( ( unsigned long ) 0x0400 )
106
 
107
/* Constants to setup the MAM. */
108
#define mainMAM_TIM_3           ( ( unsigned char ) 0x03 )
109
#define mainMAM_MODE_FULL       ( ( unsigned char ) 0x02 )
110
 
111
/* Constants to setup the peripheral bus. */
112
#define mainBUS_CLK_FULL        ( ( unsigned char ) 0x01 )
113
 
114
/* Constants to setup I/O and processor. */
115
#define mainBUS_CLK_FULL        ( ( unsigned char ) 0x01 )
116
#define mainLED_TO_OUTPUT       ( ( unsigned long ) 0xff0000 )
117
#define mainJTAG_PORT           ( ( unsigned long ) 0x3E0000UL )
118
 
119
/* Priorities for the demo application tasks. */
120
#define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )
121
#define mainHTTP_TASK_PRIORITY          ( tskIDLE_PRIORITY + 2 )
122
#define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )
123
#define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )
124
#define mainERROR_CHECK_PRIORITY        ( tskIDLE_PRIORITY + 1 )
125
 
126
/* Flash rates of the on board LED to indicate the health of the system. */
127
#define mainNO_ERROR_DELAY                      ( 3000 )
128
#define mainERROR_DELAY                         ( 500 )
129
#define mainON_BOARD_LED_BIT            ( ( unsigned long ) 0x80 )
130
 
131
/*-----------------------------------------------------------*/
132
 
133
/*
134
 * The Olimex demo board has a single built in LED.  This function simply
135
 * toggles its state.
136
 */
137
void prvToggleOnBoardLED( void );
138
 
139
/*
140
 * Configure the processor for use with the Olimex demo board.
141
 */
142
static void prvSetupHardware( void );
143
 
144
/*
145
 * Simply check for errors and toggle the onboard LED.
146
 */
147
static void prvErrorChecks( void *pvParameters );
148
 
149
/*
150
 * Return true if the demo tasks are executing without error - otherwise
151
 * return false.
152
 */
153
static void prvMainCheckOtherTasksAreStillRunning( void );
154
/*-----------------------------------------------------------*/
155
 
156
/* Flag set by prvMainCheckOtherTasksAreStillExecuting(). */
157
long lErrorInTask = pdFALSE;
158
 
159
/*
160
 * Application entry point:
161
 * Starts all the other tasks, then starts the scheduler.
162
 */
163
int main( void )
164
{
165
        /* Setup the hardware for use with the Olimex demo board. */
166
        prvSetupHardware();
167
 
168
        /* Start the standard flash tasks so the WEB server is not the only thing
169
        running. */
170
        vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
171
        vStartSemaphoreTasks( tskIDLE_PRIORITY );
172
        vStartDynamicPriorityTasks();
173
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
174
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
175
        vStartIntegerMathTasks( tskIDLE_PRIORITY );
176
 
177
        /* Start the WEB server task and the error check task. */
178
        xTaskCreate( vHTTPServerTask, ( signed char * ) "HTTP", configMINIMAL_STACK_SIZE, NULL, mainHTTP_TASK_PRIORITY, NULL );
179
        xTaskCreate( prvErrorChecks, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainERROR_CHECK_PRIORITY, NULL );
180
 
181
        /* Now all the tasks have been started - start the scheduler.
182
 
183
        NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
184
        The processor MUST be in supervisor mode when vTaskStartScheduler is
185
        called.  The demo applications included in the FreeRTOS.org download switch
186
        to supervisor mode prior to main being called.  If you are not using one of
187
        these demo application projects then ensure Supervisor mode is used. */
188
        vTaskStartScheduler();
189
 
190
        /* Should never reach here! */
191
        return 0;
192
}
193
/*-----------------------------------------------------------*/
194
 
195
static void prvSetupHardware( void )
196
{
197
        #ifdef RUN_FROM_RAM
198
                /* Remap the interrupt vectors to RAM if we are are running from RAM. */
199
                SCB_MEMMAP = 2;
200
        #endif
201
 
202
        /* Set all GPIO to output other than the P0.14 (BSL), and the JTAG pins.
203
        The JTAG pins are left as input as I'm not sure what will happen if the
204
        Wiggler is connected after powerup - not that it would be a good idea to
205
        do that anyway. */
206
        GPIO_IODIR = ~( mainJTAG_PORT );
207
 
208
        /* Setup the PLL to multiply the XTAL input by 4. */
209
        SCB_PLLCFG = ( mainPLL_MUL_4 | mainPLL_DIV_1 );
210
 
211
        /* Activate the PLL by turning it on then feeding the correct sequence of
212
        bytes. */
213
        SCB_PLLCON = mainPLL_ENABLE;
214
        SCB_PLLFEED = mainPLL_FEED_BYTE1;
215
        SCB_PLLFEED = mainPLL_FEED_BYTE2;
216
 
217
        /* Wait for the PLL to lock... */
218
        while( !( SCB_PLLSTAT & mainPLL_LOCK ) );
219
 
220
        /* ...before connecting it using the feed sequence again. */
221
        SCB_PLLCON = mainPLL_CONNECT;
222
        SCB_PLLFEED = mainPLL_FEED_BYTE1;
223
        SCB_PLLFEED = mainPLL_FEED_BYTE2;
224
 
225
        /* Setup and turn on the MAM.  Three cycle access is used due to the fast
226
        PLL used.  It is possible faster overall performance could be obtained by
227
        tuning the MAM and PLL settings. */
228
        MAM_TIM = mainMAM_TIM_3;
229
        MAM_CR = mainMAM_MODE_FULL;
230
 
231
        /* Setup the peripheral bus to be the same as the PLL output. */
232
        SCB_VPBDIV = mainBUS_CLK_FULL;
233
 
234
        /* Initialise the i2c peripheral. */
235
        i2cInit();
236
 
237
        /* Initialise the LED's used by the flash tasks. */
238
        vParTestInitialise();
239
}
240
/*-----------------------------------------------------------*/
241
 
242
static void prvMainCheckOtherTasksAreStillRunning( void )
243
{
244
        /* Check all the demo tasks (other than the flash tasks) to ensure
245
        that they are all still running, and that none of them have detected
246
        an error. */
247
 
248
        /* This function is called from more than one task. */
249
        if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
250
        {
251
                lErrorInTask = pdTRUE;
252
        }
253
 
254
        if( xArePollingQueuesStillRunning() != pdTRUE )
255
        {
256
                lErrorInTask = pdTRUE;
257
        }
258
 
259
        if( xAreSemaphoreTasksStillRunning() != pdTRUE )
260
        {
261
                lErrorInTask = pdTRUE;
262
        }
263
 
264
        if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
265
        {
266
                lErrorInTask = pdTRUE;
267
        }
268
 
269
        if( xAreBlockingQueuesStillRunning() != pdTRUE )
270
        {
271
                lErrorInTask = pdTRUE;
272
        }
273
}
274
/*-----------------------------------------------------------*/
275
 
276
void prvToggleOnBoardLED( void )
277
{
278
unsigned long ulState;
279
 
280
        ulState = GPIO0_IOPIN;
281
        if( ulState & mainON_BOARD_LED_BIT )
282
        {
283
                GPIO_IOCLR = mainON_BOARD_LED_BIT;
284
        }
285
        else
286
        {
287
                GPIO_IOSET = mainON_BOARD_LED_BIT;
288
        }
289
}
290
/*-----------------------------------------------------------*/
291
 
292
static void prvErrorChecks( void *pvParameters )
293
{
294
portTickType xDelay = mainNO_ERROR_DELAY;
295
 
296
        /* The parameters are not used. */
297
        ( void ) pvParameters;
298
 
299
        for( ;; )
300
        {
301
                /* How long we delay depends on whether an error has been detected
302
                or not.  Therefore the flash rate of the on board LED indicates
303
                whether or not an error has occurred. */
304
                vTaskDelay( xDelay );
305
 
306
                /* Update the lErrorInTask flag. */
307
                prvMainCheckOtherTasksAreStillRunning();
308
 
309
                if( lErrorInTask )
310
                {
311
                        /* An error has been found so reduce the delay period and in so
312
                        doing speed up the flash rate of the on board LED. */
313
                        xDelay = mainERROR_DELAY;
314
                }
315
 
316
                prvToggleOnBoardLED();
317
        }
318
}
319
 

powered by: WebSVN 2.1.0

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