From dbab746e3c887fd0ec41af9a089053a85fcc2431 Mon Sep 17 00:00:00 2001 From: Alastair D'Silva Date: Mon, 11 Apr 2016 20:46:38 +1000 Subject: [PATCH 01/15] Add support for the TX_ENABLE signal for RS-485 trancievers --- esp-link/cgipins.c | 16 ++++++--- esp-link/config.h | 1 + esp-link/main.c | 5 ++- html/home.html | 5 +++ html/ui.js | 16 +++++---- serial/serbridge.c | 15 ++++++-- serial/uart.c | 89 ++++++++++++++++++++++++++++++++++++++++++++-- serial/uart.h | 4 ++- 8 files changed, 131 insertions(+), 20 deletions(-) diff --git a/esp-link/cgipins.c b/esp-link/cgipins.c index b763d12..7880195 100644 --- a/esp-link/cgipins.c +++ b/esp-link/cgipins.c @@ -32,9 +32,10 @@ int ICACHE_FLASH_ATTR cgiPinsGet(HttpdConnData *connData) { int len; len = os_sprintf(buff, - "{ \"reset\":%d, \"isp\":%d, \"conn\":%d, \"ser\":%d, \"swap\":%d, \"rxpup\":%d }", + "{ \"reset\":%d, \"isp\":%d, \"conn\":%d, \"ser\":%d, \"swap\":%d, \"rxpup\":%d, \"uart0_tx_enable\":%d }", flashConfig.reset_pin, flashConfig.isp_pin, flashConfig.conn_led_pin, - flashConfig.ser_led_pin, !!flashConfig.swap_uart, !!flashConfig.rx_pullup); + flashConfig.ser_led_pin, !!flashConfig.swap_uart, !!flashConfig.rx_pullup, + flashConfig.uart0_tx_enable_pin); jsonHeader(connData, 200); httpdSend(connData, buff, len); @@ -48,7 +49,7 @@ int ICACHE_FLASH_ATTR cgiPinsSet(HttpdConnData *connData) { } int8_t ok = 0; - int8_t reset, isp, conn, ser; + int8_t reset, isp, conn, ser, uart0_tx_enable; uint8_t swap, rxpup; ok |= getInt8Arg(connData, "reset", &reset); ok |= getInt8Arg(connData, "isp", &isp); @@ -56,6 +57,7 @@ int ICACHE_FLASH_ATTR cgiPinsSet(HttpdConnData *connData) { ok |= getInt8Arg(connData, "ser", &ser); ok |= getBoolArg(connData, "swap", &swap); ok |= getBoolArg(connData, "rxpup", &rxpup); + ok |= getInt8Arg(connData, "uart0_tx_enable", &uart0_tx_enable); if (ok < 0) return HTTPD_CGI_DONE; char *coll; @@ -75,6 +77,10 @@ int ICACHE_FLASH_ATTR cgiPinsSet(HttpdConnData *connData) { if (pins & (1<= 0) { + if (pins & (1< #include "httpd.h" #include "httpdespfs.h" @@ -110,6 +112,7 @@ void user_rf_pre_init(void) { // Main routine to initialize esp-link. void user_init(void) { + system_timer_reinit(); // get the flash config so we know how to init things //configWipe(); // uncomment to reset the config for testing purposes bool restoreOk = configRestore(); @@ -117,7 +120,7 @@ void user_init(void) { gpio_init(); 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); + uart_init(flashConfig.baud_rate, flashConfig.uart0_tx_enable_pin, 115200); logInit(); // must come after init of uart // Say hello (leave some time to cause break in TX after boot loader's msg os_delay_us(10000L); diff --git a/html/home.html b/html/home.html index c977c74..bf8392d 100644 --- a/html/home.html +++ b/html/home.html @@ -76,6 +76,11 @@ +
+ + + +
diff --git a/html/ui.js b/html/ui.js index aa66f69..9b8637c 100644 --- a/html/ui.js +++ b/html/ui.js @@ -393,12 +393,12 @@ function showNotification(text) { //===== GPIO Pin mux card var pinPresets = { - // array: reset, isp, conn, ser, swap, rxpup - "esp-01": [ 0, -1, 2, -1, 0, 1 ], - "esp-12": [ 12, 14, 0, 2, 0, 1 ], - "esp-12 swap": [ 1, 3, 0, 2, 1, 1 ], - "esp-bridge": [ 12, 13, 0, 14, 0, 0 ], - "wifi-link-12": [ 1, 3, 0, 2, 1, 0 ], + // array: reset, isp, conn, ser, swap, rxpup, uart0_tx_enable + "esp-01": [ 0, -1, 2, -1, 0, 1, -1 ], + "esp-12": [ 12, 14, 0, 2, 0, 1, -1 ], + "esp-12 swap": [ 1, 3, 0, 2, 1, 1, -1 ], + "esp-bridge": [ 12, 13, 0, 14, 0, 0, -1 ], + "wifi-link-12": [ 1, 3, 0, 2, 1, 0, -1 ], }; function createPresets(sel) { @@ -418,6 +418,7 @@ function createPresets(sel) { setPP("ser", pp[3]); setPP("swap", pp[4]); $("#pin-rxpup").checked = !!pp[5]; + setPP("uart0-tx-enable", pp[6]); sel.value = 0; }; @@ -453,6 +454,7 @@ function displayPins(resp) { createSelectForPin("ser", resp["ser"]); $("#pin-swap").value = resp["swap"]; $("#pin-rxpup").checked = !!resp["rxpup"]; + createSelectForPin("uart0_tx_enable", resp["uart0_tx_enable"]); createPresets($("#pin-preset")); $("#pin-spinner").setAttribute("hidden", ""); @@ -469,7 +471,7 @@ function setPins(ev) { ev.preventDefault(); var url = "/pins"; var sep = "?"; - ["reset", "isp", "conn", "ser", "swap"].forEach(function(p) { + ["reset", "isp", "conn", "ser", "swap", "uart0_tx_enable"].forEach(function(p) { url += sep + p + "=" + $("#pin-"+p).value; sep = "&"; }); diff --git a/serial/serbridge.c b/serial/serbridge.c index 1e82e3d..5b8b53b 100644 --- a/serial/serbridge.c +++ b/serial/serbridge.c @@ -17,7 +17,7 @@ static struct espconn serbridgeConn1; // plain bridging port static struct espconn serbridgeConn2; // programming port static esp_tcp serbridgeTcp1, serbridgeTcp2; -static int8_t mcu_reset_pin, mcu_isp_pin; +static int8_t mcu_reset_pin, mcu_isp_pin, uart0_tx_enable_pin; extern uint8_t slip_disabled; // disable slip to allow flashing of attached MCU @@ -439,9 +439,10 @@ serbridgeInitPins() { mcu_reset_pin = flashConfig.reset_pin; mcu_isp_pin = flashConfig.isp_pin; + uart0_tx_enable_pin = flashConfig.uart0_tx_enable_pin; #ifdef SERBR_DBG - os_printf("Serbridge pins: reset=%d isp=%d swap=%d\n", - mcu_reset_pin, mcu_isp_pin, flashConfig.swap_uart); + os_printf("Serbridge pins: reset=%d isp=%d tx_enable=%d swap=%d\n", + mcu_reset_pin, mcu_isp_pin, uart0_tx_enable_pin, flashConfig.swap_uart); #endif if (flashConfig.swap_uart) { @@ -463,9 +464,17 @@ serbridgeInitPins() // set both pins to 1 before turning them on so we don't cause a reset if (mcu_isp_pin >= 0) GPIO_OUTPUT_SET(mcu_isp_pin, 1); if (mcu_reset_pin >= 0) GPIO_OUTPUT_SET(mcu_reset_pin, 1); + // set TX_ENABLE to 0 so we start up listening + if (mcu_reset_pin >= 0) GPIO_OUTPUT_SET(uart0_tx_enable_pin, 0); // switch pin mux to make these pins GPIO pins if (mcu_reset_pin >= 0) makeGpio(mcu_reset_pin); if (mcu_isp_pin >= 0) makeGpio(mcu_isp_pin); + if (uart0_tx_enable_pin >= 0) { + makeGpio(uart0_tx_enable_pin); + uart0_set_tx_enable_pin(uart0_tx_enable_pin); + } + + } // Start transparent serial bridge TCP server on specified port (typ. 23) diff --git a/serial/uart.c b/serial/uart.c index f7f07fa..206006c 100644 --- a/serial/uart.c +++ b/serial/uart.c @@ -17,9 +17,11 @@ * ---------------------------------------------------------------------------- * Heavily modified and enhanced by Thorsten von Eicken in 2015 */ +#define USE_US_TIMER #include "esp8266.h" #include "task.h" #include "uart.h" +#include #ifdef UART_DBG #define DBG_UART(format, ...) os_printf(format, ## __VA_ARGS__) @@ -28,6 +30,7 @@ #endif LOCAL uint8_t uart_recvTaskNum; +LOCAL int8_t uart0_tx_enable_pin; // UartDev is defined and initialized in rom code. extern UartDevice UartDev; @@ -36,6 +39,52 @@ static UartRecv_cb uart_recv_cb[4]; static void uart0_rx_intr_handler(void *para); +/****************************************************************************** + * FunctionName : set_tx_enable_pin + * Description : Set which pin to use for RS-485 TX_ENABLE + * Parameters : pin, the pin to use + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +uart0_set_tx_enable_pin(int8_t pin) { + uart0_tx_enable_pin = pin; +} + +/****************************************************************************** + * FunctionName : tx_enable + * Description : Internal used function + * Set the TX_ENABLE line for RS-485 communications + * Parameters : state, true if the TX_ENABLE line should be asserted high + * Returns : NONE +*******************************************************************************/ +static void ICACHE_FLASH_ATTR +tx_enable(bool state) +{ + if (uart0_tx_enable_pin >= 0) { +#ifdef SERBR_DBG + os_printf("TX_ENABLE gpio%d state=%d\n", uart0_tx_enable_pin, (int)state); +#endif + GPIO_OUTPUT_SET(uart0_tx_enable_pin, (state) ? 1 : 0); + } +#ifdef SERBR_DBG + else { os_printf("TX Enable: no pin\n"); } +#endif +} + +/****************************************************************************** + * FunctionName : tx_completed_interrupt + * Description : Internal used function + * Set the TX enable line low, after the UART has completed tranmission + * Parameters : unused unused + * Returns : NONE +*******************************************************************************/ +static void ICACHE_FLASH_ATTR +tx_completed_interrupt(void *arg) +{ + tx_enable(false); +} + + /****************************************************************************** * FunctionName : uart_config * Description : Internal used function @@ -81,12 +130,19 @@ uart_config(uint8 uart_no) // to set the threshold here... // We do not enable framing error interrupts 'cause they tend to cause an interrupt avalanche // and instead just poll for them when we get a std RX interrupt. + + uint32_t tx_empty_bits = 0; + if (uart0_tx_enable_pin >= 0) { + tx_empty_bits = (0 & UART_TXFIFO_EMPTY_THRHD) << UART_TXFIFO_EMPTY_THRHD_S | UART_TXFIFO_EMPTY_INT_ENA; + } WRITE_PERI_REG(UART_CONF1(uart_no), ((80 & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S) | ((100 & UART_RX_FLOW_THRHD) << UART_RX_FLOW_THRHD_S) | UART_RX_FLOW_EN | (4 & UART_RX_TOUT_THRHD) << UART_RX_TOUT_THRHD_S | - UART_RX_TOUT_EN); + UART_RX_TOUT_EN) | + tx_empty_bits + ; SET_PERI_REG_MASK(UART_INT_ENA(uart_no), UART_RXFIFO_FULL_INT_ENA | UART_RXFIFO_TOUT_INT_ENA); } else { WRITE_PERI_REG(UART_CONF1(uart_no), @@ -97,6 +153,9 @@ uart_config(uint8 uart_no) WRITE_PERI_REG(UART_INT_CLR(uart_no), 0xffff); } +os_timer_t uart_tx_enable_timer; +bool uart_tx_enable_timer_inited = false; + /****************************************************************************** * FunctionName : uart1_tx_one_char * Description : Internal used function @@ -110,6 +169,16 @@ uart_tx_one_char(uint8 uart, uint8 c) //Wait until there is room in the FIFO while (((READ_PERI_REG(UART_STATUS(uart))>>UART_TXFIFO_CNT_S)&UART_TXFIFO_CNT)>=100) ; //Send the character + if (UART0 == uart) { + if (uart_tx_enable_timer_inited) { + // If a tx_completed_interrupt has already been scheduled, cancel it before it fires during our transmission + os_timer_disarm(&uart_tx_enable_timer); + } else { + os_timer_setfn(&uart_tx_enable_timer, tx_completed_interrupt, NULL); + } + + tx_enable(true); + } WRITE_PERI_REG(UART_FIFO(uart), c); return OK; } @@ -168,6 +237,7 @@ uart0_sendStr(const char *str) } static uint32 last_frm_err; // time in us when last framing error message was printed +static int uart0_baud_rate = 0; // The baud rate for uart0 /****************************************************************************** * FunctionName : uart0_rx_intr_handler @@ -206,6 +276,12 @@ uart0_rx_intr_handler(void *para) //DBG_UART("stat:%02X",*(uint8 *)UART_INT_ENA(uart_no)); ETS_UART_INTR_DISABLE(); post_usr_task(uart_recvTaskNum, 0); + } else if (UART_TXFIFO_EMPTY_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_TXFIFO_EMPTY_INT_ST)) { + // TX Queue is empty, disable the TX_ENABLE line once the transmission is complete + if (0 != uart0_baud_rate) { + int tx_char_time = 8 * 1000000 / uart0_baud_rate; // assumes 8 bits per character + os_timer_arm_us(&uart_tx_enable_timer, tx_char_time, false); + } } } @@ -255,6 +331,7 @@ done: void ICACHE_FLASH_ATTR uart0_baud(int rate) { + uart0_baud_rate = rate; os_printf("UART %d baud\n", rate); uart_div_modify(UART0, UART_CLK_FREQ / rate); } @@ -263,13 +340,19 @@ uart0_baud(int rate) { * FunctionName : uart_init * Description : user interface for init uart * Parameters : UartBautRate uart0_br - uart0 bautrate + * uart0TxEnablePin * UartBautRate uart1_br - uart1 bautrate * Returns : NONE *******************************************************************************/ void ICACHE_FLASH_ATTR -uart_init(UartBautRate uart0_br, UartBautRate uart1_br) +uart_init(UartBautRate uart0_br, int8_t uart0TxEnablePin, UartBautRate uart1_br) { + if (uart0TxEnablePin >= 0) { + uart0_set_tx_enable_pin(uart0TxEnablePin); + } + // rom use 74880 baut_rate, here reinitialize + uart0_baud_rate = (int)uart0_br; UartDev.baut_rate = uart0_br; uart_config(UART0); UartDev.baut_rate = uart1_br; @@ -298,7 +381,7 @@ uart_add_recv_cb(UartRecv_cb cb) { void ICACHE_FLASH_ATTR uart_reattach() { - uart_init(BIT_RATE_74880, BIT_RATE_74880); + uart_init(BIT_RATE_74880, -1, BIT_RATE_74880); // ETS_UART_INTR_ATTACH(uart_rx_intr_handler_ssc, &(UartDev.rcv_buff)); // ETS_UART_INTR_ENABLE(); } diff --git a/serial/uart.h b/serial/uart.h index 24fb2df..82880ee 100644 --- a/serial/uart.h +++ b/serial/uart.h @@ -8,7 +8,7 @@ typedef void (*UartRecv_cb)(char *buf, short len); // Initialize UARTs to the provided baud rates (115200 recommended). This also makes the os_printf // calls use uart1 for output (for debugging purposes) -void uart_init(UartBautRate uart0_br, UartBautRate uart1_br); +void uart_init(UartBautRate uart0_br, int8_t uart0TxEnablePin, UartBautRate uart1_br); // Transmit a buffer of characters on UART0 void uart0_tx_buffer(char *buf, uint16 len); @@ -28,4 +28,6 @@ uint16_t uart0_rx_poll(char *buff, uint16_t nchars, uint32_t timeout_us); void uart0_baud(int rate); +void uart0_set_tx_enable_pin(int8_t pin); + #endif /* __UART_H__ */ From e8f569dc5f589bd6ffcbac13a20136d503ead9b0 Mon Sep 17 00:00:00 2001 From: Alastair D'Silva Date: Mon, 11 Apr 2016 21:09:03 +1000 Subject: [PATCH 02/15] Use microsecond timer for heap use as the timer is in microsecond mode --- esp-link/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp-link/main.c b/esp-link/main.c index dbb4381..fcbfabb 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -143,7 +143,7 @@ void user_init(void) { #ifdef SHOW_HEAP_USE os_timer_disarm(&prHeapTimer); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); - os_timer_arm(&prHeapTimer, 10000, 1); + os_timer_arm_us(&prHeapTimer, 10 * 1000000, 1); #endif struct rst_info *rst_info = system_get_rst_info(); From 19c56c80c80885f12a325b5afaccf3c04ee94018 Mon Sep 17 00:00:00 2001 From: Alastair D'Silva Date: Mon, 11 Apr 2016 21:33:51 +1000 Subject: [PATCH 03/15] Update all timer instances to microsecond timers --- esp-link/cgiflash.c | 5 +++-- esp-link/cgioptiboot.c | 6 ++++-- esp-link/cgiservices.c | 14 ++++++++------ esp-link/cgiwifi.c | 20 +++++++++++--------- esp-link/status.c | 10 ++++++---- mqtt/mqtt.c | 4 +++- serial/serled.c | 4 +++- syslog/syslog.c | 4 +++- 8 files changed, 41 insertions(+), 26 deletions(-) diff --git a/esp-link/cgiflash.c b/esp-link/cgiflash.c index 4b9277d..f909e28 100644 --- a/esp-link/cgiflash.c +++ b/esp-link/cgiflash.c @@ -13,6 +13,7 @@ Some flash handling cgi routines. Used for reading the existing flash and updati * ---------------------------------------------------------------------------- */ +#define USE_US_TIMER #include #include @@ -181,7 +182,7 @@ int ICACHE_FLASH_ATTR cgiRebootFirmware(HttpdConnData *connData) { system_upgrade_flag_set(UPGRADE_FLAG_FINISH); os_timer_disarm(&flash_reboot_timer); os_timer_setfn(&flash_reboot_timer, (os_timer_func_t *)system_upgrade_reboot, NULL); - os_timer_arm(&flash_reboot_timer, 2000, 1); + os_timer_arm_us(&flash_reboot_timer, 2 * 1000000, 1); return HTTPD_CGI_DONE; } @@ -195,6 +196,6 @@ int ICACHE_FLASH_ATTR cgiReset(HttpdConnData *connData) { // Schedule a reboot os_timer_disarm(&flash_reboot_timer); os_timer_setfn(&flash_reboot_timer, (os_timer_func_t *)system_restart, NULL); - os_timer_arm(&flash_reboot_timer, 2000, 1); + os_timer_arm_us(&flash_reboot_timer, 2 * 1000000, 1); return HTTPD_CGI_DONE; } diff --git a/esp-link/cgioptiboot.c b/esp-link/cgioptiboot.c index ed87d0e..ecaa242 100644 --- a/esp-link/cgioptiboot.c +++ b/esp-link/cgioptiboot.c @@ -1,5 +1,7 @@ // Copyright (c) 2015 by Thorsten von Eicken, see LICENSE.txt in the esp-link repo +#define USE_US_TIMER + #include #include #include "cgi.h" @@ -140,7 +142,7 @@ int ICACHE_FLASH_ATTR cgiOptibootSync(HttpdConnData *connData) { // start sync timer os_timer_disarm(&optibootTimer); os_timer_setfn(&optibootTimer, optibootTimerCB, NULL); - os_timer_arm(&optibootTimer, INIT_DELAY, 0); + os_timer_arm_us(&optibootTimer, INIT_DELAY * 1000, 0); // respond with optimistic OK noCacheHeaders(connData, 204); @@ -491,7 +493,7 @@ static bool ICACHE_FLASH_ATTR programPage(void) { static void ICACHE_FLASH_ATTR armTimer(uint32_t ms) { os_timer_disarm(&optibootTimer); - os_timer_arm(&optibootTimer, ms, 0); + os_timer_arm_us(&optibootTimer, ms * 1000, 0); } static int baudRates[] = { 0, 9600, 57600, 115200 }; diff --git a/esp-link/cgiservices.c b/esp-link/cgiservices.c index 6b3f553..e284b9e 100644 --- a/esp-link/cgiservices.c +++ b/esp-link/cgiservices.c @@ -1,3 +1,5 @@ +#define USE_US_TIMER + #include #include "cgiwifi.h" #include "cgi.h" @@ -36,7 +38,7 @@ int ICACHE_FLASH_ATTR cgiSystemSet(HttpdConnData *connData) { // schedule hostname change-over os_timer_disarm(&reassTimer); os_timer_setfn(&reassTimer, configWifiIP, NULL); - os_timer_arm(&reassTimer, 1000, 0); // 1 second for the response of this request to make it + os_timer_arm_us(&reassTimer, 1 * 1000000, 0); // 1 second for the response of this request to make it } if (configSave()) { @@ -92,10 +94,10 @@ int ICACHE_FLASH_ATTR cgiSystemInfo(HttpdConnData *connData) { } void ICACHE_FLASH_ATTR cgiServicesSNTPInit() { - if (flashConfig.sntp_server[0] != '\0') { + if (flashConfig.sntp_server[0] != '\0') { sntp_stop(); if (true == sntp_set_timezone(flashConfig.timezone_offset)) { - sntp_setservername(0, flashConfig.sntp_server); + sntp_setservername(0, flashConfig.sntp_server); sntp_init(); } DBG("SNTP timesource set to %s with offset %d\n", flashConfig.sntp_server, flashConfig.timezone_offset); @@ -107,7 +109,7 @@ int ICACHE_FLASH_ATTR cgiServicesInfo(HttpdConnData *connData) { if (connData->conn == NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. - os_sprintf(buff, + os_sprintf(buff, "{ " "\"syslog_host\": \"%s\", " "\"syslog_minheap\": %d, " @@ -118,7 +120,7 @@ int ICACHE_FLASH_ATTR cgiServicesInfo(HttpdConnData *connData) { "\"sntp_server\": \"%s\", " "\"mdns_enable\": \"%s\", " "\"mdns_servername\": \"%s\"" - " }", + " }", flashConfig.syslog_host, flashConfig.syslog_minheap, flashConfig.syslog_filter, @@ -168,7 +170,7 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) { int8_t mdns = 0; mdns |= getBoolArg(connData, "mdns_enable", &flashConfig.mdns_enable); if (mdns < 0) return HTTPD_CGI_DONE; - + if (mdns > 0) { if (flashConfig.mdns_enable){ DBG("Services: MDNS Enabled\n"); diff --git a/esp-link/cgiwifi.c b/esp-link/cgiwifi.c index 6b88167..2be8b02 100644 --- a/esp-link/cgiwifi.c +++ b/esp-link/cgiwifi.c @@ -13,6 +13,8 @@ Cgi/template routines for the /wifi url. * ---------------------------------------------------------------------------- */ +#define USE_US_TIMER + #include #include "cgiwifi.h" #include "cgi.h" @@ -222,7 +224,7 @@ static int ICACHE_FLASH_ATTR cgiWiFiStartScan(HttpdConnData *connData) { cgiWifiAps.scanInProgress = 1; os_timer_disarm(&scanTimer); os_timer_setfn(&scanTimer, scanStartCb, NULL); - os_timer_arm(&scanTimer, 200, 0); + os_timer_arm_us(&scanTimer, 200000, 0); } return HTTPD_CGI_DONE; } @@ -314,7 +316,7 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) { // We're happily connected, go to STA mode DBG("Wifi got IP. Going into STA mode..\n"); wifi_set_opmode(1); - os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); // check one more time after switching to STA-only + os_timer_arm_us(&resetTimer, RESET_TIMEOUT * 1000, 0); // check one more time after switching to STA-only #endif } log_uart(false); @@ -328,7 +330,7 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) { } log_uart(true); DBG("Enabling/continuing uart log\n"); - os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); + os_timer_arm_us(&resetTimer, RESET_TIMEOUT * 1000, 0); } } @@ -347,7 +349,7 @@ static void ICACHE_FLASH_ATTR reassTimerCb(void *arg) { // IP address os_timer_disarm(&resetTimer); os_timer_setfn(&resetTimer, resetTimerCb, NULL); - os_timer_arm(&resetTimer, 4*RESET_TIMEOUT, 0); + os_timer_arm_us(&resetTimer, 4*RESET_TIMEOUT * 1000, 0); } // This cgi uses the routines above to connect to a specific access point with the @@ -376,7 +378,7 @@ int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) { //Schedule disconnect/connect os_timer_disarm(&reassTimer); os_timer_setfn(&reassTimer, reassTimerCb, NULL); - os_timer_arm(&reassTimer, 1000, 0); // 1 second for the response of this request to make it + os_timer_arm_us(&reassTimer, 1 * 1000000, 0); // 1 second for the response of this request to make it jsonHeader(connData, 200); } else { jsonHeader(connData, 400); @@ -500,7 +502,7 @@ int ICACHE_FLASH_ATTR cgiWiFiSpecial(HttpdConnData *connData) { // schedule change-over os_timer_disarm(&reassTimer); os_timer_setfn(&reassTimer, configWifiIP, NULL); - os_timer_arm(&reassTimer, 1000, 0); // 1 second for the response of this request to make it + os_timer_arm_us(&reassTimer, 1 * 1000000, 0); // 1 second for the response of this request to make it // return redirect info jsonHeader(connData, 200); httpdSend(connData, url, -1); @@ -669,7 +671,7 @@ int ICACHE_FLASH_ATTR cgiWiFiSetMode(HttpdConnData *connData) { wifi_station_connect(); os_timer_disarm(&resetTimer); os_timer_setfn(&resetTimer, resetTimerCb, NULL); - os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); + os_timer_arm_us(&resetTimer, RESET_TIMEOUT * 1000, 0); } if(previous_mode == 1){ // moving to AP or STA+AP from STA, so softap config call needed @@ -784,7 +786,7 @@ int ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData) { // Reset into AP-only mode sooner. os_timer_disarm(&resetTimer); os_timer_setfn(&resetTimer, resetTimerCb, NULL); - os_timer_arm(&resetTimer, 1000, 0); + os_timer_arm_us(&resetTimer, 1 * 1000000, 0); } } #endif @@ -926,5 +928,5 @@ void ICACHE_FLASH_ATTR wifiInit() { // check on the wifi in a few seconds to see whether we need to switch mode os_timer_disarm(&resetTimer); os_timer_setfn(&resetTimer, resetTimerCb, NULL); - os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); + os_timer_arm_us(&resetTimer, RESET_TIMEOUT * 1000, 0); } diff --git a/esp-link/status.c b/esp-link/status.c index 6905850..ef8813d 100644 --- a/esp-link/status.c +++ b/esp-link/status.c @@ -1,5 +1,7 @@ // Copyright 2015 by Thorsten von Eicken, see LICENSE.txt +#define USE_US_TIMER + #include #include "config.h" #include "serled.h" @@ -92,7 +94,7 @@ static void ICACHE_FLASH_ATTR ledTimerCb(void *v) { } setLed(ledState); - os_timer_arm(&ledTimer, time, 0); + os_timer_arm_us(&ledTimer, time * 1000, 0); } // change the wifi state indication @@ -101,7 +103,7 @@ void ICACHE_FLASH_ATTR statusWifiUpdate(uint8_t state) { // schedule an update (don't want to run into concurrency issues) os_timer_disarm(&ledTimer); os_timer_setfn(&ledTimer, ledTimerCb, NULL); - os_timer_arm(&ledTimer, 500, 0); + os_timer_arm_us(&ledTimer, 500000, 0); } //===== Init status stuff @@ -117,12 +119,12 @@ void ICACHE_FLASH_ATTR statusInit(void) { os_timer_disarm(&ledTimer); os_timer_setfn(&ledTimer, ledTimerCb, NULL); - os_timer_arm(&ledTimer, 2000, 0); + os_timer_arm_us(&ledTimer, 2 * 1000000, 0); #ifdef MQTT os_timer_disarm(&mqttStatusTimer); os_timer_setfn(&mqttStatusTimer, mqttStatusCb, NULL); - os_timer_arm(&mqttStatusTimer, MQTT_STATUS_INTERVAL, 1); // recurring timer + os_timer_arm_us(&mqttStatusTimer, MQTT_STATUS_INTERVAL * 1000, 1); // recurring timer #endif // MQTT } diff --git a/mqtt/mqtt.c b/mqtt/mqtt.c index bf785f6..cce321b 100644 --- a/mqtt/mqtt.c +++ b/mqtt/mqtt.c @@ -37,6 +37,8 @@ // Allow messages that don't require ACK to be sent even when pending_buffer is != NULL // Set dup flag in retransmissions +#define USE_US_TIMER + #include #include "pktbuf.h" #include "mqtt.h" @@ -704,7 +706,7 @@ MQTT_Connect(MQTT_Client* client) { // start timer function to tick every second os_timer_disarm(&client->mqttTimer); os_timer_setfn(&client->mqttTimer, (os_timer_func_t *)mqtt_timer, client); - os_timer_arm(&client->mqttTimer, 1000, 1); + os_timer_arm_us(&client->mqttTimer, 1 * 1000000, 1); // initiate the TCP connection or DNS lookup os_printf("MQTT: Connect to %s:%d %p (client=%p)\n", diff --git a/serial/serled.c b/serial/serled.c index 6780eb6..653074d 100644 --- a/serial/serled.c +++ b/serial/serled.c @@ -1,5 +1,7 @@ // Copyright 2015 by Thorsten von Eicken, see LICENSE.txt +#define USE_US_TIMER + #include #include #include @@ -25,7 +27,7 @@ void ICACHE_FLASH_ATTR serledFlash(int duration) { setSerled(1); os_timer_disarm(&serledTimer); os_timer_setfn(&serledTimer, serledTimerCb, NULL); - os_timer_arm(&serledTimer, duration, 0); + os_timer_arm_us(&serledTimer, duration * 1000, 0); } void ICACHE_FLASH_ATTR serledInit(void) { diff --git a/syslog/syslog.c b/syslog/syslog.c index 27d8c58..7fc2cab 100644 --- a/syslog/syslog.c +++ b/syslog/syslog.c @@ -8,6 +8,8 @@ * */ +#define USE_US_TIMER + #include #include "config.h" #include "syslog.h" @@ -89,7 +91,7 @@ static void ICACHE_FLASH_ATTR syslog_timer_arm(int delay) { syslog_timer_armed = true; os_timer_disarm(&wifi_chk_timer); os_timer_setfn(&wifi_chk_timer, (os_timer_func_t *)syslog_chk_status, NULL); - os_timer_arm(&wifi_chk_timer, delay, 0); + os_timer_arm_us(&wifi_chk_timer, delay * 1000, 0); } /****************************************************************************** From f4ee1dbed45495836d362091ed3e98111f91660d Mon Sep 17 00:00:00 2001 From: Alastair D'Silva Date: Tue, 19 Apr 2016 18:18:46 +1000 Subject: [PATCH 04/15] Move USE_US_TIMER to esp8266.h and remove redundant inclusions of osapi.h --- esp-link/cgiflash.c | 3 --- esp-link/cgioptiboot.c | 3 --- esp-link/cgiservices.c | 1 - esp-link/cgiwifi.c | 2 -- esp-link/config.c | 1 - esp-link/main.c | 2 -- esp-link/status.c | 2 -- include/esp8266.h | 4 +++- mqtt/mqtt.c | 2 -- serial/serled.c | 2 -- serial/uart.c | 2 -- syslog/syslog.c | 2 -- 12 files changed, 3 insertions(+), 23 deletions(-) diff --git a/esp-link/cgiflash.c b/esp-link/cgiflash.c index f909e28..f190b23 100644 --- a/esp-link/cgiflash.c +++ b/esp-link/cgiflash.c @@ -13,10 +13,7 @@ Some flash handling cgi routines. Used for reading the existing flash and updati * ---------------------------------------------------------------------------- */ -#define USE_US_TIMER - #include -#include #include "cgi.h" #include "cgiflash.h" diff --git a/esp-link/cgioptiboot.c b/esp-link/cgioptiboot.c index ecaa242..7f19cac 100644 --- a/esp-link/cgioptiboot.c +++ b/esp-link/cgioptiboot.c @@ -1,9 +1,6 @@ // Copyright (c) 2015 by Thorsten von Eicken, see LICENSE.txt in the esp-link repo -#define USE_US_TIMER - #include -#include #include "cgi.h" #include "cgioptiboot.h" #include "config.h" diff --git a/esp-link/cgiservices.c b/esp-link/cgiservices.c index e284b9e..cac9313 100644 --- a/esp-link/cgiservices.c +++ b/esp-link/cgiservices.c @@ -1,4 +1,3 @@ -#define USE_US_TIMER #include #include "cgiwifi.h" diff --git a/esp-link/cgiwifi.c b/esp-link/cgiwifi.c index 2be8b02..6ccbaef 100644 --- a/esp-link/cgiwifi.c +++ b/esp-link/cgiwifi.c @@ -13,8 +13,6 @@ Cgi/template routines for the /wifi url. * ---------------------------------------------------------------------------- */ -#define USE_US_TIMER - #include #include "cgiwifi.h" #include "cgi.h" diff --git a/esp-link/config.c b/esp-link/config.c index 026d139..2ae3d45 100644 --- a/esp-link/config.c +++ b/esp-link/config.c @@ -2,7 +2,6 @@ /* Configuration stored in flash */ #include -#include #include "config.h" #include "espfs.h" #include "crc16.h" diff --git a/esp-link/main.c b/esp-link/main.c index fcbfabb..5c9197d 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -9,8 +9,6 @@ * ---------------------------------------------------------------------------- */ -#define USE_US_TIMER - #include #include "httpd.h" #include "httpdespfs.h" diff --git a/esp-link/status.c b/esp-link/status.c index ef8813d..70a96d0 100644 --- a/esp-link/status.c +++ b/esp-link/status.c @@ -1,7 +1,5 @@ // Copyright 2015 by Thorsten von Eicken, see LICENSE.txt -#define USE_US_TIMER - #include #include "config.h" #include "serled.h" diff --git a/include/esp8266.h b/include/esp8266.h index 3e7eeb9..5d26905 100644 --- a/include/esp8266.h +++ b/include/esp8266.h @@ -14,6 +14,8 @@ #include #include #include + +#define USE_US_TIMER #include #include @@ -24,4 +26,4 @@ #include <_mingw.h> #endif -#endif // _ESP8266_H_ \ No newline at end of file +#endif // _ESP8266_H_ diff --git a/mqtt/mqtt.c b/mqtt/mqtt.c index cce321b..9b68e95 100644 --- a/mqtt/mqtt.c +++ b/mqtt/mqtt.c @@ -37,8 +37,6 @@ // Allow messages that don't require ACK to be sent even when pending_buffer is != NULL // Set dup flag in retransmissions -#define USE_US_TIMER - #include #include "pktbuf.h" #include "mqtt.h" diff --git a/serial/serled.c b/serial/serled.c index 653074d..c1a293f 100644 --- a/serial/serled.c +++ b/serial/serled.c @@ -1,7 +1,5 @@ // Copyright 2015 by Thorsten von Eicken, see LICENSE.txt -#define USE_US_TIMER - #include #include #include diff --git a/serial/uart.c b/serial/uart.c index 206006c..982b456 100644 --- a/serial/uart.c +++ b/serial/uart.c @@ -17,11 +17,9 @@ * ---------------------------------------------------------------------------- * Heavily modified and enhanced by Thorsten von Eicken in 2015 */ -#define USE_US_TIMER #include "esp8266.h" #include "task.h" #include "uart.h" -#include #ifdef UART_DBG #define DBG_UART(format, ...) os_printf(format, ## __VA_ARGS__) diff --git a/syslog/syslog.c b/syslog/syslog.c index 7fc2cab..6d0d4ac 100644 --- a/syslog/syslog.c +++ b/syslog/syslog.c @@ -8,8 +8,6 @@ * */ -#define USE_US_TIMER - #include #include "config.h" #include "syslog.h" From 1dcd1f7b102254f4abfbd99b2ae02f19c5094bf8 Mon Sep 17 00:00:00 2001 From: Alastair D'Silva Date: Tue, 19 Apr 2016 18:21:11 +1000 Subject: [PATCH 05/15] Add a clarifying comment about the setup of TX empty --- serial/uart.c | 1 + 1 file changed, 1 insertion(+) diff --git a/serial/uart.c b/serial/uart.c index 982b456..3141ce6 100644 --- a/serial/uart.c +++ b/serial/uart.c @@ -131,6 +131,7 @@ uart_config(uint8 uart_no) uint32_t tx_empty_bits = 0; if (uart0_tx_enable_pin >= 0) { + // Set the empty threshold to 0 and enable the buffer empty interrupt tx_empty_bits = (0 & UART_TXFIFO_EMPTY_THRHD) << UART_TXFIFO_EMPTY_THRHD_S | UART_TXFIFO_EMPTY_INT_ENA; } WRITE_PERI_REG(UART_CONF1(uart_no), From 352759b7c81662abbfc05c03790d488b7671abe7 Mon Sep 17 00:00:00 2001 From: Alastair D'Silva Date: Tue, 19 Apr 2016 18:41:34 +1000 Subject: [PATCH 06/15] Ensure the TX timer is disarmed after it has fired, allowing it to be retriggered. Only manipulate the timer if TX_ENABLE has been requested. Assert uart_tx_enable_timer_inited once the timer has been inited. --- serial/uart.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/serial/uart.c b/serial/uart.c index 3141ce6..d5160f9 100644 --- a/serial/uart.c +++ b/serial/uart.c @@ -69,6 +69,9 @@ tx_enable(bool state) #endif } +os_timer_t uart_tx_enable_timer; +bool uart_tx_enable_timer_inited = false; + /****************************************************************************** * FunctionName : tx_completed_interrupt * Description : Internal used function @@ -77,8 +80,9 @@ tx_enable(bool state) * Returns : NONE *******************************************************************************/ static void ICACHE_FLASH_ATTR -tx_completed_interrupt(void *arg) +tx_completed_interrupt(void *unused) { + os_timer_disarm(&uart_tx_enable_timer); tx_enable(false); } @@ -152,8 +156,6 @@ uart_config(uint8 uart_no) WRITE_PERI_REG(UART_INT_CLR(uart_no), 0xffff); } -os_timer_t uart_tx_enable_timer; -bool uart_tx_enable_timer_inited = false; /****************************************************************************** * FunctionName : uart1_tx_one_char @@ -168,12 +170,13 @@ uart_tx_one_char(uint8 uart, uint8 c) //Wait until there is room in the FIFO while (((READ_PERI_REG(UART_STATUS(uart))>>UART_TXFIFO_CNT_S)&UART_TXFIFO_CNT)>=100) ; //Send the character - if (UART0 == uart) { + if (UART0 == uart && uart0_tx_enable_pin >= 0) { if (uart_tx_enable_timer_inited) { - // If a tx_completed_interrupt has already been scheduled, cancel it before it fires during our transmission + // A tx_completed_interrupt may have already been scheduled, cancel it before it fires during our transmission os_timer_disarm(&uart_tx_enable_timer); } else { os_timer_setfn(&uart_tx_enable_timer, tx_completed_interrupt, NULL); + uart_tx_enable_timer_inited = true; } tx_enable(true); From 92411f0d76c3df4a5fce891a19f87d0da01b2683 Mon Sep 17 00:00:00 2001 From: Alastair D'Silva Date: Sat, 7 May 2016 16:27:29 +1000 Subject: [PATCH 07/15] Add missing initialisation for uart0_tx_enable_pin --- esp-link/config.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/esp-link/config.c b/esp-link/config.c index 2ae3d45..ad18c9d 100644 --- a/esp-link/config.c +++ b/esp-link/config.c @@ -29,7 +29,8 @@ FlashConfig flashDefault = { .rx_pullup = 1, .sntp_server = "us.pool.ntp.org\0", .syslog_host = "\0", .syslog_minheap = 8192, .syslog_filter = 7, .syslog_showtick = 1, .syslog_showdate = 0, - .mdns_enable = 1, .mdns_servername = "http\0", .timezone_offset = 0 + .mdns_enable = 1, .mdns_servername = "http\0", .timezone_offset = 0, + .uart0_tx_enable_pin = -1 }; typedef union { From c49d2072138c892b48e5aca17f45af5edd3d8a78 Mon Sep 17 00:00:00 2001 From: Alastair D'Silva Date: Tue, 10 May 2016 21:41:12 +1000 Subject: [PATCH 08/15] Standardize on uart0-tx-enable variable name on the HTML side (thanks @krzy27) --- esp-link/cgipins.c | 3 ++- esp-link/config.c | 5 ++++- html/ui.js | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/esp-link/cgipins.c b/esp-link/cgipins.c index 7880195..a35a3d8 100644 --- a/esp-link/cgipins.c +++ b/esp-link/cgipins.c @@ -57,7 +57,7 @@ int ICACHE_FLASH_ATTR cgiPinsSet(HttpdConnData *connData) { ok |= getInt8Arg(connData, "ser", &ser); ok |= getBoolArg(connData, "swap", &swap); ok |= getBoolArg(connData, "rxpup", &rxpup); - ok |= getInt8Arg(connData, "uart0_tx_enable", &uart0_tx_enable); + ok |= getInt8Arg(connData, "uart0-tx-enable", &uart0_tx_enable); if (ok < 0) return HTTPD_CGI_DONE; char *coll; @@ -96,6 +96,7 @@ int ICACHE_FLASH_ATTR cgiPinsSet(HttpdConnData *connData) { flashConfig.ser_led_pin = ser; flashConfig.swap_uart = swap; flashConfig.rx_pullup = rxpup; + flashConfig.uart0_tx_enable_pin = uart0_tx_enable; os_printf("Pins changed: reset=%d isp=%d conn=%d ser=%d swap=%d rx-pup=%d uart0_tx_enable=%d\n", reset, isp, conn, ser, swap, rxpup, uart0_tx_enable); diff --git a/esp-link/config.c b/esp-link/config.c index ad18c9d..d1d5798 100644 --- a/esp-link/config.c +++ b/esp-link/config.c @@ -134,7 +134,7 @@ bool ICACHE_FLASH_ATTR configRestore(void) { char hostname[16]; os_strcpy(hostname, "esp-link-"); os_strcat(hostname, chipIdStr); - os_memcpy(&flashConfig.hostname, hostname, os_strlen(hostname)); + os_memcpy(&flashConfig.hostname, hostname, os_strlen(hostname));u #endif os_memcpy(&flashConfig.mqtt_clientid, &flashConfig.hostname, os_strlen(flashConfig.hostname)); os_memcpy(&flashConfig.mqtt_status_topic, &flashConfig.hostname, os_strlen(flashConfig.hostname)); @@ -186,3 +186,6 @@ getFlashSize() { return 0; return 1 << size_id; } + + + diff --git a/html/ui.js b/html/ui.js index 9b8637c..50ecdc3 100644 --- a/html/ui.js +++ b/html/ui.js @@ -393,7 +393,7 @@ function showNotification(text) { //===== GPIO Pin mux card var pinPresets = { - // array: reset, isp, conn, ser, swap, rxpup, uart0_tx_enable + // array: reset, isp, conn, ser, swap, rxpup, uart0-tx-enable "esp-01": [ 0, -1, 2, -1, 0, 1, -1 ], "esp-12": [ 12, 14, 0, 2, 0, 1, -1 ], "esp-12 swap": [ 1, 3, 0, 2, 1, 1, -1 ], @@ -454,7 +454,7 @@ function displayPins(resp) { createSelectForPin("ser", resp["ser"]); $("#pin-swap").value = resp["swap"]; $("#pin-rxpup").checked = !!resp["rxpup"]; - createSelectForPin("uart0_tx_enable", resp["uart0_tx_enable"]); + createSelectForPin("uart0-tx-enable", resp["uart0-tx-enable"]); createPresets($("#pin-preset")); $("#pin-spinner").setAttribute("hidden", ""); @@ -471,7 +471,7 @@ function setPins(ev) { ev.preventDefault(); var url = "/pins"; var sep = "?"; - ["reset", "isp", "conn", "ser", "swap", "uart0_tx_enable"].forEach(function(p) { + ["reset", "isp", "conn", "ser", "swap", "uart0-tx-enable"].forEach(function(p) { url += sep + p + "=" + $("#pin-"+p).value; sep = "&"; }); From c173706d22c611a9260df4a3532fa780cf219205 Mon Sep 17 00:00:00 2001 From: Alastair D'Silva Date: Tue, 10 May 2016 22:04:07 +1000 Subject: [PATCH 09/15] Fix typo --- esp-link/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp-link/config.c b/esp-link/config.c index d1d5798..bbe28f1 100644 --- a/esp-link/config.c +++ b/esp-link/config.c @@ -134,7 +134,7 @@ bool ICACHE_FLASH_ATTR configRestore(void) { char hostname[16]; os_strcpy(hostname, "esp-link-"); os_strcat(hostname, chipIdStr); - os_memcpy(&flashConfig.hostname, hostname, os_strlen(hostname));u + os_memcpy(&flashConfig.hostname, hostname, os_strlen(hostname)); #endif os_memcpy(&flashConfig.mqtt_clientid, &flashConfig.hostname, os_strlen(flashConfig.hostname)); os_memcpy(&flashConfig.mqtt_status_topic, &flashConfig.hostname, os_strlen(flashConfig.hostname)); From fc230a39cab5b6e317d963f5eab8c9be69c8eb46 Mon Sep 17 00:00:00 2001 From: Alastair D'Silva Date: Sun, 15 May 2016 10:15:20 +1000 Subject: [PATCH 10/15] Fix tx_enable init logic save a couple of branches --- serial/serbridge.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/serial/serbridge.c b/serial/serbridge.c index 5b8b53b..80357f5 100644 --- a/serial/serbridge.c +++ b/serial/serbridge.c @@ -461,20 +461,25 @@ serbridgeInitPins() system_uart_de_swap(); } - // set both pins to 1 before turning them on so we don't cause a reset - if (mcu_isp_pin >= 0) GPIO_OUTPUT_SET(mcu_isp_pin, 1); - if (mcu_reset_pin >= 0) GPIO_OUTPUT_SET(mcu_reset_pin, 1); + /* set both pins to 1 before turning them on (so we don't cause a reset) + * then switch pin mux to make these pins GPIO pins + */ + if (mcu_isp_pin >= 0) { + GPIO_OUTPUT_SET(mcu_isp_pin, 1); + makeGpio(mcu_isp_pin); + } + + if (mcu_reset_pin >= 0) { + GPIO_OUTPUT_SET(mcu_reset_pin, 1); + makeGpio(mcu_reset_pin); + } + // set TX_ENABLE to 0 so we start up listening - if (mcu_reset_pin >= 0) GPIO_OUTPUT_SET(uart0_tx_enable_pin, 0); - // switch pin mux to make these pins GPIO pins - if (mcu_reset_pin >= 0) makeGpio(mcu_reset_pin); - if (mcu_isp_pin >= 0) makeGpio(mcu_isp_pin); if (uart0_tx_enable_pin >= 0) { + GPIO_OUTPUT_SET(uart0_tx_enable_pin, 0); makeGpio(uart0_tx_enable_pin); uart0_set_tx_enable_pin(uart0_tx_enable_pin); } - - } // Start transparent serial bridge TCP server on specified port (typ. 23) From db693751d153ae4c2423fdcc7af7b5b83165e675 Mon Sep 17 00:00:00 2001 From: Alastair D'Silva Date: Sun, 15 May 2016 10:16:55 +1000 Subject: [PATCH 11/15] fix variable name --- esp-link/cgipins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp-link/cgipins.c b/esp-link/cgipins.c index a35a3d8..94de000 100644 --- a/esp-link/cgipins.c +++ b/esp-link/cgipins.c @@ -32,7 +32,7 @@ int ICACHE_FLASH_ATTR cgiPinsGet(HttpdConnData *connData) { int len; len = os_sprintf(buff, - "{ \"reset\":%d, \"isp\":%d, \"conn\":%d, \"ser\":%d, \"swap\":%d, \"rxpup\":%d, \"uart0_tx_enable\":%d }", + "{ \"reset\":%d, \"isp\":%d, \"conn\":%d, \"ser\":%d, \"swap\":%d, \"rxpup\":%d, \"uart0-tx-enable\":%d }", flashConfig.reset_pin, flashConfig.isp_pin, flashConfig.conn_led_pin, flashConfig.ser_led_pin, !!flashConfig.swap_uart, !!flashConfig.rx_pullup, flashConfig.uart0_tx_enable_pin); From e33c924e007dc7bf92644187b46fb4bbedfe1996 Mon Sep 17 00:00:00 2001 From: Alastair D'Silva Date: Sun, 19 Jun 2016 21:17:11 +1000 Subject: [PATCH 12/15] Apply @krzy27's changes to set up the timers correctly. --- serial/uart.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/serial/uart.c b/serial/uart.c index d5160f9..b7c29c6 100644 --- a/serial/uart.c +++ b/serial/uart.c @@ -171,17 +171,15 @@ uart_tx_one_char(uint8 uart, uint8 c) while (((READ_PERI_REG(UART_STATUS(uart))>>UART_TXFIFO_CNT_S)&UART_TXFIFO_CNT)>=100) ; //Send the character if (UART0 == uart && uart0_tx_enable_pin >= 0) { - if (uart_tx_enable_timer_inited) { - // A tx_completed_interrupt may have already been scheduled, cancel it before it fires during our transmission - os_timer_disarm(&uart_tx_enable_timer); - } else { - os_timer_setfn(&uart_tx_enable_timer, tx_completed_interrupt, NULL); - uart_tx_enable_timer_inited = true; - } + // A tx_completed_interrupt may have already been scheduled, cancel it before it fires during our transmission + os_timer_disarm(&uart_tx_enable_timer); tx_enable(true); + WRITE_PERI_REG(UART_FIFO(uart), c); + SET_PERI_REG_MASK(UART_INT_ENA(uart), UART_TXFIFO_EMPTY_INT_ENA); + } else { + WRITE_PERI_REG(UART_FIFO(uart), c); } - WRITE_PERI_REG(UART_FIFO(uart), c); return OK; } @@ -280,6 +278,7 @@ uart0_rx_intr_handler(void *para) post_usr_task(uart_recvTaskNum, 0); } else if (UART_TXFIFO_EMPTY_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_TXFIFO_EMPTY_INT_ST)) { // TX Queue is empty, disable the TX_ENABLE line once the transmission is complete + CLEAR_PERI_REG_MASK(UART_INT_ENA(UART0), UART_TXFIFO_EMPTY_INT_ENA); if (0 != uart0_baud_rate) { int tx_char_time = 8 * 1000000 / uart0_baud_rate; // assumes 8 bits per character os_timer_arm_us(&uart_tx_enable_timer, tx_char_time, false); @@ -351,6 +350,9 @@ uart_init(UartBautRate uart0_br, int8_t uart0TxEnablePin, UartBautRate uart1_br) { if (uart0TxEnablePin >= 0) { uart0_set_tx_enable_pin(uart0TxEnablePin); + // Set up a timer to disable the TX line after the last byte has been transmitted + os_timer_disarm(&uart_tx_enable_timer); + os_timer_setfn(&uart_tx_enable_timer, tx_completed_interrupt, NULL); } // rom use 74880 baut_rate, here reinitialize From b87c7a239c9210e79b8fedccb224441cab895ff4 Mon Sep 17 00:00:00 2001 From: Alastair D'Silva Date: Tue, 14 Feb 2017 10:32:56 +1100 Subject: [PATCH 13/15] Fix bad merge Add missing syntax --- esp-link/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp-link/config.c b/esp-link/config.c index f88a50d..7ecd245 100644 --- a/esp-link/config.c +++ b/esp-link/config.c @@ -31,7 +31,7 @@ FlashConfig flashDefault = { .sntp_server = "us.pool.ntp.org\0", .syslog_host = "\0", .syslog_minheap = 8192, .syslog_filter = 7, .syslog_showtick = 1, .syslog_showdate = 0, .mdns_enable = 1, .mdns_servername = "http\0", .timezone_offset = 0, - .uart0_tx_enable_pin = -1 + .uart0_tx_enable_pin = -1, .data_bits = EIGHT_BITS, .parity = NONE_BITS, .stop_bits = ONE_STOP_BIT, From 2bac83278af79108c385c0d3984f89ab3c9f0fb7 Mon Sep 17 00:00:00 2001 From: Alastair D'Silva Date: Tue, 14 Feb 2017 10:33:53 +1100 Subject: [PATCH 14/15] New flash entries should be added at the end --- esp-link/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp-link/config.h b/esp-link/config.h index d4b2201..99799d0 100644 --- a/esp-link/config.h +++ b/esp-link/config.h @@ -37,11 +37,11 @@ typedef struct { uint8_t mdns_enable; char mdns_servername[32]; int8_t timezone_offset; - int8_t uart0_tx_enable_pin; char mqtt_host[64]; // MQTT host we connect to, was 32-char mqtt_old_host int8_t data_bits; int8_t parity; int8_t stop_bits; + int8_t uart0_tx_enable_pin; } FlashConfig; extern FlashConfig flashConfig; From fa6fa92df3748ce2b4175d6461960157340e5ac3 Mon Sep 17 00:00:00 2001 From: Alastair D'Silva Date: Tue, 14 Feb 2017 10:34:21 +1100 Subject: [PATCH 15/15] New flash entries should be added at the end --- esp-link/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp-link/config.c b/esp-link/config.c index 7ecd245..6e3bb35 100644 --- a/esp-link/config.c +++ b/esp-link/config.c @@ -31,10 +31,10 @@ FlashConfig flashDefault = { .sntp_server = "us.pool.ntp.org\0", .syslog_host = "\0", .syslog_minheap = 8192, .syslog_filter = 7, .syslog_showtick = 1, .syslog_showdate = 0, .mdns_enable = 1, .mdns_servername = "http\0", .timezone_offset = 0, - .uart0_tx_enable_pin = -1, .data_bits = EIGHT_BITS, .parity = NONE_BITS, .stop_bits = ONE_STOP_BIT, + .uart0_tx_enable_pin = -1, }; typedef union {