From 1a638d26113552403a8cb2c97f001eec0eb9378c Mon Sep 17 00:00:00 2001 From: proddy Date: Fri, 24 May 2019 15:08:56 +0200 Subject: [PATCH] tx logic --- src/emsuart.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/emsuart.cpp b/src/emsuart.cpp index e0b9dd054..9c2c34c87 100644 --- a/src/emsuart.cpp +++ b/src/emsuart.cpp @@ -193,7 +193,6 @@ static inline void ICACHE_FLASH_ATTR emsuart_loopback(bool enable) { * Send to Tx, ending with a */ void ICACHE_FLASH_ATTR emsuart_tx_buffer(uint8_t * buf, uint8_t len) { - // backwards compatibility if (EMS_Sys_Status.emsTxDelay < 2) { for (uint8_t i = 0; i < len; i++) { @@ -225,8 +224,10 @@ void ICACHE_FLASH_ATTR emsuart_tx_buffer(uint8_t * buf, uint8_t len) { } // wait until we received sizeof(telegram) or RxBRK (== collision detect) - while ((((USS(EMSUART_UART) >> USRXC) & 0xFF) < len) || (U0IS & (1 << UIBD))) + // while ((((USS(EMSUART_UART) >> USRXC) & 0xFF) < len) || !(USIS(EMSUART_UART) & (1 << UIBD))) + while ((((USS(EMSUART_UART) >> USRXC) & 0xFF) < len) || (U0IS & (1 << UIBD))) { delayMicroseconds(11 * EMSUART_BIT_TIME); // burn CPU cycles... + } // we got the whole telegram in Rx buffer // on Rx-BRK (bus collision), we simply enable Rx and leave @@ -237,17 +238,17 @@ void ICACHE_FLASH_ATTR emsuart_tx_buffer(uint8_t * buf, uint8_t len) { emsuart_loopback(true); USC0(EMSUART_UART) |= (1 << UCBRK); // set - while (!(U0IS & (1 << UIBD))) ; // wait until BRK detected... - delayMicroseconds(EMSUART_BIT_TIME / 8); // ~13µs - USC0(EMSUART_UART) &= ~(1 << UCBRK); // clear + while (!(USIS(EMSUART_UART) & (1 << UIBD))) + ; // wait until BRK detected... + delayMicroseconds(EMSUART_BIT_TIME / 8); // ~13µs + USC0(EMSUART_UART) &= ~(1 << UCBRK); // clear - U0IC = (1 << UIBD); // clear BRK detect IRQ - emsuart_loopback(false); // disable loopback mode + USIC(EMSUART_UART) = (1 << UIBD); // clear BRK detect IRQ + emsuart_loopback(false); // disable loopback mode } - emsuart_flush_fifos(); // flush Rx buffer to be sure + emsuart_flush_fifos(); // flush Rx buffer to be sure ETS_UART_INTR_ENABLE(); // receive anything from FIFO... - } }