1 | /* Clock |
---|
2 | * |
---|
3 | * This routine generates clock ticks using standard POSIX services. |
---|
4 | * The tick frequency is specified by the bsp. |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
8 | * All rights assigned to U.S. Government, 1994. |
---|
9 | * |
---|
10 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
11 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
12 | * notice must appear in all copies of this file and its derivatives. |
---|
13 | * |
---|
14 | * $Id$ |
---|
15 | */ |
---|
16 | |
---|
17 | #include <bsp.h> |
---|
18 | #include <rtems/libio.h> |
---|
19 | #include <stdlib.h> |
---|
20 | |
---|
21 | void Clock_exit(void); |
---|
22 | |
---|
23 | volatile rtems_unsigned32 Clock_driver_ticks; |
---|
24 | |
---|
25 | rtems_unsigned32 Clock_driver_vector; |
---|
26 | |
---|
27 | /* |
---|
28 | * These are set by clock driver during its init |
---|
29 | */ |
---|
30 | |
---|
31 | rtems_device_major_number rtems_clock_major = ~0; |
---|
32 | rtems_device_minor_number rtems_clock_minor; |
---|
33 | |
---|
34 | void |
---|
35 | Install_clock(rtems_isr_entry clock_isr) |
---|
36 | { |
---|
37 | Clock_driver_ticks = 0; |
---|
38 | |
---|
39 | (void)set_vector(clock_isr, Clock_driver_vector, 1); |
---|
40 | |
---|
41 | _CPU_Start_clock( BSP_Configuration.microseconds_per_tick ); |
---|
42 | |
---|
43 | atexit(Clock_exit); |
---|
44 | } |
---|
45 | |
---|
46 | void |
---|
47 | ReInstall_clock(rtems_isr_entry new_clock_isr) |
---|
48 | { |
---|
49 | rtems_unsigned32 isrlevel = 0; |
---|
50 | |
---|
51 | rtems_interrupt_disable(isrlevel); |
---|
52 | (void)set_vector(new_clock_isr, Clock_driver_vector, 1); |
---|
53 | rtems_interrupt_enable(isrlevel); |
---|
54 | } |
---|
55 | |
---|
56 | void |
---|
57 | Clock_isr(int vector) |
---|
58 | { |
---|
59 | Clock_driver_ticks++; |
---|
60 | rtems_clock_tick(); |
---|
61 | } |
---|
62 | |
---|
63 | /* |
---|
64 | * Called via atexit() |
---|
65 | * Remove the clock signal |
---|
66 | */ |
---|
67 | |
---|
68 | void |
---|
69 | Clock_exit(void) |
---|
70 | { |
---|
71 | _CPU_Stop_clock(); |
---|
72 | |
---|
73 | (void)set_vector(0, Clock_driver_vector, 1); |
---|
74 | } |
---|
75 | |
---|
76 | rtems_device_driver |
---|
77 | Clock_initialize( |
---|
78 | rtems_device_major_number major, |
---|
79 | rtems_device_minor_number minor, |
---|
80 | void *pargp |
---|
81 | ) |
---|
82 | { |
---|
83 | Clock_driver_vector = _CPU_Get_clock_vector(); |
---|
84 | |
---|
85 | Install_clock((rtems_isr_entry) Clock_isr); |
---|
86 | |
---|
87 | /* |
---|
88 | * make major/minor avail to others such as shared memory driver |
---|
89 | */ |
---|
90 | rtems_clock_major = major; |
---|
91 | rtems_clock_minor = minor; |
---|
92 | |
---|
93 | return RTEMS_SUCCESSFUL; |
---|
94 | } |
---|
95 | |
---|
96 | rtems_device_driver Clock_control( |
---|
97 | rtems_device_major_number major, |
---|
98 | rtems_device_minor_number minor, |
---|
99 | void *pargp |
---|
100 | ) |
---|
101 | { |
---|
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_driver_vector); |
---|
115 | } |
---|
116 | else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) |
---|
117 | { |
---|
118 | ReInstall_clock(args->buffer); |
---|
119 | } |
---|
120 | |
---|
121 | done: |
---|
122 | return RTEMS_SUCCESSFUL; |
---|
123 | } |
---|