summaryrefslogtreecommitdiff
path: root/cmd/sbc_harness
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/sbc_harness')
-rw-r--r--cmd/sbc_harness/CMakeLists.txt5
-rw-r--r--cmd/sbc_harness/main.c33
-rw-r--r--cmd/sbc_harness/usb_keyboard.c9
3 files changed, 34 insertions, 13 deletions
diff --git a/cmd/sbc_harness/CMakeLists.txt b/cmd/sbc_harness/CMakeLists.txt
index 96c2a2c..f1b1be2 100644
--- a/cmd/sbc_harness/CMakeLists.txt
+++ b/cmd/sbc_harness/CMakeLists.txt
@@ -24,6 +24,7 @@ target_link_libraries(sbc_harness_objs
libusb
libdhcp
libhw
+ lib9p
)
pico_minimize_runtime(sbc_harness_objs
INCLUDE PRINTF PRINTF_MINIMAL PRINTF_LONG_LONG PRINTF_PTRDIFF_T
@@ -38,10 +39,6 @@ add_stack_analysis(sbc_harness_stack.c sbc_harness_objs)
# Link #########################################################################
add_executable(sbc_harness)
-set_source_files_properties("$<TARGET_OBJECTS:sbc_harness_objs>" PROPERTIES
- EXTERNAL_OBJECT true
- GENERATED true
-)
target_sources(sbc_harness PRIVATE
sbc_harness_stack.c
"$<TARGET_OBJECTS:sbc_harness_objs>"
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();
}
diff --git a/cmd/sbc_harness/usb_keyboard.c b/cmd/sbc_harness/usb_keyboard.c
index f4816c1..b781d4d 100644
--- a/cmd/sbc_harness/usb_keyboard.c
+++ b/cmd/sbc_harness/usb_keyboard.c
@@ -8,11 +8,10 @@
#include <libusb/tusb_helpers.h> /* for TUD_ENDPOINT_IN */
#include <libusb/usb_common.h>
+#include <libmisc/macro.h>
#include "usb_keyboard.h"
-#define UNUSED(name)
-
/**
* A USB-HID "Report Descriptor" (see USB-HID 1.11 ยง6.2.2 "Report
* Descriptor") describing a keyboard.
@@ -108,7 +107,11 @@ uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_t
// Invoked when received SET_REPORT control request or
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
-void tud_hid_set_report_cb(uint8_t UNUSED(instance), uint8_t UNUSED(report_id), hid_report_type_t UNUSED(report_type), uint8_t const *UNUSED(buffer), uint16_t UNUSED(bufsize))
+void tud_hid_set_report_cb(uint8_t LM_UNUSED(instance),
+ uint8_t LM_UNUSED(report_id),
+ hid_report_type_t LM_UNUSED(report_type),
+ uint8_t const *LM_UNUSED(buffer),
+ uint16_t LM_UNUSED(bufsize))
{
// TODO not implemented
}