#![allow(dead_code)]
pub const KDI_VERSION: &str = "0.7";
pub const KDI_MAJOR: u16 = 0;
pub const KDI_MINOR: u16 = 7;
pub const CONTRACT_REV: u16 = KDI_MINOR;
pub const READY_TIMEOUT_MS: u64 = 3000;
pub const WORST_MS: &[(&str, u64)] = &[
("adio.adc", 5),
("power.status", 50),
("power.up", 1400),
("sys.unlock", 10000),
];
pub const USB3_READ_ALIGNMENT: usize = 16;
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[non_exhaustive]
pub enum Stream {
Samples,
Digital,
}
impl Stream {
pub const fn token(self) -> &'static str {
match self {
Stream::Samples => "samples",
Stream::Digital => "digital",
}
}
pub fn from_token(s: &str) -> Option<Self> {
Some(match s {
"samples" => Stream::Samples,
"digital" => Stream::Digital,
_ => return None,
})
}
pub const fn max_frame_bytes(self) -> usize {
match self {
Stream::Samples => 2408,
Stream::Digital => 88,
}
}
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[non_exhaustive]
pub enum Kind {
AdioDig,
RhdMatrix,
}
impl Kind {
pub const fn token(self) -> &'static str {
match self {
Kind::AdioDig => "adio_dig",
Kind::RhdMatrix => "rhd_matrix",
}
}
pub fn from_token(s: &str) -> Option<Self> {
Some(match s {
"adio_dig" => Kind::AdioDig,
"rhd_matrix" => Kind::RhdMatrix,
_ => return None,
})
}
pub const fn code(self) -> u8 {
match self {
Kind::AdioDig => 0x10,
Kind::RhdMatrix => 0x20,
}
}
pub fn from_code(c: u8) -> Option<Self> {
Some(match c {
0x10 => Kind::AdioDig,
0x20 => Kind::RhdMatrix,
_ => return None,
})
}
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[non_exhaustive]
pub enum Cap {
CleanFrame,
CommandProtocol,
Ddr3,
Adio,
Grounding,
TtlIn,
SlotHealth,
FieldUpdate,
RateControl,
}
impl Cap {
pub const fn token(self) -> &'static str {
match self {
Cap::CleanFrame => "clean_frame",
Cap::CommandProtocol => "command_protocol",
Cap::Ddr3 => "ddr3",
Cap::Adio => "adio",
Cap::Grounding => "grounding",
Cap::TtlIn => "ttl_in",
Cap::SlotHealth => "slot_health",
Cap::FieldUpdate => "field_update",
Cap::RateControl => "rate_control",
}
}
pub fn from_token(s: &str) -> Option<Self> {
Some(match s {
"clean_frame" => Cap::CleanFrame,
"command_protocol" => Cap::CommandProtocol,
"ddr3" => Cap::Ddr3,
"adio" => Cap::Adio,
"grounding" => Cap::Grounding,
"ttl_in" => Cap::TtlIn,
"slot_health" => Cap::SlotHealth,
"field_update" => Cap::FieldUpdate,
"rate_control" => Cap::RateControl,
_ => return None,
})
}
pub const fn bit(self) -> u32 {
match self {
Cap::CleanFrame => 0,
Cap::CommandProtocol => 1,
Cap::Ddr3 => 2,
Cap::Adio => 3,
Cap::Grounding => 4,
Cap::TtlIn => 5,
Cap::SlotHealth => 6,
Cap::FieldUpdate => 7,
Cap::RateControl => 8,
}
}
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[non_exhaustive]
pub enum DeviceErr {
BadArgs,
UnknownCmd,
TierLocked,
NotPresent,
NoIp,
NoDevice,
I2cNak,
I2cTimeout,
Internal,
Busy,
NotClaimed,
ConfirmRequired,
NotReady,
RoRegister,
NoSuchRegister,
ResponseTooLarge,
}
impl DeviceErr {
pub const fn token(self) -> &'static str {
match self {
DeviceErr::BadArgs => "bad_args",
DeviceErr::UnknownCmd => "unknown_cmd",
DeviceErr::TierLocked => "tier_locked",
DeviceErr::NotPresent => "not_present",
DeviceErr::NoIp => "no_ip",
DeviceErr::NoDevice => "no_device",
DeviceErr::I2cNak => "i2c_nak",
DeviceErr::I2cTimeout => "i2c_timeout",
DeviceErr::Internal => "internal",
DeviceErr::Busy => "busy",
DeviceErr::NotClaimed => "not_claimed",
DeviceErr::ConfirmRequired => "confirm_required",
DeviceErr::NotReady => "not_ready",
DeviceErr::RoRegister => "ro_register",
DeviceErr::NoSuchRegister => "no_such_register",
DeviceErr::ResponseTooLarge => "response_too_large",
}
}
pub fn from_token(s: &str) -> Option<Self> {
Some(match s {
"bad_args" => DeviceErr::BadArgs,
"unknown_cmd" => DeviceErr::UnknownCmd,
"tier_locked" => DeviceErr::TierLocked,
"not_present" => DeviceErr::NotPresent,
"no_ip" => DeviceErr::NoIp,
"no_device" => DeviceErr::NoDevice,
"i2c_nak" => DeviceErr::I2cNak,
"i2c_timeout" => DeviceErr::I2cTimeout,
"internal" => DeviceErr::Internal,
"busy" => DeviceErr::Busy,
"not_claimed" => DeviceErr::NotClaimed,
"confirm_required" => DeviceErr::ConfirmRequired,
"not_ready" => DeviceErr::NotReady,
"ro_register" => DeviceErr::RoRegister,
"no_such_register" => DeviceErr::NoSuchRegister,
"response_too_large" => DeviceErr::ResponseTooLarge,
_ => return None,
})
}
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[non_exhaustive]
pub enum HostErr {
HostTimeout,
HostShortRead,
HostOverflow,
HostUnsafeArg,
}
impl HostErr {
pub const fn token(self) -> &'static str {
match self {
HostErr::HostTimeout => "host_timeout",
HostErr::HostShortRead => "host_short_read",
HostErr::HostOverflow => "host_overflow",
HostErr::HostUnsafeArg => "host_unsafe_arg",
}
}
pub fn from_token(s: &str) -> Option<Self> {
Some(match s {
"host_timeout" => HostErr::HostTimeout,
"host_short_read" => HostErr::HostShortRead,
"host_overflow" => HostErr::HostOverflow,
"host_unsafe_arg" => HostErr::HostUnsafeArg,
_ => return None,
})
}
}
pub(crate) const USB3_REG: &[(&str, &str, u8, Option<u8>, u8)] = &[
("contract_version", "wireout", 0x35, None, 32),
("caps", "wireout", 0x36, None, 32),
("gateware_sha", "wireout", 0x37, None, 32),
("contract_ready", "wireout", 0x31, Some(1), 1),
("quiesce", "wirein", 0x00, Some(0), 1),
("run_samples", "wirein", 0x11, Some(1), 1),
("run_digital", "wirein", 0x11, Some(0), 1),
("lanes_samples", "wirein", 0x12, None, 32),
("burst_digital", "wirein", 0x13, Some(0), 16),
("burst_samples", "wirein", 0x13, Some(16), 16),
("stream_status_samples", "wireout", 0x39, None, 32),
("stream_status_digital", "wireout", 0x38, None, 32),
("occupancy", "wireout", 0x20, None, 32),
("overflow", "wireout", 0x31, Some(0), 1),
("console_tx_drop", "wireout", 0x31, Some(2), 1),
("miso_delay", "wirein", 0x04, None, 32),
("rate_md", "wirein", 0x03, None, 32),
("rate_apply", "triggerin", 0x40, Some(0), 1),
("rate_ready", "wireout", 0x3B, Some(0), 1),
];
#[rustfmt::skip]
pub(crate) const STREAM_REGS: &[(&str, &str, &str, &str, Option<&str>)] = &[
("samples", "run_samples", "burst_samples", "stream_status_samples", Some("lanes_samples")),
("digital", "run_digital", "burst_digital", "stream_status_digital", None),
];
pub(crate) const USB3_STREAM: &[(&str, &str, u8)] = &[
("samples", "okPipeOut", 0xA3),
("digital", "okPipeOut", 0xA2),
];
pub(crate) const USB3_MSG: &[(&str, &str, u8, Option<u8>)] = &[
("status", "wireout", 0x30, None),
("tx_pipe", "okPipeOut", 0xA1, None),
("rx_data", "wirein", 0x0F, None),
("rx_count", "wirein", 0x10, None),
("rx_push", "triggerin", 0x43, Some(0)),
];
pub const ARG_CHARSET: &str = "[A-Za-z0-9_.-]+";
pub const RESP_SENTINEL: u8 = 0x1e;
pub const RESP_LEN_DIGITS: usize = 3;
pub const REQ_TAG: &str = "kdi ";
pub const RESP_MAX_BODY: usize = 480;