From 4c8314f8044617197c73e6603c21a1ef8cc5470a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 27 Sep 2009 15:57:02 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1190 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/io/mac.c | 13 ++++++++++ os/io/mac.h | 1 + os/io/platforms/AT91SAM7X/mac_lld.c | 39 +++++++++++++++++++++++++++++ os/io/platforms/AT91SAM7X/mac_lld.h | 1 + os/io/templates/mac_lld.c | 13 ++++++++++ os/io/templates/mac_lld.h | 1 + 6 files changed, 68 insertions(+) diff --git a/os/io/mac.c b/os/io/mac.c index 0a2736458..d7c20df05 100644 --- a/os/io/mac.c +++ b/os/io/mac.c @@ -169,4 +169,17 @@ void macReleaseReceiveDescriptor(MACDriver *macp, mac_lld_release_receive_descriptor(macp, rdp); } +/** + * @brief Updates and returns the link status. + * + * @param[in] macp pointer to the @p MACDriver object + * @return The link status. + * @retval TRUE if the link is active. + * @retval FALSE if the link is down. + */ +bool_t macPollLinkStatus(MACDriver *macp) { + + return mac_lld_poll_link_status(macp); +} + /** @} */ diff --git a/os/io/mac.h b/os/io/mac.h index 1cb135297..de2120ec4 100644 --- a/os/io/mac.h +++ b/os/io/mac.h @@ -73,6 +73,7 @@ extern "C" { systime_t time); void macReleaseReceiveDescriptor(MACDriver *macp, MACReceiveDescriptor *rdp); + bool_t macPollLinkStatus(MACDriver *macp); #ifdef __cplusplus } #endif diff --git a/os/io/platforms/AT91SAM7X/mac_lld.c b/os/io/platforms/AT91SAM7X/mac_lld.c index 916a125f0..7b0d4b86a 100644 --- a/os/io/platforms/AT91SAM7X/mac_lld.c +++ b/os/io/platforms/AT91SAM7X/mac_lld.c @@ -379,4 +379,43 @@ uint8_t *mac_lld_get_receive_buffer(MACReceiveDescriptor *rdp) { return (uint8_t *)(rdp->w1 & W1_R_ADDRESS_MASK); } +/** + * @brief Updates and returns the link status. + * + * @param[in] macp pointer to the @p MACDriver object + * @return The link status. + * @retval TRUE if the link is active. + * @retval FALSE if the link is down. + */ +bool_t mac_lld_poll_link_status(MACDriver *macp) { + uint32_t ncfgr, bmsr, bmcr, lpa; + + AT91C_BASE_EMAC->EMAC_NCR |= AT91C_EMAC_MPE; + (void)phyGet(macp, MII_BMSR); + bmsr = phyGet(macp, MII_BMSR); + if (!(bmsr & BMSR_LSTATUS)) { + AT91C_BASE_EMAC->EMAC_NCR &= ~AT91C_EMAC_MPE; + return link_up = FALSE; + } + + ncfgr = AT91C_BASE_EMAC->EMAC_NCFGR & ~(AT91C_EMAC_SPD | AT91C_EMAC_FD); + bmcr = phyGet(macp, MII_BMCR); + if (bmcr & BMCR_ANENABLE) { + lpa = phyGet(macp, MII_LPA); + if (lpa & (LPA_100HALF | LPA_100FULL | LPA_100BASE4)) + ncfgr |= AT91C_EMAC_SPD; + if (lpa & (LPA_10FULL | LPA_100FULL)) + ncfgr |= AT91C_EMAC_FD; + } + else { + if (bmcr & BMCR_SPEED100) + ncfgr |= AT91C_EMAC_SPD; + if (bmcr & BMCR_FULLDPLX) + ncfgr |= AT91C_EMAC_FD; + } + AT91C_BASE_EMAC->EMAC_NCFGR = ncfgr; + AT91C_BASE_EMAC->EMAC_NCR &= ~AT91C_EMAC_MPE; + return link_up = TRUE; +} + /** @} */ diff --git a/os/io/platforms/AT91SAM7X/mac_lld.h b/os/io/platforms/AT91SAM7X/mac_lld.h index e038a43d7..05a8abb78 100644 --- a/os/io/platforms/AT91SAM7X/mac_lld.h +++ b/os/io/platforms/AT91SAM7X/mac_lld.h @@ -145,6 +145,7 @@ extern "C" { void mac_lld_release_receive_descriptor(MACDriver *macp, MACReceiveDescriptor *rdp); uint8_t *mac_lld_get_receive_buffer(MACReceiveDescriptor *rdp); + bool_t mac_lld_poll_link_status(MACDriver *macp); #ifdef __cplusplus } #endif diff --git a/os/io/templates/mac_lld.c b/os/io/templates/mac_lld.c index 45b3e0b50..c9bac58c0 100644 --- a/os/io/templates/mac_lld.c +++ b/os/io/templates/mac_lld.c @@ -123,4 +123,17 @@ uint8_t *mac_lld_get_receive_buffer(MACReceiveDescriptor *rdp) { return NULL; } +/** + * @brief Updates and returns the link status. + * + * @param[in] macp pointer to the @p MACDriver object + * @return The link status. + * @retval TRUE if the link is active. + * @retval FALSE if the link is down. + */ +bool_t mac_lld_poll_link_status(MACDriver *macp) { + + return FALSE; +} + /** @} */ diff --git a/os/io/templates/mac_lld.h b/os/io/templates/mac_lld.h index a01bf845e..10b84dc0f 100644 --- a/os/io/templates/mac_lld.h +++ b/os/io/templates/mac_lld.h @@ -86,6 +86,7 @@ extern "C" { void mac_lld_release_receive_descriptor(MACDriver *macp, MACReceiveDescriptor *rdp); uint8_t *mac_lld_get_receive_buffer(MACReceiveDescriptor *rdp); + bool_t mac_lld_poll_link_status(MACDriver *macp); #ifdef __cplusplus } #endif