-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
101 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use crate::api::fs::{FileIO, IO}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Uptime; | ||
|
||
impl Uptime { | ||
pub fn new() -> Self { | ||
Self {} | ||
} | ||
|
||
pub fn size() -> usize { | ||
core::mem::size_of::<f64>() | ||
} | ||
} | ||
|
||
impl FileIO for Uptime { | ||
fn read(&mut self, buf: &mut [u8]) -> Result<usize, ()> { | ||
let time = uptime().to_be_bytes(); | ||
let n = time.len(); | ||
if buf.len() >= n { | ||
buf[0..n].clone_from_slice(&time); | ||
Ok(n) | ||
} else { | ||
Err(()) | ||
} | ||
} | ||
|
||
fn write(&mut self, _buf: &[u8]) -> Result<usize, ()> { | ||
unimplemented!(); | ||
} | ||
|
||
fn close(&mut self) {} | ||
|
||
fn poll(&mut self, event: IO) -> bool { | ||
match event { | ||
IO::Read => true, | ||
IO::Write => false, | ||
} | ||
} | ||
} | ||
|
||
// NOTE: This clock is monotonic | ||
pub fn uptime() -> f64 { | ||
super::time_between_ticks() * super::ticks() as f64 | ||
} | ||
|
||
#[test_case] | ||
fn test_uptime() { | ||
assert!(uptime() > 0.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters