1 | /* |
---|
2 | * Clock Driver for SH4 simulator (timer interrupt not supported now). |
---|
3 | * |
---|
4 | * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia |
---|
5 | * Author: Victor V. Vengerov <vvv@oktet.ru> |
---|
6 | * |
---|
7 | * COPYRIGHT (c) 1989-2001. |
---|
8 | * On-Line Applications Research Corporation (OAR). |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * |
---|
13 | * http://www.OARcorp.com/rtems/license.html. |
---|
14 | * |
---|
15 | * $Id$ |
---|
16 | */ |
---|
17 | |
---|
18 | #include <stdlib.h> |
---|
19 | #include <bsp.h> |
---|
20 | #include <rtems/libio.h> |
---|
21 | |
---|
22 | /* |
---|
23 | * Clock_driver_ticks is a monotonically increasing counter of the |
---|
24 | * number of clock ticks since the driver was initialized. |
---|
25 | */ |
---|
26 | volatile rtems_unsigned32 Clock_driver_ticks; |
---|
27 | |
---|
28 | |
---|
29 | /* |
---|
30 | * These are set by clock driver during its init |
---|
31 | */ |
---|
32 | |
---|
33 | rtems_device_major_number rtems_clock_major = ~0; |
---|
34 | rtems_device_minor_number rtems_clock_minor; |
---|
35 | |
---|
36 | rtems_isr (*rtems_clock_hook)(rtems_vector_number) = NULL; |
---|
37 | |
---|
38 | static void |
---|
39 | set_clock_period(rtems_unsigned32 period) |
---|
40 | { |
---|
41 | asm volatile ("\tmov %0,r0\n" |
---|
42 | "\ttrapa\t#4\n" |
---|
43 | : |
---|
44 | : "r" (period) |
---|
45 | : "r0" ); |
---|
46 | } |
---|
47 | |
---|
48 | /* Clock_isr -- |
---|
49 | * This handles the timer interrupt by clearing the timer's interrupt |
---|
50 | * flag and announcing the clock tick to the system. |
---|
51 | * |
---|
52 | * PARAMETERS: |
---|
53 | * vector - timer interrupt vector number |
---|
54 | * |
---|
55 | * RETURNS: |
---|
56 | * none |
---|
57 | */ |
---|
58 | rtems_isr |
---|
59 | Clock_isr (rtems_vector_number vector) |
---|
60 | { |
---|
61 | /* Announce the clock tick */ |
---|
62 | Clock_driver_ticks++; |
---|
63 | rtems_clock_tick(); |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | /* Clock_exit -- |
---|
68 | * This shuts down the timer if it was enabled and removes it |
---|
69 | * from the interrupt mask. |
---|
70 | * |
---|
71 | * PARAMETERS: |
---|
72 | * none |
---|
73 | * |
---|
74 | * RETURNS: |
---|
75 | * none |
---|
76 | */ |
---|
77 | void |
---|
78 | Clock_exit(void) |
---|
79 | { |
---|
80 | if (BSP_Configuration.ticks_per_timeslice) |
---|
81 | { |
---|
82 | /* disable all timer1 interrupts */ |
---|
83 | set_clock_period(0); |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | /* Install_clock -- |
---|
89 | * This initialises timer1 with the BSP timeslice config value |
---|
90 | * as a reference and sets up the interrupt handler for clock ticks. |
---|
91 | * |
---|
92 | * PARAMETERS: |
---|
93 | * clock_isr - clock interrupt handler routine |
---|
94 | * |
---|
95 | * RETURNS: |
---|
96 | * none. |
---|
97 | */ |
---|
98 | static void |
---|
99 | Install_clock(rtems_isr_entry clock_isr) |
---|
100 | { |
---|
101 | rtems_unsigned32 period; |
---|
102 | Clock_driver_ticks = 0; |
---|
103 | if (BSP_Configuration.ticks_per_timeslice) |
---|
104 | { |
---|
105 | rtems_isr_entry old_isr; |
---|
106 | period = Cpu_table.clicks_per_second / |
---|
107 | BSP_Configuration.ticks_per_timeslice; |
---|
108 | |
---|
109 | /* Configure timer interrupts */ |
---|
110 | set_clock_period(period); |
---|
111 | |
---|
112 | /* Register the interrupt handler */ |
---|
113 | rtems_interrupt_catch(clock_isr, CLOCK_VECTOR, &old_isr); |
---|
114 | |
---|
115 | /* Register the driver exit procedure so we can shutdown */ |
---|
116 | atexit(Clock_exit); |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | /* Clock_initialize -- |
---|
122 | * This is called to setup the clock driver. It calls the hardware |
---|
123 | * setup function and make the driver major/minor values available |
---|
124 | * for other. |
---|
125 | * |
---|
126 | * PARAMETERS: |
---|
127 | * major - clock device major number |
---|
128 | * minor - clock device minor number |
---|
129 | * pargp - device driver initialization argument (not used) |
---|
130 | * |
---|
131 | * RETURNS: |
---|
132 | * RTEMS status code |
---|
133 | */ |
---|
134 | rtems_device_driver |
---|
135 | Clock_initialize(rtems_device_major_number major, |
---|
136 | rtems_device_minor_number minor, |
---|
137 | void *pargp) |
---|
138 | { |
---|
139 | Install_clock (Clock_isr); |
---|
140 | |
---|
141 | /* Make major/minor avail to others such as shared memory driver */ |
---|
142 | rtems_clock_major = major; |
---|
143 | rtems_clock_minor = minor; |
---|
144 | |
---|
145 | return RTEMS_SUCCESSFUL; |
---|
146 | } |
---|
147 | |
---|
148 | |
---|
149 | /* Clock_control -- |
---|
150 | * I/O control (IOCTL) function for Clock driver. At this moment this |
---|
151 | * just runs the interrupt handler or re-registers the interrupt handler |
---|
152 | * on request. |
---|
153 | * |
---|
154 | * PARAMETERS: |
---|
155 | * major - clock major device number |
---|
156 | * minor - clock minor device number |
---|
157 | * pargp - pointer to IOCTL arguments |
---|
158 | * |
---|
159 | * RETURNS: |
---|
160 | * RTEMS status code |
---|
161 | */ |
---|
162 | rtems_device_driver |
---|
163 | Clock_control(rtems_device_major_number major, |
---|
164 | rtems_device_minor_number minor, |
---|
165 | void *pargp) |
---|
166 | { |
---|
167 | rtems_unsigned32 isrlevel; |
---|
168 | rtems_libio_ioctl_args_t *args = pargp; |
---|
169 | |
---|
170 | if (args) |
---|
171 | { |
---|
172 | rtems_isr_entry old_isr; |
---|
173 | /* |
---|
174 | * This is hokey, but until we get a defined interface |
---|
175 | * to do this, it will just be this simple... |
---|
176 | */ |
---|
177 | if (args->command == rtems_build_name('I', 'S', 'R', ' ')) |
---|
178 | { |
---|
179 | Clock_isr(CLOCK_VECTOR); |
---|
180 | } |
---|
181 | else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) |
---|
182 | { |
---|
183 | rtems_interrupt_disable( isrlevel ); |
---|
184 | rtems_interrupt_catch(Clock_isr, CLOCK_VECTOR, &old_isr); |
---|
185 | rtems_interrupt_enable( isrlevel ); |
---|
186 | } |
---|
187 | } |
---|
188 | return RTEMS_SUCCESSFUL; |
---|
189 | } |
---|