[En-Nut-Discussion] Detecting link state

Ole Reinhardt ole.reinhardt at embedded-it.de
Sun Jul 22 15:53:38 CEST 2018


Hi Philipp,

here is my link detection code, this should run at least with any common
PHY that uses the NutOS PHY driver.

#include <dev/phy.h>

/*!
 * \brief test if the physical network link is present
 *
 * \param retry      number of retry cycles. Should be one for only a
short test
 * \param retry_wait time to wait between retries. in ms
 *
 * \return 0: link established, -1: no network link
 */
int CheckPhysicalNetworkLink(int retry, int retry_wait)
{
    uint32_t phyval = 0;

    int link_ok = 0;

    while (!link_ok && (retry > 0)) {
        if (NutPhyCtl(PHY_GET_STATUS, &phyval) != 0) {
            link_ok = 0;
        } else {
            if (! ((phyval & PHY_STATUS_HAS_LINK) && (phyval &
PHY_STATUS_AUTONEG_OK))) {
                link_ok = 0;
            } else {
                link_ok = 1;
            }
        }
        if (retry > 0) {
            retry --;
            if ((retry > 0) && (retry_wait > 0)) NutSleep(retry_wait);
        }
    }

    return link_ok ? 0 : -1;
}


Best regards,

Ole


Am 21.07.2018 um 20:08 schrieb Philipp Burch:
> Hi Ole,
> 
> it's for the TIVA microcontrollers, which have an integrated PHY. But as
> far as I remember, it is used the same way as an external standard PHY.
> 
> Thanks!
> 
> Best regards,
> Philipp
> 
> On 21.07.2018 13:41, Ole Reinhardt wrote:
>> Hi Philipp,
>>
>> which platform are you using? I implemented a link state detection in
>> several projects running on the LPC plattform.
>>
>> But as the code mainly uses PHY communication it should run with any
>> plattform with external PHY.
>>
>> Later today I'll have access to the code and can send you an example.
>>
>> Best regards,
>>
>> Ole Reinhardt
>>
>> Am 10.07.2018 um 10:43 schrieb Philipp Burch:
>>> Hi everyone,
>>>
>>> is there a good way to detect if an Ethernet link has been established
>>> when using Ethernut? I see that this has been discussed in the past, but
>>> could not find any outcome:
>>>
>>> http://microcontrollers.2385.n7.nabble.com/detecting-an-unplugged-network-cable-td160042.html
>>>
>>> Thanks.
>>>
>>> Best regards,
>>> Philipp
>>> _______________________________________________
>>> http://lists.egnite.de/mailman/listinfo/en-nut-discussion
>>>
>>
> _______________________________________________
> http://lists.egnite.de/mailman/listinfo/en-nut-discussion
> 

-- 
Embedded-IT
Alter Weg 3
57223 Kreuztal
http://www.embedded-it.de

Tel.: +49-177-7420433


More information about the En-Nut-Discussion mailing list