lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] how to set the link up


From: massimiliano cialdi
Subject: Re: [lwip-users] how to set the link up
Date: Fri, 7 Jul 2017 17:54:49 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1

I changed the task in this way but nothing changes:

static void PhyStatus_Task( struct netif *netif )
{
    enum { link_up, link_down } linkstatus = link_down;
    phy_speed_t physpeed;
    phy_duplex_t phyduplex;
    bool link;
    status_t result;

    while(1)
    {
        switch (linkstatus)
        {
        case link_down:
            vTaskDelay(100);
            ETHSPDOFF();
            netifapi_netif_set_link_down(netif);
            while(1)
            {
                result = ethernetif_GetLinkStatus(netif, &link);
                if(result == kStatus_Success)
                {
                    if(link == true)
                    {
                        break;
                    }
                }
            }

            linkstatus = link_up;
            break;
        case link_up:
            netifapi_netif_set_link_up(netif);
            while(1)
            {
                vTaskDelay(100);
                result = ethernetif_GetLinkStatus(netif, &link);
                if(result == kStatus_Success)
                {
                    if(link == false)
                    {
                        break;
                    }
                    else
                    {
result = ethernetif_GetLinkSpeedDuplex(netif, &physpeed, &phyduplex);
                        if(result == kStatus_Success)
                        {
                            ETHSPD(physpeed);
                        }
                    }
                }
                else
                    break;
            }
            linkstatus = link_down;
            break;
        }
    }
}

best regards
Max

On 07/07/2017 17:27, massimiliano cialdi wrote:
I have implement a task to check phy status (similar to what you do), and also I use netifapi_* functions:


static void PhyStatus_Task( struct netif *netif )
{
    phy_speed_t physpeed;
    phy_duplex_t phyduplex;
    bool linkstatus;
    status_t result;

    ETHSPDOFF();

    while(1)
    {
        result = ethernetif_GetLinkStatus(netif, &linkstatus);
        if(result == kStatus_Success)
        {
            if(linkstatus == true)
            {
result = ethernetif_GetLinkSpeedDuplex(netif, &physpeed, &phyduplex);
                if(result == kStatus_Success)
                {
                    ETHSPD(physpeed);
                }
                netifapi_netif_set_link_up(netif);
            }
            else
            {
                ETHSPDOFF();
                netifapi_netif_set_link_down(netif);
            }

        }
        else
        {
            ETHSPDOFF();
            netifapi_netif_set_link_down(netif);
        }

        vTaskDelay(100);
    }
}

unfortunately I have a problem: when netif_set_link_up() is finally called always return immediately:


void
netif_set_link_up(struct netif *netif)
{
  if (!(netif->flags & NETIF_FLAG_LINK_UP)) {
    netif->flags |= NETIF_FLAG_LINK_UP;

#if LWIP_DHCP
    dhcp_network_changed(netif);
#endif /* LWIP_DHCP */

#if LWIP_AUTOIP
    autoip_network_changed(netif);
#endif /* LWIP_AUTOIP */

    if (netif->flags & NETIF_FLAG_UP) {
netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV4|NETIF_REPORT_TYPE_IPV6);
    }
    NETIF_LINK_CALLBACK(netif);
  }
}


first 'if' is always false, and I wonder why


best regads

Max


On 05/07/2017 19:21, Noam Weissman wrote:

Yes Sylvain 😊

I already changed the code according to your comments 😊


Thanks.



------------------------------------------------------------------------
*From:* lwip-users <address@hidden> on behalf of Sylvain Rochet <address@hidden>
*Sent:* Wednesday, July 5, 2017 8:08 PM
*To:* Mailing list for lwIP users
*Subject:* Re: [lwip-users] how to set the link up
Hi,

On Wed, Jul 05, 2017 at 04:55:24PM +0000, Noam Weissman wrote:
>
> My DHCP task calls dhcp_start and wait for an IP. If there is a
> timeout the task will assign a static default IP. You can do something
> similar.

Erm, should I add that dhcp_start() is not thread safe ?

Sylvain







reply via email to

[Prev in Thread] Current Thread [Next in Thread]