diff --git a/src/main.rs b/src/main.rs index 192a884..f5a9203 100644 --- a/src/main.rs +++ b/src/main.rs @@ -119,14 +119,14 @@ fn main() -> ! { net::run(dp.ETHERNET_MAC, dp.ETHERNET_DMA, hwaddr, |iface| { Server::::run(iface, |server| { loop { - let now = timer::now().0; - let instant = Instant::from_millis(i64::from(now)); + let instant = Instant::from_millis(i64::from(timer::now())); cortex_m::interrupt::free(net::clear_pending); server.poll(instant) .unwrap_or_else(|e| { warn!("poll: {:?}", e); }); + let instant = Instant::from_millis(i64::from(timer::now())); // ADC input adc.data_ready().unwrap().map(|channel| { let data = adc.read_data().unwrap(); diff --git a/src/timer.rs b/src/timer.rs index 7d57d28..ba32712 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -1,15 +1,16 @@ use core::cell::RefCell; +use core::ops::Deref; use cortex_m::interrupt::Mutex; use cortex_m_rt::exception; use stm32f4xx_hal::{ rcc::Clocks, - time::{U32Ext, MilliSeconds}, + time::U32Ext, timer::{Timer, Event as TimerEvent}, stm32::SYST, }; /// Rate in Hz -const TIMER_RATE: u32 = 20; +const TIMER_RATE: u32 = 500; /// Interval duration in milliseconds const TIMER_DELTA: u32 = 1000 / TIMER_RATE; /// Elapsed time in milliseconds @@ -31,10 +32,10 @@ fn SysTick() { } /// Obtain current time in milliseconds -pub fn now() -> MilliSeconds { - let ms = cortex_m::interrupt::free(|cs| { +pub fn now() -> u32 { + cortex_m::interrupt::free(|cs| { *TIMER_MS.borrow(cs) .borrow() - }); - ms.ms() + .deref() + }) }