diff options
| author | Bob McWhirter <[email protected]> | 2021-07-12 15:48:26 -0400 |
|---|---|---|
| committer | Bob McWhirter <[email protected]> | 2021-07-13 10:09:35 -0400 |
| commit | 2e10ab2e5c330d7b55f5d7f24379ccd48b6a8b1b (patch) | |
| tree | a1482104e7b22c0220af07608952628d9f5233a1 | |
| parent | b0b61d99e69980d8c30923148d32c3f7aa50fcc0 (diff) | |
Let's count channels per DMA peripheral, shall we now?
| -rw-r--r-- | embassy-stm32/src/bdma/mod.rs | 2 | ||||
| -rw-r--r-- | stm32-metapac-gen/src/lib.rs | 25 |
2 files changed, 24 insertions, 3 deletions
diff --git a/embassy-stm32/src/bdma/mod.rs b/embassy-stm32/src/bdma/mod.rs index b4da79285..d62feb5b9 100644 --- a/embassy-stm32/src/bdma/mod.rs +++ b/embassy-stm32/src/bdma/mod.rs | |||
| @@ -152,7 +152,7 @@ unsafe fn on_irq() { | |||
| 152 | pac::$dma.ifcr().write_value(isr); | 152 | pac::$dma.ifcr().write_value(isr); |
| 153 | let dman = <crate::peripherals::$dma as sealed::Dma>::num() as usize; | 153 | let dman = <crate::peripherals::$dma as sealed::Dma>::num() as usize; |
| 154 | 154 | ||
| 155 | for chn in 0..7 { | 155 | for chn in 0..crate::pac::dma_channels_count!($dma) { |
| 156 | let n = dman * 8 + chn; | 156 | let n = dman * 8 + chn; |
| 157 | if isr.teif(chn) { | 157 | if isr.teif(chn) { |
| 158 | STATE.ch_status[n].store(CH_STATUS_ERROR, Ordering::Relaxed); | 158 | STATE.ch_status[n].store(CH_STATUS_ERROR, Ordering::Relaxed); |
diff --git a/stm32-metapac-gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs index 640d746e1..e7e3382f9 100644 --- a/stm32-metapac-gen/src/lib.rs +++ b/stm32-metapac-gen/src/lib.rs | |||
| @@ -141,6 +141,21 @@ macro_rules! peripheral_count {{ | |||
| 141 | write!(out, " }}\n").unwrap(); | 141 | write!(out, " }}\n").unwrap(); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | fn make_dma_channel_counts(out: &mut String, data: &HashMap<String, u8>) { | ||
| 145 | write!(out, | ||
| 146 | "#[macro_export] | ||
| 147 | macro_rules! dma_channels_count {{ | ||
| 148 | ").unwrap(); | ||
| 149 | for (name, count) in data { | ||
| 150 | write!(out, | ||
| 151 | "({}) => ({});\n", | ||
| 152 | name, count, | ||
| 153 | ).unwrap(); | ||
| 154 | } | ||
| 155 | write!(out, | ||
| 156 | " }}\n").unwrap(); | ||
| 157 | } | ||
| 158 | |||
| 144 | fn make_table(out: &mut String, name: &str, data: &Vec<Vec<String>>) { | 159 | fn make_table(out: &mut String, name: &str, data: &Vec<Vec<String>>) { |
| 145 | write!( | 160 | write!( |
| 146 | out, | 161 | out, |
| @@ -256,6 +271,7 @@ pub fn gen(options: Options) { | |||
| 256 | let mut dma_requests_table: Vec<Vec<String>> = Vec::new(); | 271 | let mut dma_requests_table: Vec<Vec<String>> = Vec::new(); |
| 257 | let mut peripheral_dma_channels_table: Vec<Vec<String>> = Vec::new(); | 272 | let mut peripheral_dma_channels_table: Vec<Vec<String>> = Vec::new(); |
| 258 | let mut peripheral_counts: HashMap<String, u8> = HashMap::new(); | 273 | let mut peripheral_counts: HashMap<String, u8> = HashMap::new(); |
| 274 | let mut dma_channel_counts: HashMap<String, u8> = HashMap::new(); | ||
| 259 | 275 | ||
| 260 | let dma_base = core | 276 | let dma_base = core |
| 261 | .peripherals | 277 | .peripherals |
| @@ -267,8 +283,6 @@ pub fn gen(options: Options) { | |||
| 267 | let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address; | 283 | let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address; |
| 268 | let gpio_stride = 0x400; | 284 | let gpio_stride = 0x400; |
| 269 | 285 | ||
| 270 | |||
| 271 | |||
| 272 | let number_suffix_re = Regex::new("^(.*?)[0-9]*$").unwrap(); | 286 | let number_suffix_re = Regex::new("^(.*?)[0-9]*$").unwrap(); |
| 273 | 287 | ||
| 274 | for (name, p) in &core.peripherals { | 288 | for (name, p) in &core.peripherals { |
| @@ -460,6 +474,12 @@ pub fn gen(options: Options) { | |||
| 460 | } | 474 | } |
| 461 | } | 475 | } |
| 462 | } | 476 | } |
| 477 | |||
| 478 | let dma_peri_name = channel_info.dma.clone(); | ||
| 479 | dma_channel_counts.insert( | ||
| 480 | dma_peri_name.clone(), | ||
| 481 | dma_channel_counts.get(&dma_peri_name).map_or(1, |v| v + 1), | ||
| 482 | ); | ||
| 463 | } | 483 | } |
| 464 | 484 | ||
| 465 | for (name, &num) in &core.interrupts { | 485 | for (name, &num) in &core.interrupts { |
| @@ -511,6 +531,7 @@ pub fn gen(options: Options) { | |||
| 511 | make_table(&mut extra, "bdma_channels", &bdma_channels_table); | 531 | make_table(&mut extra, "bdma_channels", &bdma_channels_table); |
| 512 | make_table(&mut extra, "dma_requests", &dma_requests_table); | 532 | make_table(&mut extra, "dma_requests", &dma_requests_table); |
| 513 | make_peripheral_counts(&mut extra, &peripheral_counts); | 533 | make_peripheral_counts(&mut extra, &peripheral_counts); |
| 534 | make_dma_channel_counts(&mut extra, &dma_channel_counts); | ||
| 514 | 535 | ||
| 515 | for (module, version) in peripheral_versions { | 536 | for (module, version) in peripheral_versions { |
| 516 | all_peripheral_versions.insert((module.clone(), version.clone())); | 537 | all_peripheral_versions.insert((module.clone(), version.clone())); |
