From b8b041b51a0d9ad31c45a508337a4bd1f4158d48 Mon Sep 17 00:00:00 2001 From: Zgarbul Andrey Date: Sun, 31 Mar 2024 20:54:53 +0300 Subject: [PATCH] SOC_ETM cleanup (#1365) * SOC_ETM cleanup * changelog * review catch Co-authored-by: Scott Mabin --------- Co-authored-by: Scott Mabin --- esp-hal/CHANGELOG.md | 1 + esp-hal/Cargo.toml | 16 ++-- esp-hal/src/etm.rs | 192 ++++++++---------------------------------- esp-lp-hal/Cargo.toml | 6 +- 4 files changed, 48 insertions(+), 167 deletions(-) diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 87eac536c..c0a953646 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Update `pac`s with removed suffixes in `int` field names. Use `W1TC` for `int_clr` (#1357) MCPWM clusters (#1360) TIMG clusters (#1364) + SOC_ETM clusters (#1365) ### Removed diff --git a/esp-hal/Cargo.toml b/esp-hal/Cargo.toml index a151b5f9c..2bcc38190 100644 --- a/esp-hal/Cargo.toml +++ b/esp-hal/Cargo.toml @@ -52,14 +52,14 @@ xtensa-lx = { version = "0.9.0", optional = true } # IMPORTANT: # Each supported device MUST have its PAC included below along with a # corresponding feature. -esp32 = { git = "https://github.com/esp-rs/esp-pacs", rev = "130e7f8", features = ["critical-section"], optional = true } -esp32c2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "130e7f8", features = ["critical-section"], optional = true } -esp32c3 = { git = "https://github.com/esp-rs/esp-pacs", rev = "130e7f8", features = ["critical-section"], optional = true } -esp32c6 = { git = "https://github.com/esp-rs/esp-pacs", rev = "130e7f8", features = ["critical-section"], optional = true } -esp32h2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "130e7f8", features = ["critical-section"], optional = true } -esp32p4 = { git = "https://github.com/esp-rs/esp-pacs", rev = "130e7f8", features = ["critical-section"], optional = true } -esp32s2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "130e7f8", features = ["critical-section"], optional = true } -esp32s3 = { git = "https://github.com/esp-rs/esp-pacs", rev = "130e7f8", features = ["critical-section"], optional = true } +esp32 = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true } +esp32c2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true } +esp32c3 = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true } +esp32c6 = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true } +esp32h2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true } +esp32p4 = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true } +esp32s2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true } +esp32s3 = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true } [target.'cfg(target_arch = "riscv32")'.dependencies] esp-riscv-rt = { version = "0.7.0", optional = true, path = "../esp-riscv-rt" } diff --git a/esp-hal/src/etm.rs b/esp-hal/src/etm.rs index fc30a146f..8748c8b29 100644 --- a/esp-hal/src/etm.rs +++ b/esp-hal/src/etm.rs @@ -51,155 +51,46 @@ use crate::{ #[non_exhaustive] pub struct EtmChannel {} -macro_rules! impl_etm_channel { - ($channel: literal, $bank: literal) => { - paste::paste! { - impl EtmChannel<$channel> { - /// Setup the channel - /// - /// Enabled the channel and configures the assigned event and task. - pub fn setup<'a, E, T>(self, event: &'a E, task: &'a T) -> EtmConfiguredChannel<'a, E,T,$channel> - where - E: EtmEvent, - T: EtmTask, - { - let etm = unsafe { crate::peripherals::SOC_ETM::steal() }; +impl EtmChannel { + /// Setup the channel + /// + /// Enabled the channel and configures the assigned event and task. + pub fn setup<'a, E, T>(self, event: &'a E, task: &'a T) -> EtmConfiguredChannel<'a, E, T, C> + where + E: EtmEvent, + T: EtmTask, + { + let etm = unsafe { crate::peripherals::SOC_ETM::steal() }; - etm.[< ch $channel _evt_id >]().modify(|_, w| w.[< ch $channel _evt_id >]().variant(event.id())); - etm.[< ch $channel _task_id >]().modify(|_, w| w.[< ch $channel _task_id >]().variant(task.id())); - etm.[< ch_ena_ad $bank _set >]().write(|w| w.[< ch_set $channel >]().set_bit()); - - EtmConfiguredChannel { - _event: event, - _task: task, - } - } - } + etm.ch(C as usize) + .evt_id() + .modify(|_, w| unsafe { w.evt_id().bits(event.id()) }); + etm.ch(C as usize) + .task_id() + .modify(|_, w| unsafe { w.task_id().bits(task.id()) }); + if C < 32 { + etm.ch_ena_ad0_set().write(|w| w.ch_set(C).set_bit()); + } else { + etm.ch_ena_ad1_set().write(|w| w.ch_set(C - 32).set_bit()); } - }; + + EtmConfiguredChannel { + _event: event, + _task: task, + } + } } -impl_etm_channel!(0, 0); -impl_etm_channel!(1, 0); -impl_etm_channel!(2, 0); -impl_etm_channel!(3, 0); -impl_etm_channel!(4, 0); -impl_etm_channel!(5, 0); -impl_etm_channel!(6, 0); -impl_etm_channel!(7, 0); -impl_etm_channel!(8, 0); -impl_etm_channel!(9, 0); -impl_etm_channel!(10, 0); -impl_etm_channel!(11, 0); -impl_etm_channel!(12, 0); -impl_etm_channel!(13, 0); -impl_etm_channel!(14, 0); -impl_etm_channel!(15, 0); -impl_etm_channel!(16, 0); -impl_etm_channel!(17, 0); -impl_etm_channel!(18, 0); -impl_etm_channel!(19, 0); -impl_etm_channel!(20, 0); -impl_etm_channel!(21, 0); -impl_etm_channel!(22, 0); -impl_etm_channel!(23, 0); -impl_etm_channel!(24, 0); -impl_etm_channel!(25, 0); -impl_etm_channel!(26, 0); -impl_etm_channel!(27, 0); -impl_etm_channel!(28, 0); -impl_etm_channel!(29, 0); -impl_etm_channel!(30, 0); -impl_etm_channel!(31, 0); -impl_etm_channel!(32, 1); -impl_etm_channel!(33, 1); -impl_etm_channel!(34, 1); -impl_etm_channel!(35, 1); -impl_etm_channel!(36, 1); -impl_etm_channel!(37, 1); -impl_etm_channel!(38, 1); -impl_etm_channel!(39, 1); -impl_etm_channel!(40, 1); -impl_etm_channel!(41, 1); -impl_etm_channel!(42, 1); -impl_etm_channel!(43, 1); -impl_etm_channel!(44, 1); -impl_etm_channel!(45, 1); -impl_etm_channel!(46, 1); -impl_etm_channel!(47, 1); -impl_etm_channel!(48, 1); -impl_etm_channel!(49, 1); - -macro_rules! impl_disable_helper { - ($(($channel:literal, $bank:literal)),+) => { - paste::paste! { - fn disable_channel(channel: u8) { - let etm = unsafe { crate::peripherals::SOC_ETM::steal() }; - match channel { - $( - $channel => {etm.[< ch_ena_ad $bank _clr>]().write(|w| w.[< ch_clr $channel >]().set_bit());}, - )+ - _ => panic!("Unknown channel {}", channel), - } - - } - } - }; +fn disable_channel(channel: u8) { + let etm = unsafe { crate::peripherals::SOC_ETM::steal() }; + if channel < 32 { + etm.ch_ena_ad0_clr().write(|w| w.ch_clr(channel).set_bit()); + } else { + etm.ch_ena_ad1_clr() + .write(|w| w.ch_clr(channel - 32).set_bit()); + } } -impl_disable_helper!( - (0, 0), - (1, 0), - (2, 0), - (3, 0), - (4, 0), - (5, 0), - (6, 0), - (7, 0), - (8, 0), - (9, 0), - (10, 0), - (11, 0), - (12, 0), - (13, 0), - (14, 0), - (15, 0), - (16, 0), - (17, 0), - (18, 0), - (19, 0), - (20, 0), - (21, 0), - (22, 0), - (23, 0), - (24, 0), - (25, 0), - (26, 0), - (27, 0), - (28, 0), - (29, 0), - (30, 0), - (31, 0), - (32, 1), - (33, 1), - (34, 1), - (35, 1), - (36, 1), - (37, 1), - (38, 1), - (39, 1), - (40, 1), - (41, 1), - (42, 1), - (43, 1), - (44, 1), - (45, 1), - (46, 1), - (47, 1), - (48, 1), - (49, 1) -); - /// A readily configured channel /// /// The channel is enabled and event and task are configured. @@ -224,7 +115,7 @@ where } } -macro_rules! create_etm_struct { +macro_rules! create_etm { ($($num:literal),+) => { paste::paste! { /// ETM Instance @@ -234,13 +125,7 @@ macro_rules! create_etm_struct { _peripheral: PeripheralRef<'d, crate::peripherals::SOC_ETM>, $(pub [< channel $num >]: EtmChannel<$num>,)+ } - } - }; -} -macro_rules! create_etm_constructor { - ($($num:literal),+) => { - paste::paste! { impl<'d> Etm<'d> { pub fn new(peripheral: impl Peripheral

+ 'd) -> Self { crate::into_ref!(peripheral); @@ -257,12 +142,7 @@ macro_rules! create_etm_constructor { }; } -create_etm_struct!( - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, - 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49 -); - -create_etm_constructor!( +create_etm!( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49 ); diff --git a/esp-lp-hal/Cargo.toml b/esp-lp-hal/Cargo.toml index a4c51ca2a..4bde78770 100644 --- a/esp-lp-hal/Cargo.toml +++ b/esp-lp-hal/Cargo.toml @@ -24,9 +24,9 @@ categories = [ cfg-if = "1.0.0" embedded-hal-02 = { version = "0.2.7", package = "embedded-hal", optional = true, features = ["unproven"] } embedded-hal-1 = { version = "1.0.0", package = "embedded-hal", optional = true } -esp32c6-lp = { git = "https://github.com/esp-rs/esp-pacs", rev = "130e7f8", features = ["critical-section"], optional = true } -esp32s2-ulp = { git = "https://github.com/esp-rs/esp-pacs", rev = "130e7f8", features = ["critical-section"], optional = true } -esp32s3-ulp = { git = "https://github.com/esp-rs/esp-pacs", rev = "130e7f8", features = ["critical-section"], optional = true } +esp32c6-lp = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true } +esp32s2-ulp = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true } +esp32s3-ulp = { git = "https://github.com/esp-rs/esp-pacs", rev = "efd414c", features = ["critical-section"], optional = true } nb = { version = "1.1.0", optional = true } paste = { version = "1.0.14", optional = true } procmacros = { package = "esp-hal-procmacros", path = "../esp-hal-procmacros" }