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