static int cc32xx_uart_rx_bytes(uint32_t base, struct cs_rbuf *rxb) { int num_recd = 0; while (rxb->avail > 0 && MAP_UARTCharsAvail(base)) { uint32_t chf = HWREG(base + UART_O_DR); /* Note: There are error flags here, we may be interested in those. */ cs_rbuf_append_one(rxb, (uint8_t) chf); num_recd++; } return num_recd; }
IRAM int esp_uart_dispatch_rx_top(int uart_no) { struct esp_uart_state *us = s_us[uart_no]; if (us == NULL || !us->rx_enabled) return 1; uint32_t rxn = 0; cs_rbuf_t *rxb = &us->rx_buf; /* RX */ if (rxb->avail > 0 && rx_fifo_len(uart_no) > 0) { int linger_counter = 0; /* 32 here is a constant measured (using system_get_time) to provide * linger time of rx_linger_micros. It basically means that one iteration * of the loop takes 3.2 us. * * Note: lingering may starve TX FIFO if the flow is bidirectional. * TODO(rojer): keep transmitting from tx_buf while lingering. */ int max_linger = us->cfg->rx_linger_micros / 10 * 32; #ifdef MEASURE_LINGER_TIME uint32_t st = system_get_time(); #endif while (rxb->avail > 0 && linger_counter <= max_linger) { int rx_len = rx_fifo_len(uart_no); if (rx_len > 0) { while (rx_len-- > 0 && rxb->avail > 0) { cs_rbuf_append_one(rxb, rx_byte(uart_no)); rxn++; } if (linger_counter > 0) { us->stats.rx_linger_conts++; linger_counter = 0; } } else { linger_counter++; } } #ifdef MEASURE_LINGER_TIME fprintf(stderr, "Time spent reading: %u us\n", system_get_time() - st); #endif us->stats.rx_bytes += rxn; } int rfl = rx_fifo_len(uart_no); if (rfl < us->cfg->rx_fifo_full_thresh) { CLEAR_PERI_REG_MASK(UART_INT_CLR(uart_no), UART_RX_INTS); } return rfl == 0; }