summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2020-05-02 15:04:25 +1000
committerDamien George <damien.p.george@gmail.com>2020-05-08 23:44:57 +1000
commitf2218c2fbdf3d5267a6d116a980a67b22c58c4b6 (patch)
treeb52b87de6f2aa7880662120cf652451451cf7cf7
parentcaa7725642d8d4d6405d54805036990649cb983a (diff)
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.
-rw-r--r--ports/esp8266/boards/esp8266_common.ld1
-rw-r--r--ports/esp8266/esp_mphal.c13
-rw-r--r--ports/esp8266/esp_mphal.h6
3 files changed, 11 insertions, 9 deletions
diff --git a/ports/esp8266/boards/esp8266_common.ld b/ports/esp8266/boards/esp8266_common.ld
index be1c02b20..c6e37d942 100644
--- a/ports/esp8266/boards/esp8266_common.ld
+++ b/ports/esp8266/boards/esp8266_common.ld
@@ -170,6 +170,7 @@ SECTIONS
*modlwip.o(.literal* .text*)
*modsocket.o(.literal* .text*)
*modonewire.o(.literal* .text*)
+ *esp_mphal.o(.literal* .text*)
/* we put as much rodata as possible in this section */
/* note that only rodata accessed as a machine word is allowed here */
diff --git a/ports/esp8266/esp_mphal.c b/ports/esp8266/esp_mphal.c
index 20d0557d6..c467ab72d 100644
--- a/ports/esp8266/esp_mphal.c
+++ b/ports/esp8266/esp_mphal.c
@@ -50,7 +50,7 @@ void mp_hal_init(void) {
uart_attached_to_dupterm = 0;
}
-void mp_hal_delay_us(uint32_t us) {
+void MP_FASTCODE(mp_hal_delay_us)(uint32_t us) {
uint32_t start = system_get_time();
while (system_get_time() - start < us) {
ets_event_poll();
@@ -128,17 +128,13 @@ void mp_hal_debug_tx_strn_cooked(void *env, const char *str, uint32_t len) {
}
}
-uint32_t mp_hal_ticks_ms(void) {
+uint32_t MP_FASTCODE(mp_hal_ticks_ms)(void) {
// Compute milliseconds from 64-bit microsecond counter
system_time_update();
return ((uint64_t)system_time_high_word << 32 | (uint64_t)system_time_low_word) / 1000;
}
-uint32_t mp_hal_ticks_us(void) {
- return system_get_time();
-}
-
-void mp_hal_delay_ms(uint32_t delay) {
+void MP_FASTCODE(mp_hal_delay_ms)(uint32_t delay) {
mp_hal_delay_us(delay * 1000);
}
@@ -152,7 +148,8 @@ void __assert_func(const char *file, int line, const char *func, const char *exp
mp_raise_msg(&mp_type_AssertionError, MP_ERROR_TEXT("C-level assert"));
}
-void mp_hal_signal_input(void) {
+// May be called by uart0_rx_intr_handler.
+void MP_FASTCODE(mp_hal_signal_input)(void) {
#if MICROPY_REPL_EVENT_DRIVEN
system_os_post(UART_TASK_ID, 0, 0);
#endif
diff --git a/ports/esp8266/esp_mphal.h b/ports/esp8266/esp_mphal.h
index eaae18f6f..89f4e0ff0 100644
--- a/ports/esp8266/esp_mphal.h
+++ b/ports/esp8266/esp_mphal.h
@@ -24,6 +24,7 @@
* THE SOFTWARE.
*/
+#include "user_interface.h"
#include "py/ringbuf.h"
#include "lib/utils/interrupt_char.h"
#include "xtirq.h"
@@ -46,7 +47,10 @@ extern int uart_attached_to_dupterm;
void mp_hal_init(void);
void mp_hal_rtc_init(void);
-uint32_t mp_hal_ticks_us(void);
+__attribute__((always_inline)) static inline uint32_t mp_hal_ticks_us(void) {
+ return system_get_time();
+}
+
__attribute__((always_inline)) static inline uint32_t mp_hal_ticks_cpu(void) {
uint32_t ccount;
__asm__ __volatile__ ("rsr %0,ccount" : "=a" (ccount));