From e671e9609c46a4d09fc9ada1aa3cf87c9240aec1 Mon Sep 17 00:00:00 2001 From: Piotr Krzyzanowski Date: Tue, 25 Feb 2025 14:54:09 +0100 Subject: [PATCH] tests: benchmarks: multicore: idle_spim_loopback: GDF switching Add test case for changing GD frequency when driver is active. Signed-off-by: Piotr Krzyzanowski --- .../multicore/idle_spim_loopback/Kconfig | 3 ++ .../multicore/idle_spim_loopback/src/main.c | 34 +++++++++---------- .../idle_spim_loopback/testcase.yaml | 29 ++++++++++++++++ 3 files changed, 49 insertions(+), 17 deletions(-) diff --git a/tests/benchmarks/multicore/idle_spim_loopback/Kconfig b/tests/benchmarks/multicore/idle_spim_loopback/Kconfig index 5000250506bb..332faf53c103 100644 --- a/tests/benchmarks/multicore/idle_spim_loopback/Kconfig +++ b/tests/benchmarks/multicore/idle_spim_loopback/Kconfig @@ -70,4 +70,7 @@ config GLOBAL_DOMAIN_CLOCK_FREQUENCY_MHZ default 128 if GLOBAL_DOMAIN_CLOCK_FREQUENCY_OPTION_128MHZ default 64 if GLOBAL_DOMAIN_CLOCK_FREQUENCY_OPTION_64MHZ +config GLOBAL_DOMAIN_CLOCK_FREQUENCY_SWITCHING + bool "Enable global domain frequency changing when driver is active" + source "Kconfig.zephyr" diff --git a/tests/benchmarks/multicore/idle_spim_loopback/src/main.c b/tests/benchmarks/multicore/idle_spim_loopback/src/main.c index 252d14793f3d..a8d946a013b8 100644 --- a/tests/benchmarks/multicore/idle_spim_loopback/src/main.c +++ b/tests/benchmarks/multicore/idle_spim_loopback/src/main.c @@ -54,34 +54,29 @@ static struct k_timer my_timer; static bool timer_expired; #if defined(CONFIG_CLOCK_CONTROL) -const struct nrf_clock_spec clk_spec_global_hsfll = { - .frequency = MHZ(CONFIG_GLOBAL_DOMAIN_CLOCK_FREQUENCY_MHZ)}; +const uint32_t freq[] = {320, 256, 128, 64}; /* * Set Global Domain frequency (HSFLL120) - * based on: CONFIG_GLOBAL_DOMAIN_CLOCK_FREQUENCY_MHZ */ -void set_global_domain_frequency(void) +void set_global_domain_frequency(uint32_t freq) { int err; int res; struct onoff_client cli; const struct device *hsfll_dev = DEVICE_DT_GET(DT_NODELABEL(hsfll120)); + const struct nrf_clock_spec clk_spec_global_hsfll = {.frequency = MHZ(freq)}; printk("Requested frequency [Hz]: %d\n", clk_spec_global_hsfll.frequency); sys_notify_init_spinwait(&cli.notify); err = nrf_clock_control_request(hsfll_dev, &clk_spec_global_hsfll, &cli); - printk("Return code: %d\n", err); - __ASSERT_NO_MSG(err < 3); - __ASSERT_NO_MSG(err >= 0); + __ASSERT((err >= 0 && err < 3), "Wrong nrf_clock_control_request return code"); do { err = sys_notify_fetch_result(&cli.notify, &res); k_yield(); } while (err == -EAGAIN); - printk("Clock control request return value: %d\n", err); - printk("Clock control request response code: %d\n", res); - __ASSERT_NO_MSG(err == 0); - __ASSERT_NO_MSG(res == 0); + __ASSERT(err == 0, "Wrong clock control request return code"); + __ASSERT(res == 0, "Wrong clock control request response"); } #endif /* CONFIG_CLOCK_CONTROL */ @@ -110,6 +105,7 @@ int main(void) { int ret; int counter = 0; + uint8_t switch_flag; uint8_t acc = 0; bool test_pass; int test_repetitions = 3; @@ -125,14 +121,11 @@ int main(void) ret = gpio_is_ready_dt(&led); __ASSERT(ret, "Error: GPIO Device not ready"); -#if defined(CONFIG_CLOCK_CONTROL) - ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_INACTIVE); - __ASSERT(ret == 0, "Could not configure led GPIO"); - gpio_pin_set_dt(&led, 1); - set_global_domain_frequency(); -#else ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE); __ASSERT(ret == 0, "Could not configure led GPIO"); + +#if defined(CONFIG_CLOCK_CONTROL) + set_global_domain_frequency(CONFIG_GLOBAL_DOMAIN_CLOCK_FREQUENCY_MHZ); #endif LOG_INF("Multicore idle_spi_loopback test on %s", CONFIG_BOARD_TARGET); @@ -182,6 +175,7 @@ int main(void) while (test_repetitions) #endif { + switch_flag = 1; test_pass = true; timer_expired = false; @@ -218,6 +212,12 @@ int main(void) if (ret != 0) { LOG_ERR("spi_transceive_dt, err: %d", ret); } +#if defined(CONFIG_GLOBAL_DOMAIN_CLOCK_FREQUENCY_SWITCHING) + if (switch_flag) { + set_global_domain_frequency(freq[counter % ARRAY_SIZE(freq)]); + switch_flag = 0; + } +#endif __ASSERT(ret == 0, "Error: spi_transceive_dt, err: %d\n", ret); /* Check if the received data is consistent with the data sent. */ diff --git a/tests/benchmarks/multicore/idle_spim_loopback/testcase.yaml b/tests/benchmarks/multicore/idle_spim_loopback/testcase.yaml index e2df3cea54ef..8b77d393565b 100644 --- a/tests/benchmarks/multicore/idle_spim_loopback/testcase.yaml +++ b/tests/benchmarks/multicore/idle_spim_loopback/testcase.yaml @@ -134,6 +134,20 @@ tests: pytest_root: - "${CUSTOM_ROOT_TEST_DIR}/test_measure_power_consumption.py::test_measure_and_data_dump_spim_and_s2ram" + benchmarks.multicore.idle_spim_loopback.4_bytes.gd_freq_switching.s2ram_fast: + filter: not CONFIG_COVERAGE + tags: ppk_power_measure + extra_args: + - idle_spim_loopback_CONF_FILE=prj_s2ram.conf + - idle_spim_loopback_DTC_OVERLAY_FILE="boards/nrf54h20dk_nrf54h20_cpuapp_fast.overlay" + - CONFIG_CLOCK_CONTROL=y + - CONFIG_GLOBAL_DOMAIN_CLOCK_FREQUENCY_SWITCHING=y + harness: pytest + harness_config: + fixture: spi_loopback + pytest_root: + - "${CUSTOM_ROOT_TEST_DIR}/test_measure_power_consumption.py::test_measure_and_data_dump_spim_and_s2ram_7s" + # # 16 Bytes of data # @@ -267,6 +281,21 @@ tests: pytest_root: - "${CUSTOM_ROOT_TEST_DIR}/test_measure_power_consumption.py::test_measure_and_data_dump_spim_and_s2ram" + benchmarks.multicore.idle_spim_loopback.16_bytes.gd_freq_switching.s2ram_fast: + filter: not CONFIG_COVERAGE + tags: ppk_power_measure + extra_args: + - idle_spim_loopback_CONF_FILE=prj_s2ram.conf + - idle_spim_loopback_DTC_OVERLAY_FILE="boards/nrf54h20dk_nrf54h20_cpuapp_fast.overlay" + - idle_spim_loopback_CONFIG_DATA_FIELD=16 + - CONFIG_CLOCK_CONTROL=y + - CONFIG_GLOBAL_DOMAIN_CLOCK_FREQUENCY_SWITCHING=y + harness: pytest + harness_config: + fixture: spi_loopback + pytest_root: + - "${CUSTOM_ROOT_TEST_DIR}/test_measure_power_consumption.py::test_measure_and_data_dump_spim_and_s2ram_7s" + # # 4 Bytes of data with SPI Chip Select Lock enabled #