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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 583 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
 * Creates all the application tasks, then starts the scheduler.
65
 *
66
 * A task defined by the function vBasicWEBServer is created.  This executes
67
 * the lwIP stack and basic WEB server sample.  A task defined by the function
68
 * vUSBCDCTask.  This executes the USB to serial CDC example.  All the other
69
 * tasks are from the set of standard demo tasks.  The WEB documentation
70
 * provides more details of the standard demo application tasks.
71
 *
72
 * Main.c also creates a task called "Check".  This only executes every three
73
 * seconds but has the highest priority so is guaranteed to get processor time.
74
 * Its main function is to check the status of all the other demo application
75
 * tasks.  LED mainCHECK_LED is toggled every three seconds by the check task
76
 * should no error conditions be detected in any of the standard demo tasks.
77
 * The toggle rate increasing to 500ms indicates that at least one error has
78
 * been detected.
79
 *
80
 * Main.c includes an idle hook function that simply periodically sends data
81
 * to the USB task for transmission.
82
 */
83
 
84
/*
85
        Changes from V3.2.2
86
 
87
        + Modified the stack sizes used by some tasks to permit use of the
88
          command line GCC tools.
89
*/
90
 
91
/* Library includes. */
92
#include <string.h>
93
#include <stdio.h>
94
 
95
/* Scheduler includes. */
96
#include "FreeRTOS.h"
97
#include "task.h"
98
 
99
/* Demo application includes. */
100
#include "partest.h"
101
#include "PollQ.h"
102
#include "semtest.h"
103
#include "flash.h"
104
#include "integer.h"
105
#include "BlockQ.h"
106
#include "BasicWEB.h"
107
#include "USB-CDC.h"
108
 
109
/* lwIP includes. */
110
#include "lwip/api.h" 
111
 
112
/* Hardware specific headers. */
113
#include "Board.h"
114
#include "AT91SAM7X256.h"
115
 
116
/* Priorities/stacks for the various tasks within the demo application. */
117
#define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 1 )
118
#define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 3 )
119
#define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )
120
#define mainFLASH_PRIORITY                      ( tskIDLE_PRIORITY + 2 )
121
#define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 1 )
122
#define mainWEBSERVER_PRIORITY      ( tskIDLE_PRIORITY + 2 )
123
#define mainUSB_PRIORITY                        ( tskIDLE_PRIORITY + 1 )
124
#define mainUSB_TASK_STACK                      ( 200 )
125
 
126
/* The rate at which the on board LED will toggle when there is/is not an
127
error. */
128
#define mainNO_ERROR_FLASH_PERIOD       ( ( portTickType ) 3000 / portTICK_RATE_MS  )
129
#define mainERROR_FLASH_PERIOD          ( ( portTickType ) 500 / portTICK_RATE_MS  )
130
 
131
/* The rate at which the idle hook sends data to the USB port. */
132
#define mainUSB_TX_FREQUENCY            ( 100 / portTICK_RATE_MS )
133
 
134
/* The string that is transmitted down the USB port. */
135
#define mainFIRST_TX_CHAR                       'a'
136
#define mainLAST_TX_CHAR                        'z'
137
 
138
/* The LED used by the check task to indicate the system status. */
139
#define mainCHECK_LED                           ( 3 )
140
/*-----------------------------------------------------------*/
141
 
142
/*
143
 * Checks that all the demo application tasks are still executing without error
144
 * - as described at the top of the file.
145
 */
146
static long prvCheckOtherTasksAreStillRunning( void );
147
 
148
/*
149
 * The task that executes at the highest priority and calls
150
 * prvCheckOtherTasksAreStillRunning().  See the description at the top
151
 * of the file.
152
 */
153
static void vErrorChecks( void *pvParameters );
154
 
155
/*
156
 * Configure the processor for use with the Atmel demo board.  This is very
157
 * minimal as most of the setup is performed in the startup code.
158
 */
159
static void prvSetupHardware( void );
160
 
161
/*
162
 * The idle hook is just used to stream data to the USB port.
163
 */
164
void vApplicationIdleHook( void );
165
/*-----------------------------------------------------------*/
166
 
167
/*
168
 * Setup hardware then start all the demo application tasks.
169
 */
170
int main( void )
171
{
172
        /* Setup the ports. */
173
        prvSetupHardware();
174
 
175
        /* Setup the IO required for the LED's. */
176
        vParTestInitialise();
177
 
178
        /* Setup lwIP. */
179
    vlwIPInit();
180
 
181
        /* Create the lwIP task.  This uses the lwIP RTOS abstraction layer.*/
182
    sys_thread_new( vBasicWEBServer, ( void * ) NULL, mainWEBSERVER_PRIORITY );
183
 
184
        /* Create the demo USB CDC task. */
185
        xTaskCreate( vUSBCDCTask, ( signed char * ) "USB", mainUSB_TASK_STACK, NULL, mainUSB_PRIORITY, NULL );
186
 
187
        /* Create the standard demo application tasks. */
188
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
189
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
190
        vStartLEDFlashTasks( mainFLASH_PRIORITY );
191
        vStartIntegerMathTasks( tskIDLE_PRIORITY );
192
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
193
 
194
        /* Start the check task - which is defined in this file. */
195
    xTaskCreate( vErrorChecks, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
196
 
197
        /* Finally, start the scheduler.
198
 
199
        NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
200
        The processor MUST be in supervisor mode when vTaskStartScheduler is
201
        called.  The demo applications included in the FreeRTOS.org download switch
202
        to supervisor mode prior to main being called.  If you are not using one of
203
        these demo application projects then ensure Supervisor mode is used here. */
204
        vTaskStartScheduler();
205
 
206
        /* Should never get here! */
207
        return 0;
208
}
209
/*-----------------------------------------------------------*/
210
 
211
 
212
static void prvSetupHardware( void )
213
{
214
        /* When using the JTAG debugger the hardware is not always initialised to
215
        the correct default state.  This line just ensures that this does not
216
        cause all interrupts to be masked at the start. */
217
        AT91C_BASE_AIC->AIC_EOICR = 0;
218
 
219
        /* Most setup is performed by the low level init function called from the
220
        startup asm file.
221
 
222
        Configure the PIO Lines corresponding to LED1 to LED4 to be outputs as
223
        well as the UART Tx line. */
224
        AT91C_BASE_PIOB->PIO_PER = LED_MASK; // Set in PIO mode
225
        AT91C_BASE_PIOB->PIO_OER = LED_MASK; // Configure in Output
226
 
227
 
228
        /* Enable the peripheral clock. */
229
    AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;
230
    AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB;
231
        AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_EMAC;
232
}
233
/*-----------------------------------------------------------*/
234
 
235
static void vErrorChecks( void *pvParameters )
236
{
237
portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
238
portTickType xLastWakeTime;
239
 
240
        /* The parameters are not used. */
241
        ( void ) pvParameters;
242
 
243
        /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()
244
        functions correctly. */
245
        xLastWakeTime = xTaskGetTickCount();
246
 
247
        /* Cycle for ever, delaying then checking all the other tasks are still
248
        operating without error.  If an error is detected then the delay period
249
        is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
250
        the Check LED flash rate will increase. */
251
        for( ;; )
252
        {
253
                /* Delay until it is time to execute again.  The delay period is
254
                shorter following an error. */
255
                vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
256
 
257
                /* Check all the standard demo application tasks are executing without
258
                error.  */
259
                if( prvCheckOtherTasksAreStillRunning() != pdPASS )
260
                {
261
                        /* An error has been detected in one of the tasks - flash faster. */
262
                        xDelayPeriod = mainERROR_FLASH_PERIOD;
263
                }
264
 
265
                vParTestToggleLED( mainCHECK_LED );
266
        }
267
}
268
/*-----------------------------------------------------------*/
269
 
270
static long prvCheckOtherTasksAreStillRunning( void )
271
{
272
long lReturn = ( long ) pdPASS;
273
 
274
        /* Check all the demo tasks (other than the flash tasks) to ensure
275
        that they are all still running, and that none of them have detected
276
        an error. */
277
 
278
        if( xArePollingQueuesStillRunning() != pdTRUE )
279
        {
280
                lReturn = ( long ) pdFAIL;
281
        }
282
 
283
        if( xAreSemaphoreTasksStillRunning() != pdTRUE )
284
        {
285
                lReturn = ( long ) pdFAIL;
286
        }
287
 
288
        if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
289
        {
290
                lReturn = ( long ) pdFAIL;
291
        }
292
 
293
        if( xAreBlockingQueuesStillRunning() != pdTRUE )
294
        {
295
                lReturn = ( long ) pdFAIL;
296
        }
297
 
298
        return lReturn;
299
}
300
/*-----------------------------------------------------------*/
301
 
302
void vApplicationIdleHook( void )
303
{
304
static portTickType xLastTx = 0;
305
char cTxByte;
306
 
307
        /* The idle hook simply sends a string of characters to the USB port.
308
        The characters will be buffered and sent once the port is connected. */
309
        if( ( xTaskGetTickCount() - xLastTx ) > mainUSB_TX_FREQUENCY )
310
        {
311
                xLastTx = xTaskGetTickCount();
312
                for( cTxByte = mainFIRST_TX_CHAR; cTxByte <= mainLAST_TX_CHAR; cTxByte++ )
313
                {
314
                        vUSBSendByte( cTxByte );
315
                }
316
        }
317
}
318
 
319
 

powered by: WebSVN 2.1.0

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