Skip to content

[nrf noup] Support intermediary SLM optimized modem UART backend #3021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions include/zephyr/modem/backend/uart_slm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/kernel.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/modem/pipe.h>
#include <zephyr/modem/stats.h>

#ifndef ZEPHYR_MODEM_BACKEND_UART_SLM_
#define ZEPHYR_MODEM_BACKEND_UART_SLM_

#ifdef __cplusplus
extern "C" {
#endif

struct slm_rx_queue_event {
uint8_t *buf;
size_t len;
};

struct modem_backend_uart_slm {
const struct device *uart;
struct modem_pipe pipe;
struct k_work_delayable receive_ready_work;
struct k_work transmit_idle_work;

#ifdef CONFIG_MODEM_STATS
struct modem_stats_buffer receive_buf_stats;
struct modem_stats_buffer transmit_buf_stats;
#endif
struct ring_buf transmit_rb;
struct k_work rx_disabled_work;
atomic_t state;

struct k_mem_slab rx_slab;
struct k_msgq rx_queue;
struct slm_rx_queue_event rx_event;
struct slm_rx_queue_event rx_queue_buf[CONFIG_MODEM_BACKEND_UART_SLM_BUFFER_COUNT];
uint32_t rx_buf_size;
uint8_t rx_buf_count;
};

struct modem_backend_uart_slm_config {
const struct device *uart;
uint8_t *receive_buf; /* Address must be word-aligned. */
uint32_t receive_buf_size;
uint8_t *transmit_buf;
uint32_t transmit_buf_size;
};

struct modem_pipe *modem_backend_uart_slm_init(struct modem_backend_uart_slm *backend,
const struct modem_backend_uart_slm_config *config);

#ifdef __cplusplus
}
#endif

#endif /* ZEPHYR_MODEM_BACKEND_UART_SLM_ */
1 change: 1 addition & 0 deletions subsys/modem/backends/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ if(CONFIG_MODEM_BACKEND_UART_ASYNC)
zephyr_library_sources_ifdef(CONFIG_MODEM_BACKEND_UART_ASYNC_HWFC modem_backend_uart_async_hwfc.c)
zephyr_library_sources_ifndef(CONFIG_MODEM_BACKEND_UART_ASYNC_HWFC modem_backend_uart_async.c)
endif()
zephyr_library_sources_ifdef(CONFIG_MODEM_BACKEND_UART_SLM modem_backend_uart_slm.c)
23 changes: 23 additions & 0 deletions subsys/modem/backends/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,26 @@ endif # MODEM_BACKEND_UART_ASYNC_HWFC
endif # MODEM_BACKEND_UART_ASYNC

endif # MODEM_BACKEND_UART

config MODEM_BACKEND_UART_SLM
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a bit confusing to have MODEM_BACKEND_UART be n when using MODEM_BACKEND_UART_SLM.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead you could just add a config MODEM_BACKEND_UART_ASYNC_SLM and make use of the existing MODEM_BACKEND_UART_ASYNC as it has all the configs you need? Well, as you want really.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows for a complete split from the MODEM_BACKEND_UART so that modem_backend_uart.c is not included.

That said, there is going to be further development on this area, which means that this will be reconsidered.

bool "SLM-optimized modem UART backend"
select MODEM_PIPE
select RING_BUFFER
depends on UART_ASYNC_API

if MODEM_BACKEND_UART_SLM

config MODEM_BACKEND_UART_SLM_BUFFER_COUNT
int "SLM modem UART backend buffer count"
range 2 4
default 3

config MODEM_BACKEND_UART_SLM_TRANSMIT_TIMEOUT_MS
int "SLM modem UART transmit timeout in milliseconds"
default 1000

config MODEM_BACKEND_UART_SLM_RECEIVE_IDLE_TIMEOUT_MS
int "SLM modem UART receive idle timeout in milliseconds"
default 30

endif # MODEM_BACKEND_UART_SLM
Loading