diff options
| author | Felipe Balbi <[email protected]> | 2025-11-19 09:11:54 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-11-19 09:11:54 -0800 |
| commit | a8eb124e47e633cd81e0863253d5f6bdd7545260 (patch) | |
| tree | 526374336411093886915121fea7245efa067c93 /src/lib.rs | |
| parent | ffe3e5acae6c0038db4176dc7d031b57f865e07f (diff) | |
OSTimer updates (#24)
* Initialize OSTIMER0 during HAL initialization
Provide the user with a working time driver.
Signed-off-by: Felipe Balbi <[email protected]>
* Handle time_driver interrupt internally
Signed-off-by: Felipe Balbi <[email protected]>
* Gate `time-driver` impl behind a `time` flag
Also prevents creation of an `Ostimer` instance if the `time`
feature is active.
* Remove some dead code
---------
Signed-off-by: Felipe Balbi <[email protected]>
Co-authored-by: James Munns <[email protected]>
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs index c885ecc50..e93ff61a6 100644 --- a/src/lib.rs +++ b/src/lib.rs | |||
| @@ -14,6 +14,9 @@ pub mod lpuart; | |||
| 14 | pub mod ostimer; | 14 | pub mod ostimer; |
| 15 | pub mod rtc; | 15 | pub mod rtc; |
| 16 | 16 | ||
| 17 | #[cfg(feature = "rt")] | ||
| 18 | pub use crate::pac::NVIC_PRIO_BITS; | ||
| 19 | |||
| 17 | #[rustfmt::skip] | 20 | #[rustfmt::skip] |
| 18 | embassy_hal_internal::peripherals!( | 21 | embassy_hal_internal::peripherals!( |
| 19 | ADC0, | 22 | ADC0, |
| @@ -83,6 +86,8 @@ embassy_hal_internal::peripherals!( | |||
| 83 | MBC0, | 86 | MBC0, |
| 84 | MRCC0, | 87 | MRCC0, |
| 85 | OPAMP0, | 88 | OPAMP0, |
| 89 | |||
| 90 | #[cfg(not(feature = "time"))] | ||
| 86 | OSTIMER0, | 91 | OSTIMER0, |
| 87 | 92 | ||
| 88 | P0_0, | 93 | P0_0, |
| @@ -335,7 +340,6 @@ pub use interrupt::InterruptExt; | |||
| 335 | pub use mcxa_pac as pac; | 340 | pub use mcxa_pac as pac; |
| 336 | #[cfg(not(feature = "unstable-pac"))] | 341 | #[cfg(not(feature = "unstable-pac"))] |
| 337 | pub(crate) use mcxa_pac as pac; | 342 | pub(crate) use mcxa_pac as pac; |
| 338 | pub use ostimer::Ostimer0 as Ostimer0Token; | ||
| 339 | pub use rtc::Rtc0 as Rtc0Token; | 343 | pub use rtc::Rtc0 as Rtc0Token; |
| 340 | 344 | ||
| 341 | /// Initialize HAL with configuration (mirrors embassy-imxrt style). Minimal: just take peripherals. | 345 | /// Initialize HAL with configuration (mirrors embassy-imxrt style). Minimal: just take peripherals. |
| @@ -343,6 +347,7 @@ pub use rtc::Rtc0 as Rtc0Token; | |||
| 343 | pub fn init(cfg: crate::config::Config) -> Peripherals { | 347 | pub fn init(cfg: crate::config::Config) -> Peripherals { |
| 344 | let peripherals = Peripherals::take(); | 348 | let peripherals = Peripherals::take(); |
| 345 | // Apply user-configured priority early; enabling is left to examples/apps | 349 | // Apply user-configured priority early; enabling is left to examples/apps |
| 350 | #[cfg(feature = "time")] | ||
| 346 | crate::interrupt::OS_EVENT.set_priority(cfg.time_interrupt_priority); | 351 | crate::interrupt::OS_EVENT.set_priority(cfg.time_interrupt_priority); |
| 347 | // Apply user-configured priority early; enabling is left to examples/apps | 352 | // Apply user-configured priority early; enabling is left to examples/apps |
| 348 | crate::interrupt::RTC.set_priority(cfg.rtc_interrupt_priority); | 353 | crate::interrupt::RTC.set_priority(cfg.rtc_interrupt_priority); |
| @@ -352,6 +357,10 @@ pub fn init(cfg: crate::config::Config) -> Peripherals { | |||
| 352 | // Configure clocks | 357 | // Configure clocks |
| 353 | crate::clocks::init(cfg.clock_cfg).unwrap(); | 358 | crate::clocks::init(cfg.clock_cfg).unwrap(); |
| 354 | 359 | ||
| 360 | // Initialize embassy-time global driver backed by OSTIMER0 | ||
| 361 | #[cfg(feature = "time")] | ||
| 362 | crate::ostimer::time_driver::init(crate::config::Config::default().time_interrupt_priority, 1_000_000); | ||
| 363 | |||
| 355 | // Enable GPIO clocks | 364 | // Enable GPIO clocks |
| 356 | unsafe { | 365 | unsafe { |
| 357 | _ = crate::clocks::enable_and_reset::<crate::peripherals::PORT0>(&crate::clocks::periph_helpers::NoConfig); | 366 | _ = crate::clocks::enable_and_reset::<crate::peripherals::PORT0>(&crate::clocks::periph_helpers::NoConfig); |
