From 414cfd2fa7c682e531e49c6ae89e1e3f33bd1e2c Mon Sep 17 00:00:00 2001 From: mwojcik Date: Mon, 20 Sep 2021 14:41:15 +0200 Subject: [PATCH] * few cleanups * libcortexa9 mutex behavior understood * io.until replaced with spinlock --- src/libboard_artiq/src/lib.rs | 16 ++++------------ src/runtime/src/main.rs | 4 +--- src/runtime/src/moninj.rs | 14 +++++++------- src/runtime/src/rtio_mgt.rs | 17 +++++++++-------- 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/libboard_artiq/src/lib.rs b/src/libboard_artiq/src/lib.rs index 580ade7..bda1e71 100644 --- a/src/libboard_artiq/src/lib.rs +++ b/src/libboard_artiq/src/lib.rs @@ -12,27 +12,19 @@ extern crate libconfig; extern crate libcortex_a9; extern crate log_buffer; - -// has csr; taken from runtime main #[path = "../../../build/pl.rs"] pub mod pl; - pub mod drtioaux_proto; - +pub mod drtio_routing; +pub mod logger; +#[cfg(has_si5324)] +pub mod si5324; #[cfg(has_drtio)] pub mod drtioaux; -// for now, memory map is only needed for DRTIO firmware #[cfg(has_drtio)] #[path = "../../../build/mem.rs"] pub mod mem; -pub mod drtio_routing; - -pub mod logger; - -#[cfg(has_si5324)] -pub mod si5324; - use core::{cmp, str}; use libboard_zynq::slcr; use libregister::RegisterW; diff --git a/src/runtime/src/main.rs b/src/runtime/src/main.rs index 21cad7a..1b5561c 100644 --- a/src/runtime/src/main.rs +++ b/src/runtime/src/main.rs @@ -21,15 +21,13 @@ use void::Void; use embedded_hal::blocking::delay::DelayMs; use libconfig::Config; use libcortex_a9::l2c::enable_l2_cache; -use libboard_artiq::{logger, identifier_read, init_gateware}; +use libboard_artiq::{logger, identifier_read, init_gateware, pl}; #[cfg(has_si5324)] use libboard_artiq::si5324; mod proto_async; mod comms; mod rpc; -#[path = "../../../build/pl.rs"] -mod pl; #[cfg(ki_impl = "csr")] #[path = "rtio_csr.rs"] mod rtio; diff --git a/src/runtime/src/moninj.rs b/src/runtime/src/moninj.rs index 06b47ec..22df6cb 100644 --- a/src/runtime/src/moninj.rs +++ b/src/runtime/src/moninj.rs @@ -61,10 +61,10 @@ enum DeviceMessage { mod remote_moninj { use drtioaux; use rtio_mgt::drtio; - use sched::{Io, Mutex}; + use libcortexa9::Mutex; - pub fn read_probe(io: &Io, aux_mutex: &Mutex, linkno: u8, destination: u8, channel: u16, probe: u8) -> u32 { - let reply = drtio::aux_transact(io, aux_mutex, linkno, &drtioaux::Packet::MonitorRequest { + pub fn read_probe( aux_mutex: &Mutex, linkno: u8, destination: u8, channel: u16, probe: u8) -> u32 { + let reply = drtio::aux_transact(aux_mutex, linkno, &drtioaux::Packet::MonitorRequest { destination: destination, channel: channel, probe: probe @@ -77,8 +77,8 @@ mod remote_moninj { 0 } - pub fn inject(io: &Io, aux_mutex: &Mutex, linkno: u8, destination: u8, channel: u16, overrd: u8, value: u8) { - let _lock = aux_mutex.lock(io).unwrap(); + pub fn inject(aux_mutex: &Mutex, linkno: u8, destination: u8, channel: u16, overrd: u8, value: u8) { + let _lock = aux_mutex.lock(); drtioaux::send(linkno, &drtioaux::Packet::InjectionRequest { destination: destination, channel: channel, @@ -87,8 +87,8 @@ mod remote_moninj { }).unwrap(); } - pub fn read_injection_status(io: &Io, aux_mutex: &Mutex, linkno: u8, destination: u8, channel: u16, overrd: u8) -> u8 { - let reply = drtio::aux_transact(io, aux_mutex, linkno, &drtioaux::Packet::InjectionStatusRequest { + pub fn read_injection_status(aux_mutex: &Mutex, linkno: u8, destination: u8, channel: u16, overrd: u8) -> u8 { + let reply = drtio::aux_transact(aux_mutex, linkno, &drtioaux::Packet::InjectionStatusRequest { destination: destination, channel: channel, overrd: overrd diff --git a/src/runtime/src/rtio_mgt.rs b/src/runtime/src/rtio_mgt.rs index 1cc74b4..ce91e2d 100644 --- a/src/runtime/src/rtio_mgt.rs +++ b/src/runtime/src/rtio_mgt.rs @@ -50,7 +50,7 @@ pub mod drtio { pub fn aux_transact(aux_mutex: &Mutex, linkno: u8, request: &drtioaux::Packet, timer: GlobalTimer) -> Result { - let _lock = aux_mutex.lock().unwrap(); + let _lock = aux_mutex.lock(); drtioaux::send(linkno, request).unwrap(); recv_aux_timeout(io, linkno, 200, timer) } @@ -83,7 +83,7 @@ pub mod drtio { } fn sync_tsc(aux_mutex: &Mutex, linkno: u8, timer: GlobalTimer) -> Result<(), &'static str> { - let _lock = aux_mutex.lock().unwrap(); + let _lock = aux_mutex.lock(); unsafe { (csr::DRTIO[linkno as usize].set_time_write)(1); @@ -137,7 +137,7 @@ pub mod drtio { } fn process_unsolicited_aux(aux_mutex: &Mutex, linkno: u8) { - let _lock = aux_mutex.lock().unwrap(); + let _lock = aux_mutex.lock(); match drtioaux::recv(linkno) { Ok(Some(packet)) => warn!("[LINK#{}] unsolicited aux packet: {:?}", linkno, packet), Ok(None) => (), @@ -320,15 +320,16 @@ pub mod drtio { use super::*; pub fn startup(_aux_mutex: &Mutex, _routing_table: &Urc>, - _up_destinations: &Urc>, timer:GlobalTimer) {} - pub fn reset(_aux_mutex: &Mutex, timer: GlobalTimer) {} + _up_destinations: &Urc>, _timer:GlobalTimer) {} + pub fn reset(_aux_mutex: &Mutex, _timer: GlobalTimer) {} } -// todo figure out what to do with these untils -fn async_error_thread(io: Io) { +fn async_error_thread() { loop { unsafe { - io.until(|| csr::rtio_core::async_error_read() != 0).unwrap(); + // replaced io.until with spinlock + while csr::rtio_core::async_error_read() != 0 {} + let errors = csr::rtio_core::async_error_read(); if errors & 1 != 0 { error!("RTIO collision involving channel {}",