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.


The library wrapper also provides callbacks for the initialization and shutdown operations. 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.


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.