Skip to content

Commit

Permalink
Create one lock per timer group
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Sep 19, 2024
1 parent de7df0c commit a6b7999
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions esp-hal/src/timer/timg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ use crate::{
Mode,
};

static INT_ENA_LOCK: Lock = Lock::new();
const NUM_TIMG: usize = 1 + cfg!(timg1) as usize;

static INT_ENA_LOCK: [Lock; NUM_TIMG] = [const { Lock::new() }; NUM_TIMG];

/// A timer group consisting of
#[cfg_attr(not(timg_timer1), doc = "a general purpose timer")]
Expand Down Expand Up @@ -474,7 +476,7 @@ where
.config()
.modify(|_, w| w.level_int_en().set_bit());

lock(&INT_ENA_LOCK, || {
lock(&INT_ENA_LOCK[self.timer_group() as usize], || {
self.register_block()
.int_ena()
.modify(|_, w| w.t(self.timer_number()).bit(state));
Expand Down Expand Up @@ -693,15 +695,15 @@ where
.config()
.modify(|_, w| w.level_int_en().set_bit());

lock(&INT_ENA_LOCK, || {
lock(&INT_ENA_LOCK[self.timer_group() as usize], || {
self.register_block()
.int_ena()
.modify(|_, w| w.t(T).set_bit());
});
}

fn unlisten(&self) {
lock(&INT_ENA_LOCK, || {
lock(&INT_ENA_LOCK[self.timer_group() as usize], || {
self.register_block()
.int_ena()
.modify(|_, w| w.t(T).clear_bit());
Expand Down

0 comments on commit a6b7999

Please sign in to comment.