RM46L852: Lwip on polling

Part Number: RM46L852


In current LwIP stack, both DHCP and Static IP is get through interrupt and call back function.

Can anyone please help us to identify the changes required for getting the DHCP "IP" by polling Ethernet Tx and RX flags?

At while loop , we have implemented and tested  the Ethernet Rx and Tx polling and it found working (web server get opened as well as control give response to ping command. 

4 Replies

  • Hello Pramod,

    Are you going to post your code for us to check your changes?

    Thanks and Regards,
    QJ Wang

  • In reply to QJ Wang:

    Hello QJ,

    We have made following changes in LwIP stack,

    1. To get the DHCP IP by polling , we have repeatably check the State DHCP state by polling Rx and Tx ethernet interrupt

    in lwIPInit() of lwiplib.c file

    if(ipMode == IPADDR_USE_DHCP)

    {

    unsigned int dhcp_flag = 0;
    unsigned int dhcp_tries = 50;
    unsigned int count;
    unsigned int delay;

    while(dhcp_tries--)
    {
            dhcp_start(&hdkNetIF[instNum]);

    state = &(hdkNetIF[instNum].dhcp->state);
    if(DHCP_BOUND == *state)
    {
        dhcp_flag = 1;
        ipAddrPtr = (unsigned int*)&(hdkNetIF[instNum].ip_addr);
        return (*ipAddrPtr);
    }

    while (!((*((volatile uint32_t *)(EMAC_BASE + EMAC_MACINVECTOR))) & EMAC_MACINVECTOR_RXPEND ))
    {
        /* Wait for RX receive flag */
    }
    lwIPRxIntHandler(0U);

    state = &(hdkNetIF[instNum].dhcp->state);
    if(DHCP_BOUND == *state)
    {
        dhcp_flag = 1;
       ipAddrPtr = (unsigned int*)&(hdkNetIF[instNum].ip_addr);
       return (*ipAddrPtr);
    }

    while((*((volatile uint32_t *)(EMAC_BASE + EMAC_MACINVECTOR))) & EMAC_MACINVECTOR_TXPEND)
    {
        lwIPTxIntHandler(0U);
    }

    delay = 0x8FFFFU;
    while(delay--);

    state = &(hdkNetIF[instNum].dhcp->state);
    if(DHCP_BOUND == *state)
    {
        dhcp_flag = 1;
        ipAddrPtr = (unsigned int*)&(hdkNetIF[instNum].ip_addr);
        return (*ipAddrPtr);
    }

    while (!((*((volatile uint32_t *)(EMAC_BASE + EMAC_MACINVECTOR))) & EMAC_MACINVECTOR_RXPEND ))
    {
      /* Wait for RX receive flag */
    }
    lwIPRxIntHandler(0U);

    state = &(hdkNetIF[instNum].dhcp->state);
    if(DHCP_BOUND == *state)
    {
        dhcp_flag = 1;
        ipAddrPtr = (unsigned int*)&(hdkNetIF[instNum].ip_addr);
        return (*ipAddrPtr);
    }

    }

    }

    2. To get the Static IP by polling ,

           In  etharp_raw() function of etharp.c file

    result = netif->linkoutput(netif, p);
    ETHARP_STATS_INC(etharp.xmit);

    while((*((volatile uint32_t *)(EMAC_BASE + EMAC_MACINVECTOR))) & EMAC_MACINVECTOR_TXPEND)
    {
    lwIPTxIntHandler(0U);
    }

    while (!((*((volatile uint32_t *)(EMAC_BASE + EMAC_MACINVECTOR))) & EMAC_MACINVECTOR_RXPEND ))
    {
    /* Wait for RX receive flag */
    }
    lwIPRxIntHandler(0U);



    /* free ARP query packet */
    pbuf_free(p);

    By using the above logic, we get the IP if we are executing the code in debug mode. if we place the code in free running mode , then we always reported as '0.0.0.0' IP.3. In main while loop.

    please advise.

    3. we did following changes for polling.

    in while(1) loop,

    if((*((volatile uint32_t *)(EMAC_BASE + EMAC_MACINVECTOR))) & EMAC_MACINVECTOR_TXPEND)
    {
    lwIPTxIntHandler(0U);
    }

    if (((*((volatile uint32_t *)(EMAC_BASE + EMAC_MACINVECTOR))) & EMAC_MACINVECTOR_RXPEND ))
    {
    lwIPRxIntHandler(0U);
    }

  • In reply to pramod gaikwad:

    QJ,

    cn you please provide comment on above code.

  • In reply to pramod gaikwad:

    Can someone LwIP expert comment on above code?

    Is the changes are correctly addressed or still we are missing somewhere?