diff --git a/cores/esp8266/Arduino.h b/cores/esp8266/Arduino.h index 80bf1f6ed..5ab2b8476 100644 --- a/cores/esp8266/Arduino.h +++ b/cores/esp8266/Arduino.h @@ -256,6 +256,7 @@ const int TIM_DIV265 __attribute__((deprecated, weak)) = TIM_DIV256; #ifdef __cplusplus #include +#include #include #include "WCharacter.h" diff --git a/cores/esp8266/core_esp8266_app_entry_noextra4k.cpp b/cores/esp8266/core_esp8266_app_entry_noextra4k.cpp index f2f9bffa3..56e4b1d59 100644 --- a/cores/esp8266/core_esp8266_app_entry_noextra4k.cpp +++ b/cores/esp8266/core_esp8266_app_entry_noextra4k.cpp @@ -27,7 +27,7 @@ extern "C" void call_user_start(); /* this is the default NONOS-SDK user's heap location */ static cont_t g_cont __attribute__ ((aligned (16))); -extern "C" void ICACHE_RAM_ATTR app_entry_redefinable(void) +extern "C" void app_entry_redefinable(void) { g_pcont = &g_cont; diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index 7b714183c..0d708ff7e 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -236,8 +236,8 @@ void init_done() { */ -extern "C" void ICACHE_RAM_ATTR app_entry_redefinable(void) __attribute__((weak)); -extern "C" void ICACHE_RAM_ATTR app_entry_redefinable(void) +extern "C" void app_entry_redefinable(void) __attribute__((weak)); +extern "C" void app_entry_redefinable(void) { /* Allocate continuation context on this SYS stack, and save pointer to it. */ @@ -248,9 +248,9 @@ extern "C" void ICACHE_RAM_ATTR app_entry_redefinable(void) call_user_start(); } -static void ICACHE_RAM_ATTR app_entry_custom (void) __attribute__((weakref("app_entry_redefinable"))); +static void app_entry_custom (void) __attribute__((weakref("app_entry_redefinable"))); -extern "C" void ICACHE_RAM_ATTR app_entry (void) +extern "C" void app_entry (void) { return app_entry_custom(); } diff --git a/libraries/ESP8266WiFi/src/include/UdpContext.h b/libraries/ESP8266WiFi/src/include/UdpContext.h index 59403dbdf..8ad074eee 100644 --- a/libraries/ESP8266WiFi/src/include/UdpContext.h +++ b/libraries/ESP8266WiFi/src/include/UdpContext.h @@ -84,11 +84,9 @@ public: void unref() { - if(this != 0) { - DEBUGV(":ur %d\r\n", _refcnt); - if(--_refcnt == 0) { - delete this; - } + DEBUGV(":ur %d\r\n", _refcnt); + if(--_refcnt == 0) { + delete this; } } diff --git a/tools/sdk/ld/eagle.app.v6.common.ld.h b/tools/sdk/ld/eagle.app.v6.common.ld.h index 97aa390a2..45aafed69 100644 --- a/tools/sdk/ld/eagle.app.v6.common.ld.h +++ b/tools/sdk/ld/eagle.app.v6.common.ld.h @@ -127,6 +127,8 @@ SECTIONS *(.init.literal) *(.init) + *(.text.app_entry*) /* The main startup code */ + /* all functional callers are placed in IRAM (including SPI/IRQ callbacks/etc) here */ *(.text._ZNKSt8functionIF*EE*) /* std::function::operator()() const */ } >iram1_0_seg :iram1_0_phdr diff --git a/tools/sdk/libc/xtensa-lx106-elf/include/sys/pgmspace.h b/tools/sdk/libc/xtensa-lx106-elf/include/sys/pgmspace.h index e5e1883d4..d74b8b000 100644 --- a/tools/sdk/libc/xtensa-lx106-elf/include/sys/pgmspace.h +++ b/tools/sdk/libc/xtensa-lx106-elf/include/sys/pgmspace.h @@ -48,13 +48,23 @@ extern "C" { asm("extui %0, %1, 0, 2\n" /* Extract offset within word (in bytes) */ \ "sub %1, %1, %0\n" /* Subtract offset from addr, yielding an aligned address */ \ "l32i.n %1, %1, 0x0\n" /* Load word from aligned address */ \ - "slli %0, %0, 3\n" /* Mulitiply offset by 8, yielding an offset in bits */ \ - "ssr %0\n" /* Prepare to shift by offset (in bits) */ \ - "srl %0, %1\n" /* Shift right; now the requested byte is the first one */ \ + "ssa8l %0\n" /* Prepare to shift by offset (in bits) */ \ + "src %0, %1, %1\n" /* Shift right; now the requested byte is the first one */ \ :"=r"(res), "=r"(addr) \ :"1"(addr) \ :); +#define pgm_read_dword_with_offset(addr, res) \ + asm("extui %0, %1, 0, 2\n" /* Extract offset within word (in bytes) */ \ + "sub %1, %1, %0\n" /* Subtract offset from addr, yielding an aligned address */ \ + "l32i a15, %1, 0\n" \ + "l32i %1, %1, 4\n" \ + "ssa8l %0\n" \ + "src %0, %1, a15\n" \ + :"=r"(res), "=r"(addr) \ + :"1"(addr) \ + :"a15"); + static inline uint8_t pgm_read_byte_inlined(const void* addr) { register uint32_t res; pgm_read_with_offset(addr, res); @@ -68,8 +78,6 @@ static inline uint16_t pgm_read_word_inlined(const void* addr) { return (uint16_t) res; /* This masks the lower half-word from the returned word */ } - - #define pgm_read_byte(addr) pgm_read_byte_inlined(addr) #define pgm_read_word_aligned(addr) pgm_read_word_inlined(addr) #ifdef __cplusplus @@ -82,26 +90,16 @@ static inline uint16_t pgm_read_word_inlined(const void* addr) { #define pgm_read_ptr_aligned(addr) (*(const void* const*)(addr)) #endif -__attribute__((optimize("-O3"), always_inline)) static inline uint32_t pgm_read_dword_unaligned(const void *addr) { - if (!(((int)addr)&3)) return *(const uint32_t *)addr; - int off = (((int)addr) & 3) << 3; - const uint32_t *p = (const uint32_t *)((int)addr & (~3)); - uint32_t a = *p++; - uint32_t b = *p; - return (a>>off) | (b <<(32-off)); +static inline uint32_t pgm_read_dword_unaligned(const void *addr) { + uint32_t res; + pgm_read_dword_with_offset(addr, res); + return res; } -__attribute__((optimize("-O3"), always_inline)) static inline float pgm_read_float_unaligned(const void *addr) { - return (float)pgm_read_dword_unaligned(addr); -} +#define pgm_read_float_unaligned(addr) ((float)pgm_read_dword_unaligned(addr)) +#define pgm_read_ptr_unaligned(addr) ((void*)pgm_read_dword_unaligned(addr)) +#define pgm_read_word_unaligned(addr) ((uint16_t)(pgm_read_dword_unaligned(addr) & 0xffff)) -__attribute__((optimize("-O3"), always_inline)) static inline void *pgm_read_ptr_unaligned(const void *addr) { - return (void *)pgm_read_dword_unaligned(addr); -} - -__attribute__((optimize("-O3"), always_inline)) static inline uint16_t pgm_read_word_unaligned(const void *addr) { - return pgm_read_dword_unaligned(addr) & 0xffff; -} // Allow selection of _aligned or _unaligned, but default to _unaligned for Arduino compatibility // Add -DPGM_READ_UNALIGNED=0 or "#define PGM_READ_UNALIGNED 0" to code to use aligned-only (faster) macros by default