Skip to content

optimize pwm interrupt handler for better precision #1267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
15 changes: 8 additions & 7 deletions cores/esp8266/core_esp8266_wiring_pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions cores/esp8266/libc_replacements.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 0 additions & 16 deletions libraries/ESP8266WiFi/src/include/wl_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
8 changes: 4 additions & 4 deletions libraries/ESP8266WiFi/src/lwip/mem_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "c_types.h"

/*------------------------��������------------------------*/
/*------------------------��������------------------------*/

#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
#ifndef IOT_SIP_MODE
Expand Down Expand Up @@ -61,17 +61,17 @@ 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;

//static void prvHeapInit( void ) ;//ICACHE_FLASH_ATTR;

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;

Expand Down
2 changes: 1 addition & 1 deletion platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down