Library wrapper
The library wrapper provides an encapsulation over the core Modem library functions such as initialization and shutdown.
The library wrapper is implemented in nrf/lib/nrf_modem_lib/nrf_modem_lib.c
.
The library wrapper encapsulates the nrf_modem_init()
and nrf_modem_shutdown()
calls of the Modem library with nrf_modem_lib_init()
and nrf_modem_lib_shutdown()
calls, respectively.
The library wrapper eases the task of initializing the Modem library by automatically passing the size and address of all the shared memory regions of the Modem library to the nrf_modem_init()
call.
Partition Manager is the component that reserves the RAM memory for the shared memory regions used by the Modem library. For more information, see Partition manager integration.
The CONFIG_NRF_MODEM_LIB_LOG_FW_VERSION_UUID
option can be enabled for printing logs of both FW version and UUID at the end of the library initialization step.
When using the Modem library in nRF Connect SDK, the library must be initialized and shutdown using the nrf_modem_lib_init()
and nrf_modem_lib_shutdown()
function calls, respectively.
Modem library callbacks
The library wrapper provides callbacks for the modem initialization and shutdown operations, as well as macros for registering multiple callbacks on changes to the modem functional mode.
Modem initialization and shutdown
The application can set up a callback for the nrf_modem_lib_init()
function using the NRF_MODEM_LIB_ON_INIT
macro, and a callback for nrf_modem_lib_shutdown()
function using the NRF_MODEM_LIB_ON_SHUTDOWN
macro.
These compile-time callbacks allow any part of the application to perform any setup steps that require the modem to be in a certain state.
Furthermore, the callbacks ensure that the setup steps are repeated whenever another part of the application turns the modem on or off.
The callbacks registered using NRF_MODEM_LIB_ON_INIT
are executed after the library is initialized.
The result of the initialization and the callback context are provided to these callbacks.
Note
The callback can be used to perform modem and library configurations that require the modem to be turned on in offline mode.
The callback cannot be used to change the modem’s functional mode.
Calls to lte_lc_connect()
and CFUN
AT calls are not allowed, and must be done after nrf_modem_lib_init()
has returned.
If a library needs to perform operations after the link is up, it can use the LTE link control and subscribe to a LTE_LC_ON_CFUN
callback.
Callbacks for the macro NRF_MODEM_LIB_ON_INIT
must have the signature void callback_name(int ret, void *ctx)
, where ret
is the result of the initialization and ctx
is the context passed to the macro.
The callbacks registered using the NRF_MODEM_LIB_ON_SHUTDOWN
macro are executed before the library is shut down.
The callback context is provided to these callbacks.
Callbacks for the macro NRF_MODEM_LIB_ON_SHUTDOWN
must have the signature void callback_name(void *ctx)
, where ctx
is the context passed to the macro.
See the Cellular: Modem callbacks sample for more information.
Modem functional mode changes
The application can set up a callback for AT CFUN calls using the NRF_MODEM_LIB_ON_CFUN
macro.
This compile-time callback allows any part of the application to perform any steps that are required when the modem changes functional mode.
The callbacks registered using the NRF_MODEM_LIB_ON_CFUN
macro are executed after the functional mode has been successfully set.
See the Cellular: Modem callbacks sample for more information.
Important
The application should not call nrf_modem_at_cfun_handler_set()
as that will override the handler set by the modem library integration layer.
Instead, the application should use the NRF_MODEM_LIB_ON_CFUN
macro to register functional mode changes.
Note
The CFUN callback is not supported with nrf_modem_at_cmd_async()
.