|
9 | 9 | #include <zephyr/shell/shell.h> |
10 | 10 | #include <hal/nrf_gpio.h> |
11 | 11 | #include <modem/modem_slm.h> |
| 12 | +#include <zephyr/shell/shell_uart.h> |
| 13 | +#include <zephyr/shell/shell_rtt.h> |
12 | 14 | #include <zephyr/logging/log.h> |
13 | 15 |
|
14 | 16 | LOG_MODULE_REGISTER(mdm_slm, CONFIG_MODEM_SLM_LOG_LEVEL); |
@@ -51,7 +53,7 @@ static struct k_work_delayable gpio_wakeup_work; |
51 | 53 | static slm_ind_handler_t ind_handler; |
52 | 54 |
|
53 | 55 | #if defined(CONFIG_MODEM_SLM_SHELL) |
54 | | -static struct shell *global_shell; |
| 56 | +static const struct shell *global_shell; |
55 | 57 | static const char at_usage_str[] = "Usage: slm <at_command>"; |
56 | 58 | #endif |
57 | 59 |
|
@@ -398,6 +400,12 @@ int modem_slm_init(slm_data_handler_t handler) |
398 | 400 | k_work_init(&slm_data_work, slm_data_wk); |
399 | 401 | k_work_init_delayable(&uart_recovery_work, uart_recovery_wk); |
400 | 402 |
|
| 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 |
401 | 409 | return 0; |
402 | 410 | } |
403 | 411 |
|
@@ -515,8 +523,6 @@ int modem_slm_send_data(const uint8_t *const data, size_t datalen) |
515 | 523 |
|
516 | 524 | int modem_slm_shell(const struct shell *shell, size_t argc, char **argv) |
517 | 525 | { |
518 | | - global_shell = (struct shell *)shell; |
519 | | - |
520 | 526 | if (argc < 2) { |
521 | 527 | shell_print(shell, "%s", at_usage_str); |
522 | 528 | return 0; |
|
0 commit comments