summaryrefslogtreecommitdiff
path: root/libhw/w5500.c
diff options
context:
space:
mode:
Diffstat (limited to 'libhw/w5500.c')
-rw-r--r--libhw/w5500.c25
1 files changed, 6 insertions, 19 deletions
diff --git a/libhw/w5500.c b/libhw/w5500.c
index 64b373b..b4ad86b 100644
--- a/libhw/w5500.c
+++ b/libhw/w5500.c
@@ -72,6 +72,7 @@
/* TODO: Write a <libhw/generic/gpio.h> to avoid w5500.c being
* pico-sdk-specific. */
#include <hardware/gpio.h> /* pico-sdk:hardware_gpio */
+#include "rp2040_gpioirq.h"
#include <libcr/coroutine.h> /* for cr_yield() */
@@ -95,9 +96,6 @@
#ifndef CONFIG_W5500_LOCAL_PORT_MAX
#error config.h must define CONFIG_W5500_LOCAL_PORT_MAX
#endif
-#ifndef CONFIG_W5500_NUM
- #error config.h must define CONFIG_W5500_NUM
-#endif
#ifndef CONFIG_W5500_DEBUG
#error config.h must define CONFIG_W5500_DEBUG
#endif
@@ -280,13 +278,10 @@ static inline void w5500_socket_close(struct _w5500_socket *socket) {
/* init() *********************************************************************/
-static struct w5500 *w5500_chips[CONFIG_W5500_NUM] = {0};
-
-static void w5500_intrhandler(uint gpio, uint32_t LM_UNUSED(event_mask)) {
- debugf("w5500_intrhandler(): interrupt on pin %u", gpio);
- for (size_t i = 0; i < LM_ARRAY_LEN(w5500_chips); i++)
- if (w5500_chips[i] && w5500_chips[i]->pin_intr == gpio)
- cr_sema_signal_from_intrhandler(&w5500_chips[i]->intr);
+static void w5500_intrhandler(void *_chip, uint LM_UNUSED(gpio), enum gpio_irq_level LM_UNUSED(event)) {
+ struct w5500 *chip = _chip;
+ debugf("w5500_intrhandler()");
+ cr_sema_signal_from_intrhandler(&chip->intr);
}
void _w5500_init(struct w5500 *chip,
@@ -318,19 +313,11 @@ void _w5500_init(struct w5500 *chip,
}
/* Initialize the hardware. */
- gpio_set_irq_enabled_with_callback(pin_intr, GPIO_IRQ_EDGE_FALL, true, w5500_intrhandler);
+ gpioirq_set_and_enable_exclusive_handler(pin_intr, GPIO_IRQ_EDGE_FALL, w5500_intrhandler, chip);
gpio_set_dir(chip->pin_reset, GPIO_OUT);
w5500_hard_reset(chip);
/* Finally, wire in the interrupt handler. */
- bool saved = cr_save_and_disable_interrupts();
- for (size_t i = 0; i < LM_ARRAY_LEN(w5500_chips); i++) {
- if (w5500_chips[i] == NULL) {
- w5500_chips[i] = chip;
- break;
- }
- }
- cr_restore_interrupts(saved);
coroutine_add("w5500_irq", w5500_irq_cr, chip);
}