rtio_mgt: implement ddma related functions

add kernel messages
pull/225/head
mwojcik 2023-03-23 17:13:34 +08:00
parent 963af1f04f
commit f1ef0219c3
3 changed files with 99 additions and 61 deletions

View File

@ -17,6 +17,7 @@ pub struct DmaRecorder {
pub name: String, pub name: String,
pub buffer: Vec<u8>, pub buffer: Vec<u8>,
pub duration: i64, pub duration: i64,
pub enable_ddma: bool
} }
static mut RECORDER: Option<DmaRecorder> = None; static mut RECORDER: Option<DmaRecorder> = None;
@ -50,11 +51,12 @@ pub extern "C" fn dma_record_start(name: CSlice<u8>) {
name, name,
buffer: Vec::new(), buffer: Vec::new(),
duration: 0, duration: 0,
enable_ddma: false
}); });
} }
} }
pub extern "C" fn dma_record_stop(duration: i64) { pub extern "C" fn dma_record_stop(duration: i64, enable_ddma: bool) {
unsafe { unsafe {
if RECORDER.is_none() { if RECORDER.is_none() {
artiq_raise!("DMAError", "DMA is not recording") artiq_raise!("DMAError", "DMA is not recording")
@ -68,6 +70,7 @@ pub extern "C" fn dma_record_stop(duration: i64) {
let mut recorder = RECORDER.take().unwrap(); let mut recorder = RECORDER.take().unwrap();
recorder.duration = duration; recorder.duration = duration;
recorder.enable_ddma = enable_ddma;
KERNEL_CHANNEL_1TO0 KERNEL_CHANNEL_1TO0
.as_mut() .as_mut()
.unwrap() .unwrap()

View File

@ -53,6 +53,22 @@ pub enum Message {
DmaEraseRequest(String), DmaEraseRequest(String),
DmaGetRequest(String), DmaGetRequest(String),
DmaGetReply(Option<(i32, i64)>), DmaGetReply(Option<(i32, i64)>),
#[cfg(has_drtio)]
DmaStartRemoteRequest {
id: i32,
timestamp: i64
},
#[cfg(has_drtio)]
DmaAwaitRemoteRequest {
id: i32
},
#[cfg(has_drtio)]
DmaAwaitRemoteReply {
timeout: bool,
error: u8,
channel: u32,
timestamp: u64
},
#[cfg(has_drtio)] #[cfg(has_drtio)]
UpDestinationsRequest(i32), UpDestinationsRequest(i32),

View File

@ -13,13 +13,16 @@ static mut RTIO_DEVICE_MAP: BTreeMap<u32, String> = BTreeMap::new();
#[cfg(has_drtio)] #[cfg(has_drtio)]
pub mod drtio { pub mod drtio {
use embedded_hal::blocking::delay::DelayMs; use embedded_hal::blocking::delay::DelayMs;
use alloc::vec::Vec;
use libasync::{delay, task}; use libasync::{delay, task};
use libboard_artiq::{drtioaux::Error, drtioaux_async, drtioaux_async::Packet}; use libboard_artiq::{drtioaux::Error, drtioaux_async, drtioaux_async::Packet};
use libboard_artiq::drtioaux_proto::DMA_TRACE_MAX_SIZE;
use libboard_zynq::time::Milliseconds; use libboard_zynq::time::Milliseconds;
use log::{error, info, warn}; use log::{error, info, warn};
use super::*; use super::*;
use crate::{ASYNC_ERROR_BUSY, ASYNC_ERROR_COLLISION, ASYNC_ERROR_SEQUENCE_ERROR, SEEN_ASYNC_ERRORS}; use crate::{ASYNC_ERROR_BUSY, ASYNC_ERROR_COLLISION, ASYNC_ERROR_SEQUENCE_ERROR, SEEN_ASYNC_ERRORS};
use crate::rtio_dma::remote_dma;
pub fn startup( pub fn startup(
aux_mutex: &Rc<Mutex<bool>>, aux_mutex: &Rc<Mutex<bool>>,
@ -390,69 +393,85 @@ pub mod drtio {
} }
} }
// pub fn ddma_upload_trace(aux_mutex: Rc<Mutex<bool>>, pub async fn ddma_upload_trace(
// routing_table: &drtio_routing::RoutingTable, aux_mutex: &Rc<Mutex<bool>>,
// id: u32, destination: u8, trace: &Vec<u8>) -> Result<(), &'static str> { routing_table: &drtio_routing::RoutingTable,
// let linkno = routing_table.0[destination as usize][0] - 1; timer: GlobalTimer,
// let mut i = 0; id: u32,
// while i < trace.len() { destination: u8,
// let mut trace_slice: [u8; DMA_TRACE_MAX_SIZE] = [0; DMA_TRACE_MAX_SIZE]; trace: &Vec<u8>
// let len: usize = if i + DMA_TRACE_MAX_SIZE < trace.len() { DMA_TRACE_MAX_SIZE } else { trace.len() - i } as usize; ) -> Result<(), &'static str> {
// let last = i + len == trace.len(); let linkno = routing_table.0[destination as usize][0] - 1;
// trace_slice[..len].clone_from_slice(&trace[i..i+len]); let mut i = 0;
// i += len; while i < trace.len() {
// let reply = aux_transact(io, aux_mutex, linkno, let mut trace_slice: [u8; DMA_TRACE_MAX_SIZE] = [0; DMA_TRACE_MAX_SIZE];
// &drtioaux::Packet::DmaAddTraceRequest { let len: usize = if i + DMA_TRACE_MAX_SIZE < trace.len() { DMA_TRACE_MAX_SIZE } else { trace.len() - i } as usize;
// id: id, destination: destination, last: last, length: len as u16, trace: trace_slice}); let last = i + len == trace.len();
// match reply { trace_slice[..len].clone_from_slice(&trace[i..i+len]);
// Ok(drtioaux::Packet::DmaAddTraceReply { succeeded: true }) => (), i += len;
// Ok(drtioaux::Packet::DmaAddTraceReply { succeeded: false }) => { let reply = aux_transact(aux_mutex, linkno,
// return Err("error adding trace on satellite"); }, &Packet::DmaAddTraceRequest {
// Ok(_) => { return Err("adding DMA trace failed, unexpected aux packet"); }, id: id, destination: destination, last: last, length: len as u16, trace: trace_slice},
// Err(_) => { return Err("adding DMA trace failed, aux error"); } timer).await;
// } match reply {
// } Ok(Packet::DmaAddTraceReply { succeeded: true }) => (),
// Ok(()) Ok(Packet::DmaAddTraceReply { succeeded: false }) => {
// } return Err("error adding trace on satellite"); },
Ok(_) => { return Err("adding DMA trace failed, unexpected aux packet"); },
Err(_) => { return Err("adding DMA trace failed, aux error"); }
}
}
Ok(())
}
// pub fn ddma_send_erase(io: &Io, aux_mutex: &Mutex, pub async fn ddma_send_erase(
// routing_table: &drtio_routing::RoutingTable, aux_mutex: &Rc<Mutex<bool>>,
// id: u32, destination: u8) -> Result<(), &'static str> { routing_table: &drtio_routing::RoutingTable,
// let linkno = routing_table.0[destination as usize][0] - 1; timer: GlobalTimer,
// let reply = aux_transact(io, aux_mutex, linkno, id: u32,
// &drtioaux::Packet::DmaRemoveTraceRequest { id: id, destination: destination }); destination: u8
// match reply { ) -> Result<(), &'static str> {
// Ok(drtioaux::Packet::DmaRemoveTraceReply { succeeded: true }) => Ok(()), let linkno = routing_table.0[destination as usize][0] - 1;
// Ok(drtioaux::Packet::DmaRemoveTraceReply { succeeded: false }) => Err("satellite DMA erase error"), let reply = aux_transact(aux_mutex, linkno,
// Ok(_) => Err("adding trace failed, unexpected aux packet"), &Packet::DmaRemoveTraceRequest { id: id, destination: destination },
// Err(_) => Err("erasing trace failed, aux error") timer).await;
// } match reply {
// } Ok(Packet::DmaRemoveTraceReply { succeeded: true }) => Ok(()),
Ok(Packet::DmaRemoveTraceReply { succeeded: false }) => Err("satellite DMA erase error"),
Ok(_) => Err("adding trace failed, unexpected aux packet"),
Err(_) => Err("erasing trace failed, aux error")
}
}
// pub fn ddma_send_playback(io: &Io, aux_mutex: &Mutex, pub async fn ddma_send_playback(
// routing_table: &drtio_routing::RoutingTable, aux_mutex: &Rc<Mutex<bool>>,
// ddma_mutex: &Mutex, id: u32, destination: u8, timestamp: u64) -> Result<(), &'static str> { routing_table: &drtio_routing::RoutingTable,
// let linkno = routing_table.0[destination as usize][0] - 1; timer: GlobalTimer,
// let _lock = aux_mutex.lock(io).unwrap(); id: u32,
// drtioaux::send(linkno, &drtioaux::Packet::DmaPlaybackRequest{ destination: u8,
// id: id, destination: destination, timestamp: timestamp }).unwrap(); timestamp: u64
// loop { ) -> Result<(), &'static str> {
// let reply = recv_aux_timeout(io, linkno, 200); let linkno = routing_table.0[destination as usize][0] - 1;
// match reply { let _lock = aux_mutex.async_lock().await;
// Ok(drtioaux::Packet::DmaPlaybackReply { succeeded: true }) => { return Ok(()) }, drtioaux_async::send(linkno, &Packet::DmaPlaybackRequest{
// Ok(drtioaux::Packet::DmaPlaybackReply { succeeded: false }) => { id: id, destination: destination, timestamp: timestamp }).await.unwrap();
// return Err("error on DMA playback request") }, loop {
// // in case we received status from another destination let reply = recv_aux_timeout(linkno, 200, timer).await;
// // but we want to get DmaPlaybackReply anyway, thus the loop match reply {
// Ok(drtioaux::Packet::DmaPlaybackStatus { id, destination, error, channel, timestamp }) => { Ok(Packet::DmaPlaybackReply { succeeded: true }) => { return Ok(()) },
// remote_dma::playback_done(io, ddma_mutex, id, destination, error, channel, timestamp); Ok(Packet::DmaPlaybackReply { succeeded: false }) => {
// }, return Err("error on DMA playback request") },
// Ok(_) => { return Err("received unexpected aux packet while DMA playback") }, // in case we received status from another destination
// Err(_) => { return Err("aux error on DMA playback") } // but we want to get DmaPlaybackReply anyway, thus the loop
// } Ok(Packet::DmaPlaybackStatus { id, destination, error, channel, timestamp }) => {
// } remote_dma::playback_done(id, destination, error, channel, timestamp).await;
// } },
Ok(_) => { return Err("received unexpected aux packet while DMA playback") },
Err(_) => { return Err("aux error on DMA playback") }
}
}
}
} }
fn read_device_map(cfg: &Config) -> BTreeMap<u32, String> { fn read_device_map(cfg: &Config) -> BTreeMap<u32, String> {