mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
add more NULL prt checks in strtok_r
Conflicts: libraries/SD/src/SD.cpp libraries/SD/src/SD.h
This commit is contained in:
commit
dd7d34ef9d
@ -30,39 +30,32 @@ void timer1_isr_handler(void *para){
|
|||||||
if(timer1_user_cb) timer1_user_cb();
|
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);
|
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;
|
timer1_user_cb = userFunc;
|
||||||
ETS_FRC1_INTR_ENABLE();
|
ETS_FRC1_INTR_ENABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void __timer1_detachInterrupt() {
|
void timer1_detachInterrupt() {
|
||||||
timer1_user_cb = 0;
|
timer1_user_cb = 0;
|
||||||
TEIE &= ~TEIE1;//edge int disable
|
TEIE &= ~TEIE1;//edge int disable
|
||||||
ETS_FRC1_INTR_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);
|
T1C = (1 << TCTE) | ((divider & 3) << TCPD) | ((int_type & 1) << TCIT) | ((reload & 1) << TCAR);
|
||||||
T1I = 0;
|
T1I = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void __timer1_write(uint32_t ticks){
|
void timer1_write(uint32_t ticks){
|
||||||
T1L = ((ticks) & 0x7FFFFF);
|
T1L = ((ticks) & 0x7FFFFF);
|
||||||
if((T1C & (1 << TCIT)) == 0) TEIE |= TEIE1;//edge int enable
|
if((T1C & (1 << TCIT)) == 0) TEIE |= TEIE1;//edge int enable
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void __timer1_disable(){
|
void timer1_disable(){
|
||||||
T1C = 0;
|
T1C = 0;
|
||||||
T1I = 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")));
|
|
@ -175,6 +175,9 @@ char* ICACHE_FLASH_ATTR strtok_r(char * str, const char * delimiters, char ** te
|
|||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
|
|
||||||
if(str == NULL) {
|
if(str == NULL) {
|
||||||
|
if(temp == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
start = *temp;
|
start = *temp;
|
||||||
} else {
|
} else {
|
||||||
start = str;
|
start = str;
|
||||||
@ -184,6 +187,10 @@ char* ICACHE_FLASH_ATTR strtok_r(char * str, const char * delimiters, char ** te
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(delimiters == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
end = start;
|
end = start;
|
||||||
|
|
||||||
while(1) {
|
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) {
|
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) {
|
int strcasecmp(const char * str1, const char * str2) {
|
||||||
|
@ -75,6 +75,11 @@ void WiFiServer::begin()
|
|||||||
|
|
||||||
extern "C" uint32_t esp_micros_at_task_start();
|
extern "C" uint32_t esp_micros_at_task_start();
|
||||||
|
|
||||||
|
bool WiFiServer::hasClient(){
|
||||||
|
if (_unclaimed) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
WiFiClient WiFiServer::available(byte* status)
|
WiFiClient WiFiServer::available(byte* status)
|
||||||
{
|
{
|
||||||
static uint32_t lastPollTime = 0;
|
static uint32_t lastPollTime = 0;
|
||||||
|
@ -44,6 +44,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
WiFiServer(uint16_t port);
|
WiFiServer(uint16_t port);
|
||||||
WiFiClient available(uint8_t* status = NULL);
|
WiFiClient available(uint8_t* status = NULL);
|
||||||
|
bool hasClient();
|
||||||
void begin();
|
void begin();
|
||||||
virtual size_t write(uint8_t);
|
virtual size_t write(uint8_t);
|
||||||
virtual size_t write(const uint8_t *buf, size_t size);
|
virtual size_t write(const uint8_t *buf, size_t size);
|
||||||
|
@ -40,6 +40,38 @@ class ClientContext {
|
|||||||
tcp_err(pcb, &_s_error);
|
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() {
|
~ClientContext() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,22 +90,11 @@ class ClientContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void unref() {
|
void unref() {
|
||||||
err_t err;
|
|
||||||
DEBUGV(":ur %d\r\n", _refcnt);
|
DEBUGV(":ur %d\r\n", _refcnt);
|
||||||
if(--_refcnt == 0) {
|
if(--_refcnt == 0) {
|
||||||
flush();
|
flush();
|
||||||
if(_pcb) {
|
close();
|
||||||
tcp_arg(_pcb, NULL);
|
if(_discard_cb) _discard_cb(_discard_cb_arg, this);
|
||||||
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;
|
|
||||||
}
|
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,6 +200,13 @@ class ClientContext {
|
|||||||
|
|
||||||
private:
|
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) {
|
void _consume(size_t size) {
|
||||||
ptrdiff_t left = _rx_buf->len - _rx_buf_offset - size;
|
ptrdiff_t left = _rx_buf->len - _rx_buf_offset - size;
|
||||||
if(left > 0) {
|
if(left > 0) {
|
||||||
@ -204,21 +232,8 @@ class ClientContext {
|
|||||||
|
|
||||||
if(pb == 0) // connection closed
|
if(pb == 0) // connection closed
|
||||||
{
|
{
|
||||||
DEBUGV(":rcl\r\n");
|
DEBUGV(":rcla\r\n");
|
||||||
tcp_arg(pcb, NULL);
|
return abort();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_rx_buf) {
|
if(_rx_buf) {
|
||||||
@ -231,27 +246,12 @@ class ClientContext {
|
|||||||
_rx_buf = pb;
|
_rx_buf = pb;
|
||||||
_rx_buf_offset = 0;
|
_rx_buf_offset = 0;
|
||||||
}
|
}
|
||||||
// tcp_recved(pcb, received);
|
|
||||||
// pbuf_free(pb);
|
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _error(err_t err) {
|
void _error(err_t err) {
|
||||||
DEBUGV(":er %d\r\n", err);
|
DEBUGV(":er %d\r\n", err);
|
||||||
|
close();
|
||||||
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;
|
|
||||||
|
|
||||||
if(_size_sent && _send_waiting) {
|
if(_size_sent && _send_waiting) {
|
||||||
esp_schedule();
|
esp_schedule();
|
||||||
}
|
}
|
||||||
@ -261,13 +261,6 @@ class ClientContext {
|
|||||||
return ERR_OK;
|
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) {
|
static err_t _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, err_t err) {
|
||||||
return reinterpret_cast<ClientContext*>(arg)->_recv(tpcb, pb, err);
|
return reinterpret_cast<ClientContext*>(arg)->_recv(tpcb, pb, err);
|
||||||
}
|
}
|
||||||
|
@ -326,7 +326,13 @@ boolean callback_rmdir(SdFile& parentDir, char *filePathComponent,
|
|||||||
return true;
|
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.
|
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 true if initialization succeeds, false otherwise.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
return card.init(sckRateID, csPin) &&
|
return card.init(speed, csPin) &&
|
||||||
volume.init(card) &&
|
volume.init(card) &&
|
||||||
root.openRoot(volume);
|
root.openRoot(volume);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
// This needs to be called to set up the connection to the SD card
|
// This needs to be called to set up the connection to the SD card
|
||||||
// before other methods are used.
|
// 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
|
// Open the specified file/directory with the supplied mode (e.g. read or
|
||||||
// write, etc). Returns a File object for interacting with the file.
|
// write, etc). Returns a File object for interacting with the file.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user