Skip to content

Commit 28e93be

Browse files
Add support to monitor die temperature
1 parent 5d24c1c commit 28e93be

5 files changed

Lines changed: 117 additions & 1 deletion

File tree

soc/nordic/nrf54l/health_monitoring_nrfx/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
cmake_minimum_required(VERSION 3.20.0)
55

66
zephyr_library_sources(health_monitoring.c
7-
battery_monitor.c)
7+
battery_monitor.c
8+
temperature_monitor.c)
89

910
zephyr_include_directories(.)
1011

soc/nordic/nrf54l/health_monitoring_nrfx/Kconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ config VBAT_MONITOR_ENABLE
99
select NRFX_SAADC
1010
# select ADC # TODO: Only enable to verify error in CMakelists.txt
1111

12+
config DIE_TEMP_MONITOR_ENABLE
13+
bool "Enable die temperature monitoring"
14+
select SOC_HEALTH_MONITORING
15+
select SENSOR
16+
select CONFIG_TEMP_NRF5
1217

1318
config VINTERNAL_MONITOR_ENABLE
1419
bool "Enable VInternal monitoring"
@@ -51,6 +56,19 @@ config VBAT_MONITOR_LOWER_THRESHOLD_MV
5156

5257
endif # VBAT_MONITOR_ENABLE
5358

59+
if DIE_TEMP_MONITOR_ENABLE
60+
61+
config DIE_TEMP_MONITOR_INTERVAL_MS
62+
int "Die temperature measurement interval (milliseconds)"
63+
default 3000
64+
range 100 3600000
65+
help
66+
Interval between die temperature measurements in milliseconds.
67+
Minimum: 100 ms
68+
Maximum: 3600000 ms (1 hour)
69+
70+
endif # DIE_TEMP_MONITOR_ENABLE
71+
5472
if SOC_HEALTH_MONITORING
5573

5674
#TODO: Align this with style used elsewhere

soc/nordic/nrf54l/health_monitoring_nrfx/health_monitoring.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
#include <stdlib.h>
12
#include <zephyr/kernel.h>
23
#include <zephyr/sys/atomic.h>
34
#include <zephyr/logging/log.h>
45
#include "battery_monitor.h"
6+
#include "temperature_monitor.h"
57

68
LOG_MODULE_REGISTER(health_monitoring, CONFIG_HEALTH_MONITOR_LOG_LEVEL);
79

810
typedef struct {
911
atomic_t *g_vbatt_value;
12+
atomic_t *g_die_temp_value;
1013
} health_metrics_t;
1114

1215
static health_metrics_t health_metrics = {};
@@ -22,11 +25,20 @@ int health_monitoring_setup(void)
2225
}
2326
health_metrics.g_vbatt_value = get_battery_voltage_pointer();
2427

28+
err = die_temperature_monitoring_setup();
29+
if (err != 0) {
30+
LOG_ERR("Die Temperature Monitoring Setup Failed");
31+
return err;
32+
}
33+
health_metrics.g_die_temp_value = get_die_temperature_pointer();
34+
2535
//Here for now to demonstrate functionality
2636
for (;;) {
2737
k_sleep(K_SECONDS(2));
2838
// uint32_t voltage = atomic_get(g_vbatt_value);
2939
printk("Global ADC: %ld mV\n", *health_metrics.g_vbatt_value);
40+
printk("Global die temp: %ld.%02u\n", *health_metrics.g_die_temp_value / 100,
41+
abs(*health_metrics.g_die_temp_value) % 100);
3042
}
3143

3244
return 0;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// nrf/tests/benchmarks/peripheral_load/src/temp_thread.c
2+
#include <zephyr/device.h>
3+
#include <zephyr/devicetree.h>
4+
#include <zephyr/logging/log.h>
5+
#include <zephyr/drivers/sensor.h>
6+
#include "temperature_monitor.h"
7+
8+
LOG_MODULE_REGISTER(die_temp_monitoring, CONFIG_HEALTH_MONITOR_LOG_LEVEL);
9+
10+
static const struct device *temp_dev = DEVICE_DT_GET(DT_NODELABEL(temp));
11+
static enum sensor_channel chan_to_use = SENSOR_CHAN_DIE_TEMP;
12+
13+
/** @brief global variable to store battery voltage */
14+
static atomic_t die_temperature_raw;
15+
16+
static void die_temperature_work_handler(struct k_work *work);
17+
18+
K_WORK_DELAYABLE_DEFINE(get_die_temperature, die_temperature_work_handler);
19+
20+
/**
21+
* @brief Function for getting pointer to die temperature.
22+
*
23+
* @return Pointer to atomic variable holding die temperature
24+
*/
25+
atomic_t *get_die_temperature_pointer(void)
26+
{
27+
return &die_temperature_raw;
28+
}
29+
30+
int die_temperature_monitoring_setup(void)
31+
{
32+
int err = 0;
33+
34+
if (!device_is_ready(temp_dev)) {
35+
LOG_ERR("Device %s is not ready.", temp_dev->name);
36+
return err = -ENODEV;
37+
}
38+
39+
k_work_schedule(&get_die_temperature, K_MSEC(CONFIG_DIE_TEMP_MONITOR_INTERVAL_MS));
40+
41+
return err;
42+
}
43+
44+
static void die_temperature_work_handler(struct k_work *work)
45+
{
46+
int err;
47+
struct sensor_value val;
48+
int32_t temp_val;
49+
50+
(void)work;
51+
52+
err = sensor_sample_fetch(temp_dev);
53+
if (err < 0) {
54+
LOG_ERR("sensor_sample_fetch_chan() returned: %d", err);
55+
return;
56+
}
57+
58+
err = sensor_channel_get(temp_dev, chan_to_use, &val);
59+
if (err < 0) {
60+
LOG_ERR("sensor_channel_get() returned: %d", err);
61+
return;
62+
}
63+
64+
temp_val = (val.val1 * 100) + (val.val2 / 10000);
65+
atomic_set(&die_temperature_raw,temp_val);
66+
LOG_INF("DIE_TEMP is %d.%02u", temp_val / 100, abs(temp_val) % 100);
67+
k_work_schedule(&get_die_temperature, K_MSEC(CONFIG_DIE_TEMP_MONITOR_INTERVAL_MS));
68+
69+
return;
70+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef _TEMPERATURE_MONITOR_H_
8+
#define _TEMPERATURE_MONITOR_H_
9+
10+
#include <zephyr/sys/atomic.h>
11+
12+
atomic_t* get_die_temperature_pointer(void);
13+
int die_temperature_monitoring_setup(void);
14+
15+
#endif //_TEMPERATURE_MONITOR_H_

0 commit comments

Comments
 (0)