RTEMS CPU Kit with SuperCore  4.11.3
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 
183  uint32_t frequency_in_hz,
184  uint32_t timecounter_ticks_per_clock_tick,
185  timecounter_get_t *get_timecount
186 );
187 
197  const rtems_timecounter_simple *tc,
198  uint32_t value
199 )
200 {
201  return (uint32_t) ( ( value * tc->scaler ) >> 32 );
202 }
203 
216 )
217 {
218  ISR_lock_Context lock_context;
219  uint32_t current;
220 
221  _Timecounter_Acquire( &lock_context );
222 
223  ( *at_tick )( tc );
224 
226  tc,
227  tc->real_interval - ( *get )( tc )
228  );
229 
230  _Timecounter_Tick_simple( tc->binary_interval, current, &lock_context );
231 }
232 
245 )
246 {
247  ISR_lock_Context lock_context;
248  uint32_t current;
249 
250  _Timecounter_Acquire( &lock_context );
251 
252  ( *at_tick )( tc );
253 
254  current = rtems_timecounter_simple_scale( tc, ( *get )( tc ) );
255 
256  _Timecounter_Tick_simple( tc->binary_interval, current, &lock_context );
257 }
258 
269  struct timecounter *tc_base,
272 )
273 {
275  uint32_t counter;
276  uint32_t interval;
277 
278  tc = (rtems_timecounter_simple *) tc_base;
279  counter = ( *get )( tc );
280  interval = tc->real_interval;
281 
282  if ( ( *is_pending )( tc ) ) {
283  counter = ( *get )( tc );
284  interval *= 2;
285  }
286 
287  return rtems_timecounter_simple_scale( tc, interval - counter );
288 }
289 
300  struct timecounter *tc_base,
303 )
304 {
306  uint32_t counter;
307  uint32_t interval;
308 
309  tc = (rtems_timecounter_simple *) tc_base;
310  counter = ( *get )( tc );
311  interval = 0;
312 
313  if ( ( *is_pending )( tc ) ) {
314  counter = ( *get )( tc );
315  interval = tc->real_interval;
316  }
317 
318  return rtems_timecounter_simple_scale( tc, interval + counter );
319 }
320 
323 #ifdef __cplusplus
324 }
325 #endif /* __cplusplus */
326 
327 #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:299
void _Timecounter_Install(struct timecounter *tc)
Installs the timecounter.
Timecounter API.
#define RTEMS_INLINE_ROUTINE
The following (in conjunction with compiler arguments) are used to choose between the use of static i...
Definition: basedefs.h:135
#define _Timecounter_Acquire(lock_context)
Lock to protect the timecounter mechanic.
Definition: timecounter.h:177
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:196
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:37
void rtems_timecounter_simple_install(rtems_timecounter_simple *tc, uint32_t frequency_in_hz, uint32_t timecounter_ticks_per_clock_tick, timecounter_get_t *get_timecount)
Initializes and installs a simple timecounter.
Definition: tcsimpleinstall.c:22
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:212
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:241
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:268
void _Timecounter_Tick_simple(uint32_t delta, uint32_t offset, ISR_lock_Context *lock_context)
Performs a simple timecounter tick.
Simple timecounter to support legacy clock drivers.
Definition: timecounter.h:89