API documentation

Library Management

group nrf_modem

Application interface offered for management of the Modem library.

Defines

NRF_MODEM_SHMEM_CTRL_SIZE

Enums

enum nrf_modem_mode

Modem library mode.

Values:

enumerator NORMAL_MODE

Normal operation mode

enumerator FULL_DFU_MODE

DFU mode

Functions

char *nrf_modem_build_version(void)

Return version string of the Modem library build.

Return values
  • Version – string if defined.

  • Empty – string if version string is not defined.

int nrf_modem_init(const struct nrf_modem_init_params *init_params, enum nrf_modem_mode mode)

Initialize the Modem library.

Library has two operation modes, normal and DFU. In normal operation mode, the DFU functionality is disabled.

Library can alternatively be initialized in DFU mode, which means that all shared memory regions are now reserved for DFU operation, and therefore no other modem functionality can be used.

To switch between DFU and normal modes, nrf_modem_shutdown() should be called in between.

Parameters
  • init_params[in] Initialization parameters.

  • mode[in] Library mode.

Return values
  • Zero – on success.

  • A – positive value from Modem DFU when executing Modem firmware updates.

  • -NRF_EFAULTinit_params is NULL.

  • -NRF_ENOMEM – Not enough shared memory for this operation.

  • -NRF_EPERM – The Modem library is already initialized.

  • -NRF_ETIMEDOUT – Operation timed out.

  • -NRF_NOLCK – Not enough semaphores.

  • -NRF_EINVAL – RPC control region size is incorrect.

  • -NRF_EOPNOTSUPP – RPC version mismatch.

  • -NRF_EIO – IPC State fault or missing root digest.

bool nrf_modem_is_initialized(void)

Check whether the modem is initialized.

Return values
  • true – If the modem is initialized.

  • false – If the modem is uninitialized or in a fault state.

int nrf_modem_shutdown(void)

Shutdown the Modem library.

Resources reserved by the library are freed when the library is shutdown.

Note

The modem must be put into offline (CFUN=0) mode before shutting it down.

Return values
  • Zero – on success.

  • -NRF_EPERM – The Modem library is not initialized.

  • -NRF_ENOMEM – Not enough shared memory for this operation.

struct nrf_modem_shmem_cfg
#include <nrf_modem.h>

Shared memory configuration.

Note

: Only the lower 128k of RAM may be shared with the modem core.

Public Members

struct nrf_modem_shmem_cfg.[anonymous] ctrl

Control memory, used for control structures. The size of this area is build constant, and must be equal to NRF_MODEM_SHMEM_CTRL_SIZE.

struct nrf_modem_shmem_cfg.[anonymous] tx

TX memory, used to send data to the modem

struct nrf_modem_shmem_cfg.[anonymous] rx

RX memory, used to receive data from the modem

struct nrf_modem_shmem_cfg.[anonymous] trace

Trace memory, used to receive traces from the modem

struct nrf_modem_init_params
#include <nrf_modem.h>

Modem library initialization parameters.

Public Members

struct nrf_modem_shmem_cfg shmem

Shared memory configuration

uint32_t ipc_irq_prio

IPC IRQ priority

nrf_modem_fault_handler_t fault_handler

Modem fault handler

nrf_modem_init() return values for modem firmware updates

group nrf_modem_dfu

nrf_modem_init() return values when executing Modem firmware updates.

Defines

MODEM_DFU_RESULT_OK

Modem firmware update successful. The modem will run the updated firmware on reboot.

MODEM_DFU_RESULT_INTERNAL_ERROR

Modem firmware update failed. The modem encountered a fatal internal error during firmware update.

MODEM_DFU_RESULT_HARDWARE_ERROR

Modem firmware update failed. The modem encountered a fatal hardware error during firmware update.

MODEM_DFU_RESULT_AUTH_ERROR

Modem firmware update failed, due to an authentication error. The modem will automatically run the previous (non-updated) firmware on reboot.

MODEM_DFU_RESULT_UUID_ERROR

Modem firmware update failed, due to UUID mismatch. The modem will automatically run the previous (non-updated) firmware on reboot.

MODEM_DFU_RESULT_VOLTAGE_LOW

Modem firmware update not executed due to low voltage. The modem will retry the update on reboot.

Modem traces

group nrf_modem_trace

API for handling modem traces.

Functions

int nrf_modem_trace_get(struct nrf_modem_trace_data **frags, size_t *n_frags, int timeout)

Get trace data.

The application shall call this function to receive trace data from the modem. The trace fragments must be processed in order from the start of the array. Processed data must be freed by calling nrf_modem_trace_processed.

Parameters
  • frags[out] On success, *frags is an array of trace data fragments.

  • n_frags[out] On success, *n_frags is the number of fragments in the *frags array.

  • timeout[in] Time to wait in milliseconds for trace data to become available or one of the special values NRF_MODEM_OS_FOREVER or NRF_MODEM_OS_NO_WAIT.

Return values
  • 0 – on success.

  • -NRF_FAULT – If frags or nfrags is NULL.

  • -NRF_EINPROGRESS – Trace is already being processed by the application.

  • -NRF_ENODATA – No more trace data is available until the modem is restarted.

  • -NRF_ESHUTDOWN – Modem was shut down.

  • -NRF_EAGAIN – If the request timed out.

int nrf_modem_trace_processed(size_t len)

Notify the Modem library that the application has completed processing of trace data.

The application shall call this function to let the Modem library free the trace memory. It is the application’s responsibility to call this function with the total size of all trace fragments received. If the data is processed in chunks, the function can be called with the size that is processed since last call.

Parameters
  • len – Length of trace data that is processed.

Return values
  • Zero – on success.

  • -NRF_EINVALlen is too large to be a valid trace length.

struct nrf_modem_trace_data
#include <nrf_modem_trace.h>

Trace data Structure to store trace data pointers and their respective sizes.

Modem fault reasons

group nrf_modem_fault_handling

Defines

NRF_MODEM_FAULT_UNDEFINED

Undefined fault (e.g. undefined interrupt)

NRF_MODEM_FAULT_HW_WD_RESET

HW WD reset detected

NRF_MODEM_FAULT_HARDFAULT

Hard fault

NRF_MODEM_FAULT_MEM_MANAGE

Memory management fault

NRF_MODEM_FAULT_BUS

Bus fault

NRF_MODEM_FAULT_USAGE

Usage fault

NRF_MODEM_FAULT_SECURE_RESET

Modem has been reset due to secure ctrl

NRF_MODEM_FAULT_PANIC_DOUBLE

Error handler has crashed

NRF_MODEM_FAULT_PANIC_RESET_LOOP

Modem startup has failed four times in row

NRF_MODEM_FAULT_ASSERT

Assert

NRF_MODEM_FAULT_PANIC

Unconditional SW reset

NRF_MODEM_FAULT_FLASH_ERASE

Flash erase fault

NRF_MODEM_FAULT_FLASH_WRITE

Flash write fault

NRF_MODEM_FAULT_POFWARN

Undervoltage fault

NRF_MODEM_FAULT_THWARN

Overtemperature fault

Typedefs

typedef void (*nrf_modem_fault_handler_t)(struct nrf_modem_fault_info *fault_info)

Modem fault handler.

struct nrf_modem_fault_info
#include <nrf_modem.h>

Modem fault info struct.

Limits of the Modem library

group nrf_modem_limits

Upper and lower bound limits of the Modem library.

Defines

NRF_MODEM_MAX_SOCKET_COUNT

Maximum number of AT and IP sockets available at the same time.

NRF_MODEM_MAX_SHMEM_SIZE

Maximum size in bytes of shared modem and application memory.

NRF_MODEM_TLS_MAX_MESSAGE_SIZE

Maximum TLS message size in bytes.

Socket parameter enumerators

Socket families

group nrf_socket_families

Defines

NRF_AF_UNSPEC

Unspecified address family

NRF_AF_INET

IPv4 socket family.

NRF_AF_INET6

IPv6 socket family.

NRF_AF_PACKET

Raw packet family.

Socket types

group nrf_socket_types

Defines

NRF_SOCK_STREAM

TCP socket type.

NRF_SOCK_DGRAM

UDP socket type.

NRF_SOCK_RAW

RAW socket type.

Socket protocols

group nrf_socket_protocols

Protocol numbers from IANA/BSD.

Defines

NRF_IPPROTO_IP

IP protocol (pseudo-val for setsockopt())

NRF_IPPROTO_TCP

TCP protocol.

NRF_IPPROTO_UDP

UDP protocol.

NRF_IPPROTO_IPV6

IPv6 protocol (pseudo-val for setsockopt())

NRF_IPPROTO_RAW

Raw IP packets

NRF_IPPROTO_ALL

IPv4 and IPv6 protocol (pseudo-val for setsockopt())

NRF_SPROTO_TLS1v2

TLS1v2 protocol.

NRF_SPROTO_DTLS1v2

DTLS1v2 protocol.

Socket option levels

group nrf_socket_options_levels

Defines

NRF_SOL_SOCKET
NRF_SOL_SECURE

Generic socket options

group nrf_socket_options_sockets

Socket options used with IP sockets.

Defines

NRF_SO_REUSEADDR

Enable reuse of server addresses

NRF_SO_ERROR

Read and clear socket error status (read only).

NRF_SO_RCVTIMEO

Receive timeout.

NRF_SO_SNDTIMEO

Send timeout.

NRF_SO_BINDTODEVICE

Bind a socket to network interface identified by a Packet Data Network ID.

NRF_SO_SILENCE_ALL

Disable ICMP echo replies on both IPv4 and IPv6. Set to 1 to enable, or to 0 to disable. Default is 0, disabled.

NRF_SO_IP_ECHO_REPLY

Enable ICMP echo reply. Set to 1 to enable, or to 0 to disable. Default is 1, enabled.

NRF_SO_IPV6_ECHO_REPLY

Enable ICMPv6 echo reply. Set to 1 to enable, or to 0 to disable. Default is 1, enabled.

NRF_SO_TCP_SRV_SESSTIMEO

Configurable TCP server session timeout in minutes. Range is 0 to 135. 0 is no timeout and 135 is 2 h 15 min. Default is 0 (no timeout).

NRF_SO_RAI_NO_DATA

Release Assistance Indication. Indicate that the application does not intend to send more data. This socket option applies immediately and lets the modem exit connected mode more quickly.

NRF_SO_RAI_LAST

Release Assistance Indication. Indicate that the application does not intend to send more data after the next call to send() or sendto(). This lets the modem exit connected mode more quickly after sending the data.

NRF_SO_RAI_ONE_RESP

Release Assistance Indication. Indicate that the application is expecting to receive just one data packet after the next call to send() or sendto(). This lets the modem exit connected mode more quickly after having received the data.

NRF_SO_RAI_ONGOING

Release Assistance Indication. Indicate that the socket is in active use by a client application. This lets the modem stay in connected mode longer.

NRF_SO_RAI_WAIT_MORE

Release Assistance Indication. Indicate that the socket is in active use by a server application. This lets the modem stay in connected mode longer.

Socket send and recv flags

group nrf_socket_send_recv_flags

Defines

NRF_MSG_PEEK

Return data from the beginning of receive queue without removing data from the queue.

NRF_MSG_DONTWAIT

Enables non-blocking operation.

NRF_MSG_WAITALL

Request a blocking operation until the request is satisfied.

fcntl parameters

group nrf_fcnt_commands

API used to manipulate the behaviour of IP sockets using nrf_fcntl().

Defines

NRF_F_GETFL

Get flag.

NRF_F_SETFL

Set flag.

NRF_O_NONBLOCK

Use non-blocking I/O.

Socket API

group nrf_socket_api

Functions

int nrf_socket(int family, int type, int protocol)

Create a network socket.

See POSIX.1-2017 article for normative description.

In addition, the function shall return -1 and set the following errno: [NRF_ESHUTDOWN] Modem was shut down.

int nrf_close(int fildes)

Close a network socket.

See POSIX.1-2017 article for normative description.

In addition, the function shall return -1 and set the following errno: [NRF_ESHUTDOWN] Modem was shut down.

int nrf_fcntl(int fd, int cmd, int flags)

Function for controlling file descriptor options.

Set or get file descriptor options or flags. For a list of supported commands, refer to Descriptor manipulate API. For a list of supported flags, refer to nrf_fcnt_flags.

Parameters
  • fd[in] The descriptor to set options on.

  • cmd[in] The command class for options.

  • flags[in] The flags to set.

Returns

Value dependent on command class: NRF_F_GETFL - Value of file status flags. -1 on error, and errno indicates the reason for failure. 0 otherwise.

int nrf_connect(int socket, const struct nrf_sockaddr *address, nrf_socklen_t address_len)

Connect a socket.

See POSIX.1-2017 article for normative description.

In addition, the function shall return -1 and set the following errno: [NRF_ESHUTDOWN] Modem was shut down.

ssize_t nrf_send(int socket, const void *buffer, size_t length, int flags)

Send a message on a connected socket.

See POSIX.1-2017 article for normative description.

In addition, the function shall return -1 and set the following errno: [NRF_ESHUTDOWN] Modem was shut down. [NRF_ECANCELED] Operation canceled because of APN rate control.

ssize_t nrf_sendto(int socket, const void *message, size_t length, int flags, const struct nrf_sockaddr *dest_addr, nrf_socklen_t dest_len)

Send a message on a socket.

See POSIX.1-2017 article for normative description.

In addition, the function shall return -1 and set the following errno: [NRF_ESHUTDOWN] Modem was shut down. [NRF_ECANCELED] Operation canceled because of APN rate control.

ssize_t nrf_recv(int socket, void *buffer, size_t length, int flags)

Receive a message from a connected socket.

See POSIX.1-2017 article for normative description.

In addition, the function shall return -1 and set the following errno: [NRF_ESHUTDOWN] Modem was shut down.

ssize_t nrf_recvfrom(int socket, void *restrict buffer, size_t length, int flags, struct nrf_sockaddr *restrict address, nrf_socklen_t *restrict address_len)

Receive a message from a socket.

See POSIX.1-2017 article for normative description.

In addition, the function shall return -1 and set the following errno: [NRF_ESHUTDOWN] Modem was shut down.

int nrf_poll(struct nrf_pollfd fds[], nrf_nfds_t nfds, int timeout)

Poll multiple sockets for events.

See POSIX.1-2017 article for normative description.

Note

In Modem library, this function works only with Modem library sockets, not arbitrary file descriptors.

int nrf_setsockopt(int socket, int level, int option_name, const void *option_value, nrf_socklen_t option_len)

Set the socket options.

See POSIX.1-2017 article for normative description.

In addition, the function shall return -1 and set the following errno: [NRF_ESHUTDOWN] Modem was shut down.

Note

In Modem library this function supports a subset of socket options described by POSIX, but also some additional options.

int nrf_getsockopt(int socket, int level, int option_name, void *restrict option_value, nrf_socklen_t *restrict option_len)

Get the socket options.

See POSIX.1-2017 article for normative description.

In Modem library this function supports a subset of socket options described by POSIX, but also some additional options.

int nrf_bind(int socket, const struct nrf_sockaddr *address, nrf_socklen_t address_len)

Bind a name to a socket.

See POSIX.1-2017 article for normative description.

In addition, the function shall return -1 and set the following errno: [NRF_ESHUTDOWN] Modem was shut down.

int nrf_listen(int sock, int backlog)

Listen for socket connections and limit the queue of incoming connections.

See POSIX.1-2017 article for normative description.

In addition, the function shall return -1 and set the following errno: [NRF_ESHUTDOWN] Modem was shut down.

int nrf_accept(int socket, struct nrf_sockaddr *restrict address, nrf_socklen_t *restrict address_len)

Accept a new connection a socket.

See POSIX.1-2017 article for normative description.

In addition, the function shall return -1 and set the following errno: [NRF_ESHUTDOWN] Modem was shut down.

struct nrf_timeval
#include <nrf_socket.h>

Structure specifying time interval.

Public Members

uint32_t tv_sec

Time interval seconds.

uint32_t tv_usec

Time interval microseconds.

TLS socket

group nrf_socket_tls

TLS socket API.

Defines

NRF_SO_SEC_TAG_LIST

Write-only socket option to select the security tags to be used.

See also

nrf_sec_tag_t.

NRF_SO_SEC_HOSTNAME

Socket option to set the hostname used for peer verification. This option accepts a string containing the hostname, and its length. The length may be set to zero to disable hostname verification.

NRF_SO_SEC_CIPHERSUITE_LIST

Write-only socket option to select which ciphersuites to use.

See also

nrf_sec_cipher_t.

NRF_SO_SEC_PEER_VERIFY

Socket option to set peer verification level. This option accepts an nrf_sec_peer_verify_t with values:

NRF_SO_SEC_ROLE

Write-only socket option to set role for the connection. Accepts an nrf_sec_role_t with values:

  • 0 - Client role.

  • 1 - Server role.

NRF_SO_SEC_SESSION_CACHE

Socket option to control TLS session caching. Accepts an nrf_sec_session_cache_t with values:

NRF_SO_SEC_SESSION_CACHE_PURGE

Socket option to purge session cache immediately. This option accepts any value.

NRF_SO_SEC_DTLS_HANDSHAKE_TIMEO

Socket option to set DTLS handshake timeout value. Please see DTLS handshake timeout values for allowed values.

NRF_IFNAMSIZ

Maximum network interface name size.

Deprecated:

since v1.1.0.

Typedefs

typedef uint32_t nrf_sec_role_t

TLS role for the connection.

  • 0 - TLS client role.

  • 1 - TLS server role.

typedef uint32_t nrf_sec_tag_t

Security tags used on the TLS socket.

More than one security tags may be used on a socket. If more than one tag is used on the socket, pass an array of security tags.

A maximum of 8 tags can be set per socket.

typedef uint32_t nrf_sec_session_cache_t

Session cache configuration for the TLS connection.

  • 0 - Disabled.

  • 1 - Enabled.

By default, the session cache is enabled.

Note

Session cache, may not be used if the peer does not support it.

typedef uint32_t nrf_sec_peer_verify_t

Peer verification level for the TLS connection.

  • 0 - None.

  • 1 - Optional.

  • 2 - Required.

By default, peer verification is optional.

typedef uint32_t nrf_sec_cipher_t

An IANA cipher suite identifier.

struct nrf_ifreq
#include <nrf_socket.h>

Data type for network interface.

Deprecated:

since v1.1.0.

DTLS handshake timeout values

group nrf_socket_tls_dtls_handshake_timeouts

Allowed timeout values for DTLS handshake timeout socket option according to RFC6347 section 4.2.4.1. Default is 123 seconds. (https://tools.ietf.org/html/rfc6347#section-4.2.4.1)

Defines

NRF_SO_SEC_DTLS_HANDSHAKE_TIMEOUT_1S

1 second

NRF_SO_SEC_DTLS_HANDSHAKE_TIMEOUT_3S

1s + 2s

NRF_SO_SEC_DTLS_HANDSHAKE_TIMEOUT_7S

1s + 2s + 4s

NRF_SO_SEC_DTLS_HANDSHAKE_TIMEOUT_15S

1s + 2s + 4s + 8s

NRF_SO_SEC_DTLS_HANDSHAKE_TIMEOUT_31S

1s + 2s + 4s + 8s + 16s

NRF_SO_SEC_DTLS_HANDSHAKE_TIMEOUT_63S

1s + 2s + 4s + 8s + 16s + 32s

NRF_SO_SEC_DTLS_HANDSHAKE_TIMEOUT_123S

1s + 2s + 4s + 8s + 16s + 32s + 60s

Socket address resolution API

group nrf_socket_address_resolution

Address resolution utility functions.

Defines

NRF_HTONS(x)

Host to network byte-orders on half word.

NRF_HTONL(x)

Host to network byte-orders on full word.

NRF_NTOHS(x)

Network to host byte-orders on half word.

NRF_NTOHL(x)

Network to host byte-orders on full word.

nrf_htons(x)

Convert byte order from host to network (short).

nrf_htonl(x)

Convert byte order from host to network (long).

nrf_ntohs(x)

Convert byte order from network to host (short).

nrf_ntohl(x)

Convert byte order from network to host (long).

NRF_INET_ADDRSTRLEN

Maximum length of IPv4 in string form, including null-termination character.

NRF_INET6_ADDRSTRLEN

Maximum length of IPv6 in string form, including null-termination character.

NRF_AI_CANONNAME

Fill in ai_canonname

NRF_AI_NUMERICSERV

Assume service (port) is numeric.

NRF_AI_PDNSERV

Assume service contains a Packet Data Network (PDN) ID. When specified together with the NRF_AI_NUMERICSERV flag, service shall be formatted as follows: “port:pdn_id” where “port” is the port number and “pdn_id” is the PDN ID. Example: “8080:1”, port 8080 PDN ID 1. Example: “42:0”, port 42 PDN ID 0.

Typedefs

typedef uint16_t nrf_in_port_t

Socket port type.

typedef unsigned int nrf_sa_family_t

Socket families.

For a list of valid values, refer to nrf_socket_families.

typedef uint32_t nrf_in_addr_t

IPv4 address.

typedef uint32_t nrf_socklen_t
typedef uint32_t nrf_nfds_t

Functions

int nrf_inet_pton(int af, const char *restrict src, void *restrict dst)

Convert IPv4 and IPv6 addresses between binary and text form.

See POSIX.1-2017 article for normative description.

const char *nrf_inet_ntop(int af, const void *restrict src, char *restrict dst, nrf_socklen_t size)

Convert IPv4 and IPv6 addresses between binary and text form.

See POSIX.1-2017 article for normative description.

int nrf_getaddrinfo(const char *restrict nodename, const char *restrict servname, const struct nrf_addrinfo *restrict hints, struct nrf_addrinfo **restrict res)

Get address information.

See POSIX.1-2017 article for normative description.

In addition, the function shall return -1 and set the following errno: [NRF_ESHUTDOWN] Modem was shut down.

void nrf_freeaddrinfo(struct nrf_addrinfo *ai)

Free address information returned by nrf_getaddrinfo().

See POSIX.1-2017 article for normative description.

int nrf_setdnsaddr(int family, const void *in_addr, nrf_socklen_t in_size)

Set a secondary DNS address.

The secondary DNS address is only used in case the primary DNS address is unreachable, or if no DNS address is provided by the operator. The secondary DNS address does not override the primary DNS address.

The function shall return -1 and set the following errno: [NRF_EPERM] The Modem library is not initialized. [NRF_EAFNOSUPPORT] The implementation does not support the specified address family. [NRF_EINVAL] Invalid parameters. [NRF_ENOBUFS] Not enough shared memory for this request. [NRF_ESHUTDOWN] Modem was shut down.

Note

It is not possible to unset a secondary DNS address set using this function.

Parameters
  • family[in] Address family.

  • in_addr[in] An IPv4 or IPv6 address encoded in a nrf_in_addr or nrf_in6_addr structure, respectively.

  • in_size[in] Size of the structure pointed to by in_addr.

Return values
  • 0 – On success

  • -1 – On error, and set errno to indicate the reason.

Variables

const struct nrf_in6_addr nrf_in6addr_any

Global IPv6 any-address.

const struct nrf_in_addr nrf_inaddr_any

Global IPv4 any-address.

struct nrf_in6_addr
#include <nrf_socket.h>

IPv6 address.

struct nrf_in_addr
#include <nrf_socket.h>

IPv4 address structure.

struct nrf_sockaddr_in6
#include <nrf_socket.h>

Address record for IPv6 addresses.

Contains the address and port of the host.

Public Members

uint8_t sin6_len

Length of this data structure.

nrf_sa_family_t sin6_family

Socket family.

nrf_in_port_t sin6_port

Port, in network byte order.

uint32_t sin6_flowinfo

IPv6 flow info parameters. Not used.

struct nrf_in6_addr sin6_addr

IPv6 address.

uint32_t sin6_scope_id

IPv6 scope ID. Not used.

struct nrf_sockaddr_in
#include <nrf_socket.h>

Address record for IPv4 addresses.

Contains the address and port of the host.

Public Members

uint8_t sin_len

Length of this data structure.

nrf_sa_family_t sin_family

Socket family.

nrf_in_port_t sin_port

Port, in network byte order.

struct nrf_in_addr sin_addr

IPv4 address.

struct nrf_sockaddr
#include <nrf_socket.h>

Generic socket address.

Only provided for API compatibility.

Public Members

uint8_t sa_len

Socket address length

int sa_family

Socket address family

char sa_data[]

Socket address

struct nrf_addrinfo
#include <nrf_socket.h>

Address information.

Public Members

int ai_flags

Input flags.

int ai_family

Address family of the socket.

int ai_socktype

Socket type.

int ai_protocol

Protocol of the socket.

nrf_socklen_t ai_addrlen

Length of the socket address.

struct nrf_sockaddr *ai_addr

Address of the socket.

char *ai_canonname

Canonical name of service location.

struct nrf_addrinfo *ai_next

Pointer to next in list.

Socket polling API

Necessary data types and defines to poll for events on one or more sockets using nrf_poll().

group nrf_socket_api_poll

Data types and defines for use with nrf_poll().

Defines

NRF_POLLIN

Data other than high-priority data may be read without blocking

NRF_POLLOUT

Data may be written without blocking

NRF_POLLERR

An error has occurred (revents only)

NRF_POLLHUP

Device has been disconnected (revents only)

NRF_POLLNVAL

Invalid fd member (revents only)

struct nrf_pollfd
#include <nrf_socket.h>

This structure is used to describe which events to poll for a given socket.

Public Members

int fd

Socket handle

short events

The input event flags

short revents

The output event flags

AT API

group nrf_modem_at

Modem library AT commands interface.

Defines

NRF_MODEM_AT_ERROR

Modem response type for ‘ERROR’ responses.

NRF_MODEM_AT_CME_ERROR

Modem response type for ‘+CME ERROR’ responses.

NRF_MODEM_AT_CMS_ERROR

Modem response type for ‘+CMS ERROR’ responses.

Typedefs

typedef void (*nrf_modem_at_notif_handler_t)(const char *notif)

AT Notification handler prototype.

Note

This handler is executed in an interrupt service routine. Offload any intensive operation as necessary.

Param notif

The AT notification.

typedef void (*nrf_modem_at_resp_handler_t)(const char *resp)

AT response handler prototype.

Note

This handler is executed in an interrupt service routine. Offload any intensive operations as necessary.

Param resp

The AT command response.

typedef int (*nrf_modem_at_cmd_handler_t)(char *buf, size_t len, char *at_cmd)

AT filter callback function format.

Note

This declaration is used for the callback functions of AT commands in the nRF SDK.

Param buf

Buffer to receive the response into.

Param len

Buffer length.

Param at_cmd

AT command.

Retval 0

On “OK” responses.

Retval -NRF_EPERM

The Modem library is not initialized.

Retval -NRF_EFAULT

buf or fmt are NULL.

Retval -NRF_ENOMEM

Not enough shared memory for this request.

Retval -NRF_E2BIG

The response is larger than the supplied buffer buf.

Return

A positive value On “ERROR”, “+CME ERROR”, and “+CMS ERROR” responses. The type of error can be distinguished using nrf_modem_at_err_type. The error value can be retrieved using nrf_modem_at_err.

Functions

int nrf_modem_at_notif_handler_set(nrf_modem_at_notif_handler_t callback)

Set a handler function for AT notifications.

Note

The callback is executed in an interrupt service routine. Take care to offload any processing as appropriate.

Parameters
  • callback – The AT notification callback. Use NULL to unset handler.

Return values

0 – On success.

int nrf_modem_at_printf(const char *fmt, ...)

Send a formatted AT command to the modem.

Supports all format specifiers of printf() as implemented by the selected C library. This function can return a negative value, zero or a positive value.

Parameters
  • fmt – Command format.

  • ... – Format arguments.

Return values
  • 0 – On “OK” responses.

  • -NRF_EPERM – The Modem library is not initialized.

  • -NRF_EFAULTfmt is NULL.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – If modem was shut down.

Returns

A positive value On “ERROR”, “+CME ERROR”, and “+CMS ERROR” responses. The type of error can be distinguished using nrf_modem_at_err_type. The error value can be retrieved using nrf_modem_at_err.

int nrf_modem_at_scanf(const char *cmd, const char *fmt, ...)

Send an AT command to the modem and read the formatted response into the supplied argument list.

Supports all the format specifiers of scanf() as implemented by the selected C library. This function does not support retrieving the modem response beyond reading the formatted response into the argument list.

Parameters
  • cmd – AT command.

  • fmt – Response format.

  • ... – Variable argument list.

Return values
  • -NRF_EPERM – The Modem library is not initialized.

  • -NRF_EFAULTcmd or fmt are NULL.

  • -NRF_EBADMSG – No arguments were matched.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – If the modem was shut down.

Returns

The number of arguments matched.

int nrf_modem_at_cmd(void *buf, size_t len, const char *fmt, ...)

Send a formatted AT command to the modem and receive the response into the supplied buffer.

Parameters
  • buf – Buffer to receive the response into.

  • len – Buffer length.

  • fmt – Command format.

  • ... – Format arguments.

Return values
  • 0 – On “OK” responses.

  • -NRF_EPERM – The Modem library is not initialized.

  • -NRF_EFAULTbuf or fmt are NULL.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_E2BIG – The response is larger than the supplied buffer buf.

  • -NRF_EINVAL – If len is zero.

  • -NRF_ESHUTDOWN – If the modem was shut down.

Returns

A positive value On “ERROR”, “+CME ERROR”, and “+CMS ERROR” responses. The type of error can be distinguished using nrf_modem_at_err_type. The error value can be retrieved using nrf_modem_at_err.

int nrf_modem_at_cmd_async(nrf_modem_at_resp_handler_t callback, const char *fmt, ...)

Send a formatted AT command to the modem and receive the response asynchronously via a callback.

This function waits for the Modem to acknowledge the AT command but will return without waiting for the command execution.

Note

The callback is executed in an interrupt context. Take care to offload any processing as appropriate.

Parameters
  • callback – Callback to receive the response.

  • fmt – Command format.

  • ... – Format arguments.

Return values
  • 0 – On “OK” responses.

  • -NRF_EPERM – The Modem library is not initialized.

  • -NRF_EFAULTcallback or fmt are NULL.

  • -NRF_EINPROGRESS – An asynchrounous request is already in progress.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – If the modem was shut down.

static inline int nrf_modem_at_err_type(int error)

Return the error type represented by the return value of nrf_modem_at_printf and nrf_modem_at_cmd.

Parameters
  • error – The return value of nrf_modem_at_printf or nrf_modem_at_cmd.

Return values
  • NRF_MODEM_AT_ERROR – If the modem response was ‘ERROR’.

  • NRF_MODEM_AT_CME_ERROR – If the modem response was ‘+CME ERROR’.

  • NRF_MODEM_AT_CMS_ERROR – If the modem response was ‘+CMS ERROR’.

static inline int nrf_modem_at_err(int error)

Retrieve the specific CME or CMS error from the return value of a nrf_modem_at_printf or nrf_modem_at_cmd call.

Parameters
  • error – The return value of a nrf_modem_at_printf or nrf_modem_at_cmd call.

Returns

int The CME or CMS error code.

int nrf_modem_at_cmd_filter_set(struct nrf_modem_at_cmd_filter *filters, size_t len)

Set a list of AT commands to be filtered by nrf_modem_at_cmd.

When a filter list is set, AT commands sent via nrf_modem_at_cmd that match any AT command in the filter will be redirected to the filter callback function instead of being sent to the modem.

Note

The filter is disabled by passing NULL to the filters and 0 to the len.

Parameters
  • filters – AT filter list.

  • len – AT filter list size.

Return values
  • 0 – On a success.

  • -NRF_EINVAL – On invalid parameters.

struct nrf_modem_at_cmd_filter
#include <nrf_modem_at.h>

Public Members

bool paused

Whether filter is paused.

Full DFU API

group nrf_modem_full_dfu

API for Full DFU.

Defines

NRF_MODEM_FULL_DFU_DIGEST_LEN

Digest buffer length.

NRF_MODEM_FULL_DFU_UUID_LEN

UUID buffer length.

NRF_MODEM_FULL_DFU_SHM_LEN

Required shared memory length.

Functions

int nrf_modem_full_dfu_init(struct nrf_modem_full_dfu_digest *digest_buffer)

Set modem in full DFU mode.

Reset the modem and set it into a state ready for full DFU operation. Before initialization, the modem library must be shut down and reinitialized with FULL_DFU_MODE.

Call once before DFU operations. If the modem goes to an error state, this can be called again to re-initialize. The root key digest response of the modem is put in the digest_buffer structure.

If success, the modem will be in a state to wait for a bootloader. Follow up with a call to nrf_modem_full_dfu_bl_write().

Parameters
  • digest_buffer[out] Pointer to the buffer to store digest hash. If NULL, digest skipped.

Return values

0 – if the procedure succeeds.

int nrf_modem_full_dfu_bl_write(uint32_t len, void *src)

Write a booloader chunk to the modem.

Call after nrf_modem_full_dfu_init() to upload modem bootloader segments. Bootloader segments are appended together, so the full bootloader may be uploaded with one or many call to this function. Once the full bootloader is uploaded, call nrf_modem_full_dfu_apply().

Firmware segments can be uploaded after successful bootloader upload.

Parameters
  • len[in] Length of data to be written.

  • src[in] Pointer to the buffer where chunk data is stored.

Return values
  • 0 – if the procedure succeeds.

  • -NRF_EINVAL – When src pointer is NULL or user tries to upload too big bootloader.

  • -NRF_EOPNOTSUPP – If the modem is not in a state to receive.

int nrf_modem_full_dfu_fw_write(uint32_t addr, uint32_t len, void *src)

Write a memory chunk to the modem.

Call after bootloader have been upload to the modem.

DFU library internally buffers all writes to a full page, so you may call split writes to any size preferred. When addr points to an area that is not continuing from previous write, the previous buffer is first written to a modem. After all firmware segments have been written, call nrf_modem_full_dfu_apply() to complete writing of the last buffer.

Parameters
  • addr[in] Address where the data to be written.

  • len[in] Length of data to be written.

  • src[in] Pointer to the buffer where chunk data is stored.

Return values
  • 0 – if the procedure succeeds.

  • -NRF_EINVAL – When src pointer is NULL, or user tries to upload too big bootloader, or addr parameter is zero after a bootloader upload.

  • -NRF_EOPNOTSUPP – If the modem is not in a state to receive.

  • -NRF_EPERM – When modem did not accept the flash programming request.

  • -NRF_ENOEXEC – When flash programming failed.

  • -NRF_ETIMEDOUT – When modem did not respond.

  • -NRF_EIO – When incorrect response received from modem.

int nrf_modem_full_dfu_apply(void)

Complete previous write cycle.

This call ensures that all parts from internal DFU buffers have been written to the modem. Call after final bootloader chunk have been written as well as when final firmware segment have been written.

Return values
  • 0 – if the procedure succeeds.

  • -NRF_EOPNOTSUPP – If the modem is not in a state to receive.

  • -NRF_EPERM – When modem did not accept the flash programming request.

  • -NRF_ENOEXEC – When flash programming failed.

  • -NRF_ETIMEDOUT – When modem did not respond.

  • -NRF_EIO – When incorrect response received from modem.

int nrf_modem_full_dfu_digest(uint32_t addr, uint32_t size, struct nrf_modem_full_dfu_digest *digest_buffer)

Read a digest hash data from the modem.

Parameters
  • addr[in] Start address.

  • size[in] Size of hash data.

  • digest_buffer[out] Pointer to the buffer to store digest hash data.

Return values
  • 0 – if the procedure succeeds.

  • -NRF_EINVAL – When digest_buffer pointer is NULL.

  • -NRF_EOPNOTSUPP – If bootloader is not programmed.

  • -NRF_EPERM – When modem did not accept RPC command.

  • -NRF_ENOEXEC – When RPC command failed.

  • -NRF_ETIMEDOUT – When modem did not respond.

  • -NRF_EIO – When incorrect response received from modem.

int nrf_modem_full_dfu_uuid(struct nrf_modem_full_dfu_uuid *modem_uuid)

Read an uuid data from the modem.

Parameters
  • modem_uuid[out] Pointer to the buffer to store uuid data.

Return values
  • 0 – if the procedure succeeds.

  • -NRF_EINVAL – When modem_uuid pointer is NULL.

  • -NRF_EOPNOTSUPP – If bootloader is not programmed.

  • -NRF_EPERM – When modem did not accept RPC command.

  • -NRF_ENOEXEC – When RPC command failed.

  • -NRF_ETIMEDOUT – When modem did not respond.

  • -NRF_EIO – When incorrect response received from modem.

int nrf_modem_full_dfu_verify(uint32_t bytes, const void *data)

Verify the modem firmware signature.

Parameters
  • bytes[in] Size of signature.

  • data[in] Pointer to the buffer where signature is stored.

Return values
  • 0 – if the procedure succeeds.

  • -NRF_EINVAL – When data pointer is NULL.

  • -NRF_EPERM – When modem did not accept RPC command.

  • -NRF_ENOEXEC – When RPC command failed.

  • -NRF_ETIMEDOUT – When modem did not respond.

  • -NRF_EIO – When incorrect response received from modem.

struct nrf_modem_full_dfu_digest
#include <nrf_modem_full_dfu.h>

Storage for 256-bit digest/hash replies. Endianness not converted.

struct nrf_modem_full_dfu_uuid
#include <nrf_modem_full_dfu.h>

Modem UUID response.

Delta DFU API

group nrf_modem_delta_dfu

API for Delta DFU.

Defines

NRF_MODEM_DELTA_DFU_UUID_LEN

Modem UUID length.

NRF_MODEM_DELTA_DFU_OFFSET_DIRTY

Offset value that indicates that the scratch area is dirty.

When the scratch area is dirty, it must be erased before a new firmware delta update can take place.

Functions

int nrf_modem_delta_dfu_uuid(struct nrf_modem_delta_dfu_uuid *modem_uuid)

Retrieve the modem firmware UUID.

Parameters
  • modem_uuid – Modem firmware UUID.

Return values
  • 0 – On success.

  • -NRF_EPERM – The Modem library is not initialized.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_EFAULT – If modem_uuid is NULL.

  • -NRF_ESHUTDOWN – Modem was shut down.

Returns

A positive error code from nrf_delta_dfu_errors, if the modem refused the operation.

int nrf_modem_delta_dfu_offset(size_t *off)

Retrieve the offset of the firmware image in the modem DFU area.

The offset will be zero if no image is in modem DFU area. The offset will be NRF_MODEM_DELTA_DFU_OFFSET_DIRTY if the modem DFU area needs to be erased before a new firmware update can be received.

Parameters
  • off – Offset of the firmware image.

Return values
  • 0 – On success.

  • -NRF_EPERM – The Modem library is not initialized.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_EFAULT – If off is NULL.

  • -NRF_ESHUTDOWN – Modem was shut down.

Returns

A positive error code from nrf_delta_dfu_errors, if the modem refused the operation.

int nrf_modem_delta_dfu_area(size_t *size)

Retrieve the size of the modem DFU area.

The size of the modem DFU area is the size of the FLASH area that the modem can use to receive an incoming firmware update.

Parameters
  • size – Size of the modem DFU area.

Return values
  • 0 – On success.

  • -NRF_EPERM – The Modem library is not initialized.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_EFAULT – If size is NULL.

  • -NRF_ESHUTDOWN – Modem was shut down.

Returns

A positive error code from nrf_delta_dfu_errors, if the modem refused the operation.

int nrf_modem_delta_dfu_write_init(void)

Ready the modem to receive a firmware update.

Ready the modem to receive a firmware update, acquiring the necessary resources. When a firmware update is not in progress, call nrf_modem_delta_dfu_write_done to release all resources.

Note

All functions of this interface, except nrf_modem_delta_dfu_write, are available regardless of the initialization status.

Return values
  • 0 – On success.

  • -NRF_EPERM – The Modem library is not initialized.

  • -NRF_EALREADY – Write already initialized.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

Returns

A positive error code from nrf_delta_dfu_errors, if the modem refused the operation.

int nrf_modem_delta_dfu_write(const void *src, size_t len)

Write bytes from a delta patch to the modem DFU area.

Parameters
  • src – Firmware update bytes.

  • len – Length of data being written.

Return values
  • 0 – On success.

  • -NRF_EPERM – The Modem library is not initialized.

  • -NRF_EFAULT – If src is NULL.

  • -NRF_EINVAL – If len is zero.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

Returns

A positive error code from nrf_delta_dfu_errors, if the modem refused the operation.

int nrf_modem_delta_dfu_write_done(void)

Pause receiving a modem firmware update and release resources.

Return values
  • 0 – On success.

  • -NRF_EPERM – The Modem library is not initialized.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

Returns

A positive error code from nrf_delta_dfu_errors, if the modem refused the operation.

int nrf_modem_delta_dfu_erase(void)

Erase the modem DFU area.

The modem DFU area must be erased before receiving a new firmware update. This function will return after commencing the erase operation, but it will not wait for its completion. Further calls to the delta DFU APIs will return MODEM_DELTA_DFU_ERASE_PENDING as long as the erase operation is pending or ongoing.

The application may poll the offset until it returns zero, to determine if the operation has completed.

Note

The erase operation may take longer when registered to the network than when not registered, i.e. in airplane mode.

Return values
  • 0 – On success.

  • -NRF_EPERM – The Modem library is not initialized.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

Returns

A positive error code from nrf_delta_dfu_errors, if the modem refused the operation.

int nrf_modem_delta_dfu_update(void)

Schedule execution of firmware update.

The modem needs to reboot to run the new firmware. To reboot the modem, uninitialize the Modem library and reinitialize it using the nrf_modem_deinit and nrf_modem_init respectively.

Note

The final result of the update operation is reported via nrf_modem_init.

Return values
  • 0 – On success.

  • -NRF_EPERM – The Modem library is not initialized.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

Returns

A positive error code from nrf_delta_dfu_errors, if the modem refused the operation.

int nrf_modem_delta_dfu_rollback(void)

Schedule a rollback to the previous firmware.

The modem needs to reboot to run the previous firmware. To reboot the modem, uninitialize the Modem library and reinitialize it using the nrf_modem_deinit and nrf_modem_init respectively.

Note

The final result of the rollback operation is reported via nrf_modem_init.

Return values
  • 0 – On success.

  • -NRF_EPERM – The Modem library is not initialized.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

Returns

A positive error code from nrf_delta_dfu_errors, if the modem refused the operation.

struct nrf_modem_delta_dfu_uuid
#include <nrf_modem_delta_dfu.h>

Modem UUID.

group nrf_modem_delta_dfu_errors

Delta DFU errors.

Defines

NRF_MODEM_DELTA_DFU_NO_ERROR

No error

NRF_MODEM_DELTA_DFU_RECEIVER_OUT_OF_MEMORY

Modem out of memory

NRF_MODEM_DELTA_DFU_RECEIVER_BLOCK_TOO_LARGE

Block too large

NRF_MODEM_DELTA_DFU_INVALID_HEADER_DATA

Invalid header

NRF_MODEM_DELTA_DFU_ERROR_INTERNAL_00

Internal error

NRF_MODEM_DELTA_DFU_INVALID_DATA

Invalid patch

NRF_MODEM_DELTA_DFU_ERROR_INTERNAL_01

Internal error

NRF_MODEM_DELTA_DFU_ERROR_INTERNAL_02

Internal error

NRF_MODEM_DELTA_DFU_ERROR_INTERNAL_03

Internal error

NRF_MODEM_DELTA_DFU_INVALID_UUID

Wrong patch for current modem

NRF_MODEM_DELTA_DFU_INVALID_ADDRESS

Invalid address

NRF_MODEM_DELTA_DFU_AREA_NOT_BLANK

Scratch area not erased

NRF_MODEM_DELTA_DFU_WRITE_ERROR

Failed to write

NRF_MODEM_DELTA_DFU_ERASE_ERROR

Failed to erase

NRF_MODEM_DELTA_DFU_INVALID_FILE_OFFSET

Invalid offset

NRF_MODEM_DELTA_DFU_PROGRESS_LOG_INVALID

Operation log corrupt

NRF_MODEM_DELTA_DFU_INVALID_RESUME_ATTEMPT

Invalid resume attempt

NRF_MODEM_DELTA_DFU_ERASE_PENDING

Erase operation is pending

NRF_MODEM_DELTA_DFU_OPERATION_NOT_ALLOWED

Operation not allowed

NRF_MODEM_DELTA_DFU_INCOMPLETE_DATA

Patch is incomplete

NRF_MODEM_DELTA_DFU_INTERRUPTED_WRITE

Write was interrupted

NRF_MODEM_DELTA_DFU_INVALID_OPERATION

Invalid operation

NRF_MODEM_DELTA_DFU_ERROR_INTERNAL_04

Internal error

NRF_MODEM_DELTA_DFU_NOT_ALLOWED_POFWARN_ON

Refused because of POFWARN

GNSS API

group nrf_modem_gnss

API for accessing the GNSS module on the modem.

Defines

NRF_MODEM_GNSS_MAX_SATELLITES

Maximum number of satellites that can be tracked at the same time.

NRF_MODEM_GNSS_NMEA_MAX_LEN

Maximum length of an NMEA string including the null-terminator.

NRF_MODEM_GNSS_NUM_GPS_SATELLITES

The number of GPS satellites.

NRF_MODEM_GNSS_AGPS_MAX_SV_TOW

Maximum number of TOW elements in the TOW array.

Typedefs

typedef void (*nrf_modem_gnss_event_handler_type_t)(int event)

Event handler prototype.

Param event

[in] Event ID, see Event type enumerator.

Functions

int32_t nrf_modem_gnss_event_handler_set(nrf_modem_gnss_event_handler_type_t handler)

Sets the GNSS event handler.

This function is used to set the function that handles events from GNSS.

Note

The event handler is executed in interrupt context so a lot of processing inside the handler may have performance implications and side effects. It’s recommended to use the handler only for signaling or re-scheduling processing to a separate thread. Data can be read at any time while GNSS is running, the events are only signaling that the data has been updated.

Parameters
  • handler[in] Pointer to the event handler function or NULL.

Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is running.

int32_t nrf_modem_gnss_system_mask_set(uint8_t system_mask)

Sets the supported GNSS systems. Systems which have the corresponding bit set are enabled.

Default value: All systems supported by the modem firmware are enabled

Note

GPS can’t be disabled and remains enabled even if the corresponding bit is not set.

Parameters
Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is running.

  • -NRF_EINVAL – GNSS stack returned an error.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

int32_t nrf_modem_gnss_elevation_threshold_set(uint8_t angle)

Set below which elevation angle GNSS should stop tracking a satellite.

Satellites with elevation angle less than the threshold are excluded from the estimation.

Default value: 5 deg

Parameters
  • angle[in] Value between 0 and 90 (degrees above the horizon).

Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is running.

  • -NRF_EINVAL – GNSS stack returned an error.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

int32_t nrf_modem_gnss_use_case_set(uint8_t use_case)

Sets targeted start and runtime performance.

Default value: NRF_MODEM_GNSS_USE_CASE_MULTIPLE_HOT_START

Parameters
Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is running.

  • -NRF_EINVAL – GNSS stack returned an error.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

int32_t nrf_modem_gnss_fix_interval_set(uint16_t fix_interval)

Sets the GNSS fix interval in seconds.

Single fix navigation mode is engaged by setting the fix interval to 0.

Continuous navigation mode is engaged by setting fix interval to 1.

Periodic navigation mode is engaged by setting the fix interval to value 10…65535. The unit is seconds.

Default value: 1 (continuous navigation)

Note

Fix interval values over 1800 seconds are only supported by modem firmware v1.3.0 or later.

Note

In periodic navigation mode, when GNSS determines it needs to download ephemerides or almanacs from the broadcast, the fix interval and fix retry parameters are temporarily ignored. GNSS will perform scheduled downloads until it has downloaded the data it needs, after which normal operation is resumed.

Parameters
  • fix_interval[in] 0 for single fix, 1 for continuous navigation or fix interval in seconds.

Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is running.

  • -NRF_EINVAL – GNSS stack returned an error.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

int32_t nrf_modem_gnss_fix_retry_set(uint16_t fix_retry)

Sets the GNSS fix retry period in seconds.

Fix retry parameter controls the maximum time the GNSS receiver is allowed to run while trying to produce a valid PVT estimate. If the fix retry time is non-zero, the GNSS receiver is turned off after the fix retry time is up regardless of whether a valid PVT estimate was produced or not. If fix retry parameter is set to zero, the GNSS receiver is allowed to run indefinitely until a valid PVT estimate is produced.

Default value: 60s

Note

For the first fix in periodic navigation mode the GNSS receiver is allowed to run for 60 seconds even if the retry interval is set shorter.

Note

Fix retry has no effect in continuous navigation mode.

Parameters
  • fix_retry[in] Fix retry period in seconds.

Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is running.

  • -NRF_EINVAL – GNSS stack returned an error.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

int32_t nrf_modem_gnss_nmea_mask_set(uint16_t nmea_mask)

Sets which NMEA strings are enabled.

Default value: 0

Parameters
Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is running.

  • -NRF_EINVAL – GNSS stack returned an error.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

int32_t nrf_modem_gnss_power_mode_set(uint8_t power_mode)

Sets the used power saving mode.

Valid only in continuous navigation mode.

Default value: NRF_MODEM_GNSS_PSM_DISABLED

Parameters
Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is running.

  • -NRF_EINVAL – GNSS stack returned an error.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

int32_t nrf_modem_gnss_timing_source_set(uint8_t timing_source)

Sets the used timing source during GNSS sleep.

Using TCXO instead of RTC during GNSS sleep periods might be beneficial when used with 1PPS. When GNSS is not running all the time (periodic navigation or duty cycling is used), 1PPS accuracy can be improved by using TCXO. It may also improve sensitivity for periodic navigation when the fix interval is short.

Default value: NRF_MODEM_GNSS_TIMING_SOURCE_RTC

Note

Use of TCXO significantly raises the idle current consumption.

Note

This feature is only supported by modem firmware v1.3.0 or later.

Parameters
Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is running.

  • -NRF_EINVAL – GNSS stack returned an error.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

int32_t nrf_modem_gnss_qzss_nmea_mode_set(uint8_t nmea_mode)

Sets the used QZSS NMEA mode.

NMEA 4.10 standard does not support QZSS satellites, so in standard NMEA mode QZSS satellites are not reported in GPGSA and GPGSV sentences. In custom NMEA mode satellite IDs 193…202 are used for QZSS satellites.

Default value: NRF_MODEM_GNSS_QZSS_NMEA_MODE_STANDARD

Note

This feature is only supported by modem firmware v1.3.0 or later.

Parameters
Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is running.

  • -NRF_EINVAL – GNSS stack returned an error.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

int32_t nrf_modem_gnss_qzss_prn_mask_set(uint16_t prn_mask)

Sets which QZSS PRNs are enabled.

QZSS satellite acquisition and tracking can be configured per satellite using QZSS PRN mask. Bits 0…9 correspond to QZSS PRNs 193…202, respectively. When a bit is set, usage of the corresponding QZSS satellite is enabled. Bits 10…15 are reserved and their value is ignored.

Default value: All QZSS PRNs (193…202) are enabled.

Note

This feature is only supported by modem firmware v1.3.0 or later.

Parameters
  • prn_mask[in] QZSS PRN mask.

Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is running.

  • -NRF_EINVAL – GNSS stack returned an error.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

int32_t nrf_modem_gnss_start(void)

Starts GNSS.

Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is running.

  • -NRF_EINVAL – GNSS stack returned an error.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

int32_t nrf_modem_gnss_stop(void)

Stops GNSS.

Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is stopped.

  • -NRF_EINVAL – GNSS stack returned an error.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

int32_t nrf_modem_gnss_nv_data_delete(uint32_t delete_mask)

Deletes GNSS data from non-volatile memory.

This function is used to delete downloaded data objects stored in non-volatile memory. The GNSS module stores this between sessions to get a fix faster on the next startup. This can for instance be used to trigger cold or warm starts.

Note

This is considered a debug feature, and is not supposed to be used in production code.

Parameters
Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is running.

  • -NRF_EINVAL – GNSS stack returned an error.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

int32_t nrf_modem_gnss_prio_mode_enable(void)

Enables GNSS priority over LTE idle mode procedures.

GNSS can produce a cold start fix when there are long enough gaps in LTE idle mode operations. LTE idle eDRX cycles approximately 1 min and above will usually guarantee the ability to produce a fix. Shorter DRX cycles will be enough after GNSS has got ephemerides. GNSS priority can be enabled to help getting GNSS into that state, if there are not long enough gaps in LTE idle mode functionality. Priority for GNSS should be used only when fix has been blocked by LTE idle mode operations, which can be detected by NRF_MODEM_GNSS_PVT_FLAG_NOT_ENOUGH_WINDOW_TIME bit being set in the PVT data frame flags member. The application should not make the decision based on a single PVT event, but should enable priority only in case this flag has been set in several consecutive PVT events. Priority will be disabled automatically after producing the first fix.

Note

GNSS priority may interfere with LTE operations, if possible it would be good to time the use of priority to moments where data transfer is not anticipated. In general, long enough eDRX cycles, or PSM, will ensure better functionality for both GNSS and LTE.

Note

Priority will not stop LTE connections.

Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is stopped.

  • -NRF_EINVAL – GNSS stack returned an error.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

int32_t nrf_modem_gnss_prio_mode_disable(void)

Disables GNSS priority over LTE idle mode procedures.

Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is stopped.

  • -NRF_EINVAL – GNSS stack returned an error.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

int32_t nrf_modem_gnss_dyn_mode_change(uint32_t mode)

Changes GNSS dynamics mode.

Dynamics mode can be used to tune GNSS performance for a specific use case. Use of a matching dynamics mode improves the positioning performance. Dynamics mode can be changed without disruption in positioning. The selected dynamics mode is stored into non-volatile memory.

Default value: NRF_MODEM_GNSS_DYNAMICS_GENERAL_PURPOSE

Note

This feature is only supported by modem firmware v1.3.0 or later.

Parameters
Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is stopped.

  • -NRF_EINVAL – GNSS stack returned an error.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

int32_t nrf_modem_gnss_1pps_enable(const struct nrf_modem_gnss_1pps_config *config)

Enables 1PPS functionality.

nrf_modem_gnss_1pps_config contains the used 1PPS configuration. GNSS only starts giving pulses after it has got at least one fix. After this, the pulses will continue also when GNSS is no longer running, but the precision will start degrading.

Note

This feature is only supported by modem firmware v1.3.0 or later.

Parameters
  • config[in] Pointer to the configuration struct.

Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is running.

  • -NRF_EINVAL – if the config pointer is NULL or GNSS returned an error.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

int32_t nrf_modem_gnss_1pps_disable(void)

Disables 1PPS functionality.

Note

This feature is only supported by modem firmware v1.3.0 or later.

Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is running.

  • -NRF_EINVAL – GNSS stack returned an error.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

int32_t nrf_modem_gnss_read(void *buf, int32_t buf_len, int type)

Reads data from GNSS.

This function is used to read any data from GNSS. The data type is specified using the type argument to this function.

Parameters
  • buf[out] Pointer to a buffer that can hold the selected data type.

  • buf_len[in] Length of the buffer.

  • type[in] The data type to read, see Data type enumerator.

Return values
  • 0 – on success.

  • -NRF_EINVAL – if the selected data type don’t exist or supplied buffer is NULL.

  • -NRF_EMSGSIZE – if the buffer supplied by the application is too small for the selected data type.

  • -NRF_ENOMSG – if there is no data to read for the selected data type.

int32_t nrf_modem_gnss_agps_write(void *buf, int32_t buf_len, uint16_t type)

Writes A-GPS data to GNSS.

This function is used to write A-GPS data to GNSS to decrease the time to first fix.

Parameters
  • buf[in] Pointer to a buffer that contain A-GPS data.

  • buf_len[in] Length of the buffer.

  • type[in] A-GPS data type identifier, see A-GPS data type enumerator.

Return values
  • 0 – on success.

  • -NRF_EPERM – Cannot execute while GNSS is running.

  • -NRF_EINVAL – if the buffer supplied by the application is NULL, buffer length is 0, the A-GPS data type doesn’t exist or the A-GPS data was not accepted by GNSS.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_ESHUTDOWN – Modem was shut down.

int32_t nrf_modem_gnss_agps_expiry_get(struct nrf_modem_gnss_agps_expiry *agps_expiry)

Reads the current A-GPS data need and expiry times from GNSS.

Returns detailed information about the current GNSS A-GPS data need. The data structure contains expiry times in seconds for different types of assistance data. This function can be called at any time. If GNSS doesn’t know the current GPS system time, the expiry times can not be calculated

Note

When A-GPS data has been injected but GNSS has not yet been started, ephemerides and almanacs are in some cases reported as expired. This happens when ephemerides and almanacs are injected before GPS system time. This can be prevented by either injecting GPS system time before ephemerides and almanacs or briefly starting and stopping GNSS before calling the function.

Note

Only supported by modem firmware v1.3.2 or later.

Parameters
  • agps_expiry[out] Pointer to a buffer where the data is stored to.

Return values
  • -NRF_EINVAL – if the buffer supplied by the application is NULL.

  • -NRF_ENOMEM – Not enough shared memory for this request.

  • -NRF_EOPNOTSUPP – if operation is not supported by the modem firmware.

  • -NRF_ESHUTDOWN – Modem was shut down.

Returns

0 on success.

struct nrf_modem_gnss_1pps_config
#include <nrf_modem_gnss.h>

Configuration for the nrf_modem_gnss_1pps_enable function.

Public Members

uint16_t pulse_interval

Pulse interval in seconds. Range 0…1800s. Value 0 denotes one-time pulse mode.

uint16_t pulse_width

Pulse width in milliseconds. Range 1…500ms.

bool apply_start_time

If true, pulses are started at given start time. If false, the date and time fields are ignored.

uint16_t year

Gregorian year. Range 0…4000.

uint8_t month

Month of the year. Range 1…12.

uint8_t day

Day of the month. Range 1…31.

uint8_t hour

Hour of the day. Range 0…23.

uint8_t minute

Minute of the hour. Range 0…59.

uint8_t second

Second of the minute. Range 0…59.

struct nrf_modem_gnss_datetime
#include <nrf_modem_gnss.h>

Date and time.

Public Members

uint16_t year

4-digit representation (Gregorian calendar).

uint8_t month

1…12

uint8_t day

1…31

uint8_t hour

0…23

uint8_t minute

0…59

uint8_t seconds

0…59

uint16_t ms

0…999

struct nrf_modem_gnss_sv
#include <nrf_modem_gnss.h>

Space Vehicle (SV) information.

Public Members

uint16_t sv

SV number 1…32 for GPS, 193…202 for QZSS.

uint8_t signal

Signal type. 0: invalid, 1: GPS L1C/A, 3: QZSS L1C/A, other values are reserved for other GNSSes or signals.

uint16_t cn0

0.1 dB/Hz.

int16_t elevation

SV elevation angle in degrees.

int16_t azimuth

SV azimuth angle in degrees.

uint8_t flags

See Satellite flags bitmask values.

struct nrf_modem_gnss_pvt_data_frame
#include <nrf_modem_gnss.h>

Position, Velocity and Time (PVT) data frame.

Public Members

double latitude

Latitude in degrees.

double longitude

Longitude in degrees.

float altitude

Altitude above WGS-84 ellipsoid in meters.

float accuracy

Position accuracy (2D 1-sigma) in meters.

float altitude_accuracy

Altitude accuracy (1-sigma) in meters.

Note

Only valid with modem firmware v1.3.2 or later.

float speed

Horizontal speed in m/s.

float speed_accuracy

Speed accuracy (1-sigma) in m/s.

Note

Only valid with modem firmware v1.3.0 or later.

float vertical_speed

Vertical speed in m/s. Positive is up.

Note

Only valid with modem firmware v1.3.2 or later.

float vertical_speed_accuracy

Vertical speed accuracy (1-sigma) in m/s.

Note

Only valid with modem firmware v1.3.2 or later.

float heading

Heading of user movement in degrees.

float heading_accuracy

Heading accuracy (1-sigma) in degrees.

Note

Only valid with modem firmware v1.3.2 or later.

struct nrf_modem_gnss_datetime datetime

Date and time.

float pdop

Position dilution of precision.

float hdop

Horizontal dilution of precision.

float vdop

Vertical dilution of precision.

float tdop

Time dilution of precision.

uint8_t flags

See Bitmask values for flags in the PVT notification.

struct nrf_modem_gnss_sv sv[12]

Describes up to 12 of the space vehicles used for the measurement.

uint32_t execution_time

Cumulative GNSS execution time since last start in milliseconds.

Note

Only valid with modem firmware v1.3.2 or later.

struct nrf_modem_gnss_nmea_data_frame
#include <nrf_modem_gnss.h>

Single null-terminated NMEA sentence.

Public Members

char nmea_str[83]

Null-terminated NMEA sentence.

struct nrf_modem_gnss_agps_data_frame
#include <nrf_modem_gnss.h>

A-GPS notification data frame used by GNSS to let the application know it needs new A-GPS data.

Public Members

uint32_t sv_mask_ephe

Bit mask indicating the satellite PRNs for which the assistance GPS ephemeris data is needed.

uint32_t sv_mask_alm

Bit mask indicating the satellite PRNs for which the assistance GPS almanac data is needed.

uint32_t data_flags

Indicating what kind of A-GPS data is needed by GNSS.

See A-GPS data request bitmask values.

struct nrf_modem_gnss_agps_expiry
#include <nrf_modem_gnss.h>

A-GPS data expiry.

Expiry times are given in seconds. 0 indicates that data is needed immediately. 0xffffffff indicates that data is not used by GNSS.

Public Members

uint32_t data_flags

Flags indicating the A-GPS data types needed by GNSS.

See A-GPS data request bitmask values. If bit NRF_MODEM_GNSS_AGPS_SYS_TIME_AND_SV_TOW_REQUEST is set, GNSS doesn’t have GPS system time and the expiry time fields are not valid.

Note

Only supported by modem firmware v1.3.2 or later.

uint32_t ephe_expiry[32]

Ephemeris expiry time for each GPS satellite.

uint32_t alm_expiry[32]

Almamac expiry time for each GPS satellite.

uint32_t utc_expiry

UTC parameters expiry time.

uint32_t klob_expiry

Klobuchar ionospheric correction parameters expiry time.

uint32_t neq_expiry

NeQuick ionospheric correction parameters expiry time.

uint32_t integrity_expiry

Integrity assistance parameters expiry time.

struct nrf_modem_gnss_agps_data_utc
#include <nrf_modem_gnss.h>

A-GPS UTC parameters.

Public Members

int32_t a1

First order term of polynomial (sec/sec). Scale factor 2^-50. Range -8388608…8388607 (25 bits).

int32_t a0

Constant term of polynomial (sec). Scale factor 2^-30.

uint8_t tot

UTC reference GPS time-of-week (sec). Scale factor 2^12. Range 0..147.

uint8_t wn_t

UTC reference GPS week number modulo 256.

int8_t delta_tls

Current or past leap second count (sec).

uint8_t wn_lsf

Leap second reference GPS week number modulo 256.

int8_t dn

Leap second reference GPS day-of-week (day). Range 1…7.

int8_t delta_tlsf

Current or future leap second count (sec) (total size of the type-specific assistance data).

struct nrf_modem_gnss_agps_data_ephemeris
#include <nrf_modem_gnss.h>

A-GPS ephemeris data.

Public Members

uint8_t sv_id

Satellite ID (dimensionless). Range 1…32.

uint8_t health

Satellite health (dimensionless).

uint16_t iodc

Issue of data, clock parameters (dimensionless). Range 0…2047 (11 bits).

uint16_t toc

Clock parameters reference GPS time-of-week (sec). Scale factor 2^4. Range 0…37799.

int8_t af2

Clock drift rate (sec/sec2). Scale factor 2^-55.

int16_t af1

Clock drift (sec/sec). Scale factor 2^-43.

int32_t af0

Clock bias (sec). Scale factor 2^-31. Range -2097152…2097151 (22 bit)

int8_t tgd

Group delay (sec). Scale factor 2^-31.

uint8_t ura

URA index (dimensionless). Range 0…15.

uint8_t fit_int

Curve fit interval indication. Range 0…1.

uint16_t toe

Ephemeris parameters reference GPS time-of-week (sec). Scale factor 2^4. Range 0…37799.

int32_t w

Argument of perigee (semi-circle). Scale factor 2^-31.

int16_t delta_n

Mean motion difference (semi-circle/sec). Scale factor 2^-43.

int32_t m0

Mean anomaly at reference time (semi-circle). Scale factor 2^-31.

int32_t omega_dot

Rate of right ascension (semi-circle/sec). Scale factor 2^-43. Range -8388608…8388607 (24 bits).

uint32_t e

Eccentricity (dimensionless). Scale factor 2^-33.

int16_t idot

Rate of inclination angle (semi-circle/sec). Scale factor 2-43. Range -8192…8191 (14 bits).

uint32_t sqrt_a

Square root of semi-major axis (m). Scale factor 2^-19.

int32_t i0

Inclination angle at reference time (semi-circle). Scale factor 2^-31.

int32_t omega0

Longitude of ascending node at weekly epoch (semi-circle). Scale factor 2^-31.

int16_t crs

Orbit radius, sine harmonic amplitude (m). Scale factor 2^-5.

int16_t cis

Inclination angle, sine harmonic amplitude (rad). Scale factor 2^-29.

int16_t cus

Argument of latitude, sine harmonic amplitude (rad). Scale factor 2^-29.

int16_t crc

Orbit radius, cosine harmonic amplitude (m). Scale factor 2^-5.

int16_t cic

Inclination angle, cosine harmonic amplitude (rad). Scale factor 2^-29.

int16_t cuc

Argument of latitude, cosine harmonic amplitude (rad). Scale factor 2^-29.

struct nrf_modem_gnss_agps_data_almanac
#include <nrf_modem_gnss.h>

A-GPS almanac data.

Public Members

uint8_t sv_id

Satellite ID (dimensionless). Range 1…32.

uint8_t wn

Almanac reference GPS week number modulo 256.

uint8_t toa

Almanac reference GPS time-of-week (sec). Scale factor 2^12. Range 0…147.

uint8_t ioda

Issue of data, almanac (dimensionless). Range 0…3 (2 bits).

uint16_t e

Eccentricity (dimensionless). Scale factor 2^-21.

int16_t delta_i

Correction to inclination (semi-circle). Scale factor 2^-19.

int16_t omega_dot

Rate of right ascension (semi-circle/sec). Scale factor 2^-38.

uint8_t sv_health

Satellite health (dimensionless)

uint32_t sqrt_a

Square root of semi-major axis (m^(1/2)). Scale factor 2^-11. Range 0…16777215 (24 bit).

int32_t omega0

Longitude of ascending node at weekly epoch (semi-circle). Scale factor 2^-23. Range -8388608…8388607 (24 bits).

int32_t w

Argument of perigee (semi-circle). Scale factor 2^-23.

int32_t m0

Mean anomaly at reference time (semi-circle). Scale factor 2^-23. Range -8388608…8388608 (24 bits).

int16_t af0

Clock bias (sec). Scale factor 2^-20. Range -1024…1023 (11 bits).

int16_t af1

Clock drift (sec/sec). Scale factor 2^-38. Range -1024…1023 (11 bits).

struct nrf_modem_gnss_agps_data_klobuchar
#include <nrf_modem_gnss.h>

A-GPS Klobuchar ionospheric correction data.

Public Members

int8_t alpha0

Constant term (sec). Scale factor 2^-30.

int8_t alpha1

First-order coefficient (sec/semi-circle). Scale factor 2^-27.

int8_t alpha2

Second-order coefficient (sec/semi-circle^2). Scale factor 2^-24.

int8_t alpha3

Third-order coefficient (sec/semi-circle^3). Scale factor 2^-24.

int8_t beta0

Constant term (sec). Scale factor 2^11.

int8_t beta1

First-order coefficient (sec/semi-circle). Scale factor 2^14.

int8_t beta2

Second-order coefficient (sec/semi-circle^2). Scale factor 2^16.

int8_t beta3

Third-order coefficient (sec/semi-circle^3). Scale factor 2^16.

struct nrf_modem_gnss_agps_data_nequick
#include <nrf_modem_gnss.h>

A-GPS NeQuick ionospheric correction data.

Public Members

int16_t ai0

Effective ionisation level 1st order parameter (SFU). Scale factor 2^-2. Range 0…2047 (11 bits).

int16_t ai1

Effective ionisation level 2nd order parameter (SFU/deg). Scale factor 2^-8. Range -1024…1023 (11 bits).

int16_t ai2

Effective ionisation level 3rd order parameter (SFU/deg^2). Scale factor 2^-15. Range -8192…8191 (14 bits).

uint8_t storm_cond

Storm condition bit mask indicating the ionospheric storm condition for different regions.

uint8_t storm_valid

Storm validity bit mask indicating for which regions the ionospheric storm condition bit is valid.

struct nrf_modem_gnss_agps_data_tow_element
#include <nrf_modem_gnss.h>

A-GPS TOW assistance data for a SV.

Public Members

uint16_t tlm

First two bits (MSB) represent the reserved bit and integrity status flag in the telemetry message (TLM) word. The following 14 bits represent the TLM being broadcast by the satellite.

uint8_t flags

Bit 0 (LSB): anti-spoof flag. Bit 1: alert flag.

struct nrf_modem_gnss_agps_data_system_time_and_sv_tow
#include <nrf_modem_gnss.h>

A-GPS system time and SV TOW data.

Public Members

uint16_t date_day

Day number since Jan 6th, 1980 00:00:00 UTC (USNO).

uint32_t time_full_s

Full seconds part of time-of-day (s). Range 0…86399.

uint16_t time_frac_ms

Fraction of a second part of time-of-day (ms). Range 0…999.

uint32_t sv_mask

Bit mask indicating the satellite PRNs for which the satellite-specific TOW assistance data is valid.

struct nrf_modem_gnss_agps_data_tow_element sv_tow[32]

TOW assistance data for SVs.

struct nrf_modem_gnss_agps_data_location
#include <nrf_modem_gnss.h>

A-GPS location data.

Public Members

int32_t latitude

Geodetic latitude in WGS-84. Range -8388607…8388607. The relation between the coded number N and the latitude range X (in degrees) is as follows: N <= (2^23/90) * X < N + 1. For N = 2^23 - 1, the range is extended to include N+1. Range of X (in degrees) -90…90.

int32_t longitude

Geodetic longitude in WGS-84. Range -8388607..8388607. The relation between the coded number N and the longitude range X (in degrees) is as follows: N <= (2^24/360) * X < N + 1. Range of X (in degrees) -180…180.

int16_t altitude

Altitude. Above (positive value) or below (negative value) WGS-84 ellipsoid surface. Range -32767…32767. The relation between the coded number N and the altitude range a (in meters) is as follows: N <= a < N + 1. For N = 2^15 - 1 the range is extended to include all greater values of a.

uint8_t unc_semimajor

Uncertainty, semi-major. Range 0…127 or 255 for missing latitude and longitude. The uncertainty (in meters) is mapped from the coded number K with following formula: r = C * ((1 + x)^K - 1), where C = 10 and x = 0,1. Range of r (in kilometers) 0…1800.

Note

Value 255 is only supported by modem firmware v1.3.0 or later.

uint8_t unc_semiminor

Uncertainty, semi-minor. Range 0…127 or 255 for missing latitude and longitude. The uncertainty (in meters) is mapped from the coded number K with following formula: r = C * ((1 + x)^K - 1), where C = 10 and x = 0,1. Range of r (in kilometers) 0…1800.

Note

Value 255 is only supported by modem firmware v1.3.0 or later.

uint8_t orientation_major

Orientation angle between the major axis and north. Range in degrees 0…179.

uint8_t unc_altitude

Uncertainty, altitude. Range 0…127 or 255 for missing altitude. The uncertainty in altitude h (in meters) is mapped from the coded number K with following formula: h = C * ((1 + x)^K - 1), where C = 45 and x = 0,025. Range of h (in meters) 0…990,5.

Note

Value 255 is only supported by modem firmware v1.3.0 or later.

uint8_t confidence

The confidence level (expressed as a percentage) with which the position of a target entity is included within the uncertainty ellipsoid. Range 0…128. ‘0’ indicates ‘no information’. Values 101..128 should be treated as ‘0’.

struct nrf_modem_gnss_agps_data_integrity
#include <nrf_modem_gnss.h>

A-GPS satellite integrity data.

Public Members

uint32_t integrity_mask

Bit mask indicating the unhealthy GPS satellite PRNs. When a mask bit is set, the corresponding GPS satellite PRN is unhealthy.

Event types

group nrf_modem_gnss_event_type

Event types that trigger the handler function.

The event parameter in the handler function will hold one of these values. Some of the events have associated payload which can be read using nrf_modem_gnss_read.

Defines

NRF_MODEM_GNSS_EVT_PVT

PVT event.

Payload is of type nrf_modem_gnss_pvt_data_frame.

NRF_MODEM_GNSS_EVT_FIX

GNSS fix event.

Payload is of type nrf_modem_gnss_pvt_data_frame.

NRF_MODEM_GNSS_EVT_NMEA

NMEA event.

Payload is of type nrf_modem_gnss_nmea_data_frame.

NRF_MODEM_GNSS_EVT_AGPS_REQ

Need new APGS data event.

Payload is of type nrf_modem_gnss_agps_data_frame.

NRF_MODEM_GNSS_EVT_BLOCKED

GNSS is blocked by LTE event.

This event doesn’t have any payload.

NRF_MODEM_GNSS_EVT_UNBLOCKED

GNSS is unblocked by LTE event.

This event doesn’t have any payload.

NRF_MODEM_GNSS_EVT_PERIODIC_WAKEUP

GNSS woke up in periodic mode.

This event is sent when GNSS receiver is turned on in periodic mode. This happens when GNSS starts acquiring the next periodic fix but also when a scheduled download starts.

This event doesn’t have any payload.

Note

This event is only supported by modem firmware v1.3.0 or later.

NRF_MODEM_GNSS_EVT_SLEEP_AFTER_TIMEOUT

GNSS enters sleep because fix retry timeout was reached in periodic or single fix mode.

This event doesn’t have any payload.

Note

This event is only supported by modem firmware v1.3.0 or later.

NRF_MODEM_GNSS_EVT_SLEEP_AFTER_FIX

GNSS enters sleep because fix was achieved in periodic mode.

This event doesn’t have any payload.

Note

This event is only supported by modem firmware v1.3.0 or later.

NRF_MODEM_GNSS_EVT_REF_ALT_EXPIRED

Reference altitude for 3-satellite fix expired.

This event doesn’t have any payload.

Note

This event is only supported by modem firmware v1.3.0 or later.

Data types

group nrf_modem_gnss_data_type

Use these values to indicate the type of data read using nrf_modem_gnss_read.

Defines

NRF_MODEM_GNSS_DATA_PVT

PVT (Position-Velocity-Time) data.

Use this data type to read PVT data using the nrf_modem_gnss_read function. New PVT data will be available when an NRF_MODEM_GNSS_EVT_PVT or NRF_MODEM_GNSS_EVT_FIX event is received.

NRF_MODEM_GNSS_DATA_NMEA

NMEA data.

Use this data type to read NMEA data using the nrf_modem_gnss_read function. New NMEA data will be available when an NRF_MODEM_GNSS_EVT_NMEA event is received.

Note

There’s no buffering for NMEA data. Because of this NMEA data needs to be read inside the event handler function, otherwise some of the data may be overwritten before it’s read.

NRF_MODEM_GNSS_DATA_AGPS_REQ

A-GPS request data.

Use this data type to read A-GPS request data using the nrf_modem_gnss_read function. New A-GPS request data is received when an NRF_MODEM_GNSS_EVT_AGPS_REQ event is received.

PVT notification flags bitmask values

group nrf_modem_gnss_pvt_flag_bitmask

Bitmask values for the flags member in the nrf_modem_gnss_pvt_data_frame.

Defines

NRF_MODEM_GNSS_PVT_FLAG_FIX_VALID

A valid fix has been acquired.

NRF_MODEM_GNSS_PVT_FLAG_LEAP_SECOND_VALID

The leap second information is valid.

This bit in the notification flags tells if receiver has decoded leap second from the navigation message. The leap second is needed for determining GPS-UTC time offset (in seconds). If it is not decoded (bit is zero), the value of 18 seconds is used. This is the effective value since January 1st 2017.

NRF_MODEM_GNSS_PVT_FLAG_SLEEP_BETWEEN_PVT

At least one sleep period has passed since the last PVT notification.

Indicates sleep periods during duty-cycled tracking.

NRF_MODEM_GNSS_PVT_FLAG_DEADLINE_MISSED

Notification deadline was missed.

Indicates that GNSS has not received a time window since the last PVT notification due to LTE activity, blocking GNSS operation.

NRF_MODEM_GNSS_PVT_FLAG_NOT_ENOUGH_WINDOW_TIME

Average time windows granted to GNSS may be too short.

Indicates that the inability to produce a valid PVT estimate is likely caused by too short GNSS time windows. Usually this happens when eDRX and/or PSM are not used, because LTE needs to monitor pagings from the network with a short interval.

NRF_MODEM_GNSS_PVT_FLAG_VELOCITY_VALID

The velocity estimate is valid.

Satellite flags bitmask values

group nrf_modem_gnss_sv_flag_bitmask

Bitmask values for the flags member in the SV elements in the PVT notification struct.

Defines

NRF_MODEM_GNSS_SV_FLAG_USED_IN_FIX

The satellite is used in the position calculation.

NRF_MODEM_GNSS_SV_FLAG_UNHEALTHY

The satellite is unhealthy.

A-GPS data request bitmask values

group nrf_modem_gnss_agps_data_bitmask

Bitmask values for the data_flags member in the nrf_modem_gnss_agps_data_frame.

Defines

NRF_MODEM_GNSS_AGPS_GPS_UTC_REQUEST

GPS UTC parameters assistance data.

NRF_MODEM_GNSS_AGPS_KLOBUCHAR_REQUEST

Klobuchar ionospheric correction parameters assistance data.

NRF_MODEM_GNSS_AGPS_NEQUICK_REQUEST

NeQuick ionospheric correction parameters assistance data.

NRF_MODEM_GNSS_AGPS_SYS_TIME_AND_SV_TOW_REQUEST

GPS system time and SV TOWs assistance data.

NRF_MODEM_GNSS_AGPS_POSITION_REQUEST

Position assistance parameters assistance data.

NRF_MODEM_GNSS_AGPS_INTEGRITY_REQUEST

Integrity assistance parameters assistance data.

A-GPS data types

group nrf_modem_gnss_agps_data_type

Use these values to indicate the type of A-GPS data written using nrf_modem_gnss_agps_write.

Defines

NRF_MODEM_GNSS_AGPS_UTC_PARAMETERS

GPS UTC assistance A-GPS parameters.

Data model nrf_modem_gnss_agps_data_utc.

NRF_MODEM_GNSS_AGPS_EPHEMERIDES

GPS ephemeris assistance A-GPS parameters.

Data model nrf_modem_gnss_agps_data_ephemeris.

NRF_MODEM_GNSS_AGPS_ALMANAC

GPS almanac assistance A-GPS parameters.

Data model nrf_modem_gnss_agps_data_almanac.

NRF_MODEM_GNSS_AGPS_KLOBUCHAR_IONOSPHERIC_CORRECTION

GPS ionospheric assistance A-GPS parameters, Klobuchar model.

Data model nrf_modem_gnss_agps_data_klobuchar.

NRF_MODEM_GNSS_AGPS_NEQUICK_IONOSPHERIC_CORRECTION

GPS ionospheric assistance A-GPS parameters, NeQuick model.

Data model nrf_modem_gnss_agps_data_nequick.

NRF_MODEM_GNSS_AGPS_GPS_SYSTEM_CLOCK_AND_TOWS

GPS system time and SV TOW assistance A-GPS parameter.

Data model nrf_modem_gnss_agps_data_system_time_and_sv_tow.

NRF_MODEM_GNSS_AGPS_LOCATION

GPS location assistance A-GPS parameters.

Data model nrf_modem_gnss_agps_data_location.

NRF_MODEM_GNSS_AGPS_INTEGRITY

GPS integrity assistance A-GPS parameters.

Data model nrf_modem_gnss_agps_data_integrity.

Delete bitmask values

group nrf_modem_gnss_delete_bitmask

Bitmask values to be used as an argument for function nrf_modem_gnss_nv_data_delete.

Defines

NRF_MODEM_GNSS_DELETE_EPHEMERIDES

Ephemerides.

NRF_MODEM_GNSS_DELETE_ALMANACS

Almanacs (excluding leap second and ionospheric correction).

NRF_MODEM_GNSS_DELETE_IONO_CORRECTION_DATA

Ionospheric correction parameters.

NRF_MODEM_GNSS_DELETE_LAST_GOOD_FIX

Last good fix (the last position).

NRF_MODEM_GNSS_DELETE_GPS_TOW

GPS time-of-week (TOW).

NRF_MODEM_GNSS_DELETE_GPS_WEEK

GPS week number.

NRF_MODEM_GNSS_DELETE_UTC_DATA

Leap second (UTC parameters).

NRF_MODEM_GNSS_DELETE_TCXO_OFFSET

Local clock (TCXO) frequency offset.

NRF_MODEM_GNSS_DELETE_GPS_TOW_PRECISION

Precision estimate of GPS time-of-week (TOW).

GNSS system bitmask values

group nrf_modem_gnss_system_bitmask

Use these bitmask values to enable different GNSS systems.

The values can be OR’ed together to enable multiple GNSS systems at the same time. If a systems bit is 0, the corresponding system is disabled.

Defines

NRF_MODEM_GNSS_SYSTEM_GPS_MASK

Global Positioning System (GPS).

Note

GPS can’t be disabled and remains enabled even if the corresponding bit is not set.

NRF_MODEM_GNSS_SYSTEM_QZSS_MASK

Quasi-Zenith Satellite System (QZSS).

Note

Only supported by modem firmware v1.3.0 or later.

NMEA string bitmask values

group nrf_modem_gnss_nmea_string_bitmask

Use these bitmask values to enable different type of NMEA output strings.

The values can be OR’ed together to enable multiple string types at the same time. Writing 0 to the bit position will disable the corresponding NMEA string type.

Defines

NRF_MODEM_GNSS_NMEA_GGA_MASK

Enables Global Positioning System Fix Data.

NRF_MODEM_GNSS_NMEA_GLL_MASK

Enables Geographic Position Latitude/Longitude and time.

NRF_MODEM_GNSS_NMEA_GSA_MASK

Enables DOP and active satellites.

NRF_MODEM_GNSS_NMEA_GSV_MASK

Enables Satellites in view.

NRF_MODEM_GNSS_NMEA_RMC_MASK

Enables Recommended minimum specific GPS/Transit data.

Power save modes

group nrf_modem_gnss_power_save_modes

Use these values to select which power save mode GNSS should use. This only affects continuous navigation mode. When GNSS engages duty-cycled tracking, it only tracks for 20% of time and spends the rest of the time in sleep. The different modes control how aggressively GNSS engages duty-cycled tracking, but the duty-cycling itself is the same with both modes.

Defines

NRF_MODEM_GNSS_PSM_DISABLED

No power save mode is enabled.

NRF_MODEM_GNSS_PSM_DUTY_CYCLING_PERFORMANCE

Enables duty-cycling performance policy power save mode.

NRF_MODEM_GNSS_PSM_DUTY_CYCLING_POWER

Enables duty-cycling power policy power save mode.

Use case bitmask values

group nrf_modem_gnss_use_case_bitmask

Use these bit values to select which use case mode GNSS should use. A use case mode is a combination of the values of all of the bits.

Defines

NRF_MODEM_GNSS_USE_CASE_MULTIPLE_HOT_START

Multiple hot starts performance mode.

Note

This is the only start mode currently supported, but the bit should always be set when setting the use-case modes to keep the code compliant with future versions of the modem firmware.

NRF_MODEM_GNSS_USE_CASE_LOW_ACCURACY

Low accuracy fixes allowed.

The error in position calculation can be larger than in normal accuracy mode. In addition, GNSS might only use three satellites to determine a fix, while in normal accuracy mode at least four satellites are used.

NRF_MODEM_GNSS_USE_CASE_SCHED_DOWNLOAD_DISABLE

Disable scheduled downloads.

By default, in periodic navigation mode, when GNSS determines it needs to download ephemerides or almanacs from the broadcast, the fix interval and fix retry parameters are temporarily ignored. GNSS will perform scheduled downloads until it has downloaded the data it needs, after which normal operation is resumed.

When this bit is set, scheduled downloads are disabled. This is recommended when A-GPS is used to supply assistance data to the GNSS. It is also possible to use this option without A-GPS, but it should be noted that in that case GNSS will never get some data (for example ionospheric corrections), which may affect the accuracy.

Note

This is only supported by modem firmware v1.3.1 or later.

Sleep timing sources

group nrf_modem_gnss_timing_source

Used to select which sleep timing source GNSS uses.

Using TCXO instead of RTC during GNSS sleep periods might be beneficial when used with 1PPS. When GNSS is not running all the time (periodic navigation or duty-cycling is used), 1PPS accuracy can be improved by using TCXO. It may also improve sensitivity for periodic navigation when the fix interval is short.

Note

Use of TCXO significantly raises the idle current consumption.

Defines

NRF_MODEM_GNSS_TIMING_SOURCE_RTC

Real time clock (RTC).

NRF_MODEM_GNSS_TIMING_SOURCE_TCXO

Temperature compensated crystal oscillator (TCXO).

QZSS NMEA modes

group nrf_modem_gnss_qzss_nmea_mode

Use these values to select if QZSS satellites are reported in NMEA sentences or not.

Defines

NRF_MODEM_GNSS_QZSS_NMEA_MODE_STANDARD

Standard NMEA reporting.

QZSS satellites not reported in GPGSA and GPGSV sentences.

NRF_MODEM_GNSS_QZSS_NMEA_MODE_CUSTOM

Custom NMEA reporting with QZSS satellites.

QZSS satellites reported in GPGSA and GPGSV sentences using satellite IDs 193…202.

Dynamics modes

group nrf_modem_gnss_dynamics_mode

Dynamics mode values to be used as an argument for function nrf_modem_gnss_dyn_mode_change.

Defines

NRF_MODEM_GNSS_DYNAMICS_GENERAL_PURPOSE

General purpose mode.

NRF_MODEM_GNSS_DYNAMICS_STATIONARY

Optimize for stationary use case.

NRF_MODEM_GNSS_DYNAMICS_PEDESTRIAN

Optimize for pedestrian use case.

NRF_MODEM_GNSS_DYNAMICS_AUTOMOTIVE

Optimize for automotive use case.

OS specific definitions

group nrf_modem_os

Defines

NRF_MODEM_OS_NO_WAIT

Zero time-out.

NRF_MODEM_OS_FOREVER

Infinite time-out.

NRF_MODEM_OS_NUM_SEM_REQUIRED

Number of OS semaphores required.

Enums

enum log_level

Values:

enumerator NRF_MODEM_LOG_LEVEL_NONE
enumerator NRF_MODEM_LOG_LEVEL_ERR
enumerator NRF_MODEM_LOG_LEVEL_WRN
enumerator NRF_MODEM_LOG_LEVEL_INF
enumerator NRF_MODEM_LOG_LEVEL_DBG

Functions

void nrf_modem_os_init(void)

Initialize the glue layer.

void nrf_modem_os_shutdown(void)

Deinitialize the glue layer.

When shutdown is called, all pending calls to nrf_modem_os_timedwait shall exit and return -NRF_ESHUTDOWN.

void *nrf_modem_os_shm_tx_alloc(size_t bytes)

Allocate a buffer on the TX area of shared memory.

Parameters
  • bytes – Buffer size.

Returns

A pointer to the allocated memory buffer or NULL if allocation failed.

void nrf_modem_os_shm_tx_free(void *mem)

Free a shared memory buffer in the TX area.

Parameters
  • mem – Buffer to free.

void *nrf_modem_os_alloc(size_t bytes)

Allocate a buffer on the library heap.

Parameters
  • bytes – Buffer size.

Returns

A pointer to the allocated memory buffer or NULL if allocation failed.

void nrf_modem_os_free(void *mem)

Free a memory buffer in the library heap.

Parameters
  • mem – Buffer to free.

void nrf_modem_os_busywait(int32_t usec)

Busy wait.

Parameters
  • usec – Microseconds to busy wait for.

int32_t nrf_modem_os_timedwait(uint32_t context, int32_t *timeout)

Put a thread to sleep for a specific time or until an event occurs.

All waiting threads shall be woken by nrf_modem_event_notify.

Parameters
  • context[in] A unique identifier assigned by the library to identify the context.

  • timeout[inout] Timeout in millisec or -1 for infinite timeout. Contains the timeout value as input and the remainig time to sleep as output.

Return values
  • 0 – The thread is woken before the timeout expired.

  • -NRF_EAGAIN – The timeout expired.

  • -NRF_ESHUTDOWN – Modem is not initialized, or was shut down.

void nrf_modem_os_event_notify(void)

Notify the application that an event has occurred.

Wake threads waiting in nrf_modem_os_timedwait for a modem event or freeing of memory.

This function shall wake all threads sleeping in nrf_modem_os_timedwait.

void nrf_modem_os_errno_set(int errno_val)

Set errno.

Parameters
  • errno_val – errno to set.

bool nrf_modem_os_is_in_isr(void)

Check if executing in interrupt context.

Return values
  • true – If in interrupt context.

  • false – If not in interrupt context.

int nrf_modem_os_sem_init(void **sem, unsigned int initial_count, unsigned int limit)

Initialize a semaphore.

The function shall allocate and initialize a semaphore and return its address as an output. If an address of an already allocated semaphore is provided as an input, the allocation part is skipped and the semaphore is only reinitialized.

Parameters
  • sem[inout] The address of the semaphore.

  • initial_count – Initial semaphore count.

  • limit – Maximum semaphore count.

Returns

0 on success, a negative errno otherwise.

void nrf_modem_os_sem_give(void *sem)

Give a semaphore.

Note

Can be called from an ISR.

Parameters
  • sem – The semaphore.

int nrf_modem_os_sem_take(void *sem, int timeout)

Take a semaphore.

Note

timeout shall be set to NRF_MODEM_OS_NO_WAIT if called from ISR.

Parameters
  • sem – The semaphore.

  • timeout – Timeout in milliseconds. NRF_MODEM_OS_FOREVER indicates infinite timeout. NRF_MODEM_OS_NO_WAIT indicates no timeout.

Return values
  • 0 – on success.

  • -NRF_EAGAIN – If the semaphore could not be taken.

unsigned int nrf_modem_os_sem_count_get(void *sem)

Get a semaphore’s count.

Parameters
  • sem – The semaphore.

Returns

Current semaphore count.

void nrf_modem_os_log(int level, const char *fmt, ...)

Generic logging procedure.

Parameters
  • level – Log level.

  • fmt – Format string.

  • ... – Varargs.

void nrf_modem_os_logdump(int level, const char *str, const void *data, size_t len)

Logging procedure for dumping hex representation of object.

Parameters
  • level – Log level.

  • str – String to print in the log.

  • data – Data whose hex representation we want to log.

  • len – Length of the data to hex dump.