mgmt: smp: Change smp_shell_rx_byte to process data in bulk

The smp_shell_rx_byte has been renamed to smp_shell_rx_bytes and now
accepts data buffer pointer and its size as parameters. Return value
has been changed to size_t and represents number of bytes processed from
the given buffer.

The change has been done to more efficiently serve most common scenario
when the function is called in loop to process buffer, byte by byte.
Previously such operation required passing each byte separately,
with the change the function will work directly on source buffer
reducing number of calls and byte copy operations.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
This commit is contained in:
Dominik Ermel 2020-08-18 23:13:29 +00:00 committed by Carles Cufí
commit 1b617a368f
3 changed files with 44 additions and 39 deletions

View file

@ -34,6 +34,9 @@ static void uart_rx_handle(const struct device *dev,
uint32_t len;
uint32_t rd_len;
bool new_data = false;
#ifdef CONFIG_MCUMGR_SMP_SHELL
struct smp_shell_data *const smp = &sh_uart->ctrl_blk->smp;
#endif
do {
len = ring_buf_put_claim(sh_uart->rx_ringbuf, &data,
@ -53,14 +56,7 @@ static void uart_rx_handle(const struct device *dev,
/* Divert bytes from shell handling if it is
* part of an mcumgr frame.
*/
size_t i;
for (i = 0; i < rd_len; i++) {
if (!smp_shell_rx_byte(&sh_uart->ctrl_blk->smp,
data[i])) {
break;
}
}
size_t i = smp_shell_rx_bytes(smp, data, rd_len);
rd_len -= i;
@ -86,7 +82,7 @@ static void uart_rx_handle(const struct device *dev,
* feeding it to SMP as a part of mcumgr frame.
*/
if ((rd_len != 0) &&
smp_shell_rx_byte(&sh_uart->ctrl_blk->smp, dummy)) {
(smp_shell_rx_bytes(smp, &dummy, 1) == 1)) {
new_data = true;
}
#endif /* CONFIG_MCUMGR_SMP_SHELL */