merge rs485 branch

pull/326/head
Thorsten von Eicken 8 years ago
commit dbe495968b
No known key found for this signature in database
GPG Key ID: C7F972A59D834B46
  1. 6
      esp-link/cgiflash.c
  2. 5
      esp-link/cgioptiboot.c
  3. 17
      esp-link/cgipins.c
  4. 3
      esp-link/cgiservices.c
  5. 20
      esp-link/cgiwifi.c
  6. 2
      esp-link/config.c
  7. 1
      esp-link/config.h
  8. 8
      esp-link/main.c
  9. 8
      esp-link/status.c
  10. 5
      html/home.html
  11. 16
      html/ui.js
  12. 2
      include/esp8266.h
  13. 2
      mqtt/mqtt.c
  14. 32
      serial/serbridge.c
  15. 2
      serial/serled.c
  16. 93
      serial/uart.c
  17. 4
      serial/uart.h
  18. 2
      syslog/syslog.c

@ -13,9 +13,7 @@ Some flash handling cgi routines. Used for reading the existing flash and updati
* ----------------------------------------------------------------------------
*/
#include <esp8266.h>
#include <osapi.h>
#include "cgi.h"
#include "cgiflash.h"
@ -181,7 +179,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 +193,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;
}

@ -1,7 +1,6 @@
// Copyright (c) 2015 by Thorsten von Eicken, see LICENSE.txt in the esp-link repo
#include <esp8266.h>
#include <osapi.h>
#include "cgi.h"
#include "cgioptiboot.h"
#include "config.h"
@ -143,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);
@ -494,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 };

@ -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<<ser)) { coll = "Serial LED"; goto collision; }
pins |= 1 << ser;
}
if (uart0_tx_enable >= 0) {
if (pins & (1<<uart0_tx_enable)) { coll = "UART0 TX Enable"; goto collision; }
pins |= 1 << uart0_tx_enable;
}
if (swap) {
if (pins & (1<<15)) { coll = "Uart TX"; goto collision; }
if (pins & (1<<13)) { coll = "Uart RX"; goto collision; }
@ -90,8 +96,9 @@ int ICACHE_FLASH_ATTR cgiPinsSet(HttpdConnData *connData) {
flashConfig.ser_led_pin = ser;
flashConfig.swap_uart = swap;
flashConfig.rx_pullup = rxpup;
os_printf("Pins changed: reset=%d isp=%d conn=%d ser=%d swap=%d rx-pup=%d\n",
reset, isp, conn, ser, swap, 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);
// apply the changes
serbridgeInitPins();

@ -1,3 +1,4 @@
#include <esp8266.h>
#include "cgiwifi.h"
#include "cgi.h"
@ -38,7 +39,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()) {

@ -279,7 +279,7 @@ void ICACHE_FLASH_ATTR wifiStartScan() {
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);
}
}
@ -335,7 +335,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);
@ -349,7 +349,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);
}
}
@ -368,7 +368,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);
}
// Kick off connection to some network
@ -380,7 +380,7 @@ void ICACHE_FLASH_ATTR connectToNetwork(char *ssid, char *pass) {
// 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, 1000000, 0); // 1 second for the response of this request to make it
}
// This cgi uses the routines above to connect to a specific access point with the
@ -527,7 +527,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);
@ -700,7 +700,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
@ -815,7 +815,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
@ -959,7 +959,7 @@ 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);
}
// Access functions for cgiWifiAps : query the number of entries in the table
@ -983,7 +983,7 @@ ICACHE_FLASH_ATTR void wifiGetApName(int i, char *ptr) {
}
// Access functions for cgiWifiAps : returns the signal strength of network (i is index into array). Return current network strength for negative i.
ICACHE_FLASH_ATTR int wifiSignalStrength(int i) {
ICACHE_FLASH_ATTR int wifiSignalStrength(int i) {
sint8 rssi;
if (i < 0 || i == 255)

@ -2,7 +2,6 @@
/* Configuration stored in flash */
#include <esp8266.h>
#include <osapi.h>
#include "config.h"
#include "espfs.h"
#include "crc16.h"
@ -35,6 +34,7 @@ FlashConfig flashDefault = {
.data_bits = EIGHT_BITS,
.parity = NONE_BITS,
.stop_bits = ONE_STOP_BIT,
.uart0_tx_enable_pin = -1,
};
typedef union {

@ -41,6 +41,7 @@ typedef struct {
int8_t data_bits;
int8_t parity;
int8_t stop_bits;
int8_t uart0_tx_enable_pin;
} FlashConfig;
extern FlashConfig flashConfig;

@ -147,7 +147,9 @@ user_rf_cal_sector_set(void) {
// Main routine to initialize esp-link.
void ICACHE_FLASH_ATTR
user_init(void) {
// uncomment the following three lines to see flash config messages for troubleshooting
system_timer_reinit();
// uncomment the following three lines to see flash config messages for troubleshooting
//uart_init(115200, 115200);
//logInit();
//os_delay_us(100000L);
@ -159,7 +161,7 @@ user_init(void) {
gpio_output_set(0, 0, 0, (1<<15)); // some people tie it to GND, gotta ensure it's disabled
// init UART
uart_init(CALC_UARTMODE(flashConfig.data_bits, flashConfig.parity, flashConfig.stop_bits),
flashConfig.baud_rate, 115200);
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);
@ -185,7 +187,7 @@ 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();

@ -92,7 +92,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 +101,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 +117,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
}

@ -76,6 +76,11 @@
<div class="popup">Second signal to program &#xb5;C.
AVR:not used, esp8266:gpio2, ARM:ISP</div>
</div>
<div class="pure-control-group">
<label for="pin-uart0-tx-enable">TX Enable</label>
<select id="pin-uart0-tx-enable"></select>
<div class="popup">A pin that should be asserted high whilst transmitting (eg. to put RS/485 trancievers into TX mode)</div>
</div>
<div class="pure-control-group">
<label for="pin-conn">Conn LED</label>
<select id="pin-conn"></select>

@ -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 = "&";
});

@ -17,6 +17,8 @@
#include <ets_sys.h>
#include <gpio.h>
#include <mem.h>
#define USE_US_TIMER
#include <osapi.h>
#include <upgrade.h>

@ -703,7 +703,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",

@ -18,7 +18,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;
uint8_t in_mcu_flashing; // for disabling slip during MCU flashing
@ -557,9 +557,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) {
@ -578,12 +579,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);
// 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);
/* 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 (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)

@ -25,7 +25,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) {

@ -28,6 +28,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 +37,56 @@ 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
}
os_timer_t uart_tx_enable_timer;
bool uart_tx_enable_timer_inited = false;
/******************************************************************************
* 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 *unused)
{
os_timer_disarm(&uart_tx_enable_timer);
tx_enable(false);
}
/******************************************************************************
* FunctionName : uart_config
* Description : Internal used function
@ -78,12 +129,20 @@ uart_config(uint8 uart_no, UartBautRate baudrate, uint32 conf0)
// 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) {
// 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),
((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),
@ -94,6 +153,7 @@ uart_config(uint8 uart_no, UartBautRate baudrate, uint32 conf0)
WRITE_PERI_REG(UART_INT_CLR(uart_no), 0xffff);
}
/******************************************************************************
* FunctionName : uart1_tx_one_char
* Description : Internal used function
@ -107,7 +167,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
WRITE_PERI_REG(UART_FIFO(uart), c);
if (UART0 == uart && uart0_tx_enable_pin >= 0) {
// 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);
}
return OK;
}
@ -165,6 +234,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
@ -203,6 +273,13 @@ 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
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);
}
}
}
@ -252,6 +329,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);
}
@ -266,12 +344,20 @@ uart0_config(uint8_t data_bits, uint8_t parity, uint8_t stop_bits) {
* 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(uint32 conf0, UartBautRate uart0_br, UartBautRate uart1_br)
uart_init(uint32 conf0, 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
uart_config(UART0, uart0_br, conf0);
uart_config(UART1, uart1_br, conf0);
@ -295,4 +381,3 @@ uart_add_recv_cb(UartRecv_cb cb) {
}
os_printf("UART: max cb count exceeded\n");
}

@ -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(uint32 conf0, UartBautRate uart0_br, UartBautRate uart1_br);
void uart_init(uint32 conf0, UartBautRate uart0_br, int8_t uart0TxEnablePin, UartBautRate uart1_br);
// Transmit a buffer of characters on UART0
void uart0_tx_buffer(char *buf, uint16 len);
@ -30,4 +30,6 @@ void uart0_baud(int rate);
void uart0_config(uint8_t data_bits, uint8_t parity, uint8_t stop_bits);
void uart_config(uint8 uart_no, UartBautRate baudrate, uint32 conf0);
void uart0_set_tx_enable_pin(int8_t pin);
#endif /* __UART_H__ */

@ -91,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);
}
/******************************************************************************

Loading…
Cancel
Save