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

Last change on this file since 599d71f was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/*
2 * Copyright (c) 2014 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#include <rtems/counter.h>
16
17RTEMS_STATIC_ASSERT(sizeof(rtems_counter_ticks) <= sizeof(uint32_t), type);
18
19static uint64_t to_ns_scaler = UINT64_C(1) << 32;
20
21static uint64_t from_ns_scaler = UINT64_C(1) << 32;
22
23uint64_t rtems_counter_ticks_to_nanoseconds( rtems_counter_ticks counter )
24{
25  return (uint32_t) ((counter * to_ns_scaler) >> 32);
26}
27
28rtems_counter_ticks rtems_counter_nanoseconds_to_ticks( uint32_t nanoseconds )
29{
30  return (rtems_counter_ticks) ((nanoseconds * from_ns_scaler) >> 32);
31}
32
33void rtems_counter_initialize_converter( uint32_t frequency )
34{
35  uint64_t ns_per_s = UINT64_C(1000000000);
36
37  to_ns_scaler = ((ns_per_s << 32) + frequency - 1) / frequency;
38  from_ns_scaler = ((UINT64_C(1) << 32) * frequency + ns_per_s - 1) / ns_per_s;
39}
Note: See TracBrowser for help on using the repository browser.