soundstream: make mailbox optional - make mailbox usage conditional on the device being present (still need to fill in gpio support when not present) - make mailbox driver conditional on sencha (no way to check board config for the device being present) Change-Id: I4713460bbfeb8aeb2f78edce07f2d1b00d87437a
diff --git a/sw/device/cheriot/soundstream/soundstream.cc b/sw/device/cheriot/soundstream/soundstream.cc index 9e880da..a1c4fc6 100644 --- a/sw/device/cheriot/soundstream/soundstream.cc +++ b/sw/device/cheriot/soundstream/soundstream.cc
@@ -43,7 +43,9 @@ i2s_init(); ml_top_init(); +#if DEVICE_EXISTS_mailbox mailbox_init(); +#endif i2s_rxfifo_clear(); i2s_irq_acknowledge_all(); @@ -69,6 +71,7 @@ #else { #endif +#if DEVICE_EXISTS_mailbox // TODO(sleffler): need custom security core code running and // a way to toggle the gpio associated with the button; for now // just force it to appear as though the button has been pressed. @@ -79,12 +82,19 @@ mailbox_wait_for_button_pressed(); mailbox_set_led(/*enabled=*/true); +#else +#endif Debug::log("Start recording (max {} samples)...", kSamples); i2s_record_begin(); // Record until our buffer is full or the switch is released. int sample = 0; - while (sample < kSamples && mailbox_button_pressed()) { + while (sample < kSamples +#if DEVICE_EXISTS_mailbox + && mailbox_button_pressed() +#else +#endif + ) { i2s_irq_set_enabled(kI2sIrqRxWatermark, /*enabled=*/true); i2s_wait_for_rx_watermark(); @@ -111,14 +121,22 @@ uint32_t offset_reg_val = (((left - mean_left) & 0xFFFF) << 16) | ((right - mean_right) & 0xFFFF); samples[sample++] = offset_reg_val; - if (sample == kSamples || !mailbox_button_pressed()) { + if (sample == kSamples +#if DEVICE_EXISTS_mailbox + || !mailbox_button_pressed() +#else +#endif + ) { break; } } } i2s_record_end(); +#if DEVICE_EXISTS_mailbox mailbox_set_led(/*enabled=*/false); +#else +#endif Debug::log("Done recording {} samples", sample); int samples_captured = sample;
diff --git a/sw/device/cheriot/soundstream/soundstream.h b/sw/device/cheriot/soundstream/soundstream.h index 640834c..4158d95 100644 --- a/sw/device/cheriot/soundstream/soundstream.h +++ b/sw/device/cheriot/soundstream/soundstream.h
@@ -21,7 +21,9 @@ #include "encode.h" #include "i2s.h" +#if DEVICE_EXISTS_mailbox #include "mailbox.h" +#endif #include "ml_top.h" #endif // EXAMPLES_SOUNDSTREAM_SOUNDSTREAM_H_
diff --git a/sw/device/cheriot/soundstream/xmake.lua b/sw/device/cheriot/soundstream/xmake.lua index 0872683..a99ec77 100644 --- a/sw/device/cheriot/soundstream/xmake.lua +++ b/sw/device/cheriot/soundstream/xmake.lua
@@ -41,6 +41,10 @@ includes(path.join(sdkdir, "lib")) includes(path.join(sdkdir, "lib/freestanding")) +local function is_sencha() + return is_config("board", "sencha") +end + -- Each driver operates in a compartment. compartment("i2s") add_files("i2s.cc") @@ -49,12 +53,14 @@ add_includedirs(matcha_dir, matcha_gen_dir, opentitan_dir) add_defines("CHERIOT_NO_AMBIENT_MALLOC") +if is_sencha() then compartment("mailbox") add_files("mailbox.cc") add_files(path.join(dif_dir, "dif_tlul_mailbox.c"), path.join(dif_autogen_dir, "dif_tlul_mailbox_autogen.c")) add_includedirs(matcha_dir, matcha_gen_dir, opentitan_dir) add_defines("CHERIOT_NO_AMBIENT_MALLOC") +end compartment("ml_top") add_files("ml_top.cc") @@ -72,13 +78,17 @@ -- Firmware image. firmware("soundstream-firmware") - add_deps("freestanding") - add_deps("debug", "i2s", "ml_top", "mailbox", "soundstream") + add_deps("i2s", "ml_top") + if is_sencha() then + add_deps("mailbox") + end + add_deps("soundstream") + add_deps("freestanding", "debug") on_load(function(target) target:values_set("board", "$(board)") -- NB: trusted_stack_frames is a guess; +1'd for any -- compartment error handler usage? - target:values_set("threads", { + local threads = { { compartment = "soundstream", priority = 1, @@ -101,12 +111,15 @@ stack_size = 0x400, -- 512B trusted_stack_frames = 3 }, - { + } + if is_sencha() then + table.insert(threads, { compartment = "mailbox", priority = 10, entry_point = "mailbox_isr", stack_size = 0x400, -- 512B trusted_stack_frames = 3 - } - }, {expand = false}) + }) + end + target:values_set("threads", threads, {expand = false}) end)