[ac7d5ef0] | 1 | /* Timer_init() |
---|
| 2 | * |
---|
| 3 | * This routine initializes the Z8536 timer on the SQSIO4 SQUALL |
---|
| 4 | * board for the CVME961 board. The timer is setup to provide a |
---|
| 5 | * tick every 1 millisecond. |
---|
| 6 | * |
---|
| 7 | * Input parameters: NONE |
---|
| 8 | * |
---|
| 9 | * Output parameters: NONE |
---|
| 10 | * |
---|
| 11 | * NOTE: This routine will not work if the optimizer is enabled |
---|
| 12 | * for most compilers. The multiple writes to the Z8536 |
---|
| 13 | * will be optimized away. |
---|
| 14 | * |
---|
| 15 | * It is important that the timer start/stop overhead be |
---|
| 16 | * determined when porting or modifying this code. |
---|
| 17 | * |
---|
| 18 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
| 19 | * On-Line Applications Research Corporation (OAR). |
---|
| 20 | * All rights assigned to U.S. Government, 1994. |
---|
| 21 | * |
---|
| 22 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
| 23 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
| 24 | * notice must appear in all copies of this file and its derivatives. |
---|
| 25 | * |
---|
| 26 | * $Id$ |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | #include <rtems.h> |
---|
| 31 | #include <bsp.h> |
---|
| 32 | #include "z8536.h" |
---|
| 33 | |
---|
| 34 | #define TIMER 0xc00000a0 |
---|
| 35 | |
---|
| 36 | int Ttimer_val; |
---|
| 37 | rtems_boolean Timer_driver_Find_average_overhead; |
---|
| 38 | |
---|
| 39 | void flush_reg(); |
---|
| 40 | rtems_isr timerisr(); |
---|
| 41 | |
---|
| 42 | void Timer_initialize() |
---|
| 43 | { |
---|
| 44 | set_vector( timerisr, 4, 0 ); /* install ISR */ |
---|
| 45 | |
---|
| 46 | i960_mask_intr( 5 ); /* disable VIC068 tick */ |
---|
| 47 | flush_reg(); /* timed code starts clean */ |
---|
| 48 | Ttimer_val = 0; /* clear timer ISR count */ |
---|
| 49 | Z8x36_WRITE( TIMER, MASTER_INTR, 0x01 ); /* reset */ |
---|
| 50 | Z8x36_WRITE( TIMER, MASTER_INTR, 0x00 ); /* clear reset */ |
---|
| 51 | Z8x36_WRITE( TIMER, MASTER_CFG, 0x00 ); /* disable everything */ |
---|
| 52 | Z8x36_WRITE( TIMER, CNT_TMR_VECTOR, 0x72 ); /* clear intr vector */ |
---|
| 53 | Z8x36_WRITE( TIMER, MASTER_CFG, 0x20 ); /* clear intr info */ |
---|
| 54 | Z8x36_WRITE( TIMER, MASTER_CFG, 0xe0 ); /* disable interrupts */ |
---|
| 55 | Z8x36_WRITE( TIMER, MASTER_CFG, 0x20 ); /* clear intr info */ |
---|
| 56 | Z8x36_WRITE( TIMER, MASTER_CFG, 0xe0 ); /* disable interrupts */ |
---|
| 57 | Z8x36_WRITE( TIMER, MASTER_INTR, 0xe2 ); /* disable lower chain, */ |
---|
| 58 | /* no vector, set right */ |
---|
| 59 | /* justified addr and */ |
---|
| 60 | /* master int enable */ |
---|
| 61 | Z8x36_WRITE( TIMER, CT1_MODE_SPEC, 0x80 ); /* T1 continuous, and */ |
---|
| 62 | /* cycle/pulse output */ |
---|
| 63 | Z8x36_WRITE( TIMER, CT1_TIME_CONST_MSB, 0x00 ); |
---|
| 64 | Z8x36_WRITE( TIMER, CT1_TIME_CONST_LSB, 0x00 ); |
---|
| 65 | Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0xc0 ); /* set INTR enable (IE) */ |
---|
| 66 | Z8x36_WRITE( TIMER, MASTER_CFG, 0x40 ); /* enable timer1 */ |
---|
| 67 | Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0x06 ); /* set trigger command */ |
---|
| 68 | /* (TCB) and gate */ |
---|
| 69 | /* command (GCB) bits */ |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | #define AVG_OVERHEAD 11 /* It typically takes 5.5 microseconds */ |
---|
| 73 | /* (11 countdowns) to start/stop the timer. */ |
---|
| 74 | #define LEAST_VALID 15 /* Don't trust a value lower than this */ |
---|
| 75 | |
---|
| 76 | int Read_timer() |
---|
| 77 | { |
---|
| 78 | rtems_unsigned8 msb, lsb; |
---|
| 79 | rtems_unsigned32 remaining, total; |
---|
| 80 | |
---|
| 81 | Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0xce ); /* read the counter value */ |
---|
| 82 | Z8x36_READ( TIMER, CT1_CUR_CNT_MSB, msb ); |
---|
| 83 | Z8x36_READ( TIMER, CT1_CUR_CNT_LSB, lsb ); |
---|
| 84 | |
---|
| 85 | remaining = 0xffff - ((msb << 8) + lsb); |
---|
| 86 | total = (Ttimer_val * 0x10000) + remaining; |
---|
| 87 | |
---|
| 88 | if ( Timer_driver_Find_average_overhead == 1 ) |
---|
| 89 | return total; /* in one-half microsecond units */ |
---|
| 90 | else { |
---|
| 91 | if ( total < LEAST_VALID ) |
---|
| 92 | return 0; /* below timer resolution */ |
---|
| 93 | return (total-AVG_OVERHEAD) >> 1; |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | rtems_status_code Empty_function( void ) |
---|
| 98 | { |
---|
| 99 | return RTEMS_SUCCESSFUL; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | void Set_find_average_overhead( |
---|
| 103 | rtems_boolean find_flag |
---|
| 104 | ) |
---|
| 105 | { |
---|
| 106 | Timer_driver_Find_average_overhead = find_flag; |
---|
| 107 | } |
---|