2021-05-11 01:04:59 +00:00
|
|
|
const SRAM_LOWER: usize = 0x2000_0000;
|
|
|
|
const SRAM_UPPER: usize = 0x3000_0000;
|
|
|
|
|
|
|
|
/// Does this slice reside entirely within RAM?
|
2021-10-26 07:37:52 +00:00
|
|
|
pub(crate) fn slice_in_ram<T>(slice: &[T]) -> bool {
|
2021-05-11 01:04:59 +00:00
|
|
|
let ptr = slice.as_ptr() as usize;
|
2021-11-04 01:56:02 +00:00
|
|
|
ptr >= SRAM_LOWER && (ptr + slice.len() * core::mem::size_of::<T>()) < SRAM_UPPER
|
2021-05-11 01:04:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Return an error if slice is not in RAM.
|
2021-10-10 23:09:57 +00:00
|
|
|
#[cfg(not(feature = "nrf51"))]
|
2021-10-26 07:37:52 +00:00
|
|
|
pub(crate) fn slice_in_ram_or<T, E>(slice: &[T], err: E) -> Result<(), E> {
|
2021-11-04 01:56:02 +00:00
|
|
|
if slice.is_empty() || slice_in_ram(slice) {
|
2021-05-11 01:04:59 +00:00
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
Err(err)
|
|
|
|
}
|
|
|
|
}
|