diff --git a/src/libboard_artiq/src/cxp_proto.rs b/src/libboard_artiq/src/cxp_proto.rs index 604e5ca..83b9368 100644 --- a/src/libboard_artiq/src/cxp_proto.rs +++ b/src/libboard_artiq/src/cxp_proto.rs @@ -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 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, 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)); - let packet_type = (CXP[channel].downconn_packet_type_read)(); + 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 packet = DownConnPacket::read_from(&mut reader, packet_type); + let mut reader = Cursor::new(slice::from_raw_parts_mut(ptr, MEM_LEN)); + let packet_type = (CXP[channel].downconn_packet_type_read)(); - println!("{:?}", packet); + 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); } }