From 5c8f361fb143c1e7e251f9038231fb4362b1b517 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Wed, 4 Dec 2024 15:18:19 +0800 Subject: [PATCH] drtio: restore copy_work_buffer for transmission --- src/libboard_artiq/src/drtioaux.rs | 15 +++++++++++++-- src/libboard_artiq/src/drtioaux_async.rs | 8 +++++--- src/libboard_artiq/src/drtioaux_proto.rs | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/libboard_artiq/src/drtioaux.rs b/src/libboard_artiq/src/drtioaux.rs index 9e27ac9..e86847b 100644 --- a/src/libboard_artiq/src/drtioaux.rs +++ b/src/libboard_artiq/src/drtioaux.rs @@ -6,7 +6,7 @@ use io::{proto::{ProtoRead, ProtoWrite}, Cursor}; use libboard_zynq::{time::Milliseconds, timer::GlobalTimer}; -pub use crate::drtioaux_proto::Packet; +pub use crate::drtioaux_proto::{Packet, MAX_PACKET}; use crate::{drtioaux_proto::Error as ProtocolError, mem::mem::DRTIOAUX_MEM, pl::csr::DRTIOAUX}; #[derive(Debug)] @@ -35,6 +35,15 @@ impl From for Error { } } +pub fn copy_work_buffer(src: *mut u32, dst: *mut u32, len: isize) { + // fix for artiq-zynq#344 + unsafe { + for i in 0..(len / 4) { + *dst.offset(i) = *src.offset(i); + } + } +} + pub fn reset(linkno: u8) { let linkno = linkno as usize; unsafe { @@ -115,7 +124,9 @@ where F: FnOnce(&mut [u8]) -> Result { unsafe { while (DRTIOAUX[linkno].aux_tx_read)() != 0 {} let ptr = DRTIOAUX_MEM[linkno].base as *mut u32; - let len = f(slice::from_raw_parts_mut(ptr as *mut u8, 0x400 as usize))?; + let mut buf: [u8; MAX_PACKET] = [0; MAX_PACKET]; + let len = f(&mut buf)?; + copy_work_buffer(buf.as_mut_ptr() as *mut u32, ptr, len as isize); (DRTIOAUX[linkno].aux_tx_length_write)(len as u16); (DRTIOAUX[linkno].aux_tx_write)(1); Ok(()) diff --git a/src/libboard_artiq/src/drtioaux_async.rs b/src/libboard_artiq/src/drtioaux_async.rs index 08f18cf..2666fd8 100644 --- a/src/libboard_artiq/src/drtioaux_async.rs +++ b/src/libboard_artiq/src/drtioaux_async.rs @@ -9,8 +9,8 @@ use libboard_zynq::{time::Milliseconds, timer::GlobalTimer}; use nb; use void::Void; -pub use crate::drtioaux_proto::Packet; -use crate::{drtioaux::{has_rx_error, Error}, +pub use crate::drtioaux_proto::{Packet, MAX_PACKET}; +use crate::{drtioaux::{copy_work_buffer, has_rx_error, Error}, mem::mem::DRTIOAUX_MEM, pl::csr::DRTIOAUX}; @@ -102,7 +102,9 @@ where F: FnOnce(&mut [u8]) -> Result { unsafe { let _ = block_async!(tx_ready(linkno)).await; let ptr = DRTIOAUX_MEM[linkno].base as *mut u32; - let len = f(slice::from_raw_parts_mut(ptr as *mut u8, 0x400 as usize))?; + let mut buf: [u8; MAX_PACKET] = [0; MAX_PACKET]; + let len = f(&mut buf)?; + copy_work_buffer(buf.as_mut_ptr() as *mut u32, ptr, len as isize); (DRTIOAUX[linkno].aux_tx_length_write)(len as u16); (DRTIOAUX[linkno].aux_tx_write)(1); Ok(()) diff --git a/src/libboard_artiq/src/drtioaux_proto.rs b/src/libboard_artiq/src/drtioaux_proto.rs index d00cf96..173aa9c 100644 --- a/src/libboard_artiq/src/drtioaux_proto.rs +++ b/src/libboard_artiq/src/drtioaux_proto.rs @@ -1,7 +1,7 @@ use core_io::{Error as IoError, Read, Write}; use io::proto::{ProtoRead, ProtoWrite}; -const MAX_PACKET: usize = 1024; +pub const MAX_PACKET: usize = 1024; // maximum size of arbitrary payloads // used by satellite -> master analyzer, subkernel exceptions -- 2.47.0