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

Subversion Repositories openrisc

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

Go to most recent revision | 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
#include "lcd_message.h"
62
 
63
/* uip includes. */
64
#include "hw_types.h"
65
 
66
#include "uip.h"
67
#include "uip_arp.h"
68
#include "httpd.h"
69
#include "timer.h"
70
#include "clock-arch.h"
71
#include "hw_ethernet.h"
72
#include "ethernet.h"
73
#include "hw_memmap.h"
74
#include "lmi_flash.h"
75
#include "sysctl.h"
76
 
77
/* Demo includes. */
78
#include "emac.h"
79
#include "partest.h"
80
 
81
/*-----------------------------------------------------------*/
82
 
83
/* IP address configuration. */
84
#define uipIP_ADDR0             192
85
#define uipIP_ADDR1             168
86
#define uipIP_ADDR2             0
87
#define uipIP_ADDR3             201
88
 
89
/* Netmask configuration. */
90
#define uipNETMASK_0    255
91
#define uipNETMASK_1    255
92
#define uipNETMASK_2    255
93
#define uipNETMASK_3    0
94
 
95
/* How long to wait before attempting to connect the MAC again. */
96
#define uipINIT_WAIT    100
97
 
98
/* Shortcut to the header within the Rx buffer. */
99
#define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
100
 
101
/* Standard constant. */
102
#define uipTOTAL_FRAME_HEADER_SIZE      54
103
 
104
/*-----------------------------------------------------------*/
105
 
106
/*
107
 * Send the uIP buffer to the MAC.
108
 */
109
static void prvENET_Send(void);
110
 
111
/*
112
 * Setup the MAC address in the MAC itself, and in the uIP stack.
113
 */
114
static void prvSetMACAddress( void );
115
 
116
/*
117
 * Port functions required by the uIP stack.
118
 */
119
void clock_init( void );
120
clock_time_t clock_time( void );
121
 
122
/*-----------------------------------------------------------*/
123
 
124
/* The semaphore used by the ISR to wake the uIP task. */
125
extern xSemaphoreHandle xEMACSemaphore;
126
 
127
/*-----------------------------------------------------------*/
128
 
129
void clock_init(void)
130
{
131
        /* This is done when the scheduler starts. */
132
}
133
/*-----------------------------------------------------------*/
134
 
135
clock_time_t clock_time( void )
136
{
137
        return xTaskGetTickCount();
138
}
139
 
140
 
141
void vuIP_Task( void *pvParameters )
142
{
143
portBASE_TYPE i;
144
uip_ipaddr_t xIPAddr;
145
struct timer periodic_timer, arp_timer;
146
extern void ( vEMAC_ISR )( void );
147
 
148
        /* Enable/Reset the Ethernet Controller */
149
        SysCtlPeripheralEnable( SYSCTL_PERIPH_ETH );
150
        SysCtlPeripheralReset( SYSCTL_PERIPH_ETH );
151
 
152
        /* Create the semaphore used by the ISR to wake this task. */
153
        vSemaphoreCreateBinary( xEMACSemaphore );
154
 
155
        /* Initialise the uIP stack. */
156
        timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
157
        timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
158
        uip_init();
159
        uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
160
        uip_sethostaddr( xIPAddr );
161
        uip_ipaddr( xIPAddr, uipNETMASK_0, uipNETMASK_1, uipNETMASK_2, uipNETMASK_3 );
162
    uip_setnetmask( xIPAddr );
163
        httpd_init();
164
 
165
        while( vInitEMAC() != pdPASS )
166
    {
167
        vTaskDelay( uipINIT_WAIT );
168
    }
169
        prvSetMACAddress();
170
 
171
 
172
        for( ;; )
173
        {
174
                /* Is there received data ready to be processed? */
175
                uip_len = uiGetEMACRxData( uip_buf );
176
 
177
                if( uip_len > 0 )
178
                {
179
                        /* Standard uIP loop taken from the uIP manual. */
180
 
181
                        if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
182
                        {
183
                                uip_arp_ipin();
184
                                uip_input();
185
 
186
                                /* If the above function invocation resulted in data that
187
                                should be sent out on the network, the global variable
188
                                uip_len is set to a value > 0. */
189
                                if( uip_len > 0 )
190
                                {
191
                                        uip_arp_out();
192
                                        prvENET_Send();
193
                                }
194
                        }
195
                        else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
196
                        {
197
                                uip_arp_arpin();
198
 
199
                                /* If the above function invocation resulted in data that
200
                                should be sent out on the network, the global variable
201
                                uip_len is set to a value > 0. */
202
                                if( uip_len > 0 )
203
                                {
204
                                        prvENET_Send();
205
                                }
206
                        }
207
                }
208
                else
209
                {
210
                        if( timer_expired( &periodic_timer ) )
211
                        {
212
                                timer_reset( &periodic_timer );
213
                                for( i = 0; i < UIP_CONNS; i++ )
214
                                {
215
                                        uip_periodic( i );
216
 
217
                                        /* If the above function invocation resulted in data that
218
                                        should be sent out on the network, the global variable
219
                                        uip_len is set to a value > 0. */
220
                                        if( uip_len > 0 )
221
                                        {
222
                                                uip_arp_out();
223
                                                prvENET_Send();
224
                                        }
225
                                }
226
 
227
                                /* Call the ARP timer function every 10 seconds. */
228
                                if( timer_expired( &arp_timer ) )
229
                                {
230
                                        timer_reset( &arp_timer );
231
                                        uip_arp_timer();
232
                                }
233
                        }
234
                        else
235
                        {
236
                                /* We did not receive a packet, and there was no periodic
237
                                processing to perform.  Block for a fixed period.  If a packet
238
                                is received during this period we will be woken by the ISR
239
                                giving us the Semaphore. */
240
                                xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
241
                        }
242
                }
243
        }
244
}
245
/*-----------------------------------------------------------*/
246
 
247
static void prvENET_Send(void)
248
{
249
    vInitialiseSend();
250
    vIncrementTxLength( uip_len );
251
    vSendBufferToMAC();
252
    vInitialiseSend();
253
    vIncrementTxLength( uip_len );
254
    vSendBufferToMAC();
255
}
256
/*-----------------------------------------------------------*/
257
 
258
static void prvSetMACAddress( void )
259
{
260
unsigned long 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( char *pcInputString, portBASE_TYPE xInputLength )
289
{
290
char *c, *pcText;
291
static char 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 = 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.