From 3133db559ecacc45532d0934abf4b3350cb90e69 Mon Sep 17 00:00:00 2001 From: Markus Lassila Date: Tue, 8 Aug 2023 12:52:40 +0300 Subject: [PATCH] applications: serial_lte_modem: Minor UART changes Minor changes to UART functionality. Signed-off-by: Markus Lassila --- applications/serial_lte_modem/src/main.c | 6 ++-- .../serial_lte_modem/src/slm_at_commands.c | 8 ++--- .../serial_lte_modem/src/slm_at_host.c | 3 -- .../serial_lte_modem/src/slm_settings.c | 4 +-- .../serial_lte_modem/src/slm_uart_handler.c | 12 +++----- .../serial_lte_modem/src/slm_uart_handler.h | 30 +++++++++++++++++-- 6 files changed, 39 insertions(+), 24 deletions(-) diff --git a/applications/serial_lte_modem/src/main.c b/applications/serial_lte_modem/src/main.c index 166fae849754..88c28b80c618 100644 --- a/applications/serial_lte_modem/src/main.c +++ b/applications/serial_lte_modem/src/main.c @@ -25,6 +25,7 @@ #include "slm_at_host.h" #include "slm_at_fota.h" #include "slm_settings.h" +#include "slm_uart_handler.h" LOG_MODULE_REGISTER(slm, CONFIG_SLM_LOG_LEVEL); @@ -42,9 +43,6 @@ struct k_work_q slm_work_q; /* global variable defined in different files */ extern int32_t auto_connect; -/* global functions defined in different files */ -int poweron_uart(void); - /* Forward declarations */ static void indicate_wk(struct k_work *work); @@ -202,7 +200,7 @@ static void gpio_cb_func(const struct device *dev, struct gpio_callback *gpio_ca if (err < 0) { LOG_WRN("Failed to enable ext XTAL: %d", err); } - err = poweron_uart(); + err = slm_uart_power_on(); if (err) { LOG_ERR("Failed to power on uart: %d", err); return; diff --git a/applications/serial_lte_modem/src/slm_at_commands.c b/applications/serial_lte_modem/src/slm_at_commands.c index ab02b93218ae..69f8daa5cb40 100644 --- a/applications/serial_lte_modem/src/slm_at_commands.c +++ b/applications/serial_lte_modem/src/slm_at_commands.c @@ -30,6 +30,7 @@ #include "slm_at_icmp.h" #include "slm_at_sms.h" #include "slm_at_fota.h" +#include "slm_uart_handler.h" #if defined(CONFIG_SLM_NATIVE_TLS) #include "slm_at_cmng.h" #endif @@ -82,14 +83,11 @@ static struct slm_work_info { /* global variable defined in different files */ extern struct at_param_list at_param_list; extern uint16_t datamode_time_limit; -extern struct uart_config slm_uart; /* global functions defined in different files */ void enter_idle(void); void enter_sleep(void); void enter_shutdown(void); -int slm_uart_configure(void); -int poweroff_uart(void); bool verify_datamode_control(uint16_t time_limit, uint16_t *time_limit_min); /** @return Whether the modem is in the given functional mode. */ @@ -139,7 +137,7 @@ static void go_sleep_wk(struct k_work *work) ARG_UNUSED(work); if (slm_work.data == SLEEP_MODE_IDLE) { - if (poweroff_uart() == 0) { + if (slm_uart_power_off() == 0) { enter_idle(); } else { LOG_ERR("failed to power off UART"); @@ -354,7 +352,7 @@ static int handle_at_slmuart(enum at_cmd_type type) } } if (type == AT_CMD_TYPE_READ_COMMAND) { - rsp_send("\r\n#XSLMUART: %d,%d\r\n", slm_uart.baudrate, slm_uart.flow_ctrl); + rsp_send("\r\n#XSLMUART: %d\r\n", slm_uart.baudrate); ret = 0; } if (type == AT_CMD_TYPE_TEST_COMMAND) { diff --git a/applications/serial_lte_modem/src/slm_at_host.c b/applications/serial_lte_modem/src/slm_at_host.c index 7da8d3d77e50..108097741ca9 100644 --- a/applications/serial_lte_modem/src/slm_at_host.c +++ b/applications/serial_lte_modem/src/slm_at_host.c @@ -54,9 +54,6 @@ static struct k_work raw_send_scheduled_work; /* global variable used across different files */ struct at_param_list at_param_list; /* For AT parser */ -/* global variable defined in different files */ -extern struct uart_config slm_uart; - /* global functions defined in different files */ int slm_at_parse(const char *at_cmd); int slm_at_init(void); diff --git a/applications/serial_lte_modem/src/slm_settings.c b/applications/serial_lte_modem/src/slm_settings.c index e720edb62565..d1df50037cbd 100644 --- a/applications/serial_lte_modem/src/slm_settings.c +++ b/applications/serial_lte_modem/src/slm_settings.c @@ -20,8 +20,8 @@ LOG_MODULE_REGISTER(slm_config, CONFIG_SLM_LOG_LEVEL); */ uint8_t fota_type; /* FOTA: image type */ enum fota_stage fota_stage = FOTA_STAGE_INIT; /* FOTA: stage of FOTA process */ -enum fota_status fota_status; /* FOTA: OK/Error status */ -int32_t fota_info; /* FOTA: failure cause in case of error or download percentage*/ +enum fota_status fota_status; /* FOTA: OK/Error status */ +int32_t fota_info; /* FOTA: failure cause in case of error or download percentage */ int32_t auto_connect = 1; /* Auto connect network at startup or after FOTA update */ diff --git a/applications/serial_lte_modem/src/slm_uart_handler.c b/applications/serial_lte_modem/src/slm_uart_handler.c index ce746c02f871..5e6428855c55 100644 --- a/applications/serial_lte_modem/src/slm_uart_handler.c +++ b/applications/serial_lte_modem/src/slm_uart_handler.c @@ -62,10 +62,6 @@ K_SEM_DEFINE(tx_done_sem, 0, 1); slm_uart_rx_callback_t rx_callback_t; -/* global variable defined in different files */ -extern bool uart_configured; -extern struct uart_config slm_uart; - /* global functions defined in different files */ int indicate_start(void); @@ -293,7 +289,7 @@ static void uart_callback(const struct device *dev, struct uart_event *evt, void } } -int poweron_uart(void) +int slm_uart_power_on(void) { int err; @@ -317,7 +313,7 @@ int poweron_uart(void) return 0; } -int poweroff_uart(void) +int slm_uart_power_off(void) { int err; @@ -401,8 +397,8 @@ int slm_uart_handler_init(slm_uart_rx_callback_t callback_t) LOG_ERR("UART device not ready"); return -ENODEV; } - /* Save UART configuration to setting page */ if (!uart_configured) { + /* Save UART configuration to settings page */ uart_configured = true; err = uart_config_get(uart_dev, &slm_uart); if (err != 0) { @@ -415,7 +411,7 @@ int slm_uart_handler_init(slm_uart_rx_callback_t callback_t) return err; } } else { - /* else re-config UART based on setting page */ + /* Configure UART based on settings page */ err = slm_uart_configure(); if (err != 0) { LOG_ERR("Fail to set UART baudrate: %d", err); diff --git a/applications/serial_lte_modem/src/slm_uart_handler.h b/applications/serial_lte_modem/src/slm_uart_handler.h index 73cfdb8387d7..63ab37532d02 100644 --- a/applications/serial_lte_modem/src/slm_uart_handler.h +++ b/applications/serial_lte_modem/src/slm_uart_handler.h @@ -7,13 +7,15 @@ #ifndef SLM_UART_HANDLER_ #define SLM_UART_HANDLER_ -#define UART_RX_MARGIN_MS 10 - /**@file slm_uart_handler.h * * @brief UART handler for serial LTE modem * @{ */ +#define UART_RX_MARGIN_MS 10 + +extern bool uart_configured; +extern struct uart_config slm_uart; /**@brief UART RX data callback type. * @@ -22,6 +24,30 @@ */ typedef void (*slm_uart_rx_callback_t)(const uint8_t *data, size_t len); +/** + * @brief Switch UART power on. + * + * @retval 0 If the UART was successfully powered on. + * Otherwise, a (negative) error code is returned. + */ +int slm_uart_power_on(void); + +/** + * @brief Switch UART power off. + * + * @retval 0 If the UART was successfully powered off. + * Otherwise, a (negative) error code is returned. + */ +int slm_uart_power_off(void); + +/** + * @brief Configure UART. + * + * @retval 0 If the UART was successfully configured. + * Otherwise, a (negative) error code is returned. + */ +int slm_uart_configure(void); + /** * @brief Write the data to TX buffer and trigger sending. *