-
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.
* Move CMOS and RTC to clk module * Add timer to clk module * Move clocks to clk module * Rename uptime and realtime to boot and epoch time * Refactor module * Refactor sync functions * Return error instead of invoking the unimplemented macro in device files
- Loading branch information
Showing
45 changed files
with
472 additions
and
414 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use super::timer; | ||
|
||
use crate::api::fs::{FileIO, IO}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct BootTime; | ||
|
||
impl BootTime { | ||
pub fn new() -> Self { | ||
Self {} | ||
} | ||
|
||
pub fn size() -> usize { | ||
core::mem::size_of::<f64>() | ||
} | ||
} | ||
|
||
impl FileIO for BootTime { | ||
fn read(&mut self, buf: &mut [u8]) -> Result<usize, ()> { | ||
let time = boot_time().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, ()> { | ||
Err(()) | ||
} | ||
|
||
fn close(&mut self) {} | ||
|
||
fn poll(&mut self, event: IO) -> bool { | ||
match event { | ||
IO::Read => true, | ||
IO::Write => false, | ||
} | ||
} | ||
} | ||
|
||
/// Returns the number of seconds since boot. | ||
/// | ||
/// This clock is monotonic. | ||
pub fn boot_time() -> f64 { | ||
timer::time_between_ticks() * timer::ticks() as f64 | ||
} | ||
|
||
#[test_case] | ||
fn test_boot_time() { | ||
assert!(boot_time() > 0.0); | ||
} |
Oops, something went wrong.