Skip to content

Commit

Permalink
tests: benchmarks: power_consumption: gpio: prevent irq when toggling
Browse files Browse the repository at this point in the history
There should be single, short impulse at pin.
If it will be interrupted by irq at state high,
will trigger irq loop.

Additionally, do not light LED when sleeping.

Signed-off-by: Piotr Kosycarz <piotr.kosycarz@nordicsemi.no>
(cherry picked from commit 35f5a4b)
  • Loading branch information
nordic-piks authored and rlubos committed Nov 13, 2024
1 parent c2555c7 commit 5bff7d9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions tests/benchmarks/power_consumption/common/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ void timer_handler(struct k_timer *dummy)
{
if (state == true) {
state = false;
gpio_pin_set_dt(&led, 0);
gpio_pin_set_dt(&led, 1);
k_thread_resume(thread_id);
} else {
state = true;
gpio_pin_set_dt(&led, 1);
gpio_pin_set_dt(&led, 0);
k_thread_suspend(thread_id);
}
}
Expand Down
6 changes: 4 additions & 2 deletions tests/benchmarks/power_consumption/gpio/src/driver_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <zephyr/drivers/gpio.h>
#include <zephyr/kernel.h>
#include <zephyr/irq.h>

#define OUTPUT_NODE DT_ALIAS(out0)
#define INPUT_NODE DT_ALIAS(in0)
Expand All @@ -24,6 +25,7 @@ void input_active(const struct device *dev, struct gpio_callback *cb, uint32_t p
void thread_definition(void)
{
int rc;
unsigned int key;

rc = gpio_is_ready_dt(&input);
__ASSERT_NO_MSG(rc);
Expand All @@ -45,12 +47,12 @@ void thread_definition(void)

while (1) {
counter = 0;
key = irq_lock();
rc = gpio_pin_set_dt(&output, 0);
__ASSERT_NO_MSG(rc == 0);
rc = gpio_pin_set_dt(&output, 1);
rc = gpio_pin_set_dt(&output, 0);
irq_unlock(key);
__ASSERT_NO_MSG(counter == 1);
__ASSERT_NO_MSG(rc == 0);

k_msleep(10);
}
Expand Down

0 comments on commit 5bff7d9

Please sign in to comment.