Skip to content

Commit 8a33143

Browse files
nordic-pikrnordicjm
authored andcommitted
tests: benchmarks: power_consumption: temperature sensor
Add test that verify power management for temp sensor Signed-off-by: Piotr Krzyzanowski <[email protected]>
1 parent 61271c3 commit 8a33143

File tree

8 files changed

+156
-0
lines changed

8 files changed

+156
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
11+
if(NOT SYSBUILD)
12+
message(FATAL_ERROR
13+
" This is a multi-image application that should be built using sysbuild.\n"
14+
" Add --sysbuild argument to west build command to prepare all the images.")
15+
endif()
16+
17+
project(temperature_sensor)
18+
19+
target_sources(app PRIVATE src/main.c)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
source "${ZEPHYR_BASE}/share/sysbuild/Kconfig"
8+
9+
config REMOTE_BOARD
10+
string "The board used for remote target"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
temp_sensor: &temp_nrfs {
2+
status = "okay";
3+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CONFIG_ASSERT=y
2+
3+
CONFIG_CONSOLE=n
4+
CONFIG_UART_CONSOLE=n
5+
CONFIG_SERIAL=n
6+
CONFIG_BOOT_BANNER=n
7+
8+
CONFIG_NRFS=y
9+
CONFIG_SENSOR=y
10+
CONFIG_TEMP_NRFS_TRIGGER_OWN_THREAD=y
11+
12+
CONFIG_PM=y
13+
CONFIG_PM_S2RAM=y
14+
CONFIG_POWEROFF=y
15+
CONFIG_PM_S2RAM_CUSTOM_MARKING=y
16+
CONFIG_NRFS_MRAM_SERVICE_ENABLED=n
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2024, Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
#include <zephyr/device.h>
7+
#include <zephyr/drivers/sensor.h>
8+
9+
static const struct device *temp_dev = DEVICE_DT_GET(DT_NODELABEL(temp_sensor));
10+
11+
void set_trigger(void);
12+
13+
static void trigger_handler(const struct device *temp_dev, const struct sensor_trigger *trig)
14+
{
15+
ARG_UNUSED(temp_dev);
16+
ARG_UNUSED(trig);
17+
18+
k_busy_wait(1000000);
19+
set_trigger();
20+
}
21+
22+
void set_trigger(void)
23+
{
24+
int rc;
25+
struct sensor_value val = {0};
26+
struct sensor_trigger trig = {.type = SENSOR_TRIG_THRESHOLD, .chan = SENSOR_CHAN_DIE_TEMP};
27+
28+
/* Set sampling frequency to 1 Hz, to expect a trigger after 1 s. */
29+
val.val1 = 1;
30+
rc = sensor_attr_set(temp_dev, SENSOR_CHAN_DIE_TEMP, SENSOR_ATTR_SAMPLING_FREQUENCY, &val);
31+
__ASSERT_NO_MSG(rc == 0);
32+
33+
rc = sensor_sample_fetch_chan(temp_dev, SENSOR_CHAN_DIE_TEMP);
34+
__ASSERT_NO_MSG(rc == 0);
35+
36+
rc = sensor_channel_get(temp_dev, SENSOR_CHAN_DIE_TEMP, &val);
37+
__ASSERT_NO_MSG(rc == 0);
38+
39+
printk("Temperature: %d.%d\n", val.val1, val.val2 / 10000);
40+
41+
/* Verify sensor reading - should be within room temperature limits.*/
42+
__ASSERT_NO_MSG(val.val1 > 10);
43+
__ASSERT_NO_MSG(val.val1 < 35);
44+
45+
/*
46+
* Set the upper threshold 5* below the current temperature to ensure that the callback will
47+
* be triggered
48+
*/
49+
val.val1 -= 5;
50+
rc = sensor_attr_set(temp_dev, SENSOR_CHAN_DIE_TEMP, SENSOR_ATTR_UPPER_THRESH, &val);
51+
__ASSERT_NO_MSG(rc == 0);
52+
printk("Upper threshold: %d.%d\n", val.val1, val.val2 / 10000);
53+
54+
rc = sensor_trigger_set(temp_dev, &trig, trigger_handler);
55+
__ASSERT_NO_MSG(rc == 0);
56+
}
57+
58+
int main(void)
59+
{
60+
int rc;
61+
62+
rc = device_is_ready(temp_dev);
63+
__ASSERT_NO_MSG(rc);
64+
65+
set_trigger();
66+
67+
return 0;
68+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
if("${SB_CONFIG_REMOTE_BOARD}" STREQUAL "")
8+
message(FATAL_ERROR "REMOTE_BOARD must be set to a valid board name")
9+
endif()
10+
11+
ExternalZephyrProject_Add(
12+
APPLICATION remote_sleep_forever
13+
SOURCE_DIR ${APP_DIR}/../common/remote_sleep_forever
14+
BOARD ${SB_CONFIG_REMOTE_BOARD}
15+
)
16+
17+
add_dependencies(temperature_sensor remote_sleep_forever)
18+
sysbuild_add_dependencies(FLASH temperature_sensor remote_sleep_forever)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SB_CONFIG_REMOTE_BOARD="nrf54h20dk/nrf54h20/cpurad"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
common:
2+
sysbuild: true
3+
tags:
4+
- drivers
5+
- sensors
6+
- ci_tests_benchmarks_current_consumption
7+
- ppk_power_measure
8+
9+
tests:
10+
benchmarks.power_consumption.temperature:
11+
platform_allow:
12+
- nrf54h20dk/nrf54h20/cpuapp
13+
integration_platforms:
14+
- nrf54h20dk/nrf54h20/cpuapp
15+
extra_args:
16+
SB_CONF_FILE=sysbuild/nrf54h20dk_nrf54h20_cpurad.conf
17+
harness: pytest
18+
harness_config:
19+
fixture: ppk_power_measure
20+
pytest_root:
21+
- "${CUSTOM_ROOT_TEST_DIR}/test_measure_power_consumption.py::test_thread_suspend_resume_gpio_54H"

0 commit comments

Comments
 (0)