summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-27 23:22:01 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-27 23:49:37 -0600
commit88adb90f5e805bea27e619fd5209ef58dbff6fd1 (patch)
treec3e24877b40ce183f1d72f6e064b0478ecf92207
parent89761191a98f7dce4d1049b9a84c3d645378222a (diff)
Factor out a libhw
-rw-r--r--CMakeLists.txt3
-rw-r--r--Makefile13
-rw-r--r--cmd/sbc_harness/CMakeLists.txt5
-rw-r--r--cmd/sbc_harness/main.c15
-rw-r--r--cmd/sbc_harness/usb_keyboard.c2
-rw-r--r--cmd/srv9p/CMakeLists.txt1
-rw-r--r--cmd/srv9p/gnet.h37
-rw-r--r--cmd/srv9p/main.c10
-rw-r--r--lib9p/CMakeLists.txt1
-rw-r--r--lib9p/include/lib9p/srv.h2
-rw-r--r--libdhcp/include/libdhcp/dhcp.h2
-rw-r--r--libhw/CMakeLists.txt30
-rw-r--r--libhw/common_include/libhw/generic/net.h (renamed from libmisc/include/libmisc/net.h)8
-rw-r--r--libhw/common_include/libhw/generic/spi.h (renamed from cmd/sbc_harness/hw/spi.h)8
-rw-r--r--libhw/host_include/libhw/host_net.h37
-rw-r--r--libhw/host_net.c (renamed from cmd/srv9p/gnet.c)196
-rw-r--r--libhw/rp2040_hwspi.c (renamed from cmd/sbc_harness/hw/rp2040_hwspi.c)8
-rw-r--r--libhw/rp2040_include/libhw/rp2040_hwspi.h (renamed from cmd/sbc_harness/hw/rp2040_hwspi.h)12
-rw-r--r--libhw/rp2040_include/libhw/w5500.h (renamed from cmd/sbc_harness/hw/w5500.h)12
-rw-r--r--libhw/w5500.c (renamed from cmd/sbc_harness/hw/w5500.c)7
-rw-r--r--libhw/w5500_ll.h (renamed from cmd/sbc_harness/hw/w5500_ll.h)13
21 files changed, 226 insertions, 196 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9b5c0e0..f0c12e8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,9 +20,10 @@ add_compile_options(-Wall -Wextra -Werror)
add_subdirectory(libcr)
add_subdirectory(libcr_ipc)
+add_subdirectory(libmisc)
+add_subdirectory(libhw)
add_subdirectory(libdhcp)
add_subdirectory(libusb)
-add_subdirectory(libmisc)
add_subdirectory(lib9p)
add_subdirectory(cmd/sbc_harness)
diff --git a/Makefile b/Makefile
index bd4f9cc..0f57255 100644
--- a/Makefile
+++ b/Makefile
@@ -104,17 +104,14 @@ lint/all: lint/%:
if ! grep -q 'Copyright (C) 2024 Luke T. Shumaker' $$filename; then \
echo "$$filename is missing a copyright statement"; r=1; \
fi; \
- dscname=$$($(get_dscname) $$filename); \
- filename_alt1=$$(echo "$$filename" | sed \
- -e 's,^cmd/,,' \
+ dscname_act=$$($(get_dscname) $$filename); \
+ dscname_exp=$$(echo "$$filename" | sed \
-e 's,.*/config/,,' \
- -e 's,.*/include/,,' \
+ -e 's,.*include/,,' \
-e 's,^lib9p/idl/,,' \
-e 's/\.wip$$//'); \
- filename_alt2=$$(echo "$$filename_alt1" | sed \
- -e 's,^sbc_harness/hw/,hw/,'); \
- if ! { [ "$$dscname" == "$$filename" ] || [ "$$dscname" == "$$filename_alt1" ] || [ "$$dscname" == "$$filename_alt2" ]; }; then \
- echo "$$filename self-identifies as $$dscname"; r=1; \
+ if [ "$$dscname_act" != "$$dscname_exp" ] && [ "cmd/$$dscname_act" != "$$dscname_exp" ]; then \
+ echo "$$filename self-identifies as $$dscname_act (expected $$dscname_exp)"; r=1; \
fi; \
if grep -n --color=auto "$$(printf '\\S\t')" $$filename; then \
echo "$$filename uses tabs for alignment"; r=1; \
diff --git a/cmd/sbc_harness/CMakeLists.txt b/cmd/sbc_harness/CMakeLists.txt
index d6261cb..57ebe99 100644
--- a/cmd/sbc_harness/CMakeLists.txt
+++ b/cmd/sbc_harness/CMakeLists.txt
@@ -8,20 +8,17 @@ if (PICO_PLATFORM STREQUAL "rp2040")
add_executable(sbc_harness
main.c
usb_keyboard.c
- hw/rp2040_hwspi.c
- hw/w5500.c
)
target_include_directories(sbc_harness PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/config)
target_include_directories(sbc_harness PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(sbc_harness
pico_stdlib
hardware_flash
- hardware_gpio
- hardware_spi
libmisc
libusb
#libdhcp
+ libhw
)
pico_enable_stdio_usb(sbc_harness 0)
diff --git a/cmd/sbc_harness/main.c b/cmd/sbc_harness/main.c
index 8ecc56c..b0c9659 100644
--- a/cmd/sbc_harness/main.c
+++ b/cmd/sbc_harness/main.c
@@ -4,17 +4,18 @@
* SPDX-Licence-Identifier: AGPL-3.0-or-later
*/
-#include <string.h> /* for strlen() */
-#include <stdio.h> /* for printf() */
-#include "pico/stdlib.h"
-#include "hardware/flash.h"
+#include <string.h> /* libc: for strlen() */
+#include <stdio.h> /* libc: for printf() */
+
+#include <pico/stdlib.h> /* pico-sdk:pico_stdlib: for stdio_uart_init() */
+#include <hardware/flash.h> /* pico-sdk:hardware_flash: for flash_get_unique_id() */
#include <libcr/coroutine.h>
-#include <libusb/usb_common.h>
+#include <libhw/rp2040_hwspi.h>
+#include <libhw/w5500.h>
#include <libmisc/hash.h>
+#include <libusb/usb_common.h>
-#include "hw/rp2040_hwspi.h"
-#include "hw/w5500.h"
#include "usb_keyboard.h"
COROUTINE hello_world_cr(void *_chan) {
diff --git a/cmd/sbc_harness/usb_keyboard.c b/cmd/sbc_harness/usb_keyboard.c
index b98345c..fcd0fe1 100644
--- a/cmd/sbc_harness/usb_keyboard.c
+++ b/cmd/sbc_harness/usb_keyboard.c
@@ -4,7 +4,7 @@
* SPDX-Licence-Identifier: AGPL-3.0-or-later
*/
-#include "tusb.h"
+#include <tusb.h>
#include <libusb/tusb_helpers.h> /* for TUD_ENDPOINT_IN */
#include <libusb/usb_common.h>
diff --git a/cmd/srv9p/CMakeLists.txt b/cmd/srv9p/CMakeLists.txt
index ccad845..d24d3d9 100644
--- a/cmd/srv9p/CMakeLists.txt
+++ b/cmd/srv9p/CMakeLists.txt
@@ -13,7 +13,6 @@ set(static_srcs
add_executable(srv9p
main.c
static9p.c
- gnet.c
)
target_include_directories(srv9p PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(srv9p PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/config)
diff --git a/cmd/srv9p/gnet.h b/cmd/srv9p/gnet.h
deleted file mode 100644
index 3e8a0f4..0000000
--- a/cmd/srv9p/gnet.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* srv9p/gnet.h - libmisc/net.h implementation for libcr + GNU libc
- *
- * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
- * SPDX-Licence-Identifier: AGPL-3.0-or-later
- */
-
-#ifndef _SRV9P_GNET_H_
-#define _SRV9P_GNET_H_
-
-#include <stdint.h> /* for uint16_6 */
-
-#include <libmisc/net.h>
-
-struct _gnet_tcp_conn {
- implements_net_stream_conn;
-
- int fd;
-};
-
-struct gnet_tcp_listener {
- implements_net_stream_listener;
-
- int fd;
- struct _gnet_tcp_conn active_conn;
-};
-
-void gnet_tcp_listener_init(struct gnet_tcp_listener *self, uint16_t port);
-
-struct gnet_udp_conn {
- implements_net_packet_conn;
-
- int fd;
-};
-
-void gnet_udp_conn_init(struct gnet_udp_conn *self, uint16_t port);
-
-#endif /* _SRV9P_GNET_H_ */
diff --git a/cmd/srv9p/main.c b/cmd/srv9p/main.c
index a2b437e..6ef2cd3 100644
--- a/cmd/srv9p/main.c
+++ b/cmd/srv9p/main.c
@@ -7,13 +7,13 @@
#include <error.h>
#include <stdio.h>
-#include <libcr/coroutine.h>
-#include <libmisc/net.h>
#include <lib9p/srv.h>
+#include <libcr/coroutine.h>
+#include <libhw/generic/net.h>
+#include <libhw/host_net.h>
#include "static9p.h"
#include "static.h"
-#include "gnet.h"
/* configuration **************************************************************/
@@ -91,8 +91,8 @@ static COROUTINE read_cr(void *_srv) {
cr_begin();
- struct gnet_tcp_listener listener;
- gnet_tcp_listener_init(&listener, 9000);
+ struct hostnet_tcp_listener listener;
+ hostnet_tcp_listener_init(&listener, 9000);
lib9p_srv_read_cr(srv, &listener);
diff --git a/lib9p/CMakeLists.txt b/lib9p/CMakeLists.txt
index 829ac8e..2448724 100644
--- a/lib9p/CMakeLists.txt
+++ b/lib9p/CMakeLists.txt
@@ -13,4 +13,5 @@ target_sources(lib9p INTERFACE
target_link_libraries(lib9p INTERFACE
libcr_ipc
libmisc
+ libhw
)
diff --git a/lib9p/include/lib9p/srv.h b/lib9p/include/lib9p/srv.h
index 072925f..3d667db 100644
--- a/lib9p/include/lib9p/srv.h
+++ b/lib9p/include/lib9p/srv.h
@@ -10,7 +10,7 @@
#include <libcr/coroutine.h>
#include <libcr_ipc/rpc.h>
#include <libcr_ipc/chan.h>
-#include <libmisc/net.h>
+#include <libhw/generic/net.h>
#include <lib9p/9p.h>
diff --git a/libdhcp/include/libdhcp/dhcp.h b/libdhcp/include/libdhcp/dhcp.h
index 660e154..e259034 100644
--- a/libdhcp/include/libdhcp/dhcp.h
+++ b/libdhcp/include/libdhcp/dhcp.h
@@ -67,7 +67,7 @@
#ifndef _LIBDHCP_DHCP_H_
#define _LIBDHCP_DHCP_H_
-#include <libmisc/net.h>
+#include <libhw/generic/net.h>
#include "hw/w5500.h"
enum dhcp_event {
diff --git a/libhw/CMakeLists.txt b/libhw/CMakeLists.txt
new file mode 100644
index 0000000..ca58a72
--- /dev/null
+++ b/libhw/CMakeLists.txt
@@ -0,0 +1,30 @@
+# libhw/CMakeLists.txt - TODO
+#
+# Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
+# SPDX-Licence-Identifier: AGPL-3.0-or-later
+
+add_library(libhw INTERFACE)
+target_include_directories(libhw SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/common_include)
+target_link_libraries(libhw INTERFACE
+ libmisc
+)
+
+if (PICO_PLATFORM STREQUAL "rp2040")
+ target_include_directories(libhw SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/rp2040_include)
+ target_sources(libhw INTERFACE
+ rp2040_hwspi.c
+ w5500.c
+ )
+ target_link_libraries(libhw INTERFACE
+ pico_time
+ hardware_gpio
+ hardware_spi
+ )
+endif()
+
+if (PICO_PLATFORM STREQUAL "host")
+ target_include_directories(libhw SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/host_include)
+ target_sources(libhw INTERFACE
+ host_net.c
+ )
+endif()
diff --git a/libmisc/include/libmisc/net.h b/libhw/common_include/libhw/generic/net.h
index 057e875..40bcd3b 100644
--- a/libmisc/include/libmisc/net.h
+++ b/libhw/common_include/libhw/generic/net.h
@@ -1,11 +1,11 @@
-/* libmisc/net.h - Base definitions for network interfaces
+/* libhw/generic/net.h - Device-independent network definitions
*
* Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
* SPDX-Licence-Identifier: AGPL-3.0-or-later
*/
-#ifndef _LIBMISC_NET_H_
-#define _LIBMISC_NET_H_
+#ifndef _LIBHW_GENERIC_NET_H_
+#define _LIBHW_GENERIC_NET_H_
#include <stdbool.h> /* for bool */
#include <stddef.h> /* for size_t */
@@ -96,4 +96,4 @@ struct net_packet_conn_vtable {
int (*close )(implements_net_packet_conn *self);
};
-#endif /* _LIBMISC_NET_H_ */
+#endif /* _LIBHW_GENERIC_NET_H_ */
diff --git a/cmd/sbc_harness/hw/spi.h b/libhw/common_include/libhw/generic/spi.h
index da588de..fcba84e 100644
--- a/cmd/sbc_harness/hw/spi.h
+++ b/libhw/common_include/libhw/generic/spi.h
@@ -1,11 +1,11 @@
-/* hw/spi.h - Generic SPI definitions
+/* libhw/generic/spi.h - Device-independent SPI definitions
*
* Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
* SPDX-Licence-Identifier: AGPL-3.0-or-later
*/
-#ifndef _HW_SPI_H_
-#define _HW_SPI_H_
+#ifndef _LIBHW_GENERIC_SPI_H_
+#define _LIBHW_GENERIC_SPI_H_
#include <stddef.h> /* for size_t */
@@ -44,4 +44,4 @@ struct spi_vtable {
void (*readwritev)(implements_spi *, const struct bidi_iovec *iov, int iovcnt);
};
-#endif /* _HW_SPI_H_ */
+#endif /* _LIBHW_GENERIC_SPI_H_ */
diff --git a/libhw/host_include/libhw/host_net.h b/libhw/host_include/libhw/host_net.h
new file mode 100644
index 0000000..c74f0bd
--- /dev/null
+++ b/libhw/host_include/libhw/host_net.h
@@ -0,0 +1,37 @@
+/* libhw/host_net.h - <libhw/generic/net.h> implementation for hosted glibc
+ *
+ * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
+ * SPDX-Licence-Identifier: AGPL-3.0-or-later
+ */
+
+#ifndef _LIBHW_HOST_NET_H_
+#define _LIBHW_HOST_NET_H_
+
+#include <stdint.h> /* for uint16_6 */
+
+#include <libhw/generic/net.h>
+
+struct _hostnet_tcp_conn {
+ implements_net_stream_conn;
+
+ int fd;
+};
+
+struct hostnet_tcp_listener {
+ implements_net_stream_listener;
+
+ int fd;
+ struct _hostnet_tcp_conn active_conn;
+};
+
+void hostnet_tcp_listener_init(struct hostnet_tcp_listener *self, uint16_t port);
+
+struct hostnet_udp_conn {
+ implements_net_packet_conn;
+
+ int fd;
+};
+
+void hostnet_udp_conn_init(struct hostnet_udp_conn *self, uint16_t port);
+
+#endif /* _LIBHW_HOST_NET_H_ */
diff --git a/cmd/srv9p/gnet.c b/libhw/host_net.c
index f1ea709..d71afee 100644
--- a/cmd/srv9p/gnet.c
+++ b/libhw/host_net.c
@@ -1,4 +1,4 @@
-/* srv9p/gnet.c - libmisc/net.h implementation for libcr + GNU libc
+/* libhw/host_net.c - <libhw/generic/net.h> implementation for hosted glibc
*
* Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
* SPDX-Licence-Identifier: AGPL-3.0-or-later
@@ -22,42 +22,44 @@
#include <libcr/coroutine.h>
#include <libmisc/vcall.h>
-#include "gnet.h"
+#include <libhw/host_net.h>
/* common *********************************************************************/
#define UNUSED(name) /* name __attribute__ ((unused)) */
-static int gnet_sig_io = 0;
+static int hostnet_sig_io = 0;
-static void gnet_handle_sig_io(int UNUSED(sig), siginfo_t *info, void *UNUSED(ucontext)) {
+static void hostnet_handle_sig_io(int UNUSED(sig), siginfo_t *info, void *UNUSED(ucontext)) {
cr_unpause_from_intrhandler((cid_t)info->si_value.sival_int);
}
-static void gnet_init(void) {
+static void hostnet_init(void) {
struct sigaction action = {0};
- if (gnet_sig_io)
+ if (hostnet_sig_io)
return;
- gnet_sig_io = SIGRTMIN;
- if (gnet_sig_io > SIGRTMAX)
+ hostnet_sig_io = SIGRTMIN;
+ if (hostnet_sig_io > SIGRTMAX)
error(1, 0, "SIGRTMAX exceeded");
action.sa_flags = SA_SIGINFO;
- action.sa_sigaction = gnet_handle_sig_io;
- if (sigaction(gnet_sig_io, &action, NULL) < 0)
+ action.sa_sigaction = hostnet_handle_sig_io;
+ if (sigaction(hostnet_sig_io, &action, NULL) < 0)
error(1, errno, "sigaction");
}
-#define WAKE_COROUTINE(args) do { \
- int r; \
- union sigval val = {0}; \
- val.sival_int = (int)((args)->cr_coroutine); \
- do { \
- r = pthread_sigqueue((args)->cr_thread, gnet_sig_io, val); \
- assert(r == 0 || r == EAGAIN); \
- } while (r == EAGAIN); \
+#define WAKE_COROUTINE(args) do { \
+ int r; \
+ union sigval val = {0}; \
+ val.sival_int = (int)((args)->cr_coroutine); \
+ do { \
+ r = pthread_sigqueue((args)->cr_thread, \
+ hostnet_sig_io, \
+ val); \
+ assert(r == 0 || r == EAGAIN); \
+ } while (r == EAGAIN); \
} while (0)
static inline bool RUN_PTHREAD(void *(*fn)(void *), void *args) {
@@ -70,7 +72,7 @@ static inline bool RUN_PTHREAD(void *(*fn)(void *), void *args) {
return false;
}
-static inline ssize_t gnet_map_errno(ssize_t v) {
+static inline ssize_t hostnet_map_errno(ssize_t v) {
if (v >= 0)
return v;
switch (v) {
@@ -83,29 +85,29 @@ static inline ssize_t gnet_map_errno(ssize_t v) {
/* TCP init() ( AKA socket(3) + listen(3) )************************************/
-static implements_net_stream_conn *gnet_tcp_accept(implements_net_stream_listener *_listener);
-static ssize_t gnet_tcp_read(implements_net_stream_conn *conn, void *buf, size_t count);
-static ssize_t gnet_tcp_write(implements_net_stream_conn *conn, void *buf, size_t count);
-static int gnet_tcp_close(implements_net_stream_conn *conn, bool rd, bool wr);
+static implements_net_stream_conn *hostnet_tcp_accept(implements_net_stream_listener *_listener);
+static ssize_t hostnet_tcp_read(implements_net_stream_conn *conn, void *buf, size_t count);
+static ssize_t hostnet_tcp_write(implements_net_stream_conn *conn, void *buf, size_t count);
+static int hostnet_tcp_close(implements_net_stream_conn *conn, bool rd, bool wr);
-static struct net_stream_listener_vtable gnet_tcp_listener_vtable = {
- .accept = gnet_tcp_accept,
+static struct net_stream_listener_vtable hostnet_tcp_listener_vtable = {
+ .accept = hostnet_tcp_accept,
};
-static struct net_stream_conn_vtable gnet_tcp_conn_vtable = {
- .read = gnet_tcp_read,
- .write = gnet_tcp_write,
- .close = gnet_tcp_close,
+static struct net_stream_conn_vtable hostnet_tcp_conn_vtable = {
+ .read = hostnet_tcp_read,
+ .write = hostnet_tcp_write,
+ .close = hostnet_tcp_close,
};
-void gnet_tcp_listener_init(struct gnet_tcp_listener *self, uint16_t port) {
+void hostnet_tcp_listener_init(struct hostnet_tcp_listener *self, uint16_t port) {
int listenerfd;
union {
struct sockaddr_in in;
struct sockaddr gen;
} addr = { 0 };
- gnet_init();
+ hostnet_init();
addr.in.sin_family = AF_INET;
addr.in.sin_port = htons(port);
@@ -121,13 +123,13 @@ void gnet_tcp_listener_init(struct gnet_tcp_listener *self, uint16_t port) {
if (listen(listenerfd, 0) < 0)
error(1, errno, "listen(fd=%d)", listenerfd);
- self->vtable = &gnet_tcp_listener_vtable;
+ self->vtable = &hostnet_tcp_listener_vtable;
self->fd = listenerfd;
}
/* TCP accept() ***************************************************************/
-struct gnet_pthread_accept_args {
+struct hostnet_pthread_accept_args {
pthread_t cr_thread;
cid_t cr_coroutine;
@@ -136,8 +138,8 @@ struct gnet_pthread_accept_args {
int *ret_connfd;
};
-static void *gnet_pthread_accept(void *_args) {
- struct gnet_pthread_accept_args *args = _args;
+static void *hostnet_pthread_accept(void *_args) {
+ struct hostnet_pthread_accept_args *args = _args;
*(args->ret_connfd) = accept(args->listenerfd, NULL, NULL);
if (*(args->ret_connfd) < 0)
*(args->ret_connfd) = -errno;
@@ -145,29 +147,29 @@ static void *gnet_pthread_accept(void *_args) {
return NULL;
};
-static implements_net_stream_conn *gnet_tcp_accept(implements_net_stream_listener *_listener) {
- struct gnet_tcp_listener *listener =
- VCALL_SELF(struct gnet_tcp_listener, implements_net_stream_listener, _listener);
+static implements_net_stream_conn *hostnet_tcp_accept(implements_net_stream_listener *_listener) {
+ struct hostnet_tcp_listener *listener =
+ VCALL_SELF(struct hostnet_tcp_listener, implements_net_stream_listener, _listener);
assert(listener);
int ret_connfd;
- struct gnet_pthread_accept_args args = {
+ struct hostnet_pthread_accept_args args = {
.cr_thread = pthread_self(),
.cr_coroutine = cr_getcid(),
.listenerfd = listener->fd,
.ret_connfd = &ret_connfd,
};
- if (RUN_PTHREAD(gnet_pthread_accept, &args))
+ if (RUN_PTHREAD(hostnet_pthread_accept, &args))
return NULL;
- listener->active_conn.vtable = &gnet_tcp_conn_vtable;
+ listener->active_conn.vtable = &hostnet_tcp_conn_vtable;
listener->active_conn.fd = ret_connfd;
return &listener->active_conn;
}
/* TCP read() *****************************************************************/
-struct gnet_pthread_read_args {
+struct hostnet_pthread_read_args {
pthread_t cr_thread;
cid_t cr_coroutine;
@@ -178,22 +180,22 @@ struct gnet_pthread_read_args {
ssize_t *ret;
};
-static void *gnet_pthread_read(void *_args) {
- struct gnet_pthread_read_args *args = _args;
+static void *hostnet_pthread_read(void *_args) {
+ struct hostnet_pthread_read_args *args = _args;
*(args->ret) = read(args->connfd, args->buf, args->count);
if (*(args->ret) < 0)
- *(args->ret) = gnet_map_errno(-errno);
+ *(args->ret) = hostnet_map_errno(-errno);
WAKE_COROUTINE(args);
return NULL;
};
-static ssize_t gnet_tcp_read(implements_net_stream_conn *_conn, void *buf, size_t count) {
- struct _gnet_tcp_conn *conn =
- VCALL_SELF(struct _gnet_tcp_conn, implements_net_stream_conn, _conn);
+static ssize_t hostnet_tcp_read(implements_net_stream_conn *_conn, void *buf, size_t count) {
+ struct _hostnet_tcp_conn *conn =
+ VCALL_SELF(struct _hostnet_tcp_conn, implements_net_stream_conn, _conn);
assert(conn);
ssize_t ret;
- struct gnet_pthread_read_args args = {
+ struct hostnet_pthread_read_args args = {
.cr_thread = pthread_self(),
.cr_coroutine = cr_getcid(),
@@ -203,14 +205,14 @@ static ssize_t gnet_tcp_read(implements_net_stream_conn *_conn, void *buf, size_
.ret = &ret,
};
- if (RUN_PTHREAD(gnet_pthread_read, &args))
+ if (RUN_PTHREAD(hostnet_pthread_read, &args))
return -NET_ETHREAD;
return ret;
}
/* TCP write() ****************************************************************/
-struct gnet_pthread_write_args {
+struct hostnet_pthread_write_args {
pthread_t cr_thread;
cid_t cr_coroutine;
@@ -221,13 +223,13 @@ struct gnet_pthread_write_args {
ssize_t *ret;
};
-static void *gnet_pthread_write(void *_args) {
- struct gnet_pthread_read_args *args = _args;
+static void *hostnet_pthread_write(void *_args) {
+ struct hostnet_pthread_read_args *args = _args;
size_t done = 0;
while (done < args->count) {
ssize_t r = write(args->connfd, args->buf, args->count);
if (r < 0) {
- gnet_map_errno(-errno);
+ hostnet_map_errno(-errno);
break;
}
done += r;
@@ -238,13 +240,13 @@ static void *gnet_pthread_write(void *_args) {
return NULL;
};
-static ssize_t gnet_tcp_write(implements_net_stream_conn *_conn, void *buf, size_t count) {
- struct _gnet_tcp_conn *conn =
- VCALL_SELF(struct _gnet_tcp_conn, implements_net_stream_conn, _conn);
+static ssize_t hostnet_tcp_write(implements_net_stream_conn *_conn, void *buf, size_t count) {
+ struct _hostnet_tcp_conn *conn =
+ VCALL_SELF(struct _hostnet_tcp_conn, implements_net_stream_conn, _conn);
assert(conn);
ssize_t ret;
- struct gnet_pthread_write_args args = {
+ struct hostnet_pthread_write_args args = {
.cr_thread = pthread_self(),
.cr_coroutine = cr_getcid(),
@@ -254,16 +256,16 @@ static ssize_t gnet_tcp_write(implements_net_stream_conn *_conn, void *buf, size
.ret = &ret,
};
- if (RUN_PTHREAD(gnet_pthread_write, &args))
+ if (RUN_PTHREAD(hostnet_pthread_write, &args))
return -NET_ETHREAD;
return ret;
}
/* TCP close() ****************************************************************/
-static int gnet_tcp_close(implements_net_stream_conn *_conn, bool rd, bool wr) {
- struct _gnet_tcp_conn *conn =
- VCALL_SELF(struct _gnet_tcp_conn, implements_net_stream_conn, _conn);
+static int hostnet_tcp_close(implements_net_stream_conn *_conn, bool rd, bool wr) {
+ struct _hostnet_tcp_conn *conn =
+ VCALL_SELF(struct _hostnet_tcp_conn, implements_net_stream_conn, _conn);
assert(conn);
int how;
@@ -275,24 +277,24 @@ static int gnet_tcp_close(implements_net_stream_conn *_conn, bool rd, bool wr) {
how = SHUT_WR;
else
assert(false);
- return gnet_map_errno(shutdown(conn->fd, how) ? -errno : 0);
+ return hostnet_map_errno(shutdown(conn->fd, how) ? -errno : 0);
}
/* UDP init() *****************************************************************/
-static ssize_t gnet_udp_sendto(implements_net_packet_conn *self, void *buf, size_t len,
- struct net_ip4_addr addr, uint16_t port);
-static ssize_t gnet_udp_recvfrom(implements_net_packet_conn *self, void *buf, size_t len,
- struct net_ip4_addr *ret_addr, uint16_t *ret_port);
-static int gnet_udp_close(implements_net_packet_conn *self);
+static ssize_t hostnet_udp_sendto(implements_net_packet_conn *self, void *buf, size_t len,
+ struct net_ip4_addr addr, uint16_t port);
+static ssize_t hostnet_udp_recvfrom(implements_net_packet_conn *self, void *buf, size_t len,
+ struct net_ip4_addr *ret_addr, uint16_t *ret_port);
+static int hostnet_udp_close(implements_net_packet_conn *self);
-static struct net_packet_conn_vtable gnet_udp_conn_vtable = {
- .sendto = gnet_udp_sendto,
- .recvfrom = gnet_udp_recvfrom,
- .close = gnet_udp_close,
+static struct net_packet_conn_vtable hostnet_udp_conn_vtable = {
+ .sendto = hostnet_udp_sendto,
+ .recvfrom = hostnet_udp_recvfrom,
+ .close = hostnet_udp_close,
};
-void gnet_udp_conn_init(struct gnet_udp_conn *self, uint16_t port) {
+void hostnet_udp_conn_init(struct hostnet_udp_conn *self, uint16_t port) {
int fd;
union {
struct sockaddr_in in;
@@ -300,7 +302,7 @@ void gnet_udp_conn_init(struct gnet_udp_conn *self, uint16_t port) {
struct sockaddr_storage stor;
} addr = { 0 };
- gnet_init();
+ hostnet_init();
addr.in.sin_family = AF_INET;
addr.in.sin_port = htons(port);
@@ -310,13 +312,13 @@ void gnet_udp_conn_init(struct gnet_udp_conn *self, uint16_t port) {
if (bind(fd, &addr.gen, sizeof addr) < 0)
error(1, errno, "bind");
- self->vtable = &gnet_udp_conn_vtable;
+ self->vtable = &hostnet_udp_conn_vtable;
self->fd = fd;
}
/* UDP sendto() ***************************************************************/
-struct gnet_pthread_sendto_args {
+struct hostnet_pthread_sendto_args {
pthread_t cr_thread;
cid_t cr_coroutine;
@@ -329,8 +331,8 @@ struct gnet_pthread_sendto_args {
ssize_t *ret;
};
-static void *gnet_pthread_sendto(void *_args) {
- struct gnet_pthread_sendto_args *args = _args;
+static void *hostnet_pthread_sendto(void *_args) {
+ struct hostnet_pthread_sendto_args *args = _args;
union {
struct sockaddr_in in;
struct sockaddr gen;
@@ -346,19 +348,19 @@ static void *gnet_pthread_sendto(void *_args) {
addr.in.sin_port = htons(args->port);
*(args->ret) = sendto(args->connfd, args->buf, args->count, 0, &addr.gen, sizeof(addr));
if (*(args->ret) < 0)
- *(args->ret) = gnet_map_errno(-errno);
+ *(args->ret) = hostnet_map_errno(-errno);
WAKE_COROUTINE(args);
return NULL;
}
-static ssize_t gnet_udp_sendto(implements_net_packet_conn *_conn, void *buf, size_t count,
+static ssize_t hostnet_udp_sendto(implements_net_packet_conn *_conn, void *buf, size_t count,
struct net_ip4_addr node, uint16_t port) {
- struct gnet_udp_conn *conn =
- VCALL_SELF(struct gnet_udp_conn, implements_net_packet_conn, _conn);
+ struct hostnet_udp_conn *conn =
+ VCALL_SELF(struct hostnet_udp_conn, implements_net_packet_conn, _conn);
assert(conn);
ssize_t ret;
- struct gnet_pthread_sendto_args args = {
+ struct hostnet_pthread_sendto_args args = {
.cr_thread = pthread_self(),
.cr_coroutine = cr_getcid(),
@@ -370,14 +372,14 @@ static ssize_t gnet_udp_sendto(implements_net_packet_conn *_conn, void *buf, siz
.ret = &ret,
};
- if (RUN_PTHREAD(gnet_pthread_sendto, &args))
+ if (RUN_PTHREAD(hostnet_pthread_sendto, &args))
return -NET_ETHREAD;
return ret;
}
/* UDP recvfrom() *************************************************************/
-struct gnet_pthread_recvfrom_args {
+struct hostnet_pthread_recvfrom_args {
pthread_t cr_thread;
cid_t cr_coroutine;
@@ -390,8 +392,8 @@ struct gnet_pthread_recvfrom_args {
uint16_t *ret_port;
};
-static void *gnet_pthread_recvfrom(void *_args) {
- struct gnet_pthread_recvfrom_args *args = _args;
+static void *hostnet_pthread_recvfrom(void *_args) {
+ struct hostnet_pthread_recvfrom_args *args = _args;
union {
struct sockaddr_in in;
@@ -402,7 +404,7 @@ static void *gnet_pthread_recvfrom(void *_args) {
*(args->ret_size) = recvfrom(args->connfd, args->buf, args->count, 0, &addr.gen, &addr_size);
if (*(args->ret_size) < 0)
- *(args->ret_size) = gnet_map_errno(-errno);
+ *(args->ret_size) = hostnet_map_errno(-errno);
else {
assert(addr.in.sin_family == AF_INET);
if (args->ret_node) {
@@ -418,14 +420,14 @@ static void *gnet_pthread_recvfrom(void *_args) {
return NULL;
}
-static ssize_t gnet_udp_recvfrom(implements_net_packet_conn *_conn, void *buf, size_t count,
+static ssize_t hostnet_udp_recvfrom(implements_net_packet_conn *_conn, void *buf, size_t count,
struct net_ip4_addr *ret_node, uint16_t *ret_port) {
- struct gnet_udp_conn *conn =
- VCALL_SELF(struct gnet_udp_conn, implements_net_packet_conn, _conn);
+ struct hostnet_udp_conn *conn =
+ VCALL_SELF(struct hostnet_udp_conn, implements_net_packet_conn, _conn);
assert(conn);
ssize_t ret;
- struct gnet_pthread_recvfrom_args args = {
+ struct hostnet_pthread_recvfrom_args args = {
.cr_thread = pthread_self(),
.cr_coroutine = cr_getcid(),
@@ -437,17 +439,17 @@ static ssize_t gnet_udp_recvfrom(implements_net_packet_conn *_conn, void *buf, s
.ret_node = ret_node,
.ret_port = ret_port,
};
- if (RUN_PTHREAD(gnet_pthread_recvfrom, &args))
+ if (RUN_PTHREAD(hostnet_pthread_recvfrom, &args))
return -NET_ETHREAD;
return ret;
}
/* UDP close() ****************************************************************/
-static int gnet_udp_close(implements_net_packet_conn *_conn) {
- struct gnet_udp_conn *conn =
- VCALL_SELF(struct gnet_udp_conn, implements_net_packet_conn, _conn);
+static int hostnet_udp_close(implements_net_packet_conn *_conn) {
+ struct hostnet_udp_conn *conn =
+ VCALL_SELF(struct hostnet_udp_conn, implements_net_packet_conn, _conn);
assert(conn);
- return gnet_map_errno(close(conn->fd) ? -errno : 0);
+ return hostnet_map_errno(close(conn->fd) ? -errno : 0);
}
diff --git a/cmd/sbc_harness/hw/rp2040_hwspi.c b/libhw/rp2040_hwspi.c
index 6742c60..b041bc9 100644
--- a/cmd/sbc_harness/hw/rp2040_hwspi.c
+++ b/libhw/rp2040_hwspi.c
@@ -1,5 +1,5 @@
-/* hw/rp2040_hwspi.c - `implements_spi` implementation for the RP2040's
- * ARM Primecell SSP (PL022) (implementation file)
+/* libhw/rp2040_hwspi.c - `implements_spi` implementation for the RP2040's
+ * ARM Primecell SSP (PL022) (implementation file)
*
* Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
* SPDX-Licence-Identifier: AGPL-3.0-or-later
@@ -8,11 +8,11 @@
#include <assert.h>
#include <hardware/spi.h> /* pico-sdk:hardware_spi */
-#include <hardware/gpio.h> /* pico-sdk:hardware_gpio5 */
+#include <hardware/gpio.h> /* pico-sdk:hardware_gpio */
#include <libmisc/vcall.h>
-#include "hw/rp2040_hwspi.h"
+#include <libhw/rp2040_hwspi.h>
static void rp2040_hwspi_readwritev(implements_spi *, const struct bidi_iovec *iov, int iovcnt);
diff --git a/cmd/sbc_harness/hw/rp2040_hwspi.h b/libhw/rp2040_include/libhw/rp2040_hwspi.h
index 393eae6..8e44e50 100644
--- a/cmd/sbc_harness/hw/rp2040_hwspi.h
+++ b/libhw/rp2040_include/libhw/rp2040_hwspi.h
@@ -1,16 +1,16 @@
-/* hw/rp2040_hwspi.h - `implements_spi` implementation for the RP2040's
- * ARM Primecell SSP (PL022) (header file)
+/* libhw/rp2040_hwspi.h - `implements_spi` implementation for the RP2040's
+ * ARM Primecell SSP (PL022) (header file)
*
* Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
* SPDX-Licence-Identifier: AGPL-3.0-or-later
*/
-#ifndef _HW_RP2040_HWSPI_H_
-#define _HW_RP2040_HWSPI_H_
+#ifndef _LIBHW_RP2040_HWSPI_H_
+#define _LIBHW_RP2040_HWSPI_H_
#include <pico/binary_info.h> /* for bi_* */
-#include "hw/spi.h"
+#include <libhw/generic/spi.h>
enum rp2040_hwspi_instance {
RP2040_HWSPI_0 = 0,
@@ -60,4 +60,4 @@ void _rp2040_hwspi_init(struct rp2040_hwspi *self,
uint pin_clk,
uint pin_cs);
-#endif /* _HW_RP2040_HWSPI_H_ */
+#endif /* _LIBHW_RP2040_HWSPI_H_ */
diff --git a/cmd/sbc_harness/hw/w5500.h b/libhw/rp2040_include/libhw/w5500.h
index 2ff04df..6b5a690 100644
--- a/cmd/sbc_harness/hw/w5500.h
+++ b/libhw/rp2040_include/libhw/w5500.h
@@ -1,17 +1,17 @@
-/* hw/w5500.h - libmisc/net.h implementation for the WIZnet W5500 chip
+/* libhw/w5500.h - <libhw/generic/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
*/
-#ifndef _HW_W5500_H_
-#define _HW_W5500_H_
+#ifndef _LIBHW_W5500_H_
+#define _LIBHW_W5500_H_
#include <libcr_ipc/sema.h>
#include <libcr_ipc/mutex.h>
-#include <libmisc/net.h>
-#include "hw/spi.h"
+#include <libhw/generic/net.h>
+#include <libhw/generic/spi.h>
struct _w5500_tcp_conn {
/* const-after-init */
@@ -99,4 +99,4 @@ implements_net_stream_listener *w5500_tcp_listen(struct w5500 *self, uint8_t soc
implements_net_packet_conn *w5500_udp_conn(struct w5500 *self, uint8_t socknum,
uint16_t port);
-#endif /* _HW_W5500_H_ */
+#endif /* _LIBHW_W5500_H_ */
diff --git a/cmd/sbc_harness/hw/w5500.c b/libhw/w5500.c
index 5e36bcf..70881ee 100644
--- a/cmd/sbc_harness/hw/w5500.c
+++ b/libhw/w5500.c
@@ -1,4 +1,4 @@
-/* hw/w5500.c - libmisc/net.h implementation for the WIZnet W5500 chip
+/* libhw/w5500.c - <libhw/generic/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
@@ -73,8 +73,9 @@
#include <libcr/coroutine.h> /* for cr_yield() */
#include <libmisc/vcall.h> /* for VCALL_SELF() */
-#include "hw/w5500_ll.h"
-#include "hw/w5500.h"
+#include <libhw/w5500.h>
+
+#include "w5500_ll.h"
/* Config *********************************************************************/
diff --git a/cmd/sbc_harness/hw/w5500_ll.h b/libhw/w5500_ll.h
index 4cc3b11..57bfccd 100644
--- a/cmd/sbc_harness/hw/w5500_ll.h
+++ b/libhw/w5500_ll.h
@@ -1,4 +1,4 @@
-/* hw/w5500_ll.h - Low-level header library for the WIZnet W5500 chip
+/* libhw/w5500_ll.h - Low-level header library for the WIZnet W5500 chip
*
* Based entirely on the W5500 datasheet, v1.1.0.
* https://docs.wiznet.io/img/products/w5500/W5500_ds_v110e.pdf
@@ -7,17 +7,18 @@
* SPDX-Licence-Identifier: AGPL-3.0-or-later
*/
-#ifndef _HW_W5500_LL_H_
-#define _HW_W5500_LL_H_
+#ifndef _LIBHW_W5500_LL_H_
+#define _LIBHW_W5500_LL_H_
#include <assert.h> /* for assert(), static_assert() */
#include <stdint.h> /* for uint{n}_t */
#include <string.h> /* for memcmp() */
-#include <libmisc/net.h> /* for struct net_eth_addr, struct net_ip4_addr */
#include <libmisc/vcall.h> /* for VCALL() */
#include <libmisc/endian.h> /* for uint16be_t */
-#include "hw/spi.h" /* for implements_spi */
+
+#include <libhw/generic/net.h> /* for struct net_eth_addr, struct net_ip4_addr */
+#include <libhw/generic/spi.h> /* for implements_spi */
/* Low-level protocol built on SPI frames. ***********************************/
@@ -359,4 +360,4 @@ static_assert(sizeof(struct w5500ll_block_sock_reg) == 0x30);
val; \
})
-#endif /* _HW_W5500_LL_H_ */
+#endif /* _LIBHW_W5500_LL_H_ */