Skip to content

Commit 5e36500

Browse files
committed
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.
1 parent ed4bf78 commit 5e36500

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

features/netsocket/emac-drivers/TARGET_Freescale/k64f_emac.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ void K64F_EMAC::phy_task()
488488
PHY_GetLinkSpeedDuplex(ENET, phyAddr, &crt_state.speed, &crt_state.duplex);
489489

490490
// Compare with previous state
491-
if (crt_state.connected != prev_state.connected) {
491+
if (crt_state.connected != prev_state.connected && emac_link_state_cb) {
492492
emac_link_state_cb(crt_state.connected);
493493
}
494494

features/netsocket/emac-drivers/TARGET_STM/stm32xx_emac.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,14 @@ void STM32_EMAC::thread_function(void* pvParameters)
347347
void STM32_EMAC::phy_task()
348348
{
349349
uint32_t status;
350+
350351
if (HAL_ETH_ReadPHYRegister(&EthHandle, PHY_BSR, &status) == HAL_OK) {
351-
if ((status & PHY_LINKED_STATUS) && !(phy_status & PHY_LINKED_STATUS)) {
352-
emac_link_state_cb(true);
353-
} else if (!(status & PHY_LINKED_STATUS) && (phy_status & PHY_LINKED_STATUS)) {
354-
emac_link_state_cb(false);
352+
if (emac_link_state_cb) {
353+
if ((status & PHY_LINKED_STATUS) && !(phy_status & PHY_LINKED_STATUS)) {
354+
emac_link_state_cb(true);
355+
} else if (!(status & PHY_LINKED_STATUS) && (phy_status & PHY_LINKED_STATUS)) {
356+
emac_link_state_cb(false);
357+
}
355358
}
356359
phy_status = status;
357360
}

0 commit comments

Comments
 (0)