mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-27 14:52:10 +00:00
refactor(rust): improve time module
[no changelog]
This commit is contained in:
parent
10f3011663
commit
c72d85296d
@ -394,6 +394,7 @@ fn generate_trezorhal_bindings() {
|
|||||||
// systick
|
// systick
|
||||||
.allowlist_function("systick_delay_ms")
|
.allowlist_function("systick_delay_ms")
|
||||||
.allowlist_function("systick_ms")
|
.allowlist_function("systick_ms")
|
||||||
|
.allowlist_function("systick_us")
|
||||||
// toif
|
// toif
|
||||||
.allowlist_type("toif_format_t")
|
.allowlist_type("toif_format_t")
|
||||||
//usb
|
//usb
|
||||||
|
@ -16,7 +16,6 @@ pub mod print;
|
|||||||
pub mod qstr;
|
pub mod qstr;
|
||||||
pub mod runtime;
|
pub mod runtime;
|
||||||
pub mod simple_type;
|
pub mod simple_type;
|
||||||
pub mod time;
|
|
||||||
pub mod typ;
|
pub mod typ;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
use crate::time::Duration;
|
|
||||||
|
|
||||||
use super::ffi;
|
|
||||||
|
|
||||||
pub fn ticks_ms() -> u32 {
|
|
||||||
unsafe { ffi::mp_hal_ticks_ms() as _ }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn sleep(delay: Duration) {
|
|
||||||
unsafe { ffi::mp_hal_delay_ms(delay.to_millis() as _) }
|
|
||||||
}
|
|
@ -30,8 +30,4 @@ pub mod wordlist;
|
|||||||
|
|
||||||
pub mod secbool;
|
pub mod secbool;
|
||||||
|
|
||||||
#[cfg(not(feature = "micropython"))]
|
|
||||||
pub mod time;
|
pub mod time;
|
||||||
|
|
||||||
#[cfg(feature = "micropython")]
|
|
||||||
pub use crate::micropython::time;
|
|
||||||
|
@ -2,12 +2,28 @@ use crate::time::Duration;
|
|||||||
|
|
||||||
use super::ffi;
|
use super::ffi;
|
||||||
|
|
||||||
|
/// Returns the current time in milliseconds since the device was reset.
|
||||||
|
/// Time is represented as a 32-bit number that wraps around every 49.7 days.
|
||||||
pub fn ticks_ms() -> u32 {
|
pub fn ticks_ms() -> u32 {
|
||||||
unsafe { ffi::systick_ms() as _ }
|
unsafe { ffi::systick_ms() as _ }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the current time in microseconds since the device was reset.
|
||||||
|
/// Time is represented as a 64-bit number and never wraps around.
|
||||||
|
pub fn ticks_us() -> u64 {
|
||||||
|
unsafe { ffi::systick_us() as _ }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sleeps for the specified duration.
|
||||||
pub fn sleep(delay: Duration) {
|
pub fn sleep(delay: Duration) {
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::systick_delay_ms(delay.to_millis() as _);
|
ffi::systick_delay_ms(delay.to_millis() as _);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Measures the time it takes to execute a closure in microseconds.
|
||||||
|
pub fn measure_us(f: impl FnOnce()) -> u64 {
|
||||||
|
let start = ticks_us();
|
||||||
|
f();
|
||||||
|
ticks_us() - start
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user