Skip to content

Commit

Permalink
Fix nrf
Browse files Browse the repository at this point in the history
  • Loading branch information
Finomnis committed Nov 29, 2023
1 parent d1c3618 commit 75a56f8
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 8 deletions.
40 changes: 36 additions & 4 deletions rtic-monotonics/src/nrf/rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,47 @@ macro_rules! make_rtc {
}
}

/// Used to access the underlying timer queue
#[doc(hidden)]
pub fn __tq() -> &'static TimerQueue<$mono_name> {
&$tq
}

#[inline(always)]
fn is_overflow() -> bool {
let rtc = unsafe { &*$rtc::PTR };
rtc.events_ovrflw.read().bits() == 1
}

/// Timeout at a specific time.
#[inline]
pub async fn timeout_at<F: Future>(
instant: <Self as Monotonic>::Instant,
future: F,
) -> Result<F::Output, TimeoutError> {
$tq.timeout_at(instant, future).await
}

/// Timeout after a specific duration.
#[inline]
pub async fn timeout_after<F: Future>(
duration: <Self as Monotonic>::Duration,
future: F,
) -> Result<F::Output, TimeoutError> {
$tq.timeout_after(duration, future).await
}

/// Delay for some duration of time.
#[inline]
pub async fn delay(duration: <Self as Monotonic>::Duration) {
$tq.delay(duration).await;
}

/// Delay to some specific time instant.
#[inline]
pub async fn delay_until(instant: <Self as Monotonic>::Instant) {
$tq.delay_until(instant).await;
}
}


Expand Down Expand Up @@ -196,10 +232,6 @@ macro_rules! make_rtc {
fn pend_interrupt() {
pac::NVIC::pend(Interrupt::$rtc);
}

fn __tq() -> &'static TimerQueue<$mono_name> {
&$tq
}
}
};
}
Expand Down
40 changes: 36 additions & 4 deletions rtic-monotonics/src/nrf/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,47 @@ macro_rules! make_timer {
}
}

/// Used to access the underlying timer queue
#[doc(hidden)]
pub fn __tq() -> &'static TimerQueue<$mono_name> {
&$tq
}

#[inline(always)]
fn is_overflow() -> bool {
let timer = unsafe { &*$timer::PTR };
timer.events_compare[1].read().bits() & 1 != 0
}

/// Timeout at a specific time.
#[inline]
pub async fn timeout_at<F: Future>(
instant: <Self as Monotonic>::Instant,
future: F,
) -> Result<F::Output, TimeoutError> {
$tq.timeout_at(instant, future).await
}

/// Timeout after a specific duration.
#[inline]
pub async fn timeout_after<F: Future>(
duration: <Self as Monotonic>::Duration,
future: F,
) -> Result<F::Output, TimeoutError> {
$tq.timeout_after(duration, future).await
}

/// Delay for some duration of time.
#[inline]
pub async fn delay(duration: <Self as Monotonic>::Duration) {
$tq.delay(duration).await;
}

/// Delay to some specific time instant.
#[inline]
pub async fn delay_until(instant: <Self as Monotonic>::Instant) {
$tq.delay_until(instant).await;
}
}

rtic_time::embedded_hal_delay_impl_fugit64!($mono_name);
Expand Down Expand Up @@ -232,10 +268,6 @@ macro_rules! make_timer {
fn pend_interrupt() {
pac::NVIC::pend(Interrupt::$timer);
}

fn __tq() -> &'static TimerQueue<$mono_name> {
&$tq
}
}
};
}
Expand Down

0 comments on commit 75a56f8

Please sign in to comment.