Updating timestamp buffer logic
This commit is contained in:
parent
b191a3f01d
commit
6eaf2cc073
|
@ -7,7 +7,6 @@ static mut BUF: [[u16; INPUT_BUFFER_SIZE]; 2] = [[0; INPUT_BUFFER_SIZE]; 2];
|
|||
|
||||
pub struct InputStamper {
|
||||
_di0_trigger: hal::gpio::gpioa::PA3<hal::gpio::Alternate<hal::gpio::AF2>>,
|
||||
timestamp_buffer: heapless::Vec<u16, heapless::consts::U128>,
|
||||
next_buffer: Option<&'static mut [u16; INPUT_BUFFER_SIZE]>,
|
||||
transfer: Transfer<
|
||||
hal::dma::dma::Stream6<hal::stm32::DMA1>,
|
||||
|
@ -47,37 +46,21 @@ impl InputStamper {
|
|||
timestamp_transfer.start(|_| {});
|
||||
|
||||
Self {
|
||||
timestamp_buffer: heapless::Vec::new(),
|
||||
next_buffer: unsafe { Some(&mut BUF[1]) },
|
||||
transfer: timestamp_transfer,
|
||||
_di0_trigger: trigger,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn transfer_complete_handler(&mut self) {
|
||||
pub fn acquire_buffer(&mut self) -> &[u16] {
|
||||
let next_buffer = self.next_buffer.take().unwrap();
|
||||
self.transfer.clear_interrupts();
|
||||
let (prev_buffer, _, remaining_transfers) =
|
||||
self.transfer.next_transfer(next_buffer).unwrap();
|
||||
|
||||
let valid_count = prev_buffer.len() - remaining_transfers;
|
||||
self.timestamp_buffer
|
||||
.extend_from_slice(&prev_buffer[..valid_count])
|
||||
.unwrap();
|
||||
|
||||
self.next_buffer.replace(prev_buffer);
|
||||
}
|
||||
|
||||
pub fn with_timestamps<F>(&mut self, f: F)
|
||||
where
|
||||
F: FnOnce(&[u16]),
|
||||
{
|
||||
// First, run the transfer complete handler to retrieve any timestamps that are pending in
|
||||
// the DMA transfer.
|
||||
self.transfer_complete_handler();
|
||||
|
||||
f(self.timestamp_buffer.as_ref());
|
||||
|
||||
self.timestamp_buffer.clear();
|
||||
&self.next_buffer.as_ref().unwrap()[..valid_count]
|
||||
}
|
||||
}
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -818,7 +818,7 @@ const APP: () = {
|
|||
}
|
||||
}
|
||||
|
||||
#[task(binds=DMA1_STR3, resources=[adcs, dacs, iir_state, iir_ch], priority=2)]
|
||||
#[task(binds=DMA1_STR3, resources=[adcs, dacs, iir_state, iir_ch, input_stamper], priority=2)]
|
||||
fn process(c: process::Context) {
|
||||
let adc_samples = [
|
||||
c.resources.adcs.0.acquire_buffer(),
|
||||
|
@ -829,6 +829,8 @@ const APP: () = {
|
|||
c.resources.dacs.1.acquire_buffer(),
|
||||
];
|
||||
|
||||
let _timestamps = c.resources.input_stamper.acquire_buffer();
|
||||
|
||||
for channel in 0..adc_samples.len() {
|
||||
for sample in 0..adc_samples[0].len() {
|
||||
let x = f32::from(adc_samples[channel][sample] as i16);
|
||||
|
@ -849,11 +851,6 @@ const APP: () = {
|
|||
c.resources.dacs.1.release_buffer(dac1);
|
||||
}
|
||||
|
||||
#[task(binds=DMA1_STR6, priority = 2)]
|
||||
fn digital_stamper(_: digital_stamper::Context) {
|
||||
panic!("Timestamp overflow")
|
||||
}
|
||||
|
||||
#[idle(resources=[net_interface, pounder, mac_addr, eth_mac, iir_state, iir_ch, afes])]
|
||||
fn idle(mut c: idle::Context) -> ! {
|
||||
let mut socket_set_entries: [_; 8] = Default::default();
|
||||
|
@ -1008,6 +1005,11 @@ const APP: () = {
|
|||
}
|
||||
}
|
||||
|
||||
#[task(binds=DMA1_STR6, priority = 2)]
|
||||
fn di0_timestamp(_: di0_timestamp::Context) {
|
||||
panic!("DI0 Timestamp overflow")
|
||||
}
|
||||
|
||||
#[task(binds = ETH, priority = 1)]
|
||||
fn eth(_: eth::Context) {
|
||||
unsafe { ethernet::interrupt_handler() }
|
||||
|
|
Loading…
Reference in New Issue