diff --git a/cores/esp8266/core_esp8266_timer.c b/cores/esp8266/core_esp8266_timer.c index 9edee3671..bfdd3692c 100644 --- a/cores/esp8266/core_esp8266_timer.c +++ b/cores/esp8266/core_esp8266_timer.c @@ -30,39 +30,32 @@ void timer1_isr_handler(void *para){ if(timer1_user_cb) timer1_user_cb(); } -extern void __timer1_isr_init(){ +void timer1_isr_init(){ ETS_FRC_TIMER1_INTR_ATTACH(timer1_isr_handler, NULL); } -extern void __timer1_attachInterrupt(void (*userFunc)(void)) { +void timer1_attachInterrupt(void (*userFunc)(void)) { timer1_user_cb = userFunc; ETS_FRC1_INTR_ENABLE(); } -extern void __timer1_detachInterrupt() { +void timer1_detachInterrupt() { timer1_user_cb = 0; TEIE &= ~TEIE1;//edge int disable ETS_FRC1_INTR_DISABLE(); } -extern void __timer1_enable(uint8_t divider, uint8_t int_type, uint8_t reload){ +void timer1_enable(uint8_t divider, uint8_t int_type, uint8_t reload){ T1C = (1 << TCTE) | ((divider & 3) << TCPD) | ((int_type & 1) << TCIT) | ((reload & 1) << TCAR); T1I = 0; } -extern void __timer1_write(uint32_t ticks){ +void timer1_write(uint32_t ticks){ T1L = ((ticks) & 0x7FFFFF); if((T1C & (1 << TCIT)) == 0) TEIE |= TEIE1;//edge int enable } -extern void __timer1_disable(){ +void timer1_disable(){ T1C = 0; T1I = 0; } - -extern void timer1_isr_init(void) __attribute__ ((weak, alias("__timer1_isr_init"))); -extern void timer1_detachInterrupt(void) __attribute__ ((weak, alias("__timer1_detachInterrupt"))); -extern void timer1_disable(void) __attribute__ ((weak, alias("__timer1_disable"))); -extern void timer1_attachInterrupt(void (*userFunc)(void)) __attribute__ ((weak, alias("__timer1_attachInterrupt"))); -extern void timer1_write(uint32_t ticks) __attribute__ ((weak, alias("__timer1_write"))); -extern void timer1_enable(uint8_t divider, uint8_t int_type, uint8_t reload) __attribute__ ((weak, alias("__timer1_enable"))); \ No newline at end of file diff --git a/cores/esp8266/libc_replacements.c b/cores/esp8266/libc_replacements.c index 0554184d5..c1abbcf6f 100644 --- a/cores/esp8266/libc_replacements.c +++ b/cores/esp8266/libc_replacements.c @@ -175,6 +175,9 @@ char* ICACHE_FLASH_ATTR strtok_r(char * str, const char * delimiters, char ** te uint32_t size = 0; if(str == NULL) { + if(temp == NULL) { + return NULL; + } start = *temp; } else { start = str; @@ -184,6 +187,10 @@ char* ICACHE_FLASH_ATTR strtok_r(char * str, const char * delimiters, char ** te return NULL; } + if(delimiters == NULL) { + return NULL; + } + end = start; while(1) { @@ -211,7 +218,9 @@ char* ICACHE_FLASH_ATTR strtok_r(char * str, const char * delimiters, char ** te } char* ICACHE_FLASH_ATTR strtok(char * str, const char * delimiters) { - return strtok_r(str, delimiters, NULL); + static char * ret = NULL; + ret = strtok_r(str, delimiters, &ret); + return ret; } int strcasecmp(const char * str1, const char * str2) { diff --git a/libraries/ESP8266WiFi/src/WiFiServer.cpp b/libraries/ESP8266WiFi/src/WiFiServer.cpp index ec61b424b..1ed2a64c1 100644 --- a/libraries/ESP8266WiFi/src/WiFiServer.cpp +++ b/libraries/ESP8266WiFi/src/WiFiServer.cpp @@ -75,6 +75,11 @@ void WiFiServer::begin() extern "C" uint32_t esp_micros_at_task_start(); +bool WiFiServer::hasClient(){ + if (_unclaimed) return true; + return false; +} + WiFiClient WiFiServer::available(byte* status) { static uint32_t lastPollTime = 0; diff --git a/libraries/ESP8266WiFi/src/WiFiServer.h b/libraries/ESP8266WiFi/src/WiFiServer.h index 0bd427e2f..7e7b0491b 100644 --- a/libraries/ESP8266WiFi/src/WiFiServer.h +++ b/libraries/ESP8266WiFi/src/WiFiServer.h @@ -44,6 +44,7 @@ private: public: WiFiServer(uint16_t port); WiFiClient available(uint8_t* status = NULL); + bool hasClient(); void begin(); virtual size_t write(uint8_t); virtual size_t write(const uint8_t *buf, size_t size); diff --git a/libraries/ESP8266WiFi/src/include/ClientContext.h b/libraries/ESP8266WiFi/src/include/ClientContext.h index f9fd4e524..0001ef08b 100644 --- a/libraries/ESP8266WiFi/src/include/ClientContext.h +++ b/libraries/ESP8266WiFi/src/include/ClientContext.h @@ -39,7 +39,39 @@ class ClientContext { tcp_sent(pcb, &_s_sent); tcp_err(pcb, &_s_error); } - + + err_t abort(){ + if(_pcb) { + DEBUGV(":abort\r\n"); + tcp_arg(_pcb, NULL); + tcp_sent(_pcb, NULL); + tcp_recv(_pcb, NULL); + tcp_err(_pcb, NULL); + tcp_abort(_pcb); + _pcb = 0; + } + return ERR_ABRT; + } + + err_t close(){ + err_t err = ERR_OK; + if(_pcb) { + DEBUGV(":close\r\n"); + tcp_arg(_pcb, NULL); + tcp_sent(_pcb, NULL); + tcp_recv(_pcb, NULL); + tcp_err(_pcb, NULL); + err = tcp_close(_pcb); + if(err != ERR_OK) { + DEBUGV(":tc err %d\r\n", err); + tcp_abort(_pcb); + err = ERR_ABRT; + } + _pcb = 0; + } + return err; + } + ~ClientContext() { } @@ -58,22 +90,11 @@ class ClientContext { } void unref() { - err_t err; DEBUGV(":ur %d\r\n", _refcnt); if(--_refcnt == 0) { flush(); - if(_pcb) { - tcp_arg(_pcb, NULL); - tcp_sent(_pcb, NULL); - tcp_recv(_pcb, NULL); - tcp_err(_pcb, NULL); - err = tcp_close(_pcb); - if(err != ERR_OK) { - DEBUGV(":tc err %d\r\n", err); - tcp_abort(_pcb); - } - _pcb = 0; - } + close(); + if(_discard_cb) _discard_cb(_discard_cb_arg, this); delete this; } } @@ -179,6 +200,13 @@ class ClientContext { private: + err_t _sent(tcp_pcb* pcb, uint16_t len) { + DEBUGV(":sent %d\r\n", len); + _size_sent -= len; + if(_size_sent == 0 && _send_waiting) esp_schedule(); + return ERR_OK; + } + void _consume(size_t size) { ptrdiff_t left = _rx_buf->len - _rx_buf_offset - size; if(left > 0) { @@ -204,21 +232,8 @@ class ClientContext { if(pb == 0) // connection closed { - DEBUGV(":rcl\r\n"); - tcp_arg(pcb, NULL); - tcp_sent(pcb, NULL); - tcp_recv(pcb, NULL); - tcp_err(pcb, NULL); - // int error = tcp_close(pcb); - // if (error != ERR_OK) - { - DEBUGV(":rcla\r\n"); - tcp_abort(pcb); - _pcb = 0; - return ERR_ABRT; - } - _pcb = 0; - return ERR_OK; + DEBUGV(":rcla\r\n"); + return abort(); } if(_rx_buf) { @@ -231,27 +246,12 @@ class ClientContext { _rx_buf = pb; _rx_buf_offset = 0; } - // tcp_recved(pcb, received); - // pbuf_free(pb); return ERR_OK; } void _error(err_t err) { DEBUGV(":er %d\r\n", err); - - if(_pcb) { - tcp_arg(_pcb, NULL); - tcp_sent(_pcb, NULL); - tcp_recv(_pcb, NULL); - tcp_err(_pcb, NULL); - err = tcp_close(_pcb); - if(err != ERR_OK) { - DEBUGV(":tc err %d\r\n", err); - tcp_abort(_pcb); - } - } - _pcb = 0; - + close(); if(_size_sent && _send_waiting) { esp_schedule(); } @@ -261,13 +261,6 @@ class ClientContext { return ERR_OK; } - err_t _sent(tcp_pcb* pcb, uint16_t len) { - DEBUGV(":sent %d\r\n", len); - _size_sent -= len; - if(_size_sent == 0 && _send_waiting) esp_schedule(); - return ERR_OK; - } - static err_t _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, err_t err) { return reinterpret_cast(arg)->_recv(tpcb, pb, err); } diff --git a/libraries/SD/src/SD.cpp b/libraries/SD/src/SD.cpp index d426dbe8e..6862daed8 100644 --- a/libraries/SD/src/SD.cpp +++ b/libraries/SD/src/SD.cpp @@ -326,7 +326,13 @@ boolean callback_rmdir(SdFile& parentDir, char *filePathComponent, return true; } -boolean SDClass::begin(uint8_t csPin, uint32_t sckRateID) { + + +/* Implementation of class used to create `SDCard` object. */ + + + +boolean SDClass::begin(uint8_t csPin, uint32_t speed) { /* Performs the initialisation required by the sdfatlib library. @@ -334,7 +340,7 @@ boolean SDClass::begin(uint8_t csPin, uint32_t sckRateID) { Return true if initialization succeeds, false otherwise. */ - return card.init(sckRateID, csPin) && + return card.init(speed, csPin) && volume.init(card) && root.openRoot(volume); } diff --git a/libraries/SD/src/SD.h b/libraries/SD/src/SD.h index e229cf8ad..449984219 100644 --- a/libraries/SD/src/SD.h +++ b/libraries/SD/src/SD.h @@ -65,7 +65,7 @@ private: public: // This needs to be called to set up the connection to the SD card // before other methods are used. - boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN, uint32_t sckRateID = SPI_FULL_SPEED); + boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN, uint32_t speed = SPI_HALF_SPEED); // Open the specified file/directory with the supplied mode (e.g. read or // write, etc). Returns a File object for interacting with the file.