1 | /* Clock_init() |
---|
2 | * |
---|
3 | * This routine initializes the Tick Timer 2 on the MVME162 board. |
---|
4 | * The tick frequency is 1 millisecond. |
---|
5 | * |
---|
6 | * Input parameters: NONE |
---|
7 | * |
---|
8 | * Output parameters: NONE |
---|
9 | * |
---|
10 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * All rights assigned to U.S. Government, 1994. |
---|
13 | * |
---|
14 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
15 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
16 | * notice must appear in all copies of this file and its derivatives. |
---|
17 | * |
---|
18 | * Modifications of respective RTEMS file: COPYRIGHT (c) 1994. |
---|
19 | * EISCAT Scientific Association. M.Savitski |
---|
20 | * |
---|
21 | * This material is a part of the MVME162 Board Support Package |
---|
22 | * for the RTEMS executive. Its licensing policies are those of the |
---|
23 | * RTEMS above. |
---|
24 | * |
---|
25 | * $Id$ |
---|
26 | */ |
---|
27 | |
---|
28 | #include <stdlib.h> |
---|
29 | |
---|
30 | #include <bsp.h> |
---|
31 | #include <rtems/libio.h> |
---|
32 | |
---|
33 | #define MS_COUNT 1000 /* T2's countdown constant (1 ms) */ |
---|
34 | #define CLOCK_INT_LEVEL 6 /* T2's interrupt level */ |
---|
35 | |
---|
36 | rtems_unsigned32 Clock_isrs; /* ISRs until next tick */ |
---|
37 | volatile rtems_unsigned32 Clock_driver_ticks; /* ticks since initialization */ |
---|
38 | rtems_isr_entry Old_ticker; |
---|
39 | |
---|
40 | void Clock_exit( void ); |
---|
41 | |
---|
42 | #define CLOCK_VECTOR (VBR0 * 0x10 + 0x9) |
---|
43 | /* |
---|
44 | * These are set by clock driver during its init |
---|
45 | */ |
---|
46 | |
---|
47 | rtems_device_major_number rtems_clock_major = ~0; |
---|
48 | rtems_device_minor_number rtems_clock_minor; |
---|
49 | |
---|
50 | |
---|
51 | /* |
---|
52 | * ISR Handler |
---|
53 | */ |
---|
54 | |
---|
55 | rtems_isr Clock_isr(rtems_vector_number vector) |
---|
56 | { |
---|
57 | Clock_driver_ticks += 1; |
---|
58 | lcsr->timer_cnt_2 = 0; /* clear counter */ |
---|
59 | lcsr->intr_clear |= 0x02000000; |
---|
60 | |
---|
61 | if ( Clock_isrs == 1 ) { |
---|
62 | rtems_clock_tick(); |
---|
63 | Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; |
---|
64 | } |
---|
65 | else |
---|
66 | Clock_isrs -= 1; |
---|
67 | } |
---|
68 | |
---|
69 | void Install_clock(rtems_isr_entry clock_isr ) |
---|
70 | { |
---|
71 | |
---|
72 | Clock_driver_ticks = 0; |
---|
73 | Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; |
---|
74 | |
---|
75 | if ( BSP_Configuration.ticks_per_timeslice ) { |
---|
76 | Old_ticker = |
---|
77 | (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 ); |
---|
78 | lcsr->vector_base |= MASK_INT; /* unmask VMEchip2 interrupts */ |
---|
79 | lcsr->to_ctl = 0xE7; /* prescaler to 1 MHz (see Appendix A1) */ |
---|
80 | lcsr->timer_cmp_2 = MS_COUNT; |
---|
81 | lcsr->timer_cnt_2 = 0; /* clear counter */ |
---|
82 | lcsr->board_ctl |= 0x700; /* increment, reset-on-compare, and */ |
---|
83 | /* clear-overflow-cnt */ |
---|
84 | |
---|
85 | lcsr->intr_level[0] |= CLOCK_INT_LEVEL * 0x10; /* set int level */ |
---|
86 | lcsr->intr_ena |= 0x02000000; /* enable tick timer 2 interrupt */ |
---|
87 | |
---|
88 | atexit( Clock_exit ); |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | void Clock_exit( void ) |
---|
93 | { |
---|
94 | /* Dummy for now. See other m68k BSP's for code examples */ |
---|
95 | } |
---|
96 | |
---|
97 | rtems_device_driver Clock_initialize( |
---|
98 | rtems_device_major_number major, |
---|
99 | rtems_device_minor_number minor, |
---|
100 | void *pargp |
---|
101 | ) |
---|
102 | { |
---|
103 | Install_clock( Clock_isr ); |
---|
104 | |
---|
105 | /* |
---|
106 | * make major/minor avail to others such as shared memory driver |
---|
107 | */ |
---|
108 | |
---|
109 | rtems_clock_major = major; |
---|
110 | rtems_clock_minor = minor; |
---|
111 | |
---|
112 | return RTEMS_SUCCESSFUL; |
---|
113 | } |
---|
114 | |
---|
115 | rtems_device_driver Clock_control( |
---|
116 | rtems_device_major_number major, |
---|
117 | rtems_device_minor_number minor, |
---|
118 | void *pargp |
---|
119 | ) |
---|
120 | { |
---|
121 | rtems_unsigned32 isrlevel; |
---|
122 | rtems_libio_ioctl_args_t *args = pargp; |
---|
123 | |
---|
124 | if (args == 0) |
---|
125 | goto done; |
---|
126 | |
---|
127 | /* |
---|
128 | * This is hokey, but until we get a defined interface |
---|
129 | * to do this, it will just be this simple... |
---|
130 | */ |
---|
131 | |
---|
132 | if (args->command == rtems_build_name('I', 'S', 'R', ' ')) |
---|
133 | { |
---|
134 | Clock_isr(CLOCK_VECTOR); |
---|
135 | } |
---|
136 | else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) |
---|
137 | { |
---|
138 | rtems_interrupt_disable( isrlevel ); |
---|
139 | (void) set_vector( args->buffer, CLOCK_VECTOR, 1 ); |
---|
140 | rtems_interrupt_enable( isrlevel ); |
---|
141 | } |
---|
142 | |
---|
143 | done: |
---|
144 | return RTEMS_SUCCESSFUL; |
---|
145 | } |
---|
146 | |
---|