From c8decc85c22f2d1ee48f6daa0f8dece4d3bdc5aa Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 10 Oct 2021 02:20:01 +0800 Subject: [PATCH] std::time doesn't exist, make a wrapper around Ticktimer for smoltcp --- services/net/src/main.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/services/net/src/main.rs b/services/net/src/main.rs index 16f8f2535..d95c6bfb6 100644 --- a/services/net/src/main.rs +++ b/services/net/src/main.rs @@ -71,6 +71,20 @@ where }); } +struct SmoltcpTimer { + ticktimer: ticktimer_server::Ticktimer, +} +impl SmoltcpTimer { + pub fn new() -> Self { + SmoltcpTimer { + ticktimer: ticktimer_server::Ticktimer::new().unwrap(), + } + } + pub fn now(&self) -> Instant { + Instant::from_millis(self.ticktimer.elapsed_ms() as i64) + } +} + #[xous::xous_main] fn xmain() -> ! { log_server::init_wait().unwrap(); @@ -126,6 +140,7 @@ fn xmain() -> ! { let timeout = Duration::from_secs(10); // link storage + let timer = SmoltcpTimer::new(); let neighbor_cache = NeighborCache::new(BTreeMap::new()); let mut routes_storage = [None; 1]; let routes = Routes::new(&mut routes_storage[..]); @@ -200,7 +215,7 @@ fn xmain() -> ! { // now fire off the smoltcp receive machine.... { - let timestamp = Instant::now(); + let timestamp = timer.now(); match iface.poll(&mut sockets, timestamp) { Ok(_) => {} Err(e) => { @@ -208,7 +223,7 @@ fn xmain() -> ! { } } { - let timestamp = Instant::now(); + let timestamp = timer.now(); let mut socket = sockets.get::(icmp_handle); if !socket.is_open() { socket.bind(IcmpEndpoint::Ident(ident)).unwrap();