RTEMS  5.0.0
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 
27 #include <rtems/score/basedefs.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif /* __cplusplus */
32 
45 #define RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER 100
46 
72  struct timecounter *tc
73 )
74 {
76 }
77 
82 {
84 }
85 
89 typedef struct {
90  struct timecounter tc;
91  uint64_t scaler;
92  uint32_t real_interval;
93  uint32_t binary_interval;
95 
101 );
102 
108 );
109 
116 );
117 
191  uint32_t counter_frequency_in_hz,
192  uint32_t counter_ticks_per_clock_tick,
193  timecounter_get_t *get_timecount
194 );
195 
205  const rtems_timecounter_simple *tc,
206  uint32_t value
207 )
208 {
209  return (uint32_t) ( ( value * tc->scaler ) >> 32 );
210 }
211 
224 )
225 {
226  ISR_lock_Context lock_context;
227  uint32_t current;
228 
229  _Timecounter_Acquire( &lock_context );
230 
231  ( *at_tick )( tc );
232 
234  tc,
235  tc->real_interval - ( *get )( tc )
236  );
237 
238  _Timecounter_Tick_simple( tc->binary_interval, current, &lock_context );
239 }
240 
253 )
254 {
255  ISR_lock_Context lock_context;
256  uint32_t current;
257 
258  _Timecounter_Acquire( &lock_context );
259 
260  ( *at_tick )( tc );
261 
262  current = rtems_timecounter_simple_scale( tc, ( *get )( tc ) );
263 
264  _Timecounter_Tick_simple( tc->binary_interval, current, &lock_context );
265 }
266 
277  struct timecounter *tc_base,
280 )
281 {
283  uint32_t counter;
284  uint32_t interval;
285 
286  tc = (rtems_timecounter_simple *) tc_base;
287  counter = ( *get )( tc );
288  interval = tc->real_interval;
289 
290  if ( ( *is_pending )( tc ) ) {
291  counter = ( *get )( tc );
292  interval *= 2;
293  }
294 
295  return rtems_timecounter_simple_scale( tc, interval - counter );
296 }
297 
308  struct timecounter *tc_base,
311 )
312 {
314  uint32_t counter;
315  uint32_t interval;
316 
317  tc = (rtems_timecounter_simple *) tc_base;
318  counter = ( *get )( tc );
319  interval = 0;
320 
321  if ( ( *is_pending )( tc ) ) {
322  counter = ( *get )( tc );
323  interval = tc->real_interval;
324  }
325 
326  return rtems_timecounter_simple_scale( tc, interval + counter );
327 }
328 
331 #ifdef __cplusplus
332 }
333 #endif /* __cplusplus */
334 
335 #endif /* _RTEMS_TIMECOUNTER_H */
void _Timecounter_Tick(void)
Performs a timecounter tick.
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:307
void _Timecounter_Install(struct timecounter *tc)
Installs the timecounter.
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:65
#define _Timecounter_Acquire(lock_context)
Lock to protect the timecounter mechanic.
Definition: timecounter.h:199
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:204
void rtems_timecounter_simple_at_tick(rtems_timecounter_simple *tc)
At tick handling done under protection of the timecounter lock.
Definition: timecounter.h:99
RTEMS_INLINE_ROUTINE void rtems_timecounter_tick(void)
Performs a timecounter tick.
Definition: timecounter.h:81
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:114
RTEMS_INLINE_ROUTINE void rtems_timecounter_install(struct timecounter *tc)
Installs the timecounter.
Definition: timecounter.h:71
Definition: timetc.h:46
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_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:220
uint32_t rtems_timecounter_simple_get(rtems_timecounter_simple *tc)
Returns the current value of a simple timecounter.
Definition: timecounter.h:106
Basic Definitions.
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:249
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
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:276
void _Timecounter_Tick_simple(uint32_t delta, uint32_t offset, ISR_lock_Context *lock_context)
Performs a simple timecounter tick.
Timecounter API.
Simple timecounter to support legacy clock drivers.
Definition: timecounter.h:89