crate::unstable_module! {
pub mod clocks;
pub mod trng;
pub mod ulp_core;
}
#[cfg(feature = "unstable")]
pub mod cpu_control;
pub mod gpio;
pub(crate) mod regi2c;
pub use esp32s3 as pac;
#[cfg_attr(not(feature = "unstable"), allow(unused))]
pub(crate) mod constants {
pub const I2S_SCLK: u32 = 160_000_000;
pub const I2S_DEFAULT_CLK_SRC: u8 = 2;
}
#[unsafe(link_section = ".rwtext")]
pub(crate) unsafe fn configure_cpu_caches() {
unsafe extern "C" {
fn Cache_Suspend_DCache();
fn Cache_Resume_DCache(param: u32);
fn rom_config_instruction_cache_mode(
cfg_cache_size: u32,
cfg_cache_ways: u8,
cfg_cache_line_size: u8,
);
fn rom_config_data_cache_mode(
cfg_cache_size: u32,
cfg_cache_ways: u8,
cfg_cache_line_size: u8,
);
}
const CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE: u32 = match () {
_ if cfg!(instruction_cache_size_32kb) => 0x8000,
_ if cfg!(instruction_cache_size_16kb) => 0x4000,
_ => core::unreachable!(),
};
const CONFIG_ESP32S3_ICACHE_ASSOCIATED_WAYS: u8 = match () {
_ if cfg!(icache_associated_ways_8) => 8,
_ if cfg!(icache_associated_ways_4) => 4,
_ => core::unreachable!(),
};
const CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_SIZE: u8 = match () {
_ if cfg!(instruction_cache_line_size_32b) => 32,
_ if cfg!(instruction_cache_line_size_16b) => 16,
_ => core::unreachable!(),
};
const CONFIG_ESP32S3_DATA_CACHE_SIZE: u32 = match () {
_ if cfg!(data_cache_size_64kb) => 0x10000,
_ if cfg!(data_cache_size_32kb) => 0x8000,
_ if cfg!(data_cache_size_16kb) => 0x4000,
_ => core::unreachable!(),
};
const CONFIG_ESP32S3_DCACHE_ASSOCIATED_WAYS: u8 = match () {
_ if cfg!(dcache_associated_ways_8) => 8,
_ if cfg!(dcache_associated_ways_4) => 4,
_ => core::unreachable!(),
};
const CONFIG_ESP32S3_DATA_CACHE_LINE_SIZE: u8 = match () {
_ if cfg!(data_cache_line_size_64b) => 64,
_ if cfg!(data_cache_line_size_32b) => 32,
_ if cfg!(data_cache_line_size_16b) => 16,
_ => core::unreachable!(),
};
unsafe {
rom_config_instruction_cache_mode(
CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE,
CONFIG_ESP32S3_ICACHE_ASSOCIATED_WAYS,
CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_SIZE,
);
}
unsafe {
Cache_Suspend_DCache();
rom_config_data_cache_mode(
CONFIG_ESP32S3_DATA_CACHE_SIZE,
CONFIG_ESP32S3_DCACHE_ASSOCIATED_WAYS,
CONFIG_ESP32S3_DATA_CACHE_LINE_SIZE,
);
Cache_Resume_DCache(0);
}
}
#[doc(hidden)]
#[unsafe(link_section = ".rwtext")]
pub unsafe fn cache_writeback_addr(addr: u32, size: u32) {
unsafe extern "C" {
fn rom_Cache_WriteBack_Addr(addr: u32, size: u32);
fn Cache_Suspend_DCache_Autoload() -> u32;
fn Cache_Resume_DCache_Autoload(value: u32);
}
unsafe {
let autoload = Cache_Suspend_DCache_Autoload();
rom_Cache_WriteBack_Addr(addr, size);
Cache_Resume_DCache_Autoload(autoload);
}
}
#[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);
}
}
#[doc(hidden)]
#[unsafe(link_section = ".rwtext")]
pub unsafe fn cache_get_dcache_line_size() -> u32 {
unsafe extern "C" {
fn Cache_Get_DCache_Line_Size() -> u32;
}
unsafe { Cache_Get_DCache_Line_Size() }
}
pub(crate) fn pre_init() {}