From 9d3513d4d152698bbf27a8b70fea4931fc360241 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Mon, 2 Aug 2021 16:29:21 +0200 Subject: [PATCH] Renaming variables, fixing pounder builds --- src/hardware/adc.rs | 6 +++--- src/hardware/dac.rs | 10 +++------- src/hardware/pounder/timestamp.rs | 18 ++++++++++++------ src/hardware/setup.rs | 13 +++++++------ 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/hardware/adc.rs b/src/hardware/adc.rs index 4814ab6..4da4100 100644 --- a/src/hardware/adc.rs +++ b/src/hardware/adc.rs @@ -259,7 +259,7 @@ macro_rules! adc_input { clear_stream: hal::dma::dma::$clear_stream, trigger_channel: timers::tim2::$trigger_channel, clear_channel: timers::tim3::$clear_channel, - sample_buffer_size: usize, + batch_size: usize, ) -> Self { // The flag clear DMA transfer always clears the EOT flag in the SPI // peripheral. It has the highest priority to ensure it is completed before the @@ -359,8 +359,8 @@ macro_rules! adc_input { spi, // Note(unsafe): The ADC_BUF[$index] is "owned" by this peripheral. // It shall not be used anywhere else in the module. - unsafe { &mut ADC_BUF[$index][0][..sample_buffer_size] }, - unsafe { Some(&mut ADC_BUF[$index][1][..sample_buffer_size]) }, + unsafe { &mut ADC_BUF[$index][0][..batch_size] }, + unsafe { Some(&mut ADC_BUF[$index][1][..batch_size]) }, data_config, ); diff --git a/src/hardware/dac.rs b/src/hardware/dac.rs index 4339a52..2699ce5 100644 --- a/src/hardware/dac.rs +++ b/src/hardware/dac.rs @@ -193,7 +193,7 @@ macro_rules! dac_output { spi: hal::spi::Spi, stream: hal::dma::dma::$data_stream, trigger_channel: timers::tim2::$trigger_channel, - sample_buffer_size: usize, + batch_size: usize, ) -> Self { // Generate DMA events when an output compare of the timer hitting zero (timer roll over) // occurs. @@ -227,13 +227,9 @@ macro_rules! dac_output { stream, $spi::new(trigger_channel, spi), // Note(unsafe): This buffer is only used once and provided for the DMA transfer. - unsafe { - &mut DAC_BUF[$index][0][..sample_buffer_size] - }, + unsafe { &mut DAC_BUF[$index][0][..batch_size] }, // Note(unsafe): This buffer is only used once and provided for the DMA transfer. - unsafe { - Some(&mut DAC_BUF[$index][1][..sample_buffer_size]) - }, + unsafe { Some(&mut DAC_BUF[$index][1][..batch_size]) }, trigger_config, ); diff --git a/src/hardware/pounder/timestamp.rs b/src/hardware/pounder/timestamp.rs index 262af9b..571820e 100644 --- a/src/hardware/pounder/timestamp.rs +++ b/src/hardware/pounder/timestamp.rs @@ -16,8 +16,7 @@ ///! capture is simultaneously triggered. That trigger is prescaled (its rate is divided) by the ///! batch size. This results in the input capture triggering identically to when the ADC samples ///! the last sample of the batch. That sample is then available for processing by the user. -use crate::{configuration, hardware::timers}; -use core::convert::TryFrom; +use crate::hardware::timers; use stm32h7xx_hal as hal; /// Software unit to timestamp stabilizer ADC samples using an external pounder reference clock. @@ -34,6 +33,7 @@ impl Timestamper { /// * `capture_channel` - The input capture channel for collecting timestamps. /// * `sampling_timer` - The stabilizer ADC sampling timer. /// * `_clock_input` - The input pin for the external clock from Pounder. + /// * `batch_size` - The number of seamples in each batch. /// /// # Returns /// The new pounder timestamper in an operational state. @@ -44,6 +44,7 @@ impl Timestamper { _clock_input: hal::gpio::gpioa::PA0< hal::gpio::Alternate, >, + batch_size: usize, ) -> Self { // The sampling timer should generate a trigger output when CH1 comparison occurs. sampling_timer.generate_trigger(timers::TriggerGenerator::ComparePulse); @@ -56,11 +57,16 @@ impl Timestamper { let mut input_capture = capture_channel .into_input_capture(timers::tim8::CaptureSource1::TRC); + let prescaler = match batch_size { + 1 => timers::Prescaler::Div1, + 2 => timers::Prescaler::Div2, + 4 => timers::Prescaler::Div4, + 8 => timers::Prescaler::Div8, + _ => panic!("Batch size does not support DDS timestamping"), + }; + // Capture at the batch period. - input_capture.configure_prescaler( - timers::Prescaler::try_from(configuration::SAMPLE_BUFFER_SIZE_LOG2) - .unwrap(), - ); + input_capture.configure_prescaler(prescaler); Self { timer: timestamp_timer, diff --git a/src/hardware/setup.rs b/src/hardware/setup.rs index 2239223..fe69da2 100644 --- a/src/hardware/setup.rs +++ b/src/hardware/setup.rs @@ -178,7 +178,7 @@ fn load_itcm() { /// # Args /// * `core` - The RTIC core for configuring the cortex-M core of the device. /// * `device` - The microcontroller peripherals to be configured. -/// * `sample_buffer_size` - The size of the ADC/DAC sample buffer. +/// * `batch_size` - The size of each ADC/DAC batch. /// * `sample_ticks` - The number of timer ticks between each sample. /// /// # Returns @@ -189,7 +189,7 @@ fn load_itcm() { pub fn setup( mut core: rtic::Peripherals, device: stm32h7xx_hal::stm32::Peripherals, - sample_buffer_size: usize, + batch_size: usize, sample_ticks: u32, ) -> (StabilizerDevices, Option) { let pwr = device.PWR.constrain(); @@ -414,7 +414,7 @@ pub fn setup( dma_streams.2, sampling_timer_channels.ch1, shadow_sampling_timer_channels.ch1, - sample_buffer_size, + batch_size, ) }; @@ -458,7 +458,7 @@ pub fn setup( dma_streams.5, sampling_timer_channels.ch2, shadow_sampling_timer_channels.ch2, - sample_buffer_size, + batch_size, ) }; @@ -546,13 +546,13 @@ pub fn setup( dac0_spi, dma_streams.6, sampling_timer_channels.ch3, - sample_buffer_size, + batch_size, ); let dac1 = dac::Dac1Output::new( dac1_spi, dma_streams.7, sampling_timer_channels.ch4, - sample_buffer_size, + batch_size, ); (dac0, dac1) }; @@ -994,6 +994,7 @@ pub fn setup( tim8_channels.ch1, &mut sampling_timer, etr_pin, + batch_size, ) };