Skip to content

Commit afbb586

Browse files
nordic-baburlubos
authored andcommitted
tests: benchmarks: timer_waiting: tweak test scenario
Remove blinking LED, use k_busy_wait instead of looping to keep CPU busy Signed-off-by: Bartlomiej Buczek <[email protected]>
1 parent b10c100 commit afbb586

File tree

1 file changed

+14
-27
lines changed
  • tests/benchmarks/power_consumption/timer_waiting/src

1 file changed

+14
-27
lines changed

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

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,32 @@
66

77
#include <zephyr/kernel.h>
88
#include <zephyr/drivers/counter.h>
9-
#include <zephyr/drivers/gpio.h>
109

1110
#define ALARM_CHANNEL_ID (0)
12-
#define LED0_NODE DT_ALIAS(led0)
13-
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
1411
const struct device *const counter_dev = DEVICE_DT_GET(DT_ALIAS(counter));
15-
static bool state = true;
16-
1712
struct counter_alarm_cfg counter_cfg;
1813

19-
void counter_handler(const struct device *counter_dev, uint8_t id, uint32_t ticks, void *user_data)
14+
void counter_handler(const struct device *counter_dev, uint8_t chan_id,
15+
uint32_t ticks, void *user_data)
2016
{
21-
counter_set_channel_alarm(counter_dev, ALARM_CHANNEL_ID, user_data);
22-
gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
23-
for (int i = 1000000UL; i > 0; i--) {
24-
if (state == true) {
25-
state = false;
26-
gpio_pin_set_dt(&led, 1);
27-
} else {
28-
state = true;
29-
gpio_pin_set_dt(&led, 0);
30-
}
31-
}
32-
gpio_pin_configure_dt(&led, GPIO_OUTPUT_INACTIVE);
17+
k_busy_wait(500000);
18+
counter_stop(counter_dev);
3319
}
3420

3521
int main(void)
3622
{
37-
counter_start(counter_dev);
38-
39-
counter_cfg.flags = 0;
40-
counter_cfg.ticks = counter_us_to_ticks(counter_dev, 1000000UL);
41-
counter_cfg.callback = counter_handler;
42-
counter_cfg.user_data = &counter_cfg;
23+
while (1) {
24+
k_msleep(1500);
25+
counter_start(counter_dev);
4326

44-
counter_set_channel_alarm(counter_dev, ALARM_CHANNEL_ID, &counter_cfg);
27+
counter_cfg.flags = 0;
28+
counter_cfg.ticks = counter_us_to_ticks(counter_dev, 1000000UL);
29+
counter_cfg.callback = counter_handler;
30+
counter_cfg.user_data = &counter_cfg;
4531

46-
while (1) {
47-
k_sleep(K_FOREVER);
32+
counter_set_channel_alarm(counter_dev, ALARM_CHANNEL_ID, &counter_cfg);
33+
k_msleep(1500);
4834
}
35+
4936
return 0;
5037
}

0 commit comments

Comments
 (0)