mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
make task cores configurable in platformio.ini
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
namespace emsesp {
|
||||
uint8_t EMSuart::last_tx_src_ = 0;
|
||||
|
||||
static TaskHandle_t xHandle;
|
||||
static QueueHandle_t uart_queue;
|
||||
uint8_t tx_mode_ = 0xFF;
|
||||
uint32_t inverse_mask = 0;
|
||||
@@ -94,12 +95,18 @@ void EMSuart::start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t
|
||||
uart_param_config(EMSUART_NUM, &uart_config);
|
||||
uart_set_pin(EMSUART_NUM, tx_gpio, rx_gpio, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
||||
uart_set_line_inverse(EMSUART_NUM, inverse_mask);
|
||||
uart_driver_install(EMSUART_NUM, 129, 0, (EMS_MAXBUFFERSIZE + 1) * 2, &uart_queue, 0); // buffer must be > fifo
|
||||
uart_driver_install(EMSUART_NUM, UART_FIFO_LEN + 1, 0, (EMS_MAXBUFFERSIZE + 1) * 2, &uart_queue, 0); // buffer must be > fifo
|
||||
uart_set_rx_full_threshold(EMSUART_NUM, 1);
|
||||
uart_set_rx_timeout(EMSUART_NUM, 0); // disable
|
||||
|
||||
// note esp32s3 crashes with 2k stacksize, stack overflow here sometimes wipes settingsfiles.
|
||||
xTaskCreate(uart_event_task, "uart_event_task", 2560, NULL, configMAX_PRIORITIES - 1, NULL);
|
||||
#if defined(CONFIG_FREERTOS_UNICORE) || (EMSESP_UART_RUNNING_CORE < 0)
|
||||
xTaskCreate(uart_event_task, "uart_event_task", EMSESP_UART_STACKSIZE, NULL, EMSESP_UART_PRIORITY, &xHandle);
|
||||
#else
|
||||
xTaskCreatePinnedToCore(uart_event_task, "uart_event_task", EMSESP_UART_STACKSIZE, NULL, EMSESP_UART_PRIORITY, &xHandle, EMSESP_UART_RUNNING_CORE);
|
||||
#endif
|
||||
} else {
|
||||
vTaskResume(xHandle);
|
||||
}
|
||||
tx_mode_ = tx_mode;
|
||||
uart_enable_intr_mask(EMSUART_NUM, UART_BRK_DET_INT_ENA | UART_RXFIFO_FULL_INT_ENA);
|
||||
@@ -111,7 +118,7 @@ void EMSuart::start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t
|
||||
void EMSuart::stop() {
|
||||
if (tx_mode_ != 0xFF) { // only call after driver initialisation
|
||||
uart_disable_intr_mask(EMSUART_NUM, UART_BRK_DET_INT_ENA | UART_RXFIFO_FULL_INT_ENA);
|
||||
// TODO should we xTaskSuspend() the event task here?
|
||||
vTaskSuspend(xHandle);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -139,7 +146,7 @@ void EMSuart::send_poll(const uint8_t data) {
|
||||
* buf contains the CRC and len is #bytes including the CRC
|
||||
* returns code, 1=success
|
||||
*/
|
||||
uint16_t EMSuart::transmit(const uint8_t * buf, const uint8_t len) {
|
||||
uint8_t EMSuart::transmit(const uint8_t * buf, const uint8_t len) {
|
||||
if (len == 0 || len >= EMS_MAXBUFFERSIZE) {
|
||||
return EMS_TX_STATUS_ERR;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,17 @@
|
||||
#ifndef EMSESP_EMSUART_H
|
||||
#define EMSESP_EMSUART_H
|
||||
|
||||
#ifndef EMSESP_UART_RUNNING_CORE
|
||||
#define EMSESP_UART_RUNNING_CORE -1
|
||||
#endif
|
||||
|
||||
#ifndef EMSESP_UART_STACKSIZE
|
||||
#define EMSESP_UART_STACKSIZE 2560
|
||||
#endif
|
||||
|
||||
#ifndef EMSESP_UART_PRIORITY
|
||||
#define EMSESP_UART_PRIORITY configMAX_PRIORITIES - 1
|
||||
#endif
|
||||
#define EMS_MAXBUFFERSIZE 33 // max size of the buffer. EMS packets are max 32 bytes, plus extra for BRK
|
||||
|
||||
#define EMSUART_NUM UART_NUM_1 // on C3 and S2 there is no UART2, use UART1 for all
|
||||
@@ -61,11 +72,11 @@ class EMSuart {
|
||||
EMSuart() = default;
|
||||
~EMSuart() = default;
|
||||
|
||||
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 uint16_t transmit(const uint8_t * buf, const uint8_t len);
|
||||
static uint8_t last_tx_src() {
|
||||
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 uint8_t transmit(const uint8_t * buf, const uint8_t len);
|
||||
static uint8_t last_tx_src() {
|
||||
return last_tx_src_;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user