fix: add bounded lwip connect waits and link status helper

This commit is contained in:
2026-04-22 23:59:19 +08:00
parent c8f27e21f1
commit afd90d357c
6 changed files with 23 additions and 1392 deletions
+7 -1
View File
@@ -1395,7 +1395,13 @@ lwip_netconn_do_connect(void *m)
#if LWIP_TCPIP_CORE_LOCKING #if LWIP_TCPIP_CORE_LOCKING
LWIP_ASSERT("state!", msg->conn->state == NETCONN_CONNECT); LWIP_ASSERT("state!", msg->conn->state == NETCONN_CONNECT);
UNLOCK_TCPIP_CORE(); UNLOCK_TCPIP_CORE();
sys_arch_sem_wait(LWIP_API_MSG_SEM(msg), 0); if (sys_arch_sem_wait(LWIP_API_MSG_SEM(msg), msg->conn->recv_timeout) == SYS_ARCH_TIMEOUT) {
if (msg->conn->state == NETCONN_CONNECT) {
msg->conn->current_msg = NULL;
msg->conn->state = NETCONN_NONE;
msg->err = ERR_TIMEOUT;
}
}
LOCK_TCPIP_CORE(); LOCK_TCPIP_CORE();
LWIP_ASSERT("state!", msg->conn->state != NETCONN_CONNECT); LWIP_ASSERT("state!", msg->conn->state != NETCONN_CONNECT);
#endif /* LWIP_TCPIP_CORE_LOCKING */ #endif /* LWIP_TCPIP_CORE_LOCKING */
@@ -24,6 +24,7 @@ err_t ethernetif_init(struct netif *netif);
void ethernetif_input(struct netif *netif); void ethernetif_input(struct netif *netif);
void lwip_netif_init(const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw); void lwip_netif_init(const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw);
void ethernetif_check_link(void); void ethernetif_check_link(void);
uint8_t ethernetif_link_is_up(void);
void ethernetif_poll(void); void ethernetif_poll(void);
void print_netif(struct netif *netif); void print_netif(struct netif *netif);
+9 -2
View File
@@ -457,6 +457,8 @@ void ethernetif_diag_poll_status(void)
*/ */
static void ethernetif_update_link(uint8_t link_status) static void ethernetif_update_link(uint8_t link_status)
{ {
LOCK_TCPIP_CORE();
if (link_status) if (link_status)
{ {
if (!netif_is_link_up(&ch390_netif)) if (!netif_is_link_up(&ch390_netif))
@@ -464,9 +466,7 @@ static void ethernetif_update_link(uint8_t link_status)
netif_set_link_up(&ch390_netif); netif_set_link_up(&ch390_netif);
if ((s_garp_sent == 0u) && netif_is_up(&ch390_netif)) if ((s_garp_sent == 0u) && netif_is_up(&ch390_netif))
{ {
LOCK_TCPIP_CORE();
etharp_gratuitous(&ch390_netif); etharp_gratuitous(&ch390_netif);
UNLOCK_TCPIP_CORE();
s_garp_sent = 1u; s_garp_sent = 1u;
} }
} }
@@ -479,6 +479,8 @@ static void ethernetif_update_link(uint8_t link_status)
s_garp_sent = 0u; s_garp_sent = 0u;
} }
} }
UNLOCK_TCPIP_CORE();
} }
/** /**
@@ -561,3 +563,8 @@ void ethernetif_check_link(void)
ethernetif_update_link(link_status); ethernetif_update_link(link_status);
} }
uint8_t ethernetif_link_is_up(void)
{
return netif_is_link_up(&ch390_netif) ? 1u : 0u;
}
+6
View File
@@ -63,6 +63,12 @@ void ethernetif_diag_poll_status(void);
*/ */
void ethernetif_check_link(void); void ethernetif_check_link(void);
/**
* @brief Query whether physical Ethernet link is currently up
* @return 1 if link is up, 0 otherwise
*/
uint8_t ethernetif_link_is_up(void);
/** /**
* @brief Process all pending RX packets * @brief Process all pending RX packets
* @note Call this from the LwIP task when RX interrupt occurs * @note Call this from the LwIP task when RX interrupt occurs
File diff suppressed because it is too large Load Diff
-8
View File
@@ -1,8 +0,0 @@
*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin'
Build target 'TCP2UART'
compiling tcp_client.c...
linking...
Program Size: Code=84560 RO-data=2496 RW-data=432 ZI-data=47056
FromELF: creating hex file...
"TCP2UART\TCP2UART.axf" - 0 Error(s), 0 Warning(s).
Build Time Elapsed: 00:00:01