Skip to content

Commit

Permalink
tests: benchmarks: multicore: idle_gpio: Add led
Browse files Browse the repository at this point in the history
Turn on the led when core becomes active
This feature is needed for the new power
consumption measurement framework

Signed-off-by: Piotr Krzyzanowski <[email protected]>
  • Loading branch information
nordic-pikr authored and nordic-piks committed Dec 18, 2024
1 parent a8d9fa1 commit 4e84c35
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
/ {
aliases {
/delete-property/ sw1;
/delete-property/ led1;
};
};

/delete-node/ &button1;
/delete-node/ &led1;

&gpiote130 {
status = "okay";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/ {
aliases {
sw1 = &button1;
led1 = &led1;
};
buttons {
compatible = "gpio-keys";
Expand All @@ -16,12 +17,23 @@
zephyr,code = <INPUT_KEY_1>;
};
};
leds {
compatible = "gpio-leds";
led1: led_1 {
gpios = <&gpio9 1 GPIO_ACTIVE_HIGH>;
label = "Green LED 1";
};
};
};

&gpio0 {
status = "okay";
};

&gpio9 {
status = "okay";
};

&gpiote130 {
status = "okay";
owned-channels = <1>;
Expand Down
16 changes: 16 additions & 0 deletions tests/benchmarks/multicore/idle_gpio/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ LOG_MODULE_REGISTER(idle_gpio);

#if IS_ENABLED(CONFIG_SOC_NRF54H20_CPUAPP)
static const struct gpio_dt_spec sw = GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios);
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios);
#elif IS_ENABLED(CONFIG_SOC_NRF54H20_CPURAD)
static const struct gpio_dt_spec sw = GPIO_DT_SPEC_GET(DT_ALIAS(sw1), gpios);
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(DT_ALIAS(led1), gpios);
#else
#error "Invalid core selected. "
#endif
Expand All @@ -24,6 +26,7 @@ static K_SEM_DEFINE(my_gpio_sem, 0, 1);

void my_gpio_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
gpio_pin_set_dt(&led, 1);
LOG_INF("User callback for %s\n", CONFIG_BOARD_TARGET);
k_sem_give(&my_gpio_sem);
}
Expand All @@ -35,6 +38,18 @@ int main(void)
unsigned int cnt = 0;
int rc;

rc = gpio_is_ready_dt(&led);
if (rc < 0) {
LOG_ERR("GPIO Device not ready (%d)\n", rc);
return 0;
}

rc = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
if (rc < 0) {
LOG_ERR("Could not configure led GPIO (%d)\n", rc);
return 0;
}

rc = gpio_is_ready_dt(&sw);
if (rc < 0) {
LOG_ERR("GPIO Device not ready (%d)\n", rc);
Expand All @@ -57,6 +72,7 @@ int main(void)
LOG_INF("Multicore idle_gpio test on %s\n", CONFIG_BOARD_TARGET);
while (1) {
LOG_INF("Multicore idle_gpio test iteration %u\n", cnt++);
gpio_pin_set_dt(&led, 0);
if (k_sem_take(&my_gpio_sem, K_FOREVER) != 0) {
LOG_ERR("Failed to take a semaphore\n");
return 0;
Expand Down

0 comments on commit 4e84c35

Please sign in to comment.