1 | /* Clock |
---|
2 | * |
---|
3 | * This routine initializes the interval timer on the |
---|
4 | * PA-RISC CPU. 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 <rtems.h> |
---|
18 | |
---|
19 | #include <stdlib.h> |
---|
20 | #include <stdio.h> |
---|
21 | #include <signal.h> |
---|
22 | #include <time.h> |
---|
23 | #include <sys/time.h> |
---|
24 | |
---|
25 | extern rtems_configuration_table Configuration; |
---|
26 | extern sigset_t UNIX_SIGNAL_MASK; |
---|
27 | |
---|
28 | /* |
---|
29 | * Function prototypes |
---|
30 | */ |
---|
31 | |
---|
32 | void Install_clock(); |
---|
33 | void Clock_isr(); |
---|
34 | void Clock_exit(); |
---|
35 | |
---|
36 | /* |
---|
37 | * CPU_HPPA_CLICKS_PER_TICK is either a #define or an rtems_unsigned32 |
---|
38 | * allocated and set by bsp_start() |
---|
39 | */ |
---|
40 | |
---|
41 | #ifndef CPU_HPPA_CLICKS_PER_TICK |
---|
42 | extern rtems_unsigned32 CPU_HPPA_CLICKS_PER_TICK; |
---|
43 | #endif |
---|
44 | |
---|
45 | volatile rtems_unsigned32 Clock_driver_ticks; |
---|
46 | |
---|
47 | struct itimerval new; |
---|
48 | |
---|
49 | rtems_device_driver |
---|
50 | Clock_initialize( |
---|
51 | rtems_device_major_number major, |
---|
52 | rtems_device_minor_number minor, |
---|
53 | void *pargp, |
---|
54 | rtems_id tid, |
---|
55 | rtems_unsigned32 *rval |
---|
56 | ) |
---|
57 | { |
---|
58 | Install_clock(Clock_isr); |
---|
59 | } |
---|
60 | |
---|
61 | void |
---|
62 | ReInstall_clock(rtems_isr_entry new_clock_isr) |
---|
63 | { |
---|
64 | rtems_unsigned32 isrlevel = 0; |
---|
65 | |
---|
66 | rtems_interrupt_disable(isrlevel); |
---|
67 | (void)set_vector(new_clock_isr, SIGALRM, 1); |
---|
68 | rtems_interrupt_enable(isrlevel); |
---|
69 | } |
---|
70 | |
---|
71 | void |
---|
72 | Install_clock(rtems_isr_entry clock_isr) |
---|
73 | { |
---|
74 | Clock_driver_ticks = 0; |
---|
75 | |
---|
76 | new.it_value.tv_sec = 0; |
---|
77 | new.it_value.tv_usec = Configuration.microseconds_per_tick; |
---|
78 | new.it_interval.tv_sec = 0; |
---|
79 | new.it_interval.tv_usec = Configuration.microseconds_per_tick; |
---|
80 | |
---|
81 | (void)set_vector(clock_isr, SIGALRM, 1); |
---|
82 | |
---|
83 | setitimer(ITIMER_REAL, &new, 0); |
---|
84 | |
---|
85 | atexit(Clock_exit); |
---|
86 | } |
---|
87 | |
---|
88 | void |
---|
89 | Clock_isr(int vector) |
---|
90 | { |
---|
91 | Clock_driver_ticks++; |
---|
92 | |
---|
93 | rtems_clock_tick(); |
---|
94 | } |
---|
95 | |
---|
96 | /* |
---|
97 | * Called via atexit() |
---|
98 | * Remove the clock signal |
---|
99 | */ |
---|
100 | |
---|
101 | void |
---|
102 | Clock_exit(void) |
---|
103 | { |
---|
104 | struct sigaction act; |
---|
105 | |
---|
106 | /* |
---|
107 | * Set the SIGALRM signal to ignore any last |
---|
108 | * signals that might come in while we are |
---|
109 | * disarming the timer and removing the interrupt |
---|
110 | * vector. |
---|
111 | */ |
---|
112 | |
---|
113 | act.sa_handler = SIG_IGN; |
---|
114 | |
---|
115 | sigaction(SIGALRM, &act, 0); |
---|
116 | |
---|
117 | new.it_value.tv_sec = 0; |
---|
118 | new.it_value.tv_usec = 0; |
---|
119 | |
---|
120 | setitimer(ITIMER_REAL, &new, 0); |
---|
121 | |
---|
122 | (void)set_vector(0, SIGALRM, 1); |
---|
123 | } |
---|