RTEMS: cpukit/include/rtems/timecounter.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
timecounter.h
Go to the documentation of this file.
1
9/*
10 * Copyright (c) 2015 embedded brains GmbH. All rights reserved.
11 *
12 * embedded brains GmbH
13 * Dornierstr. 4
14 * 82178 Puchheim
15 * Germany
16 * <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 */
22
23#ifndef _RTEMS_TIMECOUNTER_H
24#define _RTEMS_TIMECOUNTER_H
25
26#include <rtems/score/timecounter.h>
27#include <rtems/score/basedefs.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif /* __cplusplus */
32
47#define RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER 100
48
73 RTEMS_INLINE_ROUTINE void rtems_timecounter_install(
74 struct timecounter *tc
75)
76{
77 _Timecounter_Install( tc );
78}
79
83 RTEMS_INLINE_ROUTINE void rtems_timecounter_tick(void)
84{
85 _Timecounter_Tick();
86}
87
91 typedef struct {
92 struct timecounter tc;
93 uint64_t scaler;
94 uint32_t real_interval;
95 uint32_t binary_interval;
96} rtems_timecounter_simple;
97
101 typedef void rtems_timecounter_simple_at_tick(
102 rtems_timecounter_simple *tc
103);
104
108 typedef uint32_t rtems_timecounter_simple_get(
109 rtems_timecounter_simple *tc
110);
111
116 typedef bool rtems_timecounter_simple_is_pending(
117 rtems_timecounter_simple *tc
118);
119
191void rtems_timecounter_simple_install(
192 rtems_timecounter_simple *tc,
193 uint32_t counter_frequency_in_hz,
194 uint32_t counter_ticks_per_clock_tick,
195 timecounter_get_t *get_timecount
196);
197
206 RTEMS_INLINE_ROUTINE uint32_t rtems_timecounter_simple_scale(
207 const rtems_timecounter_simple *tc,
208 uint32_t value
209)
210{
211 return (uint32_t) ( ( value * tc->scaler ) >> 32 );
212}
213
222 RTEMS_INLINE_ROUTINE void rtems_timecounter_simple_downcounter_tick(
223 rtems_timecounter_simple *tc,
224 rtems_timecounter_simple_get get,
225 rtems_timecounter_simple_at_tick at_tick
226)
227{
228 ISR_lock_Context lock_context;
229 uint32_t current;
230
231 _Timecounter_Acquire( &lock_context );
232
233 ( *at_tick )( tc );
234
235 current = rtems_timecounter_simple_scale(
236 tc,
237 tc->real_interval - ( *get )( tc )
238 );
239
240 _Timecounter_Tick_simple( tc->binary_interval, current, &lock_context );
241}
242
251 RTEMS_INLINE_ROUTINE void rtems_timecounter_simple_upcounter_tick(
252 rtems_timecounter_simple *tc,
253 rtems_timecounter_simple_get get,
254 rtems_timecounter_simple_at_tick at_tick
255)
256{
257 ISR_lock_Context lock_context;
258 uint32_t current;
259
260 _Timecounter_Acquire( &lock_context );
261
262 ( *at_tick )( tc );
263
264 current = rtems_timecounter_simple_scale( tc, ( *get )( tc ) );
265
266 _Timecounter_Tick_simple( tc->binary_interval, current, &lock_context );
267}
268
278 RTEMS_INLINE_ROUTINE uint32_t rtems_timecounter_simple_downcounter_get(
279 struct timecounter *tc_base,
280 rtems_timecounter_simple_get get,
281 rtems_timecounter_simple_is_pending is_pending
282)
283{
284 rtems_timecounter_simple *tc;
285 uint32_t counter;
286 uint32_t interval;
287
288 tc = (rtems_timecounter_simple *) tc_base;
289 counter = ( *get )( tc );
290 interval = tc->real_interval;
291
292 if ( ( *is_pending )( tc ) ) {
293 counter = ( *get )( tc );
294 interval *= 2;
295 }
296
297 return rtems_timecounter_simple_scale( tc, interval - counter );
298}
299
309 RTEMS_INLINE_ROUTINE uint32_t rtems_timecounter_simple_upcounter_get(
310 struct timecounter *tc_base,
311 rtems_timecounter_simple_get get,
312 rtems_timecounter_simple_is_pending is_pending
313)
314{
315 rtems_timecounter_simple *tc;
316 uint32_t counter;
317 uint32_t interval;
318
319 tc = (rtems_timecounter_simple *) tc_base;
320 counter = ( *get )( tc );
321 interval = 0;
322
323 if ( ( *is_pending )( tc ) ) {
324 counter = ( *get )( tc );
325 interval = tc->real_interval;
326 }
327
328 return rtems_timecounter_simple_scale( tc, interval + counter );
329}
330
333#ifdef __cplusplus
334}
335#endif /* __cplusplus */
336
337#endif /* _RTEMS_TIMECOUNTER_H */
basedefs.h
Basic Definitions.
RTEMS_INLINE_ROUTINE
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:66
_Timecounter_Tick
void _Timecounter_Tick(void)
Performs a timecounter tick.
_Timecounter_Tick_simple
void _Timecounter_Tick_simple(uint32_t delta, uint32_t offset, ISR_lock_Context *lock_context)
Performs a simple timecounter tick.
_Timecounter_Install
void _Timecounter_Install(struct timecounter *tc)
Installs the timecounter.
_Timecounter_Acquire
#define _Timecounter_Acquire(lock_context)
Lock to protect the timecounter mechanic.
Definition: timecounter.h:201
rtems_timecounter_tick
RTEMS_INLINE_ROUTINE void rtems_timecounter_tick(void)
Performs a timecounter tick.
Definition: timecounter.h:83
rtems_timecounter_simple_upcounter_get
RTEMS_INLINE_ROUTINE uint32_t rtems_timecounter_simple_upcounter_get(struct timecounter *tc_base, rtems_timecounter_simple_get get, rtems_timecounter_simple_is_pending is_pending)
Gets the simple timecounter value mapped to its binary frequency domain for upcounters.
Definition: timecounter.h:309
rtems_timecounter_simple_scale
RTEMS_INLINE_ROUTINE uint32_t rtems_timecounter_simple_scale(const rtems_timecounter_simple *tc, uint32_t value)
Maps a simple timecounter value into its binary frequency domain.
Definition: timecounter.h:206
rtems_timecounter_simple_upcounter_tick
RTEMS_INLINE_ROUTINE void rtems_timecounter_simple_upcounter_tick(rtems_timecounter_simple *tc, rtems_timecounter_simple_get get, rtems_timecounter_simple_at_tick at_tick)
Performs a simple timecounter tick for upcounters.
Definition: timecounter.h:251
rtems_timecounter_simple_install
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:21
rtems_timecounter_simple_downcounter_get
RTEMS_INLINE_ROUTINE uint32_t rtems_timecounter_simple_downcounter_get(struct timecounter *tc_base, rtems_timecounter_simple_get get, rtems_timecounter_simple_is_pending is_pending)
Gets the simple timecounter value mapped to its binary frequency domain for downcounters.
Definition: timecounter.h:278
rtems_timecounter_simple_at_tick
void rtems_timecounter_simple_at_tick(rtems_timecounter_simple *tc)
At tick handling done under protection of the timecounter lock.
Definition: timecounter.h:101
rtems_timecounter_install
RTEMS_INLINE_ROUTINE void rtems_timecounter_install(struct timecounter *tc)
Installs the timecounter.
Definition: timecounter.h:73
rtems_timecounter_simple_is_pending
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:116
rtems_timecounter_simple_downcounter_tick
RTEMS_INLINE_ROUTINE void rtems_timecounter_simple_downcounter_tick(rtems_timecounter_simple *tc, rtems_timecounter_simple_get get, rtems_timecounter_simple_at_tick at_tick)
Performs a simple timecounter tick for downcounters.
Definition: timecounter.h:222
rtems_timecounter_simple_get
uint32_t rtems_timecounter_simple_get(rtems_timecounter_simple *tc)
Returns the current value of a simple timecounter.
Definition: timecounter.h:108
timecounter.h
Timecounter API.
ISR_lock_Context
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
rtems_timecounter_simple
Simple timecounter to support legacy clock drivers.
Definition: timecounter.h:91
timecounter
Definition: timetc.h:46