/*---------------------------------------------------------------------------*/ void UART_Int_Handler(void) { if(pADI_UART->COMIIR & COMIIR_STA_RXBUFFULL) { unsigned char x = pADI_UART->COMRX; if(uart_input_handler) { uart_input_handler(x); } } }
static void uart_evt_task(void *pvParameters) { int uart_num = UART_NUM_0; uart_config_t uart_config = { .baud_rate = 115200, .data_bits = UART_DATA_8_BITS, .parity = UART_PARITY_DISABLE, .stop_bits = UART_STOP_BITS_1, .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, .rx_flow_ctrl_thresh = 122, }; //Set UART parameters uart_param_config(uart_num, &uart_config); //Set UART log level esp_log_level_set(TAG, ESP_LOG_INFO); //Install UART driver, and get the queue. uart_driver_install(uart_num, BUF_SIZE * 2, BUF_SIZE * 2, 10, &uart0_queue, 0); //Set UART pins,(-1: default pin, no change.) //For UART0, we can just use the default pins. //uart_set_pin(uart_num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); //Set uart pattern detect function. uart_enable_pattern_det_intr(uart_num, '+', 3, 10000, 10, 10); //Create a task to handler UART event from ISR xTaskCreate(uart_task, "uart_task", UART_TASK_STACK_SIZE, NULL, UART_TASK_PRIO, NULL); //process data uint8_t* data = (uint8_t*) malloc(BUF_SIZE); do { int len = uart_read_bytes(uart_num, data, BUF_SIZE, 100 / portTICK_RATE_MS); if(len > 0) { //ESP_LOGI(TAG, "uart read : %d", len); //uart_write_bytes(uart_num, (const char*)data, len); uart_input_handler((const char*)data, len); } } while(1); } void uart_init(void) { memset(&rcvMsg, 0, sizeof(rcvMsg)); rcvMsg.RcvBuffSize = RECV_BUF_SIZE; rcvMsg.pRcvMsgBuff = NULL; rcvMsg.pRcvMsgBuff = (uint8_t *) malloc(RECV_BUF_SIZE); if (rcvMsg.pRcvMsgBuff == NULL) { ESP_LOGE(TAG, "receive buffer alloc failed"); return; } rcvMsg.pReadPos = rcvMsg.pRcvMsgBuff; rcvMsg.pWritePos = rcvMsg.pRcvMsgBuff; xTaskCreate(uart_evt_task, "uart_evt_task", UART_EVT_TASK_STACK_SIZE, NULL, UART_EVT_TASK_PRIO, NULL); }