forked from M-Labs/thermostat
timer: increase rate to 500 Hz
timestamp precision: 0.002s
This commit is contained in:
parent
8e41c44303
commit
9c3485d05f
|
@ -119,14 +119,14 @@ fn main() -> ! {
|
|||
net::run(dp.ETHERNET_MAC, dp.ETHERNET_DMA, hwaddr, |iface| {
|
||||
Server::<Session>::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();
|
||||
|
|
13
src/timer.rs
13
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()
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue