crate::unstable_module! {
pub mod clocks;
pub mod trng;
pub mod lp_core;
}
pub mod gpio;
pub(crate) mod regi2c;
pub(crate) use esp32s2 as pac;
#[cfg(i2s_driver_supported)]
#[cfg_attr(not(feature = "unstable"), allow(unused))]
pub(crate) fn i2s_sclk_frequency() -> u32 {
match clocks::pll_clk_frequency() {
320_000_000 => 320_000_000 / 2,
480_000_000 => 480_000_000 / 3,
_ => unreachable!(),
}
}
#[doc(hidden)]
#[unsafe(link_section = ".rwtext")]
pub unsafe fn cache_writeback_addr(addr: u32, size: u32) {
unsafe extern "C" {
fn Cache_WriteBack_Addr(addr: u32, size: u32);
}
unsafe {
Cache_WriteBack_Addr(addr, size);
}
}
#[doc(hidden)]
#[unsafe(link_section = ".rwtext")]
pub unsafe fn cache_invalidate_addr(addr: u32, size: u32) {
unsafe extern "C" {
fn Cache_Invalidate_Addr(addr: u32, size: u32);
}
unsafe {
Cache_Invalidate_Addr(addr, size);
}
}
pub(crate) const CONFIG_INSTRUCTION_CACHE_LINE_SIZE: usize = cfg_select! {
instruction_cache_line_size_16b => 16,
instruction_cache_line_size_32b => 32,
};
pub(crate) const CONFIG_DATA_CACHE_LINE_SIZE: usize = cfg_select! {
data_cache_line_size_16b => 16,
data_cache_line_size_32b => 32,
};
pub(crate) const CONFIG_INSTRUCTION_CACHE_SIZE: usize = cfg_select! {
instruction_cache_size_8kb => 0,
instruction_cache_size_16kb => 1,
};
pub(crate) const CONFIG_DATA_CACHE_SIZE: usize =
cfg_select! {
data_cache_size_0kb => 0, data_cache_size_8kb => 0,
data_cache_size_16kb => 1,
};
#[crate::ram]
pub(crate) unsafe fn configure_cpu_caches() {
unsafe extern "C" {
fn Cache_Invalidate_ICache_All();
fn Cache_Set_ICache_Mode(cache_size: u32, ways: u32, cache_line_size: u32);
fn Cache_Resume_ICache(autoload: u32);
fn Cache_Allocate_SRAM(
sram0_layout: u32,
sram1_layout: u32,
sram2_layout: u32,
sram3_layout: u32,
);
fn Cache_Set_DCache_Mode(cache_size: u32, ways: u32, cache_line_size: u32);
fn Cache_Invalidate_DCache_All();
fn Cache_Enable_DCache(autoload: u32);
}
const CACHE_4WAYS_ASSOC: u32 = 0;
#[derive(Clone, Copy, Debug)]
enum CacheLayout {
Invalid = 0,
ICacheLow = 1 << 0,
ICacheHigh = 1 << 1,
DCacheLow = 1 << 2,
DCacheHigh = 1 << 3,
}
let mut sram = [
CacheLayout::ICacheLow,
CacheLayout::Invalid,
CacheLayout::Invalid,
CacheLayout::Invalid,
];
let mut idx = 1;
if cfg!(instruction_cache_size_16kb) {
sram[idx] = CacheLayout::ICacheHigh;
idx += 1;
}
if !cfg!(data_cache_size_0kb) {
sram[idx] = CacheLayout::DCacheLow;
idx += 1;
}
if cfg!(data_cache_size_16kb) {
sram[idx] = CacheLayout::DCacheHigh;
}
unsafe {
Cache_Allocate_SRAM(
sram[0] as u32,
sram[1] as u32,
sram[2] as u32,
sram[3] as u32,
);
}
unsafe {
Cache_Set_ICache_Mode(
CONFIG_INSTRUCTION_CACHE_SIZE as u32,
CACHE_4WAYS_ASSOC,
match CONFIG_INSTRUCTION_CACHE_LINE_SIZE {
16 => 0,
32 => 1,
_ => unreachable!(),
},
);
Cache_Invalidate_ICache_All();
Cache_Resume_ICache(0);
Cache_Set_DCache_Mode(
CONFIG_DATA_CACHE_SIZE as u32,
CACHE_4WAYS_ASSOC,
match CONFIG_DATA_CACHE_LINE_SIZE {
16 => 0,
32 => 1,
_ => unreachable!(),
},
);
Cache_Invalidate_DCache_All();
Cache_Enable_DCache(0);
}
}
pub(crate) fn pre_init() {}