From 5d6e9dd704ab8dcc282ba56127e3b21ea1725b22 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Sun, 21 Jun 2020 14:18:28 +0200 Subject: [PATCH] do not call shell while sending --- src/console.cpp | 6 ++++++ src/telegram.cpp | 8 -------- src/uart/emsuart_esp8266.cpp | 27 +++++++++++++++++++-------- src/uart/emsuart_esp8266.h | 4 ++++ 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/console.cpp b/src/console.cpp index 28f515197..3e6412d5b 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -434,7 +434,13 @@ void Console::loop() { telnet_.loop(); #endif +#if defined(ESP8266) + if (!EMSuart::sending()) { + Shell::loop_all(); + } +#else Shell::loop_all(); +#endif } } // namespace emsesp diff --git a/src/telegram.cpp b/src/telegram.cpp index 2f44a8bfa..fceb1f86a 100644 --- a/src/telegram.cpp +++ b/src/telegram.cpp @@ -453,11 +453,6 @@ void TxService::send_telegram(const QueuedTxTelegram & tx_telegram) { length++; // add one since we want to now include the CRC -// logging interferes with the UART so disable this -#if defined(ESP8266) - if (Settings().ems_tx_mode() <= 4) { -#endif - // This logging causes errors with timer based tx-modes on esp8266! LOG_DEBUG(F("Sending %s Tx [#%d], telegram: %s"), (telegram->operation == Telegram::Operation::TX_WRITE) ? F("write") : F("read"), tx_telegram.id_, @@ -469,9 +464,6 @@ void TxService::send_telegram(const QueuedTxTelegram & tx_telegram) { LOG_NOTICE(F("[DEBUG] Tx: %s"), Helpers::data_to_hex(telegram_raw, length).c_str()); } #endif -#if defined(ESP8266) - } -#endif // send the telegram to the UART Tx uint16_t status = EMSuart::transmit(telegram_raw, length); diff --git a/src/uart/emsuart_esp8266.cpp b/src/uart/emsuart_esp8266.cpp index f86e05ae6..a2f7dfc6f 100644 --- a/src/uart/emsuart_esp8266.cpp +++ b/src/uart/emsuart_esp8266.cpp @@ -34,6 +34,7 @@ uint8_t emsTxBuf[EMS_MAXBUFFERSIZE]; uint8_t emsTxBufIdx; uint8_t emsTxBufLen; uint32_t emsTxWait; +bool EMSuart::sending_ = false; // // Main interrupt handler @@ -57,8 +58,8 @@ void ICACHE_RAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) { } if (USIS(EMSUART_UART) & ((1 << UIBD))) { // BREAK detection = End of EMS data block USC0(EMSUART_UART) &= ~(1 << UCBRK); // reset tx-brk - if (emsTxBufIdx < emsTxBufLen) { // timer tx_mode is interrupted by - emsTxBufIdx = emsTxBufLen; // stop timer mode + if (emsTxBufIdx < emsTxBufLen) { // irq tx_mode is interrupted by + emsTxBufIdx = emsTxBufLen; // stop tx drop_next_rx = true; // we have trash in buffer } USIC(EMSUART_UART) = (1 << UIBD); // INT clear the BREAK detect interrupt @@ -78,6 +79,7 @@ void ICACHE_RAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) { system_os_post(EMSUART_recvTaskPrio, 0, 0); // call emsuart_recvTask() at next opportunity } drop_next_rx = false; + sending_ = false; } } @@ -152,8 +154,11 @@ void ICACHE_FLASH_ATTR EMSuart::start(uint8_t tx_mode) { // set 9600, 8 bits, no parity check, 1 stop bit USD(EMSUART_UART) = (UART_CLK_FREQ / EMSUART_BAUD); - USC0(EMSUART_UART) = EMSUART_CONFIG; // 8N1 - + if (tx_mode_ == 5) { + USC0(EMSUART_UART) = 0x2C; // 8N1.5 + } else { + USC0(EMSUART_UART) = EMSUART_CONFIG; // 8N1 + } emsuart_flush_fifos(); // conf1 params @@ -217,6 +222,12 @@ void ICACHE_FLASH_ATTR EMSuart::restart() { emsTxBufIdx = 0; emsTxBufLen = 0; timer1_enable(TIM_DIV16, TIM_EDGE, TIM_SINGLE); + if (tx_mode_ == 5) { + USC0(EMSUART_UART) = 0x2C; // 8N1.5 + } else { + USC0(EMSUART_UART) = EMSUART_CONFIG; // 8N1 + } + } /* @@ -247,6 +258,7 @@ void ICACHE_FLASH_ATTR EMSuart::tx_brk() { void EMSuart::send_poll(uint8_t data) { // reset tx-brk, just in case it is accidentally set USC0(EMSUART_UART) &= ~(1 << UCBRK); + sending_ = true; if (tx_mode_ > 5) { // timer controlled modes USF(EMSUART_UART) = data; @@ -300,9 +312,9 @@ uint16_t ICACHE_FLASH_ATTR EMSuart::transmit(uint8_t * buf, uint8_t len) { if (len == 0 || len >= EMS_MAXBUFFERSIZE) { return EMS_TX_STATUS_ERR; // nothing or to much to send } - // reset tx-brk, just in case it is accidentally set USC0(EMSUART_UART) &= ~(1 << UCBRK); + sending_ = true; // timer controlled modes with extra delay if (tx_mode_ > 5) { @@ -323,9 +335,9 @@ uint16_t ICACHE_FLASH_ATTR EMSuart::transmit(uint8_t * buf, uint8_t len) { USIC(EMSUART_UART) |= (1 << UIFF); // clear fifo-full irq emsTxBufIdx = 0; emsTxBufLen = len; - USF(EMSUART_UART) = buf[0]; USC1(EMSUART_UART) = (0x01 << UCFFT); // fifo full to 1 - USIE(EMSUART_UART) |= (1 << UIFF); // enable fifo-full irq + USIE(EMSUART_UART) |= (1 << UIFF); // enable fifo-full irq + USF(EMSUART_UART) = buf[0]; return EMS_TX_STATUS_OK; } @@ -421,7 +433,6 @@ uint16_t ICACHE_FLASH_ATTR EMSuart::transmit(uint8_t * buf, uint8_t len) { } ETS_UART_INTR_ENABLE(); // open up the FIFO again to start receiving - return EMS_TX_STATUS_OK; // send the Tx ok status back } diff --git a/src/uart/emsuart_esp8266.h b/src/uart/emsuart_esp8266.h index 304c2ab89..a37094100 100644 --- a/src/uart/emsuart_esp8266.h +++ b/src/uart/emsuart_esp8266.h @@ -70,6 +70,9 @@ class EMSuart { static void ICACHE_FLASH_ATTR restart(); static void ICACHE_FLASH_ATTR send_poll(uint8_t data); static uint16_t ICACHE_FLASH_ATTR transmit(uint8_t * buf, uint8_t len); + static bool sending() { + return sending_; + } typedef struct { uint8_t length; @@ -82,6 +85,7 @@ class EMSuart { static void ICACHE_FLASH_ATTR emsuart_flush_fifos(); static void ICACHE_FLASH_ATTR tx_brk(); static void ICACHE_RAM_ATTR emsuart_tx_timer_intr_handler(); + static bool sending_; }; } // namespace emsesp