EMAC: check link status callback is set

Nanostack doesn't set the link status callback. Make sure the two
example drivers don't crash if it isn't set.
pull/6847/head
Kevin Bracey 2018-01-10 09:37:07 +02:00
parent ef68eb8b4d
commit 5472a9703f
2 changed files with 8 additions and 5 deletions

View File

@ -488,7 +488,7 @@ void K64F_EMAC::phy_task()
PHY_GetLinkSpeedDuplex(ENET, phyAddr, &crt_state.speed, &crt_state.duplex);
// Compare with previous state
if (crt_state.connected != prev_state.connected) {
if (crt_state.connected != prev_state.connected && emac_link_state_cb) {
emac_link_state_cb(crt_state.connected);
}

View File

@ -347,11 +347,14 @@ void STM32_EMAC::thread_function(void* pvParameters)
void STM32_EMAC::phy_task()
{
uint32_t status;
if (HAL_ETH_ReadPHYRegister(&EthHandle, PHY_BSR, &status) == HAL_OK) {
if ((status & PHY_LINKED_STATUS) && !(phy_status & PHY_LINKED_STATUS)) {
emac_link_state_cb(true);
} else if (!(status & PHY_LINKED_STATUS) && (phy_status & PHY_LINKED_STATUS)) {
emac_link_state_cb(false);
if (emac_link_state_cb) {
if ((status & PHY_LINKED_STATUS) && !(phy_status & PHY_LINKED_STATUS)) {
emac_link_state_cb(true);
} else if (!(status & PHY_LINKED_STATUS) && (phy_status & PHY_LINKED_STATUS)) {
emac_link_state_cb(false);
}
}
phy_status = status;
}