mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2025-01-11 13:01:30 +11:00
implement timer counter
This commit is contained in:
parent
d4ec87b2f7
commit
04424fb7d4
|
@ -1,3 +1,24 @@
|
||||||
//! Timers
|
//! Timer Peripheral
|
||||||
// See [Chapter 4 Section 6](https://datasheets.raspberrypi.org/rp2040/rp2040_datasheet.pdf) for more details
|
// See [Chapter 4 Section 6](https://datasheets.raspberrypi.org/rp2040/rp2040_datasheet.pdf) for more details
|
||||||
// TODO
|
|
||||||
|
use crate::pac::TIMER;
|
||||||
|
|
||||||
|
/// Timer peripheral
|
||||||
|
pub struct Timer {
|
||||||
|
timer: TIMER,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Timer {
|
||||||
|
/// Create a new [`Timer`]
|
||||||
|
pub fn new(timer: TIMER) -> Self {
|
||||||
|
Self { timer }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the current counter value.
|
||||||
|
pub fn get_counter(&self) -> u64 {
|
||||||
|
// latched read, low before high
|
||||||
|
let lo = self.timer.timelr.read().bits();
|
||||||
|
let hi = self.timer.timehr.read().bits();
|
||||||
|
(hi as u64) << 32 | lo as u64
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue