Skip to content

Commit 982b51b

Browse files
committed
app: Buffer URCs during datamode
URCs from modem and other SM threads are buffered during the data mode. When datamode is exited, all the received URCs will be received. Note: Currently this prevents the TCP and UDP clients (and servers) from receiving data in data mode, as the send is done from a thread, which is considered URC. There is a work item to refactor the TCP and UDP clients (and servers), which will address this. Signed-off-by: Markus Lassila <[email protected]>
1 parent 82459c9 commit 982b51b

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

app/src/sm_at_host.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ static bool exit_datamode(void)
133133

134134
k_mutex_unlock(&mutex_mode);
135135

136+
/* Flush the TX buffer. */
137+
sm_tx_write(NULL, 0, true, K_NO_WAIT);
138+
136139
return ret;
137140
}
138141

@@ -725,20 +728,14 @@ AT_MONITOR(at_notify, ANY, notification_handler);
725728

726729
static void notification_handler(const char *notification)
727730
{
728-
if (get_sm_mode() == SM_AT_COMMAND_MODE) {
729-
730731
#if defined(CONFIG_SM_PPP)
731-
if (!sm_fwd_cgev_notifs
732-
&& !strncmp(notification, "+CGEV: ", strlen("+CGEV: "))) {
733-
/* CGEV notifications are silenced. Do not forward them. */
734-
return;
735-
}
736-
#endif
737-
sm_at_send_internal(CRLF_STR, strlen(CRLF_STR), SM_DEBUG_PRINT_FULL);
738-
sm_at_send_str(notification);
739-
} else {
740-
LOG_DBG("Drop notification: %s", notification);
732+
if (!sm_fwd_cgev_notifs && !strncmp(notification, "+CGEV: ", strlen("+CGEV: "))) {
733+
/* CGEV notifications are silenced. Do not forward them. */
734+
return;
741735
}
736+
#endif
737+
sm_at_send_internal(CRLF_STR, strlen(CRLF_STR), SM_DEBUG_PRINT_FULL);
738+
sm_at_send_str(notification);
742739
}
743740

744741
void rsp_send_ok(void)

app/src/sm_cmux.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ static void nonblock_tx_work_fn(struct k_work *work)
198198
LOG_ERR("No URC context");
199199
return;
200200
}
201+
if (in_datamode()) {
202+
/* Do not send URCs in datamode. */
203+
return;
204+
}
201205

202206
/* Do not lock the URC mutex. */
203207
do {

app/src/sm_uart_handler.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,11 @@ static void tx_write_nonblock_fn(struct k_work *)
441441
return;
442442
}
443443

444+
if (in_datamode()) {
445+
/* Do not send URCs in datamode. */
446+
return;
447+
}
448+
444449
/* Do not lock the URC mutex.
445450
* This is the only reader and URC context ownership cannot be transferred as we
446451
* are in the same work queue that processes AT-commands.

doc/app/sm_data_mode.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ The |SM| (SM) application can run in the two operation modes defined by the AT c
1212
When running in data mode, the application does the following:
1313

1414
* It considers all the data received from the MCU over the UART bus as arbitrary data to be streamed through the LTE network by various service modules.
15-
* It considers all the data streamed from a remote service as arbitrary data to be sent to the MCU over the UART bus.
15+
* It buffers the URCs received from modem and threads and sends them to the MCU only after exiting data mode.
16+
* For TLS and UDP client (and servers), it considers all the data streamed from a remote service as arbitrary data to be sent to the MCU over the UART bus.
1617

1718
Overview
1819
********

0 commit comments

Comments
 (0)