From 65583e6af6b91cfe5b5b8ad3cb7c7a52a0ad1c55 Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Sat, 14 Nov 2015 23:37:41 -0800 Subject: [PATCH] add selection of uart1 to debug log --- esp-link/log.c | 59 +++++++++++++++++++++++-------------------------- esp-link/log.h | 7 +++--- esp-link/main.c | 2 +- html/log.html | 5 +++-- serial/uart.c | 3 --- 5 files changed, 36 insertions(+), 40 deletions(-) diff --git a/esp-link/log.c b/esp-link/log.c index 1425cb3..d7035c0 100644 --- a/esp-link/log.c +++ b/esp-link/log.c @@ -6,6 +6,12 @@ #include "config.h" #include "log.h" +#ifdef LOG_DBG +#define DBG(format, ...) os_printf(format, ## __VA_ARGS__) +#else +#define DBG(format, ...) do { } while(0) +#endif + // Web log for the esp8266 to replace outputting to uart1. // The web log has a 1KB circular in-memory buffer which os_printf prints into and // the HTTP handler simply displays the buffer content on a web page. @@ -18,30 +24,31 @@ static int log_pos; static bool log_no_uart; // start out printing to uart static bool log_newline; // at start of a new line -#define uart0_write_char uart1_write_char +// write to the uart designated for logging +static void uart_write_char(char c) { + if (flashConfig.log_mode == LOG_MODE_ON1) + uart1_write_char(c); + else + uart0_write_char(c); +} // called from wifi reset timer to turn UART on when we loose wifi and back off // when we connect to wifi AP. Here this is gated by the flash setting void ICACHE_FLASH_ATTR log_uart(bool enable) { - if (!enable && !log_no_uart && flashConfig.log_mode != LOG_MODE_ON) { + if (!enable && !log_no_uart && flashConfig.log_mode < LOG_MODE_ON0) { // we're asked to turn uart off, and uart is on, and the flash setting isn't always-on -#if 1 -#ifdef LOG_DBG - os_printf("Turning OFF uart log\n"); -#endif + DBG("Turning OFF uart log\n"); os_delay_us(4*1000L); // time for uart to flush log_no_uart = !enable; -#endif } else if (enable && log_no_uart && flashConfig.log_mode != LOG_MODE_OFF) { // we're asked to turn uart on, and uart is off, and the flash setting isn't always-off log_no_uart = !enable; -#ifdef LOG_DBG - os_printf("Turning ON uart log\n"); -#endif + DBG("Turning ON uart log\n"); } } +// write a character into the log buffer static void ICACHE_FLASH_ATTR log_write(char c) { log_buf[log_wr] = c; @@ -52,18 +59,7 @@ log_write(char c) { } } -#if 0 -static char ICACHE_FLASH_ATTR -log_read(void) { - char c = 0; - if (log_rd != log_wr) { - c = log_buf[log_rd]; - log_rd = (log_rd+1) % BUF_MAX; - } - return c; -} -#endif - +// write a character to the log buffer and the uart, and handle newlines specially static void ICACHE_FLASH_ATTR log_write_char(char c) { // log timestamp @@ -71,16 +67,16 @@ log_write_char(char c) { char buff[16]; int l = os_sprintf(buff, "%6d> ", (system_get_time()/1000)%1000000); if (!log_no_uart) - for (int i=0; igetArgs, "mode", buff, sizeof(buff)); if (len > 0) { int8_t mode = -1; - if (os_strcmp(buff, "auto") == 0) mode = LOG_MODE_AUTO; - if (os_strcmp(buff, "off") == 0) mode = LOG_MODE_OFF; - if (os_strcmp(buff, "on") == 0) mode = LOG_MODE_ON; + if (os_strcmp(buff, "auto") == 0) mode = LOG_MODE_AUTO; + if (os_strcmp(buff, "off") == 0) mode = LOG_MODE_OFF; + if (os_strcmp(buff, "on0") == 0) mode = LOG_MODE_ON0; + if (os_strcmp(buff, "on1") == 0) mode = LOG_MODE_ON1; if (mode >= 0) { flashConfig.log_mode = mode; - if (mode != LOG_MODE_AUTO) log_uart(mode == LOG_MODE_ON); + if (mode != LOG_MODE_AUTO) log_uart(mode >= LOG_MODE_ON0); status = configSave() ? 200 : 400; } } else if (connData->requestType == HTTPD_METHOD_GET) { diff --git a/esp-link/log.h b/esp-link/log.h index bf2c763..3b7e03a 100644 --- a/esp-link/log.h +++ b/esp-link/log.h @@ -3,9 +3,10 @@ #include "httpd.h" -#define LOG_MODE_AUTO 0 -#define LOG_MODE_OFF 1 -#define LOG_MODE_ON 2 +#define LOG_MODE_AUTO 0 // start by logging to uart0, turn aff after we get an IP +#define LOG_MODE_OFF 1 // always off +#define LOG_MODE_ON0 2 // always log to uart0 +#define LOG_MODE_ON1 3 // always log to uart1 void logInit(void); void log_uart(bool enable); diff --git a/esp-link/main.c b/esp-link/main.c index 8c00bae..1697d2b 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -164,7 +164,7 @@ void user_init(void) { bool restoreOk = configRestore(); // init gpio pin registers gpio_init(); - gpio_output_set(0, 0, 0, (1<<15)); // some people tie it GND, gotta ensure it's disabled + gpio_output_set(0, 0, 0, (1<<15)); // some people tie it to GND, gotta ensure it's disabled // init UART uart_init(flashConfig.baud_rate, 115200); logInit(); // must come after init of uart diff --git a/html/log.html b/html/log.html index 46ec785..cfc4104 100644 --- a/html/log.html +++ b/html/log.html @@ -14,7 +14,8 @@ UART debug log: auto off - on + on uart0 + on uart1


@@ -33,7 +34,7 @@
       fetchText(100, false);
     });
 
-    ["auto", "off", "on"].forEach(function(mode) {
+    ["auto", "off", "on0", "on1"].forEach(function(mode) {
       bnd($('#dbg-'+mode), "click", function(el) {
         ajaxJsonSpin('POST', "/log/dbg?mode="+mode,
           function(data) { showNotification("UART mode " + data.mode); showDbgMode(data.mode); },
diff --git a/serial/uart.c b/serial/uart.c
index ec356d0..5358cf1 100644
--- a/serial/uart.c
+++ b/serial/uart.c
@@ -52,16 +52,13 @@ uart_config(uint8 uart_no)
 {
   if (uart_no == UART1) {
     PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);
-    //PIN_PULLDWN_DIS(PERIPHS_IO_MUX_GPIO2_U);
     PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO2_U);
   } else {
     /* rcv_buff size is 0x100 */
     ETS_UART_INTR_ATTACH(uart0_rx_intr_handler,  &(UartDev.rcv_buff));
     PIN_PULLUP_DIS (PERIPHS_IO_MUX_U0TXD_U);
-    //PIN_PULLDWN_DIS(PERIPHS_IO_MUX_U0TXD_U);
     PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD);
     PIN_PULLUP_DIS (PERIPHS_IO_MUX_U0RXD_U);
-    //PIN_PULLDWN_DIS(PERIPHS_IO_MUX_U0RXD_U);
     PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, 0); // FUNC_U0RXD==0
   }