Skip to content

Commit

Permalink
tests: benchmarks: multicore: idle_spim_loopback: GDF switching
Browse files Browse the repository at this point in the history
Add test case for changing GD frequency when driver
is active.

Signed-off-by: Piotr Krzyzanowski <[email protected]>
  • Loading branch information
nordic-pikr committed Feb 26, 2025
1 parent 444b6e0 commit e671e96
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
3 changes: 3 additions & 0 deletions tests/benchmarks/multicore/idle_spim_loopback/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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"
34 changes: 17 additions & 17 deletions tests/benchmarks/multicore/idle_spim_loopback/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -182,6 +175,7 @@ int main(void)
while (test_repetitions)
#endif
{
switch_flag = 1;
test_pass = true;
timer_expired = false;

Expand Down Expand Up @@ -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. */
Expand Down
29 changes: 29 additions & 0 deletions tests/benchmarks/multicore/idle_spim_loopback/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -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
#
Expand Down

0 comments on commit e671e96

Please sign in to comment.