Compare commits

..

No commits in common. "8f4a97c97ed99430652c0faa819f556d2499006b" and "e75c3d3342b2b982d2b2fa721184cb851eeb447a" have entirely different histories.

3 changed files with 10 additions and 45 deletions

View File

@ -1,5 +1,5 @@
[target.thumbv7em-none-eabihf] [target.thumbv7em-none-eabihf]
runner = "gdb -q -x gdb_config/debug.gdb" runner = "gdb -q -x gdb_config/fpga_config.gdb"
rustflags = [ rustflags = [
"-C", "link-arg=-Tlink.x", "-C", "link-arg=-Tlink.x",
] ]

View File

@ -1,5 +1,4 @@
use embedded_hal::blocking::spi::Transfer; use embedded_hal::blocking::spi::Transfer;
use cortex_m_semihosting::hprintln;
use crate::Error; use crate::Error;
/* /*
@ -7,7 +6,6 @@ use crate::Error;
*/ */
macro_rules! construct_bitmask { macro_rules! construct_bitmask {
($collection: ident; $($name: ident, $shift: expr, $width: expr),+) => { ($collection: ident; $($name: ident, $shift: expr, $width: expr),+) => {
#[derive(Debug, Copy, Clone)]
pub enum $collection { pub enum $collection {
$( $(
$name, $name,
@ -35,7 +33,7 @@ macro_rules! construct_bitmask {
$collection::$name => { $collection::$name => {
let mut mask: u32 = 0; let mut mask: u32 = 0;
for bit in 0..$width { for bit in 0..$width {
mask |= (1 << ($shift + bit)); mask != 1 << ($width + bit);
} }
mask mask
}, },
@ -82,34 +80,17 @@ where
} }
} }
fn set_all_configurations(&mut self) -> Result<u32, Error<E>> { pub fn set_configuration(&mut self, config: u32) -> Result<u32, Error<E>> {
self.data = config & 0x00FFFFFF;
match self.spi.transfer(&mut [ match self.spi.transfer(&mut [
((self.data & 0x00FF0000) >> 16) as u8, ((config & 0x00FF0000) >> 16) as u8,
((self.data & 0x0000FF00) >> 8) as u8, ((config & 0x0000FF00) >> 8) as u8,
((self.data & 0x000000FF) >> 0) as u8, ((config & 0x000000FF) >> 0) as u8,
]).map_err(Error::SPI) { ]).map_err(Error::SPI) {
Ok(arr) => Ok(self.data), Ok(arr) => Ok(((arr[0] as u32) << 16) | ((arr[1] as u32) << 8) | arr[2] as u32),
Err(e) => Err(e), Err(e) => Err(e),
} }
} }
pub fn set_configurations(&mut self, configs: &mut[(CFGMask, u32)]) -> Result<u32, Error<E>> {
for config in configs.into_iter() {
// Erase the bits in the configuration region
self.data &= (!config.0.get_bitmask());
// Check validity of config data
let shifted_config: u32 = config.1 << config.0.get_shift();
assert_eq!(shifted_config | config.0.get_bitmask(), config.0.get_bitmask());
// Write the configuration onto local data
self.data |= shifted_config;
}
// Write all configurations at the same time
self.set_all_configurations()
}
pub fn get_configuration(&mut self, config_type: CFGMask) -> u8 {
((self.data & config_type.get_bitmask()) >> config_type.get_shift()) as u8
}
} }
impl<SPI, E> Transfer<u8> for ConfigRegister<SPI> impl<SPI, E> Transfer<u8> for ConfigRegister<SPI>

View File

@ -21,10 +21,7 @@ use firmware;
use firmware::{ use firmware::{
CPLD, CPLD,
attenuator::Attenuator, attenuator::Attenuator,
config_register::{ config_register::ConfigRegister,
ConfigRegister,
CFGMask,
},
}; };
#[entry] #[entry]
@ -95,20 +92,7 @@ fn main() -> ! {
attenuator.set_channel_attenuation(2, 15.3); attenuator.set_channel_attenuation(2, 15.3);
let mut config = ConfigRegister::new(parts.spi1); let mut config = ConfigRegister::new(parts.spi1);
// Target configuration: 0x000FF1CE hprintln!("{}", config.set_configuration(0xDEADBEEF).unwrap()).unwrap();
hprintln!("{}", config.set_configurations(&mut [
(CFGMask::RF_SW, 0xE),
(CFGMask::LED, 0xC),
(CFGMask::PROFILE, 0x1),
(CFGMask::IO_UPDATE, 0x1),
(CFGMask::MASK_NU, 0xF),
(CFGMask::CLK_SEL0, 0x1),
(CFGMask::SYNC_SEL, 0x1),
(CFGMask::RST, 0x1),
(CFGMask::IO_RST, 0x0),
(CFGMask::CLK_SEL1, 0x0),
(CFGMask::DIV, 0x0),
]).unwrap()).unwrap();
loop { loop {
nop(); nop();