From 32df88c771a7b9074e5de5db3244e8e79a35eeb5 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Fri, 24 Sep 2021 09:49:49 +0200 Subject: [PATCH] runtime: async delay instead of usual --- src/runtime/src/rtio_mgt.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/runtime/src/rtio_mgt.rs b/src/runtime/src/rtio_mgt.rs index 6baff99..cdadf79 100644 --- a/src/runtime/src/rtio_mgt.rs +++ b/src/runtime/src/rtio_mgt.rs @@ -5,7 +5,7 @@ use libboard_zynq::{timer::GlobalTimer, time::Milliseconds}; use embedded_hal::blocking::delay::DelayMs; use board_artiq::drtio_routing; use libcortex_a9::mutex::Mutex; -use libasync::task; +use libasync::{task, delay::delay}; #[cfg(has_drtio)] pub mod drtio { @@ -24,7 +24,7 @@ pub mod drtio { }); } - fn link_rx_up(linkno: u8) -> bool { + async fn link_rx_up(linkno: u8) -> bool { let linkno = linkno as usize; unsafe { (csr::DRTIO[linkno].rx_up_read)() == 1 @@ -34,7 +34,7 @@ pub mod drtio { async fn recv_aux_timeout(linkno: u8, timeout: u32, timer: GlobalTimer) -> Result { let max_time = timer.get_time() + Milliseconds(timeout); loop { - if !link_rx_up(linkno) { + if !link_rx_up(linkno).await { return Err("link went down"); } if timer.get_time() > max_time { @@ -257,7 +257,7 @@ pub mod drtio { let linkno = linkno as u8; if up_links[linkno as usize] { /* link was previously up */ - if link_rx_up(linkno) { + if link_rx_up(linkno).await { process_unsolicited_aux(aux_mutex, linkno, timer).await; process_local_errors(linkno).await; } else { @@ -266,7 +266,7 @@ pub mod drtio { } } else { /* link was previously down */ - if link_rx_up(linkno) { + if link_rx_up(linkno).await { info!("[LINK#{}] link RX became up, pinging", linkno); let ping_count = ping_remote(aux_mutex, linkno, timer).await; if ping_count > 0 { @@ -289,7 +289,8 @@ pub mod drtio { } } destination_survey(aux_mutex, routing_table, &up_links, up_destinations, timer).await; - timer.delay_ms(200); + let mut countdown = timer.countdown(); + delay(&mut countdown, Milliseconds(200)).await; } } @@ -309,7 +310,7 @@ pub mod drtio { for linkno in 0..csr::DRTIO.len() { let linkno = linkno as u8; if link_rx_up(linkno) { - let reply = task::block_on(aux_transact(io, aux_mutex, linkno, + let reply = task::block_on(aux_transact(aux_mutex, linkno, &drtioaux::Packet::ResetRequest, timer)); match reply { Ok(drtioaux::Packet::ResetAck) => (),