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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_LM3Sxxxx_Eclipse/] [RTOSDemo/] [webserver/] [uIP_Task.c] - Blame information for rev 590

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

powered by: WebSVN 2.1.0

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