Skip to content

Commit

Permalink
Change driver API: up(ifp) -> poll(ifp, 1second)
Browse files Browse the repository at this point in the history
Add misc extras required by Wi-Fi drivers (in progress)
  • Loading branch information
scaprile committed Feb 5, 2025
1 parent ef8e741 commit c5508a4
Show file tree
Hide file tree
Showing 30 changed files with 356 additions and 245 deletions.
5 changes: 3 additions & 2 deletions examples/pico-sdk/pico-rmii/driver_rp2040_rmii.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ static void rx_irq(void) {
s_rxno = rxno;
}

static bool mg_tcpip_driver_rp2040_rmii_up(struct mg_tcpip_if *ifp) {
static bool mg_tcpip_driver_rp2040_rmii_poll(struct mg_tcpip_if *ifp, bool s1) {
if (!s1) return false;
struct mg_tcpip_driver_rp2040_rmii_data *d =
(struct mg_tcpip_driver_rp2040_rmii_data *) ifp->driver_data;
uint32_t bsr =
Expand All @@ -332,5 +333,5 @@ struct mg_tcpip_driver mg_tcpip_driver_rp2040_rmii = {
mg_tcpip_driver_rp2040_rmii_init,
mg_tcpip_driver_rp2040_rmii_tx,
NULL,
mg_tcpip_driver_rp2040_rmii_up,
mg_tcpip_driver_rp2040_rmii_poll,
};
8 changes: 4 additions & 4 deletions examples/pico-sdk/pico-rndis-dashboard/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ static size_t usb_tx(const void *buf, size_t len, struct mg_tcpip_if *ifp) {
return len;
}

static bool usb_up(struct mg_tcpip_if *ifp) {
static bool usb_poll(struct mg_tcpip_if *ifp, bool s1) {
(void) ifp;
return tud_inited() && tud_ready() && tud_connected();
tud_task();
return s1 ? tud_inited() && tud_ready() && tud_connected() : false;
}

static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_dta) {
Expand All @@ -57,7 +58,7 @@ int main(void) {
mg_mgr_init(&mgr); // and attach it to the interface
mg_timer_add(&mgr, 500, MG_TIMER_REPEAT, blink_cb, &mgr);

struct mg_tcpip_driver driver = {.tx = usb_tx, .up = usb_up};
struct mg_tcpip_driver driver = {.tx = usb_tx, .poll = usb_poll};
struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 0x77},
.ip = mg_htonl(MG_U32(192, 168, 3, 1)),
.mask = mg_htonl(MG_U32(255, 255, 255, 0)),
Expand All @@ -74,7 +75,6 @@ int main(void) {
MG_INFO(("Starting event loop"));
for (;;) {
mg_mgr_poll(&mgr, 0);
tud_task();
}

return 0;
Expand Down
8 changes: 4 additions & 4 deletions examples/pico-sdk/pico-rndis-device/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ static size_t usb_tx(const void *buf, size_t len, struct mg_tcpip_if *ifp) {
return len;
}

static bool usb_up(struct mg_tcpip_if *ifp) {
static bool usb_poll(struct mg_tcpip_if *ifp, bool s1) {
(void) ifp;
return tud_inited() && tud_ready() && tud_connected();
tud_task();
return s1 ? tud_inited() && tud_ready() && tud_connected() : false;
}

static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_dta) {
Expand All @@ -69,7 +70,7 @@ int main(void) {
struct mg_mgr mgr; // Initialise Mongoose event manager
mg_mgr_init(&mgr); // and attach it to the interface

struct mg_tcpip_driver driver = {.tx = usb_tx, .up = usb_up};
struct mg_tcpip_driver driver = {.tx = usb_tx, .poll = usb_poll};
struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 0x77},
.ip = mg_htonl(MG_U32(192, 168, 3, 1)),
.mask = mg_htonl(MG_U32(255, 255, 255, 0)),
Expand All @@ -87,7 +88,6 @@ int main(void) {
MG_INFO(("Starting event loop"));
for (;;) {
mg_mgr_poll(&mgr, 0);
tud_task();
}

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ static size_t usb_tx(const void *buf, size_t len, struct mg_tcpip_if *ifp) {
return len;
}

static bool usb_up(struct mg_tcpip_if *ifp) {
static bool usb_poll(struct mg_tcpip_if *ifp, bool s1) {
(void) ifp;
return tud_inited() && tud_ready() && tud_connected();
tud_task();
return s1 ? tud_inited() && tud_ready() && tud_connected() : false;
}

static void fn(struct mg_connection *c, int ev, void *ev_data) {
Expand All @@ -87,7 +88,7 @@ int main(void) {


MG_INFO(("Init TCP/IP stack ..."));
struct mg_tcpip_driver driver = {.tx = usb_tx, .up = usb_up};
struct mg_tcpip_driver driver = {.tx = usb_tx, .poll = usb_poll};
struct mg_tcpip_if mif = {.mac = GENERATE_LOCALLY_ADMINISTERED_MAC(),
.ip = mg_htonl(MG_U32(192, 168, 3, 1)),
.mask = mg_htonl(MG_U32(255, 255, 255, 0)),
Expand All @@ -106,7 +107,6 @@ int main(void) {
MG_INFO(("Init done, starting main loop ..."));
for (;;) {
mg_mgr_poll(&mgr, 0);
tud_task();
}

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ static size_t usb_tx(const void *buf, size_t len, struct mg_tcpip_if *ifp) {
return len;
}

static bool usb_up(struct mg_tcpip_if *ifp) {
static bool usb_poll(struct mg_tcpip_if *ifp, bool s1) {
(void) ifp;
return tud_inited() && tud_ready() && tud_connected();
tud_task();
return s1 ? tud_inited() && tud_ready() && tud_connected() : false;
}

static void fn(struct mg_connection *c, int ev, void *ev_data) {
Expand All @@ -87,7 +88,7 @@ int main(void) {


MG_INFO(("Init TCP/IP stack ..."));
struct mg_tcpip_driver driver = {.tx = usb_tx, .up = usb_up};
struct mg_tcpip_driver driver = {.tx = usb_tx, .poll = usb_poll};
struct mg_tcpip_if mif = {.mac = GENERATE_LOCALLY_ADMINISTERED_MAC(),
.ip = mg_htonl(MG_U32(192, 168, 3, 1)),
.mask = mg_htonl(MG_U32(255, 255, 255, 0)),
Expand All @@ -106,7 +107,6 @@ int main(void) {
MG_INFO(("Init done, starting main loop ..."));
for (;;) {
mg_mgr_poll(&mgr, 0);
tud_task();
}

return 0;
Expand Down
8 changes: 4 additions & 4 deletions examples/ti/ek-tm4c1294xl-make-baremetal-builtin-rndis/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ static size_t usb_tx(const void *buf, size_t len, struct mg_tcpip_if *ifp) {
return len;
}

static bool usb_up(struct mg_tcpip_if *ifp) {
static bool usb_poll(struct mg_tcpip_if *ifp, bool s1) {
(void) ifp;
return tud_inited() && tud_ready() && tud_connected();
tud_task();
return s1 ? tud_inited() && tud_ready() && tud_connected() : false;
}

static void fn(struct mg_connection *c, int ev, void *ev_data) {
Expand All @@ -83,7 +84,7 @@ int main(void) {
mg_log_set(MG_LL_DEBUG); // Set log level

MG_INFO(("Init TCP/IP stack ..."));
struct mg_tcpip_driver driver = {.tx = usb_tx, .up = usb_up};
struct mg_tcpip_driver driver = {.tx = usb_tx, .poll = usb_poll};
struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 0x77},
.ip = mg_htonl(MG_U32(192, 168, 3, 1)),
.mask = mg_htonl(MG_U32(255, 255, 255, 0)),
Expand Down Expand Up @@ -121,7 +122,6 @@ int main(void) {
MG_INFO(("Init done, starting main loop ..."));
for (;;) {
mg_mgr_poll(&mgr, 0);
tud_task();
}

return 0;
Expand Down
Loading

0 comments on commit c5508a4

Please sign in to comment.