mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
remove deprecated wfi routines in baremetal
we're now doing wfi testing directly in xous, so these routines are no longer relevant.
This commit is contained in:
parent
f56af4f60d
commit
6424f85210
2 changed files with 0 additions and 266 deletions
|
|
@ -233,113 +233,6 @@ pub fn clockset_wrapper(freq: u32) -> u32 {
|
|||
perclk
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub unsafe fn low_power() -> u32 {
|
||||
use utra::sysctrl;
|
||||
let daric_cgu = sysctrl::HW_SYSCTRL_BASE as *mut u32;
|
||||
let mut cgu = CSR::new(daric_cgu);
|
||||
|
||||
daric_cgu.add(utra::sysctrl::SFR_CGUFD_CFGFDCR_0_4_0.offset()).write_volatile(0x3f3f); // fclk
|
||||
daric_cgu.add(utra::sysctrl::SFR_CGUFD_CFGFDCR_0_4_1.offset()).write_volatile(0x3f3f); // aclk
|
||||
daric_cgu.add(utra::sysctrl::SFR_CGUFD_CFGFDCR_0_4_2.offset()).write_volatile(0x1f1f); // hclk
|
||||
daric_cgu.add(utra::sysctrl::SFR_CGUFD_CFGFDCR_0_4_3.offset()).write_volatile(0x0f0f); // iclk
|
||||
daric_cgu.add(utra::sysctrl::SFR_CGUFD_CFGFDCR_0_4_4.offset()).write_volatile(0x0707); // pclk
|
||||
|
||||
let (min_cycle, fd, perclk) = if let Some((min_cycle, fd, perclk)) = clk_to_per(48, 24) {
|
||||
daric_cgu
|
||||
.add(utra::sysctrl::SFR_CGUFDPER.offset())
|
||||
.write_volatile((min_cycle as u32) << 16 | (fd as u32) << 8 | fd as u32);
|
||||
crate::println!("perclk {}", perclk);
|
||||
(min_cycle, fd, perclk * 1_000_000)
|
||||
} else {
|
||||
crate::println!("couldn't find perclk solution");
|
||||
daric_cgu.add(utra::sysctrl::SFR_CGUFDPER.offset()).write_volatile(0x03_ff_ff);
|
||||
(3, 0xff, 48_000_000 / 4)
|
||||
};
|
||||
let perclk = perclk;
|
||||
|
||||
// DARIC_CGU->cgusel1 = 1; // 0: RC, 1: XTAL
|
||||
cgu.wo(sysctrl::SFR_CGUSEL0, 0);
|
||||
cgu.wo(sysctrl::SFR_CGUSEL1, 1);
|
||||
cgu.wo(sysctrl::SFR_CGUFSCR, bao1x_api::FREQ_OSC_MHZ);
|
||||
cgu.wo(sysctrl::SFR_CGUSET, 0x32);
|
||||
|
||||
let duart = utra::duart::HW_DUART_BASE as *mut u32;
|
||||
duart.add(utra::duart::SFR_CR.offset()).write_volatile(0);
|
||||
// set the ETUC now that we're on the xosc.
|
||||
duart.add(utra::duart::SFR_ETUC.offset()).write_volatile(bao1x_api::FREQ_OSC_MHZ);
|
||||
duart.add(utra::duart::SFR_CR.offset()).write_volatile(1);
|
||||
|
||||
cgu.wo(sysctrl::SFR_IPCOSC, bao1x_api::FREQ_OSC_MHZ * 1_000_000);
|
||||
cgu.wo(sysctrl::SFR_IPCARIPFLOW, 0x32);
|
||||
|
||||
// lower core voltage to 0.7v
|
||||
let mut ao_sysctrl = CSR::new(utralib::HW_AO_SYSCTRL_BASE as *mut u32);
|
||||
ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUTRM0CSR, 0x08420002);
|
||||
// ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUTRM1CSR, 0x1);
|
||||
cgu.wo(sysctrl::SFR_IPCARIPFLOW, 0x57);
|
||||
|
||||
// power down the PLL
|
||||
cgu.wo(sysctrl::SFR_IPCLPEN, cgu.r(sysctrl::SFR_IPCLPEN) & !0x2);
|
||||
cgu.wo(sysctrl::SFR_IPCCR, 0x53);
|
||||
cgu.wo(sysctrl::SFR_IPCARIPFLOW, 0x32);
|
||||
|
||||
for _ in 0..1024 {
|
||||
unsafe { core::arch::asm!("nop") };
|
||||
}
|
||||
crate::println!("PLL pd delay 1");
|
||||
|
||||
crate::println!("fsvalid: {}", daric_cgu.add(sysctrl::SFR_CGUFSVLD.offset()).read_volatile());
|
||||
let clk_desc: [(&'static str, u32, usize); 8] = [
|
||||
("fclk", 16, 0x40 / size_of::<u32>()),
|
||||
("pke", 0, 0x40 / size_of::<u32>()),
|
||||
("ao", 16, 0x44 / size_of::<u32>()),
|
||||
("aoram", 0, 0x44 / size_of::<u32>()),
|
||||
("osc", 16, 0x48 / size_of::<u32>()),
|
||||
("xtal", 0, 0x48 / size_of::<u32>()),
|
||||
("pll0", 16, 0x4c / size_of::<u32>()),
|
||||
("pll1", 0, 0x4c / size_of::<u32>()),
|
||||
];
|
||||
for (name, shift, offset) in clk_desc {
|
||||
let fsfreq = (daric_cgu.add(offset).read_volatile() >> shift) & 0xffff;
|
||||
crate::println!("{}: {} MHz", name, fsfreq);
|
||||
}
|
||||
|
||||
// gates off
|
||||
daric_cgu.add(utra::sysctrl::SFR_ACLKGR.offset()).write_volatile(0x00);
|
||||
daric_cgu.add(utra::sysctrl::SFR_HCLKGR.offset()).write_volatile(0x00);
|
||||
daric_cgu.add(utra::sysctrl::SFR_ICLKGR.offset()).write_volatile(0x00);
|
||||
daric_cgu.add(utra::sysctrl::SFR_PCLKGR.offset()).write_volatile(0x00);
|
||||
// commit dividers
|
||||
daric_cgu.add(utra::sysctrl::SFR_CGUSET.offset()).write_volatile(0x32);
|
||||
let mut udmacore = CSR::new(utra::udma_ctrl::HW_UDMA_CTRL_BASE as *mut u32);
|
||||
udmacore.wo(utra::udma_ctrl::REG_CG, 0x0000_000F); // lower four are the UART
|
||||
|
||||
// reset the UART
|
||||
let uart_buf_addr = crate::platform::UART_IFRAM_ADDR;
|
||||
#[cfg(feature = "bao1x-evb")]
|
||||
let mut udma_uart = unsafe {
|
||||
// safety: this is safe to call, because we set up clock and events prior to calling
|
||||
// new.
|
||||
udma::Uart::get_handle(utra::udma_uart_1::HW_UDMA_UART_1_BASE, uart_buf_addr, uart_buf_addr)
|
||||
};
|
||||
#[cfg(not(feature = "bao1x-evb"))]
|
||||
let mut udma_uart = unsafe {
|
||||
// safety: this is safe to call, because we set up clock and events prior to calling
|
||||
// new.
|
||||
udma::Uart::get_handle(utra::udma_uart_2::HW_UDMA_UART_2_BASE, uart_buf_addr, uart_buf_addr)
|
||||
};
|
||||
let baudrate: u32 = crate::UART_BAUD;
|
||||
let freq: u32 = perclk / 2;
|
||||
udma_uart.set_baud(baudrate, freq);
|
||||
|
||||
crate::println!("Perclk solution: {:x}|{:x} -> {} MHz", min_cycle, fd, perclk / 1_000_000);
|
||||
crate::println!("powerdown: perclk is {} MHz", perclk / 1_000_000);
|
||||
udma_uart.write("powerdown with clocks\r\n".as_bytes());
|
||||
|
||||
perclk
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum KeyPress {
|
||||
|
|
|
|||
|
|
@ -747,165 +747,6 @@ impl Repl {
|
|||
iox.set_gpio_pin_value(IoxPort::PA, 5, IoxValue::High);
|
||||
}
|
||||
}
|
||||
#[cfg(all(feature = "bao1x", feature = "board-baosec"))]
|
||||
"wfi" => {
|
||||
let iox = bao1x_hal::iox::Iox::new(utra::iox::HW_IOX_BASE as *mut u32);
|
||||
|
||||
let ao_bkupreg = CSR::new(utralib::HW_AOBUREG_BASE as *mut u32);
|
||||
for i in 0..8 {
|
||||
crate::println!("backup reg {}: {:08x}", i, unsafe {
|
||||
ao_bkupreg.base().add(i).read_volatile()
|
||||
});
|
||||
}
|
||||
let bkp = ao_bkupreg.r(utra::aobureg::SFR_BUREG_CR_BUREGS0);
|
||||
// this will cause the backup regs to increment every wakeup cycle
|
||||
for i in 0..8 {
|
||||
unsafe {
|
||||
ao_bkupreg.base().add(i).write_volatile(0xcafe_0001 + i as u32 + (bkp & 0xFFFF))
|
||||
};
|
||||
}
|
||||
|
||||
// pin map to PF is controlled here, for some reason...
|
||||
let mut ao_sysctrl = CSR::new(utralib::HW_AO_SYSCTRL_BASE as *mut u32);
|
||||
ao_sysctrl.wo(utra::ao_sysctrl::SFR_IOX, 1);
|
||||
// ao_sysctrl.wo(utra::ao_sysctrl::CR_WKUPMASK, 0x10_10);
|
||||
// ao_sysctrl.wo(utra::ao_sysctrl::CR_WKUPMASK, 0x3FFFF);
|
||||
ao_sysctrl.wo(utra::ao_sysctrl::CR_WKUPMASK, 0x3F);
|
||||
crate::println!("ao wkupmsk: {:x}", ao_sysctrl.r(utra::ao_sysctrl::CR_WKUPMASK));
|
||||
for pin in 2..=9 {
|
||||
iox.setup_pin(
|
||||
IoxPort::PF,
|
||||
pin,
|
||||
Some(IoxDir::Input),
|
||||
Some(IoxFunction::AF1),
|
||||
Some(IoxEnable::Enable),
|
||||
Some(IoxEnable::Enable),
|
||||
Some(IoxEnable::Enable),
|
||||
Some(IoxDriveStrength::Drive2mA),
|
||||
);
|
||||
}
|
||||
let mut dkpc = CSR::new(utralib::HW_DKPC_BASE as *mut u32);
|
||||
dkpc.wo(utra::dkpc::SFR_CFG0, 0x1d);
|
||||
dkpc.wo(utra::dkpc::SFR_CFG1, 0x04_02_02);
|
||||
dkpc.wo(utra::dkpc::SFR_CFG2, 0x0804_02_02);
|
||||
dkpc.wo(utra::dkpc::SFR_CFG4, 20);
|
||||
while dkpc.r(utra::dkpc::SFR_SR1) != 0 {
|
||||
// this register didn't get mapped in register extraction because its type
|
||||
// is `apb_buf2`: FIXME - adjust the register extraction script to capture this type.
|
||||
// this register drains the pending interrupts from the wakeup/keyboard queue
|
||||
let _ = unsafe { dkpc.base().add(8).read_volatile() };
|
||||
}
|
||||
let mut irqarray2 = CSR::new(utralib::HW_IRQARRAY2_BASE as *mut u32);
|
||||
irqarray2.wo(utra::irqarray2::EV_PENDING, 0xFFFF_FFFF);
|
||||
irqarray2.wo(utra::irqarray2::EV_ENABLE, 0xFFFF_FFFF);
|
||||
// crate::platform::irq::enable_irq(utra::irqarray2::IRQARRAY2_IRQ);
|
||||
let forever = if args.len() > 0 { args[0] == "loop" } else { false };
|
||||
|
||||
// current status of WFI:
|
||||
// - we can scan the KP inputs using the KP scan mechanism
|
||||
// - stuff queues up in the fifo
|
||||
// - we see the vld bit set
|
||||
// - we can't get an interrupt to fire.
|
||||
let mut count = 0; // just so we know the machine hasn't crashed
|
||||
loop {
|
||||
crate::print!("{}|", count);
|
||||
for i in (0..6).chain(12..13).chain(8..9) {
|
||||
crate::print!("{:x}: {:x} ", i * 4, unsafe { dkpc.base().add(i).read_volatile() });
|
||||
}
|
||||
let fr = ao_sysctrl.r(utra::ao_sysctrl::SFR_AOFR);
|
||||
crate::print!(
|
||||
"int: {:x}/{:x}/{:x}",
|
||||
irqarray2.r(utra::irqarray2::EV_PENDING),
|
||||
irqarray2.r(utra::irqarray2::EV_STATUS),
|
||||
fr
|
||||
);
|
||||
ao_sysctrl.wo(utra::ao_sysctrl::SFR_AOFR, fr);
|
||||
crate::println!("");
|
||||
if !forever {
|
||||
break;
|
||||
} else {
|
||||
crate::platform::delay(500);
|
||||
}
|
||||
count += 1;
|
||||
}
|
||||
|
||||
// vexriscv::register::vexriscv::mim::write(0x0); // disable all interrupts
|
||||
|
||||
crate::println!("entering wfi");
|
||||
// bring us down to 100MHz so we can turn off regulators
|
||||
let perclk = crate::platform::clockset_wrapper(100_000_000);
|
||||
crate::println!("clocks @ 100MHz");
|
||||
|
||||
// configure PMIC to be off
|
||||
let i2c_channel = bao1x_hal::board::setup_i2c_pins(&iox);
|
||||
use bao1x_hal::udma::GlobalConfig;
|
||||
let udma_global = GlobalConfig::new();
|
||||
udma_global.clock(PeriphId::from(i2c_channel), true);
|
||||
let i2c_ifram = unsafe {
|
||||
bao1x_hal::ifram::IframRange::from_raw_parts(
|
||||
bao1x_hal::board::I2C_IFRAM_ADDR,
|
||||
bao1x_hal::board::I2C_IFRAM_ADDR,
|
||||
4096,
|
||||
)
|
||||
};
|
||||
let mut i2c = unsafe {
|
||||
bao1x_hal::udma::I2cDriver::new_with_ifram(
|
||||
i2c_channel,
|
||||
400_000,
|
||||
perclk,
|
||||
i2c_ifram,
|
||||
&udma_global,
|
||||
)
|
||||
};
|
||||
|
||||
if let Ok(mut pmic) = bao1x_hal::axp2101::Axp2101::new(&mut i2c) {
|
||||
match pmic.set_dcdc(&mut i2c, None, bao1x_hal::axp2101::WhichDcDc::Dcdc2) {
|
||||
Ok(_) => crate::println!("turned off DCDC2"),
|
||||
Err(_) => crate::println!("couldn't turn off DCDC2"),
|
||||
}
|
||||
}
|
||||
|
||||
unsafe {
|
||||
crate::platform::low_power();
|
||||
}
|
||||
crate::println!("pmu cr: {:x}", ao_sysctrl.r(utra::ao_sysctrl::SFR_PMUCSR));
|
||||
crate::println!("pmu status: {:x}", ao_sysctrl.r(utra::ao_sysctrl::SFR_PMUSR));
|
||||
crate::println!("pmu err: {:x}", ao_sysctrl.r(utra::ao_sysctrl::SFR_PMUFR));
|
||||
|
||||
crate::println!("trying PD mode");
|
||||
ao_sysctrl.wo(utra::ao_sysctrl::CR_CR, 7);
|
||||
ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUCRPD, 0x4c);
|
||||
ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUTRMLP0, 0x08420002); // 0.7v
|
||||
ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUPDAR, 0x5a);
|
||||
crate::println!("entered PD mode");
|
||||
|
||||
// turn regulator off - system of course does not work
|
||||
/*
|
||||
crate::println!("attempting to turn off VDD085");
|
||||
ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUCSR, 0x4c);
|
||||
let mut cgu = CSR::new(utra::sysctrl::HW_SYSCTRL_BASE as *mut u32);
|
||||
cgu.wo(utra::sysctrl::SFR_IPCARIPFLOW, 0x57);
|
||||
for _ in 0..1024 {
|
||||
unsafe { core::arch::asm!("nop") };
|
||||
}
|
||||
crate::println!("PD pmu cr: {:x}", ao_sysctrl.r(utra::ao_sysctrl::SFR_PMUCSR));
|
||||
*/
|
||||
|
||||
unsafe { core::arch::asm!("wfi", "nop", "nop", "nop", "nop") };
|
||||
|
||||
// turn regulator back on
|
||||
/*
|
||||
ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUCSR, 0x7c);
|
||||
let mut cgu = CSR::new(utra::sysctrl::HW_SYSCTRL_BASE as *mut u32);
|
||||
cgu.wo(utra::sysctrl::SFR_IPCARIPFLOW, 0x57);
|
||||
for _ in 0..1024 {
|
||||
unsafe { core::arch::asm!("nop") };
|
||||
}
|
||||
crate::println!("PU pmu cr: {:x}", ao_sysctrl.r(utra::ao_sysctrl::SFR_PMUCSR));
|
||||
*/
|
||||
crate::platform::clockset_wrapper(800_000_000);
|
||||
crate::println!("exiting wfi");
|
||||
}
|
||||
#[cfg(feature = "ci-security")]
|
||||
// write protection only works after we leave the boot environment, thus it has to be tested in
|
||||
// baremetal
|
||||
|
|
|
|||
Loading…
Reference in a new issue