Skip to main content

libbladerf_rs/protocol/
nios.rs

1pub mod packet_generic;
2pub mod targets;
3use crate::error::Error;
4use crate::protocol::nios::packet_generic::{NiosNum, NiosPktDecoder};
5pub use packet_generic::{NiosPacket, NiosPkt, NiosPktFlags, NiosPktStatus};
6pub use targets::{
7    NiosPkt8x8Target, NiosPkt8x16AddrIqCorr, NiosPkt8x16Target, NiosPkt8x32Target,
8    NiosPkt32x32Target,
9};
10#[derive(thiserror::Error, Debug)]
11pub enum NiosPacketError {
12    #[error("nfrac value {0} exceeds maximum 0x7FFFFF")]
13    NfracOverflow(u32),
14    #[error("freqsel value {0} exceeds maximum {1}")]
15    FreqselOverflow(u8, u8),
16    #[error("vcocap value {0} exceeds maximum {1}")]
17    VcocapOverflow(u8, u8),
18    #[error("invalid packet size: expected 16 bytes, got {0}")]
19    InvalidSize(usize),
20}
21pub const MIN_RESPONSE_SIZE: usize = 16;
22pub fn nios_encode_read<A: NiosNum, D: NiosNum>(buf: &mut [u8], target: u8, addr: A) {
23    NiosPkt::<A, D>::new(buf).prepare_read(target, addr);
24}
25pub fn nios_encode_write<A: NiosNum, D: NiosNum>(buf: &mut [u8], target: u8, addr: A, data: D) {
26    NiosPkt::<A, D>::new(buf).prepare_write(target, addr, data);
27}
28pub fn nios_decode_read<A: NiosNum, D: NiosNum>(response: &[u8]) -> Result<D, Error> {
29    NiosPktDecoder::decode_data::<A, D>(response)
30}
31pub fn nios_decode_write(_response: &[u8]) -> Result<(), Error> {
32    Ok(())
33}