diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/sbc_harness/hw/w5500.c | 33 | ||||
-rw-r--r-- | cmd/sbc_harness/hw/w5500.h | 5 |
2 files changed, 26 insertions, 12 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) { diff --git a/cmd/sbc_harness/hw/w5500.h b/cmd/sbc_harness/hw/w5500.h index b50ff83..1b485dd 100644 --- a/cmd/sbc_harness/hw/w5500.h +++ b/cmd/sbc_harness/hw/w5500.h @@ -38,6 +38,7 @@ struct w5500 { struct spi *spidev; uint pin_intr; uint pin_reset; + struct net_eth_addr hwaddr; /* mutable */ uint16_t next_local_port; @@ -71,12 +72,12 @@ void _w5500_init(struct w5500 *self, /** * TODO. */ -void w5500_hard_reset(struct w5500 *self, struct net_eth_addr addr); +void w5500_hard_reset(struct w5500 *self); /** * TODO. */ -void w5500_soft_reset(struct w5500 *self, struct net_eth_addr addr); +void w5500_soft_reset(struct w5500 *self); struct w5500_netcfg { struct net_ip4_addr gateway_addr; |