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-1997. |
---|
19 | * On-Line Applications Research Corporation (OAR). |
---|
20 | * |
---|
21 | * The license and distribution terms for this file may in |
---|
22 | * the file LICENSE in this distribution or at |
---|
23 | * http://www.OARcorp.com/rtems/license.html. |
---|
24 | * |
---|
25 | * $Id$ |
---|
26 | */ |
---|
27 | |
---|
28 | |
---|
29 | #include <bsp.h> |
---|
30 | #include <stdlib.h> |
---|
31 | #include <rtems/libio.h> |
---|
32 | |
---|
33 | |
---|
34 | #define TIMER_VECTOR 34 |
---|
35 | |
---|
36 | int Ttimer_val; |
---|
37 | rtems_boolean Timer_driver_Find_average_overhead = 0; |
---|
38 | |
---|
39 | void flush_reg(); |
---|
40 | rtems_isr timerisr(); |
---|
41 | |
---|
42 | void Timer_initialize() |
---|
43 | { |
---|
44 | volatile unsigned int *tmr1 = (unsigned int *) TMR1_ADDR; |
---|
45 | volatile unsigned int *trr1 = (unsigned int *) TRR1_ADDR; |
---|
46 | volatile unsigned int *tcr1 = (unsigned int *) TCR1_ADDR; |
---|
47 | volatile unsigned int *imsk = (unsigned int *) IMSK_ADDR; |
---|
48 | volatile unsigned int *icon = (unsigned int *) ICON_ADDR; |
---|
49 | volatile unsigned int *ipnd = (unsigned int *) IPND_ADDR; |
---|
50 | volatile unsigned int *imap2 = (unsigned int *) IMAP2_ADDR; |
---|
51 | |
---|
52 | #define BUS_CLOCK_1 0 |
---|
53 | #define TMR_WRITE_CNTL 8 |
---|
54 | #define TMR_AUTO_RELOAD 4 |
---|
55 | #define TMR_ENABLE 2 |
---|
56 | #define TMR_TERM_CNT_STAT 1 |
---|
57 | |
---|
58 | *tmr1 = BUS_CLOCK_1 | TMR_AUTO_RELOAD; |
---|
59 | *icon = 0x6000; |
---|
60 | |
---|
61 | |
---|
62 | set_vector( (((unsigned int) timerisr) | 0x2), TIMER_VECTOR, 1 ); |
---|
63 | |
---|
64 | *imap2 = (*imap2 & 0xff0fffff) | (((TIMER_VECTOR >> 4) & 0xf) << 20); |
---|
65 | |
---|
66 | /* initialize the i960RP timer 1 here */ |
---|
67 | |
---|
68 | /* set the timer countdown */ |
---|
69 | *trr1 = 33 * BSP_Configuration.microseconds_per_tick; |
---|
70 | *tcr1 = 33 * BSP_Configuration.microseconds_per_tick; |
---|
71 | |
---|
72 | *ipnd &= ~(1<<13); |
---|
73 | *imsk |= (1 << 13); |
---|
74 | Ttimer_val = 0; |
---|
75 | *tmr1 = BUS_CLOCK_1 | TMR_AUTO_RELOAD | TMR_ENABLE; |
---|
76 | |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | |
---|
81 | rtems_isr timerisr( |
---|
82 | rtems_vector_number vector |
---|
83 | ) |
---|
84 | { |
---|
85 | /* enable_tracing(); */ |
---|
86 | Ttimer_val++; |
---|
87 | i960_clear_intr( 13 ); |
---|
88 | } |
---|
89 | |
---|
90 | #define AVG_OVERHEAD 4 /* It typically takes 5.5 microseconds */ |
---|
91 | /* (11 countdowns) to start/stop the timer. */ |
---|
92 | #define LEAST_VALID 5 /* Don't trust a value lower than this */ |
---|
93 | |
---|
94 | int Read_timer() |
---|
95 | { |
---|
96 | volatile unsigned int *tcr1 = (unsigned int *) TCR1_ADDR; |
---|
97 | volatile unsigned int *trr1 = (unsigned int *) TRR1_ADDR; |
---|
98 | rtems_unsigned32 remaining, total; |
---|
99 | |
---|
100 | /* this routine is supposed to count in 1/2 uSec units */ |
---|
101 | /* pretty funny when using a 33MHz clock for the counter */ |
---|
102 | remaining = *tcr1; |
---|
103 | remaining = *trr1 - remaining; |
---|
104 | total = (2 * ((Ttimer_val * *trr1) + remaining)) / 33; |
---|
105 | /* |
---|
106 | putnum(remaining); |
---|
107 | console_sps_putc(':'); |
---|
108 | putnum(total); |
---|
109 | */ |
---|
110 | |
---|
111 | if ( Timer_driver_Find_average_overhead == 1 ) |
---|
112 | return total; /* in one-half microsecond units */ |
---|
113 | else { |
---|
114 | if ( total < LEAST_VALID ) |
---|
115 | return 0; /* below timer resolution */ |
---|
116 | return (total-AVG_OVERHEAD) >> 1; |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | rtems_status_code Empty_function( void ) |
---|
121 | { |
---|
122 | return RTEMS_SUCCESSFUL; |
---|
123 | } |
---|
124 | |
---|
125 | void Set_find_average_overhead( |
---|
126 | rtems_boolean find_flag |
---|
127 | ) |
---|
128 | { |
---|
129 | Timer_driver_Find_average_overhead = find_flag; |
---|
130 | } |
---|