UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Voyager
Voyager
4,328 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
Voyager
Voyager
4,314 Views
Registered: ‎02-10-2012

Re: Coding a delay without effecting timeouts

Any one?

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

Re: Coding a delay without effecting timeouts

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
Voyager
Voyager
4,300 Views
Registered: ‎02-10-2012

Re: Coding a delay without effecting timeouts

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
Voyager
Voyager
4,298 Views
Registered: ‎02-10-2012

Re: Coding a delay without effecting timeouts

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