1 | /* Clock_init() |
---|
2 | * |
---|
3 | * This routine initializes the timer on the VIC chip on the CVME961. |
---|
4 | * The tick frequency is 1 millisecond. |
---|
5 | * |
---|
6 | * Input parameters: NONE |
---|
7 | * |
---|
8 | * Output parameters: NONE |
---|
9 | * |
---|
10 | * COPYRIGHT (c) 1989-1999. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.com/license/LICENSE. |
---|
16 | * |
---|
17 | * $Id$ |
---|
18 | */ |
---|
19 | |
---|
20 | #include <stdlib.h> |
---|
21 | |
---|
22 | #include <bsp.h> |
---|
23 | #include <rtems/libio.h> |
---|
24 | |
---|
25 | #define CLOCK_VECTOR 5 |
---|
26 | |
---|
27 | rtems_unsigned32 Clock_isrs; /* ISRs until next tick */ |
---|
28 | i960_isr_entry Old_ticker; |
---|
29 | volatile rtems_unsigned32 Clock_driver_ticks; |
---|
30 | /* ticks since initialization */ |
---|
31 | |
---|
32 | void Clock_exit( void ); |
---|
33 | |
---|
34 | /* |
---|
35 | * These are set by clock driver during its init |
---|
36 | */ |
---|
37 | |
---|
38 | rtems_device_major_number rtems_clock_major = ~0; |
---|
39 | rtems_device_minor_number rtems_clock_minor; |
---|
40 | |
---|
41 | |
---|
42 | /* this is later in the file to avoid it being inlined */ |
---|
43 | rtems_isr Clock_isr( rtems_vector_number vector ); |
---|
44 | |
---|
45 | void Install_clock( |
---|
46 | rtems_isr_entry clock_isr |
---|
47 | ) |
---|
48 | { |
---|
49 | volatile unsigned char *victimer; |
---|
50 | |
---|
51 | Clock_driver_ticks = 0; |
---|
52 | Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; |
---|
53 | |
---|
54 | Old_ticker = set_vector( clock_isr, CLOCK_VECTOR, 1 ); |
---|
55 | victimer = (volatile unsigned char *) 0xa00000c3; |
---|
56 | *victimer = 0x12; |
---|
57 | *victimer = 0x92; /* 1000 HZ */ |
---|
58 | } |
---|
59 | |
---|
60 | void Clock_exit() |
---|
61 | { |
---|
62 | unsigned char *victimer; |
---|
63 | |
---|
64 | victimer = (unsigned char *) 0xa00000c3; |
---|
65 | *victimer = 0x12; |
---|
66 | i960_mask_intr( 5 ); |
---|
67 | /* do not restore old vector */ |
---|
68 | } |
---|
69 | |
---|
70 | rtems_device_driver Clock_initialize( |
---|
71 | rtems_device_major_number major, |
---|
72 | rtems_device_minor_number minor, |
---|
73 | void *pargp |
---|
74 | ) |
---|
75 | { |
---|
76 | Install_clock( Clock_isr ); |
---|
77 | |
---|
78 | atexit( Clock_exit ); |
---|
79 | |
---|
80 | /* |
---|
81 | * make major/minor avail to others such as shared memory driver |
---|
82 | */ |
---|
83 | |
---|
84 | rtems_clock_major = major; |
---|
85 | rtems_clock_minor = minor; |
---|
86 | |
---|
87 | return RTEMS_SUCCESSFUL; |
---|
88 | } |
---|
89 | |
---|
90 | rtems_device_driver Clock_control( |
---|
91 | rtems_device_major_number major, |
---|
92 | rtems_device_minor_number minor, |
---|
93 | void *pargp |
---|
94 | ) |
---|
95 | { |
---|
96 | rtems_unsigned32 isrlevel; |
---|
97 | rtems_libio_ioctl_args_t *args = pargp; |
---|
98 | |
---|
99 | if (args == 0) |
---|
100 | goto done; |
---|
101 | |
---|
102 | /* |
---|
103 | * This is hokey, but until we get a defined interface |
---|
104 | * to do this, it will just be this simple... |
---|
105 | */ |
---|
106 | |
---|
107 | if (args->command == rtems_build_name('I', 'S', 'R', ' ')) |
---|
108 | { |
---|
109 | Clock_isr(CLOCK_VECTOR); |
---|
110 | } |
---|
111 | else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) |
---|
112 | { |
---|
113 | rtems_interrupt_disable( isrlevel ); |
---|
114 | (void) set_vector( args->buffer, CLOCK_VECTOR, 1 ); |
---|
115 | rtems_interrupt_enable( isrlevel ); |
---|
116 | } |
---|
117 | |
---|
118 | done: |
---|
119 | return RTEMS_SUCCESSFUL; |
---|
120 | } |
---|
121 | |
---|
122 | rtems_isr Clock_isr( |
---|
123 | rtems_vector_number vector |
---|
124 | ) |
---|
125 | { |
---|
126 | /* enable_tracing(); */ |
---|
127 | Clock_driver_ticks += 1; |
---|
128 | if ( Clock_isrs == 1 ) { |
---|
129 | rtems_clock_tick(); |
---|
130 | Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; |
---|
131 | } |
---|
132 | else |
---|
133 | Clock_isrs -= 1; |
---|
134 | i960_clear_intr( 5 ); |
---|
135 | } |
---|
136 | |
---|