File indexing completed on 2025-05-11 08:23:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include <rtems.h>
0018 #include <rtems/btimer.h>
0019 #include <bsp/generic_or1k.h>
0020 #include <rtems/score/or1k-utility.h>
0021
0022 #define OR1K_NANOSECONDS_PER_CLK_CYCLE 10
0023
0024 static bool benchmark_timer_find_average_overhead = false;
0025 static uint64_t benchmark_timer_base;
0026
0027 void benchmark_timer_initialize(void)
0028 {
0029 benchmark_timer_base = _OR1K_mfspr(CPU_OR1K_SPR_TTCR);
0030 }
0031
0032 #define AVG_OVERHEAD 0
0033 #define LEAST_VALID 1
0034
0035 benchmark_timer_t benchmark_timer_read( void )
0036 {
0037 uint64_t clicks;
0038 uint64_t total;
0039 uint64_t delta;
0040
0041
0042
0043
0044 clicks = _OR1K_mfspr(CPU_OR1K_SPR_TTCR);
0045
0046 delta = clicks - benchmark_timer_base;
0047
0048
0049 total = OR1K_NANOSECONDS_PER_CLK_CYCLE * (delta);
0050
0051 if ( benchmark_timer_find_average_overhead == true )
0052 return total;
0053 else {
0054 if ( total < LEAST_VALID )
0055 return 0;
0056
0057 return (total - AVG_OVERHEAD);
0058 }
0059 }
0060
0061 void benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
0062 {
0063 benchmark_timer_find_average_overhead = find_flag;
0064 }