Skip to content

Commit 5c8d46f

Browse files
authored
Merge pull request #12022 from anttiylitokola/master
Make ESP8266 compatible with bare metal profile
2 parents 8fd8ea2 + 10687d6 commit 5c8d46f

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
#if DEVICE_SERIAL && DEVICE_INTERRUPTIN && defined(MBED_CONF_EVENTS_PRESENT) && defined(MBED_CONF_NSAPI_PRESENT) && defined(MBED_CONF_RTOS_PRESENT)
17+
#if DEVICE_SERIAL && DEVICE_INTERRUPTIN && defined(MBED_CONF_EVENTS_PRESENT) && defined(MBED_CONF_NSAPI_PRESENT) && defined(MBED_CONF_RTOS_API_PRESENT)
1818
#ifndef __STDC_FORMAT_MACROS
1919
#define __STDC_FORMAT_MACROS
2020
#endif
@@ -57,7 +57,6 @@ ESP8266::ESP8266(PinName tx, PinName rx, bool debug, PinName rts, PinName cts)
5757
_closed(false),
5858
_error(false),
5959
_busy(false),
60-
_reset_check(_rmutex),
6160
_reset_done(false),
6261
_conn_status(NSAPI_STATUS_DISCONNECTED)
6362
{
@@ -272,14 +271,15 @@ bool ESP8266::reset(void)
272271
continue;
273272
}
274273

275-
_rmutex.lock();
276-
while ((rtos::Kernel::get_ms_count() - start_time < ESP8266_BOOTTIME) && !_reset_done) {
274+
while (!_reset_done) {
277275
_process_oob(ESP8266_RECV_TIMEOUT, true); // UART mutex claimed -> need to check for OOBs ourselves
278-
_reset_check.wait_for(100); // Arbitrary relatively short delay
276+
if (_reset_done || (rtos::Kernel::get_ms_count() - start_time >= ESP8266_BOOTTIME)) {
277+
break;
278+
}
279+
rtos::ThisThread::sleep_for(100);
279280
}
280281

281282
done = _reset_done;
282-
_rmutex.unlock();
283283
if (done) {
284284
break;
285285
}
@@ -1040,11 +1040,7 @@ void ESP8266::_oob_watchdog_reset()
10401040

10411041
void ESP8266::_oob_ready()
10421042
{
1043-
1044-
_rmutex.lock();
10451043
_reset_done = true;
1046-
_reset_check.notify_all();
1047-
_rmutex.unlock();
10481044

10491045
for (int i = 0; i < SOCKET_COUNT; i++) {
10501046
_sock_i[i].open = false;

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#ifndef ESP8266_H
1818
#define ESP8266_H
1919

20-
#if DEVICE_SERIAL && DEVICE_INTERRUPTIN && defined(MBED_CONF_EVENTS_PRESENT) && defined(MBED_CONF_NSAPI_PRESENT) && defined(MBED_CONF_RTOS_PRESENT)
20+
#if DEVICE_SERIAL && DEVICE_INTERRUPTIN && defined(MBED_CONF_EVENTS_PRESENT) && defined(MBED_CONF_NSAPI_PRESENT) && defined(MBED_CONF_RTOS_API_PRESENT)
2121
#include <stdint.h>
2222

2323
#include "drivers/UARTSerial.h"
@@ -27,8 +27,8 @@
2727
#include "platform/ATCmdParser.h"
2828
#include "platform/Callback.h"
2929
#include "platform/mbed_error.h"
30-
#include "rtos/ConditionVariable.h"
3130
#include "rtos/Mutex.h"
31+
#include "rtos/ThisThread.h"
3232

3333
// Various timeouts for different ESP8266 operations
3434
#ifndef ESP8266_CONNECT_TIMEOUT
@@ -428,7 +428,6 @@ class ESP8266 {
428428
PinName _serial_rts;
429429
PinName _serial_cts;
430430
rtos::Mutex _smutex; // Protect serial port access
431-
rtos::Mutex _rmutex; // Reset protection
432431

433432
// AT Command Parser
434433
mbed::ATCmdParser _parser;
@@ -479,7 +478,6 @@ class ESP8266 {
479478
bool _closed;
480479
bool _error;
481480
bool _busy;
482-
rtos::ConditionVariable _reset_check;
483481
bool _reset_done;
484482

485483
// Modem's address info

components/wifi/esp8266-driver/ESP8266Interface.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
#if DEVICE_SERIAL && DEVICE_INTERRUPTIN && defined(MBED_CONF_EVENTS_PRESENT) && defined(MBED_CONF_NSAPI_PRESENT) && defined(MBED_CONF_RTOS_PRESENT)
17+
#if DEVICE_SERIAL && DEVICE_INTERRUPTIN && defined(MBED_CONF_EVENTS_PRESENT) && defined(MBED_CONF_NSAPI_PRESENT) && defined(MBED_CONF_RTOS_API_PRESENT)
1818

1919
#include <string.h>
2020
#include <stdint.h>
@@ -64,7 +64,9 @@ ESP8266Interface::ESP8266Interface()
6464
_pwr_pin(MBED_CONF_ESP8266_PWR),
6565
_ap_sec(NSAPI_SECURITY_UNKNOWN),
6666
_if_blocking(true),
67+
#if MBED_CONF_RTOS_PRESENT
6768
_if_connected(_cmutex),
69+
#endif
6870
_initialized(false),
6971
_connect_retval(NSAPI_ERROR_OK),
7072
_disconnect_retval(NSAPI_ERROR_OK),
@@ -104,7 +106,9 @@ ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug, PinName r
104106
_pwr_pin(pwr),
105107
_ap_sec(NSAPI_SECURITY_UNKNOWN),
106108
_if_blocking(true),
109+
#if MBED_CONF_RTOS_PRESENT
107110
_if_connected(_cmutex),
111+
#endif
108112
_initialized(false),
109113
_connect_retval(NSAPI_ERROR_OK),
110114
_disconnect_retval(NSAPI_ERROR_OK),
@@ -267,7 +271,9 @@ void ESP8266Interface::_connect_async()
267271
_esp.uart_enable_input(false);
268272
_software_conn_stat = IFACE_STATUS_DISCONNECTED;
269273
}
274+
#if MBED_CONF_RTOS_PRESENT
270275
_if_connected.notify_all();
276+
#endif
271277
} else {
272278
// Postpone to give other stuff time to run
273279
_connect_event_id = _global_event_queue->call_in(ESP8266_INTERFACE_CONNECT_INTERVAL_MS,
@@ -329,10 +335,12 @@ int ESP8266Interface::connect()
329335
"connect(): unable to add event to queue. Increase \"events.shared-eventsize\"\n");
330336
}
331337

338+
#if MBED_CONF_RTOS_PRESENT
332339
while (_if_blocking && (_conn_status_to_error() != NSAPI_ERROR_IS_CONNECTED)
333340
&& (_connect_retval == NSAPI_ERROR_NO_CONNECTION)) {
334341
_if_connected.wait();
335342
}
343+
#endif
336344

337345
_cmutex.unlock();
338346

@@ -418,7 +426,9 @@ void ESP8266Interface::_disconnect_async()
418426

419427
_power_off();
420428
_software_conn_stat = IFACE_STATUS_DISCONNECTED;
429+
#if MBED_CONF_RTOS_PRESENT
421430
_if_connected.notify_all();
431+
#endif
422432

423433
} else {
424434
// Postpone to give other stuff time to run
@@ -479,11 +489,13 @@ int ESP8266Interface::disconnect()
479489
"disconnect(): unable to add event to queue. Increase \"events.shared-eventsize\"\n");
480490
}
481491

492+
#if MBED_CONF_RTOS_PRESENT
482493
while (_if_blocking
483494
&& (_conn_status_to_error() != NSAPI_ERROR_NO_CONNECTION)
484495
&& (_disconnect_retval != NSAPI_ERROR_OK)) {
485496
_if_connected.wait();
486497
}
498+
#endif
487499

488500
_cmutex.unlock();
489501
if (!_if_blocking) {

components/wifi/esp8266-driver/ESP8266Interface.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#ifndef ESP8266_INTERFACE_H
1818
#define ESP8266_INTERFACE_H
1919

20-
#if DEVICE_SERIAL && DEVICE_INTERRUPTIN && defined(MBED_CONF_EVENTS_PRESENT) && defined(MBED_CONF_NSAPI_PRESENT) && defined(MBED_CONF_RTOS_PRESENT)
20+
#if DEVICE_SERIAL && DEVICE_INTERRUPTIN && defined(MBED_CONF_EVENTS_PRESENT) && defined(MBED_CONF_NSAPI_PRESENT) && defined(MBED_CONF_RTOS_API_PRESENT)
2121
#include "drivers/DigitalOut.h"
2222
#include "drivers/Timer.h"
2323
#include "ESP8266/ESP8266.h"
@@ -30,7 +30,9 @@
3030
#include "features/netsocket/WiFiAccessPoint.h"
3131
#include "features/netsocket/WiFiInterface.h"
3232
#include "platform/Callback.h"
33+
#if MBED_CONF_RTOS_PRESENT
3334
#include "rtos/ConditionVariable.h"
35+
#endif
3436
#include "rtos/Mutex.h"
3537

3638
#define ESP8266_SOCKET_COUNT 5
@@ -452,7 +454,9 @@ class ESP8266Interface : public NetworkStack, public WiFiInterface {
452454
struct _channel_info _ch_info;
453455

454456
bool _if_blocking; // NetworkInterface, blocking or not
457+
#if MBED_CONF_RTOS_PRESENT
455458
rtos::ConditionVariable _if_connected;
459+
#endif
456460

457461
// connect status reporting
458462
nsapi_error_t _conn_status_to_error();

0 commit comments

Comments
 (0)