EtcPal  0.4.1
ETC Platform Abstraction Layer (EtcPal)
View other versions:
timer.h
1 /******************************************************************************
2  * Copyright 2022 ETC Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *******************************************************************************
16  * This file is a part of EtcPal. For more information, go to:
17  * https://github.com/ETCLabs/EtcPal
18  ******************************************************************************/
19 
20 /* etcpal_timer.h: Platform-neutral implementation of system timers. */
21 
22 #ifndef ETCPAL_TIMER_H_
23 #define ETCPAL_TIMER_H_
24 
25 #include <stdbool.h>
26 #include <stdint.h>
27 
90 #ifdef __cplusplus
91 extern "C" {
92 #endif
93 
101 typedef struct EtcPalTimer
102 {
103  uint32_t reset_time;
104  uint32_t interval;
106 
112 #define ETCPAL_TIME_ELAPSED_SINCE(start_time) (uint32_t)(etcpal_getms() - (uint32_t)start_time)
113 
114 /* Function with platform-specific definition */
115 
120 uint32_t etcpal_getms(void);
121 
122 /* Functions with platform-neutral definitions */
123 
124 void etcpal_timer_start(EtcPalTimer* timer, uint32_t interval);
125 void etcpal_timer_reset(EtcPalTimer* timer);
126 uint32_t etcpal_timer_elapsed(const EtcPalTimer* timer);
127 bool etcpal_timer_is_expired(const EtcPalTimer* timer);
128 uint32_t etcpal_timer_remaining(const EtcPalTimer* timer);
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 
138 #endif /* ETCPAL_TIMER_H_ */
uint32_t etcpal_timer_elapsed(const EtcPalTimer *timer)
Get the time since a timer was reset.
Definition: timer.c:56
void etcpal_timer_start(EtcPalTimer *timer, uint32_t interval)
Start a timer.
Definition: timer.c:30
uint32_t etcpal_timer_remaining(const EtcPalTimer *timer)
Get the amount of time remaining in a timer.
Definition: timer.c:87
struct EtcPalTimer EtcPalTimer
A millisecond-resolution timer.
bool etcpal_timer_is_expired(const EtcPalTimer *timer)
Check to see if a timer is expired.
Definition: timer.c:73
uint32_t etcpal_getms(void)
Get a monotonically-increasing millisecond value.
void etcpal_timer_reset(EtcPalTimer *timer)
Reset a timer while keeping the same interval.
Definition: timer.c:43
A millisecond-resolution timer.
Definition: timer.h:102
uint32_t reset_time
The time at which this timer was reset.
Definition: timer.h:103
uint32_t interval
This timer's timeout interval.
Definition: timer.h:104