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