summaryrefslogtreecommitdiff
path: root/esp8266
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-04-06 00:12:58 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-04-06 00:12:58 +0300
commit96eca22322e45aa8b6e7e611eabe4e5c6fb93c90 (patch)
tree406a1e68c15cbf04eadfe120de23ec800fd4d887 /esp8266
parente6a4d4e23c5e3d31436d3cebfabc894d5772c0d8 (diff)
esp8266: Make destination for vendor OS debug output soft-configurable.
Use esp.osdebug(None) to disable, or esp.osdebug(uart_id) to send output to a UART.
Diffstat (limited to 'esp8266')
-rw-r--r--esp8266/modesp.c13
-rw-r--r--esp8266/qstrdefsport.h1
-rw-r--r--esp8266/uart.c17
-rw-r--r--esp8266/uart.h1
4 files changed, 29 insertions, 3 deletions
diff --git a/esp8266/modesp.c b/esp8266/modesp.c
index e04a3b365..3a82cc1f2 100644
--- a/esp8266/modesp.c
+++ b/esp8266/modesp.c
@@ -35,6 +35,8 @@
#include "py/runtime.h"
#include "netutils.h"
#include "queue.h"
+#include "ets_sys.h"
+#include "uart.h"
#include "user_interface.h"
#include "espconn.h"
#include "spi_flash.h"
@@ -514,6 +516,16 @@ void error_check(bool status, const char *msg) {
}
}
+STATIC mp_obj_t esp_osdebug(mp_obj_t val) {
+ if (val == mp_const_none) {
+ uart_os_config(-1);
+ } else {
+ uart_os_config(mp_obj_get_int(val));
+ }
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_osdebug_obj, esp_osdebug);
+
STATIC mp_obj_t esp_sleep_type(mp_uint_t n_args, const mp_obj_t *args) {
if (n_args == 0) {
return mp_obj_new_int(wifi_get_sleep_type());
@@ -608,6 +620,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp_neopixel_write_obj, esp_neopixel_write_);
STATIC const mp_map_elem_t esp_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_esp) },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_osdebug), (mp_obj_t)&esp_osdebug_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_sleep_type), (mp_obj_t)&esp_sleep_type_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_deepsleep), (mp_obj_t)&esp_deepsleep_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_flash_id), (mp_obj_t)&esp_flash_id_obj },
diff --git a/esp8266/qstrdefsport.h b/esp8266/qstrdefsport.h
index 36e34e85a..12f72a3e2 100644
--- a/esp8266/qstrdefsport.h
+++ b/esp8266/qstrdefsport.h
@@ -58,6 +58,7 @@ Q(connect)
Q(disconnect)
Q(wifi_mode)
Q(phy_mode)
+Q(osdebug)
Q(sleep_type)
Q(deepsleep)
Q(adc)
diff --git a/esp8266/uart.c b/esp8266/uart.c
index 0d180aa55..f37193539 100644
--- a/esp8266/uart.c
+++ b/esp8266/uart.c
@@ -24,6 +24,9 @@
// UartDev is defined and initialized in rom code.
extern UartDevice UartDev;
+// the uart to which OS messages go; -1 to disable
+static int uart_os = UART_OS;
+
/* unused
// circular buffer for RX buffering
#define RX_BUF_SIZE (256)
@@ -134,15 +137,23 @@ void uart_flush(uint8 uart) {
*******************************************************************************/
static void ICACHE_FLASH_ATTR
uart_os_write_char(char c) {
+ if (uart_os == -1) {
+ return;
+ }
if (c == '\n') {
- uart_tx_one_char(UART_OS, '\r');
- uart_tx_one_char(UART_OS, '\n');
+ uart_tx_one_char(uart_os, '\r');
+ uart_tx_one_char(uart_os, '\n');
} else if (c == '\r') {
} else {
- uart_tx_one_char(UART_OS, c);
+ uart_tx_one_char(uart_os, c);
}
}
+void ICACHE_FLASH_ATTR
+uart_os_config(int uart) {
+ uart_os = uart;
+}
+
/******************************************************************************
* FunctionName : uart0_rx_intr_handler
* Description : Internal used function
diff --git a/esp8266/uart.h b/esp8266/uart.h
index ed0dcfb44..2f762db5a 100644
--- a/esp8266/uart.h
+++ b/esp8266/uart.h
@@ -93,5 +93,6 @@ void uart_init(UartBautRate uart0_br, UartBautRate uart1_br);
int uart0_rx(void);
void uart_tx_one_char(uint8 uart, uint8 TxChar);
void uart_flush(uint8 uart);
+void uart_os_config(int uart);
#endif // _INCLUDED_UART_H_