Skip to content
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
2 changes: 2 additions & 0 deletions include/infuse/task_runner/schedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ struct task_schedule {
uint8_t validity;
/** TASK_PERIODICITY_* value */
uint8_t periodicity_type;
/** Task will not start for the first N minutes after boot */
uint8_t boot_lockout_minutes;
/** Duration after which task is requested to terminate */
uint32_t timeout_s;
/** Battery charge thresholds to start the task */
Expand Down
8 changes: 8 additions & 0 deletions subsys/task_runner/schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* SPDX-License-Identifier: FSL-1.1-ALv2
*/

#include <zephyr/sys/clock.h>

#include <infuse/states.h>
#include <infuse/task_runner/schedule.h>

Expand Down Expand Up @@ -114,6 +116,12 @@ bool task_schedule_should_start(const struct task_schedule *schedule,
return false;
}

/* Boot lockout */
if (schedule->boot_lockout_minutes &&
((uptime / SEC_PER_MIN) < schedule->boot_lockout_minutes)) {
return false;
}

if (schedule->periodicity_type == TASK_PERIODICITY_FIXED) {
periodicity = (epoch_time % schedule->periodicity.fixed.period_s) == 0;
} else if (schedule->periodicity_type == TASK_PERIODICITY_LOCKOUT) {
Expand Down
24 changes: 24 additions & 0 deletions tests/subsys/task_runner/schedules/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,30 @@ ZTEST(task_runner_schedules, test_inactive_schedule)
}
}

ZTEST(task_runner_schedules, test_boot_lockout)
{
INFUSE_STATES_ARRAY(app_states) = {0};
struct task_schedule schedule = {
.validity = TASK_VALID_ALWAYS,
.boot_lockout_minutes = 2,
};
struct task_schedule_state state = {0};

zassert_true(task_schedule_validate(&schedule));

zassert_false(task_schedule_should_start(&schedule, &state, app_states, 0, 100, 100));
zassert_false(task_schedule_should_start(&schedule, &state, app_states, 100, 101, 100));
zassert_false(task_schedule_should_start(&schedule, &state, app_states, 118, 102, 100));
zassert_false(task_schedule_should_start(&schedule, &state, app_states, 119, 103, 100));
zassert_true(task_schedule_should_start(&schedule, &state, app_states, 120, 104, 100));
zassert_true(task_schedule_should_start(&schedule, &state, app_states, 121, 105, 100));
zassert_true(task_schedule_should_start(&schedule, &state, app_states, 123, 106, 100));
zassert_true(task_schedule_should_start(&schedule, &state, app_states, 1000, 107, 100));
zassert_true(task_schedule_should_start(&schedule, &state, app_states, 1000000, 108, 100));
zassert_true(
task_schedule_should_start(&schedule, &state, app_states, UINT32_MAX, 109, 100));
}

ZTEST(task_runner_schedules, test_periodicity_fixed)
{
INFUSE_STATES_ARRAY(app_states) = {0};
Expand Down