cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
arvindnr
Voyager
Voyager
4,484 Views
Registered: ‎02-10-2012

Coding a delay without effecting timeouts

Hey

I wanted to insert a delay function to allow sufficient time for my lwip DHCP configuration to bind so that i can print it successfully. I have a while loop as follows :

while (1) {
                            xemacif_input(netif);
                            if (netif->ip_addr.addr) {
                                xil_printf("DHCP IP stack added success\r\n");
                                *some delay function which does not effect timeouts*
                              

   xil_printf("%d.%d.%d.%d\n\r", ip4_addr1(netif->ip_addr.addr),ip4_addr2(netif->ip_addr.addr),ip4_addr3(netif->ip_addr.addr), ip4_addr4(netif->ip_addr.addr));
                                 xil_printf("%d.%d.%d.%d\n\r", ip4_addr1(netif->netmask.addr),ip4_addr2(netif->netmask.addr),ip4_addr3(netif->netmask.addr), ip4_addr4(netif->netmask.addr));
                                 xil_printf("%d.%d.%d.%d\n\r", ip4_addr1(netif->gw.addr),ip4_addr2(netif->gw.addr),ip4_addr3(netif->gw.addr), ip4_addr4(netif->gw.addr));
                                break;
                            }
                            mscnt += DHCP_FINE_TIMER_MSECS;
                            if (mscnt >= DHCP_TIMEOUT_MS) {
                                xil_printf("ERROR: DHCP request timed out\r\n");
                                break;
                            }
                        }
When i try to run the program without the delay function the printf is still showing the initial values of the ip ( Which is 0.0.0.0  as it was initialised to this value at the start of my program )
But the DHCP is working perfectly. The DHCP is successfully configured and an IP address configuration is added to my netif . I even tested the echo server . But to find out the new dhcp address assigned i had to go to the network admin computer and check the dhcp server log manually to find out the assigned IP. I feel the printf is a bit premature so i want to insert a delay function to give it enough time to bind.

Can u suggest a suitable delay function which DOES NOT AFFECT THE TIME OUT PROCESS .  Or is there a better way of going about it?

Thanks a lot
0 Kudos
4 Replies
arvindnr
Voyager
Voyager
4,470 Views
Registered: ‎02-10-2012

Any one?

0 Kudos
johnmcd
Xilinx Employee
Xilinx Employee
4,465 Views
Registered: ‎02-01-2008

Here's what I used a while ago:

 

    // Wait for DHCP IP configuration
    while (1) {
        sleep(DHCP_FINE_TIMER_MSECS);
        if (netif->ip_addr.addr) {
            xil_printf("DHCP request success\r\n");
            break;
        }
        millisec_cnt += DHCP_FINE_TIMER_MSECS;
        if (millisec_cnt >= DHCP_TIMEOUT_MS) {
            xil_printf("ERROR: DHCP request timed out\r\n");
            return;
        }
    }            


0 Kudos
arvindnr
Voyager
Voyager
4,456 Views
Registered: ‎02-10-2012

I tried the same thing. The DHCP configuration  is working but i am not able to print the new ip settings sent by the DHCP server to the xilinx board. Is using the following method to print the new ip settings wrong ?

 

    xil_printf("%d.%d.%d.%d\n\r", ip4_addr1(netif->ip_addr.addr),ip4_addr2(netif->ip_addr.addr),ip4_addr3(netif->ip_addr.addr), ip4_addr4(netif->ip_addr.addr));

 

The above code is just supposed to print the ip address. Simillarly for netmask i use :

 

xil_printf("%d.%d.%d.%d\n\r", ip4_addr1(netif->netmask.addr),ip4_addr2(netif->netmask.addr),ip4_addr3(netif->netmask.addr), ip4_addr4(netif->netmask.addr));
    

and for the gateway :

 

xil_printf("%d.%d.%d.%d\n\r", ip4_addr1(netif->gw.addr),ip4_addr2(netif->gw.addr),ip4_addr3(netif->gw.addr), ip4_addr4(netif->gw.addr));

0 Kudos
arvindnr
Voyager
Voyager
4,454 Views
Registered: ‎02-10-2012

I initially thought that its a delay problem , as in i was priniting the ip settings too early after the DHCP configuration. But now i think its something else entirely..

0 Kudos