Skip to content

Commit c49596a

Browse files
Balaji Srinivasancarlescufi
authored andcommitted
lib: nrf_modem: Create new module for modem traces
Created a new module that handles starting, stopping and forwarding of modem traces to selected (compile time) transport. This is created for the purpose of separating the tracing functionality from the nrf_modem_os.c glue layer and also making future improvements like deferred trace processing in a dedicated thread/work queue. Fixes CIA-454. Signed-off-by: Balaji Srinivasan <[email protected]>
1 parent fd72f45 commit c49596a

File tree

21 files changed

+1223
-271
lines changed

21 files changed

+1223
-271
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ Kconfig* @tejlmand
201201
/tests/lib/lte_lc/ @jtguggedal
202202
/tests/lib/modem_jwt/ @SeppoTakalo
203203
/tests/lib/sms/ @trantanen @tokangas
204+
/tests/lib/modem_trace/ @balaji-nordic
204205
/tests/modules/lib/cddl-gen/ @oyvindronningstad
205206
/tests/modules/mcuboot/external_flash/ @hakonfam @sigvartmh
206207
/tests/modules/tfm/ @hakonfam @SebastianBoe

doc/nrf/libraries/modem/nrf_modem_lib.rst

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Modem library integration layer
99

1010

1111
The Modem library integration layer handles the integration of the Modem library into |NCS|.
12-
The integration layer is constituted by the library wrapper and functionalities like socket offloading, OS abstraction, memory reservation by the Partition manager, and diagnostics.
12+
The integration layer is constituted by the library wrapper and functionalities like socket offloading, OS abstraction, memory reservation by the Partition manager, handling modem traces, and diagnostics.
1313

1414
Library wrapper
1515
***************
@@ -31,6 +31,8 @@ If your application performs an update of the nRF9160 modem firmware, you must d
3131
The library wrapper also coordinates the shutdown operation among different parts of the application that use the Modem library.
3232
This is done by the :c:func:`nrf_modem_lib_shutdown` function call, by waking the sleeping threads when the modem is being shut down.
3333

34+
When :kconfig:`CONFIG_NRF_MODEM_LIB_TRACE_ENABLED` Kconfig option is enabled, the library wrapper enables proprietary modem traces and forwards it to the `Modem trace module`_.
35+
3436
When using the Modem library in |NCS|, the library should be initialized and shutdown using the :c:func:`nrf_modem_lib_init` and :c:func:`nrf_modem_lib_shutdown` function calls, respectively.
3537

3638
Socket offloading
@@ -62,6 +64,23 @@ The behavior of the functions in the OS abstraction layer is dependent on the |N
6264
This is relevant for functions such as :c:func:`nrf_modem_os_shm_tx_alloc`, which uses :ref:`Zephyr's Heap implementation <zephyr:heap_v2>` to dynamically allocate memory.
6365
In this case, the characteristics of the allocations made by these functions depend on the heap implementation by Zephyr.
6466

67+
Modem trace module
68+
******************
69+
The modem trace module is implemented in :file:`nrf\\lib\\nrf_modem_lib\\nrf_modem_lib_trace.c`.
70+
71+
The module provides the functionality for starting, stopping, and forwarding of modem traces to a transport medium that can be set by enabling any one of the following Kconfig options:
72+
73+
* :kconfig:`CONFIG_NRF_MODEM_LIB_TRACE_MEDIUM_UART` to send modem traces over UARTE1
74+
* :kconfig:`CONFIG_NRF_MODEM_LIB_TRACE_MEDIUM_RTT` to send modem traces over SEGGER RTT
75+
76+
When :kconfig:`CONFIG_NRF_MODEM_LIB_TRACE_ENABLED` Kconfig option is enabled, :c:func:`nrf_modem_lib_init` sends the trace memory configuration to the modem.
77+
When this happens, the modem starts sending startup trace data.
78+
If the application wants the trace data, :c:func:`nrf_modem_lib_trace_init` must be called before :c:func:`nrf_modem_lib_init`.
79+
This is done automatically when using the OS Abstraction layer.
80+
If the application wants to stop an ongoing trace session, it can use the :c:func:`nrf_modem_lib_trace_stop` function.
81+
The :c:func:`nrf_modem_lib_trace_start` function supports activating a subset of traces or all traces.
82+
It is also possible to use this function to run a trace session either for a specific time interval or until a given amount of trace data is received.
83+
6584
.. _partition_mgr_integration:
6685

6786
Partition manager integration
@@ -125,9 +144,13 @@ The report will be printed by a dedicated work queue that is distinct from the s
125144
API documentation
126145
*****************
127146

128-
| Header file: :file:`include/modem/nrf_modem_lib.h`
147+
| Header file: :file:`include/modem/nrf_modem_lib.h`, :file:`include/modem/nrf_modem_lib_trace.h`
129148
| Source file: :file:`lib/nrf_modem_lib.c`
130149
131150
.. doxygengroup:: nrf_modem_lib
132151
:project: nrf
133152
:members:
153+
154+
.. doxygengroup:: nrf_modem_lib_trace
155+
:project: nrf
156+
:members:

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ Modem libraries
226226

227227
* Can now parse AT command responses containing the response result, for example, ``OK`` or ``ERROR``.
228228

229+
* :ref:`nrf_modem_lib_readme`:
230+
231+
* The modem trace handling is moved from :file:`nrf_modem_os.c` to a new file :file:`nrf_modem_lib_trace.c`, which also provides the API for starting a trace session for a given time interval or until a given size of trace data is received.
232+
229233
Event manager
230234
-------------
231235

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright (c) 2021 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/**@file nrf_modem_lib_trace.h
8+
*
9+
* @defgroup nrf_modem_lib_trace nRF91 Modem trace module
10+
* @{
11+
*/
12+
#ifndef NRF_MODEM_LIB_TRACE_H__
13+
#define NRF_MODEM_LIB_TRACE_H__
14+
15+
#include <stdint.h>
16+
17+
/** @brief Initialize the modem trace module.
18+
*
19+
* Initializes the module and the trace transport medium.
20+
*
21+
* @return Zero on success, non-zero otherwise.
22+
*/
23+
int nrf_modem_lib_trace_init(void);
24+
25+
/**@brief Trace mode
26+
*
27+
* The trace mode can be used to filter the traces.
28+
*/
29+
enum nrf_modem_lib_trace_mode {
30+
NRF_MODEM_LIB_TRACE_COREDUMP_ONLY = 1, /**< Coredump only. */
31+
NRF_MODEM_LIB_TRACE_ALL = 2, /**< LTE, IP, GNSS, and coredump. */
32+
NRF_MODEM_LIB_TRACE_IP_ONLY = 4, /**< IP. */
33+
NRF_MODEM_LIB_TRACE_LTE_IP = 5, /**< LTE and IP. */
34+
};
35+
36+
/** @brief Start a trace session.
37+
*
38+
* This function sends AT command that requests the modem to start sending traces.
39+
*
40+
* @param trace_mode Trace mode
41+
* @param duration Trace duration in seconds. If set to 0, the trace session will
42+
* continue until @ref nrf_modem_lib_trace_stop is called or until
43+
* the required size of max trace data (specified by the
44+
* @p max_size parameter) is received.
45+
* @param max_size Maximum size (in bytes) of trace data that should be received.
46+
* The tracing will be stopped after receiving @p max_size
47+
* bytes. If set to 0, the trace session will continue until
48+
* @ref nrf_modem_lib_trace_stop is called or until the duration
49+
* set via the @p duration parameter is reached.
50+
* To ensure the integrity of the trace output, the
51+
* modem_trace module will never skip a trace message. For
52+
* this purpose, if it detects that a received trace won't fit
53+
* in the maximum allowed size, it will stop the trace session
54+
* without sending out that trace to the transport medium.
55+
*
56+
* @return Zero on success, non-zero otherwise.
57+
*/
58+
int nrf_modem_lib_trace_start(enum nrf_modem_lib_trace_mode trace_mode, uint16_t duration,
59+
uint32_t max_size);
60+
61+
/** @brief Process modem trace data
62+
*
63+
* This function should only be called to process a trace received from the modem by the
64+
* nrf_modem_os_trace_put() function. This function forwards the trace to the selected
65+
* (during compile time) trace transport medium. When the maximum number of trace bytes
66+
* (configured via the @ref nrf_modem_lib_trace_start) is received, this function stops the trace
67+
* session.
68+
*
69+
* @param data Memory buffer containing the modem trace data.
70+
* @param len Memory buffer length.
71+
*
72+
* @return Zero on success, non-zero otherwise.
73+
*/
74+
int nrf_modem_lib_trace_process(const uint8_t *data, uint32_t len);
75+
76+
/** @brief Stop an ongoing trace session
77+
*
78+
* This function stops an ongoing trace session.
79+
*
80+
* @return Zero on success, non-zero otherwise.
81+
*/
82+
int nrf_modem_lib_trace_stop(void);
83+
84+
#endif /* NRF_MODEM_LIB_TRACE_H__ */
85+
/**@} */

lib/lte_link_control/lte_lc.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ enum lte_lc_notif_type {
5555

5656
static bool is_initialized;
5757

58-
#if defined(CONFIG_NRF_MODEM_LIB_TRACE_ENABLED)
59-
/* Enable modem trace */
60-
static const char mdm_trace[] = "AT%%XMODEMTRACE=1,2";
61-
#endif
62-
6358
#if defined(CONFIG_LTE_LOCK_BANDS)
6459
/* Lock LTE bands 3, 4, 13 and 20 (volatile setting) */
6560
static const char lock_bands[] = "AT%%XBANDLOCK=2,\""CONFIG_LTE_LOCK_BAND_MASK
@@ -608,11 +603,6 @@ static int init_and_config(void)
608603
return -EIO;
609604
}
610605
#endif
611-
#if defined(CONFIG_NRF_MODEM_LIB_TRACE_ENABLED)
612-
if (nrf_modem_at_printf(mdm_trace)) {
613-
return -EIO;
614-
}
615-
#endif
616606
#if defined(CONFIG_LTE_LOCK_BANDS)
617607
/* Set LTE band lock (volatile setting).
618608
* Has to be done every time before activating the modem.

lib/nrf_modem_lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ zephyr_library()
77
zephyr_library_sources(nrf_modem_lib.c)
88
zephyr_library_sources(nrf_modem_os.c)
99
zephyr_library_sources_ifdef(CONFIG_NET_SOCKETS nrf91_sockets.c)
10+
zephyr_library_sources_ifdef(CONFIG_NRF_MODEM_LIB_TRACE_ENABLED nrf_modem_lib_trace.c)
1011
zephyr_library_sources(errno_sanity.c)
1112
zephyr_library_sources(shmem_sanity.c)

lib/nrf_modem_lib/Kconfig

Lines changed: 1 addition & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -19,163 +19,6 @@ menuconfig NRF_MODEM_LIB
1919

2020
if NRF_MODEM_LIB
2121

22-
# Redefine this symbol here and give it a non-zero default value
23-
# so that the Zephyr system heap is enabled, the offloading layer
24-
# depends on it
25-
config HEAP_MEM_POOL_SIZE
26-
int
27-
default 512
28-
29-
config NRF_MODEM_LIB_SYS_INIT
30-
bool "Initialize during SYS_INIT"
31-
default y
32-
help
33-
Initialize the Modem library automatically during the SYS_INIT sequence.
34-
Please note that initialization is synchronous and can take up to one
35-
minute in case the modem firmware is updated.
36-
37-
config NRF_MODEM_LIB_TRACE_ENABLED
38-
bool
39-
prompt "Enable proprietary traces"
40-
help
41-
The default size of the Trace region is defined by the
42-
NRF_MODEM_LIB_SHMEM_TRACE_SIZE option.
43-
44-
if NRF_MODEM_LIB_TRACE_ENABLED
45-
46-
choice NRF_MODEM_LIB_TRACE_MEDIUM
47-
prompt "nRF modem trace medium"
48-
default NRF_MODEM_LIB_TRACE_MEDIUM_UART
49-
50-
config NRF_MODEM_LIB_TRACE_MEDIUM_UART
51-
bool "Send modem trace over UARTE1"
52-
# Modem tracing over UART use the UARTE1 as dedicated peripheral.
53-
# This enable UARTE1 peripheral and includes nrfx UARTE driver.
54-
select NRFX_UARTE1
55-
56-
config NRF_MODEM_LIB_TRACE_MEDIUM_RTT
57-
bool "Send modem trace over SEGGER RTT"
58-
select USE_SEGGER_RTT
59-
60-
endchoice # NRF_MODEM_LIB_TRACE_MEDIUM
61-
62-
if NRF_MODEM_LIB_TRACE_MEDIUM_RTT
63-
64-
config NRF_MODEM_LIB_TRACE_MEDIUM_RTT_BUF_SIZE
65-
int "Size of the buffer used by the RTT to write messages"
66-
default 255
67-
68-
endif # NRF_MODEM_LIB_TRACE_MEDIUM_RTT
69-
70-
endif # NRF_MODEM_LIB_TRACE_ENABLED
71-
72-
config NRF91_SOCKET_SEND_SPLIT_LARGE_BLOCKS
73-
bool "Split large blocks passed to send() or sendto()"
74-
default n
75-
help
76-
Workaround a limitation in the Modem library regarding the return
77-
value for send() or sendto() calls larger than the module can handle.
78-
It should send the data up to the maximum, and return that as the return value.
79-
Instead, it returns error 22.
80-
81-
config NRF91_SOCKET_BLOCK_LIMIT
82-
int "Maximum size the modem can send"
83-
default 2048
84-
help
85-
Blocks larger than this value will be split into two or more
86-
send() or sendto() calls. This may not work for certain kinds
87-
of sockets or certain flag parameter values.
88-
89-
config NRF_MODEM_LIB_SENDMSG_BUF_SIZE
90-
int "Size of the sendmsg intermediate buffer"
91-
default 128
92-
help
93-
Size of an intermediate buffer used by `sendmsg` to repack data and
94-
therefore limit the number of `sendto` calls. The buffer is created
95-
in a static memory, so it does not impact stack/heap usage. In case
96-
the repacked message would not fit into the buffer, `sendmsg` sends
97-
each message part separately.
98-
99-
comment "Heap and buffers"
100-
101-
config NRF_MODEM_LIB_HEAP_SIZE
102-
int "Library heap size"
103-
default 1024
104-
range 512 4096
105-
help
106-
Size of the heap buffer used by the library.
107-
This heap is allocated in the application's RAM.
108-
109-
config NRF_MODEM_LIB_SHMEM_CTRL_SIZE
110-
hex
111-
default NRF_MODEM_SHMEM_CTRL_SIZE
112-
help
113-
Size of the shared memory area used for control structures.
114-
This is a constant for a given library build, and is exported
115-
by the library via NRF_MODEM_SHMEM_CTRL_SIZE.
116-
117-
config NRF_MODEM_LIB_SHMEM_TX_SIZE
118-
int "TX region size"
119-
range 1024 16384
120-
default 8192
121-
help
122-
Size of the shared memory area owned by the application.
123-
This area holds all outgoing data from the application, e.g. buffers passed to `send()`.
124-
The size of this buffer affects directly the largest payload that can sent be on AT sockets.
125-
126-
config NRF_MODEM_LIB_SHMEM_RX_SIZE
127-
int "RX region size"
128-
range 1544 16384
129-
default 8192
130-
help
131-
Size of the shared memory area owned by the modem.
132-
This area holds all incoming data from the modem, plus the modem's own control structures.
133-
The minimum memory requirements stem from the size of the RPC lists (264 bytes = 8 + (32 * 8)),
134-
plus the RPC messages and data buffers (1280 bytes = 256 + 1024).
135-
136-
config NRF_MODEM_LIB_SHMEM_TRACE_SIZE_OVERRIDE
137-
bool "Custom Trace region size"
138-
depends on NRF_MODEM_LIB_TRACE_ENABLED
139-
help
140-
Override the default size of the Trace region (16384 bytes).
141-
142-
config NRF_MODEM_LIB_SHMEM_TRACE_SIZE
143-
int "Trace region size" if NRF_MODEM_LIB_SHMEM_TRACE_SIZE_OVERRIDE
144-
default 16384 if NRF_MODEM_LIB_TRACE_ENABLED
145-
default 0
146-
help
147-
Size of the shared memory area used to receive modem traces.
148-
149-
menu "Diagnostics"
150-
151-
config NRF_MODEM_LIB_DEBUG_ALLOC
152-
depends on LOG
153-
bool "Print allocations on the library heap"
154-
155-
config NRF_MODEM_LIB_DEBUG_SHM_TX_ALLOC
156-
depends on LOG
157-
bool "Print allocations on the TX region"
158-
159-
config NRF_MODEM_LIB_HEAP_DUMP_PERIODIC
160-
bool "Periodically dump library heap contents"
161-
162-
config NRF_MODEM_LIB_HEAP_DUMP_PERIOD_MS
163-
depends on NRF_MODEM_LIB_HEAP_DUMP_PERIODIC
164-
int "Period (millisec)"
165-
default 20000
166-
167-
config NRF_MODEM_LIB_SHM_TX_DUMP_PERIODIC
168-
bool "Periodically dump the TX memory region contents"
169-
170-
config NRF_MODEM_LIB_SHMEM_TX_DUMP_PERIOD_MS
171-
depends on NRF_MODEM_LIB_SHM_TX_DUMP_PERIODIC
172-
int "Period (millisec)"
173-
default 20000
174-
175-
endmenu
176-
177-
module = NRF_MODEM_LIB
178-
module-str = Modem library
179-
source "subsys/logging/Kconfig.template.log_config"
22+
rsource "Kconfig.modemlib"
18023

18124
endif # NRF_MODEM_LIB

0 commit comments

Comments
 (0)