summaryrefslogtreecommitdiff
path: root/cmd/sbc_harness
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/sbc_harness')
-rw-r--r--cmd/sbc_harness/CMakeLists.txt2
-rw-r--r--cmd/sbc_harness/hw/rp2040_hwspi.c8
-rw-r--r--cmd/sbc_harness/hw/rp2040_hwspi.h2
-rw-r--r--cmd/sbc_harness/hw/spi.h7
-rw-r--r--cmd/sbc_harness/hw/w5500.c40
-rw-r--r--cmd/sbc_harness/hw/w5500.h18
-rw-r--r--cmd/sbc_harness/main.c4
7 files changed, 41 insertions, 40 deletions
diff --git a/cmd/sbc_harness/CMakeLists.txt b/cmd/sbc_harness/CMakeLists.txt
index 04f231d..c42fecb 100644
--- a/cmd/sbc_harness/CMakeLists.txt
+++ b/cmd/sbc_harness/CMakeLists.txt
@@ -18,8 +18,8 @@ target_link_libraries(sbc_harness
hardware_spi
hardware_gpio
+ libmisc
libusb
- libnet
)
pico_enable_stdio_usb(sbc_harness 0)
diff --git a/cmd/sbc_harness/hw/rp2040_hwspi.c b/cmd/sbc_harness/hw/rp2040_hwspi.c
index e6e4566..dd9a577 100644
--- a/cmd/sbc_harness/hw/rp2040_hwspi.c
+++ b/cmd/sbc_harness/hw/rp2040_hwspi.c
@@ -10,9 +10,11 @@
#include <hardware/spi.h> /* pico-sdk:hardware_spi */
#include <hardware/gpio.h> /* pico-sdk:hardware_gpio5 */
+#include <libmisc/vcall.h>
+
#include "hw/rp2040_hwspi.h"
-static void rp2040_hwspi_readwritev(struct spi *_self, const struct bidi_iovec *iov, int iovcnt);
+static void rp2040_hwspi_readwritev(implements_spi *, const struct bidi_iovec *iov, int iovcnt);
struct spi_vtable rp2040_hwspi_vtable = {
.readwritev = rp2040_hwspi_readwritev,
@@ -96,8 +98,8 @@ void _rp2040_hwspi_init(struct rp2040_hwspi *self,
self->pin_cs = pin_cs;
}
-static void rp2040_hwspi_readwritev(struct spi *_self, const struct bidi_iovec *iov, int iovcnt) {
- struct rp2040_hwspi *self = (struct rp2040_hwspi *)_self;
+static void rp2040_hwspi_readwritev(implements_spi *_self, const struct bidi_iovec *iov, int iovcnt) {
+ struct rp2040_hwspi *self = VCALL_SELF(struct rp2040_hwspi, implements_spi, _self);
assert(self);
spi_inst_t *inst = self->inst;
diff --git a/cmd/sbc_harness/hw/rp2040_hwspi.h b/cmd/sbc_harness/hw/rp2040_hwspi.h
index 8793fd6..8bf783f 100644
--- a/cmd/sbc_harness/hw/rp2040_hwspi.h
+++ b/cmd/sbc_harness/hw/rp2040_hwspi.h
@@ -18,7 +18,7 @@ enum rp2040_hwspi_instance {
};
struct rp2040_hwspi {
- struct spi_vtable *vtable;
+ implements_spi;
void /*spi_inst_t*/ *inst;
uint pin_cs;
diff --git a/cmd/sbc_harness/hw/spi.h b/cmd/sbc_harness/hw/spi.h
index 86b831e..653e80f 100644
--- a/cmd/sbc_harness/hw/spi.h
+++ b/cmd/sbc_harness/hw/spi.h
@@ -40,11 +40,8 @@ struct spi_vtable {
void (*readwritev)(struct spi *, const struct bidi_iovec *iov, int iovcnt);
};
-struct spi {
+typedef struct spi {
struct spi_vtable *vtable;
-
- /* This is where your implementation data goes. */
- char data[0];
-};
+} implements_spi;
#endif /* _HW_SPI_H_ */
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);
diff --git a/cmd/sbc_harness/hw/w5500.h b/cmd/sbc_harness/hw/w5500.h
index bb629c5..4ec6edd 100644
--- a/cmd/sbc_harness/hw/w5500.h
+++ b/cmd/sbc_harness/hw/w5500.h
@@ -1,4 +1,4 @@
-/* hw/w5500.h - libnet implementation for the WIZnet W5500 chip
+/* hw/w5500.h - 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
@@ -7,20 +7,20 @@
#ifndef _HW_W5500_H_
#define _HW_W5500_H_
-#include <libnet/libnet.h>
+#include <libmisc/net.h>
#include "hw/spi.h"
struct _w5500_listener;
struct _w5500_conn {
- struct libnet_conn_vtable *vtable;
+ implements_net_conn;
struct _w5500_listener *parent_listener;
};
struct _w5500_listener {
- struct libnet_listener_vtable *vtable;
+ implements_net_listener;
struct w5500 *chip;
uint8_t socknum;
@@ -56,7 +56,7 @@ struct w5500 {
} while (0)
void _w5500_init(struct w5500 *self,
struct spi* spi, uint pin_intr, uint pin_reset,
- struct eth_addr addr);
+ struct net_eth_addr addr);
/**
* TODO.
@@ -64,9 +64,9 @@ void _w5500_init(struct w5500 *self,
void w5500_reset(struct w5500 *self);
struct w5500_netcfg {
- struct ip4_addr gateway_addr;
- struct ip4_addr subnet_mask;
- struct ip4_addr addr;
+ struct net_ip4_addr gateway_addr;
+ struct net_ip4_addr subnet_mask;
+ struct net_ip4_addr addr;
};
/**
@@ -74,6 +74,6 @@ struct w5500_netcfg {
*/
void w5500_netcfg(struct w5500 *self, struct w5500_netcfg cfg);
-struct libnet_listener *w5500_listen(struct w5500 *self, uint8_t socknum, uint16_t port);
+implements_net_listener *w5500_listen(struct w5500 *self, uint8_t socknum, uint16_t port);
#endif /* _HW_W5500_H_ */
diff --git a/cmd/sbc_harness/main.c b/cmd/sbc_harness/main.c
index 9564665..c6df8f5 100644
--- a/cmd/sbc_harness/main.c
+++ b/cmd/sbc_harness/main.c
@@ -44,10 +44,10 @@ int main() {
19, /* PIN_MOSI */
18, /* PIN_CLK */
17); /* PIN_CS */
- w5500_init(&dev_w5500, "W5500", (struct spi *)&dev_spi,
+ w5500_init(&dev_w5500, "W5500", &dev_spi,
21, /* PIN_INTR */
20, /* PIN_RESET */
- ((struct eth_addr){{0xDE,0xAD,0xBE,0xEF,0x01,0x02}}));
+ ((struct net_eth_addr){{0xDE,0xAD,0xBE,0xEF,0x01,0x02}}));
usb_common_earlyinit();
usb_keyboard_init();