forked from M-Labs/artiq-zynq
proto fw: handle ring buffer
This commit is contained in:
parent
f9da1dddf9
commit
9305336ba4
|
@ -22,19 +22,6 @@ pub enum Error {
|
|||
UnknownPacket(u8),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CtrlError {
|
||||
AddressReadOnly,
|
||||
AddressWriteOnly,
|
||||
CRCFailed,
|
||||
DataSizeDifferent,
|
||||
InvalidAddress,
|
||||
InvalidData,
|
||||
InvalidOpcode,
|
||||
MalformedPacket,
|
||||
SizeToolarge,
|
||||
}
|
||||
|
||||
impl From<IoError> for Error {
|
||||
fn from(_: IoError) -> Error {
|
||||
Error::BufferError
|
||||
|
@ -137,17 +124,25 @@ impl DownConnPacket {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn receive(channel: usize) -> Result<(), Error> {
|
||||
pub fn receive(channel: usize) -> Result<Option<DownConnPacket>, Error> {
|
||||
unsafe {
|
||||
let ptr = CXP_RX_MEM[channel].base as *mut u32;
|
||||
let mut reader = Cursor::new(slice::from_raw_parts_mut(ptr as *mut u8, MEM_LEN));
|
||||
if (CXP[channel].downconn_pending_packet_read)() == 1 {
|
||||
let read_buffer_ptr = (CXP[channel].downconn_read_ptr_read)() as usize;
|
||||
println!("buffer ptr = {}", read_buffer_ptr);
|
||||
let ptr = (CXP_RX_MEM[channel].base + read_buffer_ptr * MEM_LEN) as *mut u8;
|
||||
|
||||
let mut reader = Cursor::new(slice::from_raw_parts_mut(ptr, MEM_LEN));
|
||||
let packet_type = (CXP[channel].downconn_packet_type_read)();
|
||||
|
||||
let packet = DownConnPacket::read_from(&mut reader, packet_type);
|
||||
|
||||
println!("{:?}", packet);
|
||||
|
||||
(CXP[channel].downconn_pending_packet_write)(1);
|
||||
Ok(Some(packet?))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
trait CxpWrite {
|
||||
|
@ -405,8 +400,9 @@ pub fn downconn_debug_send(channel: usize, packet: &UpConnPacket) -> Result<(),
|
|||
|
||||
pub fn downconn_debug_mem_print(channel: usize) {
|
||||
unsafe {
|
||||
let ptr = CXP_RX_MEM[channel].base as *mut u32;
|
||||
print_packet(slice::from_raw_parts_mut(ptr as *mut u8, MEM_LEN));
|
||||
let ptr = CXP_RX_MEM[channel].base as *mut u8;
|
||||
let arr = slice::from_raw_parts_mut(ptr, MEM_LEN * 4);
|
||||
print_packet(arr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue