From d203f21caf91c9adc78f065a887eabc2f9e78ed8 Mon Sep 17 00:00:00 2001 From: Astro Date: Sat, 21 Mar 2020 00:46:24 +0100 Subject: [PATCH] main: re-enable interrupts also swap ADC polling and network processing to read the ADC first after an interrupt. --- src/main.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index e38006f..029c1de 100644 --- a/src/main.rs +++ b/src/main.rs @@ -99,10 +99,12 @@ fn main() -> ! { adc.setup_channel(0, ad7172::Input::Ain0, ad7172::Input::Ain1).unwrap(); adc.setup_channel(1, ad7172::Input::Ain2, ad7172::Input::Ain3).unwrap(); adc.calibrate_offset().unwrap(); + let mut dac0 = ad5680::Dac::new(pins.dac0_spi, pins.dac0_sync); dac0.set(0).unwrap(); let mut dac1 = ad5680::Dac::new(pins.dac1_spi, pins.dac1_sync); dac1.set(0).unwrap(); + let mut pwm = pins.pwm; let mut shdn0 = pins.shdn0; let mut shdn1 = pins.shdn1; @@ -125,13 +127,6 @@ fn main() -> ! { net::run(dp.ETHERNET_MAC, dp.ETHERNET_DMA, hwaddr, |iface| { Server::::run(iface, |server| { loop { - 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| { @@ -159,6 +154,13 @@ fn main() -> ! { server.for_each(|_, session| session.set_report_pending(channel.into())); }); + 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); + }); + // TCP protocol handling server.for_each(|mut socket, session| { if ! socket.is_active() { @@ -418,12 +420,13 @@ fn main() -> ! { // Update watchdog wd.feed(); - // cortex_m::interrupt::free(|cs| { - // if !net::is_pending(cs) { - // // Wait for interrupts - // wfi(); - // } - // }); + cortex_m::interrupt::free(|cs| { + if !net::is_pending(cs) { + // Wait for interrupts + // (Ethernet or SysTick) + wfi(); + } + }); } }); });