Skip to content

Commit 2db2c75

Browse files
committed
samples: sm_at_client_shell: Enable PM_DEVICE_RUNTIME
Enable PM_DEVICE_RUNTIME for the sm_at_client_shell. UART will be disabled automatically. Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
1 parent 7c8eb25 commit 2db2c75

3 files changed

Lines changed: 7 additions & 44 deletions

File tree

lib/sm_at_client/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ menuconfig SM_AT_CLIENT
1212
select UART_USE_RUNTIME_CONFIGURE
1313
select GPIO_GET_CONFIG
1414
select PM_DEVICE
15+
select PM_DEVICE_RUNTIME
16+
select PM_DEVICE_RUNTIME_DEFAULT_ENABLE
1517

1618
if SM_AT_CLIENT
1719

lib/sm_at_client/sm_at_client.c

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -580,34 +580,6 @@ static int uart_init(const struct device *uart_dev)
580580
return err;
581581
}
582582

583-
static int uart_power_state_action(enum pm_device_action action)
584-
{
585-
enum pm_device_state state = PM_DEVICE_STATE_OFF;
586-
int err = pm_device_state_get(uart_dev, &state);
587-
588-
if (err) {
589-
LOG_ERR("Failed to get PM device state: %d", err);
590-
return err;
591-
}
592-
593-
if (action != PM_DEVICE_ACTION_RESUME && action != PM_DEVICE_ACTION_SUSPEND) {
594-
return -EOPNOTSUPP;
595-
}
596-
597-
if ((action == PM_DEVICE_ACTION_RESUME && state == PM_DEVICE_STATE_ACTIVE) ||
598-
(action == PM_DEVICE_ACTION_SUSPEND && state == PM_DEVICE_STATE_SUSPENDED)) {
599-
return 0;
600-
}
601-
602-
err = pm_device_action_run(uart_dev, action);
603-
if (err) {
604-
LOG_ERR("Action %d failed on UART device: %d", action, err);
605-
return err;
606-
}
607-
608-
return 0;
609-
}
610-
611583
static int dtr_pin_set(bool level)
612584
{
613585
int err;
@@ -651,20 +623,13 @@ static int dtr_uart_disable(void)
651623
/* Optional: Wait for possible Serial Modem TX to complete. */
652624
/* k_sleep(K_MSEC(100)); */
653625

654-
/* Disable RX. */
626+
/* Disable RX: UART is automatically suspended. */
655627
err = rx_disable();
656628
if (err) {
657629
LOG_ERR("RX disable failed (%d).", err);
658630
return err;
659631
}
660632

661-
/* Power off UART module */
662-
err = uart_power_state_action(PM_DEVICE_ACTION_SUSPEND);
663-
if (err) {
664-
LOG_ERR("Failed to suspend UART (%d).", err);
665-
return err;
666-
}
667-
668633
LOG_DBG("DTR UART disable: %s.", "Done");
669634
return 0;
670635
}
@@ -690,14 +655,7 @@ static int dtr_uart_enable(void)
690655
/* Set DTR state at beginning so that we have correct state when RI comes. */
691656
dtr_config.active = true;
692657

693-
/* Power on UART module */
694-
err = uart_power_state_action(PM_DEVICE_ACTION_RESUME);
695-
if (err) {
696-
LOG_ERR("Failed to resume UART (%d).", err);
697-
return err;
698-
}
699-
700-
/* Enable RX. */
658+
/* Enable RX: UART is automatically resumed. */
701659
atomic_clear_bit(&uart_state, SM_AT_CLIENT_RX_RECOVERY_DISABLED_BIT);
702660
err = rx_enable();
703661
if (err) {

samples/sm_at_client_shell/prj.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ CONFIG_SHELL_CMD_BUFF_SIZE=1024
2020
CONFIG_SHELL_STACK_SIZE=2048
2121
CONFIG_SHELL_LOG_BACKEND=n
2222

23+
CONFIG_PM_DEVICE=y
24+
CONFIG_PM_DEVICE_RUNTIME=y
25+
2326
CONFIG_SERIAL=y
2427
CONFIG_UART_ASYNC_API=y
2528

0 commit comments

Comments
 (0)