mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-09 01:09:51 +03:00
set EMSUART_TX_TIMEOUT to 256 so tx_mode 1 works again - #398
This commit is contained in:
@@ -35,7 +35,6 @@ uint8_t emsTxBufIdx;
|
|||||||
uint8_t emsTxBufLen;
|
uint8_t emsTxBufLen;
|
||||||
uint32_t emsTxWait;
|
uint32_t emsTxWait;
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Main interrupt handler
|
// Main interrupt handler
|
||||||
// Important: must not use ICACHE_FLASH_ATTR
|
// Important: must not use ICACHE_FLASH_ATTR
|
||||||
@@ -46,9 +45,9 @@ void ICACHE_RAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) {
|
|||||||
|
|
||||||
if (USIS(EMSUART_UART) & ((1 << UIBD))) { // BREAK detection = End of EMS data block
|
if (USIS(EMSUART_UART) & ((1 << UIBD))) { // BREAK detection = End of EMS data block
|
||||||
USC0(EMSUART_UART) &= ~(1 << UCBRK); // reset tx-brk
|
USC0(EMSUART_UART) &= ~(1 << UCBRK); // reset tx-brk
|
||||||
if (emsTxBufIdx < emsTxBufLen) { // timer tx_mode is interrupted by <brk>
|
if (emsTxBufIdx < emsTxBufLen) { // timer tx_mode is interrupted by <brk>
|
||||||
emsTxBufIdx = emsTxBufLen; // stop timer mode
|
emsTxBufIdx = emsTxBufLen; // stop timer mode
|
||||||
drop_next_rx = true; // we have trash in buffer
|
drop_next_rx = true; // we have trash in buffer
|
||||||
}
|
}
|
||||||
USIC(EMSUART_UART) = (1 << UIBD); // INT clear the BREAK detect interrupt
|
USIC(EMSUART_UART) = (1 << UIBD); // INT clear the BREAK detect interrupt
|
||||||
length = 0;
|
length = 0;
|
||||||
@@ -107,6 +106,7 @@ void ICACHE_RAM_ATTR EMSuart::emsuart_tx_timer_intr_handler() {
|
|||||||
USC0(EMSUART_UART) |= (1 << UCBRK); // set <BRK>
|
USC0(EMSUART_UART) |= (1 << UCBRK); // set <BRK>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* init UART0 driver
|
* init UART0 driver
|
||||||
*/
|
*/
|
||||||
@@ -177,7 +177,6 @@ void ICACHE_FLASH_ATTR EMSuart::start(uint8_t tx_mode) {
|
|||||||
ETS_UART_INTR_ATTACH(emsuart_rx_intr_handler, nullptr);
|
ETS_UART_INTR_ATTACH(emsuart_rx_intr_handler, nullptr);
|
||||||
ETS_UART_INTR_ENABLE();
|
ETS_UART_INTR_ENABLE();
|
||||||
drop_next_rx = true;
|
drop_next_rx = true;
|
||||||
// LOG_INFO(F("UART service for Rx/Tx started"));
|
|
||||||
|
|
||||||
// for sending with large delay in EMS+ mode we use a timer interrupt
|
// for sending with large delay in EMS+ mode we use a timer interrupt
|
||||||
timer1_attachInterrupt(emsuart_tx_timer_intr_handler); // Add ISR Function
|
timer1_attachInterrupt(emsuart_tx_timer_intr_handler); // Add ISR Function
|
||||||
@@ -212,7 +211,6 @@ void ICACHE_FLASH_ATTR EMSuart::restart() {
|
|||||||
* Which is a 11-bit set of zero's (11 cycles)
|
* Which is a 11-bit set of zero's (11 cycles)
|
||||||
*/
|
*/
|
||||||
void ICACHE_FLASH_ATTR EMSuart::tx_brk() {
|
void ICACHE_FLASH_ATTR EMSuart::tx_brk() {
|
||||||
|
|
||||||
// make sure Tx FIFO is empty
|
// make sure Tx FIFO is empty
|
||||||
while (((USS(EMSUART_UART) >> USTXC) & 0xFF)) {
|
while (((USS(EMSUART_UART) >> USTXC) & 0xFF)) {
|
||||||
}
|
}
|
||||||
@@ -223,7 +221,7 @@ void ICACHE_FLASH_ATTR EMSuart::tx_brk() {
|
|||||||
USC0(EMSUART_UART) |= (1 << UCBRK); // set bit
|
USC0(EMSUART_UART) |= (1 << UCBRK); // set bit
|
||||||
|
|
||||||
// also for EMS+ there is no need to wait longer, we are finished and can free the bus.
|
// also for EMS+ there is no need to wait longer, we are finished and can free the bus.
|
||||||
delayMicroseconds(EMSUART_TX_WAIT_BRK); // 1144
|
delayMicroseconds(EMSUART_TX_WAIT_BRK); // 1144
|
||||||
|
|
||||||
USC0(EMSUART_UART) &= ~(1 << UCBRK); // clear BRK bit
|
USC0(EMSUART_UART) &= ~(1 << UCBRK); // clear BRK bit
|
||||||
ETS_UART_INTR_ENABLE();
|
ETS_UART_INTR_ENABLE();
|
||||||
@@ -253,11 +251,13 @@ void EMSuart::send_poll(uint8_t data) {
|
|||||||
USF(EMSUART_UART) = data;
|
USF(EMSUART_UART) = data;
|
||||||
delayMicroseconds(EMSUART_TX_WAIT_PLUS);
|
delayMicroseconds(EMSUART_TX_WAIT_PLUS);
|
||||||
tx_brk(); // send <BRK>
|
tx_brk(); // send <BRK>
|
||||||
} else { // EMS1.0, same logic as in transmit
|
} else {
|
||||||
|
// tx_mode 1
|
||||||
|
// EMS1.0, same logic as in transmit
|
||||||
ETS_UART_INTR_DISABLE();
|
ETS_UART_INTR_DISABLE();
|
||||||
volatile uint8_t _usrxc = (USS(EMSUART_UART) >> USRXC) & 0xFF;
|
volatile uint8_t _usrxc = (USS(EMSUART_UART) >> USRXC) & 0xFF;
|
||||||
USF(EMSUART_UART) = data;
|
USF(EMSUART_UART) = data;
|
||||||
uint8_t timeoutcnt = EMSUART_TX_TIMEOUT;
|
uint16_t timeoutcnt = EMSUART_TX_TIMEOUT;
|
||||||
while ((((USS(EMSUART_UART) >> USRXC) & 0xFF) == _usrxc) && (--timeoutcnt > 0)) {
|
while ((((USS(EMSUART_UART) >> USRXC) & 0xFF) == _usrxc) && (--timeoutcnt > 0)) {
|
||||||
delayMicroseconds(EMSUART_TX_BUSY_WAIT); // burn CPU cycles...
|
delayMicroseconds(EMSUART_TX_BUSY_WAIT); // burn CPU cycles...
|
||||||
}
|
}
|
||||||
@@ -306,7 +306,7 @@ uint16_t ICACHE_FLASH_ATTR EMSuart::transmit(uint8_t * buf, uint8_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// EMS+ https://github.com/proddy/EMS-ESP/issues/23#
|
// EMS+ https://github.com/proddy/EMS-ESP/issues/23#
|
||||||
if (tx_mode_ == EMS_TXMODE_EMSPLUS) { // With extra tx delay for EMS+
|
if (tx_mode_ == EMS_TXMODE_EMSPLUS) { // tx_mode 2, With extra tx delay for EMS+
|
||||||
for (uint8_t i = 0; i < len; i++) {
|
for (uint8_t i = 0; i < len; i++) {
|
||||||
USF(EMSUART_UART) = buf[i];
|
USF(EMSUART_UART) = buf[i];
|
||||||
delayMicroseconds(EMSUART_TX_WAIT_PLUS); // 2070
|
delayMicroseconds(EMSUART_TX_WAIT_PLUS); // 2070
|
||||||
@@ -315,7 +315,7 @@ uint16_t ICACHE_FLASH_ATTR EMSuart::transmit(uint8_t * buf, uint8_t len) {
|
|||||||
return EMS_TX_STATUS_OK;
|
return EMS_TX_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Junkers logic by @philrich
|
// Junkers logic by @philrich, tx_mode 3
|
||||||
if (tx_mode_ == EMS_TXMODE_HT3) {
|
if (tx_mode_ == EMS_TXMODE_HT3) {
|
||||||
for (uint8_t i = 0; i < len; i++) {
|
for (uint8_t i = 0; i < len; i++) {
|
||||||
USF(EMSUART_UART) = buf[i];
|
USF(EMSUART_UART) = buf[i];
|
||||||
@@ -361,9 +361,9 @@ uint16_t ICACHE_FLASH_ATTR EMSuart::transmit(uint8_t * buf, uint8_t len) {
|
|||||||
|
|
||||||
// send the bytes along the serial line
|
// send the bytes along the serial line
|
||||||
for (uint8_t i = 0; i < len; i++) {
|
for (uint8_t i = 0; i < len; i++) {
|
||||||
volatile uint8_t _usrxc = (USS(EMSUART_UART) >> USRXC) & 0xFF;
|
volatile uint8_t _usrxc = (USS(EMSUART_UART) >> USRXC) & 0xFF;
|
||||||
uint8_t timeoutcnt = EMSUART_TX_TIMEOUT;
|
uint16_t timeoutcnt = EMSUART_TX_TIMEOUT;
|
||||||
USF(EMSUART_UART) = buf[i]; // send each Tx byte
|
USF(EMSUART_UART) = buf[i]; // send each Tx byte
|
||||||
// wait for echo
|
// wait for echo
|
||||||
while ((((USS(EMSUART_UART) >> USRXC) & 0xFF) == _usrxc) && (--timeoutcnt > 0)) {
|
while ((((USS(EMSUART_UART) >> USRXC) & 0xFF) == _usrxc) && (--timeoutcnt > 0)) {
|
||||||
delayMicroseconds(EMSUART_TX_BUSY_WAIT); // burn CPU cycles...
|
delayMicroseconds(EMSUART_TX_BUSY_WAIT); // burn CPU cycles...
|
||||||
@@ -378,7 +378,7 @@ uint16_t ICACHE_FLASH_ATTR EMSuart::transmit(uint8_t * buf, uint8_t len) {
|
|||||||
if (!(USIS(EMSUART_UART) & (1 << UIBD))) {
|
if (!(USIS(EMSUART_UART) & (1 << UIBD))) {
|
||||||
// no bus collision - send terminating BRK signal
|
// no bus collision - send terminating BRK signal
|
||||||
USC0(EMSUART_UART) |= (1 << UCBRK); // set <BRK>
|
USC0(EMSUART_UART) |= (1 << UCBRK); // set <BRK>
|
||||||
uint8_t timeoutcnt = EMSUART_TX_TIMEOUT;
|
uint16_t timeoutcnt = EMSUART_TX_TIMEOUT;
|
||||||
// wait until BRK detected...
|
// wait until BRK detected...
|
||||||
while (!(USIR(EMSUART_UART) & (1 << UIBD)) && (--timeoutcnt > 0)) {
|
while (!(USIR(EMSUART_UART) & (1 << UIBD)) && (--timeoutcnt > 0)) {
|
||||||
delayMicroseconds(EMSUART_TX_BUSY_WAIT);
|
delayMicroseconds(EMSUART_TX_BUSY_WAIT);
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include <user_interface.h>
|
#include <user_interface.h>
|
||||||
#include <uuid/log.h>
|
|
||||||
|
|
||||||
#define EMSUART_UART 0 // UART 0
|
#define EMSUART_UART 0 // UART 0
|
||||||
#define EMSUART_CONFIG 0x1C // 8N1 (8 bits, no parity, 1 stop bit)
|
#define EMSUART_CONFIG 0x1C // 8N1 (8 bits, no parity, 1 stop bit)
|
||||||
@@ -41,12 +40,13 @@
|
|||||||
#define EMS_TXMODE_NEW 4 // for michael's testing
|
#define EMS_TXMODE_NEW 4 // for michael's testing
|
||||||
|
|
||||||
// LEGACY
|
// LEGACY
|
||||||
#define EMSUART_TX_BIT_TIME 104 // bit time @9600 baud
|
#define EMSUART_TX_BIT_TIME 104 // bit time @9600 baud
|
||||||
#define EMSUART_TX_WAIT_BRK (EMSUART_TX_BIT_TIME * 11) // 1144
|
#define EMSUART_TX_WAIT_BRK (EMSUART_TX_BIT_TIME * 11) // 1144
|
||||||
|
|
||||||
// EMS 1.0
|
// EMS 1.0
|
||||||
#define EMSUART_TX_BUSY_WAIT (EMSUART_TX_BIT_TIME / 8) // 13
|
#define EMSUART_TX_BUSY_WAIT (EMSUART_TX_BIT_TIME / 8) // 13
|
||||||
#define EMSUART_TX_TIMEOUT (22 * EMSUART_TX_BIT_TIME / EMSUART_TX_BUSY_WAIT) // 176
|
// #define EMSUART_TX_TIMEOUT (22 * EMSUART_TX_BIT_TIME / EMSUART_TX_BUSY_WAIT) // 176
|
||||||
|
#define EMSUART_TX_TIMEOUT (42 * 8) // 256 for tx_mode 1
|
||||||
|
|
||||||
// HT3/Junkers - Time to send one Byte (8 Bits, 1 Start Bit, 1 Stop Bit) plus 7 bit delay. The -8 is for lag compensation.
|
// HT3/Junkers - Time to send one Byte (8 Bits, 1 Start Bit, 1 Stop Bit) plus 7 bit delay. The -8 is for lag compensation.
|
||||||
// since we use a faster processor the lag is negligible
|
// since we use a faster processor the lag is negligible
|
||||||
|
|||||||
Reference in New Issue
Block a user