Merge pull request #828 from betrusted-io/dabao-tester

Dabao tester
This commit is contained in:
bunnie 2026-03-02 02:15:42 +08:00 committed by GitHub
commit 31738d94ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 19 deletions

View file

@ -151,7 +151,7 @@ struct DeviceDescriptor {
pub b_num_configurations: u8,
}
const VENDOR_ID: u16 = 0x1d50;
const PRODUCT_ID: u16 = 0x6196; // This is pending acceptance of a PR to the openmoko registry
const PRODUCT_ID: u16 = 0x6196;
const MANUFACTURER: &'static str = "Baochip";
const PRODUCT: &'static str = "Baochip-1x";

View file

@ -2,7 +2,8 @@ use utralib::*;
use xous_bio_bdma::*;
// pinmask 29 is not mapped out. This is tested by pushing the button to allow boot
const DABAO_PINMASK: u32 = 0b0001_1111_1000_1111_0111_1000_0011_1110; // 0x1F8F783E;
// pinmask 12 & 13 not mapped out. This is tested by tx/rx with the tester
const DABAO_PINMASK: u32 = 0b0001_1111_1000_1111_0001_1000_0011_1110; // 0x1F8F183E;
pub fn dabao_selftest() {
let one_way = bao1x_hal::acram::OneWayCounter::new();
@ -14,34 +15,23 @@ pub fn dabao_selftest() {
let mut bio_ss = BioSharedState::new();
let iox = bao1x_hal::iox::Iox::new(utra::iox::HW_IOX_BASE as *mut u32);
iox.set_ports_from_bio_bitmask(DABAO_PINMASK);
iox.set_ports_from_bio_bitmask(DABAO_PINMASK, bao1x_api::bio::IoConfigMode::Overwrite);
bio_ss.init();
bio_ss.load_code(db_pin_test_code(), 0, BioCore::Core0);
bio_ss.bio.wo(utra::bio_bdma::SFR_QDIV0, 0x1_0001);
bio_ss.set_core_run_states([true, false, false, false]);
let pin_ordering: [u32; 19] = [28, 27, 26, 25, 24, 23, 19, 18, 17, 16, 14, 13, 12, 11, 1, 2, 3, 4, 5];
let pin_ordering: [u32; 17] = [28, 27, 26, 25, 24, 23, 19, 18, 17, 16, 12, 11, 1, 2, 3, 4, 5];
crate::println!(
"Starting dabao mini self-test: sets each pin sequentially, in a counter-clockwise order."
);
crate::usb::flush();
crate::delay(30);
const TOTAL_ITERS: usize = 2;
const TOTAL_ITERS: usize = 4;
for i in 0..TOTAL_ITERS {
crate::println!("Iter {}/{}", i + 1, TOTAL_ITERS);
crate::usb::flush();
for pin in pin_ordering {
crate::print!("{} ", pin);
crate::usb::flush();
bio_ss.bio.wo(utra::bio_bdma::SFR_TXF0, 1u32 << pin);
crate::delay(100);
crate::delay(50);
}
crate::println!("");
}
crate::println!("Done; pin state reverted");
crate::usb::flush();
iox.set_ports_from_bio_bitmask(0x0);
iox.set_ports_from_bio_bitmask(0x0, bao1x_api::bio::IoConfigMode::Overwrite);
}
#[rustfmt::skip]
@ -50,7 +40,7 @@ bio_code!(db_pin_test_code, BM_PIN_TEST_START, BM_PIN_TEST_END,
"li a0, -1",
"mv x26, a0", // mask
"mv x25, a0", // inputs
"li a1, 0x3F8F783E", // connected pin mask
"li a1, 0x1F8F183E", // connected pin mask
"mv x24, a1", // select pins as outputs
// receive data from the FIFO, update it to the pins
"10:",

View file

@ -18,6 +18,8 @@ use num_traits::ToPrimitive;
use xous::MemoryRange;
use crate::IoxPort;
#[cfg(feature = "std")]
use crate::bio_resources::ResourceSpec;
pub const BIO_SERVER_NAME: &'static str = "_BIO server_";
@ -401,6 +403,22 @@ impl Default for IoConfig {
}
}
}
#[cfg(feature = "std")]
impl IoConfig {
pub fn from_resource_spec(spec: &ResourceSpec, mode: &Option<IoConfigMode>) -> Result<Self, String> {
let mut mask: u32 = 0;
for &pin in spec.static_pins.iter() {
if pin > 31 {
return Err(format!("Pin {} exceeds maximum bit position of 31", pin));
}
mask |= 1u32 << pin;
}
let mut ret = IoConfig::default();
ret.mapped = mask;
ret.mode = mode.unwrap_or(IoConfigMode::Overwrite);
Ok(ret)
}
}
#[bitfield(u8)]
#[derive(Debug)]