10 #include <sys/types.h>
16 #include <linux/hpet.h>
19 extern void hpet_open_close(int, const char **);
20 extern void hpet_info(int, const char **);
21 extern void hpet_poll(int, const char **);
22 extern void hpet_fasync(int, const char **);
23 extern void hpet_read(int, const char **);
26 #include <sys/ioctl.h>
31 void (*func
)(int argc
, const char ** argv
);
52 main(int argc
, const char ** argv
)
60 fprintf(stderr
, "-hpet: requires command\n");
65 for (i
= 0; i
< (sizeof (hpet_command
) / sizeof (hpet_command
[0])); i
++)
66 if (!strcmp(argv
[0], hpet_command
[i
].command
)) {
69 fprintf(stderr
, "-hpet: executing %s\n",
70 hpet_command
[i
].command
);
71 hpet_command
[i
].func(argc
, argv
);
75 fprintf(stderr
, "do_hpet: command %s not implemented\n", argv
[0]);
81 hpet_open_close(int argc
, const char **argv
)
86 fprintf(stderr
, "hpet_open_close: device-name\n");
90 fd
= open(argv
[0], O_RDONLY
);
92 fprintf(stderr
, "hpet_open_close: open failed\n");
100 hpet_info(int argc
, const char **argv
)
105 hpet_poll(int argc
, const char **argv
)
108 int iterations
, i
, fd
;
110 struct hpet_info info
;
111 struct timeval stv
, etv
;
116 fprintf(stderr
, "hpet_poll: device-name freq iterations\n");
120 freq
= atoi(argv
[1]);
121 iterations
= atoi(argv
[2]);
123 fd
= open(argv
[0], O_RDONLY
);
126 fprintf(stderr
, "hpet_poll: open of %s failed\n", argv
[0]);
130 if (ioctl(fd
, HPET_IRQFREQ
, freq
) < 0) {
131 fprintf(stderr
, "hpet_poll: HPET_IRQFREQ failed\n");
135 if (ioctl(fd
, HPET_INFO
, &info
) < 0) {
136 fprintf(stderr
, "hpet_poll: failed to get info\n");
140 fprintf(stderr
, "hpet_poll: info.hi_flags 0x%lx\n", info
.hi_flags
);
142 if (info
.hi_flags
&& (ioctl(fd
, HPET_EPI
, 0) < 0)) {
143 fprintf(stderr
, "hpet_poll: HPET_EPI failed\n");
147 if (ioctl(fd
, HPET_IE_ON
, 0) < 0) {
148 fprintf(stderr
, "hpet_poll, HPET_IE_ON failed\n");
155 for (i
= 0; i
< iterations
; i
++) {
157 gettimeofday(&stv
, &tz
);
158 if (poll(&pfd
, 1, -1) < 0)
159 fprintf(stderr
, "hpet_poll: poll failed\n");
163 gettimeofday(&etv
, &tz
);
164 usec
= stv
.tv_sec
* 1000000 + stv
.tv_usec
;
165 usec
= (etv
.tv_sec
* 1000000 + etv
.tv_usec
) - usec
;
168 "hpet_poll: expired time = 0x%lx\n", usec
);
170 fprintf(stderr
, "hpet_poll: revents = 0x%x\n",
173 if (read(fd
, &data
, sizeof(data
)) != sizeof(data
)) {
174 fprintf(stderr
, "hpet_poll: read failed\n");
177 fprintf(stderr
, "hpet_poll: data 0x%lx\n",
187 static int hpet_sigio_count
;
192 fprintf(stderr
, "hpet_sigio: called\n");
197 hpet_fasync(int argc
, const char **argv
)
200 int iterations
, i
, fd
, value
;
202 struct hpet_info info
;
204 hpet_sigio_count
= 0;
207 if ((oldsig
= signal(SIGIO
, hpet_sigio
)) == SIG_ERR
) {
208 fprintf(stderr
, "hpet_fasync: failed to set signal handler\n");
213 fprintf(stderr
, "hpet_fasync: device-name freq iterations\n");
217 fd
= open(argv
[0], O_RDONLY
);
220 fprintf(stderr
, "hpet_fasync: failed to open %s\n", argv
[0]);
225 if ((fcntl(fd
, F_SETOWN
, getpid()) == 1) ||
226 ((value
= fcntl(fd
, F_GETFL
)) == 1) ||
227 (fcntl(fd
, F_SETFL
, value
| O_ASYNC
) == 1)) {
228 fprintf(stderr
, "hpet_fasync: fcntl failed\n");
232 freq
= atoi(argv
[1]);
233 iterations
= atoi(argv
[2]);
235 if (ioctl(fd
, HPET_IRQFREQ
, freq
) < 0) {
236 fprintf(stderr
, "hpet_fasync: HPET_IRQFREQ failed\n");
240 if (ioctl(fd
, HPET_INFO
, &info
) < 0) {
241 fprintf(stderr
, "hpet_fasync: failed to get info\n");
245 fprintf(stderr
, "hpet_fasync: info.hi_flags 0x%lx\n", info
.hi_flags
);
247 if (info
.hi_flags
&& (ioctl(fd
, HPET_EPI
, 0) < 0)) {
248 fprintf(stderr
, "hpet_fasync: HPET_EPI failed\n");
252 if (ioctl(fd
, HPET_IE_ON
, 0) < 0) {
253 fprintf(stderr
, "hpet_fasync, HPET_IE_ON failed\n");
257 for (i
= 0; i
< iterations
; i
++) {
259 fprintf(stderr
, "hpet_fasync: count = %d\n", hpet_sigio_count
);
263 signal(SIGIO
, oldsig
);