Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:48

0001 /*
0002  *  This routine initializes the Tick Timer 1 on the MVME162 board.
0003  *
0004  *  COPYRIGHT (c) 1989-1999.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  *  The license and distribution terms for this file may be
0008  *  found in the file LICENSE in this distribution or at
0009  *  http://www.rtems.org/license/LICENSE.
0010  *
0011  *  Modifications of respective RTEMS file: COPYRIGHT (c) 1994.
0012  *  EISCAT Scientific Association. M.Savitski
0013  *
0014  *  This material is a part of the MVME162 Board Support Package
0015  *  for the RTEMS executive. Its licensing policies are those of the
0016  *  RTEMS above.
0017  */
0018 
0019 #include <rtems.h>
0020 #include <rtems/btimer.h>
0021 #include <bsp.h>
0022 
0023 /* Periodic tick interval */
0024 #define TICK_INTERVAL         0x10000U
0025 #define TIMER_INT_LEVEL       6
0026 
0027 uint32_t            Ttimer_val;
0028 bool                benchmark_timer_find_average_overhead;
0029 
0030 rtems_isr timerisr(rtems_vector_number vector);
0031 
0032 void benchmark_timer_initialize(void)
0033 {
0034   (void) set_vector( timerisr, VBR0 * 0x10 + 0x8, 0 );
0035 
0036   Ttimer_val = 0;                     /* clear timer ISR count */
0037   lcsr->vector_base |= MASK_INT;      /* unmask VMEchip2 interrupts */
0038   lcsr->intr_clear |= 0x01000000;     /* clear pending interrupt */
0039   lcsr->to_ctl = 0xE7;                /* prescaler to 1 MHz (see Appendix A1) */
0040   lcsr->timer_cmp_1 = TICK_INTERVAL;
0041   lcsr->timer_cnt_1 = 0;              /* clear counter */
0042   lcsr->board_ctl |= 7;               /* increment, reset-on-compare, */
0043                                       /*   and clear-overflow-cnt */
0044 
0045   lcsr->intr_level[0] |= TIMER_INT_LEVEL; /* set int level */
0046   lcsr->intr_ena |= 0x01000000;           /* enable tick timer 1 interrupt */
0047 }
0048 
0049 #define AVG_OVERHEAD      3U    /* It typically takes 3.0 microseconds */
0050                                 /* (3 countdowns) to start/stop the timer. */
0051 #define LEAST_VALID       10U   /* Don't trust a value lower than this */
0052 
0053 benchmark_timer_t benchmark_timer_read(void)
0054 {
0055   uint32_t            total;
0056 
0057   total = (Ttimer_val * TICK_INTERVAL) + lcsr->timer_cnt_1;
0058 
0059   if ( benchmark_timer_find_average_overhead == true )
0060     return total;          /* in one-half microsecond units */
0061 
0062   if ( total < LEAST_VALID )
0063     return 0;            /* below timer resolution */
0064 
0065   return (total-AVG_OVERHEAD) >> 1;
0066 }
0067 
0068 void benchmark_timer_disable_subtracting_average_overhead(
0069   bool find_flag
0070 )
0071 {
0072   benchmark_timer_find_average_overhead = find_flag;
0073 }