Skip to content

Commit cf583ef

Browse files
committed
app: Buffer all URC messages
When dedicated AT pipe is in datamode, buffer URC messages. Don't bypass buffering, at URC might come from ISR context. Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
1 parent 4e983c2 commit cf583ef

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

app/src/sm_at_host.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -343,22 +343,14 @@ struct sm_at_host_ctx *sm_at_host_get_urc_ctx(void)
343343
return ctx;
344344
}
345345
}
346-
return NULL;
347-
}
348-
349-
ctx = sm_at_host_get_ctx_from(sm_cmux_get_dlci(urc_channel));
350-
if (in_at_mode(ctx)) {
351-
return ctx;
346+
} else {
347+
return sm_at_host_get_ctx_from(sm_cmux_get_dlci(urc_channel));
352348
}
353-
return NULL;
354349
}
355350
#endif /* CONFIG_SM_CMUX */
356351

357-
ctx = SYS_SLIST_PEEK_HEAD_CONTAINER(&instance_list, ctx, node);
358-
if (in_at_mode(ctx)) {
359-
return ctx;
360-
}
361-
return NULL;
352+
/* Fallback to first instance if no context is found */
353+
return SYS_SLIST_PEEK_HEAD_CONTAINER(&instance_list, ctx, node);
362354
}
363355

364356
struct modem_pipe *sm_at_host_get_pipe(struct sm_at_host_ctx *ctx)
@@ -1034,8 +1026,7 @@ static int sm_at_send_internal(struct sm_at_host_ctx *ctx, const uint8_t *data,
10341026
return -EINTR;
10351027
}
10361028

1037-
/* Even if this is URC, bypass buffering if pipe is free */
1038-
if (urc && (!ctx || (ctx && !is_idle(ctx)))) {
1029+
if (urc) {
10391030
if (ctx == NULL) {
10401031
ctx = sm_at_host_get_urc_ctx();
10411032
LOG_DBG("URC: %s", (const char *)data);
@@ -1048,6 +1039,9 @@ static int sm_at_send_internal(struct sm_at_host_ctx *ctx, const uint8_t *data,
10481039
ret = ring_buf_put(&urc_buf, data, len);
10491040
if (ret < len) {
10501041
LOG_ERR("URC buffer full, dropped %d bytes", len - ret);
1042+
/* Safe to assume that already buffered URCs are outdated as well */
1043+
ring_buf_reset(&urc_buf);
1044+
return -EIO;
10511045
}
10521046
} else {
10531047
/* Pipe specific URC */

0 commit comments

Comments
 (0)