Skip to content

Commit 3ce24dc

Browse files
committed
sm_host: DTR/RI implementation for host side
Terms: Data Terminal Equipment (DTE), AKA. host. Data Communication Equipment (DCE), AKA. Serial Modem. Data Terminal Ready (DTR) Ring Indicate (RI) DTR operation for DTE: When DTE wants to enable UART, it resumes UART, enables RX, asserts DTR and sends any possible pending TX data. When DTE wants to disable UART, it aborts possible TX, deasserts DTR, disables RX and suspends UART. The UART control in DTE can be done either manual or automatic. With automatic control, UART will be enabled when there is a TX request and disabled after a configured timeout has passed since UART was last active. Replaces following Kconfigs with dtr-gpios & ri-gpios: CONFIG_SM_HOST_POWER_PIN, CONFIG_SM_HOST_POWER_PIN_TIME and CONFIG_SM_HOST_INDICATE_PIN. Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
1 parent 91e01d1 commit 3ce24dc

11 files changed

Lines changed: 551 additions & 260 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
3+
4+
description: |
5+
DTE side of DTR/RI UART
6+
7+
compatible: "nordic,dte-dtr"
8+
9+
properties:
10+
dtr-gpios:
11+
type: phandle-array
12+
description: Output. Data Terminal Ready pin
13+
required: true
14+
15+
ri-gpios:
16+
type: phandle-array
17+
description: Input. Ring Indicator pin
18+
required: true

include/sm_host.h

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,45 +57,62 @@ enum at_cmd_state {
5757
typedef void (*sm_data_handler_t)(const uint8_t *data, size_t datalen);
5858

5959
/**
60-
* @typedef sm_ind_handler_t
60+
* @typedef sm_ri_handler_t
6161
*
62-
* Handler to handle @kconfig{CONFIG_SM_HOST_INDICATE_PIN} signal from Serial Modem.
62+
* Handler to handle the Ring Indicate (RI) signal from Serial Modem.
6363
*/
64-
typedef void (*sm_ind_handler_t)(void);
64+
typedef void (*sm_ri_handler_t)(void);
6565

6666
/**@brief Initialize Serial Modem Host library.
6767
*
6868
* @param handler Pointer to a handler function of type @ref sm_data_handler_t.
69+
* @param automatic_uart If true, DTR and UART are automatically managed by the library.
70+
* @param inactivity_timeout Inactivity timeout for DTR and UART disablement. Only used if @p
71+
* automatic is true.
6972
*
7073
* @return Zero on success, non-zero otherwise.
7174
*/
72-
int sm_host_init(sm_data_handler_t handler);
75+
int sm_host_init(sm_data_handler_t handler, bool automatic_uart, k_timeout_t inactivity_timeout);
7376

7477
/**@brief Un-initialize Serial Modem Host
7578
*/
7679
int sm_host_uninit(void);
7780

7881
/**
79-
* @brief Register callback for @kconfig{CONFIG_SM_HOST_INDICATE_PIN} indication
82+
* @brief Register callback for Ring Indicate (RI) pin.
8083
*
81-
* @param handler Pointer to a handler function of type @ref sm_ind_handler_t.
82-
* @param wakeup Enable/disable System Off wakeup by GPIO Sense.
84+
* @param handler Pointer to a handler function of type @ref sm_ri_handler_t.
8385
*
84-
* @retval Zero Success.
85-
* @retval -EFAULT if @kconfig{CONFIG_SM_HOST_INDICATE_PIN} is not defined.
86+
* @retval Zero on success. Otherwise, a (negative) error code is returned.
8687
*/
87-
int sm_host_register_ind(sm_ind_handler_t handler, bool wakeup);
88+
int sm_host_register_ri_handler(sm_ri_handler_t handler);
8889

8990
/**
90-
* @brief Toggle power pin of the nRF91 Series device configured with
91-
* @kconfig{CONFIG_SM_HOST_POWER_PIN}.
91+
* @brief Configure automatic DTR UART handling
9292
*
93-
* The pin is enabled for the time specified in @kconfig{CONFIG_SM_HOST_POWER_PIN_TIME}
94-
* and then disabled.
93+
* If automatic DTR UART handling is enabled, the library will enable DTR UART when RI
94+
* signal is detected, and disable it after inactivity timeout.
95+
*
96+
* @param automatic If true, DTR UART is automatically managed by the library.
97+
* @param inactivity Inactivity timeout for DTR UART disablement. Only used if @p
98+
* automatic is true.
9599
*
96100
* @return Zero on success, non-zero otherwise.
97101
*/
98-
int sm_host_power_pin_toggle(void);
102+
void sm_host_configure_dtr_uart(bool automatic, k_timeout_t inactivity);
103+
104+
/**
105+
* @brief Disable DTR UART
106+
*
107+
* Disables DTR UART. Disables automatic DTR UART handling.
108+
*/
109+
void sm_host_disable_dtr_uart(void);
110+
111+
/** @brief Enable DTR UART
112+
*
113+
* Enables DTR UART. Disables automatic DTR UART handling.
114+
*/
115+
void sm_host_enable_dtr_uart(void);
99116

100117
/**
101118
* @brief Function to send an AT command in Serial Modem command mode

lib/sm_host/Kconfig

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
menuconfig SM_HOST
88
bool "Serial Modem Host Library"
99
depends on SERIAL
10-
depends on UART_ASYNC_API
11-
depends on RING_BUFFER
10+
select UART_ASYNC_API
11+
select RING_BUFFER
1212
select UART_USE_RUNTIME_CONFIGURE
13+
select GPIO_GET_CONFIG
14+
select PM_DEVICE
1315

1416
if SM_HOST
1517

@@ -72,26 +74,6 @@ config SM_HOST_CR_LF_TERMINATION
7274

7375
endchoice
7476

75-
config SM_HOST_POWER_PIN
76-
int "Power pin"
77-
default -1
78-
help
79-
Interface GPIO to toggle power pin of the nRF91 Series device.
80-
81-
config SM_HOST_POWER_PIN_TIME
82-
int "Power pin active time"
83-
default 100
84-
help
85-
GPIO active time in milliseconds. This setting specifies
86-
the period length for the pin to be active.
87-
88-
config SM_HOST_INDICATE_PIN
89-
int "Indicate pin"
90-
default -1
91-
help
92-
Interface GPIO pin used by Serial Modem to indicate that data is available or
93-
an unexpected reset has occurred.
94-
9577
module = SM_HOST
9678
module-str = SM Host
9779
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"

0 commit comments

Comments
 (0)