Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tighten signal_generator symmetry bounds #410

Merged
merged 4 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/hardware/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ impl TcpSocketStorage {
}
}

impl NetStorage {
pub fn new() -> Self {
impl Default for NetStorage {
fn default() -> Self {
NetStorage {
// Placeholder for the real IP address, which is initialized at runtime.
ip_addrs: [smoltcp::wire::IpCidr::Ipv6(
Expand Down Expand Up @@ -671,7 +671,7 @@ pub fn setup(
// Note(unwrap): The hardware configuration function is only allowed to be called once.
// Unwrapping is intended to panic if called again to prevent re-use of global memory.
let store =
cortex_m::singleton!(: NetStorage = NetStorage::new()).unwrap();
cortex_m::singleton!(: NetStorage = NetStorage::default()).unwrap();

store.ip_addrs[0] = smoltcp::wire::IpCidr::new(
smoltcp::wire::IpAddress::Ipv4(
Expand Down
14 changes: 9 additions & 5 deletions src/hardware/signal_generator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{configuration::ADC_SAMPLE_TICKS_LOG2, hardware::dac::DacCode};
use crate::{
configuration::ADC_SAMPLE_TICKS_LOG2, hardware::dac::DacCode,
hardware::design_parameters::TIMER_FREQUENCY,
};
use core::convert::{TryFrom, TryInto};
use miniconf::Miniconf;
use serde::Deserialize;
Expand Down Expand Up @@ -60,13 +63,14 @@ impl TryFrom<BasicConfig> for Config {
fn try_from(config: BasicConfig) -> Result<Config, Error> {
// Calculate the frequency tuning words
let frequency_tuning_word: [u32; 2] = {
const LSB_PER_HERTZ: f32 =
(1u64 << (31 + ADC_SAMPLE_TICKS_LOG2)) as f32 / 100.0e6;
const LSB_PER_HERTZ: f32 = (1u64 << (31 + ADC_SAMPLE_TICKS_LOG2))
as f32
/ (TIMER_FREQUENCY.0 * 1_000_000) as f32;
let ftw = config.frequency * LSB_PER_HERTZ;

if config.symmetry <= 0.0 {
if config.symmetry <= ftw / u32::MAX as f32 {
jordens marked this conversation as resolved.
Show resolved Hide resolved
[1u32 << 31, ftw as u32]
} else if config.symmetry >= 1.0 {
} else if 1. - config.symmetry <= ftw / u32::MAX as f32 {
[ftw as u32, 1u32 << 31]
} else {
[
Expand Down
6 changes: 2 additions & 4 deletions src/net/network_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,10 @@ impl NetworkProcessor {
// Service the network stack to process any inbound and outbound traffic.
let now = self.clock.current_ms();

let result = match self.stack.lock(|stack| stack.poll(now)) {
match self.stack.lock(|stack| stack.poll(now)) {
Ok(true) => UpdateState::Updated,
Ok(false) => UpdateState::NoChange,
Err(_) => UpdateState::Updated,
};

result
}
}
}