Compare commits

..

No commits in common. "6088e6bb6f4a741cb90ece386e709d6c75fc3f41" and "9aabaacb21430d0f1852d919c695f9dfe2f44910" have entirely different histories.

6 changed files with 131 additions and 183 deletions

View File

@ -486,7 +486,7 @@ class _SatelliteBase(SoCCore):
enable_routing=True) enable_routing=True)
self.csr_devices.append("cri_con") self.csr_devices.append("cri_con")
self.submodules.rtio_analyzer = analyzer.Analyzer(self.rtio_tsc, self.local_io.cri, self.submodules.rtio_analyzer = analyzer.Analyzer(self.rtio_tsc, self.rtio_core.cri,
self.ps7.s_axi_hp1) self.ps7.s_axi_hp1)
self.csr_devices.append("rtio_analyzer") self.csr_devices.append("rtio_analyzer")

View File

@ -137,7 +137,7 @@ pub enum Packet {
}, },
AnalyzerHeaderRequest { AnalyzerHeaderRequest {
destination: u8, destination: u8
}, },
AnalyzerHeader { AnalyzerHeader {
sent_bytes: u32, sent_bytes: u32,
@ -316,7 +316,7 @@ impl Packet {
}, },
0xa0 => Packet::AnalyzerHeaderRequest { 0xa0 => Packet::AnalyzerHeaderRequest {
destination: reader.read_u8()?, destination: reader.read_u8()?
}, },
0xa1 => Packet::AnalyzerHeader { 0xa1 => Packet::AnalyzerHeader {
sent_bytes: reader.read_u32()?, sent_bytes: reader.read_u32()?,
@ -324,7 +324,7 @@ impl Packet {
overflow_occurred: reader.read_bool()?, overflow_occurred: reader.read_bool()?,
}, },
0xa2 => Packet::AnalyzerDataRequest { 0xa2 => Packet::AnalyzerDataRequest {
destination: reader.read_u8()?, destination: reader.read_u8()?
}, },
0xa3 => { 0xa3 => {
let last = reader.read_bool()?; let last = reader.read_bool()?;
@ -334,9 +334,9 @@ impl Packet {
Packet::AnalyzerData { Packet::AnalyzerData {
last: last, last: last,
length: length, length: length,
data: data, data: data
}
} }
},
0xb0 => { 0xb0 => {
let destination = reader.read_u8()?; let destination = reader.read_u8()?;
@ -573,7 +573,7 @@ impl Packet {
Packet::AnalyzerHeader { Packet::AnalyzerHeader {
sent_bytes, sent_bytes,
total_byte_count, total_byte_count,
overflow_occurred, overflow_occurred
} => { } => {
writer.write_u8(0xa1)?; writer.write_u8(0xa1)?;
writer.write_u32(sent_bytes)?; writer.write_u32(sent_bytes)?;
@ -584,7 +584,11 @@ impl Packet {
writer.write_u8(0xa2)?; writer.write_u8(0xa2)?;
writer.write_u8(destination)?; writer.write_u8(destination)?;
} }
Packet::AnalyzerData { last, length, data } => { Packet::AnalyzerData {
last,
length,
data
} => {
writer.write_u8(0xa3)?; writer.write_u8(0xa3)?;
writer.write_bool(last)?; writer.write_bool(last)?;
writer.write_u16(length)?; writer.write_u16(length)?;

View File

@ -1,11 +1,10 @@
use alloc::{rc::Rc, vec::Vec};
use core::cell::RefCell;
use libasync::{smoltcp::TcpStream, task}; use libasync::{smoltcp::TcpStream, task};
use libboard_artiq::drtio_routing;
use libboard_zynq::{smoltcp::Error, timer::GlobalTimer}; use libboard_zynq::{smoltcp::Error, timer::GlobalTimer};
use libcortex_a9::{cache, mutex::Mutex}; use libcortex_a9::{cache, mutex::Mutex};
use log::{debug, error, info, warn}; use log::{debug, info, warn, error};
use core::cell::RefCell;
use alloc::{rc::Rc, vec::Vec};
use libboard_artiq::drtio_routing;
use crate::{pl, proto_async::*}; use crate::{pl, proto_async::*};
@ -50,15 +49,13 @@ pub mod remote_analyzer {
pub total_byte_count: u64, pub total_byte_count: u64,
pub sent_bytes: u32, pub sent_bytes: u32,
pub error: bool, pub error: bool,
pub data: Vec<u8>, pub data: Vec<u8>
} }
pub async fn get_data( pub async fn get_data(aux_mutex: &Rc<Mutex<bool>>,
aux_mutex: &Rc<Mutex<bool>>,
routing_table: &drtio_routing::RoutingTable, routing_table: &drtio_routing::RoutingTable,
up_destinations: &Rc<RefCell<[bool; drtio_routing::DEST_COUNT]>>, up_destinations: &Rc<RefCell<[bool; drtio_routing::DEST_COUNT]>>,
timer: GlobalTimer, timer: GlobalTimer) -> Result<RemoteBuffer, &'static str> {
) -> Result<RemoteBuffer, &'static str> {
// gets data from satellites and returns consolidated data // gets data from satellites and returns consolidated data
let mut remote_data: Vec<u8> = Vec::new(); let mut remote_data: Vec<u8> = Vec::new();
let mut remote_error = false; let mut remote_error = false;
@ -67,7 +64,7 @@ pub mod remote_analyzer {
let data_vec = match drtio::analyzer_query(aux_mutex, routing_table, up_destinations, timer).await { let data_vec = match drtio::analyzer_query(aux_mutex, routing_table, up_destinations, timer).await {
Ok(data_vec) => data_vec, Ok(data_vec) => data_vec,
Err(e) => return Err(e), Err(e) => return Err(e)
}; };
for data in data_vec { for data in data_vec {
remote_total_bytes += data.total_byte_count; remote_total_bytes += data.total_byte_count;
@ -80,7 +77,7 @@ pub mod remote_analyzer {
total_byte_count: remote_total_bytes, total_byte_count: remote_total_bytes,
sent_bytes: remote_sent_bytes, sent_bytes: remote_sent_bytes,
error: remote_error, error: remote_error,
data: remote_data, data: remote_data
}) })
} }
} }
@ -104,13 +101,10 @@ async fn write_header(stream: &mut TcpStream, header: &Header) -> Result<(), Err
Ok(()) Ok(())
} }
async fn handle_connection( async fn handle_connection(stream: &mut TcpStream, _aux_mutex: &Rc<Mutex<bool>>,
stream: &mut TcpStream,
_aux_mutex: &Rc<Mutex<bool>>,
_routing_table: &drtio_routing::RoutingTable, _routing_table: &drtio_routing::RoutingTable,
_up_destinations: &Rc<RefCell<[bool; drtio_routing::DEST_COUNT]>>, _up_destinations: &Rc<RefCell<[bool; drtio_routing::DEST_COUNT]>>,
_timer: GlobalTimer, _timer: GlobalTimer) -> Result<(), Error> {
) -> Result<(), Error> {
info!("received connection"); info!("received connection");
let data = unsafe { &BUFFER.data[..] }; let data = unsafe { &BUFFER.data[..] };
@ -119,11 +113,7 @@ async fn handle_connection(
let total_byte_count = unsafe { pl::csr::rtio_analyzer::dma_byte_count_read() as u64 }; let total_byte_count = unsafe { pl::csr::rtio_analyzer::dma_byte_count_read() as u64 };
let pointer = (total_byte_count % BUFFER_SIZE as u64) as usize; let pointer = (total_byte_count % BUFFER_SIZE as u64) as usize;
let wraparound = total_byte_count >= BUFFER_SIZE as u64; let wraparound = total_byte_count >= BUFFER_SIZE as u64;
let sent_bytes = if wraparound { let sent_bytes = if wraparound { BUFFER_SIZE as u32 } else { total_byte_count as u32 };
BUFFER_SIZE as u32
} else {
total_byte_count as u32
};
if overflow_occurred { if overflow_occurred {
warn!("overflow occured"); warn!("overflow occured");
@ -136,28 +126,23 @@ async fn handle_connection(
let remote = remote_analyzer::get_data(_aux_mutex, _routing_table, _up_destinations, _timer).await; let remote = remote_analyzer::get_data(_aux_mutex, _routing_table, _up_destinations, _timer).await;
#[cfg(has_drtio)] #[cfg(has_drtio)]
let (header, remote_data) = match remote { let (header, remote_data) = match remote {
Ok(remote) => ( Ok(remote) => (Header {
Header {
total_byte_count: total_byte_count + remote.total_byte_count, total_byte_count: total_byte_count + remote.total_byte_count,
sent_bytes: sent_bytes + remote.sent_bytes, sent_bytes: sent_bytes + remote.sent_bytes,
error_occurred: overflow_occurred | bus_error_occurred | remote.error, error_occurred: overflow_occurred | bus_error_occurred | remote.error,
log_channel: pl::csr::CONFIG_RTIO_LOG_CHANNEL as u8, log_channel: pl::csr::CONFIG_RTIO_LOG_CHANNEL as u8,
dds_onehot_sel: true, dds_onehot_sel: true
}, }, remote.data),
remote.data,
),
Err(e) => { Err(e) => {
error!("Error getting remote analyzer data: {}", e); error!("Error getting remote analyzer data: {}", e);
( (Header {
Header {
total_byte_count: total_byte_count, total_byte_count: total_byte_count,
sent_bytes: sent_bytes, sent_bytes: sent_bytes,
error_occurred: true, error_occurred: true,
log_channel: pl::csr::CONFIG_RTIO_LOG_CHANNEL as u8, log_channel: pl::csr::CONFIG_RTIO_LOG_CHANNEL as u8,
dds_onehot_sel: true, dds_onehot_sel: true
}, },
Vec::new(), Vec::new())
)
} }
}; };
@ -184,12 +169,10 @@ async fn handle_connection(
Ok(()) Ok(())
} }
pub fn start( pub fn start(aux_mutex: &Rc<Mutex<bool>>,
aux_mutex: &Rc<Mutex<bool>>,
routing_table: &Rc<RefCell<drtio_routing::RoutingTable>>, routing_table: &Rc<RefCell<drtio_routing::RoutingTable>>,
up_destinations: &Rc<RefCell<[bool; drtio_routing::DEST_COUNT]>>, up_destinations: &Rc<RefCell<[bool; drtio_routing::DEST_COUNT]>>,
timer: GlobalTimer, timer: GlobalTimer,) {
) {
let aux_mutex = aux_mutex.clone(); let aux_mutex = aux_mutex.clone();
let routing_table = routing_table.clone(); let routing_table = routing_table.clone();
let up_destinations = up_destinations.clone(); let up_destinations = up_destinations.clone();

View File

@ -21,8 +21,8 @@ pub mod drtio {
use log::{error, info, warn}; use log::{error, info, warn};
use super::*; use super::*;
use crate::{analyzer::remote_analyzer::RemoteBuffer, rtio_dma::remote_dma, ASYNC_ERROR_BUSY, use crate::{rtio_dma::remote_dma, ASYNC_ERROR_BUSY, ASYNC_ERROR_COLLISION, ASYNC_ERROR_SEQUENCE_ERROR,
ASYNC_ERROR_COLLISION, ASYNC_ERROR_SEQUENCE_ERROR, SEEN_ASYNC_ERRORS}; SEEN_ASYNC_ERRORS, analyzer::remote_analyzer::RemoteBuffer};
pub fn startup( pub fn startup(
aux_mutex: &Rc<Mutex<bool>>, aux_mutex: &Rc<Mutex<bool>>,
@ -527,48 +527,37 @@ pub mod drtio {
aux_mutex: &Rc<Mutex<bool>>, aux_mutex: &Rc<Mutex<bool>>,
routing_table: &drtio_routing::RoutingTable, routing_table: &drtio_routing::RoutingTable,
timer: GlobalTimer, timer: GlobalTimer,
destination: u8, destination: u8
) -> Result<RemoteBuffer, &'static str> { ) -> Result<RemoteBuffer, &'static str> {
let linkno = routing_table.0[destination as usize][0] - 1; let linkno = routing_table.0[destination as usize][0] - 1;
let reply = aux_transact( let reply = aux_transact(
aux_mutex, aux_mutex,
linkno, linkno,
&Packet::AnalyzerHeaderRequest { &Packet::AnalyzerHeaderRequest { destination: destination },
destination: destination,
},
timer, timer,
) )
.await; .await;
let (sent, total, overflow) = match reply { let (sent, total, overflow) = match reply {
Ok(Packet::AnalyzerHeader { Ok(Packet::AnalyzerHeader {
sent_bytes, sent_bytes, total_byte_count, overflow_occurred }
total_byte_count, ) => (sent_bytes, total_byte_count, overflow_occurred),
overflow_occurred,
}) => (sent_bytes, total_byte_count, overflow_occurred),
Ok(_) => return Err("received unexpected aux packet during remote analyzer header request"), Ok(_) => return Err("received unexpected aux packet during remote analyzer header request"),
Err(e) => return Err(e), Err(e) => return Err(e)
}; };
let mut remote_data: Vec<u8> = Vec::new(); let mut remote_data: Vec<u8> = Vec::new();
if sent > 0 { if sent > 0 {
let mut last_packet = false; let mut last_packet = false;
while !last_packet { while !last_packet {
let reply = aux_transact( let reply = aux_transact(aux_mutex, linkno,
aux_mutex, &Packet::AnalyzerDataRequest { destination: destination }, timer,).await;
linkno,
&Packet::AnalyzerDataRequest {
destination: destination,
},
timer,
)
.await;
match reply { match reply {
Ok(Packet::AnalyzerData { last, length, data }) => { Ok(Packet::AnalyzerData { last, length, data }) => {
last_packet = last; last_packet = last;
remote_data.extend(&data[0..length as usize]); remote_data.extend(&data[0..length as usize]);
} },
Ok(_) => return Err("received unexpected aux packet during remote analyzer data request"), Ok(_) => return Err("received unexpected aux packet during remote analyzer data request"),
Err(e) => return Err(e), Err(e) => return Err(e)
} }
} }
} }
@ -577,12 +566,11 @@ pub mod drtio {
sent_bytes: sent, sent_bytes: sent,
total_byte_count: total, total_byte_count: total,
error: overflow, error: overflow,
data: remote_data, data: remote_data
}) })
} }
pub async fn analyzer_query( pub async fn analyzer_query(aux_mutex: &Rc<Mutex<bool>>,
aux_mutex: &Rc<Mutex<bool>>,
routing_table: &drtio_routing::RoutingTable, routing_table: &drtio_routing::RoutingTable,
up_destinations: &Rc<RefCell<[bool; drtio_routing::DEST_COUNT]>>, up_destinations: &Rc<RefCell<[bool; drtio_routing::DEST_COUNT]>>,
timer: GlobalTimer, timer: GlobalTimer,

View File

@ -1,5 +1,6 @@
use libboard_artiq::{drtioaux_proto::ANALYZER_MAX_SIZE, pl::csr}; use libboard_artiq::pl::csr;
use libcortex_a9::cache; use libcortex_a9::cache;
use libboard_artiq::drtioaux_proto::ANALYZER_MAX_SIZE;
const BUFFER_SIZE: usize = 512 * 1024; const BUFFER_SIZE: usize = 512 * 1024;
@ -8,7 +9,9 @@ struct Buffer {
data: [u8; BUFFER_SIZE], data: [u8; BUFFER_SIZE],
} }
static mut BUFFER: Buffer = Buffer { data: [0; BUFFER_SIZE] }; static mut BUFFER: Buffer = Buffer {
data: [0; BUFFER_SIZE]
};
fn arm() { fn arm() {
unsafe { unsafe {
@ -33,18 +36,18 @@ fn disarm() {
pub struct Analyzer { pub struct Analyzer {
// necessary for keeping track of sent data // necessary for keeping track of sent data
sent_bytes: usize, sent_bytes: usize,
data_iter: usize, data_iter: usize
} }
pub struct Header { pub struct Header {
pub total_byte_count: u64, pub total_byte_count: u64,
pub sent_bytes: u32, pub sent_bytes: u32,
pub error: bool, pub error: bool
} }
pub struct AnalyzerSliceMeta { pub struct AnalyzerSliceMeta {
pub len: u16, pub len: u16,
pub last: bool, pub last: bool
} }
impl Analyzer { impl Analyzer {
@ -53,7 +56,7 @@ impl Analyzer {
arm(); arm();
Analyzer { Analyzer {
sent_bytes: 0, sent_bytes: 0,
data_iter: 0, data_iter: 0
} }
} }
@ -68,16 +71,8 @@ impl Analyzer {
let bus_err = unsafe { csr::rtio_analyzer::dma_bus_error_read() != 0 }; let bus_err = unsafe { csr::rtio_analyzer::dma_bus_error_read() != 0 };
let total_byte_count = unsafe { csr::rtio_analyzer::dma_byte_count_read() as u64 }; let total_byte_count = unsafe { csr::rtio_analyzer::dma_byte_count_read() as u64 };
let wraparound = total_byte_count >= BUFFER_SIZE as u64; let wraparound = total_byte_count >= BUFFER_SIZE as u64;
self.sent_bytes = if wraparound { self.sent_bytes = if wraparound { BUFFER_SIZE } else { total_byte_count as usize };
BUFFER_SIZE self.data_iter = if wraparound { (total_byte_count % BUFFER_SIZE as u64) as usize } else { 0 };
} else {
total_byte_count as usize
};
self.data_iter = if wraparound {
(total_byte_count % BUFFER_SIZE as u64) as usize
} else {
0
};
if overflow { if overflow {
warn!("overflow occured"); warn!("overflow occured");
@ -89,24 +84,20 @@ impl Analyzer {
Header { Header {
total_byte_count: total_byte_count, total_byte_count: total_byte_count,
sent_bytes: self.sent_bytes as u32, sent_bytes: self.sent_bytes as u32,
error: overflow | bus_err, error: overflow | bus_err
} }
} }
pub fn get_data(&mut self, data_slice: &mut [u8; ANALYZER_MAX_SIZE]) -> AnalyzerSliceMeta { pub fn get_data(&mut self, data_slice: &mut [u8; ANALYZER_MAX_SIZE]) -> AnalyzerSliceMeta {
let data = unsafe { &BUFFER.data[..] }; let data = unsafe { &BUFFER.data[..] };
let i = self.data_iter; let i = self.data_iter;
let len = if i + ANALYZER_MAX_SIZE < self.sent_bytes { let len = if i + ANALYZER_MAX_SIZE < self.sent_bytes { ANALYZER_MAX_SIZE } else { self.sent_bytes - i };
ANALYZER_MAX_SIZE
} else {
self.sent_bytes - i
};
let last = i + len == self.sent_bytes; let last = i + len == self.sent_bytes;
if i + len >= BUFFER_SIZE { if i + len >= BUFFER_SIZE {
data_slice[..len].clone_from_slice(&data[i..BUFFER_SIZE]); data_slice[..len].clone_from_slice(&data[i..BUFFER_SIZE]);
data_slice[..len].clone_from_slice(&data[..(i + len) % BUFFER_SIZE]); data_slice[..len].clone_from_slice(&data[..(i+len) % BUFFER_SIZE]);
} else { } else {
data_slice[..len].clone_from_slice(&data[i..i + len]); data_slice[..len].clone_from_slice(&data[i..i+len]);
} }
self.data_iter += len; self.data_iter += len;
@ -116,7 +107,7 @@ impl Analyzer {
AnalyzerSliceMeta { AnalyzerSliceMeta {
len: len as u16, len: len as u16,
last: last, last: last
} }
} }
} }

View File

@ -20,14 +20,15 @@ extern crate alloc;
use core::sync::atomic::{AtomicBool, Ordering}; use core::sync::atomic::{AtomicBool, Ordering};
use analyzer::Analyzer; use analyzer::Analyzer as Analyzer;
use dma::Manager as DmaManager; use dma::Manager as DmaManager;
use embedded_hal::blocking::delay::DelayUs; use embedded_hal::blocking::delay::DelayUs;
#[cfg(feature = "target_kasli_soc")] #[cfg(feature = "target_kasli_soc")]
use libboard_artiq::io_expander; use libboard_artiq::io_expander;
#[cfg(has_si5324)] #[cfg(has_si5324)]
use libboard_artiq::si5324; use libboard_artiq::si5324;
use libboard_artiq::{drtio_routing, drtioaux, drtioaux_proto::ANALYZER_MAX_SIZE, identifier_read, logger, pl::csr}; use libboard_artiq::{drtio_routing, drtioaux, identifier_read, logger, pl::csr};
use libboard_artiq::{drtioaux_proto::ANALYZER_MAX_SIZE};
#[cfg(feature = "target_kasli_soc")] #[cfg(feature = "target_kasli_soc")]
use libboard_zynq::error_led::ErrorLED; use libboard_zynq::error_led::ErrorLED;
use libboard_zynq::{gic, i2c::I2c, mpcore, print, println, stdio, time::Milliseconds, timer::GlobalTimer}; use libboard_zynq::{gic, i2c::I2c, mpcore, print, println, stdio, time::Milliseconds, timer::GlobalTimer};
@ -39,9 +40,9 @@ use libcortex_a9::{asm, interrupt_handler,
use libregister::{RegisterR, RegisterW}; use libregister::{RegisterR, RegisterW};
use libsupport_zynq::ram; use libsupport_zynq::ram;
mod analyzer;
mod dma; mod dma;
mod repeater; mod repeater;
mod analyzer;
fn drtiosat_reset(reset: bool) { fn drtiosat_reset(reset: bool) {
unsafe { unsafe {
@ -415,34 +416,24 @@ fn process_aux_packet(
) )
} }
drtioaux::Packet::AnalyzerHeaderRequest { drtioaux::Packet::AnalyzerHeaderRequest { destination: _destination } => {
destination: _destination,
} => {
forward!(_routing_table, _destination, *_rank, _repeaters, &packet, timer); forward!(_routing_table, _destination, *_rank, _repeaters, &packet, timer);
let header = analyzer.get_header(); let header = analyzer.get_header();
drtioaux::send( drtioaux::send(0, &drtioaux::Packet::AnalyzerHeader {
0,
&drtioaux::Packet::AnalyzerHeader {
total_byte_count: header.total_byte_count, total_byte_count: header.total_byte_count,
sent_bytes: header.sent_bytes, sent_bytes: header.sent_bytes,
overflow_occurred: header.error, overflow_occurred: header.error,
}, })
)
} }
drtioaux::Packet::AnalyzerDataRequest { drtioaux::Packet::AnalyzerDataRequest { destination: _destination } => {
destination: _destination,
} => {
forward!(_routing_table, _destination, *_rank, _repeaters, &packet, timer); forward!(_routing_table, _destination, *_rank, _repeaters, &packet, timer);
let mut data_slice: [u8; ANALYZER_MAX_SIZE] = [0; ANALYZER_MAX_SIZE]; let mut data_slice: [u8; ANALYZER_MAX_SIZE] = [0; ANALYZER_MAX_SIZE];
let meta = analyzer.get_data(&mut data_slice); let meta = analyzer.get_data(&mut data_slice);
drtioaux::send( drtioaux::send(0, &drtioaux::Packet::AnalyzerData {
0,
&drtioaux::Packet::AnalyzerData {
last: meta.last, last: meta.last,
length: meta.len, length: meta.len,
data: data_slice, data: data_slice,
}, })
)
} }
drtioaux::Packet::DmaAddTraceRequest { drtioaux::Packet::DmaAddTraceRequest {
@ -492,16 +483,7 @@ fn process_aux_packets(
) { ) {
let result = drtioaux::recv(0).and_then(|packet| { let result = drtioaux::recv(0).and_then(|packet| {
if let Some(packet) = packet { if let Some(packet) = packet {
process_aux_packet( process_aux_packet(repeaters, routing_table, rank, packet, timer, i2c, dma_manager, analyzer)
repeaters,
routing_table,
rank,
packet,
timer,
i2c,
dma_manager,
analyzer,
)
} else { } else {
Ok(()) Ok(())
} }