create interface around the clock
This commit is contained in:
parent
96d50ab941
commit
9014c1f167
|
@ -0,0 +1,20 @@
|
||||||
|
use chrono::prelude::*;
|
||||||
|
use cmos::{CMOSCenturyHandler, CMOS};
|
||||||
|
use core::convert::TryInto;
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
use spin::Mutex;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref CLOCK: Mutex<CMOS> = Mutex::new(unsafe { CMOS::new() });
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn current_time() -> DateTime<Utc> {
|
||||||
|
let rtc = CLOCK.lock().read_rtc(CMOSCenturyHandler::CurrentYear(2019));
|
||||||
|
return Utc
|
||||||
|
.ymd(
|
||||||
|
rtc.year.try_into().unwrap(),
|
||||||
|
rtc.month.into(),
|
||||||
|
rtc.day.into(),
|
||||||
|
)
|
||||||
|
.and_hms(rtc.hour.into(), rtc.minute.into(), rtc.second.into());
|
||||||
|
}
|
|
@ -9,6 +9,7 @@
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
pub mod allocator;
|
pub mod allocator;
|
||||||
|
pub mod clock;
|
||||||
pub mod gdt;
|
pub mod gdt;
|
||||||
pub mod interrupts;
|
pub mod interrupts;
|
||||||
pub mod memory;
|
pub mod memory;
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
|
use alloc::string::ToString;
|
||||||
use bootloader::{entry_point, BootInfo};
|
use bootloader::{entry_point, BootInfo};
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
use xe_os::println;
|
use xe_os::println;
|
||||||
|
@ -13,21 +14,14 @@ use xe_os::println;
|
||||||
entry_point!(kernel_main);
|
entry_point!(kernel_main);
|
||||||
|
|
||||||
fn kernel_main(boot_info: &'static BootInfo) -> ! {
|
fn kernel_main(boot_info: &'static BootInfo) -> ! {
|
||||||
use cmos::{CMOSCenturyHandler, CMOS};
|
|
||||||
// Create a CMOS object (unsafe due to the use of port I/O)
|
|
||||||
let mut cmos = unsafe { CMOS::new() };
|
|
||||||
|
|
||||||
xe_os::init(&boot_info);
|
xe_os::init(&boot_info);
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
test_main();
|
test_main();
|
||||||
|
|
||||||
// Read the rtc date time using this year
|
// Read the rtc date time using this year
|
||||||
let rtc = cmos.read_rtc(CMOSCenturyHandler::CurrentYear(2019));
|
let now = xe_os::clock::current_time();
|
||||||
println!(
|
println!("{}", now.to_string());
|
||||||
"current time: {}:{}:{} {} M{} {}",
|
|
||||||
rtc.hour, rtc.minute, rtc.second, rtc.year, rtc.month, rtc.day
|
|
||||||
);
|
|
||||||
|
|
||||||
println!("Running WASM:");
|
println!("Running WASM:");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue