Ignore:
Timestamp:
Nov 30, 2018, 12:57:04 PM (11 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
577d9a5
Parents:
d0a7f03
git-author:
Sebastian Huber <sebastian.huber@…> (11/30/18 12:57:04)
git-committer:
Sebastian Huber <sebastian.huber@…> (12/03/18 08:45:37)
Message:

Convert CPU counter ticks to/from sbintime_t

The sbintime_t is an efficient time format. Add the ability to convert
CPU counter ticks to/from sbintime_t.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/sapi/src/cpucounterconverter.c

    rd0a7f03 rb9ffb624  
    2222static uint64_t from_ns_scaler;
    2323
    24 uint64_t rtems_counter_ticks_to_nanoseconds( rtems_counter_ticks counter )
     24static uint64_t to_sbt_scaler;
     25
     26static uint64_t from_sbt_scaler;
     27
     28uint64_t rtems_counter_ticks_to_nanoseconds( rtems_counter_ticks ticks )
    2529{
    26   return (uint32_t) ((counter * to_ns_scaler) >> 32);
     30  return (uint32_t) ((ticks * to_ns_scaler) >> 32);
    2731}
    2832
     
    3236}
    3337
     38int64_t rtems_counter_ticks_to_sbintime( rtems_counter_ticks ticks )
     39{
     40  return (int64_t) ((ticks * to_sbt_scaler) >> 31);
     41}
     42
     43rtems_counter_ticks rtems_counter_sbintime_to_ticks( int64_t sbt )
     44{
     45  return (rtems_counter_ticks) (((uint64_t) sbt * from_sbt_scaler) >> 31);
     46}
     47
    3448void rtems_counter_initialize_converter( uint32_t frequency )
    3549{
    3650  uint64_t ns_per_s = UINT64_C(1000000000);
     51  uint64_t bin_per_s = UINT64_C(1) << 32;
    3752
    3853  to_ns_scaler = ((ns_per_s << 32) + frequency - 1) / frequency;
    3954  from_ns_scaler = ((UINT64_C(1) << 32) * frequency + ns_per_s - 1) / ns_per_s;
     55
     56  to_sbt_scaler = ((bin_per_s << 31) + frequency - 1) / frequency;
     57  from_sbt_scaler = ((UINT64_C(1) << 31) * frequency + bin_per_s - 1) / bin_per_s;
    4058}
    4159
Note: See TracChangeset for help on using the changeset viewer.