Index: src/asf/avr32/drivers/macb/macb.c =================================================================== --- src/asf/avr32/drivers/macb/macb.c (revision 307) +++ src/asf/avr32/drivers/macb/macb.c (working copy) @@ -782,11 +782,67 @@ macb->ncr &= ~AVR32_MACB_NCR_MPE_MASK; } +static void prvSetupMACBConfig(volatile avr32_macb_t *macb) +{ + volatile unsigned long lpa, config, advertise; + + // read the LPA configuration of the PHY + lpa = ulReadMDIO(macb, PHY_LPA); + + // read the MACB config register + config = macb->ncfgr; + + // set advertise register +#if ETHERNET_CONF_AN_ENABLE == 1 + advertise = ADVERTISE_CSMA | ADVERTISE_ALL; +#else + advertise = ADVERTISE_CSMA; + #if ETHERNET_CONF_USE_100MB + #if ETHERNET_CONF_USE_FULL_DUPLEX + advertise |= ADVERTISE_100FULL; + #else + advertise |= ADVERTISE_100HALF; + #endif + #else + #if ETHERNET_CONF_USE_FULL_DUPLEX + advertise |= ADVERTISE_10FULL; + #else + advertise |= ADVERTISE_10HALF; + #endif + #endif +#endif + + // if 100MB needed + if ((lpa & advertise) & (LPA_100HALF | LPA_100FULL)) + { + config |= AVR32_MACB_SPD_MASK; + } + else + { + config &= ~(AVR32_MACB_SPD_MASK); + } + + // if FULL DUPLEX needed + if ((lpa & advertise) & (LPA_10FULL | LPA_100FULL)) + { + config |= AVR32_MACB_FD_MASK; + } + else + { + config &= ~(AVR32_MACB_FD_MASK); + } + + // write the MACB config register + macb->ncfgr = config; +} + static bool prvProbePHY(volatile avr32_macb_t *macb) { +#if ETHERNET_CONF_USE_PHY_IT == 0 volatile unsigned long mii_status; +#endif /* ETHERNET_CONF_USE_PHY_IT == 0 */ volatile unsigned long config; - unsigned long upper, lower, advertise, lpa; + unsigned long upper, lower, advertise; volatile unsigned long physID; // Read Phy Identifier register 1 & 2 @@ -832,40 +888,15 @@ // update ctrl register vWriteMDIO(macb, PHY_BMCR, config); +#if ETHERNET_CONF_USE_PHY_IT == 0 // loop while link status isn't OK do { mii_status = ulReadMDIO(macb, PHY_BMSR); } while (!(mii_status & BMSR_LSTATUS)); - // read the LPA configuration of the PHY - lpa = ulReadMDIO(macb, PHY_LPA); + prvSetupMACBConfig(macb); +#endif /* ETHERNET_CONF_USE_PHY_IT == 0 */ - // read the MACB config register - config = AVR32_MACB.ncfgr; - - // if 100MB needed - if ((lpa & advertise) & (LPA_100HALF | LPA_100FULL)) - { - config |= AVR32_MACB_SPD_MASK; - } - else - { - config &= ~(AVR32_MACB_SPD_MASK); - } - - // if FULL DUPLEX needed - if ((lpa & advertise) & (LPA_10FULL | LPA_100FULL)) - { - config |= AVR32_MACB_FD_MASK; - } - else - { - config &= ~(AVR32_MACB_FD_MASK); - } - - // write the MACB config register - macb->ncfgr = config; - return true; } return false; @@ -1045,6 +1076,10 @@ // dummy read ulEventStatus = ulReadMDIO(&AVR32_MACB, PHY_BMSR); + if(ulEventStatus & BMSR_LSTATUS) { + prvSetupMACBConfig(&AVR32_MACB); + } + // clear interrupt flag on GPIO gpio_port->ifrc = 1 << (EXTPHY_MACB_INTERRUPT_PIN%32);