Code: Select all
void uart_intr_setup(void){
state = STARTUP;
reset_mem();
config();
periph_module_enable(PERIPH_UHCI0_MODULE);
init_dmaDesc();
esp_err_t ret;
uart_param_config(uart_num, &uart_config);
ret = uart_set_pin(uart_num, 16, 17, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
if (ret) {
ESP_LOGI("MAIN_TAG", "ERROR SETTING UART PINS");
}
UART[uart_num]->idle_conf.tx_idle_num = 0;
ESP_LOGI(TAG, "Starting to allocate interrupts on uart_num: %d", uart_num);
UART_ENTER_CRITICAL(&uart_spinlock[uart_num]); //Enable the UART interrupt
UART[uart_num]->int_clr.rxfifo_full = 1;
UART[uart_num]->conf1.rxfifo_full_thrhd = 1U;
UART[uart_num]->int_ena.rxfifo_full = 1;
UART[uart_num]->int_clr.brk_det = 1;
UART[uart_num]->int_ena.brk_det = 1;
UART[uart_num]->conf1.rx_tout_thrhd = 1;
UART[uart_num]->int_clr.rxfifo_tout = 1;
UART[uart_num]->int_ena.rxfifo_tout = 1;
UART[uart_num]->int_clr.txfifo_empty = 1;
UART[uart_num]->conf1.txfifo_empty_thrhd = 1U;
// UART[uart_num]->int_ena.txfifo_empty = 1;
UART[uart_num]->int_clr.tx_done = 1;
// UART[uart_num]->int_ena.tx_done = 1;
UART_EXIT_CRITICAL(&uart_spinlock[uart_num]);
ESP_LOGI(TAG, "RX interrupt configured");
ret= esp_intr_alloc(ETS_UART1_INTR_SOURCE, ESP_INTR_FLAG_LEVEL1, uart_isr, NULL, &s_uart_handle);
ESP_LOGI(TAG, "UART 1 interrupt allocated");
return;
}
void init_dmaDesc (void) {
dmaDesc_Msg.length = 24;
dmaDesc_Msg.size = 24;
dmaDesc_Msg.owner = 1;
dmaDesc_Msg.sosf = 0;
dmaDesc_Msg.buf = (uint8_t *)Msg_8[0];
dmaDesc_Msg.offset = 0;
dmaDesc_Msg.empty = 0;
dmaDesc_Msg.eof = 1;
UHCI0.conf0.val = ( UHCI_UART1_CE );
//UART1.conf0.txfifo_rst = 1;
UHCI0.int_clr.val = 0xFFFFFFFF;
}
void IRAM_ATTR send_msg (void) {
dmaDesc_Msg.length = 24;
UART1.conf0.txfifo_rst = 1;
UHCI0.dma_out_link.start = 0;
UHCI0.dma_in_link.start = 0;
UART1.conf0.txfifo_rst = 0;
UHCI0.dma_out_link.addr = (uint32_t)(&dmaDesc_Msg);
UHCI0.dma_out_link.start = 1;
UHCI0.int_clr.val = 0xFFFFFFFF;
}
void IRAM_ATTR timer_handler (void) {
uint64_t ticks;
switch (state) {
/// ... edited for brevity
case RESPOND:
stop_timer_g0_t0 ();
#ifdef USE_DMA
send_msg();
#else
tx_cntr = 0;
while (tx_cntr < 24) {
WRITE_PERI_REG(UART_FIFO_AHB_REG(uart_num), Msg_8[tx_cntr++]);
}
#endif
state = WAIT;
ticks = 25 * TIMER_BYTE_TICKS;
restart_timer_g0_t0 (ticks);
break;
// ... edited for brevity
}
}