Skip to content

Commit aac3ef5

Browse files
nordic-bamiPerMac
authored andcommitted
tests: benchmarks: Add GRTC idle test
Assess GRTC timer count value after exiting s2ram. Signed-off-by: Bartosz Miller <[email protected]>
1 parent 735d03f commit aac3ef5

File tree

9 files changed

+218
-0
lines changed

9 files changed

+218
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# Copyright (c) 2025 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(idle_grtc)
18+
19+
if((DEFINED CONFIG_SOC_NRF54H20_CPUPPR) OR (DEFINED CONFIG_SOC_NRF54H20_ENGB_CPUPPR))
20+
message(STATUS "Power Mode handler for RISC V is included.")
21+
target_sources(app PRIVATE ${ZEPHYR_NRF_MODULE_DIR}/tests/benchmarks/multicore/common/power_off.c)
22+
endif()
23+
24+
target_sources(app PRIVATE src/main.c)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
config APP_PROVIDE_PM_HOOKS
8+
bool "Application provides PM hooks"
9+
default y
10+
select HAS_PM
11+
select HAS_POWEROFF
12+
13+
source "Kconfig.zephyr"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/ {
8+
aliases {
9+
/delete-property/ led1;
10+
};
11+
};
12+
13+
/delete-node/ &led1;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/ {
8+
cpus {
9+
power-states {
10+
wait: wait {
11+
compatible = "zephyr,power-state";
12+
power-state-name = "standby";
13+
substate-id = <0>;
14+
min-residency-us = <20000>;
15+
};
16+
17+
hibernate: hibernate {
18+
compatible = "zephyr,power-state";
19+
power-state-name = "suspend-to-ram";
20+
substate-id = <0>;
21+
min-residency-us = <400000>;
22+
};
23+
};
24+
};
25+
};
26+
27+
&cpu {
28+
cpu-power-states = <&wait &hibernate>;
29+
};
30+
31+
&grtc {
32+
owned-channels = <5 6>;
33+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CONFIG_PM=y
2+
CONFIG_PM_DEVICE=y
3+
CONFIG_PM_DEVICE_RUNTIME=y
4+
CONFIG_POWEROFF=y
5+
6+
CONFIG_GPIO=y
7+
8+
CONFIG_ASSERT=y
9+
10+
CONFIG_LOG=n
11+
CONFIG_CONSOLE=n
12+
CONFIG_UART_CONSOLE=n
13+
CONFIG_SERIAL=n
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/drivers/gpio.h>
9+
#include <zephyr/pm/device.h>
10+
#include <zephyr/pm/device_runtime.h>
11+
#include <zephyr/drivers/timer/nrf_grtc_timer.h>
12+
#include <hal/nrf_grtc.h>
13+
14+
#define TIMER_COUNT_TIME_MS 995
15+
#define SLEEP_TIME_MS 1500
16+
/*
17+
* The timer value readout is not time synchronised,
18+
* this tolerance accounts for the readout delay
19+
*/
20+
#define READOUT_TIMER_TOLERANCE_IN_TICKS 1500
21+
#define EXPECTED_READOUT_VALUE \
22+
(sys_clock_hw_cycles_per_sec() / 1000) * (SLEEP_TIME_MS - TIMER_COUNT_TIME_MS)
23+
24+
static volatile uint64_t isr_count_value;
25+
static volatile bool count_isr_triggered;
26+
27+
static void timer_compare_interrupt_handler(int32_t id, uint64_t expire_time, void *user_data)
28+
{
29+
isr_count_value = z_nrf_grtc_timer_read();
30+
count_isr_triggered = true;
31+
}
32+
33+
int main(void)
34+
{
35+
int err;
36+
uint64_t test_ticks = 0;
37+
uint64_t compare_value = 0;
38+
uint64_t count_difference = 0;
39+
char user_data[] = "test_timer_count_in_compare_mode\n";
40+
int32_t channel = z_nrf_grtc_timer_chan_alloc();
41+
42+
__ASSERT(channel > 0, "GRTC channel not allocated\n");
43+
while (1) {
44+
count_isr_triggered = false;
45+
test_ticks = z_nrf_grtc_timer_get_ticks(K_MSEC(TIMER_COUNT_TIME_MS));
46+
err = z_nrf_grtc_timer_set(channel, test_ticks, timer_compare_interrupt_handler,
47+
(void *)user_data);
48+
49+
__ASSERT(err == 0, "z_nrf_grtc_timer_set raised an error: %d", err);
50+
51+
z_nrf_grtc_timer_compare_read(channel, &compare_value);
52+
__ASSERT(K_TIMEOUT_EQ(K_TICKS(compare_value), K_TICKS(test_ticks)) == true,
53+
"Compare register set failed");
54+
__ASSERT(err == 0, "Unexpected error raised when setting timer, err: %d", err);
55+
56+
/* Got to sleep */
57+
k_sleep(K_MSEC(SLEEP_TIME_MS));
58+
59+
/*
60+
* Read counter value after exiting the sleep
61+
* and compare it to the value captured in the ISR
62+
*/
63+
count_difference = z_nrf_grtc_timer_read() - isr_count_value;
64+
__ASSERT((EXPECTED_READOUT_VALUE - READOUT_TIMER_TOLERANCE_IN_TICKS <=
65+
count_difference) &&
66+
(count_difference <=
67+
EXPECTED_READOUT_VALUE + READOUT_TIMER_TOLERANCE_IN_TICKS),
68+
"GRTC timer readout after sleep returned incorrect value. Returned, "
69+
"expected, abs tolerance (%lld/%d/%d)",
70+
count_difference, EXPECTED_READOUT_VALUE,
71+
READOUT_TIMER_TOLERANCE_IN_TICKS);
72+
}
73+
74+
z_nrf_grtc_timer_chan_free(channel);
75+
return 0;
76+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
# Add remote project
8+
ExternalZephyrProject_Add(
9+
APPLICATION remote
10+
SOURCE_DIR ${ZEPHYR_NRF_MODULE_DIR}/tests/benchmarks/power_consumption/common/remote_sleep_forever
11+
BOARD ${SB_CONFIG_BOARD}/${SB_CONFIG_SOC}/cpurad
12+
BOARD_REVISION ${BOARD_REVISION}
13+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
common:
2+
sysbuild: true
3+
4+
tests:
5+
benchmarks.multicore.idle_grtc:
6+
tags:
7+
- ci_build
8+
- ci_tests_benchmarks_multicore
9+
- timer
10+
- ppk_power_measure
11+
platform_allow:
12+
- nrf54h20dk/nrf54h20/cpuppr
13+
integration_platforms:
14+
- nrf54h20dk/nrf54h20/cpuppr
15+
extra_args:
16+
- vpr_launcher_EXTRA_CONF_FILE=${ZEPHYR_NRF_MODULE_DIR}/tests/benchmarks/multicore/idle_grtc/vpr_launcher.conf
17+
- vpr_launcher_EXTRA_DTC_OVERLAY_FILE=${ZEPHYR_NRF_MODULE_DIR}/tests/benchmarks/multicore/idle_grtc/boards/nrf54h20dk_nrf54h20_cpuapp.overlay
18+
harness: pytest
19+
harness_config:
20+
fixture: ppk_power_measure
21+
pytest_root:
22+
- "${CUSTOM_ROOT_TEST_DIR}/test_measure_power_consumption.py::test_measure_power_consumption_idle_grtc"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CONFIG_PM=y
2+
CONFIG_PM_S2RAM=y
3+
CONFIG_PM_S2RAM_CUSTOM_MARKING=y
4+
CONFIG_PM_DEVICE=y
5+
CONFIG_PM_DEVICE_RUNTIME=y
6+
CONFIG_POWEROFF=y
7+
8+
CONFIG_LOG=n
9+
CONFIG_CONSOLE=n
10+
CONFIG_UART_CONSOLE=n
11+
CONFIG_SERIAL=n

0 commit comments

Comments
 (0)