diff --git a/interface/src/project/EMSESPSettingsController.tsx b/interface/src/project/EMSESPSettingsController.tsx
index 29702c7ef..4f394814e 100644
--- a/interface/src/project/EMSESPSettingsController.tsx
+++ b/interface/src/project/EMSESPSettingsController.tsx
@@ -55,18 +55,19 @@ function EMSESPSettingsControllerForm(props: EMSESPSettingsControllerFormProps)
EMS Bus
-
+ margin="normal">
+
+
+
+
+
+
4))) {
+ if (rxbuf[length - 1]) { // check if last byte is break
+ length++;
+ }
+ if ((!drop_next_rx_) && ((length == 2) || (length > 4))) {
int baseType = 0;
- xRingbufferSendFromISR(buf_handle, rxbuf, length - 1, &baseType);
+ xRingbufferSendFromISR(buf_handle_, rxbuf, length - 1, &baseType);
}
- drop_next_rx = false;
+ drop_next_rx_ = false;
}
- portEXIT_CRITICAL(&mux);
-}
-
-void IRAM_ATTR EMSuart::emsuart_tx_timer_intr_handler() {
- if (emsTxBufLen == 0) {
- return;
- }
- portENTER_CRITICAL(&mux);
- if (emsTxBufIdx < emsTxBufLen) {
- EMS_UART.fifo.rw_byte = emsTxBuf[emsTxBufIdx];
- if (emsTxBufIdx == 1) {
- timerAlarmWrite(timer, emsTxWait, true);
- }
- } else if (emsTxBufIdx == emsTxBufLen) {
- EMS_UART.conf0.txd_inv = 1;
- timerAlarmWrite(timer, EMSUART_TX_BRK_TIMER, true);
- } else if (emsTxBufIdx == emsTxBufLen + 1) {
- EMS_UART.conf0.txd_inv = 0;
- emsTxBufLen = 0;
- timerAlarmDisable(timer);
- }
- emsTxBufIdx++;
- portEXIT_CRITICAL(&mux);
+ portEXIT_CRITICAL(&mux_);
}
/*
@@ -111,7 +89,7 @@ void EMSuart::start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t
return;
}
tx_mode_ = tx_mode;
-
+ portENTER_CRITICAL(&mux_);
uart_config_t uart_config = {
.baud_rate = EMSUART_BAUD,
.data_bits = UART_DATA_8_BITS,
@@ -125,14 +103,17 @@ void EMSuart::start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t
EMS_UART.int_ena.val = 0; // disable all intr.
EMS_UART.int_clr.val = 0xFFFFFFFF; // clear all intr. flags
EMS_UART.idle_conf.tx_brk_num = 10; // breaklength 10 bit
- EMS_UART.idle_conf.rx_idle_thrhd = 256;
- drop_next_rx = true;
- buf_handle = xRingbufferCreate(128, RINGBUF_TYPE_NOSPLIT);
+ drop_next_rx_ = true;
+ // EMS_UART.idle_conf.rx_idle_thrhd = 256;
+ // EMS_UART.auto_baud.glitch_filt = 192;
+#if (EMSUART_UART != UART_NUM_2)
+ EMS_UART.conf0.rxfifo_rst = 1; // flush fifos, remove for UART2
+ EMS_UART.conf0.txfifo_rst = 1;
+#endif
+ buf_handle_ = xRingbufferCreate(128, RINGBUF_TYPE_NOSPLIT);
uart_isr_register(EMSUART_UART, emsuart_rx_intr_handler, NULL, ESP_INTR_FLAG_IRAM, NULL);
- xTaskCreate(emsuart_recvTask, "emsuart_recvTask", 2048, NULL, configMAX_PRIORITIES - 1, NULL);
-
- timer = timerBegin(0, 80, true); // timer prescale to 1 us, countup
- timerAttachInterrupt(timer, &emsuart_tx_timer_intr_handler, true); // Timer with edge interrupt
+ xTaskCreate(emsuart_recvTask, "emsuart_recvTask", 2048, NULL, configMAX_PRIORITIES - 3, NULL);
+ portEXIT_CRITICAL(&mux_);
restart();
}
@@ -140,34 +121,24 @@ void EMSuart::start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t
* Stop, disable interrupt
*/
void EMSuart::stop() {
- EMS_UART.int_ena.val = 0; // disable all intr.
- EMS_UART.conf0.txd_inv = 0; // stop break
- if (emsTxBufLen > 0) {
- timerAlarmDisable(timer);
- }
+ portENTER_CRITICAL(&mux_);
+ EMS_UART.int_ena.val = 0; // disable all intr.
+ portEXIT_CRITICAL(&mux_);
};
/*
* Restart uart and make mode dependent configs.
*/
void EMSuart::restart() {
+ portENTER_CRITICAL(&mux_);
if (EMS_UART.int_raw.brk_det) { // we received a break in the meantime
EMS_UART.int_clr.brk_det = 1; // clear flag
- drop_next_rx = true; // and drop first frame
+ drop_next_rx_ = true; // and drop first frame
}
EMS_UART.int_ena.brk_det = 1; // activate only break
- emsTxBufIdx = 0;
- emsTxBufLen = 0;
- if (tx_mode_ > 100) {
- emsTxWait = EMSUART_TX_BIT_TIME * (tx_mode_ - 90);
- } else {
- emsTxWait = EMSUART_TX_BIT_TIME * (tx_mode_ + 10);
- }
- if (tx_mode_ == EMS_TXMODE_NEW) {
- EMS_UART.conf0.txd_brk = 1;
- } else {
- EMS_UART.conf0.txd_brk = 0;
- }
+ EMS_UART.conf0.txd_brk = (tx_mode_ == EMS_TXMODE_HW) ? 1 : 0;
+ portEXIT_CRITICAL(&mux_);
+
}
/*
@@ -186,26 +157,12 @@ uint16_t EMSuart::transmit(const uint8_t * buf, const uint8_t len) {
if (len == 0 || len >= EMS_MAXBUFFERSIZE) {
return EMS_TX_STATUS_ERR;
}
+
if (tx_mode_ == 0) {
return EMS_TX_STATUS_OK;
}
- if (tx_mode_ > 5) { // timer controlled modes
- for (uint8_t i = 0; i < len; i++) {
- emsTxBuf[i] = buf[i];
- }
- emsTxBufIdx = 0;
- emsTxBufLen = len;
- if (tx_mode_ > 100 && len > 1) {
- timerAlarmWrite(timer, EMSUART_TX_WAIT_REPLY, true);
- } else {
- timerAlarmWrite(timer, emsTxWait, true); // start with autoreload
- }
- timerAlarmEnable(timer);
- return EMS_TX_STATUS_OK;
- }
-
- if (tx_mode_ == EMS_TXMODE_NEW) { // hardware controlled modes
+ if (tx_mode_ == EMS_TXMODE_HW) { // hardware controlled mode
for (uint8_t i = 0; i < len; i++) {
EMS_UART.fifo.rw_byte = buf[i];
}
diff --git a/src/uart/emsuart_esp32.h b/src/uart/emsuart_esp32.h
index eac3a2902..f2ec41b08 100644
--- a/src/uart/emsuart_esp32.h
+++ b/src/uart/emsuart_esp32.h
@@ -43,15 +43,11 @@
#define EMS_TXMODE_DEFAULT 1
#define EMS_TXMODE_EMSPLUS 2
#define EMS_TXMODE_HT3 3
-#define EMS_TXMODE_NEW 4 // for michael's testing
+#define EMS_TXMODE_HW 4
// LEGACY
#define EMSUART_TX_BIT_TIME 104 // bit time @9600 baud
-// Timer controlled modes
-#define EMSUART_TX_BRK_TIMER (EMSUART_TX_BIT_TIME * 10 + 28) // 10.25 bit times
-#define EMSUART_TX_WAIT_REPLY 100000 // delay 100ms after first byte
-
// EMS 1.0
#define EMSUART_TX_BUSY_WAIT (EMSUART_TX_BIT_TIME / 8) // 13
#define EMSUART_TX_TIMEOUT (20 * EMSUART_TX_BIT_TIME / EMSUART_TX_BUSY_WAIT)
@@ -79,13 +75,12 @@ class EMSuart {
static void start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t tx_gpio);
static void send_poll(const uint8_t data);
static void stop();
- static void restart();
static uint16_t transmit(const uint8_t * buf, const 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();
+ static void restart();
};
} // namespace emsesp