Skip to content

Commit 8fb43a8

Browse files
authored
Merge pull request #11817 from AnttiKauppila/esp_fix
ESP8266 "busy s..." fix (ONME-4352)
2 parents 8fcfbe1 + d5fdcfd commit 8fb43a8

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

components/wifi/esp8266-driver/ESP8266/ESP8266.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ nsapi_error_t ESP8266::send(int id, const void *data, uint32_t amount)
626626
}
627627

628628
_smutex.lock();
629+
RETRY:
629630
set_timeout(ESP8266_SEND_TIMEOUT);
630631
_busy = false;
631632
_error = false;
@@ -634,11 +635,25 @@ nsapi_error_t ESP8266::send(int id, const void *data, uint32_t amount)
634635
goto END;
635636
}
636637

638+
//We might receive "busy s/p..." and "OK" from modem, so we need to check that also
639+
_ok_received = false;
640+
_parser.oob("OK", callback(this, &ESP8266::_oob_ok_received));
641+
637642
if (!_parser.recv(">")) {
643+
_parser.remove_oob("OK");
644+
if (_busy) {
645+
if (_ok_received) {
646+
goto RETRY;
647+
} else if (_parser.recv("OK")) {
648+
goto RETRY;
649+
}
650+
}
638651
tr_debug("send(): Didn't get \">\"");
639652
ret = NSAPI_ERROR_WOULD_BLOCK;
640653
goto END;
641654
}
655+
_ok_received = false;
656+
_parser.remove_oob("OK");
642657

643658
if (_parser.write((char *)data, (int)amount) >= 0 && _parser.recv("SEND OK")) {
644659
ret = NSAPI_ERROR_OK;
@@ -1071,7 +1086,6 @@ void ESP8266::_oob_busy()
10711086
"ESP8266::_oob_busy() AT timeout\n");
10721087
}
10731088
_busy = true;
1074-
_parser.abort();
10751089
}
10761090

10771091
void ESP8266::_oob_tcp_data_hdlr()
@@ -1205,6 +1219,12 @@ void ESP8266::_oob_connection_status()
12051219
_conn_stat_cb();
12061220
}
12071221

1222+
void ESP8266::_oob_ok_received()
1223+
{
1224+
tr_debug("_oob_ok_received called");
1225+
_ok_received = true;
1226+
}
1227+
12081228
int8_t ESP8266::default_wifi_mode()
12091229
{
12101230
int8_t mode;

components/wifi/esp8266-driver/ESP8266/ESP8266.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ class ESP8266 {
469469
void _oob_tcp_data_hdlr();
470470
void _oob_ready();
471471
void _oob_scan_results();
472+
void _oob_ok_received();
472473

473474
// OOB state variables
474475
int _connect_error;
@@ -479,6 +480,7 @@ class ESP8266 {
479480
bool _error;
480481
bool _busy;
481482
bool _reset_done;
483+
bool _ok_received;
482484

483485
// Modem's address info
484486
char _ip_buffer[16];

platform/ATCmdParser.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,12 @@ class ATCmdParser : private NonCopyable<ATCmdParser> {
311311
*/
312312
void oob(const char *prefix, mbed::Callback<void()> func);
313313

314+
/**
315+
* @brief remove_oob Removes oob callback handler
316+
* @param prefix Prefix to identify oob to be removed.
317+
*/
318+
void remove_oob(const char *prefix);
319+
314320
/**
315321
* Flushes the underlying stream
316322
*/

platform/source/ATCmdParser.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,25 @@ void ATCmdParser::oob(const char *prefix, Callback<void()> cb)
362362
_oobs = oob;
363363
}
364364

365+
void ATCmdParser::remove_oob(const char *prefix)
366+
{
367+
struct oob *prev = NULL;
368+
struct oob *oob = _oobs;
369+
while (oob) {
370+
if (memcmp(oob->prefix, prefix, strlen(prefix)) == 0) {
371+
if (prev) {
372+
prev->next = oob->next;
373+
} else {
374+
_oobs = oob->next;
375+
}
376+
delete oob;
377+
return;
378+
}
379+
prev = oob;
380+
oob = oob->next;
381+
}
382+
}
383+
365384
void ATCmdParser::abort()
366385
{
367386
_aborted = true;

0 commit comments

Comments
 (0)