Add missing TIM for time-driver; reorder time-driver selection when use "time-drvier-any".

This commit is contained in:
eZio Pan 2024-02-14 17:17:27 +08:00
parent 63d592c7b0
commit bbe1eebc53
2 changed files with 73 additions and 34 deletions

View File

@ -183,40 +183,33 @@ fn main() {
let time_driver_singleton = match time_driver.as_ref().map(|x| x.as_ref()) { let time_driver_singleton = match time_driver.as_ref().map(|x| x.as_ref()) {
None => "", None => "",
Some("tim1") => "TIM1",
Some("tim2") => "TIM2", Some("tim2") => "TIM2",
Some("tim3") => "TIM3", Some("tim3") => "TIM3",
Some("tim4") => "TIM4", Some("tim4") => "TIM4",
Some("tim5") => "TIM5", Some("tim5") => "TIM5",
Some("tim8") => "TIM8",
Some("tim9") => "TIM9", Some("tim9") => "TIM9",
Some("tim11") => "TIM11",
Some("tim12") => "TIM12", Some("tim12") => "TIM12",
Some("tim15") => "TIM15", Some("tim15") => "TIM15",
Some("tim20") => "TIM20",
Some("tim21") => "TIM21", Some("tim21") => "TIM21",
Some("tim22") => "TIM22", Some("tim22") => "TIM22",
Some("tim23") => "TIM23",
Some("tim24") => "TIM24",
Some("any") => { Some("any") => {
if singletons.contains(&"TIM2".to_string()) { // Order of TIM candidators:
"TIM2" // 1. 2CH -> 2CH_CMP -> GP16 -> GP32 -> ADV
} else if singletons.contains(&"TIM3".to_string()) { // 2. In same catagory: larger TIM number first
"TIM3" [
} else if singletons.contains(&"TIM4".to_string()) { "TIM22", "TIM21", "TIM12", "TIM9", // 2CH
"TIM4" "TIM15", // 2CH_CMP
} else if singletons.contains(&"TIM5".to_string()) { "TIM19", "TIM4", "TIM3", // GP16
"TIM5" "TIM24", "TIM23", "TIM5", "TIM2", // GP32
} else if singletons.contains(&"TIM9".to_string()) { "TIM20", "TIM8", "TIM1", //ADV
"TIM9" ]
} else if singletons.contains(&"TIM11".to_string()) { .iter()
"TIM11" .find(|tim| singletons.contains(&tim.to_string())).expect("time-driver-any requested, but the chip doesn't have TIM1, TIM2, TIM3, TIM4, TIM5, TIM8, TIM9, TIM12, TIM15, TIM20, TIM21, TIM22, TIM23 or TIM24.")
} else if singletons.contains(&"TIM12".to_string()) {
"TIM12"
} else if singletons.contains(&"TIM15".to_string()) {
"TIM15"
} else if singletons.contains(&"TIM21".to_string()) {
"TIM21"
} else if singletons.contains(&"TIM22".to_string()) {
"TIM22"
} else {
panic!("time-driver-any requested, but the chip doesn't have TIM2, TIM3, TIM4, TIM5, TIM9, TIM11, TIM12 or TIM15.")
}
} }
_ => panic!("unknown time_driver {:?}", time_driver), _ => panic!("unknown time_driver {:?}", time_driver),
}; };

View File

@ -1,3 +1,5 @@
#![allow(non_snake_case)]
use core::cell::Cell; use core::cell::Cell;
use core::convert::TryInto; use core::convert::TryInto;
use core::sync::atomic::{compiler_fence, AtomicU32, AtomicU8, Ordering}; use core::sync::atomic::{compiler_fence, AtomicU32, AtomicU8, Ordering};
@ -22,18 +24,22 @@ use crate::{interrupt, peripherals};
// As of 2023-12-04, this driver is implemented using CC1 as the halfway rollover interrupt, and any // As of 2023-12-04, this driver is implemented using CC1 as the halfway rollover interrupt, and any
// additional CC capabilities to provide timer alarms to embassy-time. embassy-time requires AT LEAST // additional CC capabilities to provide timer alarms to embassy-time. embassy-time requires AT LEAST
// one alarm to be allocatable, which means timers that only have CC1, such as TIM16/TIM17, are not // one alarm to be allocatable, which means timers that only have CC1, such as TIM16/TIM17, are not
// candidates for use as an embassy-time driver provider. // candidates for use as an embassy-time driver provider. (a.k.a 1CH and 1CH_CMP are not, others are good.)
// //
// The values of ALARM_COUNT below are not the TOTAL CC registers available, but rather the number // The values of ALARM_COUNT below are not the TOTAL CC registers available, but rather the number
// available after reserving CC1 for regular time keeping. For example, TIM2 has four CC registers: // available after reserving CC1 for regular time keeping. For example, TIM2 has four CC registers:
// CC1, CC2, CC3, and CC4, so it can provide ALARM_COUNT = 3. // CC1, CC2, CC3, and CC4, so it can provide ALARM_COUNT = 3.
#[cfg(not(any(time_driver_tim12, time_driver_tim15, time_driver_tim21, time_driver_tim22)))] cfg_if::cfg_if! {
const ALARM_COUNT: usize = 3; if #[cfg(any(time_driver_tim9, time_driver_tim12, time_driver_tim15, time_driver_tim21, time_driver_tim22))] {
#[cfg(any(time_driver_tim12, time_driver_tim15, time_driver_tim21, time_driver_tim22))]
const ALARM_COUNT: usize = 1; const ALARM_COUNT: usize = 1;
} else {
const ALARM_COUNT: usize = 3;
}
}
#[cfg(time_drvier_tim1)]
type T = peripherals::TIM1;
#[cfg(time_driver_tim2)] #[cfg(time_driver_tim2)]
type T = peripherals::TIM2; type T = peripherals::TIM2;
#[cfg(time_driver_tim3)] #[cfg(time_driver_tim3)]
@ -42,6 +48,8 @@ type T = peripherals::TIM3;
type T = peripherals::TIM4; type T = peripherals::TIM4;
#[cfg(time_driver_tim5)] #[cfg(time_driver_tim5)]
type T = peripherals::TIM5; type T = peripherals::TIM5;
#[cfg(time_driver_tim8)]
type T = peripherals::TIM8;
#[cfg(time_driver_tim9)] #[cfg(time_driver_tim9)]
type T = peripherals::TIM9; type T = peripherals::TIM9;
#[cfg(time_driver_tim11)] #[cfg(time_driver_tim11)]
@ -50,12 +58,26 @@ type T = peripherals::TIM11;
type T = peripherals::TIM12; type T = peripherals::TIM12;
#[cfg(time_driver_tim15)] #[cfg(time_driver_tim15)]
type T = peripherals::TIM15; type T = peripherals::TIM15;
#[cfg(time_driver_tim20)]
type T = peripherals::TIM20;
#[cfg(time_driver_tim21)] #[cfg(time_driver_tim21)]
type T = peripherals::TIM21; type T = peripherals::TIM21;
#[cfg(time_driver_tim22)] #[cfg(time_driver_tim22)]
type T = peripherals::TIM22; type T = peripherals::TIM22;
#[cfg(time_driver_tim23)]
type T = peripherals::TIM23;
#[cfg(time_driver_tim24)]
type T = peripherals::TIM24;
foreach_interrupt! { foreach_interrupt! {
(TIM1, timer, $block:ident, UP, $irq:ident) => {
#[cfg(time_driver_tim1)]
#[cfg(feature = "rt")]
#[interrupt]
fn $irq() {
DRIVER.on_interrupt()
}
};
(TIM2, timer, $block:ident, UP, $irq:ident) => { (TIM2, timer, $block:ident, UP, $irq:ident) => {
#[cfg(time_driver_tim2)] #[cfg(time_driver_tim2)]
#[cfg(feature = "rt")] #[cfg(feature = "rt")]
@ -88,16 +110,16 @@ foreach_interrupt! {
DRIVER.on_interrupt() DRIVER.on_interrupt()
} }
}; };
(TIM9, timer, $block:ident, UP, $irq:ident) => { (TIM8, timer, $block:ident, UP, $irq:ident) => {
#[cfg(time_driver_tim9)] #[cfg(time_driver_tim8)]
#[cfg(feature = "rt")] #[cfg(feature = "rt")]
#[interrupt] #[interrupt]
fn $irq() { fn $irq() {
DRIVER.on_interrupt() DRIVER.on_interrupt()
} }
}; };
(TIM11, timer, $block:ident, UP, $irq:ident) => { (TIM9, timer, $block:ident, UP, $irq:ident) => {
#[cfg(time_driver_tim11)] #[cfg(time_driver_tim9)]
#[cfg(feature = "rt")] #[cfg(feature = "rt")]
#[interrupt] #[interrupt]
fn $irq() { fn $irq() {
@ -120,6 +142,14 @@ foreach_interrupt! {
DRIVER.on_interrupt() DRIVER.on_interrupt()
} }
}; };
(TIM20, timer, $block:ident, UP, $irq:ident) => {
#[cfg(time_driver_tim20)]
#[cfg(feature = "rt")]
#[interrupt]
fn $irq() {
DRIVER.on_interrupt()
}
};
(TIM21, timer, $block:ident, UP, $irq:ident) => { (TIM21, timer, $block:ident, UP, $irq:ident) => {
#[cfg(time_driver_tim21)] #[cfg(time_driver_tim21)]
#[cfg(feature = "rt")] #[cfg(feature = "rt")]
@ -136,6 +166,22 @@ foreach_interrupt! {
DRIVER.on_interrupt() DRIVER.on_interrupt()
} }
}; };
(TIM23, timer, $block:ident, UP, $irq:ident) => {
#[cfg(time_driver_tim23)]
#[cfg(feature = "rt")]
#[interrupt]
fn $irq() {
DRIVER.on_interrupt()
}
};
(TIM24, timer, $block:ident, UP, $irq:ident) => {
#[cfg(time_driver_tim24)]
#[cfg(feature = "rt")]
#[interrupt]
fn $irq() {
DRIVER.on_interrupt()
}
};
} }
// Clock timekeeping works with something we call "periods", which are time intervals // Clock timekeeping works with something we call "periods", which are time intervals