File indexing completed on 2025-05-11 08:24:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 #include <rtems/counter.h>
0038 #include <rtems/sysinit.h>
0039
0040 RTEMS_STATIC_ASSERT(sizeof(rtems_counter_ticks) <= sizeof(uint32_t), type);
0041
0042 static uint64_t to_ns_scaler;
0043
0044 static uint64_t from_ns_scaler;
0045
0046 static uint64_t to_sbt_scaler;
0047
0048 static uint64_t from_sbt_scaler;
0049
0050 uint64_t rtems_counter_ticks_to_nanoseconds( rtems_counter_ticks ticks )
0051 {
0052 return (uint32_t) ((ticks * to_ns_scaler) >> 32);
0053 }
0054
0055 rtems_counter_ticks rtems_counter_nanoseconds_to_ticks( uint32_t nanoseconds )
0056 {
0057 return (rtems_counter_ticks) ((nanoseconds * from_ns_scaler) >> 32);
0058 }
0059
0060 int64_t rtems_counter_ticks_to_sbintime( rtems_counter_ticks ticks )
0061 {
0062 return (int64_t) ((ticks * to_sbt_scaler) >> 31);
0063 }
0064
0065 rtems_counter_ticks rtems_counter_sbintime_to_ticks( int64_t sbt )
0066 {
0067 return (rtems_counter_ticks) (((uint64_t) sbt * from_sbt_scaler) >> 32);
0068 }
0069
0070 void rtems_counter_initialize_converter( uint32_t frequency )
0071 {
0072 uint64_t ns_per_s = UINT64_C(1000000000);
0073 uint64_t bin_per_s = UINT64_C(1) << 32;
0074 uint64_t bin_freq = (uint64_t) frequency << 32;
0075
0076 to_ns_scaler = ((ns_per_s << 32) + frequency - 1) / frequency;
0077 from_ns_scaler = (bin_freq + ns_per_s - 1) / ns_per_s;
0078
0079 to_sbt_scaler = ((bin_per_s << 31) + frequency - 1) / frequency;
0080 from_sbt_scaler = (bin_freq + bin_per_s - 1) / bin_per_s;
0081 }
0082
0083 static void rtems_counter_sysinit( void )
0084 {
0085 rtems_counter_initialize_converter( rtems_counter_frequency() );
0086 }
0087
0088 RTEMS_SYSINIT_ITEM(
0089 rtems_counter_sysinit,
0090 RTEMS_SYSINIT_CPU_COUNTER,
0091 RTEMS_SYSINIT_ORDER_LAST_BUT_5
0092 );