Skip to content

Commit 499de99

Browse files
tokangasrlubos
authored andcommitted
samples: cellular: modem_shell: Add SYSTEMOFF support
Add support to set device to SYSTEMOFF using the "link modem --systemoff" command. Signed-off-by: Tommi Kangas <[email protected]>
1 parent 4a671af commit 499de99

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

samples/cellular/modem_shell/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ CONFIG_DEVMEM_SHELL=n
5050

5151
# Device power management
5252
CONFIG_PM_DEVICE=y
53+
CONFIG_POWEROFF=y
5354

5455
# Needed for changing the UART baudrate at runtime
5556
CONFIG_UART_USE_RUNTIME_CONFIGURE=y

samples/cellular/modem_shell/src/link/link_shell.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
*/
66

77
#include <stdio.h>
8+
#include <unistd.h>
9+
#include <getopt.h>
810

911
#include <zephyr/shell/shell.h>
1012
#include <zephyr/shell/shell_uart.h>
11-
#include <unistd.h>
12-
#include <getopt.h>
13+
#include <zephyr/sys/poweroff.h>
1314

1415
#include <nrf_modem_at.h>
1516
#include <modem/nrf_modem_lib.h>
@@ -375,6 +376,7 @@ static const char link_modem_usage_str[] =
375376
" --init, Initialize modem using nrf_modem_lib_init()\n"
376377
" --shutdown, Shutdown modem\n"
377378
" --shutdown_cfun0, Send AT+CFUN=0 AT command and shutdown modem\n"
379+
" --systemoff, Send AT+CFUN=0 AT command, shutdown modem and trigger SYSTEMOFF\n"
378380
" -h, --help, Shows this help information\n"
379381
"\n"
380382
"Several options can be given and they are run in the given order.";
@@ -448,6 +450,7 @@ enum {
448450
LINK_SHELL_OPT_MODEM_INIT,
449451
LINK_SHELL_OPT_MODEM_SHUTDOWN,
450452
LINK_SHELL_OPT_MODEM_SHUTDOWN_CFUN0,
453+
LINK_SHELL_OPT_MODEM_SYSTEMOFF,
451454
LINK_SHELL_OPT_ENVEVAL_EVAL_TYPE,
452455
LINK_SHELL_OPT_ENVEVAL_PLMNS,
453456
};
@@ -528,6 +531,7 @@ static struct option long_options[] = {
528531
{ "init", no_argument, 0, LINK_SHELL_OPT_MODEM_INIT },
529532
{ "shutdown", no_argument, 0, LINK_SHELL_OPT_MODEM_SHUTDOWN },
530533
{ "shutdown_cfun0", no_argument, 0, LINK_SHELL_OPT_MODEM_SHUTDOWN_CFUN0 },
534+
{ "systemoff", no_argument, 0, LINK_SHELL_OPT_MODEM_SYSTEMOFF },
531535
{ "eval_type", required_argument, 0, LINK_SHELL_OPT_ENVEVAL_EVAL_TYPE },
532536
{ "plmns", required_argument, 0, LINK_SHELL_OPT_ENVEVAL_PLMNS },
533537
{ 0, 0, 0, 0 }
@@ -1719,6 +1723,14 @@ static int link_shell_modem(const struct shell *shell, size_t argc, char **argv)
17191723
nrf_modem_at_printf("AT+CFUN=0");
17201724
nrf_modem_lib_shutdown();
17211725
break;
1726+
case LINK_SHELL_OPT_MODEM_SYSTEMOFF:
1727+
operation_selected = true;
1728+
nrf_modem_at_printf("AT+CFUN=0");
1729+
nrf_modem_lib_shutdown();
1730+
printk("Entering SYSTEMOFF in 1 second, wakeup only with reset\n");
1731+
k_sleep(K_SECONDS(1));
1732+
sys_poweroff();
1733+
break;
17221734

17231735
case 'h':
17241736
goto show_usage;

0 commit comments

Comments
 (0)