From 0502737481b271a96b8d0baad28f487a51050789 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Fri, 23 Jul 2021 13:15:07 +0200 Subject: [PATCH] satman: replaced clock with GlobalTimer completely --- src/libboard_artiq/drtioaux.rs | 8 +++--- src/satman/main.rs | 24 +++++++++--------- src/satman/repeater.rs | 45 ++++++++++++++++++---------------- 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/src/libboard_artiq/drtioaux.rs b/src/libboard_artiq/drtioaux.rs index c0abd4c6..e2bf32f5 100644 --- a/src/libboard_artiq/drtioaux.rs +++ b/src/libboard_artiq/drtioaux.rs @@ -2,11 +2,13 @@ use core::slice; use crc; use io::{ProtoRead, ProtoWrite, Cursor, Error as IoError}; -use board_misoc::{csr::DRTIOAUX, mem::DRTIOAUX_MEM}; // <- port -use proto_artiq::drtioaux_proto::Error as ProtocolError; +//use board_misoc::{mem::DRTIOAUX_MEM}; // <- port +//^ uses generated files (like csr, but mem) - todo check after initial generation +use pl::csr::DRTIOAUX; +use drtioaux_proto::Error as ProtocolError; use libboard_zynq::{timer::GlobalTimer, time::Milliseconds}; -pub use proto_artiq::drtioaux_proto::Packet; +pub use drtioaux_proto::Packet; // this is parametric over T because there's no impl Fail for !. #[derive(Fail, Debug)] diff --git a/src/satman/main.rs b/src/satman/main.rs index ad097eb9..57d65a00 100644 --- a/src/satman/main.rs +++ b/src/satman/main.rs @@ -5,12 +5,12 @@ extern crate log; use core::convert::TryFrom; -use board_misoc::{csr, irq, ident, clock, i2c}; // <- port, use libboard_zynq +use board_misoc::{csr, irq, ident, i2c}; // <- port, use libboard_zynq use libboard_zynq::timer::GlobalTimer; #[cfg(has_si5324)] -use libboard_artiqzynq::si5324; +use libboard_artiq::si5324; use board_artiq::spi; // <- port?, use libboard_zynq (if spi available/necessary) -use libboard_artiqzynq::{drtio_routing, drtioaux, logger}; +use libboard_artiq::{drtio_routing, drtioaux, logger}; mod repeater; @@ -357,11 +357,11 @@ fn drtiosat_process_errors() { #[cfg(has_rtio_crg)] -fn init_rtio_crg() { +fn init_rtio_crg(timer: GlobalTimer) { unsafe { csr::rtio_crg::pll_reset_write(0); } - clock::spin_us(150); + timer.delay_us(150); let locked = unsafe { csr::rtio_crg::pll_locked_read() != 0 }; if !locked { error!("RTIO clock failed"); @@ -369,13 +369,11 @@ fn init_rtio_crg() { } #[cfg(not(has_rtio_crg))] -fn init_rtio_crg() { } +fn init_rtio_crg(timer: GlobalTimer) { } -fn hardware_tick(ts: &mut u64) { - let now = clock::get_ms(); +fn hardware_tick(ts: &mut u64, timer: GlobalTimer) { + let now = timer.get_time(); if now > *ts { - #[cfg(has_grabber)] - board_artiq::grabber::tick(); *ts = now + 200; } } @@ -476,7 +474,7 @@ pub extern fn main() -> i32 { while !drtiosat_link_rx_up() { drtiosat_process_errors(); for mut rep in repeaters.iter_mut() { - rep.service(&routing_table, rank); + rep.service(&routing_table, rank, timer); } #[cfg(all(soc_platform = "kasli", hw_rev = "v2.0"))] { @@ -508,11 +506,11 @@ pub extern fn main() -> i32 { io_expander0.service().expect("I2C I/O expander #0 service failed"); io_expander1.service().expect("I2C I/O expander #1 service failed"); } - hardware_tick(&mut hardware_tick_ts); + hardware_tick(&mut hardware_tick_ts, timer); if drtiosat_tsc_loaded() { info!("TSC loaded from uplink"); for rep in repeaters.iter() { - if let Err(e) = rep.sync_tsc() { + if let Err(e) = rep.sync_tsc(timer) { error!("failed to sync TSC ({})", e); } } diff --git a/src/satman/repeater.rs b/src/satman/repeater.rs index 193511cd..82a716b6 100644 --- a/src/satman/repeater.rs +++ b/src/satman/repeater.rs @@ -1,6 +1,8 @@ -use board_artiqzynq::{drtioaux, drtio_routing}; +use libboard_artiq::{drtioaux, drtio_routing}; #[cfg(has_drtio_routing)] -use board_artiqzynq::{pl::csr, clock}; +use libboard_artiq::{pl::csr}; +#[cfg(has_drtio_routing)] +use libboard_zynq::timer::{GlobalTimer, Milliseconds}; #[cfg(has_drtio_routing)] fn rep_link_rx_up(repno: u8) -> bool { @@ -48,7 +50,8 @@ impl Repeater { self.state == RepeaterState::Up } - pub fn service(&mut self, routing_table: &drtio_routing::RoutingTable, rank: u8) { + pub fn service(&mut self, routing_table: &drtio_routing::RoutingTable, rank: u8, + timer: GlobalTimer) { self.process_local_errors(); match self.state { @@ -63,7 +66,7 @@ impl Repeater { drtioaux::send(self.auxno, &drtioaux::Packet::EchoRequest).unwrap(); self.state = RepeaterState::WaitPingReply { ping_count: ping_count + 1, - timeout: clock::get_ms() + 100 + timeout: timer.get_time() + Milliseconds(100) } } else { error!("[REP#{}] link RX went down during ping", self.repno); @@ -91,7 +94,7 @@ impl Repeater { return; } } else { - if clock::get_ms() > timeout { + if timer.get_time() > timeout { if ping_count > 200 { error!("[REP#{}] ping failed", self.repno); self.state = RepeaterState::Failed; @@ -162,13 +165,13 @@ impl Repeater { } } - fn recv_aux_timeout(&self, timeout: u32) -> Result> { - let max_time = clock::get_ms() + timeout as u64; + fn recv_aux_timeout(&self, timeout: u32, timer: GlobalTimer) -> Result> { + let max_time = timer.get_time() + timeout as u64; loop { if !rep_link_rx_up(self.repno) { return Err(drtioaux::Error::LinkDown); } - if clock::get_ms() > max_time { + if timer.get_time() > max_time { return Err(drtioaux::Error::TimedOut); } match drtioaux::recv(self.auxno) { @@ -179,17 +182,17 @@ impl Repeater { } } - pub fn aux_forward(&self, request: &drtioaux::Packet) -> Result<(), drtioaux::Error> { + pub fn aux_forward(&self, request: &drtioaux::Packet, timer: GlobalTimer) -> Result<(), drtioaux::Error> { if self.state != RepeaterState::Up { return Err(drtioaux::Error::LinkDown); } drtioaux::send(self.auxno, request).unwrap(); - let reply = self.recv_aux_timeout(200)?; + let reply = self.recv_aux_timeout(200, timer)?; drtioaux::send(0, &reply).unwrap(); Ok(()) } - pub fn sync_tsc(&self) -> Result<(), drtioaux::Error> { + pub fn sync_tsc(&self, timer: GlobalTimer) -> Result<(), drtioaux::Error> { if self.state != RepeaterState::Up { return Ok(()); } @@ -202,7 +205,7 @@ impl Repeater { // 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 = self.recv_aux_timeout(10000)?; + let reply = self.recv_aux_timeout(10000, timer)?; if reply == drtioaux::Packet::TSCAck { return Ok(()); } else { @@ -210,7 +213,7 @@ impl Repeater { } } - pub fn set_path(&self, destination: u8, hops: &[u8; drtio_routing::MAX_HOPS]) -> Result<(), drtioaux::Error> { + pub fn set_path(&self, destination: u8, hops: &[u8; drtio_routing::MAX_HOPS], timer: GlobalTimer) -> Result<(), drtioaux::Error> { if self.state != RepeaterState::Up { return Ok(()); } @@ -219,7 +222,7 @@ impl Repeater { destination: destination, hops: *hops }).unwrap(); - let reply = self.recv_aux_timeout(200)?; + let reply = self.recv_aux_timeout(200, timer)?; if reply != drtioaux::Packet::RoutingAck { return Err(drtioaux::Error::UnexpectedReply); } @@ -233,24 +236,24 @@ impl Repeater { Ok(()) } - pub fn set_rank(&self, rank: u8) -> Result<(), drtioaux::Error> { + pub fn set_rank(&self, rank: u8, timer: GlobalTimer) -> Result<(), drtioaux::Error> { if self.state != RepeaterState::Up { return Ok(()); } drtioaux::send(self.auxno, &drtioaux::Packet::RoutingSetRank { rank: rank }).unwrap(); - let reply = self.recv_aux_timeout(200)?; + let reply = self.recv_aux_timeout(200, timer)?; if reply != drtioaux::Packet::RoutingAck { return Err(drtioaux::Error::UnexpectedReply); } Ok(()) } - pub fn rtio_reset(&self) -> Result<(), drtioaux::Error> { + pub fn rtio_reset(&self, timer: GlobalTimer) -> Result<(), drtioaux::Error> { let repno = self.repno as usize; unsafe { (csr::DRTIOREP[repno].reset_write)(1); } - clock::spin_us(100); + timer.delay_us(100); unsafe { (csr::DRTIOREP[repno].reset_write)(0); } if self.state != RepeaterState::Up { @@ -258,7 +261,7 @@ impl Repeater { } drtioaux::send(self.auxno, &drtioaux::Packet::ResetRequest).unwrap(); - let reply = self.recv_aux_timeout(200)?; + let reply = self.recv_aux_timeout(200, timer)?; if reply != drtioaux::Packet::ResetAck { return Err(drtioaux::Error::UnexpectedReply); } @@ -275,9 +278,9 @@ pub struct Repeater { impl Repeater { pub fn new(_repno: u8) -> Repeater { Repeater::default() } - pub fn service(&self, _routing_table: &drtio_routing::RoutingTable, _rank: u8) { } + pub fn service(&self, _routing_table: &drtio_routing::RoutingTable, _rank: u8, timer: GlobalTimer) { } pub fn sync_tsc(&self) -> Result<(), drtioaux::Error> { Ok(()) } - pub fn rtio_reset(&self) -> Result<(), drtioaux::Error> { Ok(()) } + pub fn rtio_reset(&self, timer: GlobalTimer) -> Result<(), drtioaux::Error> { Ok(()) } }