Compare commits

..
1 Commits
Author SHA1 Message Date
cpq b30acaaabb can_write() honors link state 2026-11-26 11:50:49 +00:00
6 changed files with 17 additions and 21 deletions

No files matched your search

+5 -3
View File
@@ -12008,7 +12008,7 @@ static void mg_tcpip_poll(struct mg_tcpip_if *ifp, uint64_t now) {
if (expired_1000ms) { // ifp->state rules over state6 if (expired_1000ms) { // ifp->state rules over state6
mg_ip_link(ifp, drv_up, l2_up); // Handle IPv4 mg_ip_link(ifp, drv_up, l2_up); // Handle IPv4
mg_ip6_link(ifp, drv_up, l2_up); // Handle IPv6 mg_ip6_link(ifp, drv_up, l2_up); // Handle IPv6
if (ifp->state < MG_TCPIP_STATE_UP) MG_ERROR(("Network is down")); if (ifp->state < MG_TCPIP_STATE_UP) MG_ERROR(("Network is down, state %hhu", ifp->state));
mg_tcpip_call(ifp, MG_TCPIP_EV_TIMER_1S, NULL); mg_tcpip_call(ifp, MG_TCPIP_EV_TIMER_1S, NULL);
} }
} }
@@ -12254,8 +12254,10 @@ static void write_conn(struct mg_connection *c) {
} }
static bool can_write(struct mg_connection *c) { static bool can_write(struct mg_connection *c) {
return c->is_connecting == 0 && c->is_resolving == 0 && c->send.len > 0 && struct mg_tcpip_if *ifp = c->mgr->ifp;
c->is_tls_hs == 0 && c->is_arplooking == 0; bool ready = (ifp->ip != 0 && ifp->state == MG_TCPIP_STATE_READY);
return ready && c->is_connecting == 0 && c->is_resolving == 0 &&
c->send.len > 0 && c->is_tls_hs == 0 && c->is_arplooking == 0;
} }
void mg_mgr_poll(struct mg_mgr *mgr, int ms) { void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
+5 -3
View File
@@ -2200,7 +2200,7 @@ static void mg_tcpip_poll(struct mg_tcpip_if *ifp, uint64_t now) {
if (expired_1000ms) { // ifp->state rules over state6 if (expired_1000ms) { // ifp->state rules over state6
mg_ip_link(ifp, drv_up, l2_up); // Handle IPv4 mg_ip_link(ifp, drv_up, l2_up); // Handle IPv4
mg_ip6_link(ifp, drv_up, l2_up); // Handle IPv6 mg_ip6_link(ifp, drv_up, l2_up); // Handle IPv6
if (ifp->state < MG_TCPIP_STATE_UP) MG_ERROR(("Network is down")); if (ifp->state < MG_TCPIP_STATE_UP) MG_ERROR(("Network is down, state %hhu", ifp->state));
mg_tcpip_call(ifp, MG_TCPIP_EV_TIMER_1S, NULL); mg_tcpip_call(ifp, MG_TCPIP_EV_TIMER_1S, NULL);
} }
} }
@@ -2446,8 +2446,10 @@ static void write_conn(struct mg_connection *c) {
} }
static bool can_write(struct mg_connection *c) { static bool can_write(struct mg_connection *c) {
return c->is_connecting == 0 && c->is_resolving == 0 && c->send.len > 0 && struct mg_tcpip_if *ifp = c->mgr->ifp;
c->is_tls_hs == 0 && c->is_arplooking == 0; bool ready = (ifp->ip != 0 && ifp->state == MG_TCPIP_STATE_READY);
return ready && c->is_connecting == 0 && c->is_resolving == 0 &&
c->send.len > 0 && c->is_tls_hs == 0 && c->is_arplooking == 0;
} }
void mg_mgr_poll(struct mg_mgr *mgr, int ms) { void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
+2
View File
@@ -1280,6 +1280,8 @@ static void test_frag_send_path(void) {
mif.driver = &driver; mif.driver = &driver;
mif.driver_data = &s_driver_data; mif.driver_data = &s_driver_data;
mg_tcpip_init(&mgr, &mif); mg_tcpip_init(&mgr, &mif);
mif.ip = mg_htonl(0xa00001);
mif.state = MG_TCPIP_STATE_READY; // so can_write() lets the data out
mif.mtu = 500; // force ad hoc small MTU to fragment IP mif.mtu = 500; // force ad hoc small MTU to fragment IP
mg_http_listen(&mgr, "http://0.0.0.0:80", frag_send_fn, NULL); mg_http_listen(&mgr, "http://0.0.0.0:80", frag_send_fn, NULL);
mgr.conns->pfn = NULL; mgr.conns->pfn = NULL;
@@ -1,3 +0,0 @@
#pragma once
#define BOARD_ETH_PHY_ADDR 5U
+5 -9
View File
@@ -484,9 +484,7 @@ static inline uint8_t hal_uart_read_byte(LPUART_Type *uart) {
return (uint8_t) (uart->DATA & 0xFFU); return (uint8_t) (uart->DATA & 0xFFU);
} }
// NETC switch link binding needs PHY address, shared with Mongoose config #define HAL_NETC_PHY0_ADDR 5U
#include "board_config.h"
#define HAL_NETC_PHY0_RESET PIN('1', 15) #define HAL_NETC_PHY0_RESET PIN('1', 15)
static inline void hal_netc_trdc_region(uint8_t mrc, uint8_t domain, static inline void hal_netc_trdc_region(uint8_t mrc, uint8_t domain,
@@ -607,11 +605,6 @@ static inline void hal_netc_pins_init(void) {
} }
} }
// RT1180's SoC-specific topology fixes link 0 to switch port 0, link 4 to
// ENETC0, and link 5 between switch port 4 and ENETC1.
// Hardcoded to use link 0; Mongoose defaults to MG_TCPIP_NETC_LINK = 0
// Any use of other switch port x would need to access NETC_LINK_CFG[x] and
// NETC_IERB->LxBCR instead, and Mongoose needs MG_TCPIP_NETC_LINK = x
static inline bool hal_netc_ierb_init(void) { static inline bool hal_netc_ierb_init(void) {
uint32_t timeout = 1000000UL; uint32_t timeout = 1000000UL;
@@ -631,7 +624,10 @@ static inline bool hal_netc_ierb_init(void) {
// Attribute 1 permits MSI-X writes through the root-complex window. // Attribute 1 permits MSI-X writes through the root-complex window.
NETC_IERB->ARRAY_NUM_RC[0].RCMSIAMQR = NETC_IERB->ARRAY_NUM_RC[0].RCMSIAMQR =
(NETC_IERB->ARRAY_NUM_RC[0].RCMSIAMQR & ~(7UL << 27)) | (1UL << 27); (NETC_IERB->ARRAY_NUM_RC[0].RCMSIAMQR & ~(7UL << 27)) | (1UL << 27);
NETC_IERB->L0BCR = NETC_IERB_L0BCR_MDIO_PHYAD_PRTAD(BOARD_ETH_PHY_ADDR); // RT1180's SoC-specific topology fixes link 0 to switch port 0, link 4 to
// ENETC0, and link 5 between switch port 4 and ENETC1.
NETC_IERB->L0BCR =
NETC_IERB_L0BCR_MDIO_PHYAD_PRTAD(HAL_NETC_PHY0_ADDR);
__DSB(); __DSB();
if ((NETC_PRIV->NETCSR & NETC_PRIV_NETCSR_ERROR_MASK) != 0U) return false; if ((NETC_PRIV->NETCSR & NETC_PRIV_NETCSR_ERROR_MASK) != 0U) return false;
@@ -3,9 +3,6 @@
#define MG_ENABLE_TCPIP 1 #define MG_ENABLE_TCPIP 1
#define MG_ENABLE_DRIVER_NETC 1 #define MG_ENABLE_DRIVER_NETC 1
#define MG_OTA MG_OTA_RT1180 #define MG_OTA MG_OTA_RT1180
// Keep the Mongoose PHY address aligned with NETC switch link binding
#include "board_config.h"
#define MG_TCPIP_PHY_ADDR BOARD_ETH_PHY_ADDR
#define MG_IO_SIZE 256 #define MG_IO_SIZE 256
#define MG_ENABLE_CUSTOM_MILLIS 1 #define MG_ENABLE_CUSTOM_MILLIS 1