Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: benchmarks: power_consumption: i2c: Fix increased power consumpion #19861

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
pinctrl-1 = <&i2c130_sleep>;
pinctrl-names = "default", "sleep";
zephyr,concat-buf-size = <255>;
zephyr,pm-device-runtime-auto;

bme688: bme688@76 {
compatible = "bosch,bme680";
Expand Down Expand Up @@ -82,6 +83,7 @@
pinctrl-1 = <&spi131_sleep>;
pinctrl-names = "default", "sleep";
overrun-character = <0x00>;
zephyr,pm-device-runtime-auto;
cs-gpios = <&gpio0 4 GPIO_ACTIVE_LOW>,
<&gpio1 2 GPIO_ACTIVE_LOW>;

Expand Down
14 changes: 13 additions & 1 deletion tests/benchmarks/power_consumption/common/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(DT_ALIAS(led2), gpios);
static bool state = true;
extern void thread_definition(void);

/* Some tests require that test thread controls the moment when it is
* suspended. In that case test implements this function and returns true to
* indicated that test thread will take case of the suspension and it can
* be skipped in the common code.
*/
__weak bool self_suspend_req(void)
{
return false;
}

K_THREAD_DEFINE(thread_id, 500, thread_definition, NULL, NULL, NULL,
5, 0, 0);

Expand All @@ -24,7 +34,9 @@ void timer_handler(struct k_timer *dummy)
} else {
state = true;
gpio_pin_set_dt(&led, 0);
k_thread_suspend(thread_id);
if (self_suspend_req() == false) {
k_thread_suspend(thread_id);
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions tests/benchmarks/power_consumption/i2c/src/driver_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@

static const struct device *i2c = DEVICE_DT_GET(DT_ALIAS(sensor_bme688));

static bool suspend_req;

bool self_suspend_req(void)
{
suspend_req = true;
return true;
}

void thread_definition(void)
{
Expand All @@ -17,6 +24,10 @@ void thread_definition(void)

while (1) {
ret = i2c_reg_read_byte(i2c, 0x76, 0x75, &value);
if (suspend_req) {
suspend_req = false;
k_thread_suspend(k_current_get());
}
if (ret < 0) {
printk("Failure in reading byte %d", ret);
return;
Expand Down