source: rtems/cpukit/sapi/src/tcsimpleinstall.c @ 599d71f

Last change on this file since 599d71f was 31be416, checked in by Alexander Krutwig <alexander.krutwig@…>, on Apr 20, 2015 at 9:08:22 AM

timecounter: Port to RTEMS

New test sptests/timecounter01.

Update #2271.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/*
2 * Copyright (c) 2015 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#if HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include <rtems/timecounter.h>
20
21void rtems_timecounter_simple_install(
22  rtems_timecounter_simple *tc,
23  uint32_t                  frequency_in_hz,
24  uint32_t                  counter_ticks_per_clock_tick,
25  timecounter_get_t        *get_timecount
26)
27{
28  uint32_t power_of_two = 1;
29  uint32_t mask;
30  uint64_t scaler;
31  int i;
32
33  for ( i = 0; i < 32; ++i ) {
34    if ( power_of_two >= counter_ticks_per_clock_tick ) {
35      break;
36    }
37
38    power_of_two *= 2;
39  }
40
41  mask = ( 2 * power_of_two ) - 1;
42  scaler = ( (uint64_t) power_of_two << 32 ) / counter_ticks_per_clock_tick;
43
44  tc->scaler = scaler;
45  tc->real_interval = counter_ticks_per_clock_tick;
46  tc->binary_interval = ( mask + 1 ) / 2;
47  tc->tc.tc_get_timecount = get_timecount;
48  tc->tc.tc_counter_mask = mask;
49  tc->tc.tc_frequency = (uint32_t) ( ( frequency_in_hz * scaler ) >> 32 );
50  tc->tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
51  _Timecounter_Install( &tc->tc );
52}
Note: See TracBrowser for help on using the repository browser.