diff --git a/Cargo.toml b/Cargo.toml index e4fdfe3..1fd18b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ path = "./src/bin/main.rs" [features] default = ["real-output"] real-output = [] +dual-core = [] simulation = ["dep:rmp"] radio = [ "dep:bleps", diff --git a/src/bin/main.rs b/src/bin/main.rs index 856a63e..cf5995e 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -63,13 +63,6 @@ async fn main(spawner: Spawner) { esp_rtos::start(sys_timer.alarm0); info!("Embassy initialized!"); - let timer0 = TimerGroup::new(peripherals.TIMG0); - - let timer1 = TimerGroup::new(peripherals.TIMG1); - let mut ui_wdt = timer1.wdt; - ui_wdt.set_timeout(esp_hal::timer::timg::MwdtStage::Stage0, esp_hal::time::Duration::from_secs(10)); - ui_wdt.enable(); - static MOTION_BUS: StaticCell > = StaticCell::new(); let motion_bus = MOTION_BUS.init_with(|| { Channel::new() }); @@ -87,13 +80,15 @@ async fn main(spawner: Spawner) { let mut safety_surfaces = UiSurfacePool::default(); let safety_ui = SafetyUi::new(&mut safety_surfaces, display_controls.clone()); + 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(); + 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()); - //wdt.enable(); hi_spawn.must_spawn(renderbug_embassy::tasks::render::render(peripherals.RMT, peripherals.GPIO5.degrade(), surfaces, safety_surfaces, display_controls, wdt)); #[cfg(feature="motion")] @@ -148,45 +143,58 @@ async fn main(spawner: Spawner) { #[cfg(feature="radio")] let wifi_init = { info!("Configuring wifi"); - //let rng = esp_hal::rng::Rng::new(peripherals.RNG); WIFI_INIT.init_with(|| {esp_radio::init().expect("Failed to initialize radio controller")}) }; info!("Starting core 2"); - //let mut cpu_control = CpuControl::new(peripherals.CPU_CTRL); + + let core2_main = |spawner: Spawner| { + let garage = BUS_GARAGE.init_with(|| { Default::default() }); + + 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")] + { + info!("Launching networking stack"); + spawner.must_spawn(renderbug_embassy::tasks::wifi::wireless_task(garage.predict.dyn_subscriber().unwrap(), wifi_init, peripherals.WIFI)); + } + + #[cfg(feature="demo")] + { + warn!("Launching with demo sequencer"); + spawner.must_spawn(renderbug_embassy::tasks::demo::demo_task(garage.notify.dyn_publisher().unwrap())); + } + + #[cfg(feature="dual-core")] + { + info!("Launching core 2 watchdog"); + let timer1 = TimerGroup::new(peripherals.TIMG1); + let mut ui_wdt = timer1.wdt; + ui_wdt.set_timeout(esp_hal::timer::timg::MwdtStage::Stage0, esp_hal::time::Duration::from_secs(10)); + #[cfg(feature="dual-core")] + ui_wdt.enable(); + spawner.must_spawn(wdt_task(ui_wdt)); + } + + info!("System is ready in {}ms", Instant::now().as_millis()); + }; + + #[cfg(feature="dual-core")] esp_rtos::start_second_core(peripherals.CPU_CTRL, swi.software_interrupt0, swi.software_interrupt1, unsafe { &mut *addr_of_mut!(CORE2_STACK) }, || { let exec = CORE2_EXEC.init_with(|| { Executor::new() }); - exec.run(|spawner| { - let garage = BUS_GARAGE.init_with(|| { Default::default() }); - - 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")] - { - info!("Launching networking stack"); - spawner.must_spawn(renderbug_embassy::tasks::wifi::wireless_task(garage.predict.dyn_subscriber().unwrap(), wifi_init, peripherals.WIFI)); - } - - #[cfg(feature="demo")] - { - warn!("Launching with demo sequencer"); - spawner.must_spawn(renderbug_embassy::tasks::demo::demo_task(garage.notify.dyn_publisher().unwrap())); - } - - info!("Launching core 2 watchdog"); - spawner.must_spawn(wdt_task(ui_wdt)); - - info!("System is ready in {}ms", Instant::now().as_millis()); - }); + exec.run(core2_main); }); + + #[cfg(not(feature="dual-core"))] + core2_main(spawner); } #[embassy_executor::task]