From d38bf3ff2dbb75f0ad8bf4b9abcdce40cda0c07d Mon Sep 17 00:00:00 2001 From: raiden00pl Date: Thu, 16 Nov 2023 14:16:14 +0100 Subject: [PATCH] nrf91/nrf91_modem.c: configure system mode --- arch/arm/src/nrf91/Kconfig | 27 +++++++++++++++++++ arch/arm/src/nrf91/nrf91_modem.c | 46 ++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/arch/arm/src/nrf91/Kconfig b/arch/arm/src/nrf91/Kconfig index 902d71babd..ed57c976fa 100644 --- a/arch/arm/src/nrf91/Kconfig +++ b/arch/arm/src/nrf91/Kconfig @@ -742,4 +742,31 @@ config NRF91_MODEM_AT bool "Modem AT interface support" default y +config NRF91_MODEM_LTEM + bool "Modem LTE-M mode support" + default y + +config NRF91_MODEM_NBIOT + bool "Modem NB-IoT mode support" + default n + +config NRF91_MODEM_GNSS + bool "Modem GNSS support" + depends on SENSORS_GPS + default y + +config NRF91_MODEM_PREFERENCE + int "Modem mode preference" + default 0 + range 0 4 + ---help--- + 0 - No preference. Initial system selection is based on history data and USIM + 1 - LTE-M preferred + 2 - NB-IoT preferred + 3 - Network selection priorities override system priority, but LTE-M is prefered + 4 - Network selection priorities override system priority, but NB-IoT is prefered + + For details look at "nRF9160 AT Commands Command Reference Guid" from Nordic, + section "5.27 System mode" + endif # NRF91_MODEM diff --git a/arch/arm/src/nrf91/nrf91_modem.c b/arch/arm/src/nrf91/nrf91_modem.c index c18e2adac9..59d97e7b32 100644 --- a/arch/arm/src/nrf91/nrf91_modem.c +++ b/arch/arm/src/nrf91/nrf91_modem.c @@ -32,6 +32,7 @@ #include "chip.h" #include "nrf_modem.h" +#include "nrf_modem_at.h" #include "nrf91_modem.h" @@ -47,6 +48,18 @@ # error NRF91 modem requires using LFXO as the LFCLK source #endif +#ifndef CONFIG_NRF91_MODEM_LTEM +# define CONFIG_NRF91_MODEM_LTEM 0 +#endif + +#ifndef CONFIG_NRF91_MODEM_NBIOT +# define CONFIG_NRF91_MODEM_NBIOT 0 +#endif + +#ifndef CONFIG_NRF91_MODEM_GNSS +# define CONFIG_NRF91_MODEM_GNSS 0 +#endif + /**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -102,6 +115,30 @@ static void nrf91_modem_fault_handler(struct nrf_modem_fault_info *info) ASSERT(0); } +/**************************************************************************** + * Name: nrf91_modem_config + ****************************************************************************/ + +static int nrf91_modem_config(void) +{ + int ret; + + /* Configure modem system mode */ + + ret = nrf_modem_at_printf("AT%%XSYSTEMMODE=%d,%d,%d,%d", + CONFIG_NRF91_MODEM_LTEM, + CONFIG_NRF91_MODEM_NBIOT, + CONFIG_NRF91_MODEM_GNSS, + CONFIG_NRF91_MODEM_PREFERENCE); + if (ret < 0) + { + goto errout; + } + +errout: + return ret; +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -125,6 +162,15 @@ int nrf91_modem_initialize(void) /* Initial modem configuration */ + ret = nrf91_modem_config(); + if (ret < 0) + { + nerr("nrf91_modem_config failed %d\n", ret); + goto errout; + } + + /* Initial modem configuration */ + ret = nrf91_modem_config(); if (ret < 0) {