I have used the following code as a template for my project:
while(1)
{
switch(DHCP_run())
{
case DHCP_IP_ASSIGN:
case DHCP_IP_CHANGED:
/* If this block empty, act with default_ip_assign & default_ip_update */
//
// This example calls the registered 'my_ip_assign' in the two case.
//
// Add to ...
//
break;
case DHCP_IP_LEASED:
//
// TO DO YOUR NETWORK APPs.
//
break;
case DHCP_FAILED:
/* ===== Example pseudo code ===== */
// The below code can be replaced your code or omitted.
// if omitted, retry to process DHCP
my_dhcp_retry++;
if(my_dhcp_retry > MY_MAX_DHCP_RETRY)
{
#if DEBUG_MODE != DEBUG_NO
printf(">> DHCP %d Failed\r\n",my_dhcp_retry);
#endif
my_dhcp_retry = 0;
DHCP_stop(); // if restart, recall DHCP_init()
network_init(); // apply the default static network
}
break;
default:
break;
}
/* User LED Toggle every 1s */
if((msTicks - prevTick) > 1000)
{
prevTick = msTicks;
if ( GPIO_PinOutGet(LED_PORT, LED_PIN) )
GPIO_PinOutClear(LED_PORT, LED_PIN);
else
GPIO_PinOutSet(LED_PORT, LED_PIN);
}
}
But what should happen if I remove the LAN cable and re attach it to another router. Will this code detect this and reassign a new IP address?
Or should I detect the PHY_LINK_OFF condition and call DHCP_init() ?