diff --git a/src/runtime.rs b/src/runtime.rs index f4811823f27d8d87f3e41b326d5ad782769d634b..e57770af4a26c7f989ca8d00e684da49462b6d3e 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -3,7 +3,7 @@ use embassy_time::{Duration, Timer}; use esp_println::println; use hal::{ clock::{ClockControl, Clocks}, - cpu_control::CpuControl, + cpu_control::{CpuControl, AppCoreGuard}, embassy, gdma::Gdma, i2c::I2C, @@ -11,7 +11,7 @@ use hal::{ peripherals::{Peripherals, I2C0}, prelude::*, systimer::SystemTimer, - timer::TimerGroup, Rng, Rtc, Spi, Uart, IO, uart::{self, TxRxPins}, gpio::{Gpio6, Unknown, Gpio4, Gpio7, Gpio5}, Rmt, + timer::TimerGroup, Rng, Rtc, Spi, Uart, IO, uart::{self, TxRxPins}, Rmt, }; use static_cell::StaticCell; @@ -30,7 +30,9 @@ const READ_BUF_SIZE: usize = 64; static RNG: StaticCell<Rng> = StaticCell::new(); static EXECUTOR: StaticCell<Executor> = StaticCell::new(); -//static APP_CORE_EXECUTOR: StaticCell<Executor> = StaticCell::new(); +static APP_CORE_EXECUTOR: StaticCell<Executor> = StaticCell::new(); +static APP_CORE_GUARD: StaticCell<AppCoreGuard> = StaticCell::new(); +static APP_CORE_FN: StaticCell<fn()> = StaticCell::new(); static CLOCKS: StaticCell<Clocks> = StaticCell::new(); pub fn start_runtime() -> ! { @@ -40,18 +42,22 @@ pub fn start_runtime() -> ! { }); } +fn start_app_core () { + let executor = APP_CORE_EXECUTOR.init(Executor::new()); + executor.run(|spawner| { + spawner.spawn(init_second_core()).ok(); + }); +} + + #[embassy_executor::task] -async fn start_app_core(mut cpu_control: CpuControl) -> ! { - let mut app_core_function = || { - /*let executor = APP_CORE_EXECUTOR.init(Executor::new()); - executor.run(|spawner| { - spawner.spawn(display_refresh()).ok(); - })*/ - }; - let _guard = cpu_control.start_app_core(&mut app_core_function).unwrap(); +async fn init_second_core() { + loop { - Timer::after(Duration::from_secs(100)).await; + println!("second core running"); + Timer::after(Duration::from_millis(1000)).await; } + } #[embassy_executor::task] @@ -83,7 +89,9 @@ async fn init_runtime() { embassy::init(&clocks, SystemTimer::new(peripherals.SYSTIMER)); - let _cpu_control = CpuControl::new(system.cpu_control); + let app_core_fn = APP_CORE_FN.init(start_app_core); + let mut cpu_control = CpuControl::new(system.cpu_control); + let _ = APP_CORE_GUARD.init(cpu_control.start_app_core(app_core_fn).unwrap()); // Async requires the GPIO interrupt to wake futures hal::interrupt::enable( @@ -195,7 +203,7 @@ async fn init_runtime() { // Init Flow3r components - let mut badgelink = BadgeLink::new(i2c_busmanager.acquire_i2c()); + let badgelink = BadgeLink::new(i2c_busmanager.acquire_i2c()); let imu = ImuHandler::new(i2c_busmanager.acquire_i2c()); let inputs = InputHandler; let captouch = CaptouchHandler; @@ -275,4 +283,4 @@ async fn test_pins_c(pin: Gpio4<Unknown>) -> ! { pin.wait_for_any_edge().await.unwrap(); println!("pin 4 changed, is now {}", pin.is_high().unwrap()); } -} */ \ No newline at end of file +} */