pounder_timestamper: use input capture prescaler
This commit is contained in:
parent
35536c0623
commit
2ba9e9c2f7
@ -22,10 +22,10 @@
|
|||||||
///! mode. As soon as the DMA transfer completes, the hardware automatically swaps over to a second
|
///! mode. As soon as the DMA transfer completes, the hardware automatically swaps over to a second
|
||||||
///! buffer to continue capturing. This alleviates timing sensitivities of the DMA transfer
|
///! buffer to continue capturing. This alleviates timing sensitivities of the DMA transfer
|
||||||
///! schedule.
|
///! schedule.
|
||||||
|
use crate::hardware::{design_parameters, timers};
|
||||||
|
use core::convert::TryFrom;
|
||||||
use stm32h7xx_hal as hal;
|
use stm32h7xx_hal as hal;
|
||||||
|
|
||||||
use crate::hardware::timers;
|
|
||||||
|
|
||||||
/// 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.
|
||||||
pub struct Timestamper {
|
pub struct Timestamper {
|
||||||
timer: timers::PounderTimestampTimer,
|
timer: timers::PounderTimestampTimer,
|
||||||
@ -64,9 +64,17 @@ impl Timestamper {
|
|||||||
timestamp_timer.set_trigger_source(timers::TriggerSource::Trigger1);
|
timestamp_timer.set_trigger_source(timers::TriggerSource::Trigger1);
|
||||||
|
|
||||||
// The capture channel should capture whenever the trigger input occurs.
|
// The capture channel should capture whenever the trigger input occurs.
|
||||||
let input_capture = capture_channel
|
let mut input_capture = capture_channel
|
||||||
.into_input_capture(timers::tim8::CaptureSource1::TRC);
|
.into_input_capture(timers::tim8::CaptureSource1::TRC);
|
||||||
|
|
||||||
|
// Capture at the batch period.
|
||||||
|
input_capture.configure_prescaler(
|
||||||
|
timers::Prescaler::try_from(
|
||||||
|
design_parameters::SAMPLE_BUFFER_SIZE_LOG2,
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
timer: timestamp_timer,
|
timer: timestamp_timer,
|
||||||
capture_channel: input_capture,
|
capture_channel: input_capture,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
///! The sampling timer is used for managing ADC sampling and external reference timestamping.
|
///! The sampling timer is used for managing ADC sampling and external reference timestamping.
|
||||||
use super::hal;
|
use super::hal;
|
||||||
|
use num_enum::TryFromPrimitive;
|
||||||
|
|
||||||
use hal::stm32::{
|
use hal::stm32::{
|
||||||
// TIM1 and TIM8 have identical registers.
|
// TIM1 and TIM8 have identical registers.
|
||||||
@ -34,6 +35,8 @@ pub enum TriggerSource {
|
|||||||
|
|
||||||
/// Prescalers for externally-supplied reference clocks.
|
/// Prescalers for externally-supplied reference clocks.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
#[derive(TryFromPrimitive)]
|
||||||
|
#[repr(u8)]
|
||||||
pub enum Prescaler {
|
pub enum Prescaler {
|
||||||
Div1 = 0b00,
|
Div1 = 0b00,
|
||||||
Div2 = 0b01,
|
Div2 = 0b01,
|
||||||
@ -353,6 +356,21 @@ macro_rules! timer_channels {
|
|||||||
let regs = unsafe { &*<$TY>::ptr() };
|
let regs = unsafe { &*<$TY>::ptr() };
|
||||||
regs.[< $ccmrx _input >]().modify(|_, w| w.[< ic $index f >]().bits(filter as u8));
|
regs.[< $ccmrx _input >]().modify(|_, w| w.[< ic $index f >]().bits(filter as u8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Configure the input capture prescaler.
|
||||||
|
///
|
||||||
|
/// # Args
|
||||||
|
/// * `psc` - Prescaler exponent.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn configure_prescaler(&mut self, prescaler: super::Prescaler) {
|
||||||
|
// Note(unsafe): This channel owns all access to the specific timer channel.
|
||||||
|
// Only atomic operations on completed on the timer registers.
|
||||||
|
let regs = unsafe { &*<$TY>::ptr() };
|
||||||
|
// Note(unsafe): Enum values are all valid.
|
||||||
|
#[allow(unused_unsafe)]
|
||||||
|
regs.[< $ccmrx _input >]().modify(|_, w| unsafe {
|
||||||
|
w.[< ic $index psc >]().bits(prescaler as u8)});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note(unsafe): This manually implements DMA support for input-capture channels. This
|
// Note(unsafe): This manually implements DMA support for input-capture channels. This
|
||||||
|
Loading…
Reference in New Issue
Block a user