Fix Serial
This commit is contained in:
parent
cc00af38ec
commit
db77195404
@ -27,9 +27,7 @@
|
|||||||
#include "soc/io_mux_reg.h"
|
#include "soc/io_mux_reg.h"
|
||||||
#include "soc/gpio_sig_map.h"
|
#include "soc/gpio_sig_map.h"
|
||||||
#include "soc/dport_reg.h"
|
#include "soc/dport_reg.h"
|
||||||
|
#include "esp_intr_alloc.h"
|
||||||
#define ETS_UART_INUM 5
|
|
||||||
#define ETS_UART2_INUM ETS_UART_INUM
|
|
||||||
|
|
||||||
#define UART_REG_BASE(u) ((u==0)?DR_REG_UART_BASE:( (u==1)?DR_REG_UART1_BASE:( (u==2)?DR_REG_UART2_BASE:0)))
|
#define UART_REG_BASE(u) ((u==0)?DR_REG_UART_BASE:( (u==1)?DR_REG_UART1_BASE:( (u==2)?DR_REG_UART2_BASE:0)))
|
||||||
#define UART_RXD_IDX(u) ((u==0)?U0RXD_IN_IDX:( (u==1)?U1RXD_IN_IDX:( (u==2)?U2RXD_IN_IDX:0)))
|
#define UART_RXD_IDX(u) ((u==0)?U0RXD_IN_IDX:( (u==1)?U1RXD_IN_IDX:( (u==2)?U2RXD_IN_IDX:0)))
|
||||||
@ -45,6 +43,7 @@ struct uart_struct_t {
|
|||||||
#endif
|
#endif
|
||||||
uint8_t num;
|
uint8_t num;
|
||||||
xQueueHandle queue;
|
xQueueHandle queue;
|
||||||
|
intr_handle_t intr_handle;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if CONFIG_DISABLE_HAL_LOCKS
|
#if CONFIG_DISABLE_HAL_LOCKS
|
||||||
@ -52,18 +51,18 @@ struct uart_struct_t {
|
|||||||
#define UART_MUTEX_UNLOCK()
|
#define UART_MUTEX_UNLOCK()
|
||||||
|
|
||||||
static uart_t _uart_bus_array[3] = {
|
static uart_t _uart_bus_array[3] = {
|
||||||
{(volatile uart_dev_t *)(DR_REG_UART_BASE), 0, NULL},
|
{(volatile uart_dev_t *)(DR_REG_UART_BASE), 0, NULL, NULL},
|
||||||
{(volatile uart_dev_t *)(DR_REG_UART1_BASE), 1, NULL},
|
{(volatile uart_dev_t *)(DR_REG_UART1_BASE), 1, NULL, NULL},
|
||||||
{(volatile uart_dev_t *)(DR_REG_UART2_BASE), 2, NULL}
|
{(volatile uart_dev_t *)(DR_REG_UART2_BASE), 2, NULL, NULL}
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
#define UART_MUTEX_LOCK() do {} while (xSemaphoreTake(uart->lock, portMAX_DELAY) != pdPASS)
|
#define UART_MUTEX_LOCK() do {} while (xSemaphoreTake(uart->lock, portMAX_DELAY) != pdPASS)
|
||||||
#define UART_MUTEX_UNLOCK() xSemaphoreGive(uart->lock)
|
#define UART_MUTEX_UNLOCK() xSemaphoreGive(uart->lock)
|
||||||
|
|
||||||
static uart_t _uart_bus_array[3] = {
|
static uart_t _uart_bus_array[3] = {
|
||||||
{(volatile uart_dev_t *)(DR_REG_UART_BASE), NULL, 0, NULL},
|
{(volatile uart_dev_t *)(DR_REG_UART_BASE), NULL, 0, NULL, NULL},
|
||||||
{(volatile uart_dev_t *)(DR_REG_UART1_BASE), NULL, 1, NULL},
|
{(volatile uart_dev_t *)(DR_REG_UART1_BASE), NULL, 1, NULL, NULL},
|
||||||
{(volatile uart_dev_t *)(DR_REG_UART2_BASE), NULL, 2, NULL}
|
{(volatile uart_dev_t *)(DR_REG_UART2_BASE), NULL, 2, NULL, NULL}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -75,6 +74,9 @@ static void IRAM_ATTR _uart_isr(void *arg)
|
|||||||
|
|
||||||
for(i=0;i<3;i++){
|
for(i=0;i<3;i++){
|
||||||
uart = &_uart_bus_array[i];
|
uart = &_uart_bus_array[i];
|
||||||
|
if(uart->intr_handle == NULL){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
uart->dev->int_clr.rxfifo_full = 1;
|
uart->dev->int_clr.rxfifo_full = 1;
|
||||||
uart->dev->int_clr.frm_err = 1;
|
uart->dev->int_clr.frm_err = 1;
|
||||||
uart->dev->int_clr.rxfifo_tout = 1;
|
uart->dev->int_clr.rxfifo_tout = 1;
|
||||||
@ -91,18 +93,6 @@ static void IRAM_ATTR _uart_isr(void *arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void uartEnableGlobalInterrupt()
|
|
||||||
{
|
|
||||||
xt_set_interrupt_handler(ETS_UART_INUM, _uart_isr, NULL);
|
|
||||||
ESP_INTR_ENABLE(ETS_UART_INUM);
|
|
||||||
}
|
|
||||||
|
|
||||||
void uartDisableGlobalInterrupt()
|
|
||||||
{
|
|
||||||
ESP_INTR_DISABLE(ETS_UART_INUM);
|
|
||||||
xt_set_interrupt_handler(ETS_UART_INUM, NULL, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void uartEnableInterrupt(uart_t* uart)
|
void uartEnableInterrupt(uart_t* uart)
|
||||||
{
|
{
|
||||||
UART_MUTEX_LOCK();
|
UART_MUTEX_LOCK();
|
||||||
@ -114,7 +104,7 @@ void uartEnableInterrupt(uart_t* uart)
|
|||||||
uart->dev->int_ena.rxfifo_tout = 1;
|
uart->dev->int_ena.rxfifo_tout = 1;
|
||||||
uart->dev->int_clr.val = 0xffffffff;
|
uart->dev->int_clr.val = 0xffffffff;
|
||||||
|
|
||||||
intr_matrix_set(xPortGetCoreID(), UART_INTR_SOURCE(uart->num), ETS_UART_INUM);
|
esp_intr_alloc(UART_INTR_SOURCE(uart->num), (int)ESP_INTR_FLAG_IRAM, _uart_isr, NULL, &uart->intr_handle);
|
||||||
UART_MUTEX_UNLOCK();
|
UART_MUTEX_UNLOCK();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,6 +114,10 @@ void uartDisableInterrupt(uart_t* uart)
|
|||||||
uart->dev->conf1.val = 0;
|
uart->dev->conf1.val = 0;
|
||||||
uart->dev->int_ena.val = 0;
|
uart->dev->int_ena.val = 0;
|
||||||
uart->dev->int_clr.val = 0xffffffff;
|
uart->dev->int_clr.val = 0xffffffff;
|
||||||
|
|
||||||
|
esp_intr_free(uart->intr_handle);
|
||||||
|
uart->intr_handle = NULL;
|
||||||
|
|
||||||
UART_MUTEX_UNLOCK();
|
UART_MUTEX_UNLOCK();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +146,6 @@ void uartAttachRx(uart_t* uart, uint8_t rxPin, bool inverted)
|
|||||||
pinMode(rxPin, INPUT);
|
pinMode(rxPin, INPUT);
|
||||||
pinMatrixInAttach(rxPin, UART_RXD_IDX(uart->num), inverted);
|
pinMatrixInAttach(rxPin, UART_RXD_IDX(uart->num), inverted);
|
||||||
uartEnableInterrupt(uart);
|
uartEnableInterrupt(uart);
|
||||||
uartEnableGlobalInterrupt();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void uartAttachTx(uart_t* uart, uint8_t txPin, bool inverted)
|
void uartAttachTx(uart_t* uart, uint8_t txPin, bool inverted)
|
||||||
|
Loading…
Reference in New Issue
Block a user