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