Adding streaming to lockin app

This commit is contained in:
Ryan Summers 2021-06-15 13:22:38 +02:00
parent 2815d6d9e9
commit 9e083842ee
1 changed files with 19 additions and 2 deletions

View File

@ -20,6 +20,7 @@ use stabilizer::{
DigitalInput0, DigitalInput1, AFE0, AFE1, DigitalInput0, DigitalInput1, AFE0, AFE1,
}, },
net::{ net::{
data_stream::{BlockGenerator, StreamTarget},
miniconf::Miniconf, miniconf::Miniconf,
serde::Deserialize, serde::Deserialize,
telemetry::{Telemetry, TelemetryBuffer}, telemetry::{Telemetry, TelemetryBuffer},
@ -64,6 +65,8 @@ pub struct Settings {
output_conf: [Conf; 2], output_conf: [Conf; 2],
telemetry_period: u16, telemetry_period: u16,
stream_target: StreamTarget,
} }
impl Default for Settings { impl Default for Settings {
@ -82,6 +85,8 @@ impl Default for Settings {
output_conf: [Conf::InPhase, Conf::Quadrature], output_conf: [Conf::InPhase, Conf::Quadrature],
// The default telemetry period in seconds. // The default telemetry period in seconds.
telemetry_period: 10, telemetry_period: 10,
stream_target: StreamTarget::default(),
} }
} }
} }
@ -96,6 +101,7 @@ const APP: () = {
settings: Settings, settings: Settings,
telemetry: TelemetryBuffer, telemetry: TelemetryBuffer,
digital_inputs: (DigitalInput0, DigitalInput1), digital_inputs: (DigitalInput0, DigitalInput1),
generator: BlockGenerator,
timestamper: InputStamper, timestamper: InputStamper,
pll: RPLL, pll: RPLL,
@ -108,7 +114,7 @@ const APP: () = {
let (mut stabilizer, _pounder) = let (mut stabilizer, _pounder) =
hardware::setup::setup(c.core, c.device); hardware::setup::setup(c.core, c.device);
let network = NetworkUsers::new( let mut network = NetworkUsers::new(
stabilizer.net.stack, stabilizer.net.stack,
stabilizer.net.phy, stabilizer.net.phy,
stabilizer.cycle_counter, stabilizer.cycle_counter,
@ -116,6 +122,8 @@ const APP: () = {
stabilizer.net.mac_address, stabilizer.net.mac_address,
); );
let generator = network.enable_streaming();
let settings = Settings::default(); let settings = Settings::default();
let pll = RPLL::new( let pll = RPLL::new(
@ -155,6 +163,7 @@ const APP: () = {
telemetry: TelemetryBuffer::default(), telemetry: TelemetryBuffer::default(),
settings, settings,
generator,
pll, pll,
lockin: Lockin::default(), lockin: Lockin::default(),
@ -168,7 +177,7 @@ const APP: () = {
/// This is an implementation of a externally (DI0) referenced PLL lockin on the ADC0 signal. /// This is an implementation of a externally (DI0) referenced PLL lockin on the ADC0 signal.
/// It outputs either I/Q or power/phase on DAC0/DAC1. Data is normalized to full scale. /// It outputs either I/Q or power/phase on DAC0/DAC1. Data is normalized to full scale.
/// PLL bandwidth, filter bandwidth, slope, and x/y or power/phase post-filters are available. /// PLL bandwidth, filter bandwidth, slope, and x/y or power/phase post-filters are available.
#[task(binds=DMA1_STR4, resources=[adcs, dacs, lockin, timestamper, pll, settings, telemetry], priority=2)] #[task(binds=DMA1_STR4, resources=[adcs, dacs, lockin, timestamper, pll, settings, telemetry, generator], priority=2)]
#[inline(never)] #[inline(never)]
#[link_section = ".itcm.process"] #[link_section = ".itcm.process"]
fn process(mut c: process::Context) { fn process(mut c: process::Context) {
@ -180,6 +189,7 @@ const APP: () = {
ref mut lockin, ref mut lockin,
ref mut pll, ref mut pll,
ref mut timestamper, ref mut timestamper,
ref mut generator,
} = c.resources; } = c.resources;
let (reference_phase, reference_frequency) = match settings.lockin_mode let (reference_phase, reference_frequency) = match settings.lockin_mode
@ -252,6 +262,10 @@ const APP: () = {
*sample = DacCode::from(value as i16).0; *sample = DacCode::from(value as i16).0;
} }
} }
// Stream data
generator.send(&adc_samples, &dac_samples);
// Update telemetry measurements. // Update telemetry measurements.
telemetry.adcs = telemetry.adcs =
[AdcCode(adc_samples[0][0]), AdcCode(adc_samples[1][0])]; [AdcCode(adc_samples[0][0]), AdcCode(adc_samples[1][0])];
@ -285,6 +299,9 @@ const APP: () = {
c.resources.afes.1.set_gain(settings.afe[1]); c.resources.afes.1.set_gain(settings.afe[1]);
c.resources.settings.lock(|current| *current = *settings); c.resources.settings.lock(|current| *current = *settings);
let target = settings.stream_target.into();
c.resources.network.direct_stream(target);
} }
#[task(priority = 1, resources=[network, digital_inputs, settings, telemetry], schedule=[telemetry])] #[task(priority = 1, resources=[network, digital_inputs, settings, telemetry], schedule=[telemetry])]