modem: iface_uart: use ring_buf_{claim,finish} API
This API allows to drop use of preallocated isr_buf. Most importantly as a result RAM usage is reduced for each driver utilizing modem_context framework. Additionally there is less copying done in ISR context, as data is direcly read from UART FIFO to ring_buf. Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This commit is contained in:
parent
53007a8559
commit
763bd27c75
6 changed files with 22 additions and 24 deletions
|
@ -50,7 +50,6 @@ static struct gsm_modem {
|
|||
|
||||
struct modem_iface_uart_data gsm_data;
|
||||
struct k_delayed_work gsm_configure_work;
|
||||
char gsm_isr_buf[PPP_MRU];
|
||||
char gsm_rx_rb_buf[PPP_MRU * 3];
|
||||
|
||||
uint8_t *ppp_recv_buf;
|
||||
|
@ -647,8 +646,6 @@ static int gsm_init(const struct device *device)
|
|||
#endif /* CONFIG_MODEM_SIM_NUMBERS */
|
||||
#endif /* CONFIG_MODEM_SHELL */
|
||||
|
||||
gsm->gsm_data.isr_buf = &gsm->gsm_isr_buf[0];
|
||||
gsm->gsm_data.isr_buf_len = sizeof(gsm->gsm_isr_buf);
|
||||
gsm->gsm_data.rx_rb_buf = &gsm->gsm_rx_rb_buf[0];
|
||||
gsm->gsm_data.rx_rb_buf_len = sizeof(gsm->gsm_rx_rb_buf);
|
||||
|
||||
|
|
|
@ -53,6 +53,9 @@ static void modem_iface_uart_isr(const struct device *uart_dev,
|
|||
struct modem_context *ctx;
|
||||
struct modem_iface_uart_data *data;
|
||||
int rx = 0, ret;
|
||||
uint8_t *dst;
|
||||
uint32_t partial_size = 0;
|
||||
uint32_t total_size = 0;
|
||||
|
||||
ARG_UNUSED(user_data);
|
||||
|
||||
|
@ -66,22 +69,30 @@ static void modem_iface_uart_isr(const struct device *uart_dev,
|
|||
/* get all of the data off UART as fast as we can */
|
||||
while (uart_irq_update(ctx->iface.dev) &&
|
||||
uart_irq_rx_ready(ctx->iface.dev)) {
|
||||
rx = uart_fifo_read(ctx->iface.dev,
|
||||
data->isr_buf, data->isr_buf_len);
|
||||
if (!partial_size) {
|
||||
partial_size = ring_buf_put_claim(&data->rx_rb, &dst,
|
||||
UINT32_MAX);
|
||||
}
|
||||
if (!partial_size) {
|
||||
LOG_ERR("Rx buffer doesn't have enough space");
|
||||
modem_iface_uart_flush(&ctx->iface);
|
||||
break;
|
||||
}
|
||||
|
||||
rx = uart_fifo_read(ctx->iface.dev, dst, partial_size);
|
||||
if (rx <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = ring_buf_put(&data->rx_rb, data->isr_buf, rx);
|
||||
if (ret != rx) {
|
||||
LOG_ERR("Rx buffer doesn't have enough space. "
|
||||
"Bytes pending: %d, written: %d",
|
||||
rx, ret);
|
||||
modem_iface_uart_flush(&ctx->iface);
|
||||
k_sem_give(&data->rx_sem);
|
||||
break;
|
||||
}
|
||||
dst += rx;
|
||||
total_size += rx;
|
||||
partial_size -= rx;
|
||||
}
|
||||
|
||||
ret = ring_buf_put_finish(&data->rx_rb, total_size);
|
||||
__ASSERT_NO_MSG(ret == 0);
|
||||
|
||||
if (total_size > 0) {
|
||||
k_sem_give(&data->rx_sem);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,10 +20,6 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
struct modem_iface_uart_data {
|
||||
/* ISR char buffer */
|
||||
char *isr_buf;
|
||||
size_t isr_buf_len;
|
||||
|
||||
/* ring buffer char buffer */
|
||||
char *rx_rb_buf;
|
||||
size_t rx_rb_buf_len;
|
||||
|
|
|
@ -131,7 +131,6 @@ struct modem_data {
|
|||
|
||||
/* modem interface */
|
||||
struct modem_iface_uart_data iface_data;
|
||||
uint8_t iface_isr_buf[MDM_RECV_BUF_SIZE];
|
||||
uint8_t iface_rb_buf[MDM_MAX_DATA_LENGTH];
|
||||
|
||||
/* modem cmds */
|
||||
|
@ -1755,8 +1754,6 @@ static int modem_init(const struct device *dev)
|
|||
}
|
||||
|
||||
/* modem interface */
|
||||
mdata.iface_data.isr_buf = &mdata.iface_isr_buf[0];
|
||||
mdata.iface_data.isr_buf_len = sizeof(mdata.iface_isr_buf);
|
||||
mdata.iface_data.rx_rb_buf = &mdata.iface_rb_buf[0];
|
||||
mdata.iface_data.rx_rb_buf_len = sizeof(mdata.iface_rb_buf);
|
||||
ret = modem_iface_uart_init(&mctx.iface, &mdata.iface_data,
|
||||
|
|
|
@ -880,8 +880,6 @@ static int esp_init(const struct device *dev)
|
|||
}
|
||||
|
||||
/* modem interface */
|
||||
data->iface_data.isr_buf = &data->iface_isr_buf[0];
|
||||
data->iface_data.isr_buf_len = sizeof(data->iface_isr_buf);
|
||||
data->iface_data.rx_rb_buf = &data->iface_rb_buf[0];
|
||||
data->iface_data.rx_rb_buf_len = sizeof(data->iface_rb_buf);
|
||||
ret = modem_iface_uart_init(&data->mctx.iface, &data->iface_data,
|
||||
|
|
|
@ -169,7 +169,6 @@ struct esp_data {
|
|||
|
||||
/* modem interface */
|
||||
struct modem_iface_uart_data iface_data;
|
||||
uint8_t iface_isr_buf[MDM_RECV_BUF_SIZE];
|
||||
uint8_t iface_rb_buf[MDM_RING_BUF_SIZE];
|
||||
|
||||
/* modem cmds */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue