Compare commits

...

4 Commits

4 changed files with 63 additions and 21 deletions

View File

@ -1,10 +1,13 @@
[workspace] [workspace]
members = [ members = [
"libboard_zynq",
"libc", "libc",
"libdyld", "libdyld",
"libdwarf", "libdwarf",
"libio",
"libunwind", "libunwind",
"runtime", "runtime",
"satman"
] ]
[profile.release] [profile.release]

View File

@ -0,0 +1,15 @@
use std::env;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
fn main() {
let out_dir = env::var("BUILDINC_DIRECTORY").unwrap();
let cfg_path = Path::new(&out_dir).join("generated").join("rust-cfg");
println!("cargo:rerun-if-changed={}", cfg_path.to_str().unwrap());
let f = BufReader::new(File::open(&cfg_path).unwrap());
for line in f.lines() {
println!("cargo:rustc-cfg={}", line.unwrap());
}
}

View File

@ -1,5 +1,15 @@
extern crate build_misoc; use std::env;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
fn main() { fn main() {
build_misoc::cfg(); // <- port - see if it's necessary, how necessary, maybe move to board_artiqzync let out_dir = env::var("BUILDINC_DIRECTORY").unwrap();
let cfg_path = Path::new(&out_dir).join("generated").join("rust-cfg");
println!("cargo:rerun-if-changed={}", cfg_path.to_str().unwrap());
let f = BufReader::new(File::open(&cfg_path).unwrap());
for line in f.lines() {
println!("cargo:rustc-cfg={}", line.unwrap());
}
} }

View File

@ -5,15 +5,28 @@
extern crate log; extern crate log;
use core::convert::TryFrom; 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; use libboard_zynq::timer::GlobalTimer;
#[cfg(has_si5324)] #[cfg(has_si5324)]
use libboard_artiq::si5324; use libboard_artiq::si5324;
use board_artiq::spi; // <- port?, use libboard_zynq (if spi available/necessary) 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; 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) { fn drtiosat_reset(reset: bool) {
unsafe { unsafe {
csr::drtiosat::reset_write(if reset { 1 } else { 0 }); csr::drtiosat::reset_write(if reset { 1 } else { 0 });
@ -65,7 +78,7 @@ macro_rules! forward {
fn process_aux_packet(_repeaters: &mut [repeater::Repeater], fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
_routing_table: &mut drtio_routing::RoutingTable, _rank: &mut u8, _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, // In the code below, *_chan_sel_write takes an u8 if there are fewer than 256 channels,
// and u16 otherwise; hence the `as _` conversion. // and u16 otherwise; hence the `as _` conversion.
match packet { match packet {
@ -74,7 +87,7 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
drtioaux::Packet::ResetRequest => { drtioaux::Packet::ResetRequest => {
info!("resetting RTIO"); info!("resetting RTIO");
drtiosat_reset(true); drtiosat_reset(true);
clock::spin_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() {
@ -232,22 +245,22 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
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);
let succeeded = i2c::start(busno).is_ok(); let succeeded = i2c.start(busno).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);
let succeeded = i2c::restart(busno).is_ok(); let succeeded = i2c.restart(busno).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);
let succeeded = i2c::stop(busno).is_ok(); let succeeded = i2c.stop(busno).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);
match i2c::write(busno, data) { match i2c.write(busno, 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 }),
Err(_) => drtioaux::send(0, Err(_) => drtioaux::send(0,
@ -256,7 +269,7 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
} }
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);
match i2c::read(busno, ack) { match i2c.read(busno, 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 }),
Err(_) => drtioaux::send(0, Err(_) => drtioaux::send(0,
@ -302,11 +315,12 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
} }
fn process_aux_packets(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 = let result =
drtioaux::recv(0).and_then(|packet| { drtioaux::recv(0).and_then(|packet| {
if let Some(packet) = 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 { } else {
Ok(()) Ok(())
} }
@ -416,10 +430,11 @@ pub extern fn main() -> i32 {
info!("ARTIQ satellite manager starting..."); info!("ARTIQ satellite manager starting...");
info!("software ident {}", csr::CONFIG_IDENTIFIER_STR); 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) //see if below is applicable (probably not - not kasli)
#[cfg(all(soc_platform = "kasli", hw_rev = "v2.0"))] #[cfg(all(soc_platform = "kasli", hw_rev = "v2.0"))]
let (mut io_expander0, mut io_expander1); let (mut io_expander0, mut io_expander1);
@ -456,7 +471,7 @@ pub extern fn main() -> i32 {
unsafe { unsafe {
csr::drtio_transceiver::txenable_write(0xffffffffu32 as _); csr::drtio_transceiver::txenable_write(0xffffffffu32 as _);
} }
init_rtio_crg(); init_rtio_crg(timer);
#[cfg(has_drtio_routing)] #[cfg(has_drtio_routing)]
let mut repeaters = [repeater::Repeater::default(); csr::DRTIOREP.len()]; let mut repeaters = [repeater::Repeater::default(); csr::DRTIOREP.len()];
@ -497,9 +512,9 @@ pub extern fn main() -> i32 {
while drtiosat_link_rx_up() { while drtiosat_link_rx_up() {
drtiosat_process_errors(); 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() { 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"))] #[cfg(all(soc_platform = "kasli", hw_rev = "v2.0"))]
{ {
@ -531,7 +546,6 @@ pub extern fn main() -> i32 {
#[no_mangle] #[no_mangle]
pub extern fn exception(vect: u32, _regs: *const u32, pc: u32, ea: u32) { 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) { fn hexdump(addr: u32) {
let addr = (addr - addr % 4) as *const 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(pc);
hexdump(ea); 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] #[no_mangle]