blob: d9abe5a33b03b905420185b7d3ff7201e9bb7edc [file] [log] [blame]
Austin Schuh208337d2022-01-01 14:29:11 -08001/*
2 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include "pico/timeout_helper.h"
8
9static bool check_single_timeout_us(timeout_state_t *ts) {
10 return time_reached(ts->next_timeout);
11}
12
13check_timeout_fn init_single_timeout_until(timeout_state_t *ts, absolute_time_t target) {
14 ts->next_timeout = target;
15 return check_single_timeout_us;
16}
17
18static bool check_per_iteration_timeout_us(timeout_state_t *ts) {
19 if (time_reached(ts->next_timeout)) {
20 return true;
21 }
22 ts->next_timeout = make_timeout_time_us(ts->param);
23 return false;
24}
25
26check_timeout_fn init_per_iteration_timeout_us(timeout_state_t *ts, uint64_t per_iteration_timeout_us) {
27 ts->next_timeout = make_timeout_time_us(per_iteration_timeout_us);
28 ts->param = per_iteration_timeout_us;
29 return check_per_iteration_timeout_us;
30}