This commit is contained in:
MichaelDvP
2020-06-15 18:57:09 +02:00
18 changed files with 176 additions and 115 deletions

View File

@@ -173,7 +173,8 @@ void EMSuart::restart() {
* Sends a 1-byte poll, ending with a <BRK>
*/
void EMSuart::send_poll(uint8_t data) {
if (tx_mode_ > 5 || tx_mode_ < 4) {
if (tx_mode_ > 5 || tx_mode_ < 4) { // modes 1, 2, 3 also here
// if (tx_mode_ > 5) {
EMS_UART.fifo.rw_byte = data;
emsTxBufIdx = 0;
emsTxBufLen = 1;
@@ -186,13 +187,19 @@ void EMSuart::send_poll(uint8_t data) {
EMS_UART.fifo.rw_byte = data;
delayMicroseconds(EMSUART_TX_WAIT_HT3);
EMS_UART.conf0.txd_brk = 1; // <brk>
// delayMicroseconds(EMSUART_TX_WAIT_BRK);
// EMS_UART.conf0.txd_brk = 0;
} else if (tx_mode_ == EMS_TXMODE_EMSPLUS) {
EMS_UART.fifo.rw_byte = data;
delayMicroseconds(EMSUART_TX_WAIT_PLUS);
EMS_UART.conf0.txd_brk = 1; // <brk>
// delayMicroseconds(EMSUART_TX_WAIT_BRK);
// EMS_UART.conf0.txd_brk = 0;
} else {
EMS_UART.fifo.rw_byte = data;
delayMicroseconds(EMSUART_TX_WAIT_BRK);
volatile uint8_t _usrxc = EMS_UART.status.rxfifo_cnt;
EMS_UART.fifo.rw_byte = data;
while (EMS_UART.status.rxfifo_cnt == _usrxc) {
}
EMS_UART.conf0.txd_brk = 1; // <brk>
}
}
@@ -206,7 +213,8 @@ uint16_t EMSuart::transmit(uint8_t * buf, uint8_t len) {
if (len == 0 || len >= EMS_MAXBUFFERSIZE) {
return EMS_TX_STATUS_ERR;
}
if (tx_mode_ > 5 || tx_mode_ < 4) { // timer controlled modes
if (tx_mode_ > 5 || tx_mode_ < 4) { // timer controlled modes, also modes 1, 2, 3 because delays not working
// if (tx_mode_ > 5) { // timer controlled modes
for (uint8_t i = 0; i < len; i++) {
emsTxBuf[i] = buf[i];
}
@@ -230,6 +238,8 @@ uint16_t EMSuart::transmit(uint8_t * buf, uint8_t len) {
delayMicroseconds(EMSUART_TX_WAIT_PLUS);
}
EMS_UART.conf0.txd_brk = 1; // <brk> after send, cleard by hardware after send
// delayMicroseconds(EMSUART_TX_WAIT_BRK);
// EMS_UART.conf0.txd_brk = 0;
return EMS_TX_STATUS_OK;
}
if (tx_mode_ == EMS_TXMODE_HT3) { // HT3 with 7 bittimes delay
@@ -238,6 +248,8 @@ uint16_t EMSuart::transmit(uint8_t * buf, uint8_t len) {
delayMicroseconds(EMSUART_TX_WAIT_HT3);
}
EMS_UART.conf0.txd_brk = 1; // <brk> after send, cleard by hardware after send
// delayMicroseconds(EMSUART_TX_WAIT_BRK);
// EMS_UART.conf0.txd_brk = 0;
return EMS_TX_STATUS_OK;
}
// mode 1
@@ -249,10 +261,12 @@ uint16_t EMSuart::transmit(uint8_t * buf, uint8_t len) {
EMS_UART.fifo.rw_byte = buf[i]; // send each Tx byte
// wait for echo
while (EMS_UART.status.rxfifo_cnt == _usrxc) {
delayMicroseconds(EMSUART_TX_BUSY_WAIT); // burn CPU cycles...
// delayMicroseconds(EMSUART_TX_BUSY_WAIT); // burn CPU cycles...
}
}
EMS_UART.conf0.txd_brk = 1; // <brk> after send, cleard by hardware after send
// delayMicroseconds(EMSUART_TX_WAIT_BRK);
// EMS_UART.conf0.txd_brk = 0;
return EMS_TX_STATUS_OK;
}

View File

@@ -78,17 +78,16 @@ class EMSuart {
EMSuart() = default;
~EMSuart() = default;
static void start(uint8_t tx_mode);
static void send_poll(uint8_t data);
static void stop();
static void restart();
static uint16_t transmit(uint8_t * buf, uint8_t len);
static void start(uint8_t tx_mode);
static void send_poll(uint8_t data);
static void stop();
static void restart();
static uint16_t transmit(uint8_t * buf, uint8_t len);
private:
static void emsuart_recvTask(void * para);
static void IRAM_ATTR emsuart_rx_intr_handler(void * para);
static void IRAM_ATTR emsuart_tx_timer_intr_handler();
};
} // namespace emsesp

View File

@@ -272,9 +272,16 @@ void EMSuart::send_poll(uint8_t data) {
delayMicroseconds(EMSUART_TX_WAIT_PLUS);
tx_brk(); // send <BRK>
} else { // EMS1.0
USF(EMSUART_UART) = data;
delayMicroseconds(EMSUART_TX_WAIT_BRK);
tx_brk(); // send <BRK>
ETS_UART_INTR_DISABLE();
volatile uint8_t _usrxc = (USS(EMSUART_UART) >> USRXC) & 0xFF;
USF(EMSUART_UART) = data;
while (((USS(EMSUART_UART) >> USRXC) & 0xFF) == _usrxc) {
}
USC0(EMSUART_UART) |= (1 << UCBRK); // set <BRK>
while (!(USIR(EMSUART_UART) & (1 << UIBD))) {
}
USC0(EMSUART_UART) &= ~(1 << UCBRK); // clear <BRK>
ETS_UART_INTR_ENABLE();
}
}