1 | /* Clock_init() |
---|
2 | * |
---|
3 | * This routine initailizes the periodic interrupt timer on |
---|
4 | * the Motorola 68332. |
---|
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 | #include <bsp.h> |
---|
23 | #include <rtems/libio.h> |
---|
24 | #include <efi332.h> |
---|
25 | |
---|
26 | #define CLOCK_VECTOR EFI_PIV |
---|
27 | |
---|
28 | rtems_unsigned32 Clock_isrs; /* ISRs until next tick */ |
---|
29 | volatile rtems_unsigned32 Clock_driver_ticks; |
---|
30 | /* ticks since initialization */ |
---|
31 | rtems_isr_entry Old_ticker; |
---|
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 | rtems_isr Clock_isr(rtems_vector_number vector) |
---|
43 | { |
---|
44 | Clock_driver_ticks += 1; |
---|
45 | |
---|
46 | if ( Clock_isrs == 1 ) { |
---|
47 | rtems_clock_tick(); |
---|
48 | Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; |
---|
49 | } |
---|
50 | else |
---|
51 | Clock_isrs -= 1; |
---|
52 | } |
---|
53 | |
---|
54 | void Install_clock( |
---|
55 | rtems_isr_entry clock_isr |
---|
56 | ) |
---|
57 | { |
---|
58 | Clock_driver_ticks = 0; |
---|
59 | Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; |
---|
60 | |
---|
61 | if ( BSP_Configuration.ticks_per_timeslice ) { |
---|
62 | Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 ); |
---|
63 | |
---|
64 | /* enable 1mS interrupts */ |
---|
65 | *PITR = (unsigned short int)( SAM(0x09,0,PITM) );/* load counter */ |
---|
66 | *PICR = (unsigned short int) /* enable interrupt */ |
---|
67 | ( SAM(ISRL_PIT,8,PIRQL) | SAM(CLOCK_VECTOR,0,PIV) ); |
---|
68 | |
---|
69 | atexit( Clock_exit ); |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | void Clock_exit( void ) |
---|
74 | { |
---|
75 | |
---|
76 | if ( BSP_Configuration.ticks_per_timeslice ) { |
---|
77 | |
---|
78 | /* shutdown the periodic interrupt */ |
---|
79 | *PICR = (unsigned short int) |
---|
80 | ( SAM(0,8,PIRQL) | SAM(CLOCK_VECTOR,0,PIV) ); |
---|
81 | /* ^^ zero disables interrupt */ |
---|
82 | |
---|
83 | /* do not restore old vector */ |
---|
84 | |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | rtems_device_driver Clock_initialize( |
---|
89 | rtems_device_major_number major, |
---|
90 | rtems_device_minor_number minor, |
---|
91 | void *pargp |
---|
92 | ) |
---|
93 | { |
---|
94 | Install_clock( Clock_isr ); |
---|
95 | |
---|
96 | /* |
---|
97 | * make major/minor avail to others such as shared memory driver |
---|
98 | */ |
---|
99 | |
---|
100 | rtems_clock_major = major; |
---|
101 | rtems_clock_minor = minor; |
---|
102 | |
---|
103 | return RTEMS_SUCCESSFUL; |
---|
104 | } |
---|
105 | |
---|
106 | rtems_device_driver Clock_control( |
---|
107 | rtems_device_major_number major, |
---|
108 | rtems_device_minor_number minor, |
---|
109 | void *pargp |
---|
110 | ) |
---|
111 | { |
---|
112 | rtems_unsigned32 isrlevel; |
---|
113 | rtems_libio_ioctl_args_t *args = pargp; |
---|
114 | |
---|
115 | if (args == 0) |
---|
116 | goto done; |
---|
117 | |
---|
118 | /* |
---|
119 | * This is hokey, but until we get a defined interface |
---|
120 | * to do this, it will just be this simple... |
---|
121 | */ |
---|
122 | |
---|
123 | if (args->command == rtems_build_name('I', 'S', 'R', ' ')) |
---|
124 | { |
---|
125 | Clock_isr(CLOCK_VECTOR); |
---|
126 | } |
---|
127 | else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) |
---|
128 | { |
---|
129 | rtems_interrupt_disable( isrlevel ); |
---|
130 | (void) set_vector( args->buffer, CLOCK_VECTOR, 1 ); |
---|
131 | rtems_interrupt_enable( isrlevel ); |
---|
132 | } |
---|
133 | |
---|
134 | done: |
---|
135 | return RTEMS_SUCCESSFUL; |
---|
136 | } |
---|
137 | |
---|