From 1ae423021a3327b416919b95c17de6eafeffcffc Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Mon, 21 Dec 2015 13:50:29 +0200 Subject: [PATCH 1/5] optimize pwm interrupt handler for better precision --- cores/esp8266/core_esp8266_wiring_pwm.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cores/esp8266/core_esp8266_wiring_pwm.c b/cores/esp8266/core_esp8266_wiring_pwm.c index 9dd47e29b3..a7647b3484 100644 --- a/cores/esp8266/core_esp8266_wiring_pwm.c +++ b/cores/esp8266/core_esp8266_wiring_pwm.c @@ -94,18 +94,19 @@ void ICACHE_RAM_ATTR pwm_timer_isr(){ static uint16_t steps[17]; static uint32_t masks[17]; if(current_step < stepcount){ - GPOC = masks[current_step] & 0xFFFF; - if(masks[current_step] & 0x10000) GP16O &= ~1; + T1L = (pwm_steps[current_step+1] * pwm_multiplier); + TEIE |= TEIE1; + if(masks[current_step] & 0xFFFF) GPOC = masks[current_step] & 0xFFFF; + if(masks[current_step] & 0x10000) GP16O = 0; current_step++; - timer1_write(pwm_steps[current_step] * pwm_multiplier); } else { - current_step = 0; stepcount = 0; if(pwm_mask == 0) return; - GPOS = pwm_mask & 0xFFFF; - if(pwm_mask & 0x10000) GP16O |= 1; - timer1_write(pwm_steps[0] * pwm_multiplier); + T1L = (pwm_steps[current_step+1] * pwm_multiplier); + TEIE |= TEIE1; + if(pwm_mask & 0xFFFF) GPOS = pwm_mask & 0xFFFF; + if(pwm_mask & 0x10000) GP16O = 1; stepcount = pwm_steps_len; memcpy(steps, pwm_steps, (stepcount + 1) * 2); memcpy(masks, pwm_steps_mask, stepcount * 4); From a33dba099ffb6d6655327c59b72e0f090e219f1c Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Mon, 21 Dec 2015 13:54:29 +0200 Subject: [PATCH 2/5] fix identation --- cores/esp8266/core_esp8266_wiring_pwm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cores/esp8266/core_esp8266_wiring_pwm.c b/cores/esp8266/core_esp8266_wiring_pwm.c index a7647b3484..9d16b62b7b 100644 --- a/cores/esp8266/core_esp8266_wiring_pwm.c +++ b/cores/esp8266/core_esp8266_wiring_pwm.c @@ -94,18 +94,18 @@ void ICACHE_RAM_ATTR pwm_timer_isr(){ static uint16_t steps[17]; static uint32_t masks[17]; if(current_step < stepcount){ - T1L = (pwm_steps[current_step+1] * pwm_multiplier); - TEIE |= TEIE1; - if(masks[current_step] & 0xFFFF) GPOC = masks[current_step] & 0xFFFF; + T1L = (pwm_steps[current_step+1] * pwm_multiplier); + TEIE |= TEIE1; + if(masks[current_step] & 0xFFFF) GPOC = masks[current_step] & 0xFFFF; if(masks[current_step] & 0x10000) GP16O = 0; current_step++; } else { current_step = 0; stepcount = 0; if(pwm_mask == 0) return; - T1L = (pwm_steps[current_step+1] * pwm_multiplier); - TEIE |= TEIE1; - if(pwm_mask & 0xFFFF) GPOS = pwm_mask & 0xFFFF; + T1L = (pwm_steps[current_step+1] * pwm_multiplier); + TEIE |= TEIE1; + if(pwm_mask & 0xFFFF) GPOS = pwm_mask & 0xFFFF; if(pwm_mask & 0x10000) GP16O = 1; stepcount = pwm_steps_len; memcpy(steps, pwm_steps, (stepcount + 1) * 2); From 0fd1201633322b1f8ddcccd92f0fea53e3cfd525 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Mon, 21 Dec 2015 14:47:48 +0200 Subject: [PATCH 3/5] fix tcp status redefinition and bad mem definitions in lwip --- .../ESP8266WiFi/src/include/wl_definitions.h | 16 ---------------- libraries/ESP8266WiFi/src/lwip/mem.h | 10 +++++----- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/libraries/ESP8266WiFi/src/include/wl_definitions.h b/libraries/ESP8266WiFi/src/include/wl_definitions.h index 45bee6764e..0669661b39 100644 --- a/libraries/ESP8266WiFi/src/include/wl_definitions.h +++ b/libraries/ESP8266WiFi/src/include/wl_definitions.h @@ -68,20 +68,4 @@ enum wl_enc_type { /* Values map to 802.11 encryption suites... */ ENC_TYPE_AUTO = 8 }; -#if !defined(LWIP_INTERNAL) -enum wl_tcp_state { - CLOSED = 0, - LISTEN = 1, - SYN_SENT = 2, - SYN_RCVD = 3, - ESTABLISHED = 4, - FIN_WAIT_1 = 5, - FIN_WAIT_2 = 6, - CLOSE_WAIT = 7, - CLOSING = 8, - LAST_ACK = 9, - TIME_WAIT = 10 -}; -#endif - #endif /* WL_DEFINITIONS_H_ */ diff --git a/libraries/ESP8266WiFi/src/lwip/mem.h b/libraries/ESP8266WiFi/src/lwip/mem.h index 1d768856c6..ed58aa47f7 100644 --- a/libraries/ESP8266WiFi/src/lwip/mem.h +++ b/libraries/ESP8266WiFi/src/lwip/mem.h @@ -51,19 +51,19 @@ typedef size_t mem_size_t; * allow these defines to be overridden. */ #ifndef mem_free -#define mem_free(p) vPortFree(p, "", 0) +#define mem_free(p) vPortFree(p) #endif #ifndef mem_malloc -#define mem_malloc(s) pvPortMalloc(s, "", 0) +#define mem_malloc(s) pvPortMalloc(s) #endif #ifndef mem_calloc -#define mem_calloc(s) pvPortCalloc(s, "", 0) +#define mem_calloc(s) pvPortCalloc(s) #endif #ifndef mem_realloc -#define mem_realloc(p, s) pvPortRealloc(p, s, "", 0) +#define mem_realloc(p, s) pvPortRealloc(p, s) #endif #ifndef mem_zalloc -#define mem_zalloc(s) pvPortZalloc(s, "", 0) +#define mem_zalloc(s) pvPortZalloc(s) #endif #ifndef os_malloc From bcfdfb6b67f92c72b26352ee6821bba90b25ac93 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Mon, 21 Dec 2015 14:52:56 +0200 Subject: [PATCH 4/5] more bad definitions interesting that they differ in issues with 1.3 over the same source did pvPort* change in between? --- libraries/ESP8266WiFi/src/lwip/mem.h | 10 +++++----- libraries/ESP8266WiFi/src/lwip/mem_manager.h | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libraries/ESP8266WiFi/src/lwip/mem.h b/libraries/ESP8266WiFi/src/lwip/mem.h index ed58aa47f7..1d768856c6 100644 --- a/libraries/ESP8266WiFi/src/lwip/mem.h +++ b/libraries/ESP8266WiFi/src/lwip/mem.h @@ -51,19 +51,19 @@ typedef size_t mem_size_t; * allow these defines to be overridden. */ #ifndef mem_free -#define mem_free(p) vPortFree(p) +#define mem_free(p) vPortFree(p, "", 0) #endif #ifndef mem_malloc -#define mem_malloc(s) pvPortMalloc(s) +#define mem_malloc(s) pvPortMalloc(s, "", 0) #endif #ifndef mem_calloc -#define mem_calloc(s) pvPortCalloc(s) +#define mem_calloc(s) pvPortCalloc(s, "", 0) #endif #ifndef mem_realloc -#define mem_realloc(p, s) pvPortRealloc(p, s) +#define mem_realloc(p, s) pvPortRealloc(p, s, "", 0) #endif #ifndef mem_zalloc -#define mem_zalloc(s) pvPortZalloc(s) +#define mem_zalloc(s) pvPortZalloc(s, "", 0) #endif #ifndef os_malloc diff --git a/libraries/ESP8266WiFi/src/lwip/mem_manager.h b/libraries/ESP8266WiFi/src/lwip/mem_manager.h index 035596891d..58c2a02aee 100644 --- a/libraries/ESP8266WiFi/src/lwip/mem_manager.h +++ b/libraries/ESP8266WiFi/src/lwip/mem_manager.h @@ -3,7 +3,7 @@ #include "c_types.h" -/*------------------------±äÁ¿¶¨Òå------------------------*/ +/*------------------------��������------------------------*/ #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE #ifndef IOT_SIP_MODE @@ -61,7 +61,7 @@ static const unsigned short heapSTRUCT_SIZE = ( sizeof( xBlockLink ) + portBYTE_ //static size_t xFreeBytesRemaining = ( ( size_t ) configADJUSTED_HEAP_SIZE ) & ( ( size_t ) ~portBYTE_ALIGNMENT_MASK ); -/*------------------------º¯ÊýÉùÃ÷-----------------------------------*/ +/*------------------------��������-----------------------------------*/ //static void prvInsertBlockIntoFreeList( xBlockLink *pxBlockToInsert ) ;//ICACHE_FLASH_ATTR; @@ -69,9 +69,9 @@ static const unsigned short heapSTRUCT_SIZE = ( sizeof( xBlockLink ) + portBYTE_ void vApplicationMallocFailedHook( void ) ;//ICACHE_FLASH_ATTR; -void *pvPortMalloc( size_t xWantedSize ) ;//ICACHE_FLASH_ATTR; +//void *pvPortMalloc( size_t xWantedSize ) ;//ICACHE_FLASH_ATTR; -void vPortFree( void *pv ) ;//ICACHE_FLASH_ATTR; +//void vPortFree( void *pv ) ;//ICACHE_FLASH_ATTR; size_t xPortGetFreeHeapSize( void ) ;//ICACHE_FLASH_ATTR; From f553467f64762650ddab63dc6ecd27d7f4866fd8 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Tue, 22 Dec 2015 01:06:32 +0200 Subject: [PATCH 5/5] add aligned wraps for pvPortMalloc and pvPortRealloc --- cores/esp8266/libc_replacements.c | 10 ++++++++++ platform.txt | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cores/esp8266/libc_replacements.c b/cores/esp8266/libc_replacements.c index f7d1420e3c..948bc7e038 100644 --- a/cores/esp8266/libc_replacements.c +++ b/cores/esp8266/libc_replacements.c @@ -39,6 +39,16 @@ #include "user_interface.h" #include "debug.h" +extern void *__real_pvPortMalloc(size_t xWantedSize, const char* file, int line); +extern void *__wrap_pvPortMalloc(size_t xWantedSize, const char* file, int line){ + return __real_pvPortMalloc(((xWantedSize + 3) & ~((size_t)0x3)), file, line); +} + +extern void *__real_pvPortRealloc(void* ptr, size_t xWantedSize, const char* file, int line); +extern void *__wrap_pvPortRealloc(void* ptr, size_t xWantedSize, const char* file, int line){ + return __real_pvPortRealloc(ptr, ((xWantedSize + 3) & ~((size_t)0x3)), file, line); +} + void* ICACHE_RAM_ATTR malloc(size_t size) { size = ((size + 3) & ~((size_t)0x3)); return os_malloc(size); diff --git a/platform.txt b/platform.txt index efeb816e97..1ffbf2818f 100644 --- a/platform.txt +++ b/platform.txt @@ -27,7 +27,7 @@ compiler.c.flags=-c {compiler.warning_flags} -Os -g -Wpointer-arith -Wno-implici compiler.S.cmd=xtensa-lx106-elf-gcc compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls -compiler.c.elf.flags=-g {compiler.warning_flags} -Os -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" "-T{build.flash_ld}" -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,register_chipv6_phy +compiler.c.elf.flags=-g {compiler.warning_flags} -Os -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" "-T{build.flash_ld}" -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,register_chipv6_phy -Wl,-wrap,pvPortMalloc -Wl,-wrap,pvPortRealloc compiler.c.elf.cmd=xtensa-lx106-elf-gcc compiler.c.elf.libs=-lm -lgcc -lhal -lphy -lpp -lnet80211 -llwip -lwpa -lcrypto -lmain -lwps -laxtls -lsmartconfig -lmesh