diff --git a/libs/cramium-hal/src/board/dabao.rs b/libs/cramium-hal/src/board/dabao.rs new file mode 100644 index 000000000..687277c52 --- /dev/null +++ b/libs/cramium-hal/src/board/dabao.rs @@ -0,0 +1,69 @@ +// Constants that define pin locations, RAM offsets, etc. for the DaBao basic breakout board +use crate::iox::IoSetup; +use crate::iox::*; + +// console uart buffer +pub const UART_DMA_TX_BUF_PHYS: usize = utralib::HW_IFRAM0_MEM + utralib::HW_IFRAM0_MEM_LEN - 4096; + +// RAM needs two buffers of 1k + 16 bytes = 2048 + 16 = 2064 bytes; round up to one page +pub const SPIM_RAM_IFRAM_ADDR: usize = utralib::HW_IFRAM0_MEM + utralib::HW_IFRAM0_MEM_LEN - 2 * 4096; + +// app uart buffer +pub const APP_UART_IFRAM_ADDR: usize = utralib::HW_IFRAM0_MEM + utralib::HW_IFRAM0_MEM_LEN - 3 * 4096; + +// one page for the I2C driver +pub const I2C_IFRAM_ADDR: usize = utralib::HW_IFRAM0_MEM + utralib::HW_IFRAM0_MEM_LEN - 4 * 4096; + +// USB pages - USB subsystem is a hog, needs a lot of pages, note this is mutually exclusive with camera, +// can't use both at once +pub const CRG_IFRAM_PAGES: usize = 23; // +1 for extended application buffer by 4k +pub const CRG_UDC_MEMBASE: usize = + utralib::HW_IFRAM1_MEM + utralib::HW_IFRAM1_MEM_LEN - CRG_IFRAM_PAGES * 0x1000; + +// MANUALLY SYNCED TO ALLOCATIONS ABOVE +// inclusive numbering - we allocate pages from the top-down, so the last number should generally be 31 +pub const IFRAM0_RESERVED_PAGE_RANGE: [usize; 2] = [31 - 4, 31]; +pub const IFRAM1_RESERVED_PAGE_RANGE: [usize; 2] = [31 - 0, 31]; + +/// returns the USB SE0 port and pin number +const SE0_PIN: u8 = 14; +pub fn setup_usb_pins(iox: &T) -> (IoxPort, u8) { + iox.setup_pin( + IoxPort::PB, + SE0_PIN, + Some(IoxDir::Output), + Some(IoxFunction::Gpio), + None, + None, + Some(IoxEnable::Enable), + Some(IoxDriveStrength::Drive2mA), + ); + iox.set_gpio_pin_value(IoxPort::PB, SE0_PIN, IoxValue::Low); + (IoxPort::PB, SE0_PIN) +} + +pub fn setup_i2c_pins(iox: &dyn IoSetup) -> crate::udma::I2cChannel { + // I2C_SCL_B[0] + iox.setup_pin( + IoxPort::PB, + 11, + Some(IoxDir::Output), + Some(IoxFunction::AF1), + None, + None, + Some(IoxEnable::Enable), + Some(IoxDriveStrength::Drive2mA), + ); + // I2C_SDA_B[0] + iox.setup_pin( + IoxPort::PB, + 12, + Some(IoxDir::Output), + Some(IoxFunction::AF1), + Some(IoxEnable::Enable), + None, + Some(IoxEnable::Enable), + Some(IoxDriveStrength::Drive2mA), + ); + crate::udma::I2cChannel::Channel0 +} diff --git a/libs/cramium-hal/src/board/mod.rs b/libs/cramium-hal/src/board/mod.rs index f8d67d674..d4f813907 100644 --- a/libs/cramium-hal/src/board/mod.rs +++ b/libs/cramium-hal/src/board/mod.rs @@ -6,3 +6,7 @@ pub use baosec::*; pub mod baosor; #[cfg(feature = "board-baosor")] pub use baosor::*; +#[cfg(feature = "board-dabao")] +pub mod dabao; +#[cfg(feature = "board-dabao")] +pub use dabao::*; diff --git a/libs/cramium-hal/src/lib.rs b/libs/cramium-hal/src/lib.rs index 50b2d1252..f26c056ec 100644 --- a/libs/cramium-hal/src/lib.rs +++ b/libs/cramium-hal/src/lib.rs @@ -2,12 +2,15 @@ #[macro_use] pub mod debug; +#[cfg(feature = "axp2101")] pub mod axp2101; pub mod board; pub mod ifram; pub mod iox; +#[cfg(feature = "camera-ov2640")] pub mod ov2640; pub mod sce; +#[cfg(feature = "display-sh1107")] pub mod sh1107; pub mod shared_csr; pub mod udma; diff --git a/libs/cramium-hal/src/sce/trng.rs b/libs/cramium-hal/src/sce/trng.rs index 5d16e1a5a..b73c67044 100644 --- a/libs/cramium-hal/src/sce/trng.rs +++ b/libs/cramium-hal/src/sce/trng.rs @@ -84,6 +84,7 @@ const RAW_ENTRIES: usize = 16; /// for at least this many cycles before the next sample is taken, thus /// making it more difficult for any adversary to reason about the current /// state of the TRNG given the QC samples. +#[allow(dead_code)] const RAW_GUARDBAND: usize = 32; pub struct Trng { @@ -92,6 +93,9 @@ pub struct Trng { mode: Mode, /// Buffer some raw entropy inside the kernel, so we can "burst out" entropy /// for reseed operations without having to wait for the TRNG to regenerate data. + /// + /// This generates an unused warning when `verilator-only` is selected. We leave this + /// warning in place to remind ourselves that the TRNG is not real. raw: [Option; RAW_ENTRIES], #[cfg(feature = "compress-entropy")] rng_var: u8, @@ -110,6 +114,7 @@ impl Trng { } } + #[cfg(not(feature = "verilator-only"))] pub fn setup_raw_generation(&mut self, count: u16) { self._count = count; self.mode = Mode::Raw; @@ -137,6 +142,10 @@ impl Trng { self.csr.wo(utra::trng::SFR_OPT, 0); } + #[cfg(feature = "verilator-only")] + pub fn setup_raw_generation(&mut self, _count: u16) { self.mode = Mode::Raw; } + + #[cfg(not(feature = "verilator-only"))] pub fn get_raw(&mut self) -> u32 { // Pull from the buffered entropy pool, until it's empty. for d in self.raw.iter_mut() { @@ -217,6 +226,13 @@ impl Trng { self.raw[0].take().unwrap() } + #[cfg(feature = "verilator-only")] + pub fn get_raw(&mut self) -> u32 { + // guaranteed random by fair dice roll + // (in all seriousness, this is intentional in verilator because there is no TRNG in the RTL model) + 4 + } + pub fn get_u32(&mut self) -> Option { match self.mode { Mode::Uninit => None,