From 5168b83158e912fbfbe8416957e00d3f4a16e6e9 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 6 Apr 2020 22:33:15 +0800 Subject: [PATCH] drtio: make sure receive buffer is drained after ping reply --- artiq/firmware/runtime/rtio_mgt.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/artiq/firmware/runtime/rtio_mgt.rs b/artiq/firmware/runtime/rtio_mgt.rs index 10ac429c6..825900b78 100644 --- a/artiq/firmware/runtime/rtio_mgt.rs +++ b/artiq/firmware/runtime/rtio_mgt.rs @@ -68,7 +68,17 @@ pub mod drtio { } let reply = aux_transact(io, aux_mutex, linkno, &drtioaux::Packet::EchoRequest); match reply { - Ok(drtioaux::Packet::EchoReply) => return count, + Ok(drtioaux::Packet::EchoReply) => { + // make sure receive buffer is drained + let max_time = clock::get_ms() + 200; + loop { + if clock::get_ms() > max_time { + return count; + } + let _ = drtioaux::recv(linkno); + io.relinquish().unwrap(); + } + } _ => {} } io.relinquish().unwrap();