RTEMS 6.1-rc2
Loading...
Searching...
No Matches
timecounter.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
11/*
12 * Copyright (c) 2015 embedded brains GmbH & Co. KG
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef _RTEMS_TIMECOUNTER_H
37#define _RTEMS_TIMECOUNTER_H
38
41
42#ifdef __cplusplus
43extern "C" {
44#endif /* __cplusplus */
45
63#define RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER 100
64
89static inline void rtems_timecounter_install(
90 struct timecounter *tc
91)
92{
94}
95
99static inline void rtems_timecounter_tick(void)
100{
102}
103
107typedef struct {
108 struct timecounter tc;
109 uint64_t scaler;
110 uint32_t real_interval;
111 uint32_t binary_interval;
113
119);
120
126);
127
134);
135
209 uint32_t counter_frequency_in_hz,
210 uint32_t counter_ticks_per_clock_tick,
211 timecounter_get_t *get_timecount
212);
213
222static inline uint32_t rtems_timecounter_simple_scale(
223 const rtems_timecounter_simple *tc,
224 uint32_t value
225)
226{
227 return (uint32_t) ( ( value * tc->scaler ) >> 32 );
228}
229
238static inline void rtems_timecounter_simple_downcounter_tick(
242)
243{
244 ISR_lock_Context lock_context;
245 uint32_t current;
246
247 _Timecounter_Acquire( &lock_context );
248
249 ( *at_tick )( tc );
250
251 current = rtems_timecounter_simple_scale(
252 tc,
253 tc->real_interval - ( *get )( tc )
254 );
255
256 _Timecounter_Tick_simple( tc->binary_interval, current, &lock_context );
257}
258
267static inline void rtems_timecounter_simple_upcounter_tick(
271)
272{
273 ISR_lock_Context lock_context;
274 uint32_t current;
275
276 _Timecounter_Acquire( &lock_context );
277
278 ( *at_tick )( tc );
279
280 current = rtems_timecounter_simple_scale( tc, ( *get )( tc ) );
281
282 _Timecounter_Tick_simple( tc->binary_interval, current, &lock_context );
283}
284
294static inline uint32_t rtems_timecounter_simple_downcounter_get(
295 struct timecounter *tc_base,
298)
299{
301 uint32_t counter;
302 uint32_t interval;
303
304 tc = (rtems_timecounter_simple *) tc_base;
305 counter = ( *get )( tc );
306 interval = tc->real_interval;
307
308 if ( ( *is_pending )( tc ) ) {
309 counter = ( *get )( tc );
310 interval *= 2;
311 }
312
313 return rtems_timecounter_simple_scale( tc, interval - counter );
314}
315
325static inline uint32_t rtems_timecounter_simple_upcounter_get(
326 struct timecounter *tc_base,
329)
330{
332 uint32_t counter;
333 uint32_t interval;
334
335 tc = (rtems_timecounter_simple *) tc_base;
336 counter = ( *get )( tc );
337 interval = 0;
338
339 if ( ( *is_pending )( tc ) ) {
340 counter = ( *get )( tc );
341 interval = tc->real_interval;
342 }
343
344 return rtems_timecounter_simple_scale( tc, interval + counter );
345}
346
349#ifdef __cplusplus
350}
351#endif /* __cplusplus */
352
353#endif /* _RTEMS_TIMECOUNTER_H */
This header file provides basic definitions used by the API and the implementation.
void rtems_timecounter_simple_install(rtems_timecounter_simple *tc, uint32_t counter_frequency_in_hz, uint32_t counter_ticks_per_clock_tick, timecounter_get_t *get_timecount)
Initializes and installs a simple timecounter.
Definition: tcsimpleinstall.c:43
void rtems_timecounter_simple_at_tick(rtems_timecounter_simple *tc)
At tick handling done under protection of the timecounter lock.
Definition: timecounter.h:117
bool rtems_timecounter_simple_is_pending(rtems_timecounter_simple *tc)
Returns true if the interrupt of a simple timecounter is pending, and false otherwise.
Definition: timecounter.h:132
uint32_t rtems_timecounter_simple_get(rtems_timecounter_simple *tc)
Returns the current value of a simple timecounter.
Definition: timecounter.h:124
void _Timecounter_Tick(void)
Performs a timecounter tick.
void _Timecounter_Tick_simple(uint32_t delta, uint32_t offset, ISR_lock_Context *lock_context)
Performs a simple timecounter tick.
void _Timecounter_Install(struct timecounter *tc)
Installs the timecounter.
#define _Timecounter_Acquire(lock_context)
Lock to protect the timecounter mechanic.
Definition: timecounter.h:215
This header file provides interfaces of the Timecounter Handler which are used by the implementation ...
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:81
Simple timecounter to support legacy clock drivers.
Definition: timecounter.h:107
Definition: timetc.h:60