Skip to content

Commit

Permalink
lib: nrf_modem: NRF_MODEM_LIB_ON_INIT only allow pre-link operations
Browse files Browse the repository at this point in the history
Turning on the modem and attaching to the network are two different
operations. CFUN can take an unpredictable amount of time, which we
cannot allow in modem lib init hooks. Also, the hooks may require
the modem to be in offline modem when performing its operations.

Signed-off-by: Eivind Jølsgard <eivind.jolsgard@nordicsemi.no>
  • Loading branch information
eivindj-nordic authored and jfischer-no committed Jun 21, 2023
1 parent 5bbc797 commit 64922e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/nrf/libraries/modem/nrf_modem_lib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ These compile-time callbacks allow any part of the application to perform any se
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 :c:macro:`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 :c:func:`lte_lc_connect` and ``CFUN`` AT calls are not allowed, and must be done after :c:func:`nrf_modem_lib_init` has returned.
If a library needs to perform operations after the link is up, it can use the :ref:`lte_lc_readme` and subscribe to a :c:macro:`LTE_LC_ON_CFUN` callback.

Callbacks for the macro :c: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 :c:macro:`NRF_MODEM_LIB_ON_SHUTDOWN` are executed before the library is shut down.
The callback context is provided to these callbacks.
Expand Down
7 changes: 7 additions & 0 deletions include/modem/nrf_modem_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ struct nrf_modem_lib_shutdown_cb {
*
* The callback function @p _callback is invoked after the library has been initialized.
*
* @note The @c NRF_MODEM_LIB_ON_INIT callback can be used to perform modem and library
* configurations that require the modem to be turned on in offline mode. It cannot be used to
* change the modem functional mode. Calls to @c lte_lc_connect and CFUN AT calls are not
* allowed, and must be done after @c nrf_modem_lib_init has returned. If a library needs to
* perform operations after the link is up, it can use the link controller and subscribe to a
* @c LTE_LC_ON_CFUN callback.
*
* @param name Callback name
* @param _callback Callback function name
* @param _context User-defined context for the callback
Expand Down

0 comments on commit 64922e8

Please sign in to comment.