Skip to content

Commit f2218c2

Browse files
committed
esp8266/esp_mphal: Move most functions in esp_mphal.c from iRAM to iROM.
The ones that are moved out of iRAM should not need to be there, because either they call functions in iROM (eg mp_hal_stdout_tx_str), or they are only ever called from a function in iROM and not from an interrupt (eg ets_esf_free_bufs). This frees up about 800 bytes of iRAM.
1 parent caa7725 commit f2218c2

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

ports/esp8266/boards/esp8266_common.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ SECTIONS
170170
*modlwip.o(.literal* .text*)
171171
*modsocket.o(.literal* .text*)
172172
*modonewire.o(.literal* .text*)
173+
*esp_mphal.o(.literal* .text*)
173174

174175
/* we put as much rodata as possible in this section */
175176
/* note that only rodata accessed as a machine word is allowed here */

ports/esp8266/esp_mphal.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void mp_hal_init(void) {
5050
uart_attached_to_dupterm = 0;
5151
}
5252

53-
void mp_hal_delay_us(uint32_t us) {
53+
void MP_FASTCODE(mp_hal_delay_us)(uint32_t us) {
5454
uint32_t start = system_get_time();
5555
while (system_get_time() - start < us) {
5656
ets_event_poll();
@@ -128,17 +128,13 @@ void mp_hal_debug_tx_strn_cooked(void *env, const char *str, uint32_t len) {
128128
}
129129
}
130130

131-
uint32_t mp_hal_ticks_ms(void) {
131+
uint32_t MP_FASTCODE(mp_hal_ticks_ms)(void) {
132132
// Compute milliseconds from 64-bit microsecond counter
133133
system_time_update();
134134
return ((uint64_t)system_time_high_word << 32 | (uint64_t)system_time_low_word) / 1000;
135135
}
136136

137-
uint32_t mp_hal_ticks_us(void) {
138-
return system_get_time();
139-
}
140-
141-
void mp_hal_delay_ms(uint32_t delay) {
137+
void MP_FASTCODE(mp_hal_delay_ms)(uint32_t delay) {
142138
mp_hal_delay_us(delay * 1000);
143139
}
144140

@@ -152,7 +148,8 @@ void __assert_func(const char *file, int line, const char *func, const char *exp
152148
mp_raise_msg(&mp_type_AssertionError, MP_ERROR_TEXT("C-level assert"));
153149
}
154150

155-
void mp_hal_signal_input(void) {
151+
// May be called by uart0_rx_intr_handler.
152+
void MP_FASTCODE(mp_hal_signal_input)(void) {
156153
#if MICROPY_REPL_EVENT_DRIVEN
157154
system_os_post(UART_TASK_ID, 0, 0);
158155
#endif

ports/esp8266/esp_mphal.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* THE SOFTWARE.
2525
*/
2626

27+
#include "user_interface.h"
2728
#include "py/ringbuf.h"
2829
#include "lib/utils/interrupt_char.h"
2930
#include "xtirq.h"
@@ -46,7 +47,10 @@ extern int uart_attached_to_dupterm;
4647
void mp_hal_init(void);
4748
void mp_hal_rtc_init(void);
4849

49-
uint32_t mp_hal_ticks_us(void);
50+
__attribute__((always_inline)) static inline uint32_t mp_hal_ticks_us(void) {
51+
return system_get_time();
52+
}
53+
5054
__attribute__((always_inline)) static inline uint32_t mp_hal_ticks_cpu(void) {
5155
uint32_t ccount;
5256
__asm__ __volatile__ ("rsr %0,ccount" : "=a" (ccount));

0 commit comments

Comments
 (0)