|
|
|
@ -5,15 +5,28 @@
|
|
|
|
|
extern crate log;
|
|
|
|
|
|
|
|
|
|
use core::convert::TryFrom;
|
|
|
|
|
use board_misoc::{csr, irq, ident, i2c}; // <- port, use libboard_zynq
|
|
|
|
|
use libboard_zynq::i2c::I2c; // not using a wrapper like runtime
|
|
|
|
|
use libboard_zynq::timer::GlobalTimer;
|
|
|
|
|
#[cfg(has_si5324)]
|
|
|
|
|
use libboard_artiq::si5324;
|
|
|
|
|
use board_artiq::spi; // <- port?, use libboard_zynq (if spi available/necessary)
|
|
|
|
|
use libboard_artiq::{drtio_routing, drtioaux, logger};
|
|
|
|
|
use libboard_artiq::{pl::csr, drtio_routing, drtioaux, logger};
|
|
|
|
|
|
|
|
|
|
mod repeater;
|
|
|
|
|
|
|
|
|
|
fn identifier_read(buf: &mut [u8]) -> &str {
|
|
|
|
|
unsafe {
|
|
|
|
|
pl::csr::identifier::address_write(0);
|
|
|
|
|
let len = pl::csr::identifier::data_read();
|
|
|
|
|
let len = cmp::min(len, buf.len() as u8);
|
|
|
|
|
for i in 0..len {
|
|
|
|
|
pl::csr::identifier::address_write(1 + i);
|
|
|
|
|
buf[i as usize] = pl::csr::identifier::data_read();
|
|
|
|
|
}
|
|
|
|
|
str::from_utf8_unchecked(&buf[..len as usize])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn drtiosat_reset(reset: bool) {
|
|
|
|
|
unsafe {
|
|
|
|
|
csr::drtiosat::reset_write(if reset { 1 } else { 0 });
|
|
|
|
@ -65,7 +78,7 @@ macro_rules! forward {
|
|
|
|
|
|
|
|
|
|
fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
|
|
|
|
|
_routing_table: &mut drtio_routing::RoutingTable, _rank: &mut u8,
|
|
|
|
|
packet: drtioaux::Packet) -> Result<(), drtioaux::Error<!>> {
|
|
|
|
|
packet: drtioaux::Packet, timer: GlobalTimer, i2c: I2c) -> Result<(), drtioaux::Error<!>> {
|
|
|
|
|
// In the code below, *_chan_sel_write takes an u8 if there are fewer than 256 channels,
|
|
|
|
|
// and u16 otherwise; hence the `as _` conversion.
|
|
|
|
|
match packet {
|
|
|
|
@ -74,7 +87,7 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
|
|
|
|
|
drtioaux::Packet::ResetRequest => {
|
|
|
|
|
info!("resetting RTIO");
|
|
|
|
|
drtiosat_reset(true);
|
|
|
|
|
clock::spin_us(100);
|
|
|
|
|
timer.delay_us(100);
|
|
|
|
|
drtiosat_reset(false);
|
|
|
|
|
for rep in _repeaters.iter() {
|
|
|
|
|
if let Err(e) = rep.rtio_reset() {
|
|
|
|
@ -232,22 +245,22 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
|
|
|
|
|
|
|
|
|
|
drtioaux::Packet::I2cStartRequest { destination: _destination, busno } => {
|
|
|
|
|
forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
|
|
|
|
|
let succeeded = i2c::start(busno).is_ok();
|
|
|
|
|
let succeeded = i2c.start(busno).is_ok();
|
|
|
|
|
drtioaux::send(0, &drtioaux::Packet::I2cBasicReply { succeeded: succeeded })
|
|
|
|
|
}
|
|
|
|
|
drtioaux::Packet::I2cRestartRequest { destination: _destination, busno } => {
|
|
|
|
|
forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
|
|
|
|
|
let succeeded = i2c::restart(busno).is_ok();
|
|
|
|
|
let succeeded = i2c.restart(busno).is_ok();
|
|
|
|
|
drtioaux::send(0, &drtioaux::Packet::I2cBasicReply { succeeded: succeeded })
|
|
|
|
|
}
|
|
|
|
|
drtioaux::Packet::I2cStopRequest { destination: _destination, busno } => {
|
|
|
|
|
forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
|
|
|
|
|
let succeeded = i2c::stop(busno).is_ok();
|
|
|
|
|
let succeeded = i2c.stop(busno).is_ok();
|
|
|
|
|
drtioaux::send(0, &drtioaux::Packet::I2cBasicReply { succeeded: succeeded })
|
|
|
|
|
}
|
|
|
|
|
drtioaux::Packet::I2cWriteRequest { destination: _destination, busno, data } => {
|
|
|
|
|
forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
|
|
|
|
|
match i2c::write(busno, data) {
|
|
|
|
|
match i2c.write(busno, data) {
|
|
|
|
|
Ok(ack) => drtioaux::send(0,
|
|
|
|
|
&drtioaux::Packet::I2cWriteReply { succeeded: true, ack: ack }),
|
|
|
|
|
Err(_) => drtioaux::send(0,
|
|
|
|
@ -256,7 +269,7 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
|
|
|
|
|
}
|
|
|
|
|
drtioaux::Packet::I2cReadRequest { destination: _destination, busno, ack } => {
|
|
|
|
|
forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
|
|
|
|
|
match i2c::read(busno, ack) {
|
|
|
|
|
match i2c.read(busno, ack) {
|
|
|
|
|
Ok(data) => drtioaux::send(0,
|
|
|
|
|
&drtioaux::Packet::I2cReadReply { succeeded: true, data: data }),
|
|
|
|
|
Err(_) => drtioaux::send(0,
|
|
|
|
@ -302,11 +315,12 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn process_aux_packets(repeaters: &mut [repeater::Repeater],
|
|
|
|
|
routing_table: &mut drtio_routing::RoutingTable, rank: &mut u8) {
|
|
|
|
|
routing_table: &mut drtio_routing::RoutingTable, rank: &mut u8,
|
|
|
|
|
timer::GlobalTimer, i2c: I2c) {
|
|
|
|
|
let result =
|
|
|
|
|
drtioaux::recv(0).and_then(|packet| {
|
|
|
|
|
if let Some(packet) = packet {
|
|
|
|
|
process_aux_packet(repeaters, routing_table, rank, packet)
|
|
|
|
|
process_aux_packet(repeaters, routing_table, rank, packet, timer, i2c)
|
|
|
|
|
} else {
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
@ -416,10 +430,11 @@ pub extern fn main() -> i32 {
|
|
|
|
|
|
|
|
|
|
info!("ARTIQ satellite manager starting...");
|
|
|
|
|
info!("software ident {}", csr::CONFIG_IDENTIFIER_STR);
|
|
|
|
|
info!("gateware ident {}", ident::read(&mut [0; 64]));
|
|
|
|
|
info!("gateware ident {}", identifier_read(&mut [0; 64]));
|
|
|
|
|
|
|
|
|
|
let mut i2c = I2c::i2c0();
|
|
|
|
|
i2c.init().expect("I2C initialization failed");
|
|
|
|
|
|
|
|
|
|
#[cfg(has_i2c)]
|
|
|
|
|
i2c::init().expect("I2C initialization failed"); // port
|
|
|
|
|
//see if below is applicable (probably not - not kasli)
|
|
|
|
|
#[cfg(all(soc_platform = "kasli", hw_rev = "v2.0"))]
|
|
|
|
|
let (mut io_expander0, mut io_expander1);
|
|
|
|
@ -456,7 +471,7 @@ pub extern fn main() -> i32 {
|
|
|
|
|
unsafe {
|
|
|
|
|
csr::drtio_transceiver::txenable_write(0xffffffffu32 as _);
|
|
|
|
|
}
|
|
|
|
|
init_rtio_crg();
|
|
|
|
|
init_rtio_crg(timer);
|
|
|
|
|
|
|
|
|
|
#[cfg(has_drtio_routing)]
|
|
|
|
|
let mut repeaters = [repeater::Repeater::default(); csr::DRTIOREP.len()];
|
|
|
|
@ -497,9 +512,9 @@ pub extern fn main() -> i32 {
|
|
|
|
|
|
|
|
|
|
while drtiosat_link_rx_up() {
|
|
|
|
|
drtiosat_process_errors();
|
|
|
|
|
process_aux_packets(&mut repeaters, &mut routing_table, &mut rank);
|
|
|
|
|
process_aux_packets(&mut repeaters, &mut routing_table, &mut rank, timer, i2c);
|
|
|
|
|
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"))]
|
|
|
|
|
{
|
|
|
|
@ -531,7 +546,6 @@ pub extern fn main() -> i32 {
|
|
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
|
pub extern fn exception(vect: u32, _regs: *const u32, pc: u32, ea: u32) {
|
|
|
|
|
let vect = irq::Exception::try_from(vect).expect("unknown exception");
|
|
|
|
|
|
|
|
|
|
fn hexdump(addr: u32) {
|
|
|
|
|
let addr = (addr - addr % 4) as *const u32;
|
|
|
|
@ -548,7 +562,7 @@ pub extern fn exception(vect: u32, _regs: *const u32, pc: u32, ea: u32) {
|
|
|
|
|
|
|
|
|
|
hexdump(pc);
|
|
|
|
|
hexdump(ea);
|
|
|
|
|
panic!("exception {:?} at PC 0x{:x}, EA 0x{:x}", vect, pc, ea)
|
|
|
|
|
panic!("exception at PC 0x{:x}, EA 0x{:x}", pc, ea)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
|