mirror of https://github.com/m-labs/artiq.git
libdrtioaux: do not attempt to access non-existent DRTIO gateware
This commit is contained in:
parent
257527629a
commit
016743f079
|
@ -2,6 +2,7 @@
|
||||||
authors = ["M-Labs"]
|
authors = ["M-Labs"]
|
||||||
name = "drtioaux"
|
name = "drtioaux"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
|
build = "build.rs"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "drtioaux"
|
name = "drtioaux"
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
use std::env;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::io::{BufRead, BufReader};
|
||||||
|
use std::fs::File;
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,7 +10,7 @@ extern crate byteorder;
|
||||||
mod proto;
|
mod proto;
|
||||||
mod crc32;
|
mod crc32;
|
||||||
|
|
||||||
use std::io::{self, Cursor, Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
use core::slice;
|
use core::slice;
|
||||||
use proto::*;
|
use proto::*;
|
||||||
|
|
||||||
|
@ -40,6 +40,11 @@ impl Packet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(has_drtio)]
|
||||||
|
pub mod hw {
|
||||||
|
use super::*;
|
||||||
|
use std::io::Cursor;
|
||||||
|
|
||||||
const AUX_TX_BASE: usize = board::mem::DRTIO_AUX_BASE;
|
const AUX_TX_BASE: usize = board::mem::DRTIO_AUX_BASE;
|
||||||
const AUX_TX_SIZE: usize = board::mem::DRTIO_AUX_SIZE/2;
|
const AUX_TX_SIZE: usize = board::mem::DRTIO_AUX_SIZE/2;
|
||||||
const AUX_RX_BASE: usize = AUX_TX_BASE + AUX_TX_SIZE;
|
const AUX_RX_BASE: usize = AUX_TX_BASE + AUX_TX_SIZE;
|
||||||
|
@ -54,7 +59,7 @@ fn rx_has_error() -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct RxBuffer(&'static [u8]);
|
struct RxBuffer(&'static [u8]);
|
||||||
|
|
||||||
impl Drop for RxBuffer {
|
impl Drop for RxBuffer {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
|
@ -76,7 +81,7 @@ fn rx_get_buffer() -> Option<RxBuffer> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn recv_packet() -> io::Result<Option<Packet>> {
|
pub fn recv() -> io::Result<Option<Packet>> {
|
||||||
if rx_has_error() {
|
if rx_has_error() {
|
||||||
return Err(io::Error::new(io::ErrorKind::Other, "gateware reported error"))
|
return Err(io::Error::new(io::ErrorKind::Other, "gateware reported error"))
|
||||||
}
|
}
|
||||||
|
@ -122,7 +127,7 @@ fn tx_ack_buffer(length: u16) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_packet(packet: &Packet) -> io::Result<()> {
|
pub fn send(packet: &Packet) -> io::Result<()> {
|
||||||
let sl = tx_get_buffer();
|
let sl = tx_get_buffer();
|
||||||
|
|
||||||
let mut writer = Cursor::new(sl);
|
let mut writer = Cursor::new(sl);
|
||||||
|
@ -145,3 +150,4 @@ pub fn send_packet(packet: &Packet) -> io::Result<()> {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -113,9 +113,9 @@ mod drtio {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
count += 1;
|
count += 1;
|
||||||
drtioaux::send_packet(&drtioaux::Packet::EchoRequest).unwrap();
|
drtioaux::hw::send(&drtioaux::Packet::EchoRequest).unwrap();
|
||||||
io.sleep(100).unwrap();
|
io.sleep(100).unwrap();
|
||||||
let pr = drtioaux::recv_packet();
|
let pr = drtioaux::hw::recv();
|
||||||
match pr {
|
match pr {
|
||||||
Ok(Some(drtioaux::Packet::EchoReply)) => return count,
|
Ok(Some(drtioaux::Packet::EchoReply)) => return count,
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
@ -14,14 +14,13 @@ extern crate drtioaux;
|
||||||
|
|
||||||
fn process_aux_packet(p: drtioaux::Packet) {
|
fn process_aux_packet(p: drtioaux::Packet) {
|
||||||
match p {
|
match p {
|
||||||
drtioaux::Packet::EchoRequest => drtioaux::send_packet(&drtioaux::Packet::EchoReply).unwrap(),
|
drtioaux::Packet::EchoRequest => drtioaux::hw::send(&drtioaux::Packet::EchoReply).unwrap(),
|
||||||
_ => warn!("received unexpected aux packet {:?}", p)
|
_ => warn!("received unexpected aux packet {:?}", p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn process_aux_packets() {
|
fn process_aux_packets() {
|
||||||
let pr = drtioaux::recv_packet();
|
let pr = drtioaux::hw::recv();
|
||||||
match pr {
|
match pr {
|
||||||
Ok(None) => {},
|
Ok(None) => {},
|
||||||
Ok(Some(p)) => process_aux_packet(p),
|
Ok(Some(p)) => process_aux_packet(p),
|
||||||
|
|
Loading…
Reference in New Issue