diff --git a/src/drivers/imxrt.c b/src/drivers/imxrt.c index 952f7dfd..2178af73 100644 --- a/src/drivers/imxrt.c +++ b/src/drivers/imxrt.c @@ -104,6 +104,7 @@ static bool mg_tcpip_driver_imxrt_init(struct mg_tcpip_if *ifp) { ENET->MSCR = (1 << 8) | ((cr & 0x3f) << 1); // HOLDTIME 2 clks struct mg_phy phy = {enet_read_phy, enet_write_phy}; mg_phy_init(&phy, d->phy_addr, MG_PHY_LEDS_ACTIVE_HIGH); // MAC clocks PHY + mg_tcpip_call(ifp, MG_TCPIP_EV_PHY_INIT, &phy); // Select RMII mode, 100M, keep CRC, set max rx length, disable loop ENET->RCR = (1518 << 16) | MG_BIT(8) | MG_BIT(2); // ENET->RCR |= MG_BIT(3); // Receive all diff --git a/src/drivers/netc.c b/src/drivers/netc.c index c8fbe13b..2b636d9f 100644 --- a/src/drivers/netc.c +++ b/src/drivers/netc.c @@ -243,6 +243,7 @@ static bool mg_tcpip_driver_netc_init(struct mg_tcpip_if *ifp) { NETC_EMDIO->EMDIO_CFG = ((mdc_cr & 0x1ffU) << 7) | MG_BIT(2); // MDIO_CLK_DIV, MDIO_HOLD mg_phy_init(&phy, d->phy_addr, MG_PHY_RGMII); + mg_tcpip_call(ifp, MG_TCPIP_EV_PHY_INIT, &phy); // Initialize ENETC1 PSI0 and port NETC_ENETC1_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS diff --git a/src/drivers/ra.c b/src/drivers/ra.c index 4208067a..6ac8f241 100644 --- a/src/drivers/ra.c +++ b/src/drivers/ra.c @@ -164,6 +164,7 @@ static bool mg_tcpip_driver_ra_init(struct mg_tcpip_if *ifp) { MG_DEBUG(("PHY addr: %d, smispin: %d", d->phy_addr, s_smispin)); struct mg_phy phy = {raeth_read_phy, raeth_write_phy}; mg_phy_init(&phy, d->phy_addr, MG_PHY_CLOCKS_MAC); + mg_tcpip_call(ifp, MG_TCPIP_EV_PHY_INIT, &phy); // Select RMII mode, ETHERC->ECMR = MG_BIT(2) | MG_BIT(1); // 100M, Full-duplex, CRC diff --git a/src/drivers/rw612.c b/src/drivers/rw612.c index 6e129133..2c9fb772 100644 --- a/src/drivers/rw612.c +++ b/src/drivers/rw612.c @@ -69,6 +69,7 @@ static bool mg_tcpip_driver_rw612_init(struct mg_tcpip_if *ifp) { ENET->MSCR = ((d->mdc_cr & 0x3f) << 1) | ((d->mdc_holdtime & 7) << 8); struct mg_phy phy = {eth_read_phy, eth_write_phy}; mg_phy_init(&phy, d->phy_addr, 0); + mg_tcpip_call(ifp, MG_TCPIP_EV_PHY_INIT, &phy); ENET->ECR |= MG_BIT(0); // reset ETH // initialize descriptors diff --git a/src/drivers/same54.c b/src/drivers/same54.c index 68195135..5908b192 100644 --- a/src/drivers/same54.c +++ b/src/drivers/same54.c @@ -128,6 +128,7 @@ static bool mg_tcpip_driver_same54_init(struct mg_tcpip_if *ifp) { struct mg_phy phy = {eth_read_phy, eth_write_phy}; mg_phy_init(&phy, d->phy_addr, 0); + mg_tcpip_call(ifp, MG_TCPIP_EV_PHY_INIT, &phy); for (int i = 0; i < ETH_DESC_CNT; i++) { // Init TX descriptors s_txdesc[i][0] = (uint32_t) s_txbuf[i]; // Point to data buffer diff --git a/src/drivers/stm32f.c b/src/drivers/stm32f.c index a303f059..3919afd3 100644 --- a/src/drivers/stm32f.c +++ b/src/drivers/stm32f.c @@ -142,6 +142,7 @@ static bool mg_tcpip_driver_stm32f_init(struct mg_tcpip_if *ifp) { ETH->MACFFR = MG_BIT(10); // Perfect filtering struct mg_phy phy = {eth_read_phy, eth_write_phy}; mg_phy_init(&phy, phy_addr, MG_PHY_CLOCKS_MAC); + mg_tcpip_call(ifp, MG_TCPIP_EV_PHY_INIT, &phy); ETH->DMARDLAR = (uint32_t) (uintptr_t) s_rxdesc; // RX descriptors ETH->DMATDLAR = (uint32_t) (uintptr_t) s_txdesc; // RX descriptors ETH->DMAIER = MG_BIT(6) | MG_BIT(16); // RIE, NISE diff --git a/src/drivers/stm32h.c b/src/drivers/stm32h.c index 80abb704..23b110b8 100644 --- a/src/drivers/stm32h.c +++ b/src/drivers/stm32h.c @@ -196,6 +196,7 @@ static bool mg_tcpip_driver_stm32h_init(struct mg_tcpip_if *ifp) { #endif struct mg_phy phy = {eth_read_phy, eth_write_phy}; mg_phy_init(&phy, phy_addr, phy_conf); + mg_tcpip_call(ifp, MG_TCPIP_EV_PHY_INIT, &phy); ETH->DMACRDLAR = (uint32_t) (uintptr_t) s_rxdesc; // RX descriptors start address ETH->DMACRDRLR = ETH_DESC_CNT - 1; // ring length diff --git a/src/drivers/tms570.c b/src/drivers/tms570.c index 68b83842..bffc7318 100644 --- a/src/drivers/tms570.c +++ b/src/drivers/tms570.c @@ -108,6 +108,7 @@ static bool mg_tcpip_driver_tms570_init(struct mg_tcpip_if *ifp) { while (delay-- != 0) (void) 0; struct mg_phy phy = {emac_read_phy, emac_write_phy}; mg_phy_init(&phy, d->phy_addr, MG_PHY_CLOCKS_MAC); + mg_tcpip_call(ifp, MG_TCPIP_EV_PHY_INIT, &phy); uint32_t channel; for (channel = 0; channel < 8; channel++) { EMAC->MACINDEX = channel; diff --git a/src/drivers/xmc.c b/src/drivers/xmc.c index 4ea411d9..dfad030a 100644 --- a/src/drivers/xmc.c +++ b/src/drivers/xmc.c @@ -89,6 +89,7 @@ static bool mg_tcpip_driver_xmc_init(struct mg_tcpip_if *ifp) { // init phy struct mg_phy phy = {eth_read_phy, eth_write_phy}; mg_phy_init(&phy, d->phy_addr, MG_PHY_CLOCKS_MAC); + mg_tcpip_call(ifp, MG_TCPIP_EV_PHY_INIT, &phy); // configure MAC: DO, DM, FES, TC ETH0->MAC_CONFIGURATION = MG_BIT(13) | MG_BIT(11) | MG_BIT(14) | MG_BIT(24); diff --git a/src/drivers/xmc7.c b/src/drivers/xmc7.c index 05eba9b2..2edb217d 100644 --- a/src/drivers/xmc7.c +++ b/src/drivers/xmc7.c @@ -150,6 +150,7 @@ static bool mg_tcpip_driver_xmc7_init(struct mg_tcpip_if *ifp) { // init phy struct mg_phy phy = {eth_read_phy, eth_write_phy}; mg_phy_init(&phy, d->phy_addr, MG_PHY_RGMII); + mg_tcpip_call(ifp, MG_TCPIP_EV_PHY_INIT, &phy); (void) d; return true; diff --git a/src/net_builtin.c b/src/net_builtin.c index bffb8709..01ea63ee 100644 --- a/src/net_builtin.c +++ b/src/net_builtin.c @@ -251,6 +251,7 @@ void mg_tcpip_call(struct mg_tcpip_if *ifp, int ev, void *ev_data) { "TCPIP_EV_WIFI_SCAN_END", "TCPIP_EV_WIFI_CONNECT_ERR", "TCPIP_EV_DRIVER", "TCPIP_EV_STATE6_CHANGE", "TCPIP_EV_PHY_RX", "TCPIP_EV_PHY_TX", + "TCPIP_EV_PHY_INIT", "TCPIP_EV_USER"}; if (ev != MG_TCPIP_EV_TIMER_1S && ev < (int) (sizeof(names) / sizeof(names[0]))) { MG_PROF_ADD(ifp, names[ev]); // TODO(): call MG_PROF_DUMP() MG_PROF_FREE() diff --git a/src/net_builtin.h b/src/net_builtin.h index f72337a1..ecceafcb 100644 --- a/src/net_builtin.h +++ b/src/net_builtin.h @@ -42,6 +42,7 @@ enum { MG_TCPIP_EV_STATE6_CHANGE, // IPv6 link state changed uint8_t *(&ifp->state6) MG_TCPIP_EV_PHY_RX, // Radio frame received struct mg_str * MG_TCPIP_EV_PHY_TX, // Radio frame about to be sent struct mg_str * + MG_TCPIP_EV_PHY_INIT, // PHY initialised struct mg_phy * MG_TCPIP_EV_USER // Starting ID for user-defined events }; // clang-format on