forked from M-Labs/artiq
1
0
Fork 0

analyzer: fix satellite behavior

This commit is contained in:
mwojcik 2023-05-29 13:07:06 +08:00 committed by Sébastien Bourdeauducq
parent ef2cc2cc12
commit a4895b591a
2 changed files with 25 additions and 17 deletions

View File

@ -1,4 +1,6 @@
use io::{Write, Error as IoError}; use io::{Write, Error as IoError};
#[cfg(has_drtio)]
use alloc::vec::Vec;
use board_misoc::{csr, cache}; use board_misoc::{csr, cache};
use sched::{Io, Mutex, TcpListener, TcpStream, Error as SchedError}; use sched::{Io, Mutex, TcpListener, TcpStream, Error as SchedError};
use analyzer_proto::*; use analyzer_proto::*;
@ -42,7 +44,6 @@ fn disarm() {
pub mod remote_analyzer { pub mod remote_analyzer {
use super::*; use super::*;
use rtio_mgt::drtio; use rtio_mgt::drtio;
use alloc::vec::Vec;
pub struct RemoteBuffer { pub struct RemoteBuffer {
pub total_byte_count: u64, pub total_byte_count: u64,

View File

@ -1,3 +1,4 @@
use core::cmp::min;
use board_misoc::{csr, cache}; use board_misoc::{csr, cache};
use proto_artiq::drtioaux_proto::ANALYZER_MAX_SIZE; use proto_artiq::drtioaux_proto::ANALYZER_MAX_SIZE;
@ -35,8 +36,9 @@ fn disarm() {
pub struct Analyzer { pub struct Analyzer {
// necessary for keeping track of sent data // necessary for keeping track of sent data
data_len: usize,
sent_bytes: usize, sent_bytes: usize,
data_iter: usize data_pointer: usize
} }
pub struct Header { pub struct Header {
@ -50,48 +52,53 @@ pub struct AnalyzerSliceMeta {
pub last: bool pub last: bool
} }
impl Drop for Analyzer {
fn drop(&mut self) {
disarm();
}
}
impl Analyzer { impl Analyzer {
pub fn new() -> Analyzer { pub fn new() -> Analyzer {
// create and arm new Analyzer // create and arm new Analyzer
arm(); arm();
Analyzer { Analyzer {
data_len: 0,
sent_bytes: 0, sent_bytes: 0,
data_iter: 0 data_pointer: 0
} }
} }
fn drop(&mut self) {
disarm();
}
pub fn get_header(&mut self) -> Header { pub fn get_header(&mut self) -> Header {
disarm(); disarm();
let overflow = unsafe { csr::rtio_analyzer::message_encoder_overflow_read() != 0 }; let overflow = unsafe { csr::rtio_analyzer::message_encoder_overflow_read() != 0 };
let total_byte_count = unsafe { csr::rtio_analyzer::dma_byte_count_read() }; let total_byte_count = unsafe { csr::rtio_analyzer::dma_byte_count_read() };
let wraparound = total_byte_count >= BUFFER_SIZE as u64; let wraparound = total_byte_count >= BUFFER_SIZE as u64;
self.sent_bytes = if wraparound { BUFFER_SIZE } else { total_byte_count as usize }; self.data_len = if wraparound { BUFFER_SIZE } else { total_byte_count as usize };
self.data_iter = if wraparound { (total_byte_count % BUFFER_SIZE as u64) as usize } else { 0 }; self.data_pointer = if wraparound { (total_byte_count % BUFFER_SIZE as u64) as usize } else { 0 };
self.sent_bytes = 0;
Header { Header {
total_byte_count: total_byte_count, total_byte_count: total_byte_count,
sent_bytes: self.sent_bytes as u32, sent_bytes: self.data_len as u32,
overflow: overflow overflow: overflow
} }
} }
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_pointer + self.sent_bytes) % BUFFER_SIZE;
let len = if i + ANALYZER_MAX_SIZE < self.sent_bytes { ANALYZER_MAX_SIZE } else { self.sent_bytes - i }; let len = min(ANALYZER_MAX_SIZE, self.data_len - self.sent_bytes);
let last = i + len == self.sent_bytes; let last = self.sent_bytes + len == self.data_len;
if i + len >= BUFFER_SIZE { if i + len >= BUFFER_SIZE {
data_slice[..len].clone_from_slice(&data[i..BUFFER_SIZE]); data_slice[..(BUFFER_SIZE-i)].clone_from_slice(&data[i..BUFFER_SIZE]);
data_slice[..len].clone_from_slice(&data[..(i+len) % BUFFER_SIZE]); data_slice[(BUFFER_SIZE-i)..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.sent_bytes += len;
if last { if last {
arm(); arm();