10 #include <sys/types.h>
15 #include <linux/hpet.h>
18 extern void hpet_open_close(int, const char **);
19 extern void hpet_info(int, const char **);
20 extern void hpet_poll(int, const char **);
21 extern void hpet_fasync(int, const char **);
22 extern void hpet_read(int, const char **);
25 #include <sys/ioctl.h>
29 void (*func)(int argc, const char ** argv);
50 main(int argc, const char ** argv)
58 fprintf(stderr, "-hpet: requires command\n");
63 for (i = 0; i < (sizeof (hpet_command) / sizeof (hpet_command[0])); i++)
64 if (!strcmp(argv[0], hpet_command[i].command)) {
67 fprintf(stderr, "-hpet: executing %s\n",
68 hpet_command[i].command);
69 hpet_command[i].func(argc, argv);
73 fprintf(stderr, "do_hpet: command %s not implemented\n", argv[0]);
79 hpet_open_close(int argc, const char **argv)
84 fprintf(stderr, "hpet_open_close: device-name\n");
88 fd = open(argv[0], O_RDONLY);
90 fprintf(stderr, "hpet_open_close: open failed\n");
98 hpet_info(int argc, const char **argv)
100 struct hpet_info info;
104 fprintf(stderr, "hpet_info: device-name\n");
108 fd = open(argv[0], O_RDONLY);
110 fprintf(stderr, "hpet_info: open of %s failed\n", argv[0]);
114 if (ioctl(fd, HPET_INFO, &info) < 0) {
115 fprintf(stderr, "hpet_info: failed to get info\n");
119 fprintf(stderr, "hpet_info: hi_irqfreq 0x%lx hi_flags 0x%lx ",
120 info.hi_ireqfreq, info.hi_flags);
121 fprintf(stderr, "hi_hpet %d hi_timer %d\n",
122 info.hi_hpet, info.hi_timer);
130 hpet_poll(int argc, const char **argv)
133 int iterations, i, fd;
135 struct hpet_info info;
136 struct timeval stv, etv;
141 fprintf(stderr, "hpet_poll: device-name freq iterations\n");
145 freq = atoi(argv[1]);
146 iterations = atoi(argv[2]);
148 fd = open(argv[0], O_RDONLY);
151 fprintf(stderr, "hpet_poll: open of %s failed\n", argv[0]);
155 if (ioctl(fd, HPET_IRQFREQ, freq) < 0) {
156 fprintf(stderr, "hpet_poll: HPET_IRQFREQ failed\n");
160 if (ioctl(fd, HPET_INFO, &info) < 0) {
161 fprintf(stderr, "hpet_poll: failed to get info\n");
165 fprintf(stderr, "hpet_poll: info.hi_flags 0x%lx\n", info.hi_flags);
167 if (info.hi_flags && (ioctl(fd, HPET_EPI, 0) < 0)) {
168 fprintf(stderr, "hpet_poll: HPET_EPI failed\n");
172 if (ioctl(fd, HPET_IE_ON, 0) < 0) {
173 fprintf(stderr, "hpet_poll, HPET_IE_ON failed\n");
180 for (i = 0; i < iterations; i++) {
182 gettimeofday(&stv, &tz);
183 if (poll(&pfd, 1, -1) < 0)
184 fprintf(stderr, "hpet_poll: poll failed\n");
188 gettimeofday(&etv, &tz);
189 usec = stv.tv_sec * 1000000 + stv.tv_usec;
190 usec = (etv.tv_sec * 1000000 + etv.tv_usec) - usec;
193 "hpet_poll: expired time = 0x%lx\n", usec);
195 fprintf(stderr, "hpet_poll: revents = 0x%x\n",
198 if (read(fd, &data, sizeof(data)) != sizeof(data)) {
199 fprintf(stderr, "hpet_poll: read failed\n");
202 fprintf(stderr, "hpet_poll: data 0x%lx\n",
212 static int hpet_sigio_count;
217 fprintf(stderr, "hpet_sigio: called\n");
222 hpet_fasync(int argc, const char **argv)
225 int iterations, i, fd, value;
227 struct hpet_info info;
229 hpet_sigio_count = 0;
232 if ((oldsig = signal(SIGIO, hpet_sigio)) == SIG_ERR) {
233 fprintf(stderr, "hpet_fasync: failed to set signal handler\n");
238 fprintf(stderr, "hpet_fasync: device-name freq iterations\n");
242 fd = open(argv[0], O_RDONLY);
245 fprintf(stderr, "hpet_fasync: failed to open %s\n", argv[0]);
250 if ((fcntl(fd, F_SETOWN, getpid()) == 1) ||
251 ((value = fcntl(fd, F_GETFL)) == 1) ||
252 (fcntl(fd, F_SETFL, value | O_ASYNC) == 1)) {
253 fprintf(stderr, "hpet_fasync: fcntl failed\n");
257 freq = atoi(argv[1]);
258 iterations = atoi(argv[2]);
260 if (ioctl(fd, HPET_IRQFREQ, freq) < 0) {
261 fprintf(stderr, "hpet_fasync: HPET_IRQFREQ failed\n");
265 if (ioctl(fd, HPET_INFO, &info) < 0) {
266 fprintf(stderr, "hpet_fasync: failed to get info\n");
270 fprintf(stderr, "hpet_fasync: info.hi_flags 0x%lx\n", info.hi_flags);
272 if (info.hi_flags && (ioctl(fd, HPET_EPI, 0) < 0)) {
273 fprintf(stderr, "hpet_fasync: HPET_EPI failed\n");
277 if (ioctl(fd, HPET_IE_ON, 0) < 0) {
278 fprintf(stderr, "hpet_fasync, HPET_IE_ON failed\n");
282 for (i = 0; i < iterations; i++) {
284 fprintf(stderr, "hpet_fasync: count = %d\n", hpet_sigio_count);
288 signal(SIGIO, oldsig);