Skip to content

Commit ab5c6f8

Browse files
applications: 93m1_at: General cleanup of the 93m1_at application
General cleanup and refactoring of the 93m1_at application. Signed-off-by: Syver Haraldsen <syver.haraldsen@nordicsemi.no>
1 parent 7bf96f4 commit ab5c6f8

21 files changed

Lines changed: 689 additions & 548 deletions

applications/93m1_at/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ target_sources(app PRIVATE
2020
src/main.c
2121
src/modules/network/network.c
2222
src/modules/modem_at/modem_at.c
23-
src/modules/cloud/cloud.c
2423
)
2524

25+
target_sources_ifdef(CONFIG_APP_CLOUD app PRIVATE src/modules/cloud/cloud.c)
2626
target_sources_ifdef(CONFIG_APP_MODEM_AT_SHELL app PRIVATE src/modules/modem_at/modem_at_shell.c)
2727
target_sources_ifdef(CONFIG_APP_LOCATION app PRIVATE src/modules/location/location.c)
2828
target_sources_ifdef(CONFIG_APP_BATTERY app PRIVATE src/modules/battery/battery.c)

applications/93m1_at/boards/nrf93m1dk_nrf54l15_cpuapp_ns.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
#
66

7-
# Async UART with hardware flow control for the raw-AT modem backend.
7+
# Async UART with hardware flow control for the cellular modem driver.
88
CONFIG_UART_INTERRUPT_DRIVEN=n
99
CONFIG_UART_ASYNC_API=y
1010
CONFIG_SHELL_BACKEND_SERIAL_API_ASYNC=y
1111
CONFIG_MODEM_BACKEND_UART_ASYNC_HWFC=y
1212
CONFIG_MODEM_BACKEND_UART_ASYNC_RECEIVE_IDLE_TIMEOUT_MS=1
13+
CONFIG_MODEM_CMUX_MSC_FC_THRESHOLD=32
1314

1415
# Default TF-M configuration
1516
CONFIG_TFM_SFN=y

applications/93m1_at/boards/nrf93m1dk_nrf54l15_cpuapp_ns.overlay

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
zephyr,console = &uart20;
1515
zephyr,shell-uart = &uart20;
1616
zephyr,entropy = &psa_rng;
17-
zephyr,modem-uart = &uart30;
1817
};
1918
};
2019

21-
/* Zephyr modem UART <-> nRF93M1 AT interface */
20+
/* Cellular modem driver */
2221
&uart30 {
2322
status = "okay";
2423
current-speed = <115200>;

applications/93m1_at/prj.conf

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ CONFIG_ZBUS=y
2828
CONFIG_ZBUS_MSG_SUBSCRIBER=y
2929
CONFIG_SMF=y
3030
CONFIG_SMF_ANCESTOR_SUPPORT=y
31+
CONFIG_SMF_INITIAL_TRANSITION=y
3132
CONFIG_TASK_WDT=y
33+
CONFIG_HEAP_MEM_POOL_SIZE=8192
3234

3335
# Logging
3436
CONFIG_LOG=y
@@ -42,10 +44,45 @@ CONFIG_SHELL_STACK_SIZE=4096
4244
CONFIG_SHELL_WILDCARD=n
4345
CONFIG_SHELL_BACKEND_SERIAL_ASYNC_RX_BUFFER_SIZE=64
4446

45-
# Zephyr modem subsystem
46-
CONFIG_MODEM_MODULES=y
47-
CONFIG_MODEM_CHAT=y
48-
CONFIG_MODEM_BACKEND_UART=y
47+
# Networking: PPP link only for automatic connectivity management
48+
CONFIG_NETWORKING=y
49+
CONFIG_NET_NATIVE=y
50+
CONFIG_NET_L2_PPP=y
51+
CONFIG_NET_L2_ETHERNET=n
52+
CONFIG_NET_IPV4=y
53+
CONFIG_NET_IPV6=n
54+
# UDP is kept on so the native IP core compiles
55+
CONFIG_NET_UDP=y
56+
CONFIG_NET_TCP=n
57+
CONFIG_NET_SOCKETS=n
58+
CONFIG_NET_MAX_CONN=4
59+
CONFIG_NET_MAX_CONTEXTS=4
60+
CONFIG_NET_MGMT=y
61+
CONFIG_NET_MGMT_EVENT=y
62+
CONFIG_NET_CONNECTION_MANAGER=y
63+
CONFIG_NET_CONNECTION_MANAGER_MONITOR_STACK_SIZE=512
64+
CONFIG_NET_MGMT_EVENT_STACK_SIZE=800
65+
CONFIG_NET_PKT_RX_COUNT=8
66+
CONFIG_NET_PKT_TX_COUNT=8
67+
CONFIG_NET_BUF_RX_COUNT=16
68+
CONFIG_NET_BUF_TX_COUNT=16
69+
CONFIG_NET_LOG=y
70+
CONFIG_NET_SHELL=y
71+
72+
# Cellular modem driver
73+
CONFIG_MODEM=y
74+
CONFIG_MODEM_CELLULAR=y
75+
CONFIG_MODEM_DEDICATED_WORKQUEUE=y
76+
CONFIG_PM_DEVICE_RUNTIME=y
77+
CONFIG_PM_DEVICE_RUNTIME_USE_DEDICATED_WQ=y
78+
CONFIG_MODEM_CMUX_MTU=127
79+
CONFIG_MODEM_CMUX_WORK_BUFFER_SIZE_EXTRA=532
80+
CONFIG_MODEM_CELLULAR_UART_BUFFER_SIZES=532
81+
# Disable the in-tree modem AT shell.
82+
CONFIG_MODEM_AT_SHELL=n
83+
CONFIG_MODEM_AT_USER_PIPE_IDX=0
84+
CONFIG_MODEM_CELLULAR_USER_PIPE_BUFFER_SIZES=1024
85+
CONFIG_MODEM_CMUX_LOG_LEVEL_INF=y
4986

5087
# Board peripherals
5188
CONFIG_GPIO=y

applications/93m1_at/src/main.c

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
#include <zephyr/smf.h>
1212

1313
#include "app_common.h"
14-
#include "modules/modem_at/modem_at.h"
1514
#include "modules/network/network.h"
16-
#include "modules/cloud/cloud.h"
1715
#if defined(CONFIG_APP_LOCATION)
1816
#include "modules/location/location.h"
1917
#endif
@@ -58,29 +56,57 @@ struct app_object {
5856
uint8_t msg_buf[MAX_MSG_SIZE];
5957
};
6058

61-
static struct app_object app;
62-
static const struct smf_state states[];
59+
static void sync_timer_fn(struct k_work *work);
60+
static K_WORK_DELAYABLE_DEFINE(sync_timer, sync_timer_fn);
61+
62+
static void request_module_updates(void);
63+
static enum smf_state_result disconnected_run(void *obj);
64+
static void connected_entry(void *obj);
65+
static enum smf_state_result connected_run(void *obj);
66+
static void connected_exit(void *obj);
67+
static void wdt_callback(int channel_id, void *user_data);
68+
69+
static const struct smf_state states[] = {
70+
[STATE_DISCONNECTED] = SMF_CREATE_STATE(NULL, disconnected_run, NULL, NULL, NULL),
71+
[STATE_CONNECTED] = SMF_CREATE_STATE(connected_entry, connected_run, connected_exit,
72+
NULL, NULL),
73+
};
6374

64-
/* Periodic sync trigger: publishes MAIN_SYNC; the state machine drives it. */
6575
static void sync_timer_fn(struct k_work *work)
6676
{
6777
ARG_UNUSED(work);
78+
6879
struct main_msg msg = { .type = MAIN_SYNC };
80+
int err;
6981

70-
(void)zbus_chan_pub(&main_chan, &msg, PUB_TIMEOUT);
82+
err = zbus_chan_pub(&main_chan, &msg, PUB_TIMEOUT);
83+
if (err) {
84+
LOG_ERR("zbus_chan_pub main_chan, error: %d", err);
85+
}
7186
}
7287

73-
static K_WORK_DELAYABLE_DEFINE(sync_timer, sync_timer_fn);
74-
75-
static void run_sync(void)
88+
static void request_module_updates(void)
7689
{
77-
LOG_INF("Sync");
90+
int err;
91+
92+
LOG_DBG("Requesting module updates");
7893
#if defined(CONFIG_APP_LOCATION)
79-
location_update();
94+
struct location_msg loc_msg = { .type = LOCATION_FIX_REQUEST };
95+
96+
err = zbus_chan_pub(&location_chan, &loc_msg, PUB_TIMEOUT);
97+
if (err) {
98+
LOG_ERR("zbus_chan_pub location_chan, error: %d", err);
99+
}
80100
#endif
81101
#if defined(CONFIG_APP_BATTERY)
82-
(void)battery_report();
102+
struct battery_msg bat_msg = { .type = BATTERY_SAMPLE };
103+
104+
err = zbus_chan_pub(&battery_chan, &bat_msg, PUB_TIMEOUT);
105+
if (err) {
106+
LOG_ERR("zbus_chan_pub battery_chan, error: %d", err);
107+
}
83108
#endif
109+
ARG_UNUSED(err);
84110
}
85111

86112
static enum smf_state_result disconnected_run(void *obj)
@@ -101,10 +127,14 @@ static enum smf_state_result disconnected_run(void *obj)
101127
static void connected_entry(void *obj)
102128
{
103129
ARG_UNUSED(obj);
130+
int err;
131+
104132
LOG_INF("Connected");
105133

106-
/* First sync shortly after connecting. */
107-
(void)k_work_reschedule(&sync_timer, K_SECONDS(CONFIG_APP_SYNC_BOOT_DELAY_SECONDS));
134+
err = k_work_reschedule(&sync_timer, K_SECONDS(CONFIG_APP_SYNC_BOOT_DELAY_SECONDS));
135+
if (err < 0) {
136+
LOG_ERR("k_work_reschedule sync_timer, error: %d", err);
137+
}
108138
}
109139

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

123153
if (msg->type == MAIN_SYNC) {
124-
run_sync();
125-
(void)k_work_reschedule(&sync_timer, K_SECONDS(CONFIG_APP_SYNC_INTERVAL));
154+
int err;
155+
156+
request_module_updates();
157+
err = k_work_reschedule(&sync_timer, K_SECONDS(CONFIG_APP_SYNC_INTERVAL));
158+
if (err < 0) {
159+
LOG_ERR("k_work_reschedule sync_timer, error: %d", err);
160+
}
126161
}
127162
}
128163

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

138-
static const struct smf_state states[] = {
139-
[STATE_DISCONNECTED] = SMF_CREATE_STATE(NULL, disconnected_run, NULL, NULL, NULL),
140-
[STATE_CONNECTED] = SMF_CREATE_STATE(connected_entry, connected_run, connected_exit,
141-
NULL, NULL),
142-
};
143-
144173
static void wdt_callback(int channel_id, void *user_data)
145174
{
146175
LOG_ERR("Main watchdog expired, channel: %d, thread: %s",
@@ -158,6 +187,7 @@ int main(void)
158187
const uint32_t execution_time_ms =
159188
(CONFIG_APP_MAIN_MSG_PROCESSING_TIMEOUT_SECONDS * MSEC_PER_SEC);
160189
const k_timeout_t zbus_wait = K_MSEC(wdt_timeout_ms - execution_time_ms);
190+
static struct app_object app;
161191

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

169-
if (modem_at_setup() < 0) {
170-
SEND_FATAL_ERROR();
171-
return -EFAULT;
172-
}
173-
(void)cloud_provision();
174-
175199
smf_set_initial(SMF_CTX(&app), &states[STATE_DISCONNECTED]);
176200

177201
while (true) {

applications/93m1_at/src/modules/battery/Kconfig.battery

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@
77
menuconfig APP_BATTERY
88
bool "Battery module"
99
default y
10-
depends on APP_MODEM_AT && NRF_FUEL_GAUGE && NPM13XX_CHARGER
10+
depends on APP_CLOUD && NRF_FUEL_GAUGE && NPM13XX_CHARGER
1111
help
12-
Samples the nPM1300 fuel gauge and reports state of charge to nRF Cloud as
13-
an AT%NRFCLOUDMESSAGE (appId "BATTERY"). Driven by the sync state machine in
14-
main.
12+
Samples the nPM1300 fuel gauge and publishes state of charge to the cloud
13+
module, which forwards it to nRF Cloud.
1514

1615
if APP_BATTERY
1716

18-
config APP_BATTERY_AT_TIMEOUT_SECONDS
19-
int "AT%NRFCLOUDMESSAGE timeout (seconds)"
20-
default 60
17+
config APP_BATTERY_THREAD_STACK_SIZE
18+
int "Battery thread stack size (bytes)"
19+
default 2048
2120

2221
module = APP_BATTERY
2322
module-str = battery

0 commit comments

Comments
 (0)