uart-rx-ringbuf
Interrupt-driven UART RX with a caller-supplied byte-granular ring buffer. Demonstrates the alp_uart_rx_ringbuf_* pattern for when the consumer can't keep up with the line rate.
Source: examples/peripheral-io/uart-rx-ringbuf/.
board.yaml
som:
sku: E1M-AEN801
preset: e1m-evk
cores:
m55_hp:
app: ./src
peripherals: [uart]
diagnostics:
log_level: info
Enable the ring-buffer path with CONFIG_ALP_SDK_UART_RX_RINGBUF=y in prj.conf or as a CMake flag.
Source (abbreviated)
#include "alp/peripheral.h"
#include "alp/board.h" /* BOARD_UART_DEBUG */
static uint8_t rx_backing[64]; /* caller-owned; must outlive the ring */
int main(void)
{
(void)alp_init();
printf("[ringbuf] open BOARD_UART_DEBUG @ 115200 8N1\n");
alp_uart_t *u = alp_uart_open(&(alp_uart_config_t){
.port_id = BOARD_UART_DEBUG, /* E1M EVK: ALP_E1M_UART0; E1M-X EVK: ALP_E1M_X_UART0 */
.baudrate = 115200,
.data_bits = 8,
.stop_bits = 1,
.parity = ALP_UART_PARITY_NONE,
});
if (u == NULL) { /* prints the error and "[ringbuf] done" */ return 0; }
alp_uart_rx_ringbuf_t *rb = alp_uart_rx_ringbuf_attach(u, rx_backing, sizeof(rx_backing));
if (rb == NULL) { /* ALP_ERR_NOSUPPORT without CONFIG_ALP_SDK_UART_RX_RINGBUF */
alp_uart_close(u);
return 0;
}
printf("[ringbuf] attached; backing=%zu bytes\n", sizeof(rx_backing));
alp_delay_ms(50); /* stand-in for the app's real work */
/* One non-blocking drain of whatever the IRQ has staged. */
uint8_t scratch[32];
size_t got = 0;
alp_status_t s = alp_uart_rx_ringbuf_pop(rb, scratch, sizeof(scratch), &got);
printf("[ringbuf] pop -> status=%d got=%zu count_remaining=%zu\n",
(int)s, got, alp_uart_rx_ringbuf_count(rb));
alp_uart_rx_ringbuf_detach(rb);
alp_uart_close(u);
printf("[ringbuf] done\n");
return 0;
}
The example does one pop and exits; there is no forever loop. A real app pops opportunistically at every wake-up and never blocks waiting for the ring.
See also
<alp/peripheral.h>reference — UARTuart-echo— polled variant- Examples overview
Questions about this page? Email contact@alplab.ai