Skip to content

Commit

Permalink
modem: cmux: make work buffer size configurable
Browse files Browse the repository at this point in the history
A Kconfig item is added and the buffer
is embedded into the modem_cmux struct.
The default value is increased from 16 to 64 bytes in
an effort to reduce the number of modem_pipe_receive() calls.

CONFIG_MODEM_CHAT_LOG_BUFFER is renamed
to CONFIG_MODEM_CHAT_LOG_BUFFER_SIZE for consistency.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
  • Loading branch information
tomi-font authored and fabiobaltieri committed Mar 26, 2024
1 parent 419a398 commit 18170eb
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
6 changes: 6 additions & 0 deletions doc/releases/migration-guide-3.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ LoRaWAN
MCUmgr
======

Modem
=====

* The ``CONFIG_MODEM_CHAT_LOG_BUFFER`` Kconfig option was
renamed to :kconfig:option:`MODEM_CHAT_LOG_BUFFER_SIZE`.

Shell
=====

Expand Down
2 changes: 2 additions & 0 deletions include/zephyr/modem/cmux.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ struct modem_cmux {
uint16_t receive_buf_size;
uint16_t receive_buf_len;

uint8_t work_buf[CONFIG_MODEM_CMUX_WORK_BUFFER_SIZE];

/* Transmit buffer */
struct ring_buf transmit_rb;
struct k_mutex transmit_rb_lock;
Expand Down
9 changes: 7 additions & 2 deletions subsys/modem/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ config MODEM_CHAT

if MODEM_CHAT

config MODEM_CHAT_LOG_BUFFER
int "Modem chat log buffer size"
config MODEM_CHAT_LOG_BUFFER_SIZE
int "Modem chat log buffer size in bytes"
default 128

endif
Expand All @@ -29,6 +29,11 @@ config MODEM_CMUX

if MODEM_CMUX

config MODEM_CMUX_WORK_BUFFER_SIZE
int "CMUX module work buffer size in bytes"
range 16 1500
default 64

module = MODEM_CMUX
module-str = modem_cmux
source "subsys/logging/Kconfig.template.log_config"
Expand Down
2 changes: 1 addition & 1 deletion subsys/modem/modem_chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ LOG_MODULE_REGISTER(modem_chat, CONFIG_MODEM_MODULES_LOG_LEVEL);

#if defined(CONFIG_LOG) && (CONFIG_MODEM_MODULES_LOG_LEVEL == LOG_LEVEL_DBG)

static char log_buffer[CONFIG_MODEM_CHAT_LOG_BUFFER];
static char log_buffer[CONFIG_MODEM_CHAT_LOG_BUFFER_SIZE];

static void modem_chat_log_received_command(struct modem_chat *chat)
{
Expand Down
7 changes: 3 additions & 4 deletions subsys/modem/modem_cmux.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,11 +842,10 @@ static void modem_cmux_receive_handler(struct k_work *item)
{
struct k_work_delayable *dwork = k_work_delayable_from_work(item);
struct modem_cmux *cmux = CONTAINER_OF(dwork, struct modem_cmux, receive_work);
uint8_t buf[16];
int ret;

/* Receive data from pipe */
ret = modem_pipe_receive(cmux->pipe, buf, sizeof(buf));
ret = modem_pipe_receive(cmux->pipe, cmux->work_buf, sizeof(cmux->work_buf));
if (ret < 1) {
if (ret < 0) {
LOG_ERR("Pipe receiving error: %d", ret);
Expand All @@ -855,8 +854,8 @@ static void modem_cmux_receive_handler(struct k_work *item)
}

/* Process received data */
for (uint16_t i = 0; i < (uint16_t)ret; i++) {
modem_cmux_process_received_byte(cmux, buf[i]);
for (int i = 0; i < ret; i++) {
modem_cmux_process_received_byte(cmux, cmux->work_buf[i]);
}

/* Reschedule received work */
Expand Down

0 comments on commit 18170eb

Please sign in to comment.