satman: straightened up drtio interface
This commit is contained in:
parent
f80f2ac99d
commit
e56f99b3ae
@ -11,7 +11,6 @@ use libboard_zynq::{timer::GlobalTimer, time::Milliseconds};
|
|||||||
|
|
||||||
pub use drtioaux_proto::Packet;
|
pub use drtioaux_proto::Packet;
|
||||||
|
|
||||||
// this is parametric over T because there's no impl Fail for !.
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
GatewareError,
|
GatewareError,
|
||||||
|
@ -62,12 +62,12 @@ fn drtiosat_tsc_loaded() -> bool {
|
|||||||
|
|
||||||
#[cfg(has_drtio_routing)]
|
#[cfg(has_drtio_routing)]
|
||||||
macro_rules! forward {
|
macro_rules! forward {
|
||||||
($routing_table:expr, $destination:expr, $rank:expr, $repeaters:expr, $packet:expr) => {{
|
($routing_table:expr, $destination:expr, $rank:expr, $repeaters:expr, $packet:expr, $timer:expr) => {{
|
||||||
let hop = $routing_table.0[$destination as usize][$rank as usize];
|
let hop = $routing_table.0[$destination as usize][$rank as usize];
|
||||||
if hop != 0 {
|
if hop != 0 {
|
||||||
let repno = (hop - 1) as usize;
|
let repno = (hop - 1) as usize;
|
||||||
if repno < $repeaters.len() {
|
if repno < $repeaters.len() {
|
||||||
return $repeaters[repno].aux_forward($packet);
|
return $repeaters[repno].aux_forward($packet, $timer);
|
||||||
} else {
|
} else {
|
||||||
return Err(drtioaux::Error::RoutingError);
|
return Err(drtioaux::Error::RoutingError);
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ macro_rules! forward {
|
|||||||
|
|
||||||
#[cfg(not(has_drtio_routing))]
|
#[cfg(not(has_drtio_routing))]
|
||||||
macro_rules! forward {
|
macro_rules! forward {
|
||||||
($routing_table:expr, $destination:expr, $rank:expr, $repeaters:expr, $packet:expr) => {}
|
($routing_table:expr, $destination:expr, $rank:expr, $repeaters:expr, $packet:expr, $timer:expr) => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
|
fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
|
||||||
@ -94,8 +94,8 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
|
|||||||
timer.delay_us(100);
|
timer.delay_us(100);
|
||||||
drtiosat_reset(false);
|
drtiosat_reset(false);
|
||||||
for rep in _repeaters.iter() {
|
for rep in _repeaters.iter() {
|
||||||
if let Err(e) = rep.rtio_reset() {
|
if let Err(e) = rep.rtio_reset(timer) {
|
||||||
error!("failed to issue RTIO reset ({})", e);
|
error!("failed to issue RTIO reset ({:?})", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drtioaux::send(0, &drtioaux::Packet::ResetAck)
|
drtioaux::send(0, &drtioaux::Packet::ResetAck)
|
||||||
@ -150,12 +150,12 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
|
|||||||
let repno = hop - 1;
|
let repno = hop - 1;
|
||||||
match _repeaters[repno].aux_forward(&drtioaux::Packet::DestinationStatusRequest {
|
match _repeaters[repno].aux_forward(&drtioaux::Packet::DestinationStatusRequest {
|
||||||
destination: _destination
|
destination: _destination
|
||||||
}) {
|
}, timer) {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(drtioaux::Error::LinkDown) => drtioaux::send(0, &drtioaux::Packet::DestinationDownReply)?,
|
Err(drtioaux::Error::LinkDown) => drtioaux::send(0, &drtioaux::Packet::DestinationDownReply)?,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
drtioaux::send(0, &drtioaux::Packet::DestinationDownReply)?;
|
drtioaux::send(0, &drtioaux::Packet::DestinationDownReply)?;
|
||||||
error!("aux error when handling destination status request: {}", e);
|
error!("aux error when handling destination status request: {:?}", e);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -171,8 +171,8 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
|
|||||||
drtioaux::Packet::RoutingSetPath { destination, hops } => {
|
drtioaux::Packet::RoutingSetPath { destination, hops } => {
|
||||||
_routing_table.0[destination as usize] = hops;
|
_routing_table.0[destination as usize] = hops;
|
||||||
for rep in _repeaters.iter() {
|
for rep in _repeaters.iter() {
|
||||||
if let Err(e) = rep.set_path(destination, &hops) {
|
if let Err(e) = rep.set_path(destination, &hops, timer) {
|
||||||
error!("failed to set path ({})", e);
|
error!("failed to set path ({:?})", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drtioaux::send(0, &drtioaux::Packet::RoutingAck)
|
drtioaux::send(0, &drtioaux::Packet::RoutingAck)
|
||||||
@ -184,8 +184,8 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
|
|||||||
|
|
||||||
let rep_rank = rank + 1;
|
let rep_rank = rank + 1;
|
||||||
for rep in _repeaters.iter() {
|
for rep in _repeaters.iter() {
|
||||||
if let Err(e) = rep.set_rank(rep_rank) {
|
if let Err(e) = rep.set_rank(rep_rank, timer) {
|
||||||
error!("failed to set rank ({})", e);
|
error!("failed to set rank ({:?})", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +205,7 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
|
|||||||
}
|
}
|
||||||
|
|
||||||
drtioaux::Packet::MonitorRequest { destination: _destination, channel, probe } => {
|
drtioaux::Packet::MonitorRequest { destination: _destination, channel, probe } => {
|
||||||
forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
|
forward!(_routing_table, _destination, *_rank, _repeaters, &packet, timer);
|
||||||
let value;
|
let value;
|
||||||
#[cfg(has_rtio_moninj)]
|
#[cfg(has_rtio_moninj)]
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -222,7 +222,7 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
|
|||||||
drtioaux::send(0, &reply)
|
drtioaux::send(0, &reply)
|
||||||
},
|
},
|
||||||
drtioaux::Packet::InjectionRequest { destination: _destination, channel, overrd, value } => {
|
drtioaux::Packet::InjectionRequest { destination: _destination, channel, overrd, value } => {
|
||||||
forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
|
forward!(_routing_table, _destination, *_rank, _repeaters, &packet, timer);
|
||||||
#[cfg(has_rtio_moninj)]
|
#[cfg(has_rtio_moninj)]
|
||||||
unsafe {
|
unsafe {
|
||||||
csr::rtio_moninj::inj_chan_sel_write(channel as _);
|
csr::rtio_moninj::inj_chan_sel_write(channel as _);
|
||||||
@ -232,7 +232,7 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
|
|||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
drtioaux::Packet::InjectionStatusRequest { destination: _destination, channel, overrd } => {
|
drtioaux::Packet::InjectionStatusRequest { destination: _destination, channel, overrd } => {
|
||||||
forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
|
forward!(_routing_table, _destination, *_rank, _repeaters, &packet, timer);
|
||||||
let value;
|
let value;
|
||||||
#[cfg(has_rtio_moninj)]
|
#[cfg(has_rtio_moninj)]
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -247,23 +247,23 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
|
|||||||
drtioaux::send(0, &drtioaux::Packet::InjectionStatusReply { value: value })
|
drtioaux::send(0, &drtioaux::Packet::InjectionStatusReply { value: value })
|
||||||
},
|
},
|
||||||
|
|
||||||
drtioaux::Packet::I2cStartRequest { destination: _destination, _busno } => {
|
drtioaux::Packet::I2cStartRequest { destination: _destination, busno } => {
|
||||||
forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
|
forward!(_routing_table, _destination, *_rank, _repeaters, &packet, timer);
|
||||||
let succeeded = i2c.start().is_ok();
|
let succeeded = i2c.start().is_ok();
|
||||||
drtioaux::send(0, &drtioaux::Packet::I2cBasicReply { succeeded: succeeded })
|
drtioaux::send(0, &drtioaux::Packet::I2cBasicReply { succeeded: succeeded })
|
||||||
}
|
}
|
||||||
drtioaux::Packet::I2cRestartRequest { destination: _destination, _busno } => {
|
drtioaux::Packet::I2cRestartRequest { destination: _destination, busno } => {
|
||||||
forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
|
forward!(_routing_table, _destination, *_rank, _repeaters, &packet, timer);
|
||||||
let succeeded = i2c.restart().is_ok();
|
let succeeded = i2c.restart().is_ok();
|
||||||
drtioaux::send(0, &drtioaux::Packet::I2cBasicReply { succeeded: succeeded })
|
drtioaux::send(0, &drtioaux::Packet::I2cBasicReply { succeeded: succeeded })
|
||||||
}
|
}
|
||||||
drtioaux::Packet::I2cStopRequest { destination: _destination, _busno } => {
|
drtioaux::Packet::I2cStopRequest { destination: _destination, busno } => {
|
||||||
forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
|
forward!(_routing_table, _destination, *_rank, _repeaters, &packet, timer);
|
||||||
let succeeded = i2c.stop().is_ok();
|
let succeeded = i2c.stop().is_ok();
|
||||||
drtioaux::send(0, &drtioaux::Packet::I2cBasicReply { succeeded: succeeded })
|
drtioaux::send(0, &drtioaux::Packet::I2cBasicReply { succeeded: succeeded })
|
||||||
}
|
}
|
||||||
drtioaux::Packet::I2cWriteRequest { destination: _destination, _busno, data } => {
|
drtioaux::Packet::I2cWriteRequest { destination: _destination, busno, data } => {
|
||||||
forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
|
forward!(_routing_table, _destination, *_rank, _repeaters, &packet, timer);
|
||||||
match i2c.write(data) {
|
match i2c.write(data) {
|
||||||
Ok(ack) => drtioaux::send(0,
|
Ok(ack) => drtioaux::send(0,
|
||||||
&drtioaux::Packet::I2cWriteReply { succeeded: true, ack: ack }),
|
&drtioaux::Packet::I2cWriteReply { succeeded: true, ack: ack }),
|
||||||
@ -271,8 +271,8 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
|
|||||||
&drtioaux::Packet::I2cWriteReply { succeeded: false, ack: false })
|
&drtioaux::Packet::I2cWriteReply { succeeded: false, ack: false })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drtioaux::Packet::I2cReadRequest { destination: _destination, _busno, ack } => {
|
drtioaux::Packet::I2cReadRequest { destination: _destination, busno, ack } => {
|
||||||
forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
|
forward!(_routing_table, _destination, *_rank, _repeaters, &packet, timer);
|
||||||
match i2c.read(ack) {
|
match i2c.read(ack) {
|
||||||
Ok(data) => drtioaux::send(0,
|
Ok(data) => drtioaux::send(0,
|
||||||
&drtioaux::Packet::I2cReadReply { succeeded: true, data: data }),
|
&drtioaux::Packet::I2cReadReply { succeeded: true, data: data }),
|
||||||
@ -282,21 +282,21 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
|
|||||||
}
|
}
|
||||||
|
|
||||||
drtioaux::Packet::SpiSetConfigRequest { destination: _destination, busno, flags, length, div, cs } => {
|
drtioaux::Packet::SpiSetConfigRequest { destination: _destination, busno, flags, length, div, cs } => {
|
||||||
forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
|
forward!(_routing_table, _destination, *_rank, _repeaters, &packet, timer);
|
||||||
// todo: reimplement when SPI is available
|
// todo: reimplement when SPI is available
|
||||||
//let succeeded = spi::set_config(busno, flags, length, div, cs).is_ok();
|
//let succeeded = spi::set_config(busno, flags, length, div, cs).is_ok();
|
||||||
drtioaux::send(0,
|
drtioaux::send(0,
|
||||||
&drtioaux::Packet::SpiBasicReply { succeeded: false})
|
&drtioaux::Packet::SpiBasicReply { succeeded: false})
|
||||||
},
|
},
|
||||||
drtioaux::Packet::SpiWriteRequest { destination: _destination, _busno, data } => {
|
drtioaux::Packet::SpiWriteRequest { destination: _destination, busno, data } => {
|
||||||
forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
|
forward!(_routing_table, _destination, *_rank, _repeaters, &packet, timer);
|
||||||
// todo: reimplement when SPI is available
|
// todo: reimplement when SPI is available
|
||||||
//let succeeded = spi::write(busno, data).is_ok();
|
//let succeeded = spi::write(busno, data).is_ok();
|
||||||
drtioaux::send(0,
|
drtioaux::send(0,
|
||||||
&drtioaux::Packet::SpiBasicReply { succeeded: false })
|
&drtioaux::Packet::SpiBasicReply { succeeded: false })
|
||||||
}
|
}
|
||||||
drtioaux::Packet::SpiReadRequest { destination: _destination, _busno } => {
|
drtioaux::Packet::SpiReadRequest { destination: _destination, busno } => {
|
||||||
forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
|
forward!(_routing_table, _destination, *_rank, _repeaters, &packet, timer);
|
||||||
// todo: reimplement when SPI is available
|
// todo: reimplement when SPI is available
|
||||||
// match spi::read(busno) {
|
// match spi::read(busno) {
|
||||||
// Ok(data) => drtioaux::send(0,
|
// Ok(data) => drtioaux::send(0,
|
||||||
@ -310,7 +310,7 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
|
|||||||
|
|
||||||
drtioaux::Packet::JdacBasicRequest { destination: _destination, dacno: _dacno,
|
drtioaux::Packet::JdacBasicRequest { destination: _destination, dacno: _dacno,
|
||||||
reqno: _reqno, param: _param } => {
|
reqno: _reqno, param: _param } => {
|
||||||
forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
|
forward!(_routing_table, _destination, *_rank, _repeaters, &packet, timer);
|
||||||
let (succeeded, retval) = (false, 0);
|
let (succeeded, retval) = (false, 0);
|
||||||
drtioaux::send(0,
|
drtioaux::send(0,
|
||||||
&drtioaux::Packet::JdacBasicReply { succeeded: succeeded, retval: retval })
|
&drtioaux::Packet::JdacBasicReply { succeeded: succeeded, retval: retval })
|
||||||
@ -336,7 +336,7 @@ fn process_aux_packets(repeaters: &mut [repeater::Repeater],
|
|||||||
});
|
});
|
||||||
match result {
|
match result {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(e) => warn!("aux packet error ({})", e)
|
Err(e) => warn!("aux packet error ({:?})", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -544,11 +544,11 @@ pub extern fn main_core0() -> i32 {
|
|||||||
info!("TSC loaded from uplink");
|
info!("TSC loaded from uplink");
|
||||||
for rep in repeaters.iter() {
|
for rep in repeaters.iter() {
|
||||||
if let Err(e) = rep.sync_tsc(timer) {
|
if let Err(e) = rep.sync_tsc(timer) {
|
||||||
error!("failed to sync TSC ({})", e);
|
error!("failed to sync TSC ({:?})", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Err(e) = drtioaux::send(0, &drtioaux::Packet::TSCAck) {
|
if let Err(e) = drtioaux::send(0, &drtioaux::Packet::TSCAck) {
|
||||||
error!("aux packet error: {}", e);
|
error!("aux packet error: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,18 +81,18 @@ impl Repeater {
|
|||||||
if let Ok(Some(drtioaux::Packet::EchoReply)) = drtioaux::recv(self.auxno) {
|
if let Ok(Some(drtioaux::Packet::EchoReply)) = drtioaux::recv(self.auxno) {
|
||||||
info!("[REP#{}] remote replied after {} packets", self.repno, ping_count);
|
info!("[REP#{}] remote replied after {} packets", self.repno, ping_count);
|
||||||
self.state = RepeaterState::Up;
|
self.state = RepeaterState::Up;
|
||||||
if let Err(e) = self.sync_tsc() {
|
if let Err(e) = self.sync_tsc(timer) {
|
||||||
error!("[REP#{}] failed to sync TSC ({})", self.repno, e);
|
error!("[REP#{}] failed to sync TSC ({:?})", self.repno, e);
|
||||||
self.state = RepeaterState::Failed;
|
self.state = RepeaterState::Failed;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let Err(e) = self.load_routing_table(routing_table, timer) {
|
if let Err(e) = self.load_routing_table(routing_table, timer) {
|
||||||
error!("[REP#{}] failed to load routing table ({})", self.repno, e);
|
error!("[REP#{}] failed to load routing table ({:?})", self.repno, e);
|
||||||
self.state = RepeaterState::Failed;
|
self.state = RepeaterState::Failed;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let Err(e) = self.set_rank(rank + 1, timer) {
|
if let Err(e) = self.set_rank(rank + 1, timer) {
|
||||||
error!("[REP#{}] failed to set rank ({})", self.repno, e);
|
error!("[REP#{}] failed to set rank ({:?})", self.repno, e);
|
||||||
self.state = RepeaterState::Failed;
|
self.state = RepeaterState::Failed;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user