mirror of https://github.com/m-labs/artiq.git
firmware: fix satman build.
This commit is contained in:
parent
07b713fdad
commit
1b0384c513
|
@ -17,6 +17,8 @@ dependencies = [
|
|||
"build_misoc 0.0.0",
|
||||
"byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"crc 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"io 0.0.0",
|
||||
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proto_artiq 0.0.0",
|
||||
|
@ -176,7 +178,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "log_buffer"
|
||||
version = "1.2.0"
|
||||
source = "git+https://github.com/whitequark/rust-log_buffer?rev=rust-1.25#ff84e565d9954d5864d60aec12b9e1381505d72a"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "logger_artiq"
|
||||
|
@ -184,7 +186,7 @@ version = "0.0.0"
|
|||
dependencies = [
|
||||
"board_misoc 0.0.0",
|
||||
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log_buffer 1.2.0 (git+https://github.com/whitequark/rust-log_buffer?rev=rust-1.25)",
|
||||
"log_buffer 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -340,7 +342,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b"
|
||||
"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
|
||||
"checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2"
|
||||
"checksum log_buffer 1.2.0 (git+https://github.com/whitequark/rust-log_buffer?rev=rust-1.25)" = "<none>"
|
||||
"checksum log_buffer 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f033173c9486b7fe97a79c895c0a3483ae395ab6744c985d10078950e2492419"
|
||||
"checksum managed 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43e2737ecabe4ae36a68061398bf27d2bfd0763f4c3c837a398478459494c4b7"
|
||||
"checksum managed 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5a31885241e61ba264d780d2e6686e7e59561c947b4581470364eb3e10102d86"
|
||||
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
|
||||
|
|
|
@ -13,6 +13,8 @@ build_misoc = { path = "../libbuild_misoc" }
|
|||
build_artiq = { path = "../libbuild_artiq" }
|
||||
|
||||
[dependencies]
|
||||
failure = { version = "0.1", default-features = false }
|
||||
failure_derive = { version = "0.1", default-features = false }
|
||||
bitflags = "1.0"
|
||||
byteorder = { version = "1.0", default-features = false }
|
||||
crc = { version = "1.7", default-features = false }
|
||||
|
|
|
@ -1,43 +1,36 @@
|
|||
use core::{slice, fmt, result};
|
||||
use core::slice;
|
||||
use crc;
|
||||
|
||||
use io::{Cursor, Error as IoError};
|
||||
use io::proto::{ProtoRead, ProtoWrite};
|
||||
use io::{ProtoRead, ProtoWrite, Cursor, Error as IoError};
|
||||
use board_misoc::{csr::DRTIO, mem::DRTIO_AUX, clock};
|
||||
use proto_artiq::drtioaux_proto::Error as ProtocolError;
|
||||
|
||||
pub use proto_artiq::drtioaux_proto::Packet;
|
||||
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Error {
|
||||
// this is parametric over T because there's no impl Fail for !.
|
||||
#[derive(Fail, Debug)]
|
||||
pub enum Error<T> {
|
||||
#[fail(display = "packet CRC failed")]
|
||||
CorruptedPacket,
|
||||
#[fail(display = "timed out waiting for data")]
|
||||
TimedOut,
|
||||
#[fail(display = "invalid node number")]
|
||||
NoRoute,
|
||||
#[fail(display = "gateware reported error")]
|
||||
GatewareError,
|
||||
Io(IoError<!>)
|
||||
#[fail(display = "protocol error: {}", _0)]
|
||||
Protocol(#[cause] ProtocolError<T>)
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Error::CorruptedPacket =>
|
||||
write!(f, "packet CRC failed"),
|
||||
&Error::TimedOut =>
|
||||
write!(f, "timed out waiting for data"),
|
||||
&Error::NoRoute =>
|
||||
write!(f, "invalid node number"),
|
||||
&Error::GatewareError =>
|
||||
write!(f, "gateware reported error"),
|
||||
&Error::Io(ref io) =>
|
||||
write!(f, "I/O error ({})", io)
|
||||
}
|
||||
impl<T> From<ProtocolError<T>> for Error<T> {
|
||||
fn from(value: ProtocolError<T>) -> Error<T> {
|
||||
Error::Protocol(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IoError<!>> for Error {
|
||||
fn from(value: IoError<!>) -> Error {
|
||||
Error::Io(value)
|
||||
impl<T> From<IoError<T>> for Error<T> {
|
||||
fn from(value: IoError<T>) -> Error<T> {
|
||||
Error::Protocol(ProtocolError::Io(value))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,8 +56,8 @@ fn has_rx_error(linkno: u8) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn receive<F, T>(linkno: u8, f: F) -> Result<Option<T>>
|
||||
where F: FnOnce(&[u8]) -> Result<T>
|
||||
fn receive<F, T>(linkno: u8, f: F) -> Result<Option<T>, Error<!>>
|
||||
where F: FnOnce(&[u8]) -> Result<T, Error<!>>
|
||||
{
|
||||
let linkidx = linkno as usize;
|
||||
unsafe {
|
||||
|
@ -80,14 +73,14 @@ fn receive<F, T>(linkno: u8, f: F) -> Result<Option<T>>
|
|||
}
|
||||
}
|
||||
|
||||
pub fn recv_link(linkno: u8) -> Result<Option<Packet>> {
|
||||
pub fn recv_link(linkno: u8) -> Result<Option<Packet>, Error<!>> {
|
||||
if has_rx_error(linkno) {
|
||||
return Err(Error::GatewareError)
|
||||
}
|
||||
|
||||
receive(linkno, |buffer| {
|
||||
if buffer.len() < 8 {
|
||||
return Err(Error::Io(IoError::UnexpectedEof))
|
||||
return Err(IoError::UnexpectedEnd.into())
|
||||
}
|
||||
|
||||
let mut reader = Cursor::new(buffer);
|
||||
|
@ -104,7 +97,7 @@ pub fn recv_link(linkno: u8) -> Result<Option<Packet>> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn recv_timeout_link(linkno: u8, timeout_ms: Option<u64>) -> Result<Packet> {
|
||||
pub fn recv_timeout_link(linkno: u8, timeout_ms: Option<u64>) -> Result<Packet, Error<!>> {
|
||||
let timeout_ms = timeout_ms.unwrap_or(10);
|
||||
let limit = clock::get_ms() + timeout_ms;
|
||||
while clock::get_ms() < limit {
|
||||
|
@ -116,8 +109,8 @@ pub fn recv_timeout_link(linkno: u8, timeout_ms: Option<u64>) -> Result<Packet>
|
|||
Err(Error::TimedOut)
|
||||
}
|
||||
|
||||
fn transmit<F>(linkno: u8, f: F) -> Result<()>
|
||||
where F: FnOnce(&mut [u8]) -> Result<usize>
|
||||
fn transmit<F>(linkno: u8, f: F) -> Result<(), Error<!>>
|
||||
where F: FnOnce(&mut [u8]) -> Result<usize, Error<!>>
|
||||
{
|
||||
let linkno = linkno as usize;
|
||||
unsafe {
|
||||
|
@ -131,7 +124,7 @@ fn transmit<F>(linkno: u8, f: F) -> Result<()>
|
|||
}
|
||||
}
|
||||
|
||||
pub fn send_link(linkno: u8, packet: &Packet) -> Result<()> {
|
||||
pub fn send_link(linkno: u8, packet: &Packet) -> Result<(), Error<!>> {
|
||||
transmit(linkno, |buffer| {
|
||||
let mut writer = Cursor::new(buffer);
|
||||
|
||||
|
@ -152,24 +145,24 @@ pub fn send_link(linkno: u8, packet: &Packet) -> Result<()> {
|
|||
}
|
||||
|
||||
// TODO: routing
|
||||
fn get_linkno(nodeno: u8) -> Result<u8> {
|
||||
fn get_linkno(nodeno: u8) -> Result<u8, Error<!>> {
|
||||
if nodeno == 0 || nodeno as usize > DRTIO.len() {
|
||||
return Err(Error::NoRoute)
|
||||
}
|
||||
Ok(nodeno - 1)
|
||||
}
|
||||
|
||||
pub fn recv(nodeno: u8) -> Result<Option<Packet>> {
|
||||
pub fn recv(nodeno: u8) -> Result<Option<Packet>, Error<!>> {
|
||||
let linkno = get_linkno(nodeno)?;
|
||||
recv_link(linkno)
|
||||
}
|
||||
|
||||
pub fn recv_timeout(nodeno: u8, timeout_ms: Option<u64>) -> Result<Packet> {
|
||||
pub fn recv_timeout(nodeno: u8, timeout_ms: Option<u64>) -> Result<Packet, Error<!>> {
|
||||
let linkno = get_linkno(nodeno)?;
|
||||
recv_timeout_link(linkno, timeout_ms)
|
||||
}
|
||||
|
||||
pub fn send(nodeno: u8, packet: &Packet) -> Result<()> {
|
||||
pub fn send(nodeno: u8, packet: &Packet) -> Result<(), Error<!>> {
|
||||
let linkno = get_linkno(nodeno)?;
|
||||
send_link(linkno, packet)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
#![feature(asm, lang_items, never_type)]
|
||||
#![no_std]
|
||||
|
||||
extern crate failure;
|
||||
#[cfg(has_drtio)]
|
||||
#[macro_use]
|
||||
extern crate failure_derive;
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
extern crate byteorder;
|
||||
|
|
|
@ -26,7 +26,7 @@ fn drtio_reset_phy(reset: bool) {
|
|||
}
|
||||
}
|
||||
|
||||
fn process_aux_packet(packet: drtioaux::Packet) -> drtioaux::Result<()> {
|
||||
fn process_aux_packet(packet: drtioaux::Packet) -> 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 {
|
||||
|
|
Loading…
Reference in New Issue