events: finally drop the whole bus garage idea

This commit is contained in:
2025-12-27 19:55:22 +01:00
parent 7e0889b624
commit d2b10288a7
3 changed files with 54 additions and 72 deletions

View File

@@ -18,9 +18,14 @@ use esp_hal::{
clock::CpuClock, system::{AppCoreGuard, CpuControl, Stack}, timer::{systimer::SystemTimer, timg::{TimerGroup, Wdt}}
};
use embassy_sync::{
pubsub::PubSubChannel,
blocking_mutex::raw::NoopRawMutex
};
use log::*;
use renderbug_embassy::{graphics::display::DisplayControls, logging::RenderbugLogger, tasks::{oled::{OledUI, OledUiSurfacePool, oled_ui}, safetyui::{SafetyUi, safety_ui_main}, ui::UiSurfacePool}};
use renderbug_embassy::events::{BusGarage, Measurement};
use renderbug_embassy::{events::Prediction, graphics::display::DisplayControls, logging::RenderbugLogger, tasks::{oled::{OledUI, OledUiSurfacePool, oled_ui}, safetyui::{SafetyUi, safety_ui_main}, ui::UiSurfacePool}};
use renderbug_embassy::events::Measurement;
use static_cell::StaticCell;
use esp_backtrace as _;
use esp_rtos::embassy::{Executor, InterruptExecutor};
@@ -31,7 +36,7 @@ use renderbug_embassy::tasks::{
ui::{Ui, ui_main}
};
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, pubsub::DynSubscriber};
use embassy_sync::channel::Channel;
extern crate alloc;
@@ -42,8 +47,6 @@ esp_bootloader_esp_idf::esp_app_desc!();
static STATIC_HI_EXEC: StaticCell<InterruptExecutor<2>> = StaticCell::new();
static CORE2_EXEC: StaticCell<Executor> = StaticCell::new();
static BUS_GARAGE: StaticCell<BusGarage> = StaticCell::new();
static mut CORE2_STACK: Stack<16384> = Stack::new();
#[cfg(feature="radio")]
static WIFI_INIT: StaticCell<esp_radio::Controller<'static>> = StaticCell::new();
@@ -83,13 +86,13 @@ async fn main(spawner: Spawner) {
let timer0 = TimerGroup::new(peripherals.TIMG0);
let mut wdt = timer0.wdt;
wdt.set_timeout(esp_hal::timer::timg::MwdtStage::Stage0, esp_hal::time::Duration::from_secs(5));
wdt.enable();
//wdt.enable();
let swi = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
let hi_exec = STATIC_HI_EXEC.init(InterruptExecutor::new(swi.software_interrupt2));
let hi_spawn = hi_exec.start(esp_hal::interrupt::Priority::max());
//let hi_exec = STATIC_HI_EXEC.init(InterruptExecutor::new(swi.software_interrupt2));
//let hi_spawn = hi_exec.start(esp_hal::interrupt::Priority::max());
hi_spawn.must_spawn(renderbug_embassy::tasks::render::render(peripherals.RMT, peripherals.GPIO5.degrade(), surfaces, safety_surfaces, display_controls, wdt));
spawner.must_spawn(renderbug_embassy::tasks::render::render(peripherals.RMT, peripherals.GPIO5.degrade(), surfaces, safety_surfaces, display_controls, wdt));
#[cfg(feature="motion")]
{
@@ -149,28 +152,32 @@ async fn main(spawner: Spawner) {
info!("Starting core 2");
let core2_main = |spawner: Spawner| {
let garage = BUS_GARAGE.init_with(|| { Default::default() });
static PREDICTIONS: StaticCell<PubSubChannel<NoopRawMutex, Prediction, 15, 5, 1>> = StaticCell::new();
let predictions = PREDICTIONS.init(PubSubChannel::new());
info!("Launching motion engine");
spawner.must_spawn(motion_task(motion_bus.dyn_receiver(), garage.predict.dyn_publisher().unwrap()));
info!("Launching Safety UI");
spawner.must_spawn(safety_ui_main(garage.predict.dyn_subscriber().unwrap(), safety_ui));
info!("Launching UI");
spawner.must_spawn(ui_main(garage.predict.dyn_subscriber().unwrap(), ui));
info!("Launching OLED UI");
spawner.must_spawn(oled_ui(garage.predict.dyn_subscriber().unwrap(), oledui));
#[cfg(feature="radio")]
#[cfg(not(feature="demo"))]
{
info!("Launching networking stack");
spawner.must_spawn(renderbug_embassy::tasks::wifi::wireless_task(garage.predict.dyn_subscriber().unwrap(), wifi_init, peripherals.WIFI));
info!("Launching motion engine");
spawner.must_spawn(motion_task(motion_bus.dyn_receiver(), predictions.dyn_publisher().unwrap()));
}
#[cfg(feature="demo")]
{
warn!("Launching with demo sequencer");
spawner.must_spawn(renderbug_embassy::tasks::demo::demo_task(garage.notify.dyn_publisher().unwrap()));
spawner.must_spawn(renderbug_embassy::tasks::demo::demo_task(predictions.dyn_publisher().unwrap()));
}
info!("Launching Safety UI");
spawner.must_spawn(safety_ui_main(predictions.dyn_subscriber().unwrap(), safety_ui));
info!("Launching UI");
spawner.must_spawn(ui_main(predictions.dyn_subscriber().unwrap(), ui));
info!("Launching OLED UI");
spawner.must_spawn(oled_ui(predictions.dyn_subscriber().unwrap(), oledui));
#[cfg(feature="radio")]
{
info!("Launching networking stack");
spawner.must_spawn(renderbug_embassy::tasks::wifi::wireless_task(predictions.dyn_subscriber().unwrap(), wifi_init, peripherals.WIFI));
}
#[cfg(feature="dual-core")]
@@ -184,6 +191,8 @@ async fn main(spawner: Spawner) {
spawner.must_spawn(wdt_task(ui_wdt));
}
spawner.must_spawn(print_telemetry(predictions.dyn_subscriber().unwrap()));
info!("System is ready in {}ms", Instant::now().as_millis());
};
@@ -206,4 +215,11 @@ async fn wdt_task(mut wdt: Wdt<esp_hal::peripherals::TIMG1<'static>>) {
wdt.feed();
Timer::after_secs(3).await;
}
}
#[embassy_executor::task]
async fn print_telemetry(mut events: DynSubscriber<'static, Prediction>) {
loop {
info!("predict={:?}", events.next_message_pure().await);
}
}