diff --git a/doc/lisp.md b/doc/lisp.md index 98370150..509bf092 100644 --- a/doc/lisp.md +++ b/doc/lisp.md @@ -79,7 +79,7 @@ MOROS Lisp is a Lisp-1 dialect inspired by Scheme, Clojure, and Ruby! - `read`, `write`, `append` - `read-binary`, `write-binary`, `append-binary` - `read-line`, `read-char` -- `uptime`, `realtime` +- `clock/boot`, `clock/epoch` - `p`, `print`, `eprint`, `error` ### Math Library @@ -176,6 +176,7 @@ Would produce the following output: ### Unreleased - Add `dirname`, `filename`, `eprint`, and `error` functions +- Rename `uptime` to `clk/boot` and `realtime` to `clk/epoch` ### 0.7.1 (2024-06-20) - Add `floor`, `ceil`, and `round` functions diff --git a/doc/manual.md b/doc/manual.md index 182c071d..6ad1caf1 100644 --- a/doc/manual.md +++ b/doc/manual.md @@ -85,9 +85,9 @@ commands to test the system or `install` to setup the Created '/dev/ata/1/0' Created '/dev/ata/1/1' Created '/dev/clk' - Created '/dev/clk/uptime' - Created '/dev/clk/realtime' - Created '/dev/rtc' + Created '/dev/clk/boot' + Created '/dev/clk/epoch' + Created '/dev/clk/rtc' Created '/dev/null' Created '/dev/random' Created '/dev/console' @@ -270,7 +270,7 @@ You can print the date with `date`: You can update the real time clock by writing the correct time to its device file: - > print "2023-03-21 10:00:00" => /dev/rtc + > print "2023-03-21 10:00:00" => /dev/clk/rtc > date 2023-03-21 10:00:00 +0000 @@ -297,12 +297,12 @@ Add `env TZ 7200` to `/ini/boot.sh` before `shell` to save the timezone: There's a device file to get the number of seconds elapsed since Unix Epoch: - > read /dev/clk/realtime + > read /dev/clk/epoch 1682105344.624905 And another one since boot: - > read /dev/clk/uptime + > read /dev/clk/boot 1169.384929 ## Aliases @@ -312,7 +312,7 @@ You can add custom commands to the shell with the `alias` command. For example you can define an `uptime` command that will read the device file described above: - > alias uptime "read /dev/clk/uptime" + > alias uptime "read /dev/clk/boot" > uptime 1406.304852 @@ -377,5 +377,5 @@ There is also a `ntp` script to synchronize the clock over the network: > ntp 2023-03-21 10:00:00 - > ntp => /dev/rtc + > ntp => /dev/clk/rtc [12.111156] RTC 2023-03-21 10:00:00 +0000 diff --git a/doc/network.md b/doc/network.md index 221b0bba..c4906ab0 100644 --- a/doc/network.md +++ b/doc/network.md @@ -163,5 +163,5 @@ passed as an argument or defined in `/ini/ntp`: It can be used to synchronize the real-time clock (RTC): - > ntp => /dev/rtc + > ntp => /dev/clk/rtc [42.123456] RTC 2023-03-21 10:00:00 +0000 diff --git a/dsk/lib/lisp/file.lsp b/dsk/lib/lisp/file.lsp index 0fa6f1ee..bac39f98 100644 --- a/dsk/lib/lisp/file.lsp +++ b/dsk/lib/lisp/file.lsp @@ -75,13 +75,13 @@ # Clocks -(def (uptime) - "Returns the current value of the uptime clock" - (binary->number (read-binary "/dev/clk/uptime") "float")) +(def (clock/boot) + "Returns the number of seconds since boot" + (binary->number (read-binary "/dev/clk/boot") "float")) -(def (realtime) - "Returns the current value of the realtime clock" - (binary->number (read-binary "/dev/clk/realtime") "float")) +(def (clock/epoch) + "Returns the number of seconds since epoch" + (binary->number (read-binary "/dev/clk/epoch") "float")) # Path diff --git a/dsk/tmp/lisp/geotime.lsp b/dsk/tmp/lisp/geotime.lsp index 72e89467..a4cd4863 100644 --- a/dsk/tmp/lisp/geotime.lsp +++ b/dsk/tmp/lisp/geotime.lsp @@ -32,7 +32,7 @@ (print (if (= (len args) 1) - (geotime (str->num (first args)) (realtime)) + (geotime (str->num (first args)) (clk/epoch)) (if (= (len args) 2) (geotime (str->num (first args)) (str->num (second args))) "Usage: geotime []"))) diff --git a/src/api/clock.rs b/src/api/clock.rs index f84bac50..6d7ba833 100644 --- a/src/api/clock.rs +++ b/src/api/clock.rs @@ -18,10 +18,10 @@ fn read_float(path: &str) -> f64 { 0.0 } -pub fn uptime() -> f64 { - read_float("/dev/clk/uptime") +pub fn boot_time() -> f64 { + read_float("/dev/clk/boot") } -pub fn realtime() -> f64 { - read_float("/dev/clk/realtime") +pub fn epoch_time() -> f64 { + read_float("/dev/clk/epoch") } diff --git a/src/api/fs.rs b/src/api/fs.rs index 0841f900..3cf255a8 100644 --- a/src/api/fs.rs +++ b/src/api/fs.rs @@ -161,9 +161,9 @@ fn device_type(name: &str) -> Result { "file" => Ok(DeviceType::File), "console" => Ok(DeviceType::Console), "random" => Ok(DeviceType::Random), - "uptime" => Ok(DeviceType::Uptime), - "realtime" => Ok(DeviceType::Realtime), - "rtc" => Ok(DeviceType::RTC), + "clk-boot" => Ok(DeviceType::BootTime), + "clk-epoch" => Ok(DeviceType::EpochTime), + "clk-rtc" => Ok(DeviceType::RTC), "tcp" => Ok(DeviceType::TcpSocket), "udp" => Ok(DeviceType::UdpSocket), "vga-buffer" => Ok(DeviceType::VgaBuffer), diff --git a/src/api/time.rs b/src/api/time.rs index 9f9b133c..63a01926 100644 --- a/src/api/time.rs +++ b/src/api/time.rs @@ -8,7 +8,7 @@ pub fn now() -> OffsetDateTime { } pub fn now_utc() -> OffsetDateTime { - let s = clock::realtime(); // Since Unix Epoch + let s = clock::epoch_time(); // Since Unix Epoch let ns = Duration::nanoseconds( libm::floor(1e9 * (s - libm::floor(s))) as i64 ); diff --git a/src/bin/geocal.rs b/src/bin/geocal.rs index 775075d6..6c2aec5b 100644 --- a/src/bin/geocal.rs +++ b/src/bin/geocal.rs @@ -37,7 +37,7 @@ fn main(args: &[&str]) { let timestamp = if args.len() == 4 { args[3].parse().unwrap() } else { - clock::realtime() as i64 + clock::epoch_time() as i64 }; let week; diff --git a/src/bin/geodate.rs b/src/bin/geodate.rs index 10aa70e8..ae74b509 100644 --- a/src/bin/geodate.rs +++ b/src/bin/geodate.rs @@ -21,7 +21,7 @@ fn main(args: &[&str]) { let timestamp = if args.len() == 3 { args[2].parse().expect("Could not parse timestamp") } else { - clock::realtime() + clock::epoch_time() }; let t = geodate::get_formatted_date(format, timestamp as i64, longitude); diff --git a/src/sys/ata.rs b/src/sys/ata.rs index 6fe63835..56d4fb5f 100644 --- a/src/sys/ata.rs +++ b/src/sys/ata.rs @@ -132,9 +132,9 @@ impl Bus { } fn poll(&mut self, bit: Status, val: bool) -> Result<(), ()> { - let start = sys::clk::uptime(); + let start = sys::clk::boot_time(); while self.status().get_bit(bit as usize) != val { - if sys::clk::uptime() - start > 1.0 { + if sys::clk::boot_time() - start > 1.0 { debug!( "ATA hanged while polling {:?} bit in status register", bit diff --git a/src/sys/clk/boot.rs b/src/sys/clk/boot.rs index 9119b98f..ab2c52ab 100644 --- a/src/sys/clk/boot.rs +++ b/src/sys/clk/boot.rs @@ -1,9 +1,9 @@ use crate::api::fs::{FileIO, IO}; #[derive(Debug, Clone)] -pub struct Uptime; +pub struct BootTime; -impl Uptime { +impl BootTime { pub fn new() -> Self { Self {} } @@ -13,9 +13,9 @@ impl Uptime { } } -impl FileIO for Uptime { +impl FileIO for BootTime { fn read(&mut self, buf: &mut [u8]) -> Result { - let time = uptime().to_be_bytes(); + let time = boot_time().to_be_bytes(); let n = time.len(); if buf.len() >= n { buf[0..n].clone_from_slice(&time); @@ -40,11 +40,11 @@ impl FileIO for Uptime { } // NOTE: This clock is monotonic -pub fn uptime() -> f64 { +pub fn boot_time() -> f64 { super::time_between_ticks() * super::ticks() as f64 } #[test_case] -fn test_uptime() { - assert!(uptime() > 0.0); +fn test_boot_time() { + assert!(boot_time() > 0.0); } diff --git a/src/sys/clk/epoch.rs b/src/sys/clk/epoch.rs index cd2823b7..c0798591 100644 --- a/src/sys/clk/epoch.rs +++ b/src/sys/clk/epoch.rs @@ -7,9 +7,9 @@ const DAYS_BEFORE_MONTH: [u64; 13] = [ ]; #[derive(Debug, Clone)] -pub struct Realtime; +pub struct EpochTime; -impl Realtime { +impl EpochTime { pub fn new() -> Self { Self {} } @@ -19,9 +19,9 @@ impl Realtime { } } -impl FileIO for Realtime { +impl FileIO for EpochTime { fn read(&mut self, buf: &mut [u8]) -> Result { - let time = realtime().to_be_bytes(); + let time = epoch_time().to_be_bytes(); let n = time.len(); if buf.len() >= n { buf[0..n].clone_from_slice(&time); @@ -46,7 +46,7 @@ impl FileIO for Realtime { } // NOTE: This clock is not monotonic -pub fn realtime() -> f64 { +pub fn epoch_time() -> f64 { let rtc = CMOS::new().rtc(); // Assuming GMT let ts = 86400 * days_before_year(rtc.year as u64) @@ -86,6 +86,6 @@ fn is_leap_year(year: u64) -> bool { } #[test_case] -fn test_realtime() { - assert!(realtime() > 1234567890.0); +fn test_epoch_time() { + assert!(epoch_time() > 1234567890.0); } diff --git a/src/sys/clk/mod.rs b/src/sys/clk/mod.rs index d2ed8a2b..827b9a60 100644 --- a/src/sys/clk/mod.rs +++ b/src/sys/clk/mod.rs @@ -5,8 +5,8 @@ mod rtc; mod sleep; mod timer; -pub use boot::{uptime, Uptime}; // TODO: Rename to boot_time -pub use epoch::{realtime, Realtime}; // TODO: Rename to epoch_time +pub use boot::{boot_time, BootTime}; // TODO: Rename to boot_time +pub use epoch::{epoch_time, EpochTime}; // TODO: Rename to epoch_time pub use cmos::CMOS; pub use rtc::RTC; pub use sleep::{sleep, nanowait, halt}; @@ -27,7 +27,7 @@ pub fn init() { } pub fn log_rtc() { - let s = realtime(); + let s = epoch_time(); let ns = Duration::nanoseconds( libm::floor(1e9 * (s - libm::floor(s))) as i64 ); diff --git a/src/sys/clk/sleep.rs b/src/sys/clk/sleep.rs index 0ea69772..86b708ad 100644 --- a/src/sys/clk/sleep.rs +++ b/src/sys/clk/sleep.rs @@ -12,8 +12,8 @@ pub fn halt() { } pub fn sleep(seconds: f64) { - let start = sys::clk::uptime(); - while sys::clk::uptime() - start < seconds { + let start = sys::clk::boot_time(); + while sys::clk::boot_time() - start < seconds { halt(); } } diff --git a/src/sys/fs/device.rs b/src/sys/fs/device.rs index ba9111ec..888a7607 100644 --- a/src/sys/fs/device.rs +++ b/src/sys/fs/device.rs @@ -4,7 +4,7 @@ use super::file::File; use super::{dirname, filename, realpath, FileIO, IO}; use crate::sys::ata::Drive; -use crate::sys::clk::{RTC, Realtime, Uptime}; +use crate::sys::clk::{RTC, EpochTime, BootTime}; use crate::sys::console::Console; use crate::sys::net::socket::tcp::TcpSocket; use crate::sys::net::socket::udp::UdpSocket; @@ -23,8 +23,8 @@ pub enum DeviceType { File = 1, Console = 2, Random = 3, - Uptime = 4, - Realtime = 5, + BootTime = 4, + EpochTime = 5, RTC = 6, TcpSocket = 7, UdpSocket = 8, @@ -44,8 +44,8 @@ impl TryFrom<&[u8]> for DeviceType { 1 => Ok(DeviceType::File), 2 => Ok(DeviceType::Console), 3 => Ok(DeviceType::Random), - 4 => Ok(DeviceType::Uptime), - 5 => Ok(DeviceType::Realtime), + 4 => Ok(DeviceType::BootTime), + 5 => Ok(DeviceType::EpochTime), 6 => Ok(DeviceType::RTC), 7 => Ok(DeviceType::TcpSocket), 8 => Ok(DeviceType::UdpSocket), @@ -66,8 +66,8 @@ impl DeviceType { pub fn buf(self) -> Vec { let len = match self { DeviceType::RTC => RTC::size(), - DeviceType::Uptime => Uptime::size(), - DeviceType::Realtime => Realtime::size(), + DeviceType::BootTime => BootTime::size(), + DeviceType::EpochTime => EpochTime::size(), DeviceType::Console => Console::size(), DeviceType::TcpSocket => TcpSocket::size(), DeviceType::UdpSocket => UdpSocket::size(), @@ -89,8 +89,8 @@ pub enum Device { File(File), Console(Console), Random(Random), - Uptime(Uptime), - Realtime(Realtime), + BootTime(BootTime), + EpochTime(EpochTime), RTC(RTC), TcpSocket(TcpSocket), UdpSocket(UdpSocket), @@ -110,8 +110,8 @@ impl TryFrom<&[u8]> for Device { DeviceType::File => Ok(Device::File(File::new())), DeviceType::Console => Ok(Device::Console(Console::new())), DeviceType::Random => Ok(Device::Random(Random::new())), - DeviceType::Uptime => Ok(Device::Uptime(Uptime::new())), - DeviceType::Realtime => Ok(Device::Realtime(Realtime::new())), + DeviceType::BootTime => Ok(Device::BootTime(BootTime::new())), + DeviceType::EpochTime => Ok(Device::EpochTime(EpochTime::new())), DeviceType::RTC => Ok(Device::RTC(RTC::new())), DeviceType::TcpSocket => Ok(Device::TcpSocket(TcpSocket::new())), DeviceType::UdpSocket => Ok(Device::UdpSocket(UdpSocket::new())), @@ -172,8 +172,8 @@ impl FileIO for Device { Device::File(io) => io.read(buf), Device::Console(io) => io.read(buf), Device::Random(io) => io.read(buf), - Device::Uptime(io) => io.read(buf), - Device::Realtime(io) => io.read(buf), + Device::BootTime(io) => io.read(buf), + Device::EpochTime(io) => io.read(buf), Device::RTC(io) => io.read(buf), Device::TcpSocket(io) => io.read(buf), Device::UdpSocket(io) => io.read(buf), @@ -191,8 +191,8 @@ impl FileIO for Device { Device::File(io) => io.write(buf), Device::Console(io) => io.write(buf), Device::Random(io) => io.write(buf), - Device::Uptime(io) => io.write(buf), - Device::Realtime(io) => io.write(buf), + Device::BootTime(io) => io.write(buf), + Device::EpochTime(io) => io.write(buf), Device::RTC(io) => io.write(buf), Device::TcpSocket(io) => io.write(buf), Device::UdpSocket(io) => io.write(buf), @@ -210,8 +210,8 @@ impl FileIO for Device { Device::File(io) => io.close(), Device::Console(io) => io.close(), Device::Random(io) => io.close(), - Device::Uptime(io) => io.close(), - Device::Realtime(io) => io.close(), + Device::BootTime(io) => io.close(), + Device::EpochTime(io) => io.close(), Device::RTC(io) => io.close(), Device::TcpSocket(io) => io.close(), Device::UdpSocket(io) => io.close(), @@ -229,8 +229,8 @@ impl FileIO for Device { Device::File(io) => io.poll(event), Device::Console(io) => io.poll(event), Device::Random(io) => io.poll(event), - Device::Uptime(io) => io.poll(event), - Device::Realtime(io) => io.poll(event), + Device::BootTime(io) => io.poll(event), + Device::EpochTime(io) => io.poll(event), Device::RTC(io) => io.poll(event), Device::TcpSocket(io) => io.poll(event), Device::UdpSocket(io) => io.poll(event), diff --git a/src/sys/fs/dir.rs b/src/sys/fs/dir.rs index a556c9e1..a90a997b 100644 --- a/src/sys/fs/dir.rs +++ b/src/sys/fs/dir.rs @@ -135,7 +135,7 @@ impl Dir { let entry_kind = kind as u8; let entry_addr = entry_block.addr(); let entry_size = 0u32; - let entry_time = sys::clk::realtime() as u64; + let entry_time = sys::clk::epoch_time() as u64; let entry_name = truncate(name, u8::MAX as usize); let n = entry_name.len(); let i = entries.block_offset(); @@ -193,7 +193,7 @@ impl Dir { } pub fn update_entry(&self, name: &str, size: u32) { - let time = sys::clk::realtime() as u64; + let time = sys::clk::epoch_time() as u64; let mut entries = self.entries(); for entry in &mut entries { if entry.name() == name { diff --git a/src/sys/mod.rs b/src/sys/mod.rs index 48ea590b..233c9638 100644 --- a/src/sys/mod.rs +++ b/src/sys/mod.rs @@ -20,18 +20,18 @@ macro_rules! debug { macro_rules! log { ($($arg:tt)*) => ({ if !cfg!(test) { - let uptime = $crate::sys::clk::uptime(); + let time = $crate::sys::clk::boot_time(); let csi_color = $crate::api::console::Style::color("lime"); let csi_reset = $crate::api::console::Style::reset(); $crate::sys::console::print_fmt(format_args!( "{}[{:.6}]{} {}\n", - csi_color, uptime, csi_reset, format_args!($($arg)*) + csi_color, time, csi_reset, format_args!($($arg)*) )); - let realtime = $crate::sys::clk::realtime(); + let time = $crate::sys::clk::epoch_time(); $crate::sys::log::write_fmt(format_args!( "[{:.6}] {}\n", - realtime, format_args!($($arg)*) + time, format_args!($($arg)*) )); } }); diff --git a/src/sys/net/mod.rs b/src/sys/net/mod.rs index 17c8d2b6..e4a26e75 100644 --- a/src/sys/net/mod.rs +++ b/src/sys/net/mod.rs @@ -28,7 +28,7 @@ pub enum SocketStatus { } fn time() -> Instant { - Instant::from_micros((sys::clk::realtime() * 1000000.0) as i64) + Instant::from_micros((sys::clk::epoch_time() * 1000000.0) as i64) } #[derive(Clone)] diff --git a/src/sys/net/socket/tcp.rs b/src/sys/net/socket/tcp.rs index d4019d11..55118577 100644 --- a/src/sys/net/socket/tcp.rs +++ b/src/sys/net/socket/tcp.rs @@ -56,10 +56,10 @@ impl TcpSocket { pub fn connect(&mut self, addr: IpAddress, port: u16) -> Result<(), ()> { let mut connecting = false; let timeout = 5.0; - let started = sys::clk::realtime(); + let started = sys::clk::epoch_time(); if let Some((ref mut iface, ref mut device)) = *sys::net::NET.lock() { loop { - if sys::clk::realtime() - started > timeout { + if sys::clk::epoch_time() - started > timeout { return Err(()); } let mut sockets = SOCKETS.lock(); @@ -119,10 +119,10 @@ impl TcpSocket { pub fn accept(&mut self) -> Result { let timeout = 5.0; - let started = sys::clk::realtime(); + let started = sys::clk::epoch_time(); if let Some((ref mut iface, ref mut device)) = *sys::net::NET.lock() { loop { - if sys::clk::realtime() - started > timeout { + if sys::clk::epoch_time() - started > timeout { return Err(()); } let mut sockets = SOCKETS.lock(); @@ -147,12 +147,12 @@ impl TcpSocket { impl FileIO for TcpSocket { fn read(&mut self, buf: &mut [u8]) -> Result { let timeout = 5.0; - let started = sys::clk::realtime(); + let started = sys::clk::epoch_time(); let mut bytes = 0; if let Some((ref mut iface, ref mut device)) = *sys::net::NET.lock() { let mut sockets = SOCKETS.lock(); loop { - if sys::clk::realtime() - started > timeout { + if sys::clk::epoch_time() - started > timeout { return Err(()); } iface.poll(sys::net::time(), device, &mut sockets); @@ -184,12 +184,12 @@ impl FileIO for TcpSocket { fn write(&mut self, buf: &[u8]) -> Result { let timeout = 5.0; - let started = sys::clk::realtime(); + let started = sys::clk::epoch_time(); let mut sent = false; if let Some((ref mut iface, ref mut device)) = *sys::net::NET.lock() { let mut sockets = SOCKETS.lock(); loop { - if sys::clk::realtime() - started > timeout { + if sys::clk::epoch_time() - started > timeout { return Err(()); } iface.poll(sys::net::time(), device, &mut sockets); diff --git a/src/sys/net/socket/udp.rs b/src/sys/net/socket/udp.rs index 41da3780..0573c65c 100644 --- a/src/sys/net/socket/udp.rs +++ b/src/sys/net/socket/udp.rs @@ -60,10 +60,10 @@ impl UdpSocket { pub fn connect(&mut self, addr: IpAddress, port: u16) -> Result<(), ()> { let timeout = 5.0; - let started = sys::clk::realtime(); + let started = sys::clk::epoch_time(); if let Some((ref mut iface, ref mut device)) = *sys::net::NET.lock() { loop { - if sys::clk::realtime() - started > timeout { + if sys::clk::epoch_time() - started > timeout { return Err(()); } let mut sockets = SOCKETS.lock(); @@ -98,12 +98,12 @@ impl UdpSocket { impl FileIO for UdpSocket { fn read(&mut self, buf: &mut [u8]) -> Result { let timeout = 5.0; - let started = sys::clk::realtime(); + let started = sys::clk::epoch_time(); if let Some((ref mut iface, ref mut device)) = *sys::net::NET.lock() { let bytes; let mut sockets = SOCKETS.lock(); loop { - if sys::clk::realtime() - started > timeout { + if sys::clk::epoch_time() - started > timeout { return Err(()); } iface.poll(sys::net::time(), device, &mut sockets); @@ -132,12 +132,12 @@ impl FileIO for UdpSocket { fn write(&mut self, buf: &[u8]) -> Result { let timeout = 5.0; - let started = sys::clk::realtime(); + let started = sys::clk::epoch_time(); let mut sent = false; if let Some((ref mut iface, ref mut device)) = *sys::net::NET.lock() { let mut sockets = SOCKETS.lock(); loop { - if sys::clk::realtime() - started > timeout { + if sys::clk::epoch_time() - started > timeout { return Err(()); } iface.poll(sys::net::time(), device, &mut sockets); diff --git a/src/sys/rng.rs b/src/sys/rng.rs index 25c88b88..d4fb29d9 100644 --- a/src/sys/rng.rs +++ b/src/sys/rng.rs @@ -82,8 +82,8 @@ pub fn init() { log!("RNG RDRAND unavailable"); let mut hasher = Sha256::new(); hasher.update(sys::clk::ticks().to_be_bytes()); - hasher.update(sys::clk::realtime().to_be_bytes()); - hasher.update(sys::clk::uptime().to_be_bytes()); + hasher.update(sys::clk::epoch_time().to_be_bytes()); + hasher.update(sys::clk::boot_time().to_be_bytes()); seed = hasher.finalize().into(); } diff --git a/src/usr/chess.rs b/src/usr/chess.rs index f8082055..2782e85b 100644 --- a/src/usr/chess.rs +++ b/src/usr/chess.rs @@ -53,7 +53,7 @@ fn update_autocomplete(prompt: &mut Prompt, game: &mut Game) { } fn system_time() -> u128 { - (api::clock::realtime() * 1000.0) as u128 + (api::clock::epoch_time() * 1000.0) as u128 } struct Chess { diff --git a/src/usr/dhcp.rs b/src/usr/dhcp.rs index 0be39fe3..3c90a4f8 100644 --- a/src/usr/dhcp.rs +++ b/src/usr/dhcp.rs @@ -34,9 +34,9 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> { debug!("DHCP Discover transmitted"); } let timeout = 30.0; - let started = clock::realtime(); + let started = clock::epoch_time(); loop { - if clock::realtime() - started > timeout { + if clock::epoch_time() - started > timeout { error!("Timeout reached"); return Err(ExitCode::Failure); } @@ -45,7 +45,7 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> { return Err(ExitCode::Failure); } - let ms = (clock::realtime() * 1000000.0) as i64; + let ms = (clock::epoch_time() * 1000000.0) as i64; let time = Instant::from_micros(ms); iface.poll(time, device, &mut sockets); let event = sockets.get_mut::(dhcp_handle).poll(); diff --git a/src/usr/geodate.rs b/src/usr/geodate.rs index 3ba8d38c..e5445f59 100644 --- a/src/usr/geodate.rs +++ b/src/usr/geodate.rs @@ -15,7 +15,7 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> { let timestamp = if args.len() == 3 { args[2].parse().expect("Could not parse timestamp") } else { - clock::realtime() + clock::epoch_time() }; let t = geodate::get_formatted_date(format, timestamp as i64, longitude); diff --git a/src/usr/httpd.rs b/src/usr/httpd.rs index 7270d01c..a0406375 100644 --- a/src/usr/httpd.rs +++ b/src/usr/httpd.rs @@ -368,7 +368,7 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> { return Ok(()); } - let ms = (clock::realtime() * 1000000.0) as i64; + let ms = (clock::epoch_time() * 1000000.0) as i64; let time = Instant::from_micros(ms); iface.poll(time, device, &mut sockets); diff --git a/src/usr/install.rs b/src/usr/install.rs index 43d58bac..d199f05e 100644 --- a/src/usr/install.rs +++ b/src/usr/install.rs @@ -54,9 +54,9 @@ pub fn copy_files(verbose: bool) { create_dev("/dev/ata/0/1", "ata-0-1", verbose); create_dev("/dev/ata/1/0", "ata-1-0", verbose); create_dev("/dev/ata/1/1", "ata-1-1", verbose); - create_dev("/dev/clk/uptime", "uptime", verbose); - create_dev("/dev/clk/realtime", "realtime", verbose); - create_dev("/dev/rtc", "rtc", verbose); + create_dev("/dev/clk/boot", "clk-boot", verbose); + create_dev("/dev/clk/epoch", "clk-epoch", verbose); + create_dev("/dev/clk/rtc", "clk-rtc", verbose); create_dev("/dev/null", "null", verbose); create_dev("/dev/random", "random", verbose); create_dev("/dev/console", "console", verbose); diff --git a/src/usr/net.rs b/src/usr/net.rs index cfab61dd..2a91542d 100644 --- a/src/usr/net.rs +++ b/src/usr/net.rs @@ -275,7 +275,7 @@ fn monitor() { } syscall::sleep(0.1); - let ms = (clock::realtime() * 1000000.0) as i64; + let ms = (clock::epoch_time() * 1000000.0) as i64; let time = Instant::from_micros(ms); iface.poll(time, device, &mut sockets); let socket = sockets.get_mut::(tcp_handle); diff --git a/src/usr/time.rs b/src/usr/time.rs index 5d0b9b8f..616d1151 100644 --- a/src/usr/time.rs +++ b/src/usr/time.rs @@ -7,9 +7,9 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> { let csi_color = Style::color("blue"); let csi_reset = Style::reset(); let cmd = args[1..].join(" "); - let start = clock::realtime(); + let start = clock::epoch_time(); let res = usr::shell::exec(&cmd); - let duration = clock::realtime() - start; + let duration = clock::epoch_time() - start; eprintln!( "{}Executed '{}' in {:.6}s{}", csi_color, cmd, duration, csi_reset diff --git a/www/lisp.html b/www/lisp.html index 08e21e65..89e1f3d6 100644 --- a/www/lisp.html +++ b/www/lisp.html @@ -104,7 +104,7 @@

File Library

  • read, write, append
  • read-binary, write-binary, append-binary
  • read-line, read-char
  • -
  • uptime, realtime
  • +
  • clock/boot, clock/epoch
  • p, print, eprint, error
  • @@ -205,6 +205,7 @@

    Unreleased

    • Add dirname, filename, eprint, and error functions
    • +
    • Rename uptime to clk/boot and realtime to clk/epoch

    0.7.1 (2024-06-20)

    diff --git a/www/manual.html b/www/manual.html index 68d440c4..babe01f2 100644 --- a/www/manual.html +++ b/www/manual.html @@ -94,9 +94,9 @@

    Installation

    Created '/dev/ata/1/0' Created '/dev/ata/1/1' Created '/dev/clk' -Created '/dev/clk/uptime' -Created '/dev/clk/realtime' -Created '/dev/rtc' +Created '/dev/clk/boot' +Created '/dev/clk/epoch' +Created '/dev/clk/rtc' Created '/dev/null' Created '/dev/random' Created '/dev/console' @@ -290,7 +290,7 @@

    Time

    You can update the real time clock by writing the correct time to its device file:

    -
    > print "2023-03-21 10:00:00" => /dev/rtc
    +    
    > print "2023-03-21 10:00:00" => /dev/clk/rtc
     
     > date
     2023-03-21 10:00:00 +0000
    @@ -320,13 +320,13 @@ 

    Time

    There's a device file to get the number of seconds elapsed since Unix Epoch:

    -
    > read /dev/clk/realtime
    +    
    > read /dev/clk/epoch
     1682105344.624905
     

    And another one since boot:

    -
    > read /dev/clk/uptime
    +    
    > read /dev/clk/boot
     1169.384929
     
    @@ -337,7 +337,7 @@

    Aliases

    For example you can define an uptime command that will read the device file described above:

    -
    > alias uptime "read /dev/clk/uptime"
    +    
    > alias uptime "read /dev/clk/boot"
     
     > uptime
     1406.304852
    @@ -407,7 +407,7 @@ 

    Network

    > ntp
     2023-03-21 10:00:00
     
    -> ntp => /dev/rtc
    +> ntp => /dev/clk/rtc
     [12.111156] RTC 2023-03-21 10:00:00 +0000
     
    diff --git a/www/network.html b/www/network.html index 73e0c199..3cd7a81e 100644 --- a/www/network.html +++ b/www/network.html @@ -188,7 +188,7 @@

    NTP

    It can be used to synchronize the real-time clock (RTC):

    -
    > ntp => /dev/rtc
    +    
    > ntp => /dev/clk/rtc
     [42.123456] RTC 2023-03-21 10:00:00 +0000