Austin Schuh | 208337d | 2022-01-01 14:29:11 -0800 | [diff] [blame^] | 1 | /* |
| 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 | |
| 9 | static bool check_single_timeout_us(timeout_state_t *ts) { |
| 10 | return time_reached(ts->next_timeout); |
| 11 | } |
| 12 | |
| 13 | check_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 | |
| 18 | static 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 | |
| 26 | check_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 | } |