Merge pull request #12022 from anttiylitokola/master

Make ESP8266 compatible with bare metal profile
pull/12085/head
Martin Kojtal 2019-12-11 14:23:46 +01:00 committed by GitHub
commit 5c8d46f4e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 16 deletions

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
#if DEVICE_SERIAL && DEVICE_INTERRUPTIN && defined(MBED_CONF_EVENTS_PRESENT) && defined(MBED_CONF_NSAPI_PRESENT) && defined(MBED_CONF_RTOS_PRESENT)
#if DEVICE_SERIAL && DEVICE_INTERRUPTIN && defined(MBED_CONF_EVENTS_PRESENT) && defined(MBED_CONF_NSAPI_PRESENT) && defined(MBED_CONF_RTOS_API_PRESENT)
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
@ -57,7 +57,6 @@ ESP8266::ESP8266(PinName tx, PinName rx, bool debug, PinName rts, PinName cts)
_closed(false),
_error(false),
_busy(false),
_reset_check(_rmutex),
_reset_done(false),
_conn_status(NSAPI_STATUS_DISCONNECTED)
{
@ -272,14 +271,15 @@ bool ESP8266::reset(void)
continue;
}
_rmutex.lock();
while ((rtos::Kernel::get_ms_count() - start_time < ESP8266_BOOTTIME) && !_reset_done) {
while (!_reset_done) {
_process_oob(ESP8266_RECV_TIMEOUT, true); // UART mutex claimed -> need to check for OOBs ourselves
_reset_check.wait_for(100); // Arbitrary relatively short delay
if (_reset_done || (rtos::Kernel::get_ms_count() - start_time >= ESP8266_BOOTTIME)) {
break;
}
rtos::ThisThread::sleep_for(100);
}
done = _reset_done;
_rmutex.unlock();
if (done) {
break;
}
@ -1040,11 +1040,7 @@ void ESP8266::_oob_watchdog_reset()
void ESP8266::_oob_ready()
{
_rmutex.lock();
_reset_done = true;
_reset_check.notify_all();
_rmutex.unlock();
for (int i = 0; i < SOCKET_COUNT; i++) {
_sock_i[i].open = false;

View File

@ -17,7 +17,7 @@
#ifndef ESP8266_H
#define ESP8266_H
#if DEVICE_SERIAL && DEVICE_INTERRUPTIN && defined(MBED_CONF_EVENTS_PRESENT) && defined(MBED_CONF_NSAPI_PRESENT) && defined(MBED_CONF_RTOS_PRESENT)
#if DEVICE_SERIAL && DEVICE_INTERRUPTIN && defined(MBED_CONF_EVENTS_PRESENT) && defined(MBED_CONF_NSAPI_PRESENT) && defined(MBED_CONF_RTOS_API_PRESENT)
#include <stdint.h>
#include "drivers/UARTSerial.h"
@ -27,8 +27,8 @@
#include "platform/ATCmdParser.h"
#include "platform/Callback.h"
#include "platform/mbed_error.h"
#include "rtos/ConditionVariable.h"
#include "rtos/Mutex.h"
#include "rtos/ThisThread.h"
// Various timeouts for different ESP8266 operations
#ifndef ESP8266_CONNECT_TIMEOUT
@ -428,7 +428,6 @@ private:
PinName _serial_rts;
PinName _serial_cts;
rtos::Mutex _smutex; // Protect serial port access
rtos::Mutex _rmutex; // Reset protection
// AT Command Parser
mbed::ATCmdParser _parser;
@ -479,7 +478,6 @@ private:
bool _closed;
bool _error;
bool _busy;
rtos::ConditionVariable _reset_check;
bool _reset_done;
// Modem's address info

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
#if DEVICE_SERIAL && DEVICE_INTERRUPTIN && defined(MBED_CONF_EVENTS_PRESENT) && defined(MBED_CONF_NSAPI_PRESENT) && defined(MBED_CONF_RTOS_PRESENT)
#if DEVICE_SERIAL && DEVICE_INTERRUPTIN && defined(MBED_CONF_EVENTS_PRESENT) && defined(MBED_CONF_NSAPI_PRESENT) && defined(MBED_CONF_RTOS_API_PRESENT)
#include <string.h>
#include <stdint.h>
@ -64,7 +64,9 @@ ESP8266Interface::ESP8266Interface()
_pwr_pin(MBED_CONF_ESP8266_PWR),
_ap_sec(NSAPI_SECURITY_UNKNOWN),
_if_blocking(true),
#if MBED_CONF_RTOS_PRESENT
_if_connected(_cmutex),
#endif
_initialized(false),
_connect_retval(NSAPI_ERROR_OK),
_disconnect_retval(NSAPI_ERROR_OK),
@ -104,7 +106,9 @@ ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug, PinName r
_pwr_pin(pwr),
_ap_sec(NSAPI_SECURITY_UNKNOWN),
_if_blocking(true),
#if MBED_CONF_RTOS_PRESENT
_if_connected(_cmutex),
#endif
_initialized(false),
_connect_retval(NSAPI_ERROR_OK),
_disconnect_retval(NSAPI_ERROR_OK),
@ -267,7 +271,9 @@ void ESP8266Interface::_connect_async()
_esp.uart_enable_input(false);
_software_conn_stat = IFACE_STATUS_DISCONNECTED;
}
#if MBED_CONF_RTOS_PRESENT
_if_connected.notify_all();
#endif
} else {
// Postpone to give other stuff time to run
_connect_event_id = _global_event_queue->call_in(ESP8266_INTERFACE_CONNECT_INTERVAL_MS,
@ -329,10 +335,12 @@ int ESP8266Interface::connect()
"connect(): unable to add event to queue. Increase \"events.shared-eventsize\"\n");
}
#if MBED_CONF_RTOS_PRESENT
while (_if_blocking && (_conn_status_to_error() != NSAPI_ERROR_IS_CONNECTED)
&& (_connect_retval == NSAPI_ERROR_NO_CONNECTION)) {
_if_connected.wait();
}
#endif
_cmutex.unlock();
@ -418,7 +426,9 @@ void ESP8266Interface::_disconnect_async()
_power_off();
_software_conn_stat = IFACE_STATUS_DISCONNECTED;
#if MBED_CONF_RTOS_PRESENT
_if_connected.notify_all();
#endif
} else {
// Postpone to give other stuff time to run
@ -479,11 +489,13 @@ int ESP8266Interface::disconnect()
"disconnect(): unable to add event to queue. Increase \"events.shared-eventsize\"\n");
}
#if MBED_CONF_RTOS_PRESENT
while (_if_blocking
&& (_conn_status_to_error() != NSAPI_ERROR_NO_CONNECTION)
&& (_disconnect_retval != NSAPI_ERROR_OK)) {
_if_connected.wait();
}
#endif
_cmutex.unlock();
if (!_if_blocking) {

View File

@ -17,7 +17,7 @@
#ifndef ESP8266_INTERFACE_H
#define ESP8266_INTERFACE_H
#if DEVICE_SERIAL && DEVICE_INTERRUPTIN && defined(MBED_CONF_EVENTS_PRESENT) && defined(MBED_CONF_NSAPI_PRESENT) && defined(MBED_CONF_RTOS_PRESENT)
#if DEVICE_SERIAL && DEVICE_INTERRUPTIN && defined(MBED_CONF_EVENTS_PRESENT) && defined(MBED_CONF_NSAPI_PRESENT) && defined(MBED_CONF_RTOS_API_PRESENT)
#include "drivers/DigitalOut.h"
#include "drivers/Timer.h"
#include "ESP8266/ESP8266.h"
@ -30,7 +30,9 @@
#include "features/netsocket/WiFiAccessPoint.h"
#include "features/netsocket/WiFiInterface.h"
#include "platform/Callback.h"
#if MBED_CONF_RTOS_PRESENT
#include "rtos/ConditionVariable.h"
#endif
#include "rtos/Mutex.h"
#define ESP8266_SOCKET_COUNT 5
@ -452,7 +454,9 @@ private:
struct _channel_info _ch_info;
bool _if_blocking; // NetworkInterface, blocking or not
#if MBED_CONF_RTOS_PRESENT
rtos::ConditionVariable _if_connected;
#endif
// connect status reporting
nsapi_error_t _conn_status_to_error();