diff options
| author | Felipe Balbi <[email protected]> | 2025-11-07 11:00:15 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-11-07 11:00:15 -0800 |
| commit | 5632acec18cc5906b1625a8facf530db56c73300 (patch) | |
| tree | abf2897f4b2f9814069c64611896be2d42cf2ce8 /examples/ostimer_async.rs | |
| parent | 47e383545f4aac3bfaec0563429cc721540e665a (diff) | |
| parent | 9590d94ee9ba016f65a13100c429fc56ffe58e40 (diff) | |
Merge pull request #1 from bogdan-petru/import/mcxa276-initial
feat(mcxa276): initial HAL import
Diffstat (limited to 'examples/ostimer_async.rs')
| -rw-r--r-- | examples/ostimer_async.rs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/examples/ostimer_async.rs b/examples/ostimer_async.rs new file mode 100644 index 000000000..27e14e022 --- /dev/null +++ b/examples/ostimer_async.rs | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use embassy_executor::Spawner; | ||
| 5 | use embassy_mcxa276 as hal; | ||
| 6 | use hal::uart; | ||
| 7 | |||
| 8 | mod common; | ||
| 9 | |||
| 10 | use embassy_mcxa276::bind_interrupts; | ||
| 11 | use embassy_time::{Duration, Timer}; | ||
| 12 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | |||
| 14 | // Bind only OS_EVENT, and retain the symbol explicitly so it can’t be GC’ed. | ||
| 15 | bind_interrupts!(struct Irqs { | ||
| 16 | OS_EVENT => hal::ostimer::time_driver::OsEventHandler; | ||
| 17 | }); | ||
| 18 | |||
| 19 | #[used] | ||
| 20 | #[no_mangle] | ||
| 21 | static KEEP_OS_EVENT: unsafe extern "C" fn() = OS_EVENT; | ||
| 22 | |||
| 23 | #[embassy_executor::main] | ||
| 24 | async fn main(_spawner: Spawner) { | ||
| 25 | let _p = hal::init(hal::config::Config::default()); | ||
| 26 | |||
| 27 | // Enable/clock OSTIMER0 and UART2 before touching their registers | ||
| 28 | unsafe { | ||
| 29 | common::init_ostimer0(hal::pac()); | ||
| 30 | } | ||
| 31 | unsafe { | ||
| 32 | common::init_uart2(hal::pac()); | ||
| 33 | } | ||
| 34 | let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) }; | ||
| 35 | let uart = uart::Uart::<uart::Lpuart2>::new(_p.LPUART2, uart::Config::new(src)); | ||
| 36 | uart.write_str_blocking("boot\n"); | ||
| 37 | |||
| 38 | // Avoid mass NVIC writes here; DefaultHandler now safely returns. | ||
| 39 | |||
| 40 | // Initialize embassy-time global driver backed by OSTIMER0 (re-enables OS_EVENT with priority) | ||
| 41 | // The bind_interrupts! macro handles handler binding automatically | ||
| 42 | |||
| 43 | // Initialize OSTIMER with default 1MHz frequency | ||
| 44 | // Adjust this value to match your actual OSTIMER clock frequency | ||
| 45 | hal::ostimer::time_driver::init(hal::config::Config::default().time_interrupt_priority, 1_000_000); | ||
| 46 | |||
| 47 | // Removed force-pend; rely on real hardware match to trigger OS_EVENT. | ||
| 48 | |||
| 49 | // Log using defmt if enabled | ||
| 50 | defmt::info!("OSTIMER async example starting..."); | ||
| 51 | |||
| 52 | loop { | ||
| 53 | defmt::info!("tick"); | ||
| 54 | uart.write_str_blocking("tick\n"); | ||
| 55 | Timer::after(Duration::from_millis(1000)).await; | ||
| 56 | } | ||
| 57 | } | ||
