diff options
Diffstat (limited to 'cmd/sbc_harness')
-rw-r--r-- | cmd/sbc_harness/CMakeLists.txt | 2 | ||||
-rw-r--r-- | cmd/sbc_harness/config/config.h | 39 | ||||
-rw-r--r-- | cmd/sbc_harness/fs_harness_flash_bin.c | 10 | ||||
-rw-r--r-- | cmd/sbc_harness/fs_harness_uptime_txt.c | 12 | ||||
-rw-r--r-- | cmd/sbc_harness/main.c | 26 | ||||
-rw-r--r-- | cmd/sbc_harness/usb_keyboard.c | 6 |
6 files changed, 58 insertions, 37 deletions
diff --git a/cmd/sbc_harness/CMakeLists.txt b/cmd/sbc_harness/CMakeLists.txt index 678af07..6e722d7 100644 --- a/cmd/sbc_harness/CMakeLists.txt +++ b/cmd/sbc_harness/CMakeLists.txt @@ -30,7 +30,7 @@ target_link_libraries(sbc_harness_objs libusb libdhcp libhw_cr - lib9p + lib9p_srv lib9p_util ) pico_minimize_runtime(sbc_harness_objs diff --git a/cmd/sbc_harness/config/config.h b/cmd/sbc_harness/config/config.h index 5e7bc06..ca23462 100644 --- a/cmd/sbc_harness/config/config.h +++ b/cmd/sbc_harness/config/config.h @@ -11,6 +11,9 @@ #define CONFIG_FLASH_DEBUG 1 +#define _CONFIG_9P_MAX_CONNS 3 /* FIXME: bump this back up to 8 */ +#define _CONFIG_9P_MAX_REQS (2*_CONFIG_9P_MAX_CONNS) + /* RP2040 *********************************************************************/ #define CONFIG_RP2040_SPI_DEBUG 1 /* bool */ @@ -36,6 +39,18 @@ #define CONFIG_9P_MAX_ERR_SIZE 128 /* 128 is what Plan 9 4e uses */ +#define CONFIG_9P_ENABLE_9P2000 1 /* bool */ +#define CONFIG_9P_ENABLE_9P2000_u 1 /* bool */ +#define CONFIG_9P_ENABLE_9P2000_e 0 /* bool */ +#define CONFIG_9P_ENABLE_9P2000_L 0 /* bool */ +#define CONFIG_9P_ENABLE_9P2000_p9p 0 /* bool */ + +/* 9P_SRV *********************************************************************/ + +#define CONFIG_9P_SRV_DEBUG 1 /* bool */ + +#define CONFIG_9P_SRV_MAX_MSG_SIZE ((4*1024)+24) + /** * This max-msg-size is sized so that a Twrite message can return * 8KiB of data. @@ -60,15 +75,6 @@ * struct padding, (2) array pointers. */ #define CONFIG_9P_SRV_MAX_HOSTMSG_SIZE CONFIG_9P_SRV_MAX_MSG_SIZE+16 -#define CONFIG_9P_SRV_MAX_FIDS 16 -#define CONFIG_9P_SRV_MAX_REQS 2 -#define CONFIG_9P_SRV_MAX_DEPTH 3 - -#define CONFIG_9P_ENABLE_9P2000 1 /* bool */ -#define CONFIG_9P_ENABLE_9P2000_u 1 /* bool */ -#define CONFIG_9P_ENABLE_9P2000_e 0 /* bool */ -#define CONFIG_9P_ENABLE_9P2000_L 0 /* bool */ -#define CONFIG_9P_ENABLE_9P2000_p9p 0 /* bool */ /* DHCP ***********************************************************************/ @@ -92,8 +98,8 @@ extern const size_t CONFIG_COROUTINE_STACK_SIZE_dhcp_cr; extern const size_t CONFIG_COROUTINE_STACK_SIZE_init_cr; -extern const size_t CONFIG_COROUTINE_STACK_SIZE_lib9p_srv_write_cr; extern const size_t CONFIG_COROUTINE_STACK_SIZE_read9p_cr; +extern const size_t CONFIG_COROUTINE_STACK_SIZE_write9p_cr; extern const size_t CONFIG_COROUTINE_STACK_SIZE_usb_common_cr; extern const size_t CONFIG_COROUTINE_STACK_SIZE_usb_keyboard_cr; extern const size_t CONFIG_COROUTINE_STACK_SIZE_w5500_irq_cr; @@ -104,12 +110,11 @@ extern const size_t CONFIG_COROUTINE_STACK_SIZE_w5500_irq_cr; #define CONFIG_COROUTINE_VALGRIND 0 /* bool */ #define CONFIG_COROUTINE_GDB 1 /* bool */ -#define _CONFIG_9P_NUM_SOCKS 3 /* FIXME: bump this back up to 8 */ -#define CONFIG_COROUTINE_NUM ( \ - 1 /* usb_common */ + \ - 1 /* usb_keyboard */ + \ - 1 /* W5500 irq handler */ + \ - _CONFIG_9P_NUM_SOCKS /* 9P accept()+read() */ + \ - (CONFIG_9P_SRV_MAX_REQS*_CONFIG_9P_NUM_SOCKS) /* 9P work+write() */ ) +#define CONFIG_COROUTINE_NUM ( \ + 1 /* usb_common */ + \ + 1 /* usb_keyboard */ + \ + 1 /* W5500 irq handler */ + \ + _CONFIG_9P_MAX_CONNS /* 9P accept()+read() */ + \ + _CONFIG_9P_MAX_REQS /* 9P work+write() */ ) #endif /* _CONFIG_H_ */ diff --git a/cmd/sbc_harness/fs_harness_flash_bin.c b/cmd/sbc_harness/fs_harness_flash_bin.c index bcdf296..bc3d061 100644 --- a/cmd/sbc_harness/fs_harness_flash_bin.c +++ b/cmd/sbc_harness/fs_harness_flash_bin.c @@ -175,13 +175,13 @@ static void flash_file_wstat(struct flash_file *self, struct lib9p_srv_ctx *ctx, assert(self); assert(ctx); - lib9p_error(&ctx->basectx, LINUX_EROFS, "read-only part of filesystem"); + lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem"); } static void flash_file_remove(struct flash_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); - lib9p_error(&ctx->basectx, LINUX_EROFS, "read-only part of filesystem"); + lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem"); } LIB9P_SRV_NOTDIR(struct flash_file, flash_file); @@ -235,7 +235,7 @@ static void flash_file_pread(struct flash_file *self, struct lib9p_srv_ctx *ctx, if (byte_offset > DATA_SIZE) { lib9p_error(&ctx->basectx, - LINUX_EINVAL, "offset is past the chip size"); + LIB9P_ERRNO_L_EINVAL, "offset is past the chip size"); return; } @@ -281,14 +281,14 @@ static uint32_t flash_file_pwrite(struct flash_file *self, struct lib9p_srv_ctx if (byte_offset > DATA_HSIZE) { lib9p_error(&ctx->basectx, - LINUX_EINVAL, "offset is past half the chip size"); + LIB9P_ERRNO_L_EINVAL, "offset is past half the chip size"); return 0; } if (byte_count == 0) return 0; if (byte_offset == DATA_HSIZE) { lib9p_error(&ctx->basectx, - LINUX_EINVAL, "offset is at half the chip size"); + LIB9P_ERRNO_L_EINVAL, "offset is at half the chip size"); return 0; } diff --git a/cmd/sbc_harness/fs_harness_uptime_txt.c b/cmd/sbc_harness/fs_harness_uptime_txt.c index 9216986..dd5c681 100644 --- a/cmd/sbc_harness/fs_harness_uptime_txt.c +++ b/cmd/sbc_harness/fs_harness_uptime_txt.c @@ -5,10 +5,10 @@ */ #include <stdio.h> /* for snprintf() */ -#include <stdlib.h> /* for malloc(), free() */ #include <libhw/generic/alarmclock.h> #include <util9p/static.h> +#include <libmisc/alloc.h> /* for heap_alloc(), free() */ #include "fs_harness_uptime_txt.h" @@ -75,13 +75,13 @@ static void uptime_file_wstat(struct uptime_file *self, struct lib9p_srv_ctx *ct assert(self); assert(ctx); - lib9p_error(&ctx->basectx, LINUX_EROFS, "read-only part of filesystem"); + lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem"); } static void uptime_file_remove(struct uptime_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); - lib9p_error(&ctx->basectx, LINUX_EROFS, "read-only part of filesystem"); + lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem"); } LIB9P_SRV_NOTDIR(struct uptime_file, uptime_file); @@ -91,7 +91,7 @@ static lo_interface lib9p_srv_fio uptime_file_fopen(struct uptime_file *self, st assert(self); assert(ctx); - struct uptime_fio *ret = malloc(sizeof(struct uptime_fio)); + struct uptime_fio *ret = heap_alloc(1, struct uptime_fio); ret->parent = self; ret->buf_len = 0; @@ -130,7 +130,7 @@ static void uptime_fio_pread(struct uptime_fio *self, struct lib9p_srv_ctx *ctx, if (byte_offset > (uint64_t)self->buf_len) { lib9p_error(&ctx->basectx, - LINUX_EINVAL, "offset is past end-of-file length"); + LIB9P_ERRNO_L_EINVAL, "offset is past end-of-file length"); return; } @@ -151,6 +151,6 @@ static uint32_t uptime_fio_pwrite(struct uptime_fio *self, struct lib9p_srv_ctx assert(self); assert(ctx); - lib9p_error(&ctx->basectx, LINUX_EROFS, "read-only part of filesystem"); + lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem"); return 0; } diff --git a/cmd/sbc_harness/main.c b/cmd/sbc_harness/main.c index 25b122c..5630e83 100644 --- a/cmd/sbc_harness/main.c +++ b/cmd/sbc_harness/main.c @@ -39,6 +39,13 @@ #include "config.h" +#ifndef _CONFIG_9P_MAX_CONNS + #error config.h must define _CONFIG_9P_MAX_CONNS +#endif +#ifndef _CONFIG_9P_MAX_REQS + #error config.h must define _CONFIG_9P_MAX_REQS +#endif + /* file tree ******************************************************************/ enum { PATH_BASE = __COUNTER__ }; @@ -153,13 +160,21 @@ static COROUTINE read9p_cr(void *) { lo_interface net_iface iface = lo_box_w5500_if_as_net_iface(&globals.dev_w5500); lo_interface net_stream_listener listener = LO_CALL(iface, tcp_listen, LIB9P_DEFAULT_PORT_9FS); - lib9p_srv_read_cr(&globals.srv, listener); + lib9p_srv_accept_and_read_loop(&globals.srv, listener); + + cr_end(); +} + +static COROUTINE write9p_cr(void *) { + cr_begin(); + + lib9p_srv_worker_loop(&globals.srv); cr_end(); } const char *const hexdig = "0123456789ABCDEF"; -static_assert(CONFIG_9P_SRV_MAX_REQS*_CONFIG_9P_NUM_SOCKS <= 16); +static_assert(_CONFIG_9P_MAX_REQS <= 16); COROUTINE init_cr(void *) { cr_begin(); @@ -215,13 +230,13 @@ COROUTINE init_cr(void *) { coroutine_add("usb_keyboard", usb_keyboard_cr, &globals.keyboard_chan); //coroutine_add("hello_world", hello_world_cr, &globals.keyboard_chan); coroutine_add("dhcp", dhcp_cr, NULL); - for (int i = 0; i < _CONFIG_9P_NUM_SOCKS; i++) { + for (int i = 0; i < _CONFIG_9P_MAX_CONNS; i++) { char name[] = {'r', 'e', 'a', 'd', '-', hexdig[i], '\0'}; coroutine_add(name, read9p_cr, NULL); } - for (int i = 0; i < CONFIG_9P_SRV_MAX_REQS*_CONFIG_9P_NUM_SOCKS; i++) { + for (int i = 0; i < _CONFIG_9P_MAX_REQS; i++) { char name[] = {'w', 'r', 'i', 't', 'e', '-', hexdig[i], '\0'}; - coroutine_add(name, lib9p_srv_write_cr, &globals.srv); + coroutine_add(name, write9p_cr, NULL); } cr_exit(); @@ -234,4 +249,5 @@ int main() { infof("==================================================================="); coroutine_add("init", init_cr, NULL); coroutine_main(); + assert_notreached("all coroutines exited"); } diff --git a/cmd/sbc_harness/usb_keyboard.c b/cmd/sbc_harness/usb_keyboard.c index f3cb42d..7dd8a24 100644 --- a/cmd/sbc_harness/usb_keyboard.c +++ b/cmd/sbc_harness/usb_keyboard.c @@ -54,8 +54,8 @@ COROUTINE usb_keyboard_cr(void *_chan) { while (!tud_hid_n_ready(kbd_ifc)) cr_yield(); - if (usb_keyboard_rpc_can_recv_req(chan)) { - usb_keyboard_rpc_req_t req = usb_keyboard_rpc_recv_req(chan); + if (cr_rpc_can_recv_req(chan)) { + usb_keyboard_rpc_req_t req = cr_rpc_recv_req(chan); uint32_t rune = req.req; modifier = ascii2keycode[rune][0] ? KEYBOARD_MODIFIER_LEFTSHIFT : 0; @@ -69,7 +69,7 @@ COROUTINE usb_keyboard_cr(void *_chan) { keycodes[0] = 0; tud_hid_n_keyboard_report(kbd_ifc, report_id, modifier, keycodes); - usb_keyboard_rpc_send_resp(req, 1); + cr_rpc_send_resp(req, 1); } else { modifier = 0; keycodes[0] = 0; |