Skip to content
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
2 changes: 1 addition & 1 deletion applications/93m1_at/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ target_sources(app PRIVATE
src/main.c
src/modules/network/network.c
src/modules/modem_at/modem_at.c
src/modules/cloud/cloud.c
)

target_sources_ifdef(CONFIG_APP_CLOUD app PRIVATE src/modules/cloud/cloud.c)
target_sources_ifdef(CONFIG_APP_MODEM_AT_SHELL app PRIVATE src/modules/modem_at/modem_at_shell.c)
target_sources_ifdef(CONFIG_APP_LOCATION app PRIVATE src/modules/location/location.c)
target_sources_ifdef(CONFIG_APP_BATTERY app PRIVATE src/modules/battery/battery.c)
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# Async UART with hardware flow control for the raw-AT modem backend.
# Async UART with hardware flow control for the cellular modem driver.
CONFIG_UART_INTERRUPT_DRIVEN=n
CONFIG_UART_ASYNC_API=y
CONFIG_SHELL_BACKEND_SERIAL_API_ASYNC=y
CONFIG_MODEM_BACKEND_UART_ASYNC_HWFC=y
CONFIG_MODEM_BACKEND_UART_ASYNC_RECEIVE_IDLE_TIMEOUT_MS=1
CONFIG_MODEM_CMUX_MSC_FC_THRESHOLD=32

# Default TF-M configuration
CONFIG_TFM_SFN=y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
zephyr,console = &uart20;
zephyr,shell-uart = &uart20;
zephyr,entropy = &psa_rng;
zephyr,modem-uart = &uart30;
};
};

/* Zephyr modem UART <-> nRF93M1 AT interface */
/* Cellular modem driver */
&uart30 {
status = "okay";
current-speed = <115200>;
Expand Down
45 changes: 41 additions & 4 deletions applications/93m1_at/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ CONFIG_ZBUS=y
CONFIG_ZBUS_MSG_SUBSCRIBER=y
CONFIG_SMF=y
CONFIG_SMF_ANCESTOR_SUPPORT=y
CONFIG_SMF_INITIAL_TRANSITION=y
CONFIG_TASK_WDT=y
CONFIG_HEAP_MEM_POOL_SIZE=8192

# Logging
CONFIG_LOG=y
Expand All @@ -42,10 +44,45 @@ CONFIG_SHELL_STACK_SIZE=4096
CONFIG_SHELL_WILDCARD=n
CONFIG_SHELL_BACKEND_SERIAL_ASYNC_RX_BUFFER_SIZE=64

# Zephyr modem subsystem
CONFIG_MODEM_MODULES=y
CONFIG_MODEM_CHAT=y
CONFIG_MODEM_BACKEND_UART=y
# Networking: PPP link only for automatic connectivity management
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=y
CONFIG_NET_L2_PPP=y
CONFIG_NET_L2_ETHERNET=n
CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=n
# UDP is kept on so the native IP core compiles
CONFIG_NET_UDP=y
CONFIG_NET_TCP=n
CONFIG_NET_SOCKETS=n
CONFIG_NET_MAX_CONN=4
CONFIG_NET_MAX_CONTEXTS=4
CONFIG_NET_MGMT=y
CONFIG_NET_MGMT_EVENT=y
CONFIG_NET_CONNECTION_MANAGER=y
CONFIG_NET_CONNECTION_MANAGER_MONITOR_STACK_SIZE=512
CONFIG_NET_MGMT_EVENT_STACK_SIZE=800
CONFIG_NET_PKT_RX_COUNT=8
CONFIG_NET_PKT_TX_COUNT=8
CONFIG_NET_BUF_RX_COUNT=16
CONFIG_NET_BUF_TX_COUNT=16
CONFIG_NET_LOG=y
CONFIG_NET_SHELL=y

# Cellular modem driver
CONFIG_MODEM=y
CONFIG_MODEM_CELLULAR=y
CONFIG_MODEM_DEDICATED_WORKQUEUE=y
CONFIG_PM_DEVICE_RUNTIME=y
CONFIG_PM_DEVICE_RUNTIME_USE_DEDICATED_WQ=y
CONFIG_MODEM_CMUX_MTU=127
CONFIG_MODEM_CMUX_WORK_BUFFER_SIZE_EXTRA=532
CONFIG_MODEM_CELLULAR_UART_BUFFER_SIZES=532
# Disable the in-tree modem AT shell.
CONFIG_MODEM_AT_SHELL=n
CONFIG_MODEM_AT_USER_PIPE_IDX=0
CONFIG_MODEM_CELLULAR_USER_PIPE_BUFFER_SIZES=1024
CONFIG_MODEM_CMUX_LOG_LEVEL_INF=y

# Board peripherals
CONFIG_GPIO=y
Expand Down
80 changes: 52 additions & 28 deletions applications/93m1_at/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
#include <zephyr/smf.h>

#include "app_common.h"
#include "modules/modem_at/modem_at.h"
#include "modules/network/network.h"
#include "modules/cloud/cloud.h"
#if defined(CONFIG_APP_LOCATION)
#include "modules/location/location.h"
#endif
Expand Down Expand Up @@ -58,29 +56,57 @@ struct app_object {
uint8_t msg_buf[MAX_MSG_SIZE];
};

static struct app_object app;
static const struct smf_state states[];
static void sync_timer_fn(struct k_work *work);
static K_WORK_DELAYABLE_DEFINE(sync_timer, sync_timer_fn);

static void request_module_updates(void);
static enum smf_state_result disconnected_run(void *obj);
static void connected_entry(void *obj);
static enum smf_state_result connected_run(void *obj);
static void connected_exit(void *obj);
static void wdt_callback(int channel_id, void *user_data);

static const struct smf_state states[] = {
[STATE_DISCONNECTED] = SMF_CREATE_STATE(NULL, disconnected_run, NULL, NULL, NULL),
[STATE_CONNECTED] = SMF_CREATE_STATE(connected_entry, connected_run, connected_exit,
NULL, NULL),
};

/* Periodic sync trigger: publishes MAIN_SYNC; the state machine drives it. */
static void sync_timer_fn(struct k_work *work)
{
ARG_UNUSED(work);

struct main_msg msg = { .type = MAIN_SYNC };
int err;

(void)zbus_chan_pub(&main_chan, &msg, PUB_TIMEOUT);
err = zbus_chan_pub(&main_chan, &msg, PUB_TIMEOUT);
if (err) {
LOG_ERR("zbus_chan_pub main_chan, error: %d", err);
}
}

static K_WORK_DELAYABLE_DEFINE(sync_timer, sync_timer_fn);

static void run_sync(void)
static void request_module_updates(void)
{
LOG_INF("Sync");
int err;

LOG_DBG("Requesting module updates");
#if defined(CONFIG_APP_LOCATION)
location_update();
struct location_msg loc_msg = { .type = LOCATION_FIX_REQUEST };

err = zbus_chan_pub(&location_chan, &loc_msg, PUB_TIMEOUT);
if (err) {
LOG_ERR("zbus_chan_pub location_chan, error: %d", err);
}
#endif
#if defined(CONFIG_APP_BATTERY)
(void)battery_report();
struct battery_msg bat_msg = { .type = BATTERY_SAMPLE };

err = zbus_chan_pub(&battery_chan, &bat_msg, PUB_TIMEOUT);
if (err) {
LOG_ERR("zbus_chan_pub battery_chan, error: %d", err);
}
#endif
ARG_UNUSED(err);
}

static enum smf_state_result disconnected_run(void *obj)
Expand All @@ -101,10 +127,14 @@ static enum smf_state_result disconnected_run(void *obj)
static void connected_entry(void *obj)
{
ARG_UNUSED(obj);
int err;

LOG_INF("Connected");

/* First sync shortly after connecting. */
(void)k_work_reschedule(&sync_timer, K_SECONDS(CONFIG_APP_SYNC_BOOT_DELAY_SECONDS));
err = k_work_reschedule(&sync_timer, K_SECONDS(CONFIG_APP_SYNC_BOOT_DELAY_SECONDS));
if (err < 0) {
LOG_ERR("k_work_reschedule sync_timer, error: %d", err);
}
}

static enum smf_state_result connected_run(void *obj)
Expand All @@ -121,8 +151,13 @@ static enum smf_state_result connected_run(void *obj)
const struct main_msg *msg = (const struct main_msg *)state->msg_buf;

if (msg->type == MAIN_SYNC) {
run_sync();
(void)k_work_reschedule(&sync_timer, K_SECONDS(CONFIG_APP_SYNC_INTERVAL));
int err;

request_module_updates();
err = k_work_reschedule(&sync_timer, K_SECONDS(CONFIG_APP_SYNC_INTERVAL));
if (err < 0) {
LOG_ERR("k_work_reschedule sync_timer, error: %d", err);
}
}
}

Expand All @@ -135,12 +170,6 @@ static void connected_exit(void *obj)
(void)k_work_cancel_delayable(&sync_timer);
}

static const struct smf_state states[] = {
[STATE_DISCONNECTED] = SMF_CREATE_STATE(NULL, disconnected_run, NULL, NULL, NULL),
[STATE_CONNECTED] = SMF_CREATE_STATE(connected_entry, connected_run, connected_exit,
NULL, NULL),
};

static void wdt_callback(int channel_id, void *user_data)
{
LOG_ERR("Main watchdog expired, channel: %d, thread: %s",
Expand All @@ -158,6 +187,7 @@ int main(void)
const uint32_t execution_time_ms =
(CONFIG_APP_MAIN_MSG_PROCESSING_TIMEOUT_SECONDS * MSEC_PER_SEC);
const k_timeout_t zbus_wait = K_MSEC(wdt_timeout_ms - execution_time_ms);
static struct app_object app;

task_wdt_id = task_wdt_add(wdt_timeout_ms, wdt_callback, (void *)k_current_get());
if (task_wdt_id < 0) {
Expand All @@ -166,12 +196,6 @@ int main(void)
return -EFAULT;
}

if (modem_at_setup() < 0) {
SEND_FATAL_ERROR();
return -EFAULT;
}
(void)cloud_provision();

smf_set_initial(SMF_CTX(&app), &states[STATE_DISCONNECTED]);

while (true) {
Expand Down
13 changes: 6 additions & 7 deletions applications/93m1_at/src/modules/battery/Kconfig.battery
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
menuconfig APP_BATTERY
bool "Battery module"
default y
depends on APP_MODEM_AT && NRF_FUEL_GAUGE && NPM13XX_CHARGER
depends on APP_CLOUD && NRF_FUEL_GAUGE && NPM13XX_CHARGER
help
Samples the nPM1300 fuel gauge and reports state of charge to nRF Cloud as
an AT%NRFCLOUDMESSAGE (appId "BATTERY"). Driven by the sync state machine in
main.
Samples the nPM1300 fuel gauge and publishes state of charge to the cloud
module, which forwards it to nRF Cloud.

if APP_BATTERY

config APP_BATTERY_AT_TIMEOUT_SECONDS
int "AT%NRFCLOUDMESSAGE timeout (seconds)"
default 60
config APP_BATTERY_THREAD_STACK_SIZE
int "Battery thread stack size (bytes)"
default 2048

module = APP_BATTERY
module-str = battery
Expand Down
Loading