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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_LM3Sxxxx_IAR_Keil/] [webserver/] [uIP_Task.c] - Blame information for rev 581

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 581 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
/* Standard includes. */
54
#include <string.h>
55
 
56
/* Scheduler includes. */
57
#include "FreeRTOS.h"
58
#include "task.h"
59
#include "semphr.h"
60
 
61
/* uip includes. */
62
#include "hw_types.h"
63
#include "uip.h"
64
#include "uip_arp.h"
65
#include "httpd.h"
66
#include "timer.h"
67
#include "clock-arch.h"
68
#include "hw_ethernet.h"
69
#include "ethernet.h"
70
#include "hw_memmap.h"
71
#include "lmi_flash.h"
72
#include "sysctl.h"
73
 
74
/* Demo includes. */
75
#include "emac.h"
76
#include "partest.h"
77
#include "lcd_message.h"
78
 
79
struct timer {
80
  clock_time_t start;
81
  clock_time_t interval;
82
};
83
 
84
 
85
/*-----------------------------------------------------------*/
86
 
87
/* IP address configuration. */
88
#define uipIP_ADDR0             172
89
#define uipIP_ADDR1             25
90
#define uipIP_ADDR2             218
91
#define uipIP_ADDR3             19      
92
 
93
/* How long to wait before attempting to connect the MAC again. */
94
#define uipINIT_WAIT    100
95
 
96
/* Shortcut to the header within the Rx buffer. */
97
#define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
98
 
99
/* Standard constant. */
100
#define uipTOTAL_FRAME_HEADER_SIZE      54
101
 
102
/*-----------------------------------------------------------*/
103
 
104
/*
105
 * Send the uIP buffer to the MAC.
106
 */
107
static void prvENET_Send(void);
108
 
109
/*
110
 * Setup the MAC address in the MAC itself, and in the uIP stack.
111
 */
112
static void prvSetMACAddress( void );
113
 
114
/*
115
 * Port functions required by the uIP stack.
116
 */
117
void clock_init( void );
118
clock_time_t clock_time( void );
119
 
120
/*-----------------------------------------------------------*/
121
 
122
/* The semaphore used by the ISR to wake the uIP task. */
123
extern xSemaphoreHandle xEMACSemaphore;
124
 
125
/*-----------------------------------------------------------*/
126
 
127
void clock_init(void)
128
{
129
        /* This is done when the scheduler starts. */
130
}
131
/*-----------------------------------------------------------*/
132
 
133
/* Define clock functions here to avoid header file name clash between uIP
134
and the Luminary Micro driver library. */
135
clock_time_t clock_time( void )
136
{
137
        return xTaskGetTickCount();
138
}
139
extern void timer_set(struct timer *t, clock_time_t interval);
140
extern int timer_expired(struct timer *t);
141
extern void timer_reset(struct timer *t);
142
 
143
 
144
 
145
 
146
void vuIP_Task( void *pvParameters )
147
{
148
portBASE_TYPE i;
149
uip_ipaddr_t xIPAddr;
150
struct timer periodic_timer, arp_timer;
151
extern void ( vEMAC_ISR )( void );
152
 
153
        /* Enable/Reset the Ethernet Controller */
154
        SysCtlPeripheralEnable( SYSCTL_PERIPH_ETH );
155
        SysCtlPeripheralReset( SYSCTL_PERIPH_ETH );
156
 
157
        /* Create the semaphore used by the ISR to wake this task. */
158
        vSemaphoreCreateBinary( xEMACSemaphore );
159
 
160
        /* Initialise the uIP stack. */
161
        timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
162
        timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
163
        uip_init();
164
        uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
165
        uip_sethostaddr( xIPAddr );
166
        httpd_init();
167
 
168
        while( vInitEMAC() != pdPASS )
169
    {
170
        vTaskDelay( uipINIT_WAIT );
171
    }
172
        prvSetMACAddress();
173
 
174
 
175
        for( ;; )
176
        {
177
                /* Is there received data ready to be processed? */
178
                uip_len = uiGetEMACRxData( uip_buf );
179
 
180
                if( uip_len > 0 )
181
                {
182
                        /* Standard uIP loop taken from the uIP manual. */
183
 
184
                        if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
185
                        {
186
                                uip_arp_ipin();
187
                                uip_input();
188
 
189
                                /* If the above function invocation resulted in data that
190
                                should be sent out on the network, the global variable
191
                                uip_len is set to a value > 0. */
192
                                if( uip_len > 0 )
193
                                {
194
                                        uip_arp_out();
195
                                        prvENET_Send();
196
                                }
197
                        }
198
                        else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
199
                        {
200
                                uip_arp_arpin();
201
 
202
                                /* If the above function invocation resulted in data that
203
                                should be sent out on the network, the global variable
204
                                uip_len is set to a value > 0. */
205
                                if( uip_len > 0 )
206
                                {
207
                                        prvENET_Send();
208
                                }
209
                        }
210
                }
211
                else
212
                {
213
                        if( timer_expired( &periodic_timer ) )
214
                        {
215
                                timer_reset( &periodic_timer );
216
                                for( i = 0; i < UIP_CONNS; i++ )
217
                                {
218
                                        uip_periodic( i );
219
 
220
                                        /* If the above function invocation resulted in data that
221
                                        should be sent out on the network, the global variable
222
                                        uip_len is set to a value > 0. */
223
                                        if( uip_len > 0 )
224
                                        {
225
                                                uip_arp_out();
226
                                                prvENET_Send();
227
                                        }
228
                                }
229
 
230
                                /* Call the ARP timer function every 10 seconds. */
231
                                if( timer_expired( &arp_timer ) )
232
                                {
233
                                        timer_reset( &arp_timer );
234
                                        uip_arp_timer();
235
                                }
236
                        }
237
                        else
238
                        {
239
                                /* We did not receive a packet, and there was no periodic
240
                                processing to perform.  Block for a fixed period.  If a packet
241
                                is received during this period we will be woken by the ISR
242
                                giving us the Semaphore. */
243
                                xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
244
                        }
245
                }
246
        }
247
}
248
/*-----------------------------------------------------------*/
249
 
250
static void prvENET_Send(void)
251
{
252
        vInitialiseSend();
253
        vIncrementTxLength( uip_len );
254
        vSendBufferToMAC();
255
}
256
/*-----------------------------------------------------------*/
257
 
258
static void prvSetMACAddress( void )
259
{
260
unsigned portLONG ulUser0, ulUser1;
261
unsigned char pucMACArray[8];
262
struct uip_eth_addr xAddr;
263
 
264
        /* Get the device MAC address from flash */
265
    FlashUserGet(&ulUser0, &ulUser1);
266
 
267
        /* Convert the MAC address from flash into sequence of bytes. */
268
    pucMACArray[0] = ((ulUser0 >>  0) & 0xff);
269
    pucMACArray[1] = ((ulUser0 >>  8) & 0xff);
270
    pucMACArray[2] = ((ulUser0 >> 16) & 0xff);
271
    pucMACArray[3] = ((ulUser1 >>  0) & 0xff);
272
    pucMACArray[4] = ((ulUser1 >>  8) & 0xff);
273
    pucMACArray[5] = ((ulUser1 >> 16) & 0xff);
274
 
275
        /* Program the MAC address. */
276
    EthernetMACAddrSet(ETH_BASE, pucMACArray);
277
 
278
        xAddr.addr[ 0 ] = pucMACArray[0];
279
        xAddr.addr[ 1 ] = pucMACArray[1];
280
        xAddr.addr[ 2 ] = pucMACArray[2];
281
        xAddr.addr[ 3 ] = pucMACArray[3];
282
        xAddr.addr[ 4 ] = pucMACArray[4];
283
        xAddr.addr[ 5 ] = pucMACArray[5];
284
        uip_setethaddr( xAddr );
285
}
286
/*-----------------------------------------------------------*/
287
 
288
void vApplicationProcessFormInput( portCHAR *pcInputString, portBASE_TYPE xInputLength )
289
{
290
char *c, *pcText;
291
static portCHAR cMessageForDisplay[ 32 ];
292
extern xQueueHandle xOLEDQueue;
293
xOLEDMessage xOLEDMessage;
294
 
295
        /* Process the form input sent by the IO page of the served HTML. */
296
 
297
        c = strstr( pcInputString, "?" );
298
 
299
    if( c )
300
    {
301
                /* Turn LED's on or off in accordance with the check box status. */
302
                if( strstr( c, "LED0=1" ) != NULL )
303
                {
304
                        vParTestSetLED( 0, 1 );
305
                }
306
                else
307
                {
308
                        vParTestSetLED( 0, 0 );
309
                }
310
 
311
                /* Find the start of the text to be displayed on the LCD. */
312
        pcText = strstr( c, "LCD=" );
313
        pcText += strlen( "LCD=" );
314
 
315
        /* Terminate the file name for further processing within uIP. */
316
        *c = 0x00;
317
 
318
        /* Terminate the LCD string. */
319
        c = strstr( pcText, " " );
320
        if( c != NULL )
321
        {
322
            *c = 0x00;
323
        }
324
 
325
        /* Add required spaces. */
326
        while( ( c = strstr( pcText, "+" ) ) != NULL )
327
        {
328
            *c = ' ';
329
        }
330
 
331
        /* Write the message to the LCD. */
332
                strcpy( cMessageForDisplay, pcText );
333
                xOLEDMessage.pcMessage = ( signed portCHAR * ) cMessageForDisplay;
334
        xQueueSend( xOLEDQueue, &xOLEDMessage, portMAX_DELAY );
335
    }
336
}
337
 

powered by: WebSVN 2.1.0

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