Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

applications: serial_lte_modem: Minor UART changes #11984

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions applications/serial_lte_modem/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions applications/serial_lte_modem/src/slm_at_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions applications/serial_lte_modem/src/slm_at_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions applications/serial_lte_modem/src/slm_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
12 changes: 4 additions & 8 deletions applications/serial_lte_modem/src/slm_uart_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand All @@ -317,7 +313,7 @@ int poweron_uart(void)
return 0;
}

int poweroff_uart(void)
int slm_uart_power_off(void)
{
int err;

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
30 changes: 28 additions & 2 deletions applications/serial_lte_modem/src/slm_uart_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand Down
Loading