Use external, custom time function for no_std environments (#281)
* Use external, custom time function for no_std environments * fixup! Use external, custom time function for no_std environments * fixup! Use external, custom time function for no_std environments
This commit is contained in:
parent
d8ef1dd90a
commit
e7ed5be9a2
@ -46,6 +46,14 @@ fn signals_set(idx: usize) {
|
|||||||
unsafe { SIGNALS[idx] = 1 };
|
unsafe { SIGNALS[idx] = 1 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Provide custom time in no_std environment
|
||||||
|
/// Use a time provider of your choice
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn external_current_millis() -> u64 {
|
||||||
|
// TODO: use "real" time here
|
||||||
|
1000
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(clippy::similar_names)]
|
#[allow(clippy::similar_names)]
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
// The closure that we want to fuzz
|
// The closure that we want to fuzz
|
||||||
|
@ -34,13 +34,22 @@ pub fn current_time() -> time::Duration {
|
|||||||
SystemTime::now().duration_since(UNIX_EPOCH).unwrap()
|
SystemTime::now().duration_since(UNIX_EPOCH).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// external defined function in case of no_std
|
||||||
|
///
|
||||||
|
/// Define your own `external_current_millis()` function via `extern "C"`
|
||||||
|
/// which is linked into the binary and called from here.
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
extern "C" {
|
||||||
|
#[no_mangle]
|
||||||
|
fn external_current_millis() -> u64;
|
||||||
|
}
|
||||||
|
|
||||||
/// Current time (fixed fallback for no_std)
|
/// Current time (fixed fallback for no_std)
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn current_time() -> time::Duration {
|
pub fn current_time() -> time::Duration {
|
||||||
// We may not have a rt clock available.
|
let millis = unsafe { external_current_millis() };
|
||||||
// TODO: Make it somehow plugin-able
|
time::Duration::from_millis(millis)
|
||||||
time::Duration::from_millis(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets current nanoseconds since [`UNIX_EPOCH`]
|
/// Gets current nanoseconds since [`UNIX_EPOCH`]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user