Skip to content

Commit b1cd303

Browse files
nordic-piksnordicjm
authored andcommitted
tests: benchmarks: multicore: add idle_clock_control
Checking s2ram while changing clocks. Signed-off-by: Piotr Kosycarz <[email protected]>
1 parent 066ac6f commit b1cd303

File tree

10 files changed

+288
-0
lines changed

10 files changed

+288
-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(idle_clock_control)
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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_GPIO=n
9+
CONFIG_BOOT_BANNER=n
10+
CONFIG_SOC_NRF54H20_NO_MRAM_LATENCY=n
11+
12+
CONFIG_NRFS=y
13+
CONFIG_CLOCK_CONTROL=y
14+
CONFIG_ASSERT=y
15+
16+
# Enable for debugging purposes only
17+
CONFIG_PRINTK=n
18+
CONFIG_LOG=n
19+
CONFIG_CONSOLE=n
20+
CONFIG_UART_CONSOLE=n
21+
CONFIG_SERIAL=n
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
project(remote)
11+
12+
target_sources(app PRIVATE src/main.c)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CONFIG_PM=y
2+
CONFIG_POWEROFF=y
3+
CONFIG_CONSOLE=n
4+
CONFIG_UART_CONSOLE=n
5+
CONFIG_SERIAL=n
6+
CONFIG_GPIO=n
7+
CONFIG_BOOT_BANNER=n
8+
CONFIG_SOC_NRF54H20_NO_MRAM_LATENCY=n
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
9+
int main(void)
10+
{
11+
k_sleep(K_FOREVER);
12+
13+
return 0;
14+
}
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/sys/printk.h>
9+
#include <zephyr/logging/log.h>
10+
#include <zephyr/devicetree.h>
11+
#include <zephyr/devicetree/clocks.h>
12+
#include <zephyr/drivers/clock_control/nrf_clock_control.h>
13+
14+
LOG_MODULE_REGISTER(idle_clock_control);
15+
16+
struct test_clk_ctx {
17+
const struct device *clk_dev;
18+
const struct nrf_clock_spec *clk_specs;
19+
size_t clk_specs_size;
20+
};
21+
22+
const struct nrf_clock_spec test_clk_specs_hsfll[] = {
23+
{
24+
.frequency = MHZ(128),
25+
.accuracy = 0,
26+
.precision = NRF_CLOCK_CONTROL_PRECISION_DEFAULT,
27+
},
28+
{
29+
.frequency = MHZ(320),
30+
.accuracy = 0,
31+
.precision = NRF_CLOCK_CONTROL_PRECISION_DEFAULT,
32+
},
33+
{
34+
.frequency = MHZ(64),
35+
.accuracy = 0,
36+
.precision = NRF_CLOCK_CONTROL_PRECISION_DEFAULT,
37+
},
38+
};
39+
40+
const struct nrf_clock_spec test_clk_specs_fll16m[] = {
41+
{
42+
.frequency = MHZ(16),
43+
.accuracy = 20000,
44+
.precision = NRF_CLOCK_CONTROL_PRECISION_DEFAULT,
45+
},
46+
{
47+
.frequency = MHZ(16),
48+
.accuracy = 5020,
49+
.precision = NRF_CLOCK_CONTROL_PRECISION_DEFAULT,
50+
},
51+
{
52+
.frequency = MHZ(16),
53+
.accuracy = 30,
54+
.precision = NRF_CLOCK_CONTROL_PRECISION_DEFAULT,
55+
},
56+
};
57+
58+
static const struct test_clk_ctx fll16m_test_clk_ctx[] = {
59+
{
60+
.clk_dev = DEVICE_DT_GET(DT_NODELABEL(fll16m)),
61+
.clk_specs = test_clk_specs_fll16m,
62+
.clk_specs_size = ARRAY_SIZE(test_clk_specs_fll16m),
63+
},
64+
};
65+
66+
static const struct test_clk_ctx hsfll_test_clk_ctx[] = {
67+
{
68+
.clk_dev = DEVICE_DT_GET(DT_NODELABEL(cpuapp_hsfll)),
69+
.clk_specs = test_clk_specs_hsfll,
70+
.clk_specs_size = ARRAY_SIZE(test_clk_specs_hsfll),
71+
},
72+
};
73+
74+
const struct nrf_clock_spec test_clk_specs_lfclk[] = {
75+
{
76+
.frequency = 32768,
77+
.accuracy = 0,
78+
.precision = NRF_CLOCK_CONTROL_PRECISION_DEFAULT,
79+
},
80+
{
81+
.frequency = 32768,
82+
.accuracy = 20,
83+
.precision = NRF_CLOCK_CONTROL_PRECISION_DEFAULT,
84+
},
85+
{
86+
.frequency = 32768,
87+
.accuracy = 20,
88+
.precision = NRF_CLOCK_CONTROL_PRECISION_HIGH,
89+
},
90+
};
91+
92+
static const struct test_clk_ctx lfclk_test_clk_ctx[] = {
93+
{
94+
.clk_dev = DEVICE_DT_GET(DT_NODELABEL(lfclk)),
95+
.clk_specs = test_clk_specs_lfclk,
96+
.clk_specs_size = ARRAY_SIZE(test_clk_specs_lfclk),
97+
},
98+
};
99+
100+
static void test_request_release_clock_spec(const struct device *clk_dev,
101+
const struct nrf_clock_spec *clk_spec)
102+
{
103+
int ret = 0;
104+
int res = 0;
105+
struct onoff_client cli;
106+
uint32_t rate;
107+
108+
LOG_INF("Clock under test: %s", clk_dev->name);
109+
sys_notify_init_spinwait(&cli.notify);
110+
ret = nrf_clock_control_request(clk_dev, clk_spec, &cli);
111+
__ASSERT_NO_MSG(ret == 0);
112+
do {
113+
ret = sys_notify_fetch_result(&cli.notify, &res);
114+
k_yield();
115+
} while (ret == -EAGAIN);
116+
__ASSERT_NO_MSG(ret == 0);
117+
__ASSERT_NO_MSG(res == 0);
118+
ret = clock_control_get_rate(clk_dev, NULL, &rate);
119+
__ASSERT_NO_MSG(ret == 0);
120+
__ASSERT_NO_MSG(rate == clk_spec->frequency);
121+
k_busy_wait(10000);
122+
ret = nrf_clock_control_release(clk_dev, clk_spec);
123+
__ASSERT_NO_MSG(ret == ONOFF_STATE_ON);
124+
}
125+
126+
static void test_clock_control_request(const struct test_clk_ctx *clk_contexts,
127+
size_t contexts_size)
128+
{
129+
const struct test_clk_ctx *clk_context;
130+
size_t clk_specs_size;
131+
const struct device *clk_dev;
132+
const struct nrf_clock_spec *clk_spec;
133+
134+
for (size_t i = 0; i < contexts_size; i++) {
135+
clk_context = &clk_contexts[i];
136+
clk_specs_size = clk_context->clk_specs_size;
137+
138+
for (size_t u = 0; u < clk_specs_size; u++) {
139+
clk_dev = clk_context->clk_dev;
140+
clk_spec = &clk_context->clk_specs[u];
141+
142+
LOG_INF("Applying clock (%s) spec: frequency %d, accuracy %d, precision "
143+
"%d",
144+
clk_dev->name, clk_spec->frequency, clk_spec->accuracy,
145+
clk_spec->precision);
146+
test_request_release_clock_spec(clk_dev, clk_spec);
147+
k_msleep(1000);
148+
}
149+
}
150+
}
151+
152+
int main(void)
153+
{
154+
LOG_INF("Idle clock_control, %s", CONFIG_BOARD_TARGET);
155+
k_msleep(100);
156+
while (1) {
157+
test_clock_control_request(hsfll_test_clk_ctx, ARRAY_SIZE(hsfll_test_clk_ctx));
158+
test_clock_control_request(fll16m_test_clk_ctx, ARRAY_SIZE(fll16m_test_clk_ctx));
159+
test_clock_control_request(lfclk_test_clk_ctx, ARRAY_SIZE(lfclk_test_clk_ctx));
160+
}
161+
162+
return 0;
163+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
# Add remote project
12+
ExternalZephyrProject_Add(
13+
APPLICATION remote
14+
SOURCE_DIR ${APP_DIR}/remote
15+
BOARD ${SB_CONFIG_REMOTE_BOARD}
16+
BOARD_REVISION ${BOARD_REVISION}
17+
)
18+
19+
# Add a dependency so that the remote image will be built and flashed first
20+
add_dependencies(idle_clock_control remote)
21+
# Add dependency so that the remote image is flashed first.
22+
sysbuild_add_dependencies(FLASH idle_clock_control remote)
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
common:
2+
sysbuild: true
3+
tags: ci_build ci_tests_benchmarks_multicore ppk_power_measure
4+
5+
tests:
6+
benchmarks.multicore.idle_clock_control:
7+
harness: pytest
8+
platform_allow:
9+
- nrf54h20dk/nrf54h20/cpuapp
10+
integration_platforms:
11+
- nrf54h20dk/nrf54h20/cpuapp
12+
extra_args:
13+
- SB_CONF_FILE=sysbuild/nrf54h20dk_nrf54h20_cpurad.conf
14+
harness_config:
15+
fixture: ppk_power_measure
16+
pytest_root:
17+
- "${CUSTOM_ROOT_TEST_DIR}/test_measure_power_consumption.py::test_measure_and_data_dump_power_consumption_clock_control"
18+
timeout: 90

0 commit comments

Comments
 (0)