mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
commit
146405fb57
23 changed files with 548 additions and 201 deletions
|
|
@ -47,5 +47,8 @@ print-ifr = []
|
||||||
test-boot0-keys = []
|
test-boot0-keys = []
|
||||||
alt-boot1 = []
|
alt-boot1 = []
|
||||||
|
|
||||||
|
oem = []
|
||||||
|
oem-baosec-lite = ["oem", "bao1x-hal/oem-baosec-lite"]
|
||||||
|
|
||||||
verilator-only = []
|
verilator-only = []
|
||||||
default = []
|
default = ["oem-baosec-lite"]
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,16 @@ pub unsafe extern "C" fn rust_entry() -> ! {
|
||||||
let one_way = bao1x_hal::acram::OneWayCounter::new();
|
let one_way = bao1x_hal::acram::OneWayCounter::new();
|
||||||
let mut board_type =
|
let mut board_type =
|
||||||
one_way.get_decoded::<bao1x_api::BoardTypeCoding>().expect("Board type coding error");
|
one_way.get_decoded::<bao1x_api::BoardTypeCoding>().expect("Board type coding error");
|
||||||
|
#[cfg(feature = "oem-baosec-lite")]
|
||||||
|
{
|
||||||
|
// this this flag was explicitly passed, this firmware image is only useful for OEM boards.
|
||||||
|
// set the board type as thus.
|
||||||
|
while board_type != bao1x_api::BoardTypeCoding::Oem {
|
||||||
|
one_way.inc_coded::<bao1x_api::BoardTypeCoding>().ok();
|
||||||
|
board_type =
|
||||||
|
one_way.get_decoded::<bao1x_api::BoardTypeCoding>().expect("Board type coding error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// crate::println_d!("TX_IDLE: {:?}", crate::platform::usb::TX_IDLE.load(Ordering::SeqCst));
|
// crate::println_d!("TX_IDLE: {:?}", crate::platform::usb::TX_IDLE.load(Ordering::SeqCst));
|
||||||
let perclk: u32;
|
let perclk: u32;
|
||||||
|
|
@ -107,6 +117,10 @@ pub unsafe extern "C" fn rust_entry() -> ! {
|
||||||
if board_type == BoardTypeCoding::Baosec {
|
if board_type == BoardTypeCoding::Baosec {
|
||||||
IS_BAOSEC.store(true, Ordering::SeqCst);
|
IS_BAOSEC.store(true, Ordering::SeqCst);
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "oem-baosec-lite")]
|
||||||
|
{
|
||||||
|
IS_BAOSEC.store(true, Ordering::SeqCst);
|
||||||
|
}
|
||||||
|
|
||||||
let iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32);
|
let iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32);
|
||||||
|
|
||||||
|
|
@ -164,6 +178,14 @@ pub unsafe extern "C" fn rust_entry() -> ! {
|
||||||
// grab a handle to the OLED if it exists on the board.
|
// grab a handle to the OLED if it exists on the board.
|
||||||
let mut udma_global = GlobalConfig::new();
|
let mut udma_global = GlobalConfig::new();
|
||||||
let mut oled_iox = iox.clone();
|
let mut oled_iox = iox.clone();
|
||||||
|
#[cfg(feature = "oem-baosec-lite")]
|
||||||
|
let mut oled = Some(bao1x_hal::sh1107::Oled128x128::new(
|
||||||
|
bao1x_hal::sh1107::MainThreadToken::new(),
|
||||||
|
perclk,
|
||||||
|
&mut oled_iox,
|
||||||
|
&mut udma_global,
|
||||||
|
));
|
||||||
|
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||||
let mut oled = if board_type == BoardTypeCoding::Baosec {
|
let mut oled = if board_type == BoardTypeCoding::Baosec {
|
||||||
Some(bao1x_hal::sh1107::Oled128x128::new(
|
Some(bao1x_hal::sh1107::Oled128x128::new(
|
||||||
bao1x_hal::sh1107::MainThreadToken::new(),
|
bao1x_hal::sh1107::MainThreadToken::new(),
|
||||||
|
|
@ -221,6 +243,8 @@ pub unsafe extern "C" fn rust_entry() -> ! {
|
||||||
if board_type == BoardTypeCoding::Baosec {
|
if board_type == BoardTypeCoding::Baosec {
|
||||||
crate::glue::setup_spim(perclk);
|
crate::glue::setup_spim(perclk);
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "oem-baosec-lite")]
|
||||||
|
crate::glue::setup_spim(perclk);
|
||||||
|
|
||||||
// it's in this loop that the board type would be set after initial boot
|
// it's in this loop that the board type would be set after initial boot
|
||||||
let mut repl = crate::repl::Repl::new();
|
let mut repl = crate::repl::Repl::new();
|
||||||
|
|
@ -324,10 +348,16 @@ pub unsafe extern "C" fn rust_entry() -> ! {
|
||||||
iox.set_gpio_dir(se0_dabao.0, se0_dabao.1, bao1x_api::IoxDir::Input);
|
iox.set_gpio_dir(se0_dabao.0, se0_dabao.1, bao1x_api::IoxDir::Input);
|
||||||
(se0_baosec.0, se0_baosec.1)
|
(se0_baosec.0, se0_baosec.1)
|
||||||
}
|
}
|
||||||
|
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||||
_ => {
|
_ => {
|
||||||
iox.set_gpio_dir(se0_baosec.0, se0_baosec.1, bao1x_api::IoxDir::Input);
|
iox.set_gpio_dir(se0_baosec.0, se0_baosec.1, bao1x_api::IoxDir::Input);
|
||||||
(se0_dabao.0, se0_dabao.1)
|
(se0_dabao.0, se0_dabao.1)
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "oem-baosec-lite")]
|
||||||
|
_ => {
|
||||||
|
iox.set_gpio_dir(se0_dabao.0, se0_dabao.1, bao1x_api::IoxDir::Input);
|
||||||
|
(se0_baosec.0, se0_baosec.1)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
boot(&iox, oled, se0_port, se0_pin, &mut csprng)
|
boot(&iox, oled, se0_port, se0_pin, &mut csprng)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ pub const FREE_MEM_LEN: usize = (RAM_BASE + RAM_SIZE) - FREE_MEM_START - STACK_L
|
||||||
// NOTE: this forces the mapping to be the same on both baosec and dabao
|
// NOTE: this forces the mapping to be the same on both baosec and dabao
|
||||||
pub const UART_IFRAM_ADDR: usize = bao1x_hal::board::UART_DMA_TX_BUF_PHYS;
|
pub const UART_IFRAM_ADDR: usize = bao1x_hal::board::UART_DMA_TX_BUF_PHYS;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
const SAFE_FCLK_FREQUENCY: u32 = 350_000_000;
|
const SAFE_FCLK_FREQUENCY: u32 = 350_000_000;
|
||||||
|
|
||||||
// Dabao port/pin constants have to be vendored in because this crate is compiled with baosec as the target.
|
// Dabao port/pin constants have to be vendored in because this crate is compiled with baosec as the target.
|
||||||
|
|
@ -168,17 +169,73 @@ pub fn early_init(mut board_type: bao1x_api::BoardTypeCoding) -> (bao1x_api::Boa
|
||||||
if setup_backup_region() == 0 {
|
if setup_backup_region() == 0 {
|
||||||
crate::println!("backup region is clean!");
|
crate::println!("backup region is clean!");
|
||||||
}
|
}
|
||||||
/* // debug RTC setting - remove once confident
|
|
||||||
let rtc = CSR::new(bao1x_hal::rtc::HW_RTC_BASE as *mut u32);
|
|
||||||
for i in 0..8 {
|
|
||||||
crate::println_d!("rtc {}: {:x}", i, unsafe { rtc.base().add(i).read_volatile() });
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// setup board-specific I/Os - early boot set. These are items that have to be
|
// setup board-specific I/Os - early boot set. These are items that have to be
|
||||||
// done in a time-sensitive fashion.
|
// done in a time-sensitive fashion.
|
||||||
match board_type {
|
match board_type {
|
||||||
BoardTypeCoding::Dabao | BoardTypeCoding::Oem => {
|
#[cfg(feature = "oem-baosec-lite")]
|
||||||
|
BoardTypeCoding::Oem => {
|
||||||
|
let power_off_port = bao1x_hal::board::get_power_off_pin();
|
||||||
|
iox.setup_pin(
|
||||||
|
power_off_port.0,
|
||||||
|
power_off_port.1,
|
||||||
|
Some(IoxDir::Output),
|
||||||
|
Some(IoxFunction::Gpio),
|
||||||
|
None,
|
||||||
|
Some(IoxEnable::Disable),
|
||||||
|
None,
|
||||||
|
Some(IoxDriveStrength::Drive2mA),
|
||||||
|
);
|
||||||
|
// ensures the device stays on
|
||||||
|
iox.set_gpio_pin(power_off_port.0, power_off_port.1, IoxValue::Low);
|
||||||
|
|
||||||
|
let mut sramtrm = CSR::new(utra::coresub_sramtrm::HW_CORESUB_SRAMTRM_BASE as *mut u32);
|
||||||
|
sramtrm.wo(utra::coresub_sramtrm::SFR_CACHE, 0x3);
|
||||||
|
sramtrm.wo(utra::coresub_sramtrm::SFR_ITCM, 0x3);
|
||||||
|
sramtrm.wo(utra::coresub_sramtrm::SFR_DTCM, 0x3);
|
||||||
|
sramtrm.wo(utra::coresub_sramtrm::SFR_VEXRAM, 0x1);
|
||||||
|
|
||||||
|
let trim_table = bao1x_hal::sram_trim::get_sram_trim_for_voltage(
|
||||||
|
bao1x_api::offsets::baosec::CPU_VDD_LDO_BOOT_MV,
|
||||||
|
);
|
||||||
|
let mut rbist = CSR::new(utra::rbist_wrp::HW_RBIST_WRP_BASE as *mut u32);
|
||||||
|
for item in trim_table {
|
||||||
|
rbist.wo(utra::rbist_wrp::SFRCR_TRM, item.raw_value());
|
||||||
|
rbist.wo(utra::rbist_wrp::SFRAR_TRM, 0x5a);
|
||||||
|
}
|
||||||
|
|
||||||
|
let (se0_port, se0_pin) = bao1x_hal::board::setup_usb_pins(&iox);
|
||||||
|
iox.set_gpio_pin(se0_port, se0_pin, IoxValue::Low); // put the USB port into SE0 while we initialize things
|
||||||
|
|
||||||
|
// setup display - turn on its power, reset the framebuffer
|
||||||
|
bao1x_hal::board::setup_display_pins(&iox);
|
||||||
|
// power on
|
||||||
|
let (oled_on_port, oled_on_pin) = bao1x_hal::board::setup_oled_power_pin(&iox);
|
||||||
|
iox.set_gpio_pin_value(oled_on_port, oled_on_pin, IoxValue::High);
|
||||||
|
|
||||||
|
// reset enable - note inversion compared to baosec (at least as of this board rev of baosec)
|
||||||
|
bao1x_hal::board::setup_periph_reset_pin(&iox);
|
||||||
|
bao1x_hal::board::assert_periph_reset(&iox, true);
|
||||||
|
// delay for reset assert
|
||||||
|
delay(1);
|
||||||
|
bao1x_hal::board::assert_periph_reset(&iox, false);
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "oem"))]
|
||||||
|
BoardTypeCoding::Oem => {
|
||||||
|
// provide a default behavior for unbound OEM board settings
|
||||||
|
setup_dabao_boot_pin(&iox);
|
||||||
|
|
||||||
|
// setup the RAMs for our trim voltage
|
||||||
|
let trim_table = bao1x_hal::sram_trim::get_sram_trim_for_voltage(
|
||||||
|
bao1x_api::offsets::dabao::CPU_VDD_LDO_BOOT_MV,
|
||||||
|
);
|
||||||
|
let mut rbist = CSR::new(utra::rbist_wrp::HW_RBIST_WRP_BASE as *mut u32);
|
||||||
|
for item in trim_table {
|
||||||
|
rbist.wo(utra::rbist_wrp::SFRCR_TRM, item.raw_value());
|
||||||
|
rbist.wo(utra::rbist_wrp::SFRAR_TRM, 0x5a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BoardTypeCoding::Dabao => {
|
||||||
// setup the dabao 'boot' read pin for reading. This also connects the USB port temporarily.
|
// setup the dabao 'boot' read pin for reading. This also connects the USB port temporarily.
|
||||||
setup_dabao_boot_pin(&iox);
|
setup_dabao_boot_pin(&iox);
|
||||||
|
|
||||||
|
|
@ -342,6 +399,9 @@ pub fn early_init(mut board_type: bao1x_api::BoardTypeCoding) -> (bao1x_api::Boa
|
||||||
// set the clock
|
// set the clock
|
||||||
let fclk_freq = match board_type {
|
let fclk_freq = match board_type {
|
||||||
BoardTypeCoding::Baosec => bao1x_api::offsets::baosec::DEFAULT_FCLK_FREQUENCY,
|
BoardTypeCoding::Baosec => bao1x_api::offsets::baosec::DEFAULT_FCLK_FREQUENCY,
|
||||||
|
#[cfg(feature = "oem-baosec-lite")]
|
||||||
|
BoardTypeCoding::Oem => bao1x_api::offsets::baosec::DEFAULT_FCLK_FREQUENCY,
|
||||||
|
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||||
BoardTypeCoding::Oem => SAFE_FCLK_FREQUENCY,
|
BoardTypeCoding::Oem => SAFE_FCLK_FREQUENCY,
|
||||||
BoardTypeCoding::Dabao => bao1x_api::offsets::dabao::DEFAULT_FCLK_FREQUENCY,
|
BoardTypeCoding::Dabao => bao1x_api::offsets::dabao::DEFAULT_FCLK_FREQUENCY,
|
||||||
};
|
};
|
||||||
|
|
@ -456,7 +516,25 @@ pub fn get_key<T: IoSetup + IoGpio>(board_type: &BoardTypeCoding, iox: &T) -> Op
|
||||||
// record which key is pressed
|
// record which key is pressed
|
||||||
if kps[0] != KeyPress::None { Some(kps[0]) } else { None }
|
if kps[0] != KeyPress::None { Some(kps[0]) } else { None }
|
||||||
}
|
}
|
||||||
_ => {
|
BoardTypeCoding::Dabao => {
|
||||||
|
let (port, pin) = crate::platform::setup_dabao_boot_pin(iox);
|
||||||
|
// sample the pin
|
||||||
|
if iox.get_gpio_pin_value(port, pin) == IoxValue::Low {
|
||||||
|
// "borrow" the dabao keypress meaning for this pin
|
||||||
|
Some(KeyPress::Select)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(feature = "oem-baosec-lite")]
|
||||||
|
BoardTypeCoding::Oem => {
|
||||||
|
let (rows, cols) = bao1x_hal::board::setup_kb_pins(iox);
|
||||||
|
let kps = bao1x_hal::board::scan_keyboard(iox, &rows, &cols);
|
||||||
|
// record which key is pressed
|
||||||
|
if kps[0] != KeyPress::None { Some(kps[0]) } else { None }
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||||
|
BoardTypeCoding::Oem => {
|
||||||
let (port, pin) = crate::platform::setup_dabao_boot_pin(iox);
|
let (port, pin) = crate::platform::setup_dabao_boot_pin(iox);
|
||||||
// sample the pin
|
// sample the pin
|
||||||
if iox.get_gpio_pin_value(port, pin) == IoxValue::Low {
|
if iox.get_gpio_pin_value(port, pin) == IoxValue::Low {
|
||||||
|
|
|
||||||
|
|
@ -597,6 +597,7 @@ impl Repl {
|
||||||
let one_way = bao1x_hal::acram::OneWayCounter::new();
|
let one_way = bao1x_hal::acram::OneWayCounter::new();
|
||||||
let board_type =
|
let board_type =
|
||||||
one_way.get_decoded::<bao1x_api::BoardTypeCoding>().expect("Board type coding error");
|
one_way.get_decoded::<bao1x_api::BoardTypeCoding>().expect("Board type coding error");
|
||||||
|
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||||
if board_type != bao1x_api::BoardTypeCoding::Baosec {
|
if board_type != bao1x_api::BoardTypeCoding::Baosec {
|
||||||
while one_way.get_decoded::<bao1x_api::BoardTypeCoding>().expect("owc coding error")
|
while one_way.get_decoded::<bao1x_api::BoardTypeCoding>().expect("owc coding error")
|
||||||
!= bao1x_api::BoardTypeCoding::Baosec
|
!= bao1x_api::BoardTypeCoding::Baosec
|
||||||
|
|
@ -604,6 +605,14 @@ impl Repl {
|
||||||
one_way.inc_coded::<bao1x_api::BoardTypeCoding>().expect("increment error");
|
one_way.inc_coded::<bao1x_api::BoardTypeCoding>().expect("increment error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "oem-baosec-lite")]
|
||||||
|
if board_type != bao1x_api::BoardTypeCoding::Oem {
|
||||||
|
while one_way.get_decoded::<bao1x_api::BoardTypeCoding>().expect("owc coding error")
|
||||||
|
!= bao1x_api::BoardTypeCoding::Oem
|
||||||
|
{
|
||||||
|
one_way.inc_coded::<bao1x_api::BoardTypeCoding>().expect("increment error");
|
||||||
|
}
|
||||||
|
}
|
||||||
// reset the USB stack so that we'll re-enumerate correctly after this reboot.
|
// reset the USB stack so that we'll re-enumerate correctly after this reboot.
|
||||||
// This also has the side-effect of redirecting the console output back to the serial port.
|
// This also has the side-effect of redirecting the console output back to the serial port.
|
||||||
crate::platform::usb::glue::shutdown();
|
crate::platform::usb::glue::shutdown();
|
||||||
|
|
@ -615,8 +624,16 @@ impl Repl {
|
||||||
// CI note: this appears on the "hard UART", not on USB serial. If we want this on USB
|
// CI note: this appears on the "hard UART", not on USB serial. If we want this on USB
|
||||||
// serial, we would want to add some wait time to ensure the USB packets get sent before
|
// serial, we would want to add some wait time to ensure the USB packets get sent before
|
||||||
// issuing the reboot command.
|
// issuing the reboot command.
|
||||||
crate::println!("{}BOOT1.SETBOARD,{}", BOOKEND_START, BOOKEND_END);
|
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||||
crate::println!("Board type set to baosec, rebooting so boot1 can provision keys!");
|
{
|
||||||
|
crate::println!("{}BOOT1.SETBOARD,{}", BOOKEND_START, BOOKEND_END);
|
||||||
|
crate::println!("Board type set to baosec, rebooting so boot1 can provision keys!");
|
||||||
|
}
|
||||||
|
#[cfg(feature = "oem-baosec-lite")]
|
||||||
|
{
|
||||||
|
crate::println!("Board type set to baosec-lite, rebooting so boot1 can provision keys!");
|
||||||
|
crate::println!("{}BOOT1.SETBOARD-LITE,{}", BOOKEND_START, BOOKEND_END);
|
||||||
|
}
|
||||||
let mut rcurst = CSR::new(utra::sysctrl::HW_SYSCTRL_BASE as *mut u32);
|
let mut rcurst = CSR::new(utra::sysctrl::HW_SYSCTRL_BASE as *mut u32);
|
||||||
rcurst.wo(utra::sysctrl::SFR_RCURST0, 0x55AA);
|
rcurst.wo(utra::sysctrl::SFR_RCURST0, 0x55AA);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,8 @@ pub const BAOCHIP_1X_UF2_FAMILY: u32 = 0xa7d7_6373;
|
||||||
// density 18, memory type 20, mfg ID C2 ==> MX25L128833F
|
// density 18, memory type 20, mfg ID C2 ==> MX25L128833F
|
||||||
// density 38, memory type 25, mfg ID C2 ==> MX25U12832F
|
// density 38, memory type 25, mfg ID C2 ==> MX25U12832F
|
||||||
// mfg ID 0b ==> XT25Q64FWOIGT cost down option (8MiB)
|
// mfg ID 0b ==> XT25Q64FWOIGT cost down option (8MiB)
|
||||||
pub const SPI_FLASH_IDS: [u32; 3] = [0x1820c2, 0x3825c2, 0x17600b];
|
// mfg ID ba ==> ZD25Q64B super-cost down option (8MiB)
|
||||||
|
pub const SPI_FLASH_IDS: [u32; 4] = [0x1820c2, 0x3825c2, 0x17600b, 0x1732ba];
|
||||||
// KGD 5D, mfg ID 9D; remainder of bits are part of the EID
|
// KGD 5D, mfg ID 9D; remainder of bits are part of the EID
|
||||||
pub const RAM_IDS: [u32; 3] = [0x5D9D, 0x559d, 0x5D0D];
|
pub const RAM_IDS: [u32; 3] = [0x5D9D, 0x559d, 0x5D0D];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,9 @@ board-baosec = [
|
||||||
"ux-api/board-baosec",
|
"ux-api/board-baosec",
|
||||||
"ux-api/std",
|
"ux-api/std",
|
||||||
] # USB form factor token
|
] # USB form factor token
|
||||||
|
# "lite" variant of baosec. Shares the same basic flags but some things remapped when this is added.
|
||||||
|
oem-baosec-lite = []
|
||||||
|
|
||||||
loader-baosec = [
|
loader-baosec = [
|
||||||
"utralib/bao1x",
|
"utralib/bao1x",
|
||||||
"camera-gc2145",
|
"camera-gc2145",
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,7 @@ pub fn setup_memory_pins(iox: &dyn IoSetup) -> SpimChannel {
|
||||||
None,
|
None,
|
||||||
Some(IoxFunction::AF1),
|
Some(IoxFunction::AF1),
|
||||||
None,
|
None,
|
||||||
None,
|
Some(IoxEnable::Enable),
|
||||||
Some(IoxEnable::Disable),
|
Some(IoxEnable::Disable),
|
||||||
Some(IoxDriveStrength::Drive8mA),
|
Some(IoxDriveStrength::Drive8mA),
|
||||||
);
|
);
|
||||||
|
|
@ -169,7 +169,7 @@ pub fn setup_memory_pins(iox: &dyn IoSetup) -> SpimChannel {
|
||||||
Some(IoxDir::Output),
|
Some(IoxDir::Output),
|
||||||
Some(IoxFunction::AF1),
|
Some(IoxFunction::AF1),
|
||||||
None,
|
None,
|
||||||
None,
|
Some(IoxEnable::Enable),
|
||||||
Some(IoxEnable::Disable),
|
Some(IoxEnable::Disable),
|
||||||
Some(IoxDriveStrength::Drive8mA),
|
Some(IoxDriveStrength::Drive8mA),
|
||||||
);
|
);
|
||||||
|
|
@ -220,9 +220,13 @@ pub fn get_i2c_channel() -> I2cChannel { I2C_CHANNEL }
|
||||||
|
|
||||||
/// returns the power-down port and pin number
|
/// returns the power-down port and pin number
|
||||||
pub fn setup_camera_pins<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
pub fn setup_camera_pins<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
||||||
|
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||||
|
let pwdn = (IoxPort::PC, 14);
|
||||||
|
#[cfg(feature = "oem-baosec-lite")]
|
||||||
|
let pwdn = (IoxPort::PA, 5);
|
||||||
iox.setup_pin(
|
iox.setup_pin(
|
||||||
IoxPort::PC,
|
pwdn.0,
|
||||||
14,
|
pwdn.1,
|
||||||
Some(IoxDir::Output),
|
Some(IoxDir::Output),
|
||||||
Some(IoxFunction::Gpio),
|
Some(IoxFunction::Gpio),
|
||||||
None,
|
None,
|
||||||
|
|
@ -231,7 +235,7 @@ pub fn setup_camera_pins<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
||||||
Some(IoxDriveStrength::Drive2mA),
|
Some(IoxDriveStrength::Drive2mA),
|
||||||
);
|
);
|
||||||
// power-down pin - default to powered down
|
// power-down pin - default to powered down
|
||||||
iox.set_gpio_pin_value(IoxPort::PC, 14, IoxValue::High);
|
iox.set_gpio_pin_value(pwdn.0, pwdn.1, IoxValue::High);
|
||||||
// camera interface proper
|
// camera interface proper
|
||||||
for pin in 2..11 {
|
for pin in 2..11 {
|
||||||
iox.setup_pin(
|
iox.setup_pin(
|
||||||
|
|
@ -245,11 +249,13 @@ pub fn setup_camera_pins<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
||||||
Some(IoxDriveStrength::Drive2mA),
|
Some(IoxDriveStrength::Drive2mA),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
(IoxPort::PC, 14)
|
pwdn
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setup_periph_reset_pin<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
pub fn setup_periph_reset_pin<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
||||||
|
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||||
let (port, pin) = (IoxPort::PC, 6);
|
let (port, pin) = (IoxPort::PC, 6);
|
||||||
|
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||||
iox.setup_pin(
|
iox.setup_pin(
|
||||||
port,
|
port,
|
||||||
pin,
|
pin,
|
||||||
|
|
@ -260,9 +266,44 @@ pub fn setup_periph_reset_pin<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
||||||
None,
|
None,
|
||||||
Some(IoxDriveStrength::Drive2mA),
|
Some(IoxDriveStrength::Drive2mA),
|
||||||
);
|
);
|
||||||
|
#[cfg(feature = "oem-baosec-lite")]
|
||||||
|
let (port, pin) = (IoxPort::PA, 6);
|
||||||
|
#[cfg(feature = "oem-baosec-lite")]
|
||||||
|
iox.setup_pin(
|
||||||
|
port,
|
||||||
|
pin,
|
||||||
|
Some(IoxDir::Output),
|
||||||
|
Some(IoxFunction::Gpio),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
Some(IoxDriveStrength::Drive2mA),
|
||||||
|
);
|
||||||
(port, pin)
|
(port, pin)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ASSUME: setup_periph_reset_pin has already been invoked
|
||||||
|
pub fn assert_periph_reset(iox: &dyn IoGpio, assert: bool) {
|
||||||
|
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||||
|
{
|
||||||
|
let (port, pin) = (IoxPort::PC, 6);
|
||||||
|
if assert {
|
||||||
|
iox.set_gpio_pin_value(port, pin, IoxValue::Low);
|
||||||
|
} else {
|
||||||
|
iox.set_gpio_pin_value(port, pin, IoxValue::High);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(feature = "oem-baosec-lite")]
|
||||||
|
{
|
||||||
|
let (port, pin) = (IoxPort::PA, 6);
|
||||||
|
if assert {
|
||||||
|
iox.set_gpio_pin_value(port, pin, IoxValue::High);
|
||||||
|
} else {
|
||||||
|
iox.set_gpio_pin_value(port, pin, IoxValue::Low);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// returns the USB SE0 port and pin number
|
/// returns the USB SE0 port and pin number
|
||||||
pub fn setup_usb_pins<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
pub fn setup_usb_pins<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
||||||
const SE0_PIN: u8 = 5;
|
const SE0_PIN: u8 = 5;
|
||||||
|
|
@ -450,6 +491,7 @@ pub fn kpc_sr1_to_key(raw_event: u32) -> KeyPress {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||||
pub fn setup_pmic_irq<T: IoIrq>(iox: &T, server: &str, opcode: usize) {
|
pub fn setup_pmic_irq<T: IoIrq>(iox: &T, server: &str, opcode: usize) {
|
||||||
iox.set_irq_pin(IoxPort::PB, 15, IoxValue::Low, server, opcode);
|
iox.set_irq_pin(IoxPort::PB, 15, IoxValue::Low, server, opcode);
|
||||||
}
|
}
|
||||||
|
|
@ -500,6 +542,12 @@ pub fn setup_trng_input_pin<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
||||||
(port, pin)
|
(port, pin)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "oem-baosec-lite")]
|
||||||
|
pub fn get_power_off_pin() -> (IoxPort, u8) {
|
||||||
|
let (port, pin) = (IoxPort::PF, 0);
|
||||||
|
(port, pin)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn setup_dcdc2_pin<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
pub fn setup_dcdc2_pin<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
||||||
let (port, pin) = (IoxPort::PF, 0);
|
let (port, pin) = (IoxPort::PF, 0);
|
||||||
iox.setup_pin(
|
iox.setup_pin(
|
||||||
|
|
|
||||||
|
|
@ -180,10 +180,6 @@ pub struct Oled128x128<'a> {
|
||||||
powerdown: bool,
|
powerdown: bool,
|
||||||
power_port: IoxPort,
|
power_port: IoxPort,
|
||||||
power_pin: u8,
|
power_pin: u8,
|
||||||
/// Note: this pin is also tied to the reset on the camera. We're assuming that there is no
|
|
||||||
/// possible state where we'd want the camera running without the display also on.
|
|
||||||
reset_port: IoxPort,
|
|
||||||
reset_pin: u8,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Oled128x128<'a> {
|
impl<'a> Oled128x128<'a> {
|
||||||
|
|
@ -246,7 +242,7 @@ impl<'a> Oled128x128<'a> {
|
||||||
};
|
};
|
||||||
spim.set_endianness(crate::udma::SpimEndian::MsbFirst);
|
spim.set_endianness(crate::udma::SpimEndian::MsbFirst);
|
||||||
let (power_port, power_pin) = crate::board::setup_oled_power_pin(iox);
|
let (power_port, power_pin) = crate::board::setup_oled_power_pin(iox);
|
||||||
let (reset_port, reset_pin) = crate::board::setup_periph_reset_pin(iox);
|
crate::board::setup_periph_reset_pin(iox);
|
||||||
Self {
|
Self {
|
||||||
spim,
|
spim,
|
||||||
// safety: this is safe because these ranges are in fact allocated, and all values can be
|
// safety: this is safe because these ranges are in fact allocated, and all values can be
|
||||||
|
|
@ -267,8 +263,6 @@ impl<'a> Oled128x128<'a> {
|
||||||
iox,
|
iox,
|
||||||
power_port,
|
power_port,
|
||||||
power_pin,
|
power_pin,
|
||||||
reset_port,
|
|
||||||
reset_pin,
|
|
||||||
powerdown: false,
|
powerdown: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -379,7 +373,7 @@ impl<'a> Oled128x128<'a> {
|
||||||
let ifram_vaddr = spim.ifram.virt_range.as_mut_ptr();
|
let ifram_vaddr = spim.ifram.virt_range.as_mut_ptr();
|
||||||
let (_channel, cd_port, cd_pin, _cs_pin) = crate::board::get_display_pins();
|
let (_channel, cd_port, cd_pin, _cs_pin) = crate::board::get_display_pins();
|
||||||
let (power_port, power_pin) = crate::board::setup_oled_power_pin(iox);
|
let (power_port, power_pin) = crate::board::setup_oled_power_pin(iox);
|
||||||
let (reset_port, reset_pin) = crate::board::setup_periph_reset_pin(iox);
|
crate::board::setup_periph_reset_pin(iox);
|
||||||
Self {
|
Self {
|
||||||
spim,
|
spim,
|
||||||
// safety: this is safe because these ranges are in fact allocated, and all values can be
|
// safety: this is safe because these ranges are in fact allocated, and all values can be
|
||||||
|
|
@ -401,8 +395,6 @@ impl<'a> Oled128x128<'a> {
|
||||||
powerdown,
|
powerdown,
|
||||||
power_pin,
|
power_pin,
|
||||||
power_port,
|
power_port,
|
||||||
reset_port,
|
|
||||||
reset_pin,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -496,7 +488,7 @@ impl<'a> Oled128x128<'a> {
|
||||||
pub fn powerdown(&mut self) {
|
pub fn powerdown(&mut self) {
|
||||||
self.powerdown = true;
|
self.powerdown = true;
|
||||||
// assert reset
|
// assert reset
|
||||||
self.iox.set_gpio_pin_value(self.reset_port, self.reset_pin, IoxValue::Low);
|
crate::board::assert_periph_reset(self.iox, true);
|
||||||
self.iox.set_gpio_pin_value(self.cd_port, self.cd_pin, IoxValue::Low);
|
self.iox.set_gpio_pin_value(self.cd_port, self.cd_pin, IoxValue::Low);
|
||||||
// cut power
|
// cut power
|
||||||
self.iox.set_gpio_pin_value(self.power_port, self.power_pin, IoxValue::Low);
|
self.iox.set_gpio_pin_value(self.power_port, self.power_pin, IoxValue::Low);
|
||||||
|
|
@ -509,7 +501,7 @@ impl<'a> Oled128x128<'a> {
|
||||||
// restore power
|
// restore power
|
||||||
self.iox.set_gpio_pin_value(self.power_port, self.power_pin, IoxValue::High);
|
self.iox.set_gpio_pin_value(self.power_port, self.power_pin, IoxValue::High);
|
||||||
// de-assert reset
|
// de-assert reset
|
||||||
self.iox.set_gpio_pin_value(self.reset_port, self.reset_pin, IoxValue::High);
|
crate::board::assert_periph_reset(self.iox, false);
|
||||||
self.powerdown = false;
|
self.powerdown = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,10 +87,11 @@ pub enum SpimWaitType {
|
||||||
pub enum CommandSet {
|
pub enum CommandSet {
|
||||||
Macronix = 0xc2,
|
Macronix = 0xc2,
|
||||||
Xtx = 0x0b,
|
Xtx = 0x0b,
|
||||||
|
Zetta = 0xba,
|
||||||
}
|
}
|
||||||
// be sure to update this when updating the command set above! this is used to iterate
|
// be sure to update this when updating the command set above! this is used to iterate
|
||||||
// through all valid types by other routines.
|
// through all valid types by other routines.
|
||||||
pub const ALL_COMMAND_SETS: [CommandSet; 2] = [CommandSet::Macronix, CommandSet::Xtx];
|
pub const ALL_COMMAND_SETS: [CommandSet; 3] = [CommandSet::Macronix, CommandSet::Xtx, CommandSet::Zetta];
|
||||||
impl TryFrom<u8> for CommandSet {
|
impl TryFrom<u8> for CommandSet {
|
||||||
type Error = xous::Error;
|
type Error = xous::Error;
|
||||||
|
|
||||||
|
|
@ -98,6 +99,7 @@ impl TryFrom<u8> for CommandSet {
|
||||||
match value {
|
match value {
|
||||||
0xc2 => Ok(CommandSet::Macronix),
|
0xc2 => Ok(CommandSet::Macronix),
|
||||||
0x0b => Ok(CommandSet::Xtx),
|
0x0b => Ok(CommandSet::Xtx),
|
||||||
|
0xba => Ok(CommandSet::Zetta),
|
||||||
_ => Err(xous::Error::BadAddress),
|
_ => Err(xous::Error::BadAddress),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -207,7 +209,7 @@ pub struct Spim {
|
||||||
// length of a pending txrx, if any
|
// length of a pending txrx, if any
|
||||||
pending_txrx: Option<usize>,
|
pending_txrx: Option<usize>,
|
||||||
// type of command set to use - inferred from ID read
|
// type of command set to use - inferred from ID read
|
||||||
command_set: Option<CommandSet>,
|
pub command_set: Option<CommandSet>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// length of the command buffer
|
// length of the command buffer
|
||||||
|
|
@ -1042,7 +1044,7 @@ impl Spim {
|
||||||
SpimMode::Standard => self.mem_send_cmd(0x9F),
|
SpimMode::Standard => self.mem_send_cmd(0x9F),
|
||||||
SpimMode::Quad => match self.command_set {
|
SpimMode::Quad => match self.command_set {
|
||||||
Some(CommandSet::Macronix) | None => self.mem_send_cmd(0xAF),
|
Some(CommandSet::Macronix) | None => self.mem_send_cmd(0xAF),
|
||||||
Some(CommandSet::Xtx) => self.mem_send_cmd(0x9F),
|
Some(CommandSet::Xtx) | Some(CommandSet::Zetta) => self.mem_send_cmd(0x9F),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1106,7 +1108,7 @@ impl Spim {
|
||||||
if activate {
|
if activate {
|
||||||
match self.command_set {
|
match self.command_set {
|
||||||
Some(CommandSet::Macronix) | None => self.mem_send_cmd(0x35),
|
Some(CommandSet::Macronix) | None => self.mem_send_cmd(0x35),
|
||||||
Some(CommandSet::Xtx) => {
|
Some(CommandSet::Xtx) | Some(CommandSet::Zetta) => {
|
||||||
crate::println!("activating Xtx QPI");
|
crate::println!("activating Xtx QPI");
|
||||||
self.mem_send_cmd(0x38)
|
self.mem_send_cmd(0x38)
|
||||||
}
|
}
|
||||||
|
|
@ -1115,7 +1117,7 @@ impl Spim {
|
||||||
self.mode = SpimMode::Quad; // pre-assumes quad mode
|
self.mode = SpimMode::Quad; // pre-assumes quad mode
|
||||||
match self.command_set {
|
match self.command_set {
|
||||||
Some(CommandSet::Macronix) | None => self.mem_send_cmd(0xF5),
|
Some(CommandSet::Macronix) | None => self.mem_send_cmd(0xF5),
|
||||||
Some(CommandSet::Xtx) => self.mem_send_cmd(0xFF),
|
Some(CommandSet::Xtx) | Some(CommandSet::Zetta) => self.mem_send_cmd(0xFF),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.mem_cs(false);
|
self.mem_cs(false);
|
||||||
|
|
@ -1128,7 +1130,7 @@ impl Spim {
|
||||||
// cleanup any parameter settings
|
// cleanup any parameter settings
|
||||||
match self.command_set {
|
match self.command_set {
|
||||||
Some(CommandSet::Macronix) | None => (),
|
Some(CommandSet::Macronix) | None => (),
|
||||||
Some(CommandSet::Xtx) => {
|
Some(CommandSet::Xtx) | Some(CommandSet::Zetta) => {
|
||||||
crate::println!("Xtx setting 6 dummy cycles");
|
crate::println!("Xtx setting 6 dummy cycles");
|
||||||
// set 6 dummy cycles; 8 is default
|
// set 6 dummy cycles; 8 is default
|
||||||
self.mem_param_set(false, 0xc0, &[0b0010_0000]);
|
self.mem_param_set(false, 0xc0, &[0b0010_0000]);
|
||||||
|
|
@ -1358,7 +1360,7 @@ impl Spim {
|
||||||
}
|
}
|
||||||
self.mem_read_id_flash();
|
self.mem_read_id_flash();
|
||||||
let addresses: &[u8] = match self.command_set {
|
let addresses: &[u8] = match self.command_set {
|
||||||
Some(CommandSet::Xtx) => &[0x05, 0x35, 0x15],
|
Some(CommandSet::Xtx) | Some(CommandSet::Zetta) => &[0x05, 0x35, 0x15],
|
||||||
Some(CommandSet::Macronix) | None => &[0x05],
|
Some(CommandSet::Macronix) | None => &[0x05],
|
||||||
};
|
};
|
||||||
let mut ret = 0u32;
|
let mut ret = 0u32;
|
||||||
|
|
@ -1396,7 +1398,7 @@ impl Spim {
|
||||||
let sr = self.flash_read_status_register();
|
let sr = self.flash_read_status_register();
|
||||||
let qe_set = match self.command_set {
|
let qe_set = match self.command_set {
|
||||||
Some(CommandSet::Macronix) => 0b0100_0000 & sr != 0,
|
Some(CommandSet::Macronix) => 0b0100_0000 & sr != 0,
|
||||||
Some(CommandSet::Xtx) => 0b10_0000_0000 & sr != 0,
|
Some(CommandSet::Xtx) | Some(CommandSet::Zetta) => 0b10_0000_0000 & sr != 0,
|
||||||
None => {
|
None => {
|
||||||
crate::println!("Can't set QE on unknown flash type");
|
crate::println!("Can't set QE on unknown flash type");
|
||||||
return;
|
return;
|
||||||
|
|
@ -1411,7 +1413,7 @@ impl Spim {
|
||||||
CommandSet::Macronix => {
|
CommandSet::Macronix => {
|
||||||
self.mem_write_status_register(0b0100_0000 | (sr & 0xFF) as u8, ((sr & 0xFF00) >> 8) as u8);
|
self.mem_write_status_register(0b0100_0000 | (sr & 0xFF) as u8, ((sr & 0xFF00) >> 8) as u8);
|
||||||
}
|
}
|
||||||
CommandSet::Xtx => {
|
CommandSet::Xtx | CommandSet::Zetta => {
|
||||||
self.mem_param_set(true, 0x31, &[((sr & 0xFF00 >> 8) as u8) | 0b0000_0010]);
|
self.mem_param_set(true, 0x31, &[((sr & 0xFF00 >> 8) as u8) | 0b0000_0010]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
141
libs/bio-lib/src/qspi_to_8080.rs
Normal file
141
libs/bio-lib/src/qspi_to_8080.rs
Normal file
|
|
@ -0,0 +1,141 @@
|
||||||
|
/// Notional sketch code that can take a QSPI data stream and turn it into 8080 panel data
|
||||||
|
///
|
||||||
|
/// The goal is to run a 320x320 panel at 16bpp and 60fps
|
||||||
|
///
|
||||||
|
/// The architecture is as follows:
|
||||||
|
///
|
||||||
|
/// - BIO core0 is the core Rx loop from SPI. There is some placeholder code for the 1-bit SPI stuff
|
||||||
|
/// that happens before QSPI mode, and it's assumed we don't have to understand it or do anything
|
||||||
|
/// with it. Once we hit QSPI mode, the loop waits for a value to come in on FIFO1 (x17) and every
|
||||||
|
/// time a value arrives there it shifts the incoming 4-bit data into an 8-bit packet, which it shoves
|
||||||
|
/// into FIFO0 (x16). It also checks if x17 is non-zero; if it is not 0, it exits the loop so you can
|
||||||
|
/// go back to the 1-bit SPI mode at the start of next frame
|
||||||
|
/// - BIO core1 generates the synchronization for cores 0 and 3 from the clock stream. It's configured
|
||||||
|
/// to trigger off of the rising clock edge on the incoming SPI bus. Every clock edge, it puts a zero
|
||||||
|
/// into x17 (FIFO1), and every two edges, it puts a zero into x18 (FIFO2). These zero-values synchronize
|
||||||
|
/// the Tx and Rx sides.
|
||||||
|
/// - BIO core2 interprets the CS line. It fully asynchronously just watches the CS line. It waits for
|
||||||
|
/// the line to go high, then low, and then once it goes high again, it sticks a *non-zero* value into
|
||||||
|
/// x17/x18. This takes advantage of the fact that you can multiple writes to every FIFO. So during
|
||||||
|
/// data transmission, the clock pules causes 0's to be shoved into x17/x18, and on the rising edge
|
||||||
|
/// of CS, a non-zero value is put into x17/x18, allowing for loop termination.
|
||||||
|
/// - BIO core3 transmits the 8080 data. There is a placeholder where data is expected to arrive
|
||||||
|
/// on x18 (FIFO2 - maybe we could use a different fifo for this?) from the *host*. This initial
|
||||||
|
/// data is currently ignored but notionally this could be commands destined for the panel to set
|
||||||
|
/// up its registers. Once this phase is done, it enters a loop where first it automatically sends
|
||||||
|
/// the "write burst" command, and then goes into data mode. In data mode it grabs data from FIFO0 (x16)
|
||||||
|
/// and blasts it to the 8080, toggling the write pulse every time, and then checking for the termination
|
||||||
|
/// condition on x18. Once it terminates, it goes back to the top of the loop where depending on the
|
||||||
|
/// host considerations we could code it to automatically arm for another frame, or we could wait
|
||||||
|
/// until the host initiates another transfer.
|
||||||
|
///
|
||||||
|
/// This is estimated to meet timing (but just barely) at 700MHz BIO speeds. If we're missing timing by a hair,
|
||||||
|
/// we could set the clock to 800MHz on the BIO core, as the core should overclock pretty well.
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
|
bio_code!(qspi_rx, QSPI_RX_START, QSPI_RX_END,
|
||||||
|
// core is configured to clock off of rising edge on SPI clk
|
||||||
|
"li x1, 0xF", // this loads the GPIO mask
|
||||||
|
"1:",
|
||||||
|
"stuff", // do stuff that handles the single-bit SPI stuff. Assuming we can ignore the contents
|
||||||
|
"10:",
|
||||||
|
"mv x8, x17", // x17 is a cleaned-up version of CS coming from a BIO that does that exclusively
|
||||||
|
"bne x8, x0, 20f", // exit the loop if CS != 0
|
||||||
|
"mv x2, x21", // read the GPIO
|
||||||
|
"and x3, x2, x1", // mask out unused bits and put in x3
|
||||||
|
"slli x3, x3, 4", // shift into place
|
||||||
|
|
||||||
|
"mv x8, x17", // x17 is a cleaned-up version of CS coming from a BIO that does that exclusively
|
||||||
|
"bne x8, x0, 20f", // exit the loop if CS != 0
|
||||||
|
"mv x2, x21", // read the GPIO
|
||||||
|
"and x4, x2, x1", // mask out unused bits
|
||||||
|
"or x3, x3, x4", // combine bits
|
||||||
|
"mv x16, x3", // send byte to FIFO
|
||||||
|
"j 10b" // loop
|
||||||
|
// 9 arith + 1 loop = 9 * 4 + 1 * 5 = 34 MHz rate (17 MHz per two edges)
|
||||||
|
// max time between edges = 5 arith + 1 loop = 5 * 4 + 1 * 5 = 28 MHz max edge rate
|
||||||
|
"20:",
|
||||||
|
"cleanup" // cleanup code
|
||||||
|
);
|
||||||
|
|
||||||
|
/// This core generates the reads off of clock edge
|
||||||
|
#[rustfmt::skip]
|
||||||
|
bio_code!(qspi_clocker, QSPI_CLK_START, QSPI_CLK_END,
|
||||||
|
// core is configured to clock off of rising edge on SPI clk
|
||||||
|
"10:",
|
||||||
|
"mv x20, x0", // wait for clock edge
|
||||||
|
"mv x17, x0", // send a 0 into the spi CS fifo to initiate read
|
||||||
|
"mv x20, x0", // wait for clock edge
|
||||||
|
"mv x17, x0", // send a 0 into the spi CS fifo to initiate read
|
||||||
|
"mv x18, x0", // send a 0 into 8080 CS fifo to continue writes
|
||||||
|
"j 10b"
|
||||||
|
);
|
||||||
|
|
||||||
|
/// This core generates the chip select termination pulse
|
||||||
|
#[rustfmt::skip]
|
||||||
|
bio_code!(qspi_cs, QSPI_CS_START, QSPI_CS_END,
|
||||||
|
"li x1, 0x10", // notional chip select on bit 4
|
||||||
|
"10:",
|
||||||
|
"mv x2, x21", // read GPIO
|
||||||
|
"and x3, x2, x1", // mask out the CS line
|
||||||
|
"bne x3, x0, 20f", // wait for high
|
||||||
|
"j 10b",
|
||||||
|
"20:", // initial high found
|
||||||
|
"mv x2, x21", // read GPIO
|
||||||
|
"and x3, x2, x1", // mask out the CS line
|
||||||
|
"beq x3, x0, 30f", // wait for low
|
||||||
|
"j 20b",
|
||||||
|
"30:", // now the CS is low, wait for it to go high
|
||||||
|
"mv x2, x21", // read GPIO
|
||||||
|
"and x3, x2, x1", // mask out the CS line
|
||||||
|
"bne x3, x0, 30f", // wait for high
|
||||||
|
"mv x17, x1", // put a non-zero value into x17, which terminates the receive loop
|
||||||
|
"mv x18, x1", // put a non-zero value into x18, which terminates the transmit loop
|
||||||
|
"j 20b" // return to searching for CS low
|
||||||
|
);
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
|
bio_code!(i8080_tx, I8080_TX_START, I8080_RX_END,
|
||||||
|
// core runs full speed whenever data comes into the FIFO
|
||||||
|
"li x1, 8", // data shift into place for GPIO
|
||||||
|
"li x2, 0x0FF0", // data pins mask, just made up for now
|
||||||
|
"li x3, 0x1000", // CSX set
|
||||||
|
"li x4, 0xFFFFEFFF", // CSX clear
|
||||||
|
"li x5, 0x2000", // DCX set
|
||||||
|
"li x6, 0xFFFFDFFF", // DCX clear
|
||||||
|
"li x7, 0x4000", // RD set
|
||||||
|
"li x8, 0x8000", // WR set
|
||||||
|
"li x9, 0xFFFF7FFF", // WR clear
|
||||||
|
"li x10 0xFFF0", // all GPIO pins mask
|
||||||
|
|
||||||
|
"mv x0, x18", // block on FIFO2 data - host sends this to setup 8080 tx loop
|
||||||
|
// later on x18 will have data automatically put in it by the CS interpreter
|
||||||
|
|
||||||
|
// setup control signals
|
||||||
|
"mv x22, x3," // set CSX
|
||||||
|
"mv x23, x6," // clear DCX
|
||||||
|
"mv x22, x7," // set RD
|
||||||
|
"mv x23, x9," // clear WR
|
||||||
|
"10:",
|
||||||
|
"mv x23, x4," // clear CSX
|
||||||
|
"li x12, 0x2C", // 8080 page write command
|
||||||
|
"slli x12, x12, x1", // shift into place
|
||||||
|
"mv x21, x12", // set 8080 page write bits
|
||||||
|
"mv x22, x8", // ** WR rising edge **
|
||||||
|
"mv x0, x0, x0", // NOP for wr high time requirement
|
||||||
|
"mv x23, x9,", // WR edge drop
|
||||||
|
"mv x22, x5", // set DCX
|
||||||
|
"20:", // main transmit loop
|
||||||
|
"mv x15, x16", // blocks until a byte arrives in the FIFO
|
||||||
|
"sll x15, x15, x1", // shift data into place
|
||||||
|
"mv x26, x2", // set GPIO pin set mask
|
||||||
|
"mv x21, x15", // change just the data pins
|
||||||
|
"mv x26, x10", // allow control pins to change
|
||||||
|
"mv x22, x8", // ** WR rising edge **
|
||||||
|
"mv x13, x18", // check termination condition while allowing WR hold time
|
||||||
|
"mv x23, x9,", // WR edge drop
|
||||||
|
"beq x13, x0, 20b", // go back if the termination condition is 0
|
||||||
|
// 9 inst + 1 br = 9 * 4 + 1 *5 = 41 cycles = 58ns total time, 17MHz tx rate
|
||||||
|
|
||||||
|
"loop cleanup", // do other 8080 commands to cleanup the panel and setup for next initiation
|
||||||
|
);
|
||||||
|
|
@ -108,6 +108,7 @@ board-baosec = [
|
||||||
"aes/loader-baosec",
|
"aes/loader-baosec",
|
||||||
"bao1x-hal/security",
|
"bao1x-hal/security",
|
||||||
]
|
]
|
||||||
|
oem-baosec-lite = []
|
||||||
board-baosor = ["bao1x-hal/loader-baosor"]
|
board-baosor = ["bao1x-hal/loader-baosor"]
|
||||||
board-dabao = [
|
board-dabao = [
|
||||||
"bao1x-hal/loader-dabao",
|
"bao1x-hal/loader-dabao",
|
||||||
|
|
|
||||||
|
|
@ -107,12 +107,17 @@ pub fn early_init_hw() -> u32 {
|
||||||
let one_way = bao1x_hal::acram::OneWayCounter::new();
|
let one_way = bao1x_hal::acram::OneWayCounter::new();
|
||||||
let board_type =
|
let board_type =
|
||||||
one_way.get_decoded::<bao1x_api::BoardTypeCoding>().expect("Board type coding error");
|
one_way.get_decoded::<bao1x_api::BoardTypeCoding>().expect("Board type coding error");
|
||||||
if board_type != bao1x_api::BoardTypeCoding::Baosec {
|
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||||
|
let expected_board = bao1x_api::BoardTypeCoding::Baosec;
|
||||||
|
#[cfg(feature = "oem-baosec-lite")]
|
||||||
|
let expected_board = bao1x_api::BoardTypeCoding::Oem;
|
||||||
|
|
||||||
|
if board_type != expected_board {
|
||||||
use bao1x_hal::board::{BOOKEND_END, BOOKEND_START};
|
use bao1x_hal::board::{BOOKEND_END, BOOKEND_START};
|
||||||
|
|
||||||
crate::println!("Board type is not Baosec; resetting it and rebooting!");
|
crate::println!("Board type is not Baosec; resetting it and rebooting!");
|
||||||
while one_way.get_decoded::<bao1x_api::BoardTypeCoding>().expect("owc coding error")
|
while one_way.get_decoded::<bao1x_api::BoardTypeCoding>().expect("owc coding error")
|
||||||
!= bao1x_api::BoardTypeCoding::Baosec
|
!= expected_board
|
||||||
{
|
{
|
||||||
one_way.inc_coded::<bao1x_api::BoardTypeCoding>().expect("increment error");
|
one_way.inc_coded::<bao1x_api::BoardTypeCoding>().expect("increment error");
|
||||||
}
|
}
|
||||||
|
|
@ -136,8 +141,10 @@ pub fn early_init_hw() -> u32 {
|
||||||
bao1x_hal::board::setup_camera_pins(&iox);
|
bao1x_hal::board::setup_camera_pins(&iox);
|
||||||
bao1x_hal::board::setup_kb_pins(&iox);
|
bao1x_hal::board::setup_kb_pins(&iox);
|
||||||
bao1x_hal::board::setup_oled_power_pin(&iox);
|
bao1x_hal::board::setup_oled_power_pin(&iox);
|
||||||
|
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||||
let trng_power = bao1x_hal::board::setup_trng_power_pin(&iox);
|
let trng_power = bao1x_hal::board::setup_trng_power_pin(&iox);
|
||||||
// kernel expects the TRNG to be on
|
// kernel expects the TRNG to be on
|
||||||
|
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||||
iox.set_gpio_pin(trng_power.0, trng_power.1, bao1x_api::IoxValue::High);
|
iox.set_gpio_pin(trng_power.0, trng_power.1, bao1x_api::IoxValue::High);
|
||||||
|
|
||||||
// select the 32khz external xosc for baosec targets
|
// select the 32khz external xosc for baosec targets
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ board-baosec = [
|
||||||
"blitstr2/board-baosec",
|
"blitstr2/board-baosec",
|
||||||
"no-gam",
|
"no-gam",
|
||||||
]
|
]
|
||||||
|
oem-baosec-lite = ["bao1x-hal/oem-baosec-lite"]
|
||||||
hosted-baosec = ["bao1x-emu", "ux-api/hosted-baosec", "no-gam"]
|
hosted-baosec = ["bao1x-emu", "ux-api/hosted-baosec", "no-gam"]
|
||||||
|
|
||||||
# temporary feature - remove after we have properly created a camera control API
|
# temporary feature - remove after we have properly created a camera control API
|
||||||
|
|
|
||||||
|
|
@ -219,6 +219,11 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
|
|
||||||
udma_global.udma_clock_config(PeriphId::Cam, true);
|
udma_global.udma_clock_config(PeriphId::Cam, true);
|
||||||
// ---- camera initialization
|
// ---- camera initialization
|
||||||
|
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||||
|
let cam_clk = (IoxPort::PA, 0);
|
||||||
|
#[cfg(feature = "oem-baosec-lite")]
|
||||||
|
let cam_clk = (IoxPort::PA, 3);
|
||||||
|
|
||||||
#[cfg(not(feature = "hosted-baosec"))]
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
let (mut cam, cam_pdwn) = {
|
let (mut cam, cam_pdwn) = {
|
||||||
// wait for other inits to finish so we can do this roughly atomically
|
// wait for other inits to finish so we can do this roughly atomically
|
||||||
|
|
@ -242,8 +247,8 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
|
|
||||||
// setup camera clock
|
// setup camera clock
|
||||||
iox.setup_pin(
|
iox.setup_pin(
|
||||||
IoxPort::PA,
|
cam_clk.0,
|
||||||
0,
|
cam_clk.1,
|
||||||
Some(IoxDir::Output),
|
Some(IoxDir::Output),
|
||||||
Some(IoxFunction::AF3),
|
Some(IoxFunction::AF3),
|
||||||
None,
|
None,
|
||||||
|
|
@ -251,12 +256,24 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
Some(IoxEnable::Disable),
|
Some(IoxEnable::Disable),
|
||||||
Some(IoxDriveStrength::Drive8mA),
|
Some(IoxDriveStrength::Drive8mA),
|
||||||
);
|
);
|
||||||
timer.wo(utra::pwm::REG_CH_EN, 1);
|
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||||
timer.rmwf(utra::pwm::REG_TIM0_CFG_R_TIMER0_SAW, 1);
|
{
|
||||||
timer.rmwf(utra::pwm::REG_TIM0_CH0_TH_R_TIMER0_CH0_TH, 0);
|
timer.wo(utra::pwm::REG_CH_EN, 1);
|
||||||
timer.rmwf(utra::pwm::REG_TIM0_CH0_TH_R_TIMER0_CH0_MODE, 3);
|
timer.rmwf(utra::pwm::REG_TIM0_CFG_R_TIMER0_SAW, 1);
|
||||||
unsafe { timer.base().add(2).write_volatile(0) }; // for some reason the register extraction didn't get this register...
|
timer.rmwf(utra::pwm::REG_TIM0_CH0_TH_R_TIMER0_CH0_TH, 0);
|
||||||
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 0);
|
timer.rmwf(utra::pwm::REG_TIM0_CH0_TH_R_TIMER0_CH0_MODE, 3);
|
||||||
|
unsafe { timer.base().add(2).write_volatile(0) }; // for some reason the register extraction didn't get this register...
|
||||||
|
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 0);
|
||||||
|
}
|
||||||
|
#[cfg(feature = "oem-baosec-lite")]
|
||||||
|
{
|
||||||
|
timer.wo(utra::pwm::REG_CH_EN, 1);
|
||||||
|
timer.rmwf(utra::pwm::REG_TIM0_CFG_R_TIMER0_SAW, 1);
|
||||||
|
timer.rmwf(utra::pwm::REG_TIM0_CH3_TH_R_TIMER0_CH3_TH, 0);
|
||||||
|
timer.rmwf(utra::pwm::REG_TIM0_CH3_TH_R_TIMER0_CH3_MODE, 3);
|
||||||
|
unsafe { timer.base().add(2).write_volatile(0) }; // for some reason the register extraction didn't get this register...
|
||||||
|
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 0);
|
||||||
|
}
|
||||||
/* // register debug
|
/* // register debug
|
||||||
for i in 0..12 {
|
for i in 0..12 {
|
||||||
println!("0x{:2x}: 0x{:08x}", i, unsafe { pwm.add(i).read_volatile() })
|
println!("0x{:2x}: 0x{:08x}", i, unsafe { pwm.add(i).read_volatile() })
|
||||||
|
|
@ -297,7 +314,16 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
tt.sleep_ms(2).ok();
|
tt.sleep_ms(2).ok();
|
||||||
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 0);
|
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 0);
|
||||||
timer.wo(utra::pwm::REG_CH_EN, 0);
|
timer.wo(utra::pwm::REG_CH_EN, 0);
|
||||||
iox.setup_pin(IoxPort::PA, 0, Some(IoxDir::Input), Some(IoxFunction::Gpio), None, None, None, None);
|
iox.setup_pin(
|
||||||
|
cam_clk.0,
|
||||||
|
cam_clk.1,
|
||||||
|
Some(IoxDir::Input),
|
||||||
|
Some(IoxFunction::Gpio),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
|
||||||
(cam, cam_pdwn)
|
(cam, cam_pdwn)
|
||||||
};
|
};
|
||||||
|
|
@ -373,8 +399,8 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
// power up the camera
|
// power up the camera
|
||||||
// starts MCLK
|
// starts MCLK
|
||||||
iox.setup_pin(
|
iox.setup_pin(
|
||||||
IoxPort::PA,
|
cam_clk.0,
|
||||||
0,
|
cam_clk.1,
|
||||||
Some(IoxDir::Output),
|
Some(IoxDir::Output),
|
||||||
Some(IoxFunction::AF3),
|
Some(IoxFunction::AF3),
|
||||||
None,
|
None,
|
||||||
|
|
@ -480,8 +506,8 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 0);
|
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 0);
|
||||||
timer.wo(utra::pwm::REG_CH_EN, 0);
|
timer.wo(utra::pwm::REG_CH_EN, 0);
|
||||||
iox.setup_pin(
|
iox.setup_pin(
|
||||||
IoxPort::PA,
|
cam_clk.0,
|
||||||
0,
|
cam_clk.1,
|
||||||
Some(IoxDir::Input),
|
Some(IoxDir::Input),
|
||||||
Some(IoxFunction::Gpio),
|
Some(IoxFunction::Gpio),
|
||||||
None,
|
None,
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ swap = []
|
||||||
mpw = ["bao1x-hal/mpw"]
|
mpw = ["bao1x-hal/mpw"]
|
||||||
bmp180 = ["bao1x-hal/bmp180"]
|
bmp180 = ["bao1x-hal/bmp180"]
|
||||||
board-baosec = ["bao1x-hal/board-baosec"]
|
board-baosec = ["bao1x-hal/board-baosec"]
|
||||||
|
oem-baosec-lite = []
|
||||||
board-baosor = ["bao1x-hal/board-baosor"]
|
board-baosor = ["bao1x-hal/board-baosor"]
|
||||||
board-dabao = ["bao1x-hal/board-dabao"]
|
board-dabao = ["bao1x-hal/board-dabao"]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
pub mod keyboard;
|
pub mod keyboard;
|
||||||
|
|
||||||
// TRNG server is only needed for baosec; dabao can cheat and use the kernel TRNG port
|
// TRNG server is only needed for baosec; dabao can cheat and use the kernel TRNG port
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(all(feature = "board-baosec", not(feature = "oem-baosec-lite")))]
|
||||||
mod baosec_hw;
|
mod baosec_hw;
|
||||||
pub mod bio;
|
pub mod bio;
|
||||||
pub mod rtc;
|
pub mod rtc;
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(all(feature = "board-baosec", not(feature = "oem-baosec-lite")))]
|
||||||
use bao1x_api::bio::IoConfigMode;
|
use bao1x_api::bio::IoConfigMode;
|
||||||
#[cfg(feature = "board-dabao")]
|
#[cfg(any(feature = "board-dabao", feature = "oem-baosec-lite"))]
|
||||||
use bao1x_hal_service::trng::Trng;
|
use bao1x_hal_service::trng::Trng;
|
||||||
use bao1x_hal_service::trng::api;
|
use bao1x_hal_service::trng::api;
|
||||||
use flatipc::Ipc;
|
use flatipc::Ipc;
|
||||||
use num_traits::*;
|
use num_traits::*;
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(all(feature = "board-baosec", not(feature = "oem-baosec-lite")))]
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
use xous::CID;
|
use xous::CID;
|
||||||
use xous_ipc::Buffer;
|
use xous_ipc::Buffer;
|
||||||
|
|
@ -18,7 +18,7 @@ struct ScalarCallback {
|
||||||
cb_to_client_id: u32,
|
cb_to_client_id: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(all(feature = "board-baosec", not(feature = "oem-baosec-lite")))]
|
||||||
pub fn start_trng_service() {
|
pub fn start_trng_service() {
|
||||||
std::thread::spawn({
|
std::thread::spawn({
|
||||||
move || {
|
move || {
|
||||||
|
|
@ -26,7 +26,7 @@ pub fn start_trng_service() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(all(feature = "board-baosec", not(feature = "oem-baosec-lite")))]
|
||||||
fn trng_service() -> ! {
|
fn trng_service() -> ! {
|
||||||
let xns = xous_names::XousNames::new().unwrap();
|
let xns = xous_names::XousNames::new().unwrap();
|
||||||
// unlimited connections allowed, anyone including less-trusted processes can get a random number
|
// unlimited connections allowed, anyone including less-trusted processes can get a random number
|
||||||
|
|
@ -88,7 +88,7 @@ fn trng_service() -> ! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "board-dabao")]
|
#[cfg(any(feature = "board-dabao", feature = "oem-baosec-lite"))]
|
||||||
pub fn start_trng_service() {
|
pub fn start_trng_service() {
|
||||||
std::thread::spawn({
|
std::thread::spawn({
|
||||||
move || {
|
move || {
|
||||||
|
|
@ -96,7 +96,7 @@ pub fn start_trng_service() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
#[cfg(feature = "board-dabao")]
|
#[cfg(any(feature = "board-dabao", feature = "oem-baosec-lite"))]
|
||||||
fn trng_service() -> ! {
|
fn trng_service() -> ! {
|
||||||
let xns = xous_names::XousNames::new().unwrap();
|
let xns = xous_names::XousNames::new().unwrap();
|
||||||
// unlimited connections allowed, anyone including less-trusted processes can get a random number
|
// unlimited connections allowed, anyone including less-trusted processes can get a random number
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,10 @@ impl Trng {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// With no avalanche TRNG, this is just a pass-through to the RO as it has enough
|
||||||
|
/// bandwidth to provide random data at the speeds we need.
|
||||||
|
pub fn fill_seeded_bytes(&mut self, dest: &mut [u8]) { self.fill_bytes_via_next(dest); }
|
||||||
|
|
||||||
/// Sets the test mode according to the argument. Blocks until mode is set.
|
/// Sets the test mode according to the argument. Blocks until mode is set.
|
||||||
pub fn set_test_mode(&mut self, test_mode: api::TrngTestMode) { self.mode = test_mode; }
|
pub fn set_test_mode(&mut self, test_mode: api::TrngTestMode) { self.mode = test_mode; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(all(feature = "board-baosec", not(feature = "oem-baosec-lite")))]
|
||||||
pub mod baosec;
|
pub mod baosec;
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(all(feature = "board-baosec", not(feature = "oem-baosec-lite")))]
|
||||||
pub use baosec::*;
|
pub use baosec::*;
|
||||||
#[cfg(feature = "board-dabao")]
|
#[cfg(any(feature = "board-dabao", feature = "oem-baosec-lite"))]
|
||||||
pub mod dabao;
|
pub mod dabao;
|
||||||
#[cfg(feature = "board-dabao")]
|
#[cfg(any(feature = "board-dabao", feature = "oem-baosec-lite"))]
|
||||||
pub use dabao::*;
|
pub use dabao::*;
|
||||||
|
|
||||||
pub mod api {
|
pub mod api {
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ board-baosec = [
|
||||||
"bao1x-hal",
|
"bao1x-hal",
|
||||||
"bao1x-hal-service",
|
"bao1x-hal-service",
|
||||||
]
|
]
|
||||||
|
oem-baosec-lite = ["bao1x-hal/oem-baosec-lite"]
|
||||||
board-dabao = ["utralib/bao1x", "utralib/std", "bao1x-hal", "bao1x-hal-service"]
|
board-dabao = ["utralib/bao1x", "utralib/std", "bao1x-hal", "bao1x-hal-service"]
|
||||||
hosted-baosec = ["utralib/hosted", "utralib/std", "bao1x-emu"]
|
hosted-baosec = ["utralib/hosted", "utralib/std", "bao1x-emu"]
|
||||||
# none of these other modes are actually supported, but are listed here
|
# none of these other modes are actually supported, but are listed here
|
||||||
|
|
|
||||||
|
|
@ -87,14 +87,16 @@ impl<'a> Bao1xUsb<'a> {
|
||||||
// to concurrently add that in - you have to kick out one of the interfaces above to add mass
|
// to concurrently add that in - you have to kick out one of the interfaces above to add mass
|
||||||
// storage!)
|
// storage!)
|
||||||
|
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(feature = "oem-baosec-lite")]
|
||||||
|
let product = "Baosec-lite";
|
||||||
|
#[cfg(all(feature = "board-baosec", not(feature = "oem-baosec-lite")))]
|
||||||
let product = "Baosec";
|
let product = "Baosec";
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(feature = "board-baosec")]
|
||||||
let pid = 0x6198; // pending PR acceptance
|
let pid = 0x6198;
|
||||||
#[cfg(feature = "board-dabao")]
|
#[cfg(feature = "board-dabao")]
|
||||||
let product = "Dabao";
|
let product = "Dabao";
|
||||||
#[cfg(feature = "board-dabao")]
|
#[cfg(feature = "board-dabao")]
|
||||||
let pid = 0x6197; // pending PR acceptance
|
let pid = 0x6197;
|
||||||
let device = UsbDeviceBuilder::new(&usb_alloc, UsbVidPid(0x1d50, pid))
|
let device = UsbDeviceBuilder::new(&usb_alloc, UsbVidPid(0x1d50, pid))
|
||||||
.manufacturer("Baochip")
|
.manufacturer("Baochip")
|
||||||
.product(product)
|
.product(product)
|
||||||
|
|
@ -160,7 +162,7 @@ impl<'a> Bao1xUsb<'a> {
|
||||||
|
|
||||||
/// Process an unplug event - only valid on baosec, because dabao doesn't have a battery and unplugging
|
/// Process an unplug event - only valid on baosec, because dabao doesn't have a battery and unplugging
|
||||||
/// it would power it down.
|
/// it would power it down.
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(all(feature = "board-baosec", not(feature = "oem-baosec-lite")))]
|
||||||
pub fn unplug(&mut self) {
|
pub fn unplug(&mut self) {
|
||||||
// disable all interrupts so we can safely go through initialization routines
|
// disable all interrupts so we can safely go through initialization routines
|
||||||
self.irq_csr.wo(utra::irqarray1::EV_ENABLE, 0);
|
self.irq_csr.wo(utra::irqarray1::EV_ENABLE, 0);
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ pub(crate) fn main_hw() -> ! {
|
||||||
use api::*;
|
use api::*;
|
||||||
use bao1x_api::IoGpio;
|
use bao1x_api::IoGpio;
|
||||||
use bao1x_api::keyboard::KeyMap;
|
use bao1x_api::keyboard::KeyMap;
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(all(feature = "board-baosec", not(feature = "oem-baosec-lite")))]
|
||||||
use bao1x_hal::axp2101::VbusIrq;
|
use bao1x_hal::axp2101::VbusIrq;
|
||||||
use bao1x_hal::usb::driver::{CorigineUsb, CorigineWrapper};
|
use bao1x_hal::usb::driver::{CorigineUsb, CorigineWrapper};
|
||||||
use hw::{Bao1xUsb, UsbIrqReq};
|
use hw::{Bao1xUsb, UsbIrqReq};
|
||||||
|
|
@ -260,9 +260,9 @@ pub(crate) fn main_hw() -> ! {
|
||||||
});
|
});
|
||||||
|
|
||||||
let iox = bao1x_api::IoxHal::new();
|
let iox = bao1x_api::IoxHal::new();
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(all(feature = "board-baosec", not(feature = "oem-baosec-lite")))]
|
||||||
let mut i2c = bao1x_hal::i2c::I2c::new();
|
let mut i2c = bao1x_hal::i2c::I2c::new();
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(all(feature = "board-baosec", not(feature = "oem-baosec-lite")))]
|
||||||
let pmic = {
|
let pmic = {
|
||||||
log::info!("Registering PMIC handler to detect USB plug/unplug events");
|
log::info!("Registering PMIC handler to detect USB plug/unplug events");
|
||||||
bao1x_hal::board::setup_pmic_irq(
|
bao1x_hal::board::setup_pmic_irq(
|
||||||
|
|
@ -292,7 +292,7 @@ pub(crate) fn main_hw() -> ! {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
match opcode {
|
match opcode {
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(all(feature = "board-baosec", not(feature = "oem-baosec-lite")))]
|
||||||
Opcode::PmicIrq => match pmic.get_vbus_irq_status(&mut i2c).unwrap() {
|
Opcode::PmicIrq => match pmic.get_vbus_irq_status(&mut i2c).unwrap() {
|
||||||
VbusIrq::Insert => {
|
VbusIrq::Insert => {
|
||||||
log::error!("VBUS insert reported by PMIC, but we didn't ask for the event!");
|
log::error!("VBUS insert reported by PMIC, but we didn't ask for the event!");
|
||||||
|
|
|
||||||
|
|
@ -710,141 +710,43 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
.set_sigblock_size(sigblock_size);
|
.set_sigblock_size(sigblock_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
Some("baosec") => {
|
Some("bao1x-boot1-lite") => {
|
||||||
let board = "board-baosec";
|
|
||||||
let sigblock_size = 0x300;
|
let sigblock_size = 0x300;
|
||||||
update_flash_origin(
|
update_flash_origin(
|
||||||
"loader/src/platform/bao1x/link.x",
|
"bao1x-boot/boot1/src/platform/bao1x/link.x",
|
||||||
|
(bao1x_api::BOOT1_START + sigblock_size + STATICS_LEN) as u32,
|
||||||
|
)?;
|
||||||
|
// builder.add_loader_feature("unsafe-debug");
|
||||||
|
builder
|
||||||
|
.set_baremetal(true)
|
||||||
|
.target_baremetal_bao1x("bao1x-boot1")
|
||||||
|
.add_loader_feature("oem-baosec-lite")
|
||||||
|
.set_sigblock_size(sigblock_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
Some("bao1x-alt-boot1-lite") => {
|
||||||
|
let sigblock_size = 0x300;
|
||||||
|
update_flash_origin(
|
||||||
|
"bao1x-boot/boot1/src/platform/bao1x/link.x",
|
||||||
(bao1x_api::LOADER_START + sigblock_size + STATICS_LEN) as u32,
|
(bao1x_api::LOADER_START + sigblock_size + STATICS_LEN) as u32,
|
||||||
)?;
|
)?;
|
||||||
// select the board
|
builder.add_loader_feature("alt-boot1");
|
||||||
builder.set_board(board);
|
// builder.add_loader_feature("force-dabao");
|
||||||
builder.add_feature(board);
|
builder
|
||||||
builder.add_loader_feature(board);
|
.set_baremetal(true)
|
||||||
builder.add_kernel_feature(board);
|
.target_baremetal_bao1x("bao1x-alt-boot1")
|
||||||
builder.set_sigblock_size(sigblock_size);
|
.add_loader_feature("oem-baosec-lite")
|
||||||
|
.set_sigblock_size(sigblock_size);
|
||||||
|
}
|
||||||
|
|
||||||
// placement in flash is a tension between dev convenience and RAM usage. Things in flash
|
Some("baosec") => {
|
||||||
// are resident, non-swapable, but end up making the slow kernel burn process take longer.
|
baosec_common(&mut builder)?;
|
||||||
// Layout:
|
|
||||||
// - kernel, ticktimer, log, names, swapper are essential services and stay resident. Must be <1
|
|
||||||
// MiB total.
|
|
||||||
// - usb-bao1x is latency-sensitive and runs a handler in a non-swappable IRQ context, and thus
|
|
||||||
// cannot be swapped out. It contains the USB stack and API layer. It needs to maintain a
|
|
||||||
// mutex with bao-video as the camera cannot run simultaneously with the USB stack due to
|
|
||||||
// sharing of the IFRAM space.
|
|
||||||
// - bao1x-hal-service contains all the non-latency sensitive hardware APIs
|
|
||||||
// - bao-video pulls camera + display + qr decoding into a single package single memory space to
|
|
||||||
// optimize performance. Must maintain a mutex with usb-bao1x on the camera IFRAM space.
|
|
||||||
// - bao-console is the serial debug console handler
|
|
||||||
// - [planned] pddb server
|
|
||||||
// - [planned] vault application
|
|
||||||
let bao_rram_pkgs = [
|
|
||||||
"xous-ticktimer",
|
|
||||||
"xous-log",
|
|
||||||
"xous-names",
|
|
||||||
"usb-bao1x",
|
|
||||||
"bao1x-hal-service",
|
|
||||||
"modals",
|
|
||||||
"pddb",
|
|
||||||
"bao-video",
|
|
||||||
]
|
|
||||||
.to_vec();
|
|
||||||
let bao_swap_pkgs = ["bao-console", "vault2"].to_vec();
|
|
||||||
if !builder.is_swap_set() {
|
|
||||||
// reserve 3MiB for system services: ultimately, "pddb, modals, and bao-video"
|
|
||||||
builder.set_swap(0, bao1x_api::offsets::baosec::SWAP_RAM_LEN as _);
|
|
||||||
}
|
|
||||||
builder.add_loader_feature("swap");
|
|
||||||
builder.add_kernel_feature("print-panics");
|
|
||||||
builder.add_kernel_feature("swap");
|
|
||||||
builder.add_feature("swap");
|
|
||||||
|
|
||||||
builder.add_loader_feature("debug-print");
|
|
||||||
// the following feature needs to be uncommented if we also enable
|
|
||||||
// debug-print-swapper inside xous-swapper
|
|
||||||
if false {
|
|
||||||
builder.add_loader_feature("userspace-swap-debug");
|
|
||||||
builder.add_feature("debug-print-swapper");
|
|
||||||
// use this to enable debug in USB, when the package is selected
|
|
||||||
// builder.add_feature("debug-print-usb");
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
// builder.add_kernel_feature("debug-swap");
|
|
||||||
// builder.add_kernel_feature("debug-print");
|
|
||||||
// builder.add_kernel_feature("debug-swap-verbose");
|
|
||||||
// builder.add_feature("quantum-timer"); // this isn't in bao1x..
|
|
||||||
builder.add_kernel_feature("v2p");
|
|
||||||
builder.target_bao1x_soc();
|
|
||||||
|
|
||||||
// It is important that this is the first service added, because the swapper *must* be in PID 2
|
|
||||||
builder.add_service("xous-swapper", LoaderRegion::Flash);
|
|
||||||
// It is important that this is the second service added, as keystore *must* be in PID 3
|
|
||||||
// (as constrained by the coreuser setting that is locked out by the time Xous runs)
|
|
||||||
builder.add_service("keystore", LoaderRegion::Flash);
|
|
||||||
|
|
||||||
for service in bao_rram_pkgs {
|
|
||||||
builder.add_service(service, LoaderRegion::Flash);
|
|
||||||
}
|
|
||||||
builder.add_services(&get_cratespecs());
|
|
||||||
for service in bao_swap_pkgs {
|
|
||||||
builder.add_service(service, LoaderRegion::Swap);
|
|
||||||
}
|
|
||||||
for app in get_cratespecs() {
|
|
||||||
builder.add_service(&app, LoaderRegion::Swap);
|
|
||||||
}
|
|
||||||
// builder.add_feature("modal-testing");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Some("baosec-lite") => {
|
Some("baosec-lite") => {
|
||||||
let board = "board-baosec";
|
baosec_common(&mut builder)?;
|
||||||
let sigblock_size = 0x300;
|
builder.add_feature("oem-baosec-lite");
|
||||||
update_flash_origin(
|
builder.add_loader_feature("oem-baosec-lite");
|
||||||
"loader/src/platform/bao1x/link.x",
|
|
||||||
(bao1x_api::LOADER_START + sigblock_size + STATICS_LEN) as u32,
|
|
||||||
)?;
|
|
||||||
// select the board
|
|
||||||
builder.set_board(board);
|
|
||||||
builder.add_feature(board);
|
|
||||||
builder.add_loader_feature(board);
|
|
||||||
builder.add_kernel_feature(board);
|
|
||||||
builder.set_sigblock_size(sigblock_size);
|
|
||||||
|
|
||||||
// needs a filesystem, which has to be implemented in...128k :-O
|
|
||||||
let bao_rram_pkgs = [
|
|
||||||
"xous-ticktimer",
|
|
||||||
"keystore",
|
|
||||||
"xous-log",
|
|
||||||
"xous-names",
|
|
||||||
"usb-bao1x",
|
|
||||||
"bao1x-hal-service",
|
|
||||||
"modals",
|
|
||||||
"bao-video",
|
|
||||||
"vault2",
|
|
||||||
]
|
|
||||||
.to_vec();
|
|
||||||
let bao_swap_pkgs = [].to_vec();
|
|
||||||
if !builder.is_swap_set() {
|
|
||||||
// reserve 3MiB for system services: ultimately, "pddb, modals, and bao-video"
|
|
||||||
builder.set_swap(0, bao1x_api::offsets::baosec::SWAP_RAM_LEN as _);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.add_loader_feature("debug-print");
|
|
||||||
// the following feature needs to be uncommented if we also enable
|
|
||||||
builder.add_kernel_feature("v2p");
|
|
||||||
builder.target_bao1x_soc();
|
|
||||||
|
|
||||||
for service in bao_rram_pkgs {
|
|
||||||
builder.add_service(service, LoaderRegion::Flash);
|
|
||||||
}
|
|
||||||
builder.add_services(&get_cratespecs());
|
|
||||||
for service in bao_swap_pkgs {
|
|
||||||
builder.add_service(service, LoaderRegion::Swap);
|
|
||||||
}
|
|
||||||
for app in get_cratespecs() {
|
|
||||||
builder.add_service(&app, LoaderRegion::Swap);
|
|
||||||
}
|
|
||||||
// builder.add_feature("modal-testing");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Some("baosec-improper-keystore") => {
|
Some("baosec-improper-keystore") => {
|
||||||
|
|
@ -1234,3 +1136,90 @@ fn update_flash_origin<P: AsRef<Path>>(path: P, new_origin: u32) -> std::io::Res
|
||||||
fs::write(path, updated)?;
|
fs::write(path, updated)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn baosec_common(builder: &mut Builder) -> std::io::Result<()> {
|
||||||
|
let board = "board-baosec";
|
||||||
|
let sigblock_size = 0x300;
|
||||||
|
update_flash_origin(
|
||||||
|
"loader/src/platform/bao1x/link.x",
|
||||||
|
(bao1x_api::LOADER_START + sigblock_size + STATICS_LEN) as u32,
|
||||||
|
)?;
|
||||||
|
// select the board
|
||||||
|
builder.set_board(board);
|
||||||
|
builder.add_feature(board);
|
||||||
|
builder.add_loader_feature(board);
|
||||||
|
builder.add_kernel_feature(board);
|
||||||
|
builder.set_sigblock_size(sigblock_size);
|
||||||
|
|
||||||
|
// placement in flash is a tension between dev convenience and RAM usage. Things in flash
|
||||||
|
// are resident, non-swapable, but end up making the slow kernel burn process take longer.
|
||||||
|
// Layout:
|
||||||
|
// - kernel, ticktimer, log, names, swapper are essential services and stay resident. Must be <1 MiB
|
||||||
|
// total.
|
||||||
|
// - usb-bao1x is latency-sensitive and runs a handler in a non-swappable IRQ context, and thus cannot
|
||||||
|
// be swapped out. It contains the USB stack and API layer. It needs to maintain a mutex with
|
||||||
|
// bao-video as the camera cannot run simultaneously with the USB stack due to sharing of the IFRAM
|
||||||
|
// space.
|
||||||
|
// - bao1x-hal-service contains all the non-latency sensitive hardware APIs
|
||||||
|
// - bao-video pulls camera + display + qr decoding into a single package single memory space to
|
||||||
|
// optimize performance. Must maintain a mutex with usb-bao1x on the camera IFRAM space.
|
||||||
|
// - bao-console is the serial debug console handler
|
||||||
|
// - [planned] pddb server
|
||||||
|
// - [planned] vault application
|
||||||
|
let bao_rram_pkgs = [
|
||||||
|
"xous-ticktimer",
|
||||||
|
"xous-log",
|
||||||
|
"xous-names",
|
||||||
|
"usb-bao1x",
|
||||||
|
"bao1x-hal-service",
|
||||||
|
"modals",
|
||||||
|
"pddb",
|
||||||
|
"bao-video",
|
||||||
|
]
|
||||||
|
.to_vec();
|
||||||
|
let bao_swap_pkgs = ["bao-console", "vault2"].to_vec();
|
||||||
|
if !builder.is_swap_set() {
|
||||||
|
// reserve 3MiB for system services: ultimately, "pddb, modals, and bao-video"
|
||||||
|
builder.set_swap(0, bao1x_api::offsets::baosec::SWAP_RAM_LEN as _);
|
||||||
|
}
|
||||||
|
builder.add_loader_feature("swap");
|
||||||
|
builder.add_kernel_feature("print-panics");
|
||||||
|
builder.add_kernel_feature("swap");
|
||||||
|
builder.add_feature("swap");
|
||||||
|
|
||||||
|
builder.add_loader_feature("debug-print");
|
||||||
|
// the following feature needs to be uncommented if we also enable
|
||||||
|
// debug-print-swapper inside xous-swapper
|
||||||
|
if false {
|
||||||
|
builder.add_loader_feature("userspace-swap-debug");
|
||||||
|
builder.add_feature("debug-print-swapper");
|
||||||
|
// use this to enable debug in USB, when the package is selected
|
||||||
|
// builder.add_feature("debug-print-usb");
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
// builder.add_kernel_feature("debug-swap");
|
||||||
|
// builder.add_kernel_feature("debug-print");
|
||||||
|
// builder.add_kernel_feature("debug-swap-verbose");
|
||||||
|
// builder.add_feature("quantum-timer"); // this isn't in bao1x..
|
||||||
|
builder.add_kernel_feature("v2p");
|
||||||
|
builder.target_bao1x_soc();
|
||||||
|
|
||||||
|
// It is important that this is the first service added, because the swapper *must* be in PID 2
|
||||||
|
builder.add_service("xous-swapper", LoaderRegion::Flash);
|
||||||
|
// It is important that this is the second service added, as keystore *must* be in PID 3
|
||||||
|
// (as constrained by the coreuser setting that is locked out by the time Xous runs)
|
||||||
|
builder.add_service("keystore", LoaderRegion::Flash);
|
||||||
|
|
||||||
|
for service in bao_rram_pkgs {
|
||||||
|
builder.add_service(service, LoaderRegion::Flash);
|
||||||
|
}
|
||||||
|
builder.add_services(&get_cratespecs());
|
||||||
|
for service in bao_swap_pkgs {
|
||||||
|
builder.add_service(service, LoaderRegion::Swap);
|
||||||
|
}
|
||||||
|
for app in get_cratespecs() {
|
||||||
|
builder.add_service(&app, LoaderRegion::Swap);
|
||||||
|
}
|
||||||
|
// builder.add_feature("modal-testing");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue