1 | /* |
---|
2 | * This routine initializes the Tick Timer 1 on the MVME162 board. |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-1999. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.org/license/LICENSE. |
---|
10 | * |
---|
11 | * Modifications of respective RTEMS file: COPYRIGHT (c) 1994. |
---|
12 | * EISCAT Scientific Association. M.Savitski |
---|
13 | * |
---|
14 | * This material is a part of the MVME162 Board Support Package |
---|
15 | * for the RTEMS executive. Its licensing policies are those of the |
---|
16 | * RTEMS above. |
---|
17 | */ |
---|
18 | |
---|
19 | #include <rtems.h> |
---|
20 | #include <rtems/btimer.h> |
---|
21 | #include <bsp.h> |
---|
22 | |
---|
23 | /* Periodic tick interval */ |
---|
24 | #define TICK_INTERVAL 0x10000U |
---|
25 | #define TIMER_INT_LEVEL 6 |
---|
26 | |
---|
27 | uint32_t Ttimer_val; |
---|
28 | bool benchmark_timer_find_average_overhead; |
---|
29 | |
---|
30 | rtems_isr timerisr(void); |
---|
31 | |
---|
32 | void benchmark_timer_initialize(void) |
---|
33 | { |
---|
34 | (void) set_vector( timerisr, VBR0 * 0x10 + 0x8, 0 ); |
---|
35 | |
---|
36 | Ttimer_val = 0; /* clear timer ISR count */ |
---|
37 | lcsr->vector_base |= MASK_INT; /* unmask VMEchip2 interrupts */ |
---|
38 | lcsr->intr_clear |= 0x01000000; /* clear pending interrupt */ |
---|
39 | lcsr->to_ctl = 0xE7; /* prescaler to 1 MHz (see Appendix A1) */ |
---|
40 | lcsr->timer_cmp_1 = TICK_INTERVAL; |
---|
41 | lcsr->timer_cnt_1 = 0; /* clear counter */ |
---|
42 | lcsr->board_ctl |= 7; /* increment, reset-on-compare, */ |
---|
43 | /* and clear-overflow-cnt */ |
---|
44 | |
---|
45 | lcsr->intr_level[0] |= TIMER_INT_LEVEL; /* set int level */ |
---|
46 | lcsr->intr_ena |= 0x01000000; /* enable tick timer 1 interrupt */ |
---|
47 | } |
---|
48 | |
---|
49 | #define AVG_OVERHEAD 3U /* It typically takes 3.0 microseconds */ |
---|
50 | /* (3 countdowns) to start/stop the timer. */ |
---|
51 | #define LEAST_VALID 10U /* Don't trust a value lower than this */ |
---|
52 | |
---|
53 | uint32_t benchmark_timer_read(void) |
---|
54 | { |
---|
55 | uint32_t total; |
---|
56 | |
---|
57 | total = (Ttimer_val * TICK_INTERVAL) + lcsr->timer_cnt_1; |
---|
58 | |
---|
59 | if ( benchmark_timer_find_average_overhead == true ) |
---|
60 | return total; /* in one-half microsecond units */ |
---|
61 | |
---|
62 | if ( total < LEAST_VALID ) |
---|
63 | return 0; /* below timer resolution */ |
---|
64 | |
---|
65 | return (total-AVG_OVERHEAD) >> 1; |
---|
66 | } |
---|
67 | |
---|
68 | void benchmark_timer_disable_subtracting_average_overhead( |
---|
69 | bool find_flag |
---|
70 | ) |
---|
71 | { |
---|
72 | benchmark_timer_find_average_overhead = find_flag; |
---|
73 | } |
---|