This section will touch upon the interfacing between the modem firmware running on the modem core and an application running on the application core.
Recalling the nRF91 Series communication stack, we are now discussing these layers
For the application to interface with the modem core on the nRF91 Series SiP, the nRF Connect SDK contains the Modem library. This is a set of standard function calls that can be used in your application to communicate with the modem.
The library implements the communication through the Remote procedure call (RPC) library, using the Inter Processor Communication (IPC) peripheral and a shared region of RAM.
The modem library contains, among other things, the socket API (nrf_socket.h
), the AT API (nrf_modem_at.h
) and the GNSS API (nrf_modem_gnss.h
), which interfaces with their respective modules in the modem firmware.
On top of this, we have the Modem library integration layer which integrates the Modem library into nRF Connect SDK. This layer consists of the library wrapper, and functionalities like socket offloading, memory partitioning of the shared memory region, handling modem tracing (covered in Lesson 7), and diagnostics.
Zephyr has the functionality to offload or redirect function calls at the socket API level. The integration layer uses this functionality to redirect all socket API calls to the Modem library’s native socket API, thereby offloading all socket calls to the IP stack in the nRF91 Series modem firmware.
The Modem library socket API sets the errno
‘s as defined in nrf_errno.h
, and the integration layer converts these errnos to adhere to the selected C library implementation (either minimal or Newlib).
When socket offloading is disabled, the socket calls will no longer be offloaded to the nRF91 Series modem firmware, but rather go to the Zephyr’s native IP stack.
Make sure you are consistent in only using either Zephyr native BSD socket API or the Modem library socket API directly in the application. We recommend using Zephyr’s native BSD socket API directly in the application, and then offloading to the Modem library through the offloading functionality
To enable the modem library in your application, first enable the configuration for the module:
CONFIG_NRF_MODEM_LIB=y
KconfigInclude the header file of the nRF Modem library in your source code.
#include <modem/nrf_modem_lib.h>
CAdditionally, want to enable the link layer and IP networking support (CONFIG_NETWORKING
), the BSD Sockets compatible API (CONFIG_NET_SOCKETS
) and the socket offloading functionality (CONFIG_NET_SOCKETS_OFFLOAD
).
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_OFFLOAD=y
KconfigWe also need to disable the Zephyr native IP stack (CONFIG_NET_NATIVE
), to be able to offload all socket calls to the IP stack running on the modem firmware.
CONFIG_NET_NATIVE=n
KconfigThen we need to set some memory configs. The size of the heap memory pool (CONFIG_HEAP_MEM_POOL_SIZE
) has a default value of zero, so it needs to be set to a non-zero value in order to be created.
The size of the stack used for initialization and the main thread (CONFIG_MAIN_STACK_SIZE
) also needs to be increased
# Increase memory heap
CONFIG_HEAP_MEM_POOL_SIZE=4096
CONFIG_MAIN_STACK_SIZE=4096
KconfigNow we need to initialize the nRF Modem library and turn on the modem by calling nrf_modem_lib_init()
, which has the following signature
This is done by adding the following code to your application code
nrf_modem_lib_init();
CThis section will touch upon the interfacing between the modem firmware running on the modem core and an application running on the application core.
Recalling the nRF91 Series communication stack, we are now discussing these layers
For the application to interface with the modem core on the nRF91 Series SiP, the nRF Connect SDK contains the Modem library. This is a set of standard function calls that can be used in your application to communicate with the modem.
The library implements the communication through the Remote procedure call (RPC) library, using the Inter Processor Communication (IPC) peripheral and a shared region of RAM.
The modem library contains, among other things, the socket API (nrf_socket.h
), the AT API (nrf_modem_at.h
) and the GNSS API (nrf_modem_gnss.h
), which interfaces with their respective modules in the modem firmware.
On top of this, we have the Modem library integration layer which integrates the Modem library into nRF Connect SDK. This layer consists of the library wrapper, and functionalities like socket offloading, memory partitioning of the shared memory region, handling modem tracing (covered in Lesson 7), and diagnostics.
Zephyr has the functionality to offload or redirect function calls at the socket API level. The integration layer uses this functionality to redirect all socket API calls to the Modem library’s native socket API, thereby offloading all socket calls to the IP stack in the nRF91 Series modem firmware.
The Modem library socket API sets the errno
‘s as defined in nrf_errno.h
, and the integration layer converts these errnos to adhere to the selected C library implementation (either minimal or Newlib).
When socket offloading is disabled, the socket calls will no longer be offloaded to the nRF91 Series modem firmware, but rather go to the Zephyr’s native IP stack.
Make sure you are consistent in only using either Zephyr native BSD socket API or the Modem library socket API directly in the application. We recommend using Zephyr’s native BSD socket API directly in the application, and then offloading to the Modem library through the offloading functionality.
To enable the modem library in your application, first enable the configuration for the module:
CONFIG_NRF_MODEM_LIB=y
KconfigInclude the header file of the nRF Modem library in your source code.
#include <modem/nrf_modem_lib.h>
CAdditionally, want to enable the link layer and IP networking support (CONFIG_NETWORKING
), the BSD Sockets compatible API (CONFIG_NET_SOCKETS
) and the socket offloading functionality (CONFIG_NET_SOCKETS_OFFLOAD
).
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_OFFLOAD=y
KconfigTo expose all the socket calls without the zsock_
prefix, we enable the following config
CONFIG_NET_SOCKETS_POSIX_NAMES=y
KconfigWe also need to disable the Zephyr native IP stack (CONFIG_NET_NATIVE
), to be able to offload all socket calls to the IP stack running on the modem firmware.
CONFIG_NET_NATIVE=n
KconfigThen we need to set some memory configs. The size of the heap memory pool (CONFIG_HEAP_MEM_POOL_SIZE
) has a default value of zero, so it needs to be set to a non-zero value in order to be created.
The size of the stack used for initialization and the main thread (CONFIG_MAIN_STACK_SIZE
) also needs to be increased
# Increase memory heap
CONFIG_HEAP_MEM_POOL_SIZE=4096
CONFIG_MAIN_STACK_SIZE=4096
KconfigNow we need to initialize the nRF Modem library and turn on the modem by calling nrf_modem_lib_init()
, which has the following signature
This is done by adding the following code to your application code
nrf_modem_lib_init();
CThis section will touch upon the interfacing between the modem firmware running on the modem core and an application running on the application core.
Recalling the nRF91 Series communication stack, we are now discussing these layers
For the application to interface with the modem core on the nRF91 Series SiP, the nRF Connect SDK contains the Modem library. This is a set of standard function calls that can be used in your application to communicate with the modem.
The library implements the communication through the Remote procedure call (RPC) library, using the Inter Processor Communication (IPC) peripheral and a shared region of RAM.
The modem library contains, among other things, the socket API (nrf_socket.h
), the AT API (nrf_modem_at.h
) and the GNSS API (nrf_modem_gnss.h
), which interfaces with their respective modules in the modem firmware.
On top of this, we have the Modem library integration layer which integrates the Modem library into nRF Connect SDK. This layer consists of the library wrapper, and functionalities like socket offloading, memory partitioning of the shared memory region, handling modem tracing (covered in Lesson 7), and diagnostics.
Zephyr has the functionality to offload or redirect function calls at the socket API level. The integration layer uses this functionality to redirect all socket API calls to the Modem library’s native socket API, thereby offloading all socket calls to the IP stack in the nRF91 Series modem firmware.
The Modem library socket API sets the errno
‘s as defined in nrf_errno.h
, and the integration layer converts these errnos to adhere to the selected C library implementation (either minimal or Newlib).
When socket offloading is disabled, the socket calls will no longer be offloaded to the nRF91 Series modem firmware, but rather go to the Zephyr’s native IP stack.
Make sure you are consistent in only using either Zephyr native BSD socket API or the Modem library socket API directly in the application. We recommend using Zephyr’s native BSD socket API directly in the application, and then offloading to the Modem library through the offloading functionality.
To enable the modem library in your application, first enable the configuration for the module:
CONFIG_NRF_MODEM_LIB=y
KconfigInclude the header file of the nRF Modem library in your source code.
#include <modem/nrf_modem_lib.h>
CAdditionally, want to enable the link layer and IP networking support (CONFIG_NETWORKING
), the BSD Sockets compatible API (CONFIG_NET_SOCKETS
) and the socket offloading functionality (CONFIG_NET_SOCKETS_OFFLOAD
).
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_OFFLOAD=y
KconfigTo expose all the socket calls without the zsock_
prefix, we enable the following config
CONFIG_NET_SOCKETS_POSIX_NAMES=y
KconfigWe also need to disable the Zephyr native IP stack (CONFIG_NET_NATIVE
), to be able to offload all socket calls to the IP stack running on the modem firmware.
CONFIG_NET_NATIVE=n
KconfigThen we need to set some memory configs. The size of the heap memory pool (CONFIG_HEAP_MEM_POOL_SIZE
) has a default value of zero, so it needs to be set to a non-zero value in order to be created.
The size of the stack used for initialization and the main thread (CONFIG_MAIN_STACK_SIZE
) also needs to be increased
# Increase memory heap
CONFIG_HEAP_MEM_POOL_SIZE=4096
CONFIG_MAIN_STACK_SIZE=4096
KconfigThe initialization of the nRF Modem library is handled automatically through the Kconfig CONFIG_NRF_MODEM_LIB_SYS_INIT
which automatically initializes the library during the SYS_INIT sequence.
The Kconfig is enabled by default, so there is no need to add it to your application.