diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-25 16:28:08 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-25 16:28:08 -0600 |
commit | 9f4494685a29714c57cc11d62dead71f7004e061 (patch) | |
tree | 32976be279a3fd89a26f382cd3a358c66f9cd726 /cmd/sbc_harness/hw/w5500.c | |
parent | 84051eb54834ff805fee1c2e0f573d4433a254c2 (diff) |
ahhh
Diffstat (limited to 'cmd/sbc_harness/hw/w5500.c')
-rw-r--r-- | cmd/sbc_harness/hw/w5500.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/cmd/sbc_harness/hw/w5500.c b/cmd/sbc_harness/hw/w5500.c index 78e4027..3bcc0a4 100644 --- a/cmd/sbc_harness/hw/w5500.c +++ b/cmd/sbc_harness/hw/w5500.c @@ -176,9 +176,10 @@ void _w5500_init(struct w5500 *chip, /* Initialize the data structures. */ *chip = (struct w5500){ /* const-after-init */ - .spidev = spi, - .pin_intr = pin_intr, - .pin_reset = pin_reset, + .spidev = spi, + .pin_intr = pin_intr, + .pin_reset = pin_reset, + .hwaddr = addr, /* mutable */ .next_local_port = CONFIG_W5500_LOCAL_PORT_MIN, }; @@ -202,7 +203,7 @@ void _w5500_init(struct w5500 *chip, /* Initialize the hardware. */ gpio_set_irq_enabled_with_callback(pin_intr, GPIO_IRQ_EDGE_FALL, true, w5500_intrhandler); gpio_set_dir(chip->pin_reset, GPIO_OUT); - w5500_hard_reset(chip, addr); + w5500_hard_reset(chip); /* Finally, wire in the interrupt handler. */ cr_disable_interrupts(); @@ -218,10 +219,10 @@ void _w5500_init(struct w5500 *chip, /* chip methods ***************************************************************/ -static inline void w5500_post_reset(struct w5500 *chip, struct net_eth_addr addr) { +static inline void w5500_post_reset(struct w5500 *chip) { /* The W5500 does not have a built-in MAC address, we must * provide one. */ - w5500ll_write_common_reg(chip->spidev, eth_addr, addr); + w5500ll_write_common_reg(chip->spidev, eth_addr, chip->hwaddr); /* The RP2040 needs a 1/sys_clk hysteresis between interrupts * for us to notice them. At the maximum-rated clock-rate of @@ -259,22 +260,22 @@ static inline void w5500_post_reset(struct w5500 *chip, struct net_eth_addr addr w5500ll_write_common_reg(chip->spidev, retry_count, 3); } -void w5500_hard_reset(struct w5500 *chip, struct net_eth_addr addr) { +void w5500_hard_reset(struct w5500 *chip) { /* TODO: Replace blocking sleep_ms() with something libcr-friendly. */ gpio_put(chip->pin_reset, 0); sleep_ms(1); /* minimum of 500us */ gpio_put(chip->pin_reset, 1); sleep_ms(2); /* minimum of 1ms */ - w5500_post_reset(chip, addr); + w5500_post_reset(chip); } -void w5500_soft_reset(struct w5500 *chip, struct net_eth_addr addr) { +void w5500_soft_reset(struct w5500 *chip) { w5500ll_write_common_reg(chip->spidev, mode, CHIPMODE_RST); while (w5500ll_read_common_reg(chip->spidev, mode) & CHIPMODE_RST) cr_yield(); - w5500_post_reset(chip, addr); + w5500_post_reset(chip); } void w5500_netcfg(struct w5500 *chip, struct w5500_netcfg cfg) { @@ -295,6 +296,18 @@ implements_net_stream_listener *w5500_tcp_listen(struct w5500 *chip, uint8_t soc return &chip->listeners[socknum]; } +implements_net_packet_conn *w5500_udp_conn(struct w5500 *chip, uint8_t socknum, + uint16_t port) { + assert(chip); + assert(socknum < 8); + assert(port); + + assert(chip->listeners[socknum].port == 0); + chip->listeners[socknum].port = port; + + return &chip->listeners[socknum]; +} + /* tcp_listener methods *******************************************************/ static struct w5500 *w5500_tcp_listener_chip(struct _w5500_tcp_listener *listener) { |