add selection of uart1 to debug log

v2.1
Thorsten von Eicken 9 years ago
parent 9b6612135a
commit 65583e6af6
  1. 59
      esp-link/log.c
  2. 7
      esp-link/log.h
  3. 2
      esp-link/main.c
  4. 5
      html/log.html
  5. 3
      serial/uart.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; i<l; i++) uart0_write_char(buff[i]);
if (1)
for (int i=0; i<l; i++) uart_write_char(buff[i]);
if (1) // set to 0 to remove timestamps from log buffer to save some space
for (int i=0; i<l; i++) log_write(buff[i]);
log_newline = false;
}
if (c == '\n') log_newline = true;
// Uart output unless disabled
if (!log_no_uart) {
if (c == '\n') uart0_write_char('\r');
uart0_write_char(c);
if (c == '\n') uart_write_char('\r');
uart_write_char(c);
}
// Store in log buffer
if (c == '\n') log_write('\r');
@ -132,7 +128,7 @@ ajaxLog(HttpdConnData *connData) {
return HTTPD_CGI_DONE;
}
static char *dbg_mode[] = { "auto", "off", "on" };
static char *dbg_mode[] = { "auto", "off", "on u0", "on u1" };
int ICACHE_FLASH_ATTR
ajaxLogDbg(HttpdConnData *connData) {
@ -142,12 +138,13 @@ ajaxLogDbg(HttpdConnData *connData) {
len = httpdFindArg(connData->getArgs, "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) {

@ -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);

@ -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

@ -14,7 +14,8 @@
UART debug log:
<a id="dbg-auto" class="dbg-btn pure-button" href="#">auto</a>
<a id="dbg-off" class="dbg-btn pure-button" href="#">off</a>
<a id="dbg-on" class="dbg-btn pure-button" href="#">on</a>
<a id="dbg-on0" class="dbg-btn pure-button" href="#">on uart0</a>
<a id="dbg-on1" class="dbg-btn pure-button" href="#">on uart1</a>
</p>
</div>
<pre id="console" class="console" style="margin-top: 0px;"></pre>
@ -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); },

@ -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
}

Loading…
Cancel
Save