forked from M-Labs/artiq-zynq
proto fw: use new csr
proto: fix compilation warning proto fw: add rx memory test
This commit is contained in:
parent
44246c293d
commit
186534ff01
|
@ -2,21 +2,22 @@ use core::slice;
|
||||||
|
|
||||||
use core_io::{Error as IoError, Write};
|
use core_io::{Error as IoError, Write};
|
||||||
use crc::crc32;
|
use crc::crc32;
|
||||||
use embedded_hal::prelude::_embedded_hal_blocking_delay_DelayUs;
|
|
||||||
use io::Cursor;
|
use io::Cursor;
|
||||||
use libboard_zynq::{println, timer::GlobalTimer};
|
use libboard_zynq::println;
|
||||||
|
|
||||||
use crate::{mem::mem::{CXP_LOOPBACK_MEM, CXP_MEM},
|
// TODO: fix the import
|
||||||
pl::csr};
|
use crate::{mem::mem::{CXP_LOOPBACK_MEM, CXP_RX_MEM, CXP_TX_MEM},
|
||||||
|
pl::csr::CXP};
|
||||||
|
|
||||||
const MAX_PACKET: usize = 128;
|
const MAX_PACKET: usize = 128;
|
||||||
const DATA_MAXSIZE: usize = /*max size*/MAX_PACKET - /*Tag*/4 - /*Op code & length*/4 - /*addr*/4 - /*CRC*/4 ;
|
const DATA_MAXSIZE: usize = /*max size*/MAX_PACKET - /*Tag*/4 - /*Op code & length*/4 - /*addr*/4 - /*CRC*/4 ;
|
||||||
const MEM_SIZE: usize = 0x200;
|
const MEM_LEN: usize = 0x200;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
BufferError,
|
BufferError,
|
||||||
LinkDown,
|
LinkDown,
|
||||||
|
UnknownPacket(u8),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<IoError> for Error {
|
impl From<IoError> for Error {
|
||||||
|
@ -109,72 +110,89 @@ impl Packet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send(packet: &Packet) -> Result<(), Error> {
|
pub fn receive(channel: usize) -> Result<(), Error> {
|
||||||
if unsafe { csr::cxp::upconn_tx_enable_read() } == 0 {
|
unsafe {
|
||||||
|
// let ptr = CXP_LOOPBACK_MEM[0].base as *mut u32;
|
||||||
|
let ptr = CXP_RX_MEM[0].base as *mut u32;
|
||||||
|
// let mut reader = Cursor::new(slice::from_raw_parts_mut(ptr as *mut u8, MEM_LEN));
|
||||||
|
|
||||||
|
print_packet(slice::from_raw_parts_mut(ptr as *mut u8, MEM_LEN));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn send(channel: usize, packet: &Packet) -> Result<(), Error> {
|
||||||
|
if unsafe { (CXP[channel].upconn_tx_enable_read)() } == 0 {
|
||||||
Err(Error::LinkDown)?
|
Err(Error::LinkDown)?
|
||||||
}
|
}
|
||||||
|
|
||||||
match *packet {
|
match *packet {
|
||||||
Packet::TestPacket => send_test_packet(),
|
Packet::TestPacket => send_test_packet(channel),
|
||||||
_ => send_data_packet(packet),
|
_ => send_data_packet(channel, packet),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_data_packet(packet: &Packet) -> Result<(), Error> {
|
fn send_data_packet(channel: usize, packet: &Packet) -> Result<(), Error> {
|
||||||
unsafe {
|
unsafe {
|
||||||
// TODO: put this in mem group
|
// TODO: put this in mem group
|
||||||
while csr::cxp::upconn_command_tx_read() == 1 {}
|
while (CXP[channel].upconn_command_tx_read)() == 1 {}
|
||||||
let ptr = CXP_MEM[0].base as *mut u32;
|
let ptr = CXP_TX_MEM[0].base as *mut u32;
|
||||||
let mut writer = Cursor::new(slice::from_raw_parts_mut(ptr as *mut u8, MEM_SIZE));
|
let mut writer = Cursor::new(slice::from_raw_parts_mut(ptr as *mut u8, MEM_LEN));
|
||||||
|
|
||||||
packet.write_to(&mut writer)?;
|
packet.write_to(&mut writer)?;
|
||||||
|
|
||||||
csr::cxp::upconn_command_tx_word_len_write(writer.position() as u8 / 4);
|
(CXP[channel].upconn_command_tx_word_len_write)(writer.position() as u8 / 4);
|
||||||
csr::cxp::upconn_command_tx_write(1);
|
(CXP[channel].upconn_command_tx_write)(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_test_packet() -> Result<(), Error> {
|
fn send_test_packet(channel: usize) -> Result<(), Error> {
|
||||||
unsafe {
|
unsafe {
|
||||||
while csr::cxp::upconn_testseq_tx_read() == 1 {}
|
while (CXP[channel].upconn_testseq_tx_read)() == 1 {}
|
||||||
csr::cxp::upconn_tx_testmode_en_write(1);
|
(CXP[channel].upconn_tx_testmode_en_write)(1);
|
||||||
csr::cxp::upconn_testseq_tx_write(1);
|
(CXP[channel].upconn_testseq_tx_write)(1);
|
||||||
|
|
||||||
// wait till all test packet is out before switching back
|
// wait till all test packet is out before switching back
|
||||||
while csr::cxp::upconn_testseq_tx_read() == 1 {}
|
while (CXP[channel].upconn_testseq_tx_read)() == 1 {}
|
||||||
csr::cxp::upconn_tx_testmode_en_write(0);
|
(CXP[channel].upconn_tx_testmode_en_write)(0);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_u32(addr: u32, data: u32) -> Result<(), Error> {
|
pub fn write_u32(channel: usize, addr: u32, data: u32) -> Result<(), Error> {
|
||||||
let mut data_slice: [u8; DATA_MAXSIZE] = [0; DATA_MAXSIZE];
|
let mut data_slice: [u8; DATA_MAXSIZE] = [0; DATA_MAXSIZE];
|
||||||
data_slice[..4].clone_from_slice(&data.to_be_bytes());
|
data_slice[..4].clone_from_slice(&data.to_be_bytes());
|
||||||
send(&Packet::CtrlWrite {
|
send(
|
||||||
addr,
|
channel,
|
||||||
length: 4,
|
&Packet::CtrlWrite {
|
||||||
data: data_slice,
|
addr,
|
||||||
})?;
|
length: 4,
|
||||||
|
data: data_slice,
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_u32(addr: u32) -> Result<(), Error> {
|
pub fn read_u32(channel: usize, addr: u32) -> Result<(), Error> {
|
||||||
send(&Packet::CtrlRead { addr, length: 4 })?;
|
send(channel, &Packet::CtrlRead { addr, length: 4 })?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_u64(addr: u32, data: u64) -> Result<(), Error> {
|
pub fn write_u64(channel: usize, addr: u32, data: u64) -> Result<(), Error> {
|
||||||
let mut data_slice: [u8; DATA_MAXSIZE] = [0; DATA_MAXSIZE];
|
let mut data_slice: [u8; DATA_MAXSIZE] = [0; DATA_MAXSIZE];
|
||||||
data_slice[..8].clone_from_slice(&data.to_be_bytes());
|
data_slice[..8].clone_from_slice(&data.to_be_bytes());
|
||||||
send(&Packet::CtrlWrite {
|
send(
|
||||||
addr,
|
channel,
|
||||||
length: 8,
|
&Packet::CtrlWrite {
|
||||||
data: data_slice,
|
addr,
|
||||||
})?;
|
length: 8,
|
||||||
|
data: data_slice,
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -214,36 +232,36 @@ pub fn print_packetu32(pak: &[u32], k: &[u8]) {
|
||||||
println!("============================================");
|
println!("============================================");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn downconn_debug_send(packet: &Packet) -> Result<(), Error> {
|
pub fn downconn_debug_send(channel: usize, packet: &Packet) -> Result<(), Error> {
|
||||||
unsafe {
|
unsafe {
|
||||||
// TODO: put this in mem group
|
// TODO: put this in mem group
|
||||||
while csr::cxp::downconn_command_tx_read() == 1 {}
|
while (CXP[channel].downconn_command_tx_read)() == 1 {}
|
||||||
let ptr = CXP_LOOPBACK_MEM[0].base as *mut u32;
|
let ptr = CXP_LOOPBACK_MEM[0].base as *mut u32;
|
||||||
let mut writer = Cursor::new(slice::from_raw_parts_mut(ptr as *mut u8, MEM_SIZE));
|
let mut writer = Cursor::new(slice::from_raw_parts_mut(ptr as *mut u8, MEM_LEN));
|
||||||
|
|
||||||
packet.write_to(&mut writer)?;
|
packet.write_to(&mut writer)?;
|
||||||
|
|
||||||
csr::cxp::downconn_command_tx_word_len_write(writer.position() as u8 / 4);
|
(CXP[channel].downconn_command_tx_word_len_write)(writer.position() as u8 / 4);
|
||||||
csr::cxp::downconn_command_tx_write(1);
|
(CXP[channel].downconn_command_tx_write)(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn downconn_debug_send_trig_ack() {
|
pub fn downconn_debug_send_trig_ack(channel: usize) {
|
||||||
unsafe {
|
unsafe {
|
||||||
csr::cxp::downconn_ack_write(1);
|
(CXP[channel].downconn_ack_write)(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn downconn_send_test_packet() {
|
pub fn downconn_send_test_packet(channel: usize) {
|
||||||
unsafe {
|
unsafe {
|
||||||
while csr::cxp::downconn_testseq_tx_read() == 1 {}
|
while (CXP[channel].downconn_testseq_tx_read)() == 1 {}
|
||||||
csr::cxp::downconn_mux_sel_write(1);
|
(CXP[channel].downconn_mux_sel_write)(1);
|
||||||
csr::cxp::downconn_testseq_tx_write(1);
|
(CXP[channel].downconn_testseq_tx_write)(1);
|
||||||
|
|
||||||
// wait till all test packet is out before switching back
|
// wait till all test packet is out before switching back
|
||||||
while csr::cxp::downconn_testseq_tx_read() == 1 {}
|
while (CXP[channel].downconn_testseq_tx_read)() == 1 {}
|
||||||
csr::cxp::downconn_mux_sel_write(0);
|
(CXP[channel].downconn_mux_sel_write)(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue