aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/util.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-05-11 03:04:59 +0200
committerDario Nieuwenhuis <[email protected]>2021-05-17 00:57:20 +0200
commitbd9589d0ce71a2aa41c9fdf439d6de6349a09d83 (patch)
treebed94fa0d977604b1f9cbcb09d27b44791aca404 /embassy-nrf/src/util.rs
parentcd4111736c0384b1ef957df7f6aa51e3727c29b2 (diff)
nrf: add support for nrf52805, nrf52811, nrf52820
Diffstat (limited to 'embassy-nrf/src/util.rs')
-rw-r--r--embassy-nrf/src/util.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/embassy-nrf/src/util.rs b/embassy-nrf/src/util.rs
new file mode 100644
index 000000000..7c3974eeb
--- /dev/null
+++ b/embassy-nrf/src/util.rs
@@ -0,0 +1,18 @@
1const SRAM_LOWER: usize = 0x2000_0000;
2const SRAM_UPPER: usize = 0x3000_0000;
3
4/// Does this slice reside entirely within RAM?
5pub(crate) fn slice_in_ram(slice: &[u8]) -> bool {
6 let ptr = slice.as_ptr() as usize;
7 ptr >= SRAM_LOWER && (ptr + slice.len()) < SRAM_UPPER
8}
9
10/// Return an error if slice is not in RAM.
11#[cfg(not(feature = "51"))]
12pub(crate) fn slice_in_ram_or<T>(slice: &[u8], err: T) -> Result<(), T> {
13 if slice.len() == 0 || slice_in_ram(slice) {
14 Ok(())
15 } else {
16 Err(err)
17 }
18}