runtime: async delay instead of usual

This commit is contained in:
mwojcik 2021-09-24 09:49:49 +02:00
parent 45b9d50e70
commit 32df88c771

View File

@ -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<drtioaux::Packet, &'static str> {
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) => (),