![]() |
|
|||
File indexing completed on 2025-05-11 08:23:50
0001 /* SPDX-License-Identifier: BSD-2-Clause */ 0002 0003 /* 0004 * This file implements a benchmark timer using a TX39 timer. 0005 * 0006 * NOTE: On the simulator, the count directly reflects instructions. 0007 * 0008 * COPYRIGHT (c) 1989-2000. 0009 * On-Line Applications Research Corporation (OAR). 0010 * 0011 * Redistribution and use in source and binary forms, with or without 0012 * modification, are permitted provided that the following conditions 0013 * are met: 0014 * 1. Redistributions of source code must retain the above copyright 0015 * notice, this list of conditions and the following disclaimer. 0016 * 2. Redistributions in binary form must reproduce the above copyright 0017 * notice, this list of conditions and the following disclaimer in the 0018 * documentation and/or other materials provided with the distribution. 0019 * 0020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0021 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0022 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0023 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0024 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0025 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0026 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0029 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0030 * POSSIBILITY OF SUCH DAMAGE. 0031 */ 0032 0033 #include <assert.h> 0034 0035 #include <bsp.h> 0036 #include <rtems/btimer.h> 0037 0038 bool benchmark_timer_find_average_overhead; 0039 0040 void benchmark_timer_initialize(void) 0041 { 0042 /* 0043 * Programming the compare register as the maximum value should let 0044 * it run long enough and accurate enough not to require an interrupt. 0045 * but if it ever does generate an interrupt, we will simply fault. 0046 * 0047 * NOTE: This is similar to the clock driver initialization 0048 * with the exception that the divider is disabled and 0049 * the compare register is set to the maximum value. 0050 */ 0051 0052 TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TCR, 0x20 ); 0053 TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_CCDR, 0x3 ); 0054 TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TRR, 0x0 ); 0055 TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_CPRA, 0xFFFFFFFF ); 0056 TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TISR, 0x00 ); 0057 TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_ITMR, 0x0001 ); 0058 TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TCR, 0xe0 ); 0059 } 0060 0061 #define AVG_OVERHEAD 0 /* It typically takes N instructions */ 0062 /* to start/stop the timer. */ 0063 #define LEAST_VALID 1 /* Don't trust a value lower than this */ 0064 /* tx39 simulator can count instructions. :) */ 0065 0066 benchmark_timer_t benchmark_timer_read(void) 0067 { 0068 uint32_t total; 0069 0070 total = TX3904_TIMER_READ( TX3904_TIMER1_BASE, TX3904_TIMER_TRR ); 0071 0072 if ( benchmark_timer_find_average_overhead == true ) 0073 return total; /* in one microsecond units */ 0074 0075 if ( total < LEAST_VALID ) 0076 return 0; /* below timer resolution */ 0077 0078 return total - AVG_OVERHEAD; 0079 } 0080 0081 void benchmark_timer_disable_subtracting_average_overhead( 0082 bool find_flag 0083 ) 0084 { 0085 benchmark_timer_find_average_overhead = find_flag; 0086 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |