Skip to content

Commit de53c92

Browse files
committed
modules: Rename battery module to power module
The battery module has been renamed to the power module to better reflect its purpose. The module is responsible for handling power management, including battery monitoring and power consumption optimization. Signed-off-by: Simen S. Røstad <simen.rostad@nordicsemi.no>
1 parent 69a0447 commit de53c92

24 files changed

+132
-134
lines changed

app/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ add_subdirectory(src/modules/fota)
2323
add_subdirectory(src/modules/button)
2424

2525
# Optional modules
26-
add_subdirectory_ifdef(CONFIG_APP_BATTERY src/modules/battery)
26+
add_subdirectory_ifdef(CONFIG_APP_POWER src/modules/power)
2727
add_subdirectory_ifdef(CONFIG_APP_ENVIRONMENTAL src/modules/environmental)
2828
add_subdirectory_ifdef(CONFIG_APP_LED src/modules/led)
2929
add_subdirectory_ifdef(CONFIG_APP_SHELL src/modules/shell)

app/Kconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ config APP_PAYLOAD_CHANNEL_BUFFER_MAX_SIZE
1414
Contains encoded CBOR data sampled and encoded in the various modules.
1515

1616
rsource "src/Kconfig.main"
17-
rsource "src/modules/battery/Kconfig.battery"
17+
rsource "src/modules/power/Kconfig.power"
1818
rsource "src/modules/network/Kconfig.network"
1919
rsource "src/modules/cloud/Kconfig.cloud"
2020
rsource "src/modules/location/Kconfig.location"

app/boards/thingy91x_nrf9151_ns.conf

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ CONFIG_APP_ENVIRONMENTAL=y
1010
# Enable BME680
1111
CONFIG_BME680=y
1212

13-
# Battery module
14-
CONFIG_APP_BATTERY=y
13+
# Power module
14+
CONFIG_APP_POWER=y
1515

1616
# LED module
1717
CONFIG_APP_LED=y
@@ -48,5 +48,5 @@ CONFIG_LOCATION_METHOD_WIFI_SCANNING_RESULTS_MAX_CNT=10
4848
CONFIG_NRF_WIFI_SCAN_MAX_BSS_CNT=10
4949

5050
# Debug logging
51-
CONFIG_APP_BATTERY_LOG_LEVEL_DBG=y
51+
CONFIG_APP_POWER_LOG_LEVEL_DBG=y
5252
CONFIG_APP_ENVIRONMENTAL_LOG_LEVEL_DBG=y

app/src/main.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#endif /* CONFIG_APP_ENVIRONMENTAL */
2828

2929
#if defined(CONFIG_APP_BATTERY)
30-
#include "battery.h"
30+
#include "power.h"
3131
#endif /* CONFIG_APP_BATTERY */
3232

3333
/* Register log module */
@@ -239,11 +239,11 @@ static void sensor_and_poll_triggers_send(void)
239239
#endif /* CONFIG_APP_REQUEST_NETWORK_QUALITY */
240240

241241
#if defined(CONFIG_APP_BATTERY)
242-
struct battery_msg battery_msg = {
243-
.type = BATTERY_PERCENTAGE_SAMPLE_REQUEST,
242+
struct power_msg power_msg = {
243+
.type = POWER_BATTERY_PERCENTAGE_SAMPLE_REQUEST,
244244
};
245245

246-
err = zbus_chan_pub(&BATTERY_CHAN, &battery_msg, K_SECONDS(1));
246+
err = zbus_chan_pub(&POWER_CHAN, &power_msg, K_SECONDS(1));
247247
if (err) {
248248
LOG_ERR("zbus_chan_pub, error: %d", err);
249249
SEND_FATAL_ERROR();
@@ -252,7 +252,7 @@ static void sensor_and_poll_triggers_send(void)
252252
#endif /* CONFIG_APP_BATTERY */
253253

254254
#if defined(CONFIG_APP_ENVIRONMENTAL)
255-
struct battery_msg environmental_msg = {
255+
struct environmental_msg environmental_msg = {
256256
.type = ENVIRONMENTAL_SENSOR_SAMPLE_REQUEST,
257257
};
258258

app/src/modules/cloud/cloud_module.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "network.h"
2424

2525
#if defined(CONFIG_APP_BATTERY)
26-
#include "battery.h"
26+
#include "power.h"
2727
#endif /* CONFIG_APP_BATTERY */
2828

2929
#if defined(CONFIG_APP_ENVIRONMENTAL)
@@ -37,7 +37,7 @@ LOG_MODULE_REGISTER(cloud, CONFIG_APP_CLOUD_LOG_LEVEL);
3737
#define CUSTOM_JSON_APPID_VAL_BATTERY "BATTERY"
3838

3939
#if defined(CONFIG_APP_BATTERY)
40-
#define BAT_MSG_SIZE sizeof(struct battery_msg)
40+
#define BAT_MSG_SIZE sizeof(struct power_msg)
4141
#else
4242
#define BAT_MSG_SIZE 0
4343
#endif /* CONFIG_APP_BATTERY */
@@ -69,7 +69,7 @@ ZBUS_CHAN_ADD_OBS(ENVIRONMENTAL_CHAN, cloud, 0);
6969
#endif /* CONFIG_APP_ENVIRONMENTAL */
7070

7171
#if defined(CONFIG_APP_BATTERY)
72-
ZBUS_CHAN_ADD_OBS(BATTERY_CHAN, cloud, 0);
72+
ZBUS_CHAN_ADD_OBS(POWER_CHAN, cloud, 0);
7373
#endif /* CONFIG_APP_BATTERY */
7474

7575
/* Define channels provided by this module */
@@ -568,10 +568,10 @@ static void state_connected_ready_run(void *o)
568568
}
569569

570570
#if defined(CONFIG_APP_BATTERY)
571-
if (state_object->chan == &BATTERY_CHAN) {
572-
struct battery_msg msg = MSG_TO_BATTERY_MSG(state_object->msg_buf);
571+
if (state_object->chan == &POWER_CHAN) {
572+
struct power_msg msg = MSG_TO_POWER_MSG(state_object->msg_buf);
573573

574-
if (msg.type == BATTERY_PERCENTAGE_SAMPLE_RESPONSE) {
574+
if (msg.type == POWER_BATTERY_PERCENTAGE_SAMPLE_RESPONSE) {
575575
err = nrf_cloud_coap_sensor_send(CUSTOM_JSON_APPID_VAL_BATTERY,
576576
msg.percentage,
577577
NRF_CLOUD_NO_TIMESTAMP,

app/src/modules/battery/CMakeLists.txt app/src/modules/power/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
#
66

7-
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/battery.c)
7+
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/power.c)
88
target_include_directories(app PRIVATE .)

app/src/modules/battery/Kconfig.battery app/src/modules/power/Kconfig.power

+15-15
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,41 @@
44
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
#
66

7-
menu "Battery"
7+
menu "Power"
88

9-
config APP_BATTERY
10-
bool "Battery module"
9+
config APP_POWER
10+
bool "Power module"
1111

12-
if APP_BATTERY
12+
if APP_POWER
1313

14-
config APP_BATTERY_THREAD_STACK_SIZE
14+
config APP_POWER_THREAD_STACK_SIZE
1515
int "Thread stack size"
1616
default 1536
1717

18-
config APP_BATTERY_WATCHDOG_TIMEOUT_SECONDS
18+
config APP_POWER_WATCHDOG_TIMEOUT_SECONDS
1919
int "Watchdog timeout"
2020
default 120
2121
help
22-
Timeout in seconds for the battery module watchdog.
22+
Timeout in seconds for the power module watchdog.
2323
The timeout given in this option covers both:
2424
* Waiting for an incoming message in zbus_sub_wait_msg().
2525
* Time spent processing the message, defined by
26-
CONFIG_APP_BATTERY_MSG_PROCESSING_TIMEOUT_SECONDS.
27-
Ensure that this value exceeds CONFIG_APP_BATTERY_MSG_PROCESSING_TIMEOUT_SECONDS.
26+
CONFIG_APP_POWER_MSG_PROCESSING_TIMEOUT_SECONDS.
27+
Ensure that this value exceeds CONFIG_APP_POWER_MSG_PROCESSING_TIMEOUT_SECONDS.
2828
A small difference between the two can mean more frequent watchdog feeds, which increases
2929
power consumption.
3030

31-
config APP_BATTERY_MSG_PROCESSING_TIMEOUT_SECONDS
31+
config APP_POWER_MSG_PROCESSING_TIMEOUT_SECONDS
3232
int "Maximum message processing time"
3333
default 3
3434
help
3535
Maximum time allowed for processing a single message in the module's state machine.
36-
The value must be smaller than CONFIG_APP_BATTERY_WATCHDOG_TIMEOUT_SECONDS.
36+
The value must be smaller than CONFIG_APP_POWER_WATCHDOG_TIMEOUT_SECONDS.
3737

38-
module = APP_BATTERY
39-
module-str = Battery
38+
module = APP_POWER
39+
module-str = Power
4040
source "subsys/logging/Kconfig.template.log_config"
4141

42-
endif # APP_BATTERY
42+
endif # APP_POWER
4343

44-
endmenu # Battery
44+
endmenu # Power

app/src/modules/battery/battery.c app/src/modules/power/power.c

+34-34
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,30 @@
1818
#include "lp803448_model.h"
1919
#include "message_channel.h"
2020
#include "modules_common.h"
21-
#include "battery.h"
21+
#include "power.h"
2222

2323
/* Register log module */
24-
LOG_MODULE_REGISTER(battery, CONFIG_APP_BATTERY_LOG_LEVEL);
24+
LOG_MODULE_REGISTER(power, CONFIG_APP_POWER_LOG_LEVEL);
2525

2626
/* Register subscriber */
27-
ZBUS_MSG_SUBSCRIBER_DEFINE(battery);
27+
ZBUS_MSG_SUBSCRIBER_DEFINE(power);
2828

2929
/* Define channels provided by this module */
30-
ZBUS_CHAN_DEFINE(BATTERY_CHAN,
31-
struct battery_msg,
30+
ZBUS_CHAN_DEFINE(POWER_CHAN,
31+
struct power_msg,
3232
NULL,
3333
NULL,
3434
ZBUS_OBSERVERS_EMPTY,
3535
ZBUS_MSG_INIT(0)
3636
);
3737

3838
/* Observe channels */
39-
ZBUS_CHAN_ADD_OBS(BATTERY_CHAN, battery, 0);
39+
ZBUS_CHAN_ADD_OBS(POWER_CHAN, power, 0);
4040

41-
#define MAX_MSG_SIZE sizeof(struct battery_msg)
41+
#define MAX_MSG_SIZE sizeof(struct power_msg)
4242

43-
BUILD_ASSERT(CONFIG_APP_BATTERY_WATCHDOG_TIMEOUT_SECONDS >
44-
CONFIG_APP_BATTERY_MSG_PROCESSING_TIMEOUT_SECONDS,
43+
BUILD_ASSERT(CONFIG_APP_POWER_WATCHDOG_TIMEOUT_SECONDS >
44+
CONFIG_APP_POWER_MSG_PROCESSING_TIMEOUT_SECONDS,
4545
"Watchdog timeout must be greater than maximum message processing time");
4646

4747
/* nPM1300 register bitmasks */
@@ -63,16 +63,16 @@ static void sample(int64_t *ref_time);
6363

6464
/* Defininig the module states.
6565
*
66-
* STATE_RUNNING: The battery module is initializing and waiting battery percentage to be requested.
66+
* STATE_RUNNING: The power module is initializing and waiting battery percentage to be requested.
6767
*/
68-
enum battery_module_state {
68+
enum power_module_state {
6969
STATE_RUNNING,
7070
};
7171

7272
/* User defined state object.
7373
* Used to transfer data between state changes.
7474
*/
75-
struct battery_state {
75+
struct power_state {
7676
/* This must be first */
7777
struct smf_ctx ctx;
7878

@@ -90,7 +90,7 @@ struct battery_state {
9090
static void state_running_entry(void *o);
9191
static void state_running_run(void *o);
9292

93-
static struct battery_state battery_state_object;
93+
static struct power_state power_state_object;
9494
static const struct smf_state states[] = {
9595
[STATE_RUNNING] =
9696
SMF_CREATE_STATE(state_running_entry, state_running_run, NULL, NULL, NULL),
@@ -106,7 +106,7 @@ static void state_running_entry(void *o)
106106
.model = &battery_model
107107
};
108108
int32_t chg_status;
109-
struct battery_state *state_object = o;
109+
struct power_state *state_object = o;
110110

111111
if (!device_is_ready(charger)) {
112112
LOG_ERR("Charger device not ready.");
@@ -132,20 +132,20 @@ static void state_running_entry(void *o)
132132

133133
err = sensor_channel_get(charger, SENSOR_CHAN_GAUGE_DESIRED_CHARGING_CURRENT, &value);
134134
if (err) {
135-
LOG_ERR("sensor_channel_get(DESIRED_CHARGING_CURRENT), error: %d", err);
135+
LOG_ERR("sensor_channel_get, DESIRED_CHARGING_CURRENT, error: %d", err);
136136
SEND_FATAL_ERROR();
137137
return;
138138
}
139139
}
140140

141141
static void state_running_run(void *o)
142142
{
143-
struct battery_state *state_object = o;
143+
struct power_state *state_object = o;
144144

145-
if (&BATTERY_CHAN == state_object->chan) {
146-
struct battery_msg msg = MSG_TO_BATTERY_MSG(state_object->msg_buf);
145+
if (&POWER_CHAN == state_object->chan) {
146+
struct power_msg msg = MSG_TO_POWER_MSG(state_object->msg_buf);
147147

148-
if (msg.type == BATTERY_PERCENTAGE_SAMPLE_REQUEST) {
148+
if (msg.type == POWER_BATTERY_PERCENTAGE_SAMPLE_REQUEST) {
149149
LOG_DBG("Battery percentage sample request received, getting battery data");
150150
sample(&state_object->fuel_gauge_ref_time);
151151
}
@@ -209,12 +209,12 @@ static void sample(int64_t *ref_time)
209209
LOG_DBG("State of charge: %f", (double)roundf(state_of_charge));
210210
LOG_DBG("The battery is %s", charging ? "charging" : "not charging");
211211

212-
struct battery_msg msg = {
213-
.type = BATTERY_PERCENTAGE_SAMPLE_RESPONSE,
212+
struct power_msg msg = {
213+
.type = POWER_BATTERY_PERCENTAGE_SAMPLE_RESPONSE,
214214
.percentage = (double)roundf(state_of_charge)
215215
};
216216

217-
err = zbus_chan_pub(&BATTERY_CHAN, &msg, K_NO_WAIT);
217+
err = zbus_chan_pub(&POWER_CHAN, &msg, K_NO_WAIT);
218218
if (err) {
219219
LOG_ERR("zbus_chan_pub, error: %d", err);
220220
SEND_FATAL_ERROR();
@@ -230,21 +230,21 @@ static void task_wdt_callback(int channel_id, void *user_data)
230230
SEND_FATAL_ERROR_WATCHDOG_TIMEOUT();
231231
}
232232

233-
static void battery_task(void)
233+
static void power_task(void)
234234
{
235235
int err;
236236
int task_wdt_id;
237237
const uint32_t wdt_timeout_ms =
238-
(CONFIG_APP_BATTERY_WATCHDOG_TIMEOUT_SECONDS * MSEC_PER_SEC);
238+
(CONFIG_APP_POWER_WATCHDOG_TIMEOUT_SECONDS * MSEC_PER_SEC);
239239
const uint32_t execution_time_ms =
240-
(CONFIG_APP_BATTERY_MSG_PROCESSING_TIMEOUT_SECONDS * MSEC_PER_SEC);
240+
(CONFIG_APP_POWER_MSG_PROCESSING_TIMEOUT_SECONDS * MSEC_PER_SEC);
241241
const k_timeout_t zbus_wait_ms = K_MSEC(wdt_timeout_ms - execution_time_ms);
242242

243-
LOG_DBG("Battery module task started");
243+
LOG_DBG("Power module task started");
244244

245245
task_wdt_id = task_wdt_add(wdt_timeout_ms, task_wdt_callback, (void *)k_current_get());
246246

247-
STATE_SET_INITIAL(battery_state_object, STATE_RUNNING);
247+
STATE_SET_INITIAL(power_state_object, STATE_RUNNING);
248248

249249
while (true) {
250250
err = task_wdt_feed(task_wdt_id);
@@ -254,9 +254,9 @@ static void battery_task(void)
254254
return;
255255
}
256256

257-
err = zbus_sub_wait_msg(&battery,
258-
&battery_state_object.chan,
259-
battery_state_object.msg_buf,
257+
err = zbus_sub_wait_msg(&power,
258+
&power_state_object.chan,
259+
power_state_object.msg_buf,
260260
zbus_wait_ms);
261261
if (err == -ENOMSG) {
262262
continue;
@@ -266,7 +266,7 @@ static void battery_task(void)
266266
return;
267267
}
268268

269-
err = STATE_RUN(battery_state_object);
269+
err = STATE_RUN(power_state_object);
270270
if (err) {
271271
LOG_ERR("handle_message, error: %d", err);
272272
SEND_FATAL_ERROR();
@@ -275,6 +275,6 @@ static void battery_task(void)
275275
}
276276
}
277277

278-
K_THREAD_DEFINE(battery_task_id,
279-
CONFIG_APP_BATTERY_THREAD_STACK_SIZE,
280-
battery_task, NULL, NULL, NULL, K_LOWEST_APPLICATION_THREAD_PRIO, 0, 0);
278+
K_THREAD_DEFINE(power_task_id,
279+
CONFIG_APP_POWER_THREAD_STACK_SIZE,
280+
power_task, NULL, NULL, NULL, K_LOWEST_APPLICATION_THREAD_PRIO, 0, 0);

0 commit comments

Comments
 (0)