From 85e7784b91ff61c762e2e41814c2c5ee75745772 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Tue, 21 Sep 2021 11:48:59 +0200 Subject: [PATCH] runtime: restored refcells for rtio_mgt --- src/runtime/src/main.rs | 9 +++++---- src/runtime/src/rtio_mgt.rs | 36 ++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/runtime/src/main.rs b/src/runtime/src/main.rs index a5df6ad..4a51099 100644 --- a/src/runtime/src/main.rs +++ b/src/runtime/src/main.rs @@ -11,6 +11,7 @@ extern crate alloc; +use core::cell::RefCell; use log::{info, warn, error}; use libboard_zynq::{timer::GlobalTimer, mpcore, gic}; @@ -184,15 +185,15 @@ pub fn main_core0() { }; #[cfg(has_drtio)] - let drtio_routing_table = drtio_routing::config_routing_table(csr::DRTIO.len(), cfg); + let drtio_routing_table = RefCell::new(drtio_routing::config_routing_table(csr::DRTIO.len(), cfg)); #[cfg(not(has_drtio))] - let drtio_routing_table = drtio_routing::RoutingTable::default_empty(); - let up_destinations = [false; drtio_routing::DEST_COUNT]; + let drtio_routing_table = RefCell::new(drtio_routing::RoutingTable::default_empty()); + let up_destinations = RefCell::new([false; drtio_routing::DEST_COUNT]); #[cfg(has_drtio_routing)] drtio_routing::interconnect_disable_all(); #[cfg(has_drtio)] init_drtio(&mut timer); - + init_rtio(&mut timer, &cfg); task::spawn(report_async_rtio_errors()); diff --git a/src/runtime/src/rtio_mgt.rs b/src/runtime/src/rtio_mgt.rs index 0b6fc80..57d1af7 100644 --- a/src/runtime/src/rtio_mgt.rs +++ b/src/runtime/src/rtio_mgt.rs @@ -1,4 +1,4 @@ - +use core::cell::RefCell; use board_artiq::pl::csr; #[cfg(has_drtio)] use libboard_zynq::{timer::GlobalTimer, time::Milliseconds}; @@ -13,14 +13,14 @@ pub mod drtio { use drtioaux; pub fn startup(aux_mutex: &Mutex, - routing_table: drtio_routing::RoutingTable, - up_destinations: [bool; drtio_routing::DEST_COUNT]) { + routing_table: &RefCell, + up_destinations: &RefCell<[bool; drtio_routing::DEST_COUNT]>) { let aux_mutex = aux_mutex.clone(); let routing_table = routing_table.clone(); let up_destinations = up_destinations.clone(); - task::spawn( { + task::spawn( || { let routing_table = routing_table.borrow(); - link_thread(io, &aux_mutex, &routing_table, &up_destinations); + link_thread(&aux_mutex, &routing_table, &up_destinations); }); } @@ -52,7 +52,7 @@ pub mod drtio { timer: GlobalTimer) -> Result { let _lock = aux_mutex.lock(); drtioaux::send(linkno, request).unwrap(); - recv_aux_timeout(io, linkno, 200, timer) + recv_aux_timeout(linkno, 200, timer) } fn ping_remote(aux_mutex: &Mutex, linkno: u8, timer: GlobalTimer) -> u32 { @@ -65,7 +65,7 @@ pub mod drtio { if count > 100 { return 0; } - let reply = aux_transact(io, aux_mutex, linkno, &drtioaux::Packet::EchoRequest, timer); + let reply = aux_transact(aux_mutex, linkno, &drtioaux::Packet::EchoRequest, timer); match reply { Ok(drtioaux::Packet::EchoReply) => { // make sure receive buffer is drained @@ -91,7 +91,7 @@ pub mod drtio { } // TSCAck is the only aux packet that is sent spontaneously // by the satellite, in response to a TSC set on the RT link. - let reply = recv_aux_timeout(io, linkno, 10000, timer)?; + let reply = recv_aux_timeout(linkno, 10000, timer)?; if reply == drtioaux::Packet::TSCAck { return Ok(()); } else { @@ -102,7 +102,7 @@ pub mod drtio { fn load_routing_table(aux_mutex: &Mutex, linkno: u8, routing_table: &drtio_routing::RoutingTable, timer: GlobalTimer) -> Result<(), &'static str> { for i in 0..drtio_routing::DEST_COUNT { - let reply = aux_transact(io, aux_mutex, linkno, &drtioaux::Packet::RoutingSetPath { + let reply = aux_transact(aux_mutex, linkno, &drtioaux::Packet::RoutingSetPath { destination: i as u8, hops: routing_table.0[i] }, timer)?; @@ -114,7 +114,7 @@ pub mod drtio { } fn set_rank(aux_mutex: &Mutex, linkno: u8, rank: u8, timer: GlobalTimer) -> Result<(), &'static str> { - let reply = aux_transact(io, aux_mutex, linkno, &drtioaux::Packet::RoutingSetRank { + let reply = aux_transact(aux_mutex, linkno, &drtioaux::Packet::RoutingSetRank { rank: rank }, timer)?; if reply != drtioaux::Packet::RoutingAck { @@ -167,7 +167,7 @@ pub mod drtio { } fn destination_set_up(routing_table: &drtio_routing::RoutingTable, - up_destinations: [bool; drtio_routing::DEST_COUNT], + up_destinations: &RefCell<[bool; drtio_routing::DEST_COUNT]>, destination: u8, up: bool) { let mut up_destinations = up_destinations.borrow_mut(); up_destinations[destination as usize] = up; @@ -180,14 +180,14 @@ pub mod drtio { } } - fn destination_up(up_destinations: &Urc>, destination: u8) -> bool { + fn destination_up(up_destinations: &RefCell<[bool; drtio_routing::DEST_COUNT]>, destination: u8) -> bool { let up_destinations = up_destinations.borrow(); up_destinations[destination as usize] } fn destination_survey(io: &Io, aux_mutex: &Mutex, routing_table: &drtio_routing::RoutingTable, up_links: &[bool], - up_destinations: &Urc>, + up_destinations: &RefCell<[bool; drtio_routing::DEST_COUNT]>, timer: GlobalTimer) { for destination in 0..drtio_routing::DEST_COUNT { let hop = routing_table.0[destination][0]; @@ -243,7 +243,7 @@ pub mod drtio { pub fn link_thread(io: Io, aux_mutex: &Mutex, routing_table: &drtio_routing::RoutingTable, - up_destinations: &Urc>, + up_destinations: &RefCell<[bool; drtio_routing::DEST_COUNT]>, timer: GlobalTimer) { let mut up_links = [false; csr::DRTIO.len()]; loop { @@ -319,8 +319,8 @@ pub mod drtio { pub mod drtio { use super::*; - pub fn startup(_aux_mutex: &Mutex, _routing_table: &Urc>, - _up_destinations: &Urc>, _timer:GlobalTimer) {} + pub fn startup(_aux_mutex: &Mutex, _routing_table: &RefCell, + _up_destinations: &RefCell<[bool; drtio_routing::DEST_COUNT]>, _timer:GlobalTimer) {} pub fn reset(_aux_mutex: &Mutex, _timer: GlobalTimer) {} } @@ -350,8 +350,8 @@ fn async_error_thread() { } pub fn startup(aux_mutex: &Mutex, - routing_table: &Urc>, - up_destinations: &Urc>, timer: GlobalTimer) { + routing_table: &RefCell, + up_destinations: &RefCell<[bool; drtio_routing::DEST_COUNT]>, timer: GlobalTimer) { drtio::startup(aux_mutex, routing_table, up_destinations, timer); unsafe { csr::rtio_core::reset_phy_write(1);