Lines Matching refs:rx_data

11 static uint8_t inc(struct uart_async_rx *rx_data, uint8_t val)  in inc()  argument
13 return (val + 1) & (rx_data->config->buf_cnt - 1); in inc()
16 static struct uart_async_rx_buf *get_buf(struct uart_async_rx *rx_data, uint8_t idx) in get_buf() argument
18 uint8_t *p = rx_data->config->buffer; in get_buf()
20 p += idx * (rx_data->buf_len + sizeof(struct uart_async_rx_buf)); in get_buf()
25 uint8_t *uart_async_rx_buf_req(struct uart_async_rx *rx_data) in uart_async_rx_buf_req() argument
29 if (rx_data->free_buf_cnt != 0) { in uart_async_rx_buf_req()
30 struct uart_async_rx_buf *buf = get_buf(rx_data, rx_data->drv_buf_idx); in uart_async_rx_buf_req()
33 rx_data->drv_buf_idx = inc(rx_data, rx_data->drv_buf_idx); in uart_async_rx_buf_req()
35 atomic_dec(&rx_data->free_buf_cnt); in uart_async_rx_buf_req()
41 void uart_async_rx_on_rdy(struct uart_async_rx *rx_data, uint8_t *buffer, size_t length) in uart_async_rx_on_rdy() argument
50 __ASSERT_NO_MSG(rx_buf->wr_idx <= rx_data->buf_len); in uart_async_rx_on_rdy()
52 atomic_add(&rx_data->pending_bytes, length); in uart_async_rx_on_rdy()
61 static void usr_rx_buf_release(struct uart_async_rx *rx_data, struct uart_async_rx_buf *buf) in usr_rx_buf_release() argument
64 rx_data->rd_idx = 0; in usr_rx_buf_release()
65 rx_data->rd_buf_idx = inc(rx_data, rx_data->rd_buf_idx); in usr_rx_buf_release()
66 atomic_inc(&rx_data->free_buf_cnt); in usr_rx_buf_release()
67 __ASSERT_NO_MSG(rx_data->free_buf_cnt <= rx_data->config->buf_cnt); in usr_rx_buf_release()
70 void uart_async_rx_on_buf_rel(struct uart_async_rx *rx_data, uint8_t *buffer) in uart_async_rx_on_buf_rel() argument
81 size_t uart_async_rx_data_claim(struct uart_async_rx *rx_data, uint8_t **data, size_t length) in uart_async_rx_data_claim() argument
86 if ((rx_data->pending_bytes == 0) || (length == 0)) { in uart_async_rx_data_claim()
91 buf = get_buf(rx_data, rx_data->rd_buf_idx); in uart_async_rx_data_claim()
95 if ((buf->completed == 1) && (rx_data->rd_idx == buf->wr_idx)) { in uart_async_rx_data_claim()
96 usr_rx_buf_release(rx_data, buf); in uart_async_rx_data_claim()
102 *data = &buf->buffer[rx_data->rd_idx]; in uart_async_rx_data_claim()
103 rem = buf->wr_idx - rx_data->rd_idx; in uart_async_rx_data_claim()
108 bool uart_async_rx_data_consume(struct uart_async_rx *rx_data, size_t length) in uart_async_rx_data_consume() argument
110 struct uart_async_rx_buf *buf = get_buf(rx_data, rx_data->rd_buf_idx); in uart_async_rx_data_consume()
112 rx_data->rd_idx += length; in uart_async_rx_data_consume()
114 if ((buf->completed == 1) && (rx_data->rd_idx == buf->wr_idx)) { in uart_async_rx_data_consume()
115 usr_rx_buf_release(rx_data, buf); in uart_async_rx_data_consume()
118 atomic_sub(&rx_data->pending_bytes, length); in uart_async_rx_data_consume()
120 __ASSERT_NO_MSG(rx_data->rd_idx <= buf->wr_idx); in uart_async_rx_data_consume()
122 return rx_data->free_buf_cnt > 0; in uart_async_rx_data_consume()
125 void uart_async_rx_reset(struct uart_async_rx *rx_data) in uart_async_rx_reset() argument
127 rx_data->free_buf_cnt = rx_data->config->buf_cnt; in uart_async_rx_reset()
128 rx_data->rd_idx = 0; in uart_async_rx_reset()
129 rx_data->rd_buf_idx = 0; in uart_async_rx_reset()
130 rx_data->drv_buf_idx = 0; in uart_async_rx_reset()
131 rx_data->pending_bytes = 0; in uart_async_rx_reset()
132 for (uint8_t i = 0; i < rx_data->config->buf_cnt; i++) { in uart_async_rx_reset()
133 buf_reset(get_buf(rx_data, i)); in uart_async_rx_reset()
137 int uart_async_rx_init(struct uart_async_rx *rx_data, in uart_async_rx_init() argument
142 memset(rx_data, 0, sizeof(*rx_data)); in uart_async_rx_init()
143 rx_data->config = config; in uart_async_rx_init()
144 rx_data->buf_len = (config->length / config->buf_cnt) - UART_ASYNC_RX_BUF_OVERHEAD; in uart_async_rx_init()
146 if (rx_data->buf_len >= BIT(7)) { in uart_async_rx_init()
149 uart_async_rx_reset(rx_data); in uart_async_rx_init()