Skip to content

Commit 35f5a4b

Browse files
nordic-piksrlubos
authored andcommitted
tests: benchmarks: power_consumption: gpio: prevent irq when toggling
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 <[email protected]>
1 parent a9732b6 commit 35f5a4b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

tests/benchmarks/power_consumption/common/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ void timer_handler(struct k_timer *dummy)
1919
{
2020
if (state == true) {
2121
state = false;
22-
gpio_pin_set_dt(&led, 0);
22+
gpio_pin_set_dt(&led, 1);
2323
k_thread_resume(thread_id);
2424
} else {
2525
state = true;
26-
gpio_pin_set_dt(&led, 1);
26+
gpio_pin_set_dt(&led, 0);
2727
k_thread_suspend(thread_id);
2828
}
2929
}

tests/benchmarks/power_consumption/gpio/src/driver_test.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <zephyr/drivers/gpio.h>
88
#include <zephyr/kernel.h>
9+
#include <zephyr/irq.h>
910

1011
#define OUTPUT_NODE DT_ALIAS(out0)
1112
#define INPUT_NODE DT_ALIAS(in0)
@@ -24,6 +25,7 @@ void input_active(const struct device *dev, struct gpio_callback *cb, uint32_t p
2425
void thread_definition(void)
2526
{
2627
int rc;
28+
unsigned int key;
2729

2830
rc = gpio_is_ready_dt(&input);
2931
__ASSERT_NO_MSG(rc);
@@ -45,12 +47,12 @@ void thread_definition(void)
4547

4648
while (1) {
4749
counter = 0;
50+
key = irq_lock();
4851
rc = gpio_pin_set_dt(&output, 0);
49-
__ASSERT_NO_MSG(rc == 0);
5052
rc = gpio_pin_set_dt(&output, 1);
5153
rc = gpio_pin_set_dt(&output, 0);
54+
irq_unlock(key);
5255
__ASSERT_NO_MSG(counter == 1);
53-
__ASSERT_NO_MSG(rc == 0);
5456

5557
k_msleep(10);
5658
}

0 commit comments

Comments
 (0)