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