source: rtems/cpukit/sapi/src/cpucounterconverter.c @ 65f868c

5
Last change on this file since 65f868c was 65f868c, checked in by Sebastian Huber <sebastian.huber@…>, on 05/23/18 at 12:17:25

Add _CPU_Counter_frequency()

Add rtems_counter_frequency() API function. Use it to initialize the
counter value converter via the new system initialization step
(RTEMS_SYSINIT_CPU_COUNTER). This decouples the counter implementation
and the counter converter. It avoids an unnecessary pull in of the
64-bit integer division from libgcc.

Update #3456.

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[24bf11e]1/*
[65f868c]2 * Copyright (c) 2014, 2018 embedded brains GmbH.  All rights reserved.
[24bf11e]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
[c499856]12 * http://www.rtems.org/license/LICENSE.
[24bf11e]13 */
14
15#include <rtems/counter.h>
[65f868c]16#include <rtems/sysinit.h>
[24bf11e]17
18RTEMS_STATIC_ASSERT(sizeof(rtems_counter_ticks) <= sizeof(uint32_t), type);
19
[65f868c]20static uint64_t to_ns_scaler;
[24bf11e]21
[65f868c]22static uint64_t from_ns_scaler;
[24bf11e]23
24uint64_t rtems_counter_ticks_to_nanoseconds( rtems_counter_ticks counter )
25{
26  return (uint32_t) ((counter * to_ns_scaler) >> 32);
27}
28
29rtems_counter_ticks rtems_counter_nanoseconds_to_ticks( uint32_t nanoseconds )
30{
31  return (rtems_counter_ticks) ((nanoseconds * from_ns_scaler) >> 32);
32}
33
34void rtems_counter_initialize_converter( uint32_t frequency )
35{
36  uint64_t ns_per_s = UINT64_C(1000000000);
37
38  to_ns_scaler = ((ns_per_s << 32) + frequency - 1) / frequency;
39  from_ns_scaler = ((UINT64_C(1) << 32) * frequency + ns_per_s - 1) / ns_per_s;
40}
[65f868c]41
42static void rtems_counter_sysinit( void )
43{
44  rtems_counter_initialize_converter( rtems_counter_frequency() );
45}
46
47RTEMS_SYSINIT_ITEM(
48  rtems_counter_sysinit,
49  RTEMS_SYSINIT_CPU_COUNTER,
50  RTEMS_SYSINIT_ORDER_LAST
51);
Note: See TracBrowser for help on using the repository browser.