summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-11-15 20:42:00 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-11-19 20:15:48 -0700
commit51e4ec63b745836c33b6f92c9cbfafb8892e1843 (patch)
treef54fc1ccdf67c61bd5959e5ab625c3846d8a590f
parent7aa534178293279b861a6dc36499c179aa70cdfb (diff)
libcr: Assert that cr_getcid() is only called inside a coroutine
-rw-r--r--cmd/sbc_harness/main.c31
-rw-r--r--libcr/coroutine.c1
2 files changed, 21 insertions, 11 deletions
diff --git a/cmd/sbc_harness/main.c b/cmd/sbc_harness/main.c
index 85dfdfb..bdd23a7 100644
--- a/cmd/sbc_harness/main.c
+++ b/cmd/sbc_harness/main.c
@@ -44,9 +44,14 @@ COROUTINE dhcp_cr(void *_chip) {
cr_end();
}
-int main() {
- /* initialization *****************************************************/
- stdio_uart_init();
+struct {
+ struct rp2040_hwspi dev_spi;
+ struct w5500 dev_w5500;
+ usb_keyboard_rpc_t keyboard_chan;
+} globals;
+
+COROUTINE init_cr(void *) {
+ cr_begin();
/* NOR flash chips have a (bog-?)standard "RUID" "Read Unique
* ID" instruction; use our flash chip's unique ID as the
@@ -62,16 +67,14 @@ int main() {
(uint8_t)((flash_id32 >> 0) & 0xFF),
};
- struct rp2040_hwspi dev_spi;
- struct w5500 dev_w5500;
- rp2040_hwspi_init(&dev_spi, "W5500", RP2040_HWSPI_0,
+ rp2040_hwspi_init(&globals.dev_spi, "W5500", RP2040_HWSPI_0,
SPI_MODE_0, /* the W5500 supports mode 0 or mode 3 */
80*1000*1000, /* run at the W5500's max rate of 80MHz */
16, /* PIN_MISO */
19, /* PIN_MOSI */
18, /* PIN_CLK */
17); /* PIN_CS */
- w5500_init(&dev_w5500, "W5500", &dev_spi,
+ w5500_init(&globals.dev_w5500, "W5500", &globals.dev_spi,
21, /* PIN_INTR */
20, /* PIN_RESET */
((struct net_eth_addr){{
@@ -85,13 +88,19 @@ int main() {
usb_keyboard_init();
usb_common_lateinit();
+ globals.keyboard_chan = (usb_keyboard_rpc_t){0};
+
/* set up coroutines **************************************************/
coroutine_add("usb_common", usb_common_cr, NULL);
- usb_keyboard_rpc_t keyboard_chan = {0};
- coroutine_add("usb_keyboard", usb_keyboard_cr, &keyboard_chan);
+ coroutine_add("usb_keyboard", usb_keyboard_cr, &globals.keyboard_chan);
//coroutine_add("hello_world", hello_world_cr, &keyboard_chan);
- coroutine_add_with_stack_size(4*1024, "dhcp", dhcp_cr, &dev_w5500);
+ coroutine_add_with_stack_size(4*1024, "dhcp", dhcp_cr, &globals.dev_w5500);
- /* event loop *********************************************************/
+ cr_exit();
+}
+
+int main() {
+ stdio_uart_init();
+ coroutine_add("init", init_cr, NULL);
coroutine_main();
}
diff --git a/libcr/coroutine.c b/libcr/coroutine.c
index 7f61e94..9f1150b 100644
--- a/libcr/coroutine.c
+++ b/libcr/coroutine.c
@@ -606,6 +606,7 @@ void cr_unpause_from_intrhandler(cid_t cid) {
}
cid_t cr_getcid(void) {
+ assert_cid_state(coroutine_running, state == CR_RUNNING);
return coroutine_running;
}