Skip to content

Commit 597d259

Browse files
authored
Merge pull request #166 from thejpster/freestanding-timer-read
Add free-standing functions to get the current time.
2 parents fd1c625 + 7ffcdcb commit 597d259

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

  • aarch32-cpu/src/generic_timer

aarch32-cpu/src/generic_timer/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,30 @@ pub trait GenericTimer {
9999
}
100100
}
101101

102+
/// A free-standing function to get the current Physical Timer value
103+
///
104+
/// In some circumstances (e.g. timestamping a defmt log) you just want to get
105+
/// the time and don't want to drag around an object representing the whole
106+
/// timer.
107+
///
108+
/// This is just a thin wrapper around the relevant CPU register's read function
109+
/// - this just has a more discoverable name.
110+
pub fn read_physical_timer() -> u64 {
111+
crate::register::CntPct::read().0
112+
}
113+
114+
/// A free-standing function to get the current Virtual Timer value
115+
///
116+
/// In some circumstances (e.g. timestamping a defmt log) you just want to get
117+
/// the time and don't want to drag around an object representing the whole
118+
/// timer.
119+
///
120+
/// This is just a thin wrapper around the relevant CPU register's read function
121+
/// - this just has a more discoverable name.
122+
pub fn read_virtual_timer() -> u64 {
123+
crate::register::CntVct::read().0
124+
}
125+
102126
/// Describes the configuration for an Edvent
103127
#[derive(Debug, Clone, PartialEq, Eq)]
104128
pub struct EventConfig {

0 commit comments

Comments
 (0)