File indexing completed on 2025-05-11 08:24:08
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 #include <bsp.h>
0028 #include <rtems/btimer.h>
0029
0030 bool benchmark_timer_find_average_overhead;
0031
0032 bool benchmark_timer_is_initialized = false;
0033
0034 void benchmark_timer_initialize(void)
0035 {
0036
0037
0038
0039
0040 if ( benchmark_timer_is_initialized == false ) {
0041
0042
0043 LEON_REG.Timer_Counter_2 = 0xffffff;
0044 LEON_REG.Timer_Reload_2 = 0xffffff;
0045
0046 } else {
0047 benchmark_timer_is_initialized = true;
0048 }
0049
0050 LEON_REG.Timer_Control_2 = (
0051 LEON_REG_TIMER_COUNTER_ENABLE_COUNTING |
0052 LEON_REG_TIMER_COUNTER_LOAD_COUNTER
0053 );
0054
0055 }
0056
0057 #define AVG_OVERHEAD 3
0058
0059 #define LEAST_VALID 2
0060
0061 benchmark_timer_t benchmark_timer_read(void)
0062 {
0063 uint32_t total;
0064
0065 total = LEON_REG.Timer_Counter_2;
0066
0067 total = 0xffffff - total;
0068
0069 if ( benchmark_timer_find_average_overhead == true )
0070 return total;
0071
0072 if ( total < LEAST_VALID )
0073 return 0;
0074
0075 return total - AVG_OVERHEAD;
0076 }
0077
0078 void benchmark_timer_disable_subtracting_average_overhead(
0079 bool find_flag
0080 )
0081 {
0082 benchmark_timer_find_average_overhead = find_flag;
0083 }