Skip to content

Commit 7ab3515

Browse files
trantanenrlubos
authored andcommitted
lib: modem_slm: Set global_shell ptr in init
Setting global_shell pointer in modem_slm_init() based on used shell backend. Signed-off-by: Tommi Rantanen <[email protected]>
1 parent 522f546 commit 7ab3515

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/modem_slm/modem_slm.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <zephyr/shell/shell.h>
1010
#include <hal/nrf_gpio.h>
1111
#include <modem/modem_slm.h>
12+
#include <zephyr/shell/shell_uart.h>
13+
#include <zephyr/shell/shell_rtt.h>
1214
#include <zephyr/logging/log.h>
1315

1416
LOG_MODULE_REGISTER(mdm_slm, CONFIG_MODEM_SLM_LOG_LEVEL);
@@ -51,7 +53,7 @@ static struct k_work_delayable gpio_wakeup_work;
5153
static slm_ind_handler_t ind_handler;
5254

5355
#if defined(CONFIG_MODEM_SLM_SHELL)
54-
static struct shell *global_shell;
56+
static const struct shell *global_shell;
5557
static const char at_usage_str[] = "Usage: slm <at_command>";
5658
#endif
5759

@@ -398,6 +400,12 @@ int modem_slm_init(slm_data_handler_t handler)
398400
k_work_init(&slm_data_work, slm_data_wk);
399401
k_work_init_delayable(&uart_recovery_work, uart_recovery_wk);
400402

403+
/* Initialize shell pointer so it's available for printing in callbacks */
404+
#if defined(CONFIG_SHELL_BACKEND_SERIAL)
405+
global_shell = shell_backend_uart_get_ptr();
406+
#elif defined(CONFIG_SHELL_BACKEND_RTT)
407+
global_shell = shell_backend_rtt_get_ptr();
408+
#endif
401409
return 0;
402410
}
403411

@@ -515,8 +523,6 @@ int modem_slm_send_data(const uint8_t *const data, size_t datalen)
515523

516524
int modem_slm_shell(const struct shell *shell, size_t argc, char **argv)
517525
{
518-
global_shell = (struct shell *)shell;
519-
520526
if (argc < 2) {
521527
shell_print(shell, "%s", at_usage_str);
522528
return 0;

0 commit comments

Comments
 (0)