mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
implementation for the composeable I/O modes
This commit is contained in:
parent
d647e41822
commit
40e740d869
2 changed files with 112 additions and 24 deletions
|
|
@ -230,6 +230,7 @@ impl BioSharedState {
|
|||
// crate::println!("ldst trial end");
|
||||
}
|
||||
self.bio.wfo(utra::bio_bdma::SFR_FIFO_CLR_SFR_FIFO_CLR, 0xf);
|
||||
self.set_core_run_states([false, false, false, false]);
|
||||
}
|
||||
|
||||
pub fn load_code(&mut self, prog: &[u8], offset_bytes: usize, core: BioCore) {
|
||||
|
|
@ -373,7 +374,7 @@ impl BioSharedState {
|
|||
}
|
||||
ClockMode::TargetFreqFrac(target) => self.compute_dividers(target, true),
|
||||
ClockMode::TargetFreqInt(target) => self.compute_dividers(target, false),
|
||||
ClockMode::ExternalPin(_) => {
|
||||
ClockMode::ExternalPin(pin) => {
|
||||
// disable divisor
|
||||
match core {
|
||||
BioCore::Core0 => self.bio.wo(bio_bdma::SFR_QDIV0, 0),
|
||||
|
|
@ -381,15 +382,59 @@ impl BioSharedState {
|
|||
BioCore::Core2 => self.bio.wo(bio_bdma::SFR_QDIV2, 0),
|
||||
BioCore::Core3 => self.bio.wo(bio_bdma::SFR_QDIV3, 0),
|
||||
};
|
||||
// set the pin for the clock origin
|
||||
match core {
|
||||
BioCore::Core0 => {
|
||||
self.bio.rmwf(bio_bdma::SFR_EXTCLOCK_EXTCLK_GPIO_0, pin.pin_number() as u32)
|
||||
}
|
||||
BioCore::Core1 => {
|
||||
self.bio.rmwf(bio_bdma::SFR_EXTCLOCK_EXTCLK_GPIO_1, pin.pin_number() as u32)
|
||||
}
|
||||
BioCore::Core2 => {
|
||||
self.bio.rmwf(bio_bdma::SFR_EXTCLOCK_EXTCLK_GPIO_2, pin.pin_number() as u32)
|
||||
}
|
||||
BioCore::Core3 => {
|
||||
self.bio.rmwf(bio_bdma::SFR_EXTCLOCK_EXTCLK_GPIO_3, pin.pin_number() as u32)
|
||||
}
|
||||
};
|
||||
// mask in the core that is now listening to the clock
|
||||
let existing_extclk = self.bio.rf(bio_bdma::SFR_EXTCLOCK_USE_EXTCLK);
|
||||
self.bio.rmwf(bio_bdma::SFR_EXTCLOCK_USE_EXTCLK, (1 << core as u32) | existing_extclk);
|
||||
crate::println!("core: {:?} - extclock {:x}", core, self.bio.r(bio_bdma::SFR_EXTCLOCK));
|
||||
return None;
|
||||
}
|
||||
};
|
||||
let sfr_value = (div_int as u32) << 16 | (div_frac as u32) << 8;
|
||||
match core {
|
||||
BioCore::Core0 => self.bio.wo(bio_bdma::SFR_QDIV0, sfr_value),
|
||||
BioCore::Core1 => self.bio.wo(bio_bdma::SFR_QDIV1, sfr_value),
|
||||
BioCore::Core2 => self.bio.wo(bio_bdma::SFR_QDIV2, sfr_value),
|
||||
BioCore::Core3 => self.bio.wo(bio_bdma::SFR_QDIV3, sfr_value),
|
||||
BioCore::Core0 => {
|
||||
self.bio.wo(bio_bdma::SFR_QDIV0, sfr_value);
|
||||
// also mask off extclock if it was previously set.
|
||||
self.bio.rmwf(
|
||||
bio_bdma::SFR_EXTCLOCK_USE_EXTCLK,
|
||||
self.bio.rf(bio_bdma::SFR_EXTCLOCK_USE_EXTCLK) & 0b1110,
|
||||
);
|
||||
}
|
||||
BioCore::Core1 => {
|
||||
self.bio.wo(bio_bdma::SFR_QDIV1, sfr_value);
|
||||
self.bio.rmwf(
|
||||
bio_bdma::SFR_EXTCLOCK_USE_EXTCLK,
|
||||
self.bio.rf(bio_bdma::SFR_EXTCLOCK_USE_EXTCLK) & 0b1101,
|
||||
);
|
||||
}
|
||||
BioCore::Core2 => {
|
||||
self.bio.wo(bio_bdma::SFR_QDIV2, sfr_value);
|
||||
self.bio.rmwf(
|
||||
bio_bdma::SFR_EXTCLOCK_USE_EXTCLK,
|
||||
self.bio.rf(bio_bdma::SFR_EXTCLOCK_USE_EXTCLK) & 0b1011,
|
||||
);
|
||||
}
|
||||
BioCore::Core3 => {
|
||||
self.bio.wo(bio_bdma::SFR_QDIV3, sfr_value);
|
||||
self.bio.rmwf(
|
||||
bio_bdma::SFR_EXTCLOCK_USE_EXTCLK,
|
||||
self.bio.rf(bio_bdma::SFR_EXTCLOCK_USE_EXTCLK) & 0xb0111,
|
||||
);
|
||||
}
|
||||
};
|
||||
Some(actual_freq)
|
||||
}
|
||||
|
|
@ -495,10 +540,33 @@ impl<'a> BioApi<'a> for BioSharedState {
|
|||
}
|
||||
|
||||
fn setup_io_config(&mut self, config: IoConfig) -> Result<(), BioError> {
|
||||
self.bio.wo(bio_bdma::SFR_IO_I_INV, config.i_inv);
|
||||
self.bio.wo(bio_bdma::SFR_IO_O_INV, config.o_inv);
|
||||
self.bio.wo(bio_bdma::SFR_IO_OE_INV, config.oe_inv);
|
||||
self.bio.wo(bio_bdma::SFR_SYNC_BYPASS, config.sync_bypass);
|
||||
match config.mode {
|
||||
IoConfigMode::Overwrite => {
|
||||
self.bio.wo(bio_bdma::SFR_IO_I_INV, config.i_inv);
|
||||
self.bio.wo(bio_bdma::SFR_IO_O_INV, config.o_inv);
|
||||
self.bio.wo(bio_bdma::SFR_IO_OE_INV, config.oe_inv);
|
||||
self.bio.wo(bio_bdma::SFR_SYNC_BYPASS, config.sync_bypass);
|
||||
}
|
||||
IoConfigMode::SetOnly => {
|
||||
self.bio.wo(bio_bdma::SFR_IO_I_INV, config.i_inv | self.bio.r(bio_bdma::SFR_IO_I_INV));
|
||||
self.bio.wo(bio_bdma::SFR_IO_O_INV, config.o_inv | self.bio.r(bio_bdma::SFR_IO_O_INV));
|
||||
self.bio.wo(bio_bdma::SFR_IO_OE_INV, config.oe_inv | self.bio.r(bio_bdma::SFR_IO_OE_INV));
|
||||
self.bio.wo(
|
||||
bio_bdma::SFR_SYNC_BYPASS,
|
||||
config.sync_bypass | self.bio.r(bio_bdma::SFR_SYNC_BYPASS),
|
||||
);
|
||||
}
|
||||
IoConfigMode::ClearOnly => {
|
||||
self.bio.wo(bio_bdma::SFR_IO_I_INV, !config.i_inv & self.bio.r(bio_bdma::SFR_IO_I_INV));
|
||||
self.bio.wo(bio_bdma::SFR_IO_O_INV, !config.o_inv & self.bio.r(bio_bdma::SFR_IO_O_INV));
|
||||
self.bio.wo(bio_bdma::SFR_IO_OE_INV, !config.oe_inv & self.bio.r(bio_bdma::SFR_IO_OE_INV));
|
||||
self.bio.wo(
|
||||
bio_bdma::SFR_SYNC_BYPASS,
|
||||
!config.sync_bypass & self.bio.r(bio_bdma::SFR_SYNC_BYPASS),
|
||||
);
|
||||
}
|
||||
}
|
||||
self.iox.set_ports_from_bio_bitmask(config.mapped, config.mode);
|
||||
|
||||
let mut sfr = self.bio.r(bio_bdma::SFR_CONFIG);
|
||||
if let Some(core) = config.snap_inputs {
|
||||
|
|
@ -523,7 +591,6 @@ impl<'a> BioApi<'a> for BioSharedState {
|
|||
}
|
||||
self.bio.wo(bio_bdma::SFR_CONFIG, sfr);
|
||||
|
||||
self.iox.set_ports_from_bio_bitmask(config.mapped);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use bao1x_api::*;
|
||||
use bao1x_api::{bio::IoConfigMode, *};
|
||||
use utralib::generated::utra::iox;
|
||||
|
||||
use crate::SharedCsr;
|
||||
|
|
@ -191,11 +191,21 @@ impl Iox {
|
|||
/// by the mapping request. The index of the array corresponds to the bit position in
|
||||
/// the bitmask. You may use this to pass as arguments to further functions
|
||||
/// that do things like control slew rate or apply pull-ups.
|
||||
pub fn set_ports_from_bio_bitmask(&self, enable_bitmask: u32) -> [Option<(IoxPort, u8)>; 32] {
|
||||
///
|
||||
/// Note: IoConfigMode is only lightly tested. ClearOnlyMode in particular could have bugs.
|
||||
pub fn set_ports_from_bio_bitmask(
|
||||
&self,
|
||||
enable_bitmask: u32,
|
||||
mode: IoConfigMode,
|
||||
) -> [Option<(IoxPort, u8)>; 32] {
|
||||
let mut mapping: [Option<(IoxPort, u8)>; 32] = [None; 32];
|
||||
|
||||
for i in 0..32 {
|
||||
let enable = ((enable_bitmask >> i) & 1) != 0;
|
||||
let mut enable = ((enable_bitmask >> i) & 1) != 0;
|
||||
|
||||
if mode == IoConfigMode::ClearOnly {
|
||||
enable = !enable;
|
||||
}
|
||||
|
||||
if enable {
|
||||
let map: Option<(IoxPort, u8)> = match i {
|
||||
|
|
@ -235,22 +245,33 @@ impl Iox {
|
|||
31 => Some((IoxPort::PC, 15)),
|
||||
_ => None,
|
||||
};
|
||||
if let Some((port, pin)) = map {
|
||||
// AF1 must be selected
|
||||
self.set_alternate_function(port, pin, IoxFunction::AF1);
|
||||
// then the BIO register must have its bit flipped to 1
|
||||
self.csr.wo(iox::SFR_PIOSEL, self.csr.r(iox::SFR_PIOSEL) | (1 << i));
|
||||
mapping[i] = Some((port, pin));
|
||||
if mode == IoConfigMode::Overwrite || mode == IoConfigMode::SetOnly {
|
||||
if let Some((port, pin)) = map {
|
||||
// AF1 must be selected
|
||||
self.set_alternate_function(port, pin, IoxFunction::AF1);
|
||||
// then the BIO register must have its bit flipped to 1
|
||||
self.csr.wo(iox::SFR_PIOSEL, self.csr.r(iox::SFR_PIOSEL) | (1 << i));
|
||||
mapping[i] = Some((port, pin));
|
||||
}
|
||||
}
|
||||
if mode == IoConfigMode::ClearOnly {
|
||||
mapping[i] = None;
|
||||
// ensure that the BIO register bit is not set
|
||||
self.csr.wo(iox::SFR_PIOSEL, self.csr.r(iox::SFR_PIOSEL) & !(1 << i));
|
||||
}
|
||||
} else {
|
||||
mapping[i] = None;
|
||||
// ensure that the BIO register bit is not set
|
||||
self.csr.wo(iox::SFR_PIOSEL, self.csr.r(iox::SFR_PIOSEL) & !(1 << i));
|
||||
if mode == IoConfigMode::Overwrite {
|
||||
mapping[i] = None;
|
||||
// ensure that the BIO register bit is not set
|
||||
self.csr.wo(iox::SFR_PIOSEL, self.csr.r(iox::SFR_PIOSEL) & !(1 << i));
|
||||
}
|
||||
}
|
||||
}
|
||||
mapping
|
||||
}
|
||||
|
||||
pub fn get_bio_mapping_bitmask(&self) -> u32 { self.csr.r(iox::SFR_PIOSEL) }
|
||||
|
||||
/// Returns the BIO bit that was enabled based on the port and pin specifier given;
|
||||
/// returns `None` if the proposed mapping is invalid.
|
||||
pub fn set_bio_bit_from_port_and_pin(&self, port: IoxPort, pin: u8) -> Option<u8> {
|
||||
|
|
@ -381,8 +402,8 @@ impl IoSetup for Iox {
|
|||
self.set_bio_bit_from_port_and_pin(port, pin)
|
||||
}
|
||||
|
||||
fn set_ports_from_bio_bitmask(&self, enable_bitmask: u32) {
|
||||
self.set_ports_from_bio_bitmask(enable_bitmask);
|
||||
fn set_ports_from_bio_bitmask(&self, enable_bitmask: u32, io_mode: bao1x_api::bio::IoConfigMode) {
|
||||
self.set_ports_from_bio_bitmask(enable_bitmask, io_mode);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue