[ac7d5ef0] | 1 | /* Timer_init() |
---|
| 2 | * |
---|
| 3 | * This routine initializes the Tick Timer 1 on the MVME162 board. |
---|
| 4 | * |
---|
| 5 | * Input parameters: NONE |
---|
| 6 | * |
---|
| 7 | * Output parameters: NONE |
---|
| 8 | * |
---|
| 9 | * NOTE: This routine will not work if the optimizer is enabled |
---|
| 10 | * for some compilers. The multiple writes |
---|
| 11 | * may be optimized away. |
---|
| 12 | * |
---|
| 13 | * It is important that the timer start/stop overhead be |
---|
| 14 | * determined when porting or modifying this code. |
---|
| 15 | * |
---|
[08311cc3] | 16 | * COPYRIGHT (c) 1989-1999. |
---|
[ac7d5ef0] | 17 | * On-Line Applications Research Corporation (OAR). |
---|
| 18 | * |
---|
[98e4ebf5] | 19 | * The license and distribution terms for this file may be |
---|
| 20 | * found in the file LICENSE in this distribution or at |
---|
[f4fe0092] | 21 | * http://www.rtems.com/license/LICENSE. |
---|
[ac7d5ef0] | 22 | * |
---|
| 23 | * Modifications of respective RTEMS file: COPYRIGHT (c) 1994. |
---|
| 24 | * EISCAT Scientific Association. M.Savitski |
---|
| 25 | * |
---|
| 26 | * This material is a part of the MVME162 Board Support Package |
---|
| 27 | * for the RTEMS executive. Its licensing policies are those of the |
---|
| 28 | * RTEMS above. |
---|
| 29 | * |
---|
| 30 | * $Id$ |
---|
| 31 | */ |
---|
| 32 | |
---|
| 33 | #include <rtems.h> |
---|
| 34 | #include <bsp.h> |
---|
| 35 | |
---|
| 36 | /* Periodic tick interval */ |
---|
[c6fb8e90] | 37 | #define TICK_INTERVAL 0x10000U |
---|
| 38 | #define TIMER_INT_LEVEL 6 |
---|
[ac7d5ef0] | 39 | |
---|
[c6fb8e90] | 40 | rtems_unsigned32 Ttimer_val; |
---|
| 41 | rtems_boolean Timer_driver_Find_average_overhead; |
---|
[ac7d5ef0] | 42 | |
---|
| 43 | rtems_isr timerisr(); |
---|
| 44 | |
---|
| 45 | void Timer_initialize() |
---|
| 46 | { |
---|
[c6fb8e90] | 47 | (void) set_vector( timerisr, VBR0 * 0x10 + 0x8, 0 ); |
---|
| 48 | |
---|
| 49 | Ttimer_val = 0; /* clear timer ISR count */ |
---|
| 50 | lcsr->vector_base |= MASK_INT; /* unmask VMEchip2 interrupts */ |
---|
| 51 | lcsr->intr_clear |= 0x01000000; /* clear pending interrupt */ |
---|
[ac7d5ef0] | 52 | lcsr->to_ctl = 0xE7; /* prescaler to 1 MHz (see Appendix A1) */ |
---|
| 53 | lcsr->timer_cmp_1 = TICK_INTERVAL; |
---|
[c6fb8e90] | 54 | lcsr->timer_cnt_1 = 0; /* clear counter */ |
---|
| 55 | lcsr->board_ctl |= 7; /* increment, reset-on-compare, */ |
---|
| 56 | /* and clear-overflow-cnt */ |
---|
[ac7d5ef0] | 57 | |
---|
[c6fb8e90] | 58 | lcsr->intr_level[0] |= TIMER_INT_LEVEL; /* set int level */ |
---|
| 59 | lcsr->intr_ena |= 0x01000000; /* enable tick timer 1 interrupt */ |
---|
[ac7d5ef0] | 60 | } |
---|
| 61 | |
---|
[c6fb8e90] | 62 | #define AVG_OVERHEAD 3U /* It typically takes 3.0 microseconds */ |
---|
| 63 | /* (3 countdowns) to start/stop the timer. */ |
---|
| 64 | #define LEAST_VALID 10U /* Don't trust a value lower than this */ |
---|
[ac7d5ef0] | 65 | |
---|
[c6fb8e90] | 66 | int Read_timer() |
---|
[ac7d5ef0] | 67 | { |
---|
[c6fb8e90] | 68 | rtems_unsigned32 total; |
---|
[ac7d5ef0] | 69 | |
---|
| 70 | total = (Ttimer_val * TICK_INTERVAL) + lcsr->timer_cnt_1; |
---|
| 71 | |
---|
| 72 | if ( Timer_driver_Find_average_overhead == 1 ) |
---|
| 73 | return total; /* in one-half microsecond units */ |
---|
| 74 | |
---|
| 75 | if ( total < LEAST_VALID ) |
---|
| 76 | return 0; /* below timer resolution */ |
---|
| 77 | |
---|
[c6fb8e90] | 78 | return (total-AVG_OVERHEAD) >> 1; |
---|
[ac7d5ef0] | 79 | } |
---|
| 80 | |
---|
[c6fb8e90] | 81 | |
---|
[ac7d5ef0] | 82 | rtems_status_code Empty_function( void ) |
---|
| 83 | { |
---|
| 84 | return RTEMS_SUCCESSFUL; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | void Set_find_average_overhead( |
---|
| 88 | rtems_boolean find_flag |
---|
| 89 | ) |
---|
| 90 | { |
---|
| 91 | Timer_driver_Find_average_overhead = find_flag; |
---|
| 92 | } |
---|