Skip to content

Commit

Permalink
Rename 'timer_in_use' to 'try_acquire_timer' and change its usage
Browse files Browse the repository at this point in the history
  • Loading branch information
RodionovMaxim05 committed Dec 5, 2024
1 parent 3eae0b8 commit a8bc43d
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/ports/mips64/hardware_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ pub fn setup_hardware_timer() {
}
}

/// Mips64 check if timer is in use.
pub fn timer_in_use(timer_index: u8) -> bool {
/// Mips64 attempt to acquire timer.
pub fn try_acquire_timer(timer_index: u8) -> bool {
if timer_index <= 4 as u8 {
unsafe {
let timer_block = TIMER_BLOCK.take().expect("Timer block error");
Expand Down
4 changes: 2 additions & 2 deletions src/ports/mips64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ impl PortTrait for Mips64 {
}
}

fn timer_in_use(timer_index: u8) -> bool {
hardware_timer::timer_in_use(timer_index)
fn try_acquire_timer(timer_index: u8) -> bool {
hardware_timer::try_acquire_timer(timer_index)
}

fn start_hardware_timer(timer_index: u8) {
Expand Down
4 changes: 2 additions & 2 deletions src/ports/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ pub trait PortTrait {
fn setup_hardware_timer();
/// Function is used to check the correctness of index.
fn valid_timer_index(timer_index: u8) -> bool;
/// Function is used to check if the timer is in use.
fn timer_in_use(timer_index: u8) -> bool;
/// Function is called to attempt to acquire the timer.
fn try_acquire_timer(timer_index: u8) -> bool;
/// Function is called to start the timer.
fn start_hardware_timer(timer_index: u8);
/// Function is called to change the timer operating mode.
Expand Down
4 changes: 2 additions & 2 deletions src/ports/mok/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ impl PortTrait for Mok {
true
}

fn timer_in_use(_timer_index: u8) -> bool {
false
fn try_acquire_timer(_timer_index: u8) -> bool {
true
}

fn start_hardware_timer(_timer_index: u8) {
Expand Down
4 changes: 2 additions & 2 deletions src/ports/xtensa_esp32/hardware_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub fn setup_hardware_timer() {
}
}

/// Esp32 check if timer is in use.
pub fn timer_in_use() -> bool {
/// Esp32 attempt to acquire timer.
pub fn try_acquire_timer() -> bool {
match TIMER_BUSY.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed) {
Ok(_) => true,
Err(_) => false,
Expand Down
4 changes: 2 additions & 2 deletions src/ports/xtensa_esp32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ impl PortTrait for XtensaEsp32 {
true
}

fn timer_in_use(_timer_index: u8) -> bool {
hardware_timer::timer_in_use()
fn try_acquire_timer(_timer_index: u8) -> bool {
hardware_timer::try_acquire_timer()
}

fn start_hardware_timer(_timer_index: u8) {
Expand Down
4 changes: 2 additions & 2 deletions src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ impl Timer {

/// Gets the timer instance at the specified index.
/// Returns Some timer instance on success.
/// Returns None if timer in use or the specified index is invalid.
/// Returns None if timer is busy or the specified index is invalid.
pub fn get_timer(timer_index: u8) -> Option<Self> {
if Port::valid_timer_index(timer_index) && !Port::timer_in_use(timer_index) {
if Port::valid_timer_index(timer_index) && Port::try_acquire_timer(timer_index) {
Some(Self {
timer_index,
tick_counter: 0,
Expand Down

0 comments on commit a8bc43d

Please sign in to comment.