extmod/network_wiznet5k: Deinit the NIC before (re-)initialisation.

If nic.active(True) is called several times in a row, the device may lock
up.  Even if that is bad coding practice, calling wiznet5k_deinit() in
wiznet5k_init() prevents the lock.
This commit is contained in:
robert-hh 2022-07-27 21:01:29 +02:00 committed by Damien George
parent be2beab71a
commit 73699a846c
1 changed files with 13 additions and 10 deletions

View File

@ -198,6 +198,16 @@ STATIC void wiznet5k_config_interrupt(bool enabled) {
);
}
void wiznet5k_deinit(void) {
for (struct netif *netif = netif_list; netif != NULL; netif = netif->next) {
if (netif == &wiznet5k_obj.netif) {
netif_remove(netif);
netif->flags = 0;
break;
}
}
}
STATIC void wiznet5k_init(void) {
// Configure wiznet for raw ethernet frame usage.
@ -219,6 +229,9 @@ STATIC void wiznet5k_init(void) {
wiznet5k_config_interrupt(true);
}
// Deinit before a new init to clear the state from a previous activation
wiznet5k_deinit();
// Hook the Wiznet into lwIP
wiznet5k_lwip_init(&wiznet5k_obj);
@ -229,16 +242,6 @@ STATIC void wiznet5k_init(void) {
mod_network_register_nic(&wiznet5k_obj);
}
void wiznet5k_deinit(void) {
for (struct netif *netif = netif_list; netif != NULL; netif = netif->next) {
if (netif == &wiznet5k_obj.netif) {
netif_remove(netif);
netif->flags = 0;
break;
}
}
}
STATIC void wiznet5k_send_ethernet(wiznet5k_obj_t *self, size_t len, const uint8_t *buf) {
uint8_t ip[4] = {1, 1, 1, 1}; // dummy
int ret = WIZCHIP_EXPORT(sendto)(0, (byte *)buf, len, ip, 11); // dummy port