mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
improve uart break timing
This commit is contained in:
@@ -110,6 +110,18 @@ void EMSuart::stop() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* generate <BRK> by inverting tx
|
||||||
|
*/
|
||||||
|
void IRAM_ATTR EMSuart::uart_gen_break(uint32_t length_us) {
|
||||||
|
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
|
||||||
|
portENTER_CRITICAL(&mux);
|
||||||
|
uart_set_line_inverse(EMSUART_NUM, UART_SIGNAL_TXD_INV ^ inverse_mask);
|
||||||
|
delayMicroseconds(length_us);
|
||||||
|
uart_set_line_inverse(EMSUART_NUM, inverse_mask);
|
||||||
|
portEXIT_CRITICAL(&mux);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sends a 1-byte poll, ending with a <BRK>
|
* Sends a 1-byte poll, ending with a <BRK>
|
||||||
*/
|
*/
|
||||||
@@ -141,9 +153,7 @@ uint16_t EMSuart::transmit(const uint8_t * buf, const uint8_t len) {
|
|||||||
uart_write_bytes(EMSUART_NUM, &buf[i], 1);
|
uart_write_bytes(EMSUART_NUM, &buf[i], 1);
|
||||||
delayMicroseconds(EMSUART_TX_WAIT_PLUS);
|
delayMicroseconds(EMSUART_TX_WAIT_PLUS);
|
||||||
}
|
}
|
||||||
uart_set_line_inverse(EMSUART_NUM, UART_SIGNAL_TXD_INV ^ inverse_mask);
|
uart_gen_break(EMSUART_TX_BRK_PLUS);
|
||||||
delayMicroseconds(EMSUART_TX_BRK_PLUS);
|
|
||||||
uart_set_line_inverse(EMSUART_NUM, inverse_mask);
|
|
||||||
return EMS_TX_STATUS_OK;
|
return EMS_TX_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,9 +162,7 @@ uint16_t EMSuart::transmit(const uint8_t * buf, const uint8_t len) {
|
|||||||
uart_write_bytes(EMSUART_NUM, &buf[i], 1);
|
uart_write_bytes(EMSUART_NUM, &buf[i], 1);
|
||||||
delayMicroseconds(EMSUART_TX_WAIT_HT3);
|
delayMicroseconds(EMSUART_TX_WAIT_HT3);
|
||||||
}
|
}
|
||||||
uart_set_line_inverse(EMSUART_NUM, UART_SIGNAL_TXD_INV ^ inverse_mask);
|
uart_gen_break(EMSUART_TX_BRK_HT3);
|
||||||
delayMicroseconds(EMSUART_TX_BRK_HT3);
|
|
||||||
uart_set_line_inverse(EMSUART_NUM, inverse_mask);
|
|
||||||
return EMS_TX_STATUS_OK;
|
return EMS_TX_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,9 +177,7 @@ uint16_t EMSuart::transmit(const uint8_t * buf, const uint8_t len) {
|
|||||||
uart_get_buffered_data_len(EMSUART_NUM, &rx1);
|
uart_get_buffered_data_len(EMSUART_NUM, &rx1);
|
||||||
} while ((rx1 == rx0) && (--timeoutcnt));
|
} while ((rx1 == rx0) && (--timeoutcnt));
|
||||||
}
|
}
|
||||||
uart_set_line_inverse(EMSUART_NUM, UART_SIGNAL_TXD_INV ^ inverse_mask);
|
uart_gen_break(EMSUART_TX_BRK_EMS);
|
||||||
delayMicroseconds(EMSUART_TX_BRK_EMS);
|
|
||||||
uart_set_line_inverse(EMSUART_NUM, inverse_mask);
|
|
||||||
return EMS_TX_STATUS_OK;
|
return EMS_TX_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ class EMSuart {
|
|||||||
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 IRAM_ATTR uart_gen_break(uint32_t length_us);
|
||||||
static void uart_event_task(void * pvParameters);
|
static void uart_event_task(void * pvParameters);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user