Ethernet Connection Status

Introduction

I wrote a wrapper code that returns information about the status of the Ethernet connection.


The code

code snippet

#include "lpc_phy.h"

/** \brief DP83848 PHY status definitions */
#define DP8_REMOTEFAULT    (1 << 6)   /**< Remote fault */
#define DP8_FULLDUPLEX     (1 << 2)   /**< 1=full duplex */
#define DP8_SPEED10MBPS    (1 << 1)   /**< 1=10MBps speed */
#define DP8_VALID_LINK     (1 << 0)   /**< 1=Link active */


    // This function returns the current status of connection.
static bool get_link_status()
{
    u32_t tmp = lpc_mii_read_data();        
    return (tmp & DP8_VALID_LINK) ? true : false;
}

    // This function returns the status of transmission.
static char* get_transmission_status()
{
    u32_t tmp = lpc_mii_read_data();
    if(tmp & DP8_FULLDUPLEX)
    { 
        return "FULL DUPLEX"; 
    }else
    {        
        return "HALF DUPLEX";
    }
}

    // This function returns the speed of the connection.
static int get_connection_speed()
{
    u32_t tmp = lpc_mii_read_data();
    return (tmp & DP8_SPEED10MBPS) ? 10 : 100;
}

    // This function returns the current value in the MII data register.
static u32_t mii_read_data()
{
    return lpc_mii_read_data();  // 16-bit MRDD - address 0x2008 4030                             
}


Example code

Import programEthernet_Status_HelloWorld

Example of code that returns information about the status of the Ethernet connection.


How it works?

When the mbed has finished initialization of the ethernet it prints to serial the type and the speed of ethernet connection.
Then when the connection is established and the cable is disconnected the mbed sets the led 1 to on and prints a warning message.


Output

/media/uploads/edodm85/outputethstatus.bmp


Please log in to post comments.