diff options
Diffstat (limited to 'cmd/sbc_harness/hw/w5500.c')
-rw-r--r-- | cmd/sbc_harness/hw/w5500.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/cmd/sbc_harness/hw/w5500.c b/cmd/sbc_harness/hw/w5500.c index e32c589..8e3dab0 100644 --- a/cmd/sbc_harness/hw/w5500.c +++ b/cmd/sbc_harness/hw/w5500.c @@ -1,4 +1,4 @@ -/* hw/w5500.c - libnet implementation for the WIZnet W5500 chip +/* hw/w5500.c - libmisc/net.h implementation for the WIZnet W5500 chip * * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-Licence-Identifier: AGPL-3.0-or-later @@ -42,6 +42,8 @@ #include <hardware/gpio.h> /* pico-sdk:hardware_gpio5 */ #include <libcr/coroutine.h> +#include <libmisc/vcall.h> + #include "hw/w5500.h" #include "config.h" @@ -110,7 +112,7 @@ void w5500_spiframe_write(struct spi *spidev, uint16_t addr, uint8_t block, void {.iov_read_dst = NULL, .iov_write_src = header, .iov_len = sizeof(header)}, {.iov_read_dst = NULL, .iov_write_src = data, .iov_len = data_len}, }; - spidev->vtable->readwritev(spidev, iov, 2); + VCALL(spidev, readwritev, iov, 2); } void w5500_spiframe_read(struct spi *spidev, uint16_t addr, uint8_t block, void *data, size_t data_len) { @@ -128,7 +130,7 @@ void w5500_spiframe_read(struct spi *spidev, uint16_t addr, uint8_t block, void {.iov_read_dst = NULL, .iov_write_src = header, .iov_len = sizeof(header)}, {.iov_read_dst = data, .iov_write_src = NULL, .iov_len = data_len}, }; - spidev->vtable->readwritev(spidev, iov, 2); + VCALL(spidev, readwritev, iov, 2); } /* Offsets and sizes for use with that protocol. *****************************/ @@ -357,16 +359,16 @@ static_assert(sizeof(struct w5500_block_sock_reg) == 0x30); /* init() *********************************************************************/ -static struct libnet_conn *w5500_accept(struct libnet_listener *_listener); -static ssize_t w5500_read(struct libnet_conn *conn, void *buf, size_t count); -static ssize_t w5500_write(struct libnet_conn *conn, void *buf, size_t count); -static int w5500_close(struct libnet_conn *conn, bool rd, bool wr); +static implements_net_conn *w5500_accept(implements_net_listener *_listener); +static ssize_t w5500_read(implements_net_conn *conn, void *buf, size_t count); +static ssize_t w5500_write(implements_net_conn *conn, void *buf, size_t count); +static int w5500_close(implements_net_conn *conn, bool rd, bool wr); -static struct libnet_listener_vtable w5500_listener_vtable = { +static struct net_listener_vtable w5500_listener_vtable = { .accept = w5500_accept, }; -static struct libnet_conn_vtable w5500_conn_vtable = { +static struct net_conn_vtable w5500_conn_vtable = { .read = w5500_read, .write = w5500_write, .close = w5500_close, @@ -381,7 +383,7 @@ uint16_t w5500_get_local_port(struct w5500 *self) { void _w5500_init(struct w5500 *chip, struct spi* spi, uint pin_intr, uint pin_reset, - struct eth_addr addr) { + struct net_eth_addr addr) { chip->spidev = spi; chip->pin_reset = pin_reset; for (uint8_t i = 0; i < 8; i++) { @@ -418,12 +420,12 @@ void w5500_netcfg(struct w5500 *chip, struct w5500_netcfg cfg) { /* listen() *******************************************************************/ -struct libnet_listener *w5500_listen(struct w5500 *chip, uint8_t socknum, uint16_t port) { +implements_net_listener *w5500_listen(struct w5500 *chip, uint8_t socknum, uint16_t port) { assert(chip); assert(socknum < 8); assert(port); - w5500_close((struct libnet_conn *)&chip->_listeners[socknum].active_conn, true, true); + w5500_close(&chip->_listeners[socknum].active_conn, true, true); REGWRITE_SOCK(chip->spidev, socknum, mode, MODE_TCP); REGWRITE_SOCK(chip->spidev, socknum, local_port, ((uint8_t[2]){port>>8, port})); REGWRITE_SOCK(chip->spidev, socknum, command, CMD_OPEN); @@ -432,13 +434,13 @@ struct libnet_listener *w5500_listen(struct w5500 *chip, uint8_t socknum, uint16 while (REGREAD_SOCK(chip->spidev, socknum, state, uint8_t) != STATE_TCP_INIT) cr_yield(); - return (struct libnet_listener *)&chip->_listeners[socknum]; + return &chip->_listeners[socknum]; } /* accept() *******************************************************************/ #define ASSERT_LISTENER() \ - struct _w5500_listener *self = (struct _w5500_listener *)_self; \ + struct _w5500_listener *self = VCALL_SELF(struct _w5500_listener, implements_net_listener, _self); \ assert(self); \ \ struct w5500 *chip = self->chip; \ @@ -446,7 +448,7 @@ struct libnet_listener *w5500_listen(struct w5500 *chip, uint8_t socknum, uint16 assert(chip); \ assert(socknum < 8) -static struct libnet_conn *w5500_accept(struct libnet_listener *_self) { +static implements_net_conn *w5500_accept(implements_net_listener *_self) { ASSERT_LISTENER(); REGWRITE_SOCK(chip->spidev, socknum, command, CMD_LISTEN); @@ -460,7 +462,7 @@ static struct libnet_conn *w5500_accept(struct libnet_listener *_self) { cr_yield(); break; default: - return (struct libnet_conn *)&self->active_conn; + return &self->active_conn; } } } @@ -468,7 +470,7 @@ static struct libnet_conn *w5500_accept(struct libnet_listener *_self) { /* write() ********************************************************************/ #define ASSERT_CONN() \ - struct _w5500_conn *self = (struct _w5500_conn *)_self; \ + struct _w5500_conn *self = VCALL_SELF(struct _w5500_conn, implements_net_conn, _self); \ assert(self); \ \ struct w5500 *chip = self->parent_listener->chip; \ @@ -476,7 +478,7 @@ static struct libnet_conn *w5500_accept(struct libnet_listener *_self) { assert(chip); \ assert(socknum < 8) -static ssize_t w5500_write(struct libnet_conn *_self, void *buf, size_t count) { +static ssize_t w5500_write(implements_net_conn *_self, void *buf, size_t count) { ASSERT_CONN(); assert(buf); assert(count); @@ -484,7 +486,7 @@ static ssize_t w5500_write(struct libnet_conn *_self, void *buf, size_t count) { // TODO } -static int w5500_close(struct libnet_conn *_self, bool rd, bool wr) { +static int w5500_close(implements_net_conn *_self, bool rd, bool wr) { ASSERT_CONN(); REGWRITE_SOCK(chip->spidev, socknum, command, CMD_CLOSE); |