|
 UltimaSerial
Windaq Add-ons
UltimaWaterfall
XChart
FFT1024

Lessons |
|
lwIP is a popular free TCP/IP stack for many embedded processors. The following workshop enables DHCP client
so that it can acquire an IP from a DHCP
server.
Here we pick a real piece
of hardware from Atmel: EVK1100. Its processor is 32UC3A0512, but
the codes below should work in other hardware.
Software Development Platform: AVR32 with lwIP and
FreeRTOS.
To enable a DHCP client on EVK1100, using
lwIP on FreeRTOS, under AVR32
- AVR32->File->New->Example, select
EVK1100-SERVICES-LWIP example
- Give a Project Name: MyTestFromLwIP, then
click Finish. This will create a new project under the Project Explorer
pane.
- Open MyTestFromLwIP->src->CONFIG->lwipopts.h, and
change
#define LWIP_DHCP
0
to #define LWIP_DHCP 1
#define MEMP_NUM_UDP_PCB 1
to #define
MEMP_NUM_UDP_PCB 2
- Add #include "lwip/dhcp.h" to the header section of
MyTestFromLwIP->src->NETWORK->ethernet.c
- Open MyTestFromLwIP->src->NETWORK->ethernet.c, and replace
prvEthernetConfigureInterface with:
static void
prvEthernetConfigureInterface(void * param){ struct
ip_addr xIpAddr, xNetMask, xGateway; extern
err_t ethernetif_init( struct netif *netif ); unsigned portCHAR
MacAddress[6];
MacAddress[0] =
ETHERNET_CONF_ETHADDR0; MacAddress[1] =
ETHERNET_CONF_ETHADDR1; MacAddress[2] =
ETHERNET_CONF_ETHADDR2; MacAddress[3] =
ETHERNET_CONF_ETHADDR3; MacAddress[4] =
ETHERNET_CONF_ETHADDR4; MacAddress[5] =
ETHERNET_CONF_ETHADDR5;
vMACBSetMACAddress( MacAddress
);
IP4_ADDR( &xIpAddr,0,0,0,0
); IP4_ADDR( &xNetMask,0,0,0,0
); IP4_ADDR( &xGateway,0,0,0,0
);
netif_add( &MACB_if,
&xIpAddr, &xNetMask, &xGateway, NULL, ethernetif_init,
tcpip_input ); netif_set_default( &MACB_if
);
dhcp_start(&MACB_if); }
-
Add the following codes to module portTASK_FUNCTION( vStartEthernetTask, pvParameters ), after
prvlwIPInit():
//init_dbg_rs232(FOSC0);
int mscnt =0;
while (MACB_if.ip_addr.addr==0) {
sys_msleep(DHCP_FINE_TIMER_MSECS);
dhcp_fine_tmr();
mscnt += DHCP_FINE_TIMER_MSECS;
if (mscnt >= DHCP_COARSE_TIMER_SECS*1000) {
dhcp_coarse_tmr();
mscnt = 0;
}
}
//print_dbg("\nDone with DHCP");
//print_dbg("\nAcquired IP ="); //
print_dbg_ulong(0xff&(MACB_if.ip_addr.addr>>24)); //print_dbg("."); //print_dbg_ulong(0xff&(MACB_if.ip_addr.addr>>16)); //print_dbg("."); //print_dbg_ulong(0xff&(MACB_if.ip_addr.addr>>8)); //print_dbg("."); //print_dbg_ulong(0xff&(MACB_if.ip_addr.addr));
- To use
the debug outputs, you will need uncomment all the functions
in the codes and add
#include "print_funcs.h" to the header section of
ethernet.c.
To receive the debug outputs, connect a RS232 cable
to UART 1 of EVK1100, start Windows' HyperTerminal and
set Bits per second =115200, Data bits = 8, Parity = none,
Stop bits = 1, Flow control =
None.
- Build and run it in a network with a DHCP server,
such as a DSL router, and
you can ping the IP once it is acquired from a DHCP
server.
Click here for more lwIP examples
Find
out how to upgrade to the latest lwIP
|
|
|
| |