Compare commits

..
1 Commits
Author SHA1 Message Date
Sergio R. Caprile 3d116475af remove PHY_TX/RX 2026-11-30 12:31:16 -03:00
16 changed files with 17 additions and 48 deletions

No files matched your search

+2 -7
View File
@@ -34596,11 +34596,8 @@ static void mgi_radio_frame_header(uint8_t *frame, uint16_t dst, uint16_t src,
frame[MGI_RADIO_HDR_LEN] = type, frame[MGI_RADIO_HDR_LEN + 1] = burst;
}
// Hand a radio frame to the hardware. The interface's fn sees it first
static bool mgi_radio_send(struct mg_radio_node *node, const void *frame,
size_t len) {
struct mg_str s = mg_str_n((const char *) frame, len);
mg_tcpip_call(node->ifp, MG_TCPIP_EV_PHY_TX, &s);
return node->hw_tx(node->ifp, frame, len) == len;
}
@@ -35121,12 +35118,10 @@ bool mg_radio_poll(struct mg_tcpip_if *ifp, bool s1) {
while (node->rx_len == 0 &&
(len = mg_queue_next(&node->frames, &record)) != 0) {
if (len > MGI_RX_STAMP_LEN) {
struct mg_str s =
mg_str_n(record + MGI_RX_STAMP_LEN, len - MGI_RX_STAMP_LEN);
uint64_t arrived;
memcpy(&arrived, record, MGI_RX_STAMP_LEN);
mg_tcpip_call(ifp, MG_TCPIP_EV_PHY_RX, &s);
mgi_radio_input(node, arrived, s.buf, s.len);
mgi_radio_input(node, arrived, record + MGI_RX_STAMP_LEN,
len - MGI_RX_STAMP_LEN);
}
mg_queue_del(&node->frames, len);
}
-2
View File
@@ -4799,8 +4799,6 @@ enum {
MG_TCPIP_EV_WIFI_CONNECT_ERR, // Wi-Fi connection failed driver and chip specific
MG_TCPIP_EV_DRIVER, // Driver-defined event driver specific
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_USER // Starting ID for user-defined events
};
// clang-format on
-1
View File
@@ -104,7 +104,6 @@ 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
-1
View File
@@ -243,7 +243,6 @@ 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
-1
View File
@@ -164,7 +164,6 @@ 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
+3 -7
View File
@@ -206,11 +206,9 @@ static void mgi_radio_frame_header(uint8_t *frame, uint16_t dst, uint16_t src,
frame[MGI_RADIO_HDR_LEN] = type, frame[MGI_RADIO_HDR_LEN + 1] = burst;
}
// Hand a radio frame to the hardware. The interface's fn sees it first
// Hand a radio frame to the hardware.
static bool mgi_radio_send(struct mg_radio_node *node, const void *frame,
size_t len) {
struct mg_str s = mg_str_n((const char *) frame, len);
mg_tcpip_call(node->ifp, MG_TCPIP_EV_PHY_TX, &s);
return node->hw_tx(node->ifp, frame, len) == len;
}
@@ -731,12 +729,10 @@ bool mg_radio_poll(struct mg_tcpip_if *ifp, bool s1) {
while (node->rx_len == 0 &&
(len = mg_queue_next(&node->frames, &record)) != 0) {
if (len > MGI_RX_STAMP_LEN) {
struct mg_str s =
mg_str_n(record + MGI_RX_STAMP_LEN, len - MGI_RX_STAMP_LEN);
uint64_t arrived;
memcpy(&arrived, record, MGI_RX_STAMP_LEN);
mg_tcpip_call(ifp, MG_TCPIP_EV_PHY_RX, &s);
mgi_radio_input(node, arrived, s.buf, s.len);
mgi_radio_input(node, arrived, record + MGI_RX_STAMP_LEN,
len - MGI_RX_STAMP_LEN);
}
mg_queue_del(&node->frames, len);
}
-1
View File
@@ -69,7 +69,6 @@ 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
-1
View File
@@ -128,7 +128,6 @@ 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
-1
View File
@@ -142,7 +142,6 @@ 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
-1
View File
@@ -196,7 +196,6 @@ 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
-1
View File
@@ -108,7 +108,6 @@ 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;
-1
View File
@@ -89,7 +89,6 @@ 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);
-1
View File
@@ -150,7 +150,6 @@ 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;
-1
View File
@@ -251,7 +251,6 @@ 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()
-3
View File
@@ -40,9 +40,6 @@ enum {
MG_TCPIP_EV_WIFI_CONNECT_ERR, // Wi-Fi connection failed driver and chip specific
MG_TCPIP_EV_DRIVER, // Driver-defined event driver specific
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
@@ -8,31 +8,27 @@
#define LED_LAN PIN(0, 0) // Blue, active low
#define LED_RED PIN(0, 1) // Red, active low
static uint64_t s_radio_led_until;
// Cumulative totals. Up: radio -> LAN; down: LAN -> radio queue.
static uint64_t s_frames_up, s_frames_down, s_bytes_up, s_bytes_down;
static uint64_t s_radio_sent, s_radio_received;
// Radio interface events: count radio frames, blink on reception
static void radio_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) {
if (ev == MG_TCPIP_EV_PHY_TX) s_radio_sent++;
if (ev == MG_TCPIP_EV_PHY_RX) {
s_radio_received++;
s_radio_led_until = mg_millis() + 2;
}
(void) ifp, (void) ev_data;
}
// Radio activity: successful frames crossing the bridge keep the LED on.
static uint64_t s_radio_led_until;
static size_t eth_up(const void *buf, size_t len, struct mg_tcpip_if *ifp) {
size_t sent = mg_tcpip_driver_rw612.tx(buf, len, ifp);
if (sent != 0) s_frames_up++, s_bytes_up += sent;
if (sent != 0) {
s_frames_up++, s_bytes_up += sent;
s_radio_led_until = mg_millis() + 2;
}
return sent;
}
static size_t eth_down(const void *buf, size_t len, struct mg_tcpip_if *ifp) {
size_t queued = mg_tcpip_driver_rw612w.tx(buf, len, ifp);
if (queued != 0) s_frames_down++, s_bytes_down += queued;
if (queued != 0) {
s_frames_down++, s_bytes_down += queued;
s_radio_led_until = mg_millis() + 2;
}
return queued;
}
@@ -66,7 +62,6 @@ int main(void) {
radio_driver = mg_tcpip_driver_rw612w;
radio_driver.tx = eth_down;
radio.driver = &radio_driver;
radio.fn = radio_fn;
if (!radio.driver->init(&radio)) return 1;
eth_data.mdc_cr = MG_DRIVER_MDC_CR;
@@ -95,9 +90,8 @@ int main(void) {
if (mg_timer_expired(&stats_timer, 5000, now)) {
MG_INFO(
("ETH frames up/down %llu/%llu, bytes up/down "
"%llu/%llu, radio frames sent/rcvd %llu/%llu",
s_frames_up, s_frames_down, s_bytes_up, s_bytes_down, s_radio_sent,
s_radio_received));
"%llu/%llu",
s_frames_up, s_frames_down, s_bytes_up, s_bytes_down));
}
if (eth.nrecv != lan_received) {
lan_received = eth.nrecv;