Skip to content

Commit

Permalink
tests: benchmarks: power_consumption: i2c: Improve thread suspend
Browse files Browse the repository at this point in the history
Test thread cannot be suspended at any time because driver power
management happens in the thread context so if thread is suspended
at the random moment and system goes to s2ram it can lead to
increased power consumption because thread got suspended before
i2c device got properly suspended.

Signed-off-by: Krzysztof Chruściński <[email protected]>
  • Loading branch information
nordic-krch authored and nordic-piks committed Jan 13, 2025
1 parent 6f4dc17 commit 4408403
Showing 1 changed file with 11 additions and 0 deletions.
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

0 comments on commit 4408403

Please sign in to comment.