Skip to content

Commit 43bb7b6

Browse files
committed
pbio/os: Add API for extending timeout by interval.
This makes it possible to have processes have constant loop time on average. Fixes pybricks/support#2282
1 parent 3dfdc34 commit 43bb7b6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/pbio/include/pbio/os.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ typedef struct pbio_os_timer_t {
7171

7272
void pbio_os_timer_set(pbio_os_timer_t *timer, uint32_t duration);
7373

74+
void pbio_os_timer_extend(pbio_os_timer_t *timer);
75+
7476
bool pbio_os_timer_is_expired(pbio_os_timer_t *timer);
7577

7678
/**

lib/pbio/src/os.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ void pbio_os_timer_set(pbio_os_timer_t *timer, uint32_t duration) {
2424
timer->duration = duration;
2525
}
2626

27+
/**
28+
* Extends the timeout by incrementing the start time by the duration.
29+
*
30+
* Duration must have been set by ::pbio_os_timer_set previously.
31+
*
32+
* @param timer The timer whose timeout to extend.
33+
*/
34+
void pbio_os_timer_extend(pbio_os_timer_t *timer) {
35+
timer->start += timer->duration;
36+
}
37+
2738
/**
2839
* Whether the timer has expired.
2940
*

0 commit comments

Comments
 (0)