Skip to content

Commit 5f6c5b6

Browse files
committed
Update Ethernet.linkStatus to handle Unknown status
Signed-off-by: Frederic Pillon <[email protected]>
1 parent 193a513 commit 5f6c5b6

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

src/STM32Ethernet.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server
103103

104104
EthernetLinkStatus EthernetClass::linkStatus()
105105
{
106-
return (stm32_eth_link_up() ? LinkON : LinkOFF);
106+
return (!stm32_eth_is_init()) ? Unknown : (stm32_eth_link_up() ? LinkON : LinkOFF);
107107
}
108108

109109
int EthernetClass::maintain(){

src/utility/ethernetif.c

+11
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,17 @@ void ethernetif_input(struct netif *netif)
431431
}
432432
}
433433

434+
/**
435+
* @brief Returns the current state
436+
*
437+
* @param None
438+
* @return 0 not initialized else 1
439+
*/
440+
uint8_t ethernetif_is_init(void)
441+
{
442+
return (EthHandle.State != HAL_ETH_STATE_RESET);
443+
}
444+
434445
/**
435446
* @brief Should be called at the beginning of the program to set up the
436447
* network interface. It calls the function low_level_init() to do the

src/utility/ethernetif.h

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#endif
5757

5858
/* Exported types ------------------------------------------------------------*/
59+
uint8_t ethernetif_is_init(void);
5960
err_t ethernetif_init(struct netif *netif);
6061
void ethernetif_input(struct netif *netif);
6162
void ethernetif_set_link(struct netif *netif);

src/utility/stm32_eth.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,15 @@ void stm32_eth_init(const uint8_t *mac, const uint8_t *ip, const uint8_t *gw, co
246246
stm32_eth_scheduler();
247247
}
248248

249+
/**
250+
* @brief Return Ethernet init status
251+
* @param None
252+
* @retval 1 for initialized, 0 for not initialized
253+
*/
254+
uint8_t stm32_eth_is_init(void) {
255+
return ethernetif_is_init();
256+
}
257+
249258
/**
250259
* @brief Return Ethernet link status
251260
* @param None

src/utility/stm32_eth.h

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ extern struct netif gnetif;
121121

122122
/* Exported functions ------------------------------------------------------- */
123123
void stm32_eth_init(const uint8_t *mac, const uint8_t *ip, const uint8_t *gw, const uint8_t *netmask);
124+
uint8_t stm32_eth_is_init(void);
124125
uint8_t stm32_eth_link_up(void);
125126
void stm32_eth_scheduler(void);
126127

0 commit comments

Comments
 (0)