@@ -15,15 +15,26 @@ extern "C" {
15
15
16
16
#define ROMFN_ATTR
17
17
18
+ #define __ESP_COUNTER__ 1
19
+ #undef __TMP__
20
+
18
21
//Normally, the linker script will put all code and rodata in flash,
19
22
//and all variables in shared RAM. These macros can be used to redirect
20
23
//particular functions/variables to other memory regions.
21
24
22
25
// Forces code into IRAM instead of flash
23
- #define IRAM_ATTR _SECTION_ATTR_IMPL(".iram1", __COUNTER__)
26
+ #define IRAM_ATTR _SECTION_ATTR_IMPL(".iram1", __ESP_COUNTER__)
27
+ #define __TMP__ __ESP_COUNTER__ + 1
28
+ #undef __ESP_COUNTER__
29
+ #define __ESP_COUNTER__ __TMP__
30
+ #undef __TMP__
24
31
25
32
// Forces data into DRAM instead of flash
26
- #define DRAM_ATTR _SECTION_ATTR_IMPL(".dram1", __COUNTER__)
33
+ #define DRAM_ATTR _SECTION_ATTR_IMPL(".dram1", __ESP_COUNTER__)
34
+ #define __TMP__ __ESP_COUNTER__ + 1
35
+ #undef __ESP_COUNTER__
36
+ #define __ESP_COUNTER__ __TMP__
37
+ #undef __TMP__
27
38
28
39
// IRAM can only be accessed as an 8-bit memory on ESP32, when CONFIG_ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY is set
29
40
#define IRAM_8BIT_ACCESSIBLE (CONFIG_IDF_TARGET_ESP32 && CONFIG_ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY)
@@ -35,7 +46,11 @@ extern "C" {
35
46
#define IRAM_DATA_ATTR __attribute__((section(".iram.data")))
36
47
37
48
// Forces data into IRAM instead of DRAM and map it to coredump
38
- #define COREDUMP_IRAM_DATA_ATTR _SECTION_ATTR_IMPL(".iram2.coredump", __COUNTER__)
49
+ #define COREDUMP_IRAM_DATA_ATTR _SECTION_ATTR_IMPL(".iram2.coredump", __ESP_COUNTER__)
50
+ #define __TMP__ __ESP_COUNTER__ + 1
51
+ #undef __ESP_COUNTER__
52
+ #define __ESP_COUNTER__ __TMP__
53
+ #undef __TMP__
39
54
40
55
// Forces bss into IRAM instead of DRAM
41
56
#define IRAM_BSS_ATTR __attribute__((section(".iram.bss")))
@@ -62,35 +77,67 @@ extern "C" {
62
77
#define DRAM_STR (str ) (__extension__({static const DRAM_ATTR char __c[] = (str); (const char *)&__c;}))
63
78
64
79
// Forces code into RTC fast memory. See "docs/deep-sleep-stub.rst"
65
- #define RTC_IRAM_ATTR _SECTION_ATTR_IMPL(".rtc.text", __COUNTER__)
80
+ #define RTC_IRAM_ATTR _SECTION_ATTR_IMPL(".rtc.text", __ESP_COUNTER__)
81
+ #define __TMP__ __ESP_COUNTER__ + 1
82
+ #undef __ESP_COUNTER__
83
+ #define __ESP_COUNTER__ __TMP__
84
+ #undef __TMP__
66
85
67
86
#if CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY
68
87
// Forces bss variable into external memory. "
69
- #define EXT_RAM_ATTR _SECTION_ATTR_IMPL(".ext_ram.bss", __COUNTER__)
88
+ #define EXT_RAM_ATTR _SECTION_ATTR_IMPL(".ext_ram.bss", __ESP_COUNTER__)
89
+ #define __TMP__ __ESP_COUNTER__ + 1
90
+ #undef __ESP_COUNTER__
91
+ #define __ESP_COUNTER__ __TMP__
92
+ #undef __TMP__
70
93
#else
71
94
#define EXT_RAM_ATTR
72
95
#endif
73
96
74
97
// Forces data into RTC slow memory. See "docs/deep-sleep-stub.rst"
75
98
// Any variable marked with this attribute will keep its value
76
99
// during a deep sleep / wake cycle.
77
- #define RTC_DATA_ATTR _SECTION_ATTR_IMPL(".rtc.data", __COUNTER__)
100
+ #define RTC_DATA_ATTR _SECTION_ATTR_IMPL(".rtc.data", __ESP_COUNTER__)
101
+ #define __TMP__ __ESP_COUNTER__ + 1
102
+ #undef __ESP_COUNTER__
103
+ #define __ESP_COUNTER__ __TMP__
104
+ #undef __TMP__
78
105
79
106
// Forces read-only data into RTC memory. See "docs/deep-sleep-stub.rst"
80
- #define RTC_RODATA_ATTR _SECTION_ATTR_IMPL(".rtc.rodata", __COUNTER__)
107
+ #define RTC_RODATA_ATTR _SECTION_ATTR_IMPL(".rtc.rodata", __ESP_COUNTER__)
108
+ #define __TMP__ __ESP_COUNTER__ + 1
109
+ #undef __ESP_COUNTER__
110
+ #define __ESP_COUNTER__ __TMP__
111
+ #undef __TMP__
81
112
82
113
// Allows to place data into RTC_SLOW memory.
83
- #define RTC_SLOW_ATTR _SECTION_ATTR_IMPL(".rtc.force_slow", __COUNTER__)
114
+ #define RTC_SLOW_ATTR _SECTION_ATTR_IMPL(".rtc.force_slow", __ESP_COUNTER__)
115
+ #define __TMP__ __ESP_COUNTER__ + 1
116
+ #undef __ESP_COUNTER__
117
+ #define __ESP_COUNTER__ __TMP__
118
+ #undef __TMP__
84
119
85
120
// Allows to place data into RTC_FAST memory.
86
- #define RTC_FAST_ATTR _SECTION_ATTR_IMPL(".rtc.force_fast", __COUNTER__)
121
+ #define RTC_FAST_ATTR _SECTION_ATTR_IMPL(".rtc.force_fast", __ESP_COUNTER__)
122
+ #define __TMP__ __ESP_COUNTER__ + 1
123
+ #undef __ESP_COUNTER__
124
+ #define __ESP_COUNTER__ __TMP__
125
+ #undef __TMP__
87
126
88
127
// Forces data into noinit section to avoid initialization after restart.
89
- #define __NOINIT_ATTR _SECTION_ATTR_IMPL(".noinit", __COUNTER__)
128
+ #define __NOINIT_ATTR _SECTION_ATTR_IMPL(".noinit", __ESP_COUNTER__)
129
+ #define __TMP__ __ESP_COUNTER__ + 1
130
+ #undef __ESP_COUNTER__
131
+ #define __ESP_COUNTER__ __TMP__
132
+ #undef __TMP__
90
133
91
134
#if CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY
92
135
// Forces data into external memory noinit section to avoid initialization after restart.
93
- #define EXT_RAM_NOINIT_ATTR _SECTION_ATTR_IMPL(".ext_ram_noinit", __COUNTER__)
136
+ #define EXT_RAM_NOINIT_ATTR _SECTION_ATTR_IMPL(".ext_ram_noinit", __ESP_COUNTER__)
137
+ #define __TMP__ __ESP_COUNTER__ + 1
138
+ #undef __ESP_COUNTER__
139
+ #define __ESP_COUNTER__ __TMP__
140
+ #undef __TMP__
94
141
#else
95
142
// Place in internal noinit section
96
143
#define EXT_RAM_NOINIT_ATTR __NOINIT_ATTR
@@ -99,18 +146,34 @@ extern "C" {
99
146
// Forces data into RTC slow memory of .noinit section.
100
147
// Any variable marked with this attribute will keep its value
101
148
// after restart or during a deep sleep / wake cycle.
102
- #define RTC_NOINIT_ATTR _SECTION_ATTR_IMPL(".rtc_noinit", __COUNTER__)
149
+ #define RTC_NOINIT_ATTR _SECTION_ATTR_IMPL(".rtc_noinit", __ESP_COUNTER__)
150
+ #define __TMP__ __ESP_COUNTER__ + 1
151
+ #undef __ESP_COUNTER__
152
+ #define __ESP_COUNTER__ __TMP__
153
+ #undef __TMP__
103
154
104
155
// Forces code into DRAM instead of flash and map it to coredump
105
156
// Use dram2 instead of dram1 to make sure this section will not be included
106
157
// by dram1 section in the linker script
107
- #define COREDUMP_DRAM_ATTR _SECTION_ATTR_IMPL(".dram2.coredump", __COUNTER__)
158
+ #define COREDUMP_DRAM_ATTR _SECTION_ATTR_IMPL(".dram2.coredump", __ESP_COUNTER__)
159
+ #define __TMP__ __ESP_COUNTER__ + 1
160
+ #undef __ESP_COUNTER__
161
+ #define __ESP_COUNTER__ __TMP__
162
+ #undef __TMP__
108
163
109
164
// Forces data into RTC memory and map it to coredump
110
- #define COREDUMP_RTC_DATA_ATTR _SECTION_ATTR_IMPL(".rtc.coredump", __COUNTER__)
165
+ #define COREDUMP_RTC_DATA_ATTR _SECTION_ATTR_IMPL(".rtc.coredump", __ESP_COUNTER__)
166
+ #define __TMP__ __ESP_COUNTER__ + 1
167
+ #undef __ESP_COUNTER__
168
+ #define __ESP_COUNTER__ __TMP__
169
+ #undef __TMP__
111
170
112
171
// Allows to place data into RTC_FAST memory and map it to coredump
113
- #define COREDUMP_RTC_FAST_ATTR _SECTION_ATTR_IMPL(".rtc.fast.coredump", __COUNTER__)
172
+ #define COREDUMP_RTC_FAST_ATTR _SECTION_ATTR_IMPL(".rtc.fast.coredump", __ESP_COUNTER__)
173
+ #define __TMP__ __ESP_COUNTER__ + 1
174
+ #undef __ESP_COUNTER__
175
+ #define __ESP_COUNTER__ __TMP__
176
+ #undef __TMP__
114
177
115
178
// Forces to not inline function
116
179
#define NOINLINE_ATTR __attribute__((noinline))
@@ -160,6 +223,9 @@ FORCE_INLINE_ATTR TYPE& operator<<=(TYPE& a, int b) { a <<= b; return a; }
160
223
#define IDF_DEPRECATED (REASON )
161
224
#endif
162
225
226
+ #undef __ESP_COUNTER__
227
+ #undef __TMP__
228
+
163
229
#ifdef __cplusplus
164
230
}
165
231
#endif
0 commit comments