Skip to content

Commit 408a6b6

Browse files
committed
feat: add mem utils, for checking memory range types
1 parent 255d10d commit 408a6b6

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ endif()
1616

1717
set(srcs
1818
src/flash.c
19+
src/mem_utils.c
1920
src/rom_wrappers.c
2021
)
2122

include/esp-stub-lib/mem_utils.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0 OR MIT
5+
*/
6+
7+
#pragma once
8+
9+
#include <stdbool.h>
10+
#include <stdint.h>
11+
12+
/**
13+
* @brief Check if address is in external memory range.
14+
*
15+
* External flash memory mapped via the instruction bus.
16+
*/
17+
bool stub_lib_mem_is_irom(uintptr_t addr);
18+
19+
/**
20+
* @brief Check if address is in external memory range.
21+
*
22+
* External flash memory mapped via the data bus.
23+
*/
24+
bool stub_lib_mem_is_drom(uintptr_t addr);
25+
26+
/**
27+
* @brief Check if address is in internal memory range.
28+
*
29+
* Internal memory accessed via the instruction bus.
30+
*/
31+
bool stub_lib_mem_is_iram(uintptr_t addr);
32+
33+
/**
34+
* @brief Check if address is in internal memory range.
35+
*
36+
* Internal memory accessed via the data bus.
37+
*/
38+
bool stub_lib_mem_is_dram(uintptr_t addr);
39+
40+
bool stub_lib_mem_is_rtc_iram_fast(uintptr_t addr);
41+
bool stub_lib_mem_is_rtc_dram_fast(uintptr_t addr);
42+
bool stub_lib_mem_is_rtc_slow(uintptr_t addr);
43+
44+
bool stub_lib_mem_is_tcm(uintptr_t addr);

src/mem_utils.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0 OR MIT
5+
*/
6+
#include <stdbool.h>
7+
#include <stdint.h>
8+
9+
#include <mem_utils.h>
10+
11+
#include <soc/soc_caps.h>
12+
#include <soc/soc.h>
13+
14+
bool stub_lib_mem_is_irom(uintptr_t addr)
15+
{
16+
return addr >= SOC_IROM_LOW && addr < SOC_IROM_HIGH;
17+
}
18+
19+
bool stub_lib_mem_is_drom(uintptr_t addr)
20+
{
21+
return addr >= SOC_DROM_LOW && addr < SOC_DROM_HIGH;
22+
}
23+
24+
bool stub_lib_mem_is_iram(uintptr_t addr)
25+
{
26+
return addr >= SOC_IRAM_LOW && addr < SOC_IRAM_HIGH;
27+
}
28+
29+
bool stub_lib_mem_is_dram(uintptr_t addr)
30+
{
31+
return addr >= SOC_DRAM_LOW && addr < SOC_DRAM_HIGH;
32+
}
33+
34+
bool stub_lib_mem_is_rtc_iram_fast(uintptr_t addr)
35+
{
36+
#if defined(SOC_RTC_FAST_MEM_SUPPORTED) && SOC_RTC_FAST_MEM_SUPPORTED
37+
return addr >= SOC_RTC_IRAM_LOW && addr < SOC_RTC_IRAM_HIGH;
38+
#else
39+
(void)addr;
40+
return false;
41+
#endif
42+
}
43+
44+
bool stub_lib_mem_is_rtc_dram_fast(uintptr_t addr)
45+
{
46+
#if defined(SOC_RTC_FAST_MEM_SUPPORTED) && SOC_RTC_FAST_MEM_SUPPORTED
47+
return addr >= SOC_RTC_DRAM_LOW && addr < SOC_RTC_DRAM_HIGH;
48+
#else
49+
(void)addr;
50+
return false;
51+
#endif
52+
53+
}
54+
55+
bool stub_lib_mem_is_rtc_slow(uintptr_t addr)
56+
{
57+
#if defined(SOC_RTC_SLOW_MEM_SUPPORTED) && SOC_RTC_SLOW_MEM_SUPPORTED
58+
return addr >= SOC_RTC_DATA_LOW && addr < SOC_RTC_DATA_HIGH;
59+
#else
60+
(void)addr;
61+
return false;
62+
#endif
63+
}
64+
65+
bool stub_lib_mem_is_tcm(uintptr_t addr)
66+
{
67+
#if defined(SOC_MEM_TCM_SUPPORTED) && SOC_MEM_TCM_SUPPORTED
68+
return (addr >= SOC_TCM_LOW && addr < SOC_TCM_HIGH);
69+
#else
70+
(void)addr;
71+
return false;
72+
#endif
73+
}

0 commit comments

Comments
 (0)