Renaming variables, fixing pounder builds

master
Ryan Summers 2021-08-02 16:29:21 +02:00
parent c4c3593bae
commit 9d3513d4d1
4 changed files with 25 additions and 22 deletions

View File

@ -259,7 +259,7 @@ macro_rules! adc_input {
clear_stream: hal::dma::dma::$clear_stream<hal::stm32::DMA1>, clear_stream: hal::dma::dma::$clear_stream<hal::stm32::DMA1>,
trigger_channel: timers::tim2::$trigger_channel, trigger_channel: timers::tim2::$trigger_channel,
clear_channel: timers::tim3::$clear_channel, clear_channel: timers::tim3::$clear_channel,
sample_buffer_size: usize, batch_size: usize,
) -> Self { ) -> Self {
// The flag clear DMA transfer always clears the EOT flag in the SPI // 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 // peripheral. It has the highest priority to ensure it is completed before the
@ -359,8 +359,8 @@ macro_rules! adc_input {
spi, spi,
// Note(unsafe): The ADC_BUF[$index] is "owned" by this peripheral. // Note(unsafe): The ADC_BUF[$index] is "owned" by this peripheral.
// It shall not be used anywhere else in the module. // It shall not be used anywhere else in the module.
unsafe { &mut ADC_BUF[$index][0][..sample_buffer_size] }, unsafe { &mut ADC_BUF[$index][0][..batch_size] },
unsafe { Some(&mut ADC_BUF[$index][1][..sample_buffer_size]) }, unsafe { Some(&mut ADC_BUF[$index][1][..batch_size]) },
data_config, data_config,
); );

View File

@ -193,7 +193,7 @@ macro_rules! dac_output {
spi: hal::spi::Spi<hal::stm32::$spi, hal::spi::Enabled, u16>, spi: hal::spi::Spi<hal::stm32::$spi, hal::spi::Enabled, u16>,
stream: hal::dma::dma::$data_stream<hal::stm32::DMA1>, stream: hal::dma::dma::$data_stream<hal::stm32::DMA1>,
trigger_channel: timers::tim2::$trigger_channel, trigger_channel: timers::tim2::$trigger_channel,
sample_buffer_size: usize, batch_size: usize,
) -> Self { ) -> Self {
// Generate DMA events when an output compare of the timer hitting zero (timer roll over) // Generate DMA events when an output compare of the timer hitting zero (timer roll over)
// occurs. // occurs.
@ -227,13 +227,9 @@ macro_rules! dac_output {
stream, stream,
$spi::new(trigger_channel, spi), $spi::new(trigger_channel, spi),
// Note(unsafe): This buffer is only used once and provided for the DMA transfer. // Note(unsafe): This buffer is only used once and provided for the DMA transfer.
unsafe { unsafe { &mut DAC_BUF[$index][0][..batch_size] },
&mut DAC_BUF[$index][0][..sample_buffer_size]
},
// Note(unsafe): This buffer is only used once and provided for the DMA transfer. // Note(unsafe): This buffer is only used once and provided for the DMA transfer.
unsafe { unsafe { Some(&mut DAC_BUF[$index][1][..batch_size]) },
Some(&mut DAC_BUF[$index][1][..sample_buffer_size])
},
trigger_config, trigger_config,
); );

View File

@ -16,8 +16,7 @@
///! capture is simultaneously triggered. That trigger is prescaled (its rate is divided) by the ///! 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 ///! 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. ///! the last sample of the batch. That sample is then available for processing by the user.
use crate::{configuration, hardware::timers}; use crate::hardware::timers;
use core::convert::TryFrom;
use stm32h7xx_hal as hal; use stm32h7xx_hal as hal;
/// Software unit to timestamp stabilizer ADC samples using an external pounder reference clock. /// 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. /// * `capture_channel` - The input capture channel for collecting timestamps.
/// * `sampling_timer` - The stabilizer ADC sampling timer. /// * `sampling_timer` - The stabilizer ADC sampling timer.
/// * `_clock_input` - The input pin for the external clock from Pounder. /// * `_clock_input` - The input pin for the external clock from Pounder.
/// * `batch_size` - The number of seamples in each batch.
/// ///
/// # Returns /// # Returns
/// The new pounder timestamper in an operational state. /// The new pounder timestamper in an operational state.
@ -44,6 +44,7 @@ impl Timestamper {
_clock_input: hal::gpio::gpioa::PA0< _clock_input: hal::gpio::gpioa::PA0<
hal::gpio::Alternate<hal::gpio::AF3>, hal::gpio::Alternate<hal::gpio::AF3>,
>, >,
batch_size: usize,
) -> Self { ) -> Self {
// The sampling timer should generate a trigger output when CH1 comparison occurs. // The sampling timer should generate a trigger output when CH1 comparison occurs.
sampling_timer.generate_trigger(timers::TriggerGenerator::ComparePulse); sampling_timer.generate_trigger(timers::TriggerGenerator::ComparePulse);
@ -56,11 +57,16 @@ impl Timestamper {
let mut input_capture = capture_channel let mut input_capture = capture_channel
.into_input_capture(timers::tim8::CaptureSource1::TRC); .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. // Capture at the batch period.
input_capture.configure_prescaler( input_capture.configure_prescaler(prescaler);
timers::Prescaler::try_from(configuration::SAMPLE_BUFFER_SIZE_LOG2)
.unwrap(),
);
Self { Self {
timer: timestamp_timer, timer: timestamp_timer,

View File

@ -178,7 +178,7 @@ fn load_itcm() {
/// # Args /// # Args
/// * `core` - The RTIC core for configuring the cortex-M core of the device. /// * `core` - The RTIC core for configuring the cortex-M core of the device.
/// * `device` - The microcontroller peripherals to be configured. /// * `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. /// * `sample_ticks` - The number of timer ticks between each sample.
/// ///
/// # Returns /// # Returns
@ -189,7 +189,7 @@ fn load_itcm() {
pub fn setup( pub fn setup(
mut core: rtic::Peripherals, mut core: rtic::Peripherals,
device: stm32h7xx_hal::stm32::Peripherals, device: stm32h7xx_hal::stm32::Peripherals,
sample_buffer_size: usize, batch_size: usize,
sample_ticks: u32, sample_ticks: u32,
) -> (StabilizerDevices, Option<PounderDevices>) { ) -> (StabilizerDevices, Option<PounderDevices>) {
let pwr = device.PWR.constrain(); let pwr = device.PWR.constrain();
@ -414,7 +414,7 @@ pub fn setup(
dma_streams.2, dma_streams.2,
sampling_timer_channels.ch1, sampling_timer_channels.ch1,
shadow_sampling_timer_channels.ch1, shadow_sampling_timer_channels.ch1,
sample_buffer_size, batch_size,
) )
}; };
@ -458,7 +458,7 @@ pub fn setup(
dma_streams.5, dma_streams.5,
sampling_timer_channels.ch2, sampling_timer_channels.ch2,
shadow_sampling_timer_channels.ch2, shadow_sampling_timer_channels.ch2,
sample_buffer_size, batch_size,
) )
}; };
@ -546,13 +546,13 @@ pub fn setup(
dac0_spi, dac0_spi,
dma_streams.6, dma_streams.6,
sampling_timer_channels.ch3, sampling_timer_channels.ch3,
sample_buffer_size, batch_size,
); );
let dac1 = dac::Dac1Output::new( let dac1 = dac::Dac1Output::new(
dac1_spi, dac1_spi,
dma_streams.7, dma_streams.7,
sampling_timer_channels.ch4, sampling_timer_channels.ch4,
sample_buffer_size, batch_size,
); );
(dac0, dac1) (dac0, dac1)
}; };
@ -994,6 +994,7 @@ pub fn setup(
tim8_channels.ch1, tim8_channels.ch1,
&mut sampling_timer, &mut sampling_timer,
etr_pin, etr_pin,
batch_size,
) )
}; };