|
 UltimaSerial
Windaq Add-ons
UltimaWaterfall
XChart
FFT1024

Lessons |
|
Please take the basic lwIP DHCP client workshop before
trying out this
one
When a DHCP server is not available, Windows
Vista/XP will use Automatic Private Internet Protocol Addressing
(APIPA) to assign itself an IP within the range of 169.254.0.1 through
169.254.255.254 inclusive (for more info, please google or wiki
it)
lwIP support this option,
too.
Here we will add this option to our basic lwIP DHCP client example
First, 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 auto IP with 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:
change
#define LWIP_DHCP
0
to #define LWIP_DHCP 1
add #define
LWIP_AUTOIP 1
add #define
LWIP_DHCP_AUTOIP_COOP 1
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); //autoip_init();
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;
}
autoip_tmr();
}
//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, start Windows' HyperTerminal and
set Bits per second =115200, Data bits = 8, Parity = none,
Stop bits = 1, Flow control =
None.
Connect
your EVK1100 to a Windows Vista PC directly, so no DHCP server
exists.
Build and
run
If you enable the debug output, you
will see the program will
acquire a private IP after DHCP times out, and you can ping the
IP.
Click here for more lwIP examples
Find
out how to upgrade to the latest lwIP
Last update: 04/08/10 |