summaryrefslogtreecommitdiff
path: root/cmd/sbc_harness/main.c
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-12-13 18:49:15 -0500
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-12-13 18:49:15 -0500
commitc578a300c7d0d46662fcd0bdce69af95a821bc18 (patch)
treea99de333f2812d7c018820f39d78b8c4e744f705 /cmd/sbc_harness/main.c
parent6a719c63ecb83a850c317ea94b8932aa0c857770 (diff)
parent57cc0523f600575feda09bd9fae13f685ce85b0f (diff)
Merge commit '57cc0523f600575feda09bd9fae13f685ce85b0f'
Diffstat (limited to 'cmd/sbc_harness/main.c')
-rw-r--r--cmd/sbc_harness/main.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/cmd/sbc_harness/main.c b/cmd/sbc_harness/main.c
index fb4b696..00f1c4a 100644
--- a/cmd/sbc_harness/main.c
+++ b/cmd/sbc_harness/main.c
@@ -13,17 +13,19 @@
#include <libhw/rp2040_hwspi.h>
#include <libhw/w5500.h>
#include <libmisc/hash.h>
+#include <libmisc/vcall.h>
#include <libusb/usb_common.h>
#include <libdhcp/client.h>
+#include <lib9p/srv.h>
#define LOG_NAME MAIN
#include <libmisc/log.h>
#include "usb_keyboard.h"
-#define ARRAY_LEN(arr) (sizeof(arr)/sizeof((arr)[0]))
+#include "config.h"
-COROUTINE hello_world_cr(void *_chan) {
+static COROUTINE hello_world_cr(void *_chan) {
const char *msg = "Hello world!\n";
usb_keyboard_rpc_t *chan = _chan;
cr_begin();
@@ -39,7 +41,7 @@ COROUTINE hello_world_cr(void *_chan) {
cr_end();
}
-COROUTINE dhcp_cr(void *_chip) {
+static COROUTINE dhcp_cr(void *_chip) {
struct w5500 *chip = _chip;
cr_begin();
@@ -53,9 +55,20 @@ struct {
struct w5500 dev_w5500;
usb_keyboard_rpc_t keyboard_chan;
uint16_t usb_serial[sizeof(uint64_t)*2]; /* UTF-16 */
+ struct lib9p_srv srv;
} globals;
+static COROUTINE read9p_cr(void *) {
+ cr_begin();
+
+ lib9p_srv_read_cr(&globals.srv,
+ VCALL(&globals.dev_w5500, tcp_listen, CONFIG_9P_PORT));
+
+ cr_end();
+}
+
const char *hexdig = "0123456789ABCDEF";
+static_assert(CONFIG_9P_MAX_REQS*_CONFIG_9P_NUM_SOCKS <= 16);
COROUTINE init_cr(void *) {
cr_begin();
@@ -91,8 +104,8 @@ COROUTINE init_cr(void *) {
flash_id24[0], flash_id24[1], flash_id24[2],
}}));
- static_assert(sizeof(flash_id64)*2 == ARRAY_LEN(globals.usb_serial));
- for (size_t i = 0; i < ARRAY_LEN(globals.usb_serial); i++)
+ static_assert(sizeof(flash_id64)*2 == LM_ARRAY_LEN(globals.usb_serial));
+ for (size_t i = 0; i < LM_ARRAY_LEN(globals.usb_serial); i++)
globals.usb_serial[i] = hexdig[(flash_id64 >> ((sizeof(flash_id64)*8)-((i+1)*4))) & 0xF];
usb_common_earlyinit(globals.usb_serial, sizeof(globals.usb_serial));
usb_keyboard_init();
@@ -103,8 +116,16 @@ COROUTINE init_cr(void *) {
/* set up coroutines **************************************************/
coroutine_add("usb_common", usb_common_cr, NULL);
coroutine_add("usb_keyboard", usb_keyboard_cr, &globals.keyboard_chan);
- //coroutine_add("hello_world", hello_world_cr, &keyboard_chan);
+ coroutine_add("hello_world", hello_world_cr, &globals.keyboard_chan);
coroutine_add_with_stack_size(4*1024, "dhcp", dhcp_cr, &globals.dev_w5500);
+ for (int i = 0; i < _CONFIG_9P_NUM_SOCKS; i++) {
+ char name[] = {'r', 'e', 'a', 'd', '-', hexdig[i], '\0'};
+ coroutine_add(name, read9p_cr, NULL);
+ }
+ for (int i = 0; i < CONFIG_9P_MAX_REQS*_CONFIG_9P_NUM_SOCKS; i++) {
+ char name[] = {'w', 'r', 'i', 't', 'e', '-', hexdig[i], '\0'};
+ coroutine_add(name, lib9p_srv_write_cr, &globals.srv);
+ }
cr_exit();
}