Skip to content

Commit 9e33182

Browse files
jtguggedaljhn-nordic
authored andcommitted
nrf_modem_lib: Add nrf_modem_lib_trace_peek_at() API
Add API to peek modem trace data from a specific offset. Support for the API is added in the flash backend. Signed-off-by: Jan Tore Guggedal <[email protected]>
1 parent 994aa70 commit 9e33182

File tree

9 files changed

+528
-137
lines changed

9 files changed

+528
-137
lines changed

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,11 @@ Modem libraries
652652
* The order of the ``LTE_LC_MODEM_EVT_SEARCH_DONE`` modem event, and registration and cell related events.
653653
See the :ref:`migration guide <migration_3.2_required>` for more information.
654654

655+
* :ref:`nrf_modem_lib_readme` library:
656+
657+
* Added the :c:func:`nrf_modem_lib_trace_peek_at` function to the :c:struct:`nrf_modem_lib_trace_backend` interface to peek trace data at a byte offset without consuming it.
658+
Support for this API has been added to the flash trace backend.
659+
655660
Multiprotocol Service Layer libraries
656661
-------------------------------------
657662

include/modem/nrf_modem_lib_trace.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,25 @@ int nrf_modem_lib_trace_read(uint8_t *buf, size_t len);
103103
*/
104104
int nrf_modem_lib_trace_clear(void);
105105

106+
/**
107+
* @brief Peek trace data at offset without consuming it
108+
*
109+
* Copy up to @p len bytes starting at @p offset from the oldest available data into @p buf
110+
* without advancing the backend read cursor.
111+
*
112+
* @param offset Byte offset relative to the oldest available byte
113+
* @param buf Output buffer
114+
* @param len Size of output buffer
115+
*
116+
* @return number of bytes copied, negative errno on failure.
117+
* @retval -ENOTSUP if the operation is not supported by the trace backend.
118+
* @retval -EPERM if the trace backend is not initialized.
119+
* @retval -EINVAL if the buffer is NULL.
120+
* @retval -EFAULT if the offset is beyond the available trace data.
121+
* @retval -ENODATA if no data is available at the offset.
122+
*/
123+
int nrf_modem_lib_trace_peek_at(size_t offset, uint8_t *buf, size_t len);
124+
106125
#if defined(CONFIG_NRF_MODEM_LIB_TRACE_BACKEND_BITRATE) || defined(__DOXYGEN__)
107126
/** @brief Get the last measured rolling average bitrate of the trace backend.
108127
*

include/modem/trace_backend.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#ifndef TRACE_BACKEND_H__
88
#define TRACE_BACKEND_H__
99

10+
#include <zephyr/kernel.h>
11+
1012
#ifdef __cplusplus
1113
extern "C" {
1214
#endif
@@ -92,6 +94,22 @@ struct nrf_modem_lib_trace_backend {
9294
*/
9395
int (*read)(void *buf, size_t len);
9496

97+
/**
98+
* @brief Peek trace data at a byte offset without consuming it.
99+
*
100+
* Copy up to @p len bytes starting at @p offset from the beginning of the
101+
* currently available trace data into @p buf. The oldest available byte is at offset 0.
102+
*
103+
* @note Set to @c NULL if this operation is not supported by the trace backend.
104+
*
105+
* @param offset Start offset from the oldest available byte.
106+
* @param buf Output buffer.
107+
* @param len Size of output buffer.
108+
*
109+
* @return Number of bytes copied on success, negative errno on failure.
110+
*/
111+
int (*peek_at)(size_t offset, void *buf, size_t len);
112+
95113
/**
96114
* @brief Erase all captured trace data in the compile-time selected trace backend.
97115
*

lib/nrf_modem_lib/nrf_modem_lib_trace.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,15 @@ int nrf_modem_lib_trace_read(uint8_t *buf, size_t len)
516516
return read;
517517
}
518518

519+
int nrf_modem_lib_trace_peek_at(size_t offset, uint8_t *buf, size_t len)
520+
{
521+
if (!trace_backend.peek_at) {
522+
return -ENOTSUP;
523+
}
524+
525+
return trace_backend.peek_at(offset, buf, len);
526+
}
527+
519528
int nrf_modem_lib_trace_clear(void)
520529
{
521530
int err;

0 commit comments

Comments
 (0)