mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
remove tx-modes 5-255
This commit is contained in:
@@ -55,18 +55,19 @@ function EMSESPSettingsControllerForm(props: EMSESPSettingsControllerFormProps)
|
|||||||
<Typography variant="h6" color="primary" >
|
<Typography variant="h6" color="primary" >
|
||||||
EMS Bus
|
EMS Bus
|
||||||
</Typography>
|
</Typography>
|
||||||
<TextValidator
|
<SelectValidator name="tx_mode"
|
||||||
validators={['required', 'isNumber', 'minNumber:0', 'maxNumber:255']}
|
label="Tx Mode"
|
||||||
errorMessages={['TX mode is required', "Must be a number", "Must be 0 or higher", "Max value is 255"]}
|
value={data.tx_mode}
|
||||||
name="tx_mode"
|
|
||||||
label="Tx Mode (0=off)"
|
|
||||||
fullWidth
|
fullWidth
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
value={data.tx_mode}
|
|
||||||
type="number"
|
|
||||||
onChange={handleValueChange('tx_mode')}
|
onChange={handleValueChange('tx_mode')}
|
||||||
margin="normal"
|
margin="normal">
|
||||||
/>
|
<MenuItem value={0}>0 - Off</MenuItem>
|
||||||
|
<MenuItem value={1}>1 - Default</MenuItem>
|
||||||
|
<MenuItem value={2}>2 - EMS+</MenuItem>
|
||||||
|
<MenuItem value={3}>3 - HT3</MenuItem>
|
||||||
|
<MenuItem value={4}>4 - Hardware</MenuItem>
|
||||||
|
</SelectValidator>
|
||||||
<SelectValidator name="ems_bus_id"
|
<SelectValidator name="ems_bus_id"
|
||||||
label="Bus ID"
|
label="Bus ID"
|
||||||
value={data.ems_bus_id}
|
value={data.ems_bus_id}
|
||||||
|
|||||||
@@ -28,15 +28,10 @@
|
|||||||
|
|
||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
static RingbufHandle_t buf_handle = NULL;
|
RingbufHandle_t buf_handle_ = NULL;
|
||||||
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
|
portMUX_TYPE mux_ = portMUX_INITIALIZER_UNLOCKED;
|
||||||
static hw_timer_t * timer = NULL;
|
bool drop_next_rx_ = true;
|
||||||
bool drop_next_rx = true;
|
uint8_t tx_mode_ = 0xFF;
|
||||||
uint8_t tx_mode_ = 0xFF;
|
|
||||||
uint8_t emsTxBuf[EMS_MAXBUFFERSIZE];
|
|
||||||
uint8_t emsTxBufIdx = 0;
|
|
||||||
uint8_t emsTxBufLen = 0;
|
|
||||||
uint32_t emsTxWait;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Task to handle the incoming data
|
* Task to handle the incoming data
|
||||||
@@ -44,11 +39,11 @@ uint32_t emsTxWait;
|
|||||||
void EMSuart::emsuart_recvTask(void * para) {
|
void EMSuart::emsuart_recvTask(void * para) {
|
||||||
while (1) {
|
while (1) {
|
||||||
size_t item_size;
|
size_t item_size;
|
||||||
uint8_t * telegram = (uint8_t *)xRingbufferReceive(buf_handle, &item_size, portMAX_DELAY);
|
uint8_t * telegram = (uint8_t *)xRingbufferReceive(buf_handle_, &item_size, portMAX_DELAY);
|
||||||
uint8_t telegramSize = item_size;
|
uint8_t telegramSize = item_size;
|
||||||
if (telegram) {
|
if (telegram) {
|
||||||
EMSESP::incoming_telegram(telegram, telegramSize);
|
EMSESP::incoming_telegram(telegram, telegramSize);
|
||||||
vRingbufferReturnItem(buf_handle, (void *)telegram);
|
vRingbufferReturnItem(buf_handle_, (void *)telegram);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,7 +52,7 @@ void EMSuart::emsuart_recvTask(void * para) {
|
|||||||
* UART interrupt, on break read the fifo and put the whole telegram to ringbuffer
|
* UART interrupt, on break read the fifo and put the whole telegram to ringbuffer
|
||||||
*/
|
*/
|
||||||
void IRAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) {
|
void IRAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) {
|
||||||
portENTER_CRITICAL(&mux);
|
portENTER_CRITICAL(&mux_);
|
||||||
if (EMS_UART.int_st.brk_det) {
|
if (EMS_UART.int_st.brk_det) {
|
||||||
EMS_UART.int_clr.brk_det = 1; // clear flag
|
EMS_UART.int_clr.brk_det = 1; // clear flag
|
||||||
uint8_t rxbuf[EMS_MAXBUFFERSIZE];
|
uint8_t rxbuf[EMS_MAXBUFFERSIZE];
|
||||||
@@ -65,40 +60,23 @@ void IRAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) {
|
|||||||
while (EMS_UART.status.rxfifo_cnt) {
|
while (EMS_UART.status.rxfifo_cnt) {
|
||||||
uint8_t rx = EMS_UART.fifo.rw_byte; // read all bytes from fifo
|
uint8_t rx = EMS_UART.fifo.rw_byte; // read all bytes from fifo
|
||||||
if (length < EMS_MAXBUFFERSIZE) {
|
if (length < EMS_MAXBUFFERSIZE) {
|
||||||
rxbuf[length++] = rx;
|
if (length || rx) { // skip leading zero
|
||||||
|
rxbuf[length++] = rx;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
drop_next_rx = true; // we have a overflow
|
drop_next_rx_ = true; // we have a overflow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((!drop_next_rx) && ((length == 2) || (length > 4))) {
|
if (rxbuf[length - 1]) { // check if last byte is break
|
||||||
|
length++;
|
||||||
|
}
|
||||||
|
if ((!drop_next_rx_) && ((length == 2) || (length > 4))) {
|
||||||
int baseType = 0;
|
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);
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -111,7 +89,7 @@ void EMSuart::start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tx_mode_ = tx_mode;
|
tx_mode_ = tx_mode;
|
||||||
|
portENTER_CRITICAL(&mux_);
|
||||||
uart_config_t uart_config = {
|
uart_config_t uart_config = {
|
||||||
.baud_rate = EMSUART_BAUD,
|
.baud_rate = EMSUART_BAUD,
|
||||||
.data_bits = UART_DATA_8_BITS,
|
.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_ena.val = 0; // disable all intr.
|
||||||
EMS_UART.int_clr.val = 0xFFFFFFFF; // clear all intr. flags
|
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.tx_brk_num = 10; // breaklength 10 bit
|
||||||
EMS_UART.idle_conf.rx_idle_thrhd = 256;
|
drop_next_rx_ = true;
|
||||||
drop_next_rx = true;
|
// EMS_UART.idle_conf.rx_idle_thrhd = 256;
|
||||||
buf_handle = xRingbufferCreate(128, RINGBUF_TYPE_NOSPLIT);
|
// 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);
|
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);
|
xTaskCreate(emsuart_recvTask, "emsuart_recvTask", 2048, NULL, configMAX_PRIORITIES - 3, NULL);
|
||||||
|
portEXIT_CRITICAL(&mux_);
|
||||||
timer = timerBegin(0, 80, true); // timer prescale to 1 us, countup
|
|
||||||
timerAttachInterrupt(timer, &emsuart_tx_timer_intr_handler, true); // Timer with edge interrupt
|
|
||||||
restart();
|
restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,34 +121,24 @@ void EMSuart::start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t
|
|||||||
* Stop, disable interrupt
|
* Stop, disable interrupt
|
||||||
*/
|
*/
|
||||||
void EMSuart::stop() {
|
void EMSuart::stop() {
|
||||||
EMS_UART.int_ena.val = 0; // disable all intr.
|
portENTER_CRITICAL(&mux_);
|
||||||
EMS_UART.conf0.txd_inv = 0; // stop break
|
EMS_UART.int_ena.val = 0; // disable all intr.
|
||||||
if (emsTxBufLen > 0) {
|
portEXIT_CRITICAL(&mux_);
|
||||||
timerAlarmDisable(timer);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Restart uart and make mode dependent configs.
|
* Restart uart and make mode dependent configs.
|
||||||
*/
|
*/
|
||||||
void EMSuart::restart() {
|
void EMSuart::restart() {
|
||||||
|
portENTER_CRITICAL(&mux_);
|
||||||
if (EMS_UART.int_raw.brk_det) { // we received a break in the meantime
|
if (EMS_UART.int_raw.brk_det) { // we received a break in the meantime
|
||||||
EMS_UART.int_clr.brk_det = 1; // clear flag
|
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
|
EMS_UART.int_ena.brk_det = 1; // activate only break
|
||||||
emsTxBufIdx = 0;
|
EMS_UART.conf0.txd_brk = (tx_mode_ == EMS_TXMODE_HW) ? 1 : 0;
|
||||||
emsTxBufLen = 0;
|
portEXIT_CRITICAL(&mux_);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -186,26 +157,12 @@ uint16_t EMSuart::transmit(const uint8_t * buf, const uint8_t len) {
|
|||||||
if (len == 0 || len >= EMS_MAXBUFFERSIZE) {
|
if (len == 0 || len >= EMS_MAXBUFFERSIZE) {
|
||||||
return EMS_TX_STATUS_ERR;
|
return EMS_TX_STATUS_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tx_mode_ == 0) {
|
if (tx_mode_ == 0) {
|
||||||
return EMS_TX_STATUS_OK;
|
return EMS_TX_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tx_mode_ > 5) { // timer controlled modes
|
if (tx_mode_ == EMS_TXMODE_HW) { // hardware controlled mode
|
||||||
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
|
|
||||||
for (uint8_t i = 0; i < len; i++) {
|
for (uint8_t i = 0; i < len; i++) {
|
||||||
EMS_UART.fifo.rw_byte = buf[i];
|
EMS_UART.fifo.rw_byte = buf[i];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,15 +43,11 @@
|
|||||||
#define EMS_TXMODE_DEFAULT 1
|
#define EMS_TXMODE_DEFAULT 1
|
||||||
#define EMS_TXMODE_EMSPLUS 2
|
#define EMS_TXMODE_EMSPLUS 2
|
||||||
#define EMS_TXMODE_HT3 3
|
#define EMS_TXMODE_HT3 3
|
||||||
#define EMS_TXMODE_NEW 4 // for michael's testing
|
#define EMS_TXMODE_HW 4
|
||||||
|
|
||||||
// LEGACY
|
// LEGACY
|
||||||
#define EMSUART_TX_BIT_TIME 104 // bit time @9600 baud
|
#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
|
// 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 (20 * EMSUART_TX_BIT_TIME / EMSUART_TX_BUSY_WAIT)
|
#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 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 send_poll(const uint8_t data);
|
||||||
static void stop();
|
static void stop();
|
||||||
static void restart();
|
|
||||||
static uint16_t transmit(const uint8_t * buf, const uint8_t len);
|
static uint16_t transmit(const uint8_t * buf, const uint8_t len);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void emsuart_recvTask(void * para);
|
static void emsuart_recvTask(void * para);
|
||||||
static void IRAM_ATTR emsuart_rx_intr_handler(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
|
} // namespace emsesp
|
||||||
|
|||||||
Reference in New Issue
Block a user