stm32/modnetwork: Replace generic netif NIC polling with specific code.
It doesn't work to tie the polling of an underlying NIC driver (eg to check the NIC for pending Ethernet frames) with its associated lwIP netif. This is because most NICs are implemented with IRQs and don't need polling, because there can be multiple lwIP netif's per NIC driver, and because it restricts the use of the netif->state variable. Instead the NIC should have its own specific way of processing incoming Ethernet frame. This patch removes this generic NIC polling feature, and for the only driver that uses it (Wiznet5k) replaces it with an explicit call to the poll function (which could eventually be improved by using a proper external interrupt).
This commit is contained in:
parent
62fe47aa3a
commit
ce8262a164
|
@ -107,7 +107,6 @@ typedef struct _eth_dma_t {
|
||||||
} eth_dma_t;
|
} eth_dma_t;
|
||||||
|
|
||||||
typedef struct _eth_t {
|
typedef struct _eth_t {
|
||||||
mod_network_nic_type_t base;
|
|
||||||
uint32_t trace_flags;
|
uint32_t trace_flags;
|
||||||
struct netif netif;
|
struct netif netif;
|
||||||
struct dhcp dhcp_struct;
|
struct dhcp dhcp_struct;
|
||||||
|
|
|
@ -55,15 +55,11 @@ u32_t sys_now(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void pyb_lwip_poll(void) {
|
STATIC void pyb_lwip_poll(void) {
|
||||||
// Poll all the NICs for incoming data
|
#if MICROPY_PY_WIZNET5K
|
||||||
for (struct netif *netif = netif_list; netif != NULL; netif = netif->next) {
|
// Poll the NIC for incoming data
|
||||||
if (netif->flags & NETIF_FLAG_LINK_UP) {
|
wiznet5k_poll();
|
||||||
mod_network_nic_type_t *nic = netif->state;
|
#endif
|
||||||
if (nic->poll_callback) {
|
|
||||||
nic->poll_callback(nic, netif);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Run the lwIP internal updates
|
// Run the lwIP internal updates
|
||||||
sys_check_timeouts();
|
sys_check_timeouts();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,17 +39,14 @@
|
||||||
|
|
||||||
struct netif;
|
struct netif;
|
||||||
|
|
||||||
typedef struct _mod_network_nic_type_t {
|
|
||||||
mp_obj_base_t base;
|
|
||||||
void (*poll_callback)(void *data, struct netif *netif);
|
|
||||||
} mod_network_nic_type_t;
|
|
||||||
|
|
||||||
extern const mp_obj_type_t network_lan_type;
|
extern const mp_obj_type_t network_lan_type;
|
||||||
extern const mp_obj_type_t mod_network_nic_type_wiznet5k;
|
extern const mp_obj_type_t mod_network_nic_type_wiznet5k;
|
||||||
|
|
||||||
void mod_network_lwip_poll_wrapper(uint32_t ticks_ms);
|
void mod_network_lwip_poll_wrapper(uint32_t ticks_ms);
|
||||||
mp_obj_t mod_network_nic_ifconfig(struct netif *netif, size_t n_args, const mp_obj_t *args);
|
mp_obj_t mod_network_nic_ifconfig(struct netif *netif, size_t n_args, const mp_obj_t *args);
|
||||||
|
|
||||||
|
void wiznet5k_poll(void);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
struct _mod_network_socket_obj_t;
|
struct _mod_network_socket_obj_t;
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
// Wiznet5k Ethernet driver in MACRAW mode
|
// Wiznet5k Ethernet driver in MACRAW mode
|
||||||
|
|
||||||
typedef struct _wiznet5k_obj_t {
|
typedef struct _wiznet5k_obj_t {
|
||||||
mod_network_nic_type_t base;
|
mp_obj_base_t base;
|
||||||
mp_uint_t cris_state;
|
mp_uint_t cris_state;
|
||||||
const spi_t *spi;
|
const spi_t *spi;
|
||||||
mp_hal_pin_obj_t cs;
|
mp_hal_pin_obj_t cs;
|
||||||
|
@ -63,7 +63,6 @@ typedef struct _wiznet5k_obj_t {
|
||||||
STATIC wiznet5k_obj_t wiznet5k_obj;
|
STATIC wiznet5k_obj_t wiznet5k_obj;
|
||||||
|
|
||||||
STATIC void wiznet5k_lwip_init(wiznet5k_obj_t *self);
|
STATIC void wiznet5k_lwip_init(wiznet5k_obj_t *self);
|
||||||
STATIC void wiznet5k_lwip_poll(void *self_in, struct netif *netif);
|
|
||||||
|
|
||||||
STATIC void wiz_cris_enter(void) {
|
STATIC void wiz_cris_enter(void) {
|
||||||
wiznet5k_obj.cris_state = MICROPY_BEGIN_ATOMIC_SECTION();
|
wiznet5k_obj.cris_state = MICROPY_BEGIN_ATOMIC_SECTION();
|
||||||
|
@ -176,7 +175,7 @@ STATIC uint16_t wiznet5k_recv_ethernet(wiznet5k_obj_t *self) {
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
int ret = WIZCHIP_EXPORT(recvfrom)(0, self->eth_frame, 1514, ip, &port);
|
int ret = WIZCHIP_EXPORT(recvfrom)(0, self->eth_frame, 1514, ip, &port);
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
printf("wiznet5k_lwip_poll: fatal error len=%u ret=%d\n", len, ret);
|
printf("wiznet5k_poll: fatal error len=%u ret=%d\n", len, ret);
|
||||||
netif_set_link_down(&self->netif);
|
netif_set_link_down(&self->netif);
|
||||||
netif_set_down(&self->netif);
|
netif_set_down(&self->netif);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -237,8 +236,11 @@ STATIC void wiznet5k_lwip_init(wiznet5k_obj_t *self) {
|
||||||
self->netif.flags &= ~NETIF_FLAG_UP;
|
self->netif.flags &= ~NETIF_FLAG_UP;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void wiznet5k_lwip_poll(void *self_in, struct netif *netif) {
|
void wiznet5k_poll(void) {
|
||||||
wiznet5k_obj_t *self = self_in;
|
wiznet5k_obj_t *self = &wiznet5k_obj;
|
||||||
|
if (!(self->netif.flags & NETIF_FLAG_LINK_UP)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
while ((len = wiznet5k_recv_ethernet(self)) > 0) {
|
while ((len = wiznet5k_recv_ethernet(self)) > 0) {
|
||||||
if (self->trace_flags & TRACE_ETH_RX) {
|
if (self->trace_flags & TRACE_ETH_RX) {
|
||||||
|
@ -267,7 +269,7 @@ STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, size
|
||||||
mp_hal_pin_obj_t rst = pin_find(args[2]);
|
mp_hal_pin_obj_t rst = pin_find(args[2]);
|
||||||
|
|
||||||
// Access the existing object, if it has been constructed with the same hardware interface
|
// Access the existing object, if it has been constructed with the same hardware interface
|
||||||
if (wiznet5k_obj.base.base.type == &mod_network_nic_type_wiznet5k) {
|
if (wiznet5k_obj.base.type == &mod_network_nic_type_wiznet5k) {
|
||||||
if (!(wiznet5k_obj.spi == spi && wiznet5k_obj.cs == cs && wiznet5k_obj.rst == rst
|
if (!(wiznet5k_obj.spi == spi && wiznet5k_obj.cs == cs && wiznet5k_obj.rst == rst
|
||||||
&& wiznet5k_obj.netif.flags != 0)) {
|
&& wiznet5k_obj.netif.flags != 0)) {
|
||||||
wiznet5k_deinit();
|
wiznet5k_deinit();
|
||||||
|
@ -275,8 +277,7 @@ STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, size
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init the wiznet5k object
|
// Init the wiznet5k object
|
||||||
wiznet5k_obj.base.base.type = &mod_network_nic_type_wiznet5k;
|
wiznet5k_obj.base.type = &mod_network_nic_type_wiznet5k;
|
||||||
wiznet5k_obj.base.poll_callback = wiznet5k_lwip_poll;
|
|
||||||
wiznet5k_obj.cris_state = 0;
|
wiznet5k_obj.cris_state = 0;
|
||||||
wiznet5k_obj.spi = spi;
|
wiznet5k_obj.spi = spi;
|
||||||
wiznet5k_obj.cs = cs;
|
wiznet5k_obj.cs = cs;
|
||||||
|
|
Loading…
Reference in New Issue