From 6c87db377865a9c6403f301fd1e21ed2893b3dcd Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Fri, 23 Jul 2021 14:12:59 +0200 Subject: [PATCH] Updating comments --- scripts/stream_throughput.py | 29 +++++++++++++++-------------- src/bin/dual-iir.rs | 28 +++++++++++++++++----------- src/hardware/setup.rs | 9 --------- src/net/data_stream.rs | 34 ++++++++++++++++++++-------------- 4 files changed, 52 insertions(+), 48 deletions(-) diff --git a/scripts/stream_throughput.py b/scripts/stream_throughput.py index d7ce9b8..3624333 100644 --- a/scripts/stream_throughput.py +++ b/scripts/stream_throughput.py @@ -13,10 +13,10 @@ import logging # Representation of a single UDP packet transmitted by Stabilizer. Packet = collections.namedtuple('Packet', ['index', 'adc', 'dac']) -Format = collections.namedtuple('Format', ['batch_size', 'batches_per_frame']) +Format = collections.namedtuple('Format', ['batch_size', 'length']) FORMAT = { - 0: Format(8, 255) + 0: Format(8, 964) } class Timer: @@ -94,30 +94,31 @@ class PacketParser: if len(self.buf) < 4: return None - start_id, format_id = struct.unpack_from('!HH', self.buf) + start_id, format_id = struct.unpack_from('(0, |buf| { - let mut offset = 0; - for device in [adc_samples.iter(), dac_samples.iter()] { - for channel in device { - for sample in channel.iter() { - buf[offset..offset + 2] - .copy_from_slice(&sample.to_ne_bytes()); - offset += 2; - } - } - } + generator.add::<_, { SAMPLE_BUFFER_SIZE * 8 }>(0, |buf| unsafe { + let dst = buf.as_ptr() as usize as *mut u16; + + let adc0 = &adc_samples[0][0] as *const u16; + core::ptr::copy_nonoverlapping(adc0, dst, SAMPLE_BUFFER_SIZE); + + let dst = dst.add(SAMPLE_BUFFER_SIZE); + let adc1 = &adc_samples[1][0] as *const u16; + core::ptr::copy_nonoverlapping(adc1, dst, SAMPLE_BUFFER_SIZE); + + let dst = dst.add(SAMPLE_BUFFER_SIZE); + let dac0 = &dac_samples[0][0] as *const u16; + core::ptr::copy_nonoverlapping(dac0, dst, SAMPLE_BUFFER_SIZE); + + let dst = dst.add(SAMPLE_BUFFER_SIZE); + let dac1 = &dac_samples[1][0] as *const u16; + core::ptr::copy_nonoverlapping(dac1, dst, SAMPLE_BUFFER_SIZE); }); // Update telemetry measurements. diff --git a/src/hardware/setup.rs b/src/hardware/setup.rs index 2b270d5..61b9a2d 100644 --- a/src/hardware/setup.rs +++ b/src/hardware/setup.rs @@ -36,11 +36,6 @@ pub struct NetStorage { [Option<(smoltcp::wire::IpAddress, smoltcp::iface::Neighbor)>; 8], pub routes_cache: [Option<(smoltcp::wire::IpCidr, smoltcp::iface::Route)>; 8], - - pub dhcp_rx_metadata: [smoltcp::socket::RawPacketMetadata; 1], - pub dhcp_tx_metadata: [smoltcp::socket::RawPacketMetadata; 1], - pub dhcp_tx_storage: [u8; 600], - pub dhcp_rx_storage: [u8; 600], } pub struct UdpSocketStorage { @@ -94,10 +89,6 @@ impl Default for NetStorage { sockets: [None, None, None, None, None, None], tcp_socket_storage: [TcpSocketStorage::new(); NUM_TCP_SOCKETS], udp_socket_storage: [UdpSocketStorage::new(); NUM_UDP_SOCKETS], - dhcp_tx_storage: [0; 600], - dhcp_rx_storage: [0; 600], - dhcp_rx_metadata: [smoltcp::socket::RawPacketMetadata::EMPTY; 1], - dhcp_tx_metadata: [smoltcp::socket::RawPacketMetadata::EMPTY; 1], } } } diff --git a/src/net/data_stream.rs b/src/net/data_stream.rs index 0e37bea..5766721 100644 --- a/src/net/data_stream.rs +++ b/src/net/data_stream.rs @@ -19,9 +19,11 @@ use heapless::pool::{Box, Init, Pool, Uninit}; use super::NetworkReference; -const FRAME_COUNT: usize = 4; +const FRAME_COUNT: usize = 6; +const FRAME_SIZE: usize = 1024; -static mut FRAME_DATA: [u8; 5200] = [0; 5200]; +static mut FRAME_DATA: [u8; FRAME_SIZE * FRAME_COUNT] = + [0; FRAME_SIZE * FRAME_COUNT]; /// Represents the destination for the UDP stream to send data to. /// @@ -70,7 +72,7 @@ pub fn setup_streaming( let (producer, consumer) = queue.split(); let frame_pool = - cortex_m::singleton!(: Pool<[u8; 1024]>= Pool::new()).unwrap(); + cortex_m::singleton!(: Pool<[u8; FRAME_SIZE]>= Pool::new()).unwrap(); // Note(unsafe): We guarantee that FRAME_DATA is only accessed once in this function. let memory = unsafe { &mut FRAME_DATA }; @@ -86,13 +88,13 @@ pub fn setup_streaming( struct StreamFrame { format: u16, sequence_number: u16, - buffer: Box<[u8; 1024], Init>, + buffer: Box<[u8; FRAME_SIZE], Init>, offset: usize, } impl StreamFrame { pub fn new( - buffer: Box<[u8; 1024], Uninit>, + buffer: Box<[u8; FRAME_SIZE], Uninit>, format: u16, sequence_number: u16, ) -> Self { @@ -132,7 +134,7 @@ impl StreamFrame { /// The data generator for a stream. pub struct FrameGenerator { queue: Producer<'static, StreamFrame, FRAME_COUNT>, - pool: &'static Pool<[u8; 1024]>, + pool: &'static Pool<[u8; FRAME_SIZE]>, current_frame: Option, sequence_number: u16, } @@ -140,7 +142,7 @@ pub struct FrameGenerator { impl FrameGenerator { fn new( queue: Producer<'static, StreamFrame, FRAME_COUNT>, - pool: &'static Pool<[u8; 1024]>, + pool: &'static Pool<[u8; FRAME_SIZE]>, ) -> Self { Self { queue, @@ -172,11 +174,15 @@ impl FrameGenerator { self.current_frame.as_mut().unwrap().add_batch::<_, T>(f); if self.current_frame.as_ref().unwrap().is_full::() { - // If we fail to enqueue the frame, free the underlying buffer. - match self.queue.enqueue(self.current_frame.take().unwrap()) { - Err(frame) => self.pool.free(frame.buffer), - _ => {} - }; + if self + .queue + .enqueue(self.current_frame.take().unwrap()) + .is_err() + { + // Given that the queue is the same size as the number of frames available, this + // should never occur. + panic!("Frame enqueue failure") + } } } } @@ -189,7 +195,7 @@ pub struct DataStream { stack: NetworkReference, socket: Option<::UdpSocket>, queue: Consumer<'static, StreamFrame, FRAME_COUNT>, - frame_pool: &'static Pool<[u8; 1024]>, + frame_pool: &'static Pool<[u8; FRAME_SIZE]>, remote: SocketAddr, } @@ -203,7 +209,7 @@ impl DataStream { fn new( stack: NetworkReference, consumer: Consumer<'static, StreamFrame, FRAME_COUNT>, - frame_pool: &'static Pool<[u8; 1024]>, + frame_pool: &'static Pool<[u8; FRAME_SIZE]>, ) -> Self { Self { stack,