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)
103 hpet_poll(int argc, const char **argv)
106 int iterations, i, fd;
108 struct hpet_info info;
109 struct timeval stv, etv;
114 fprintf(stderr, "hpet_poll: device-name freq iterations\n");
118 freq = atoi(argv[1]);
119 iterations = atoi(argv[2]);
121 fd = open(argv[0], O_RDONLY);
124 fprintf(stderr, "hpet_poll: open of %s failed\n", argv[0]);
128 if (ioctl(fd, HPET_IRQFREQ, freq) < 0) {
129 fprintf(stderr, "hpet_poll: HPET_IRQFREQ failed\n");
133 if (ioctl(fd, HPET_INFO, &info) < 0) {
134 fprintf(stderr, "hpet_poll: failed to get info\n");
138 fprintf(stderr, "hpet_poll: info.hi_flags 0x%lx\n", info.hi_flags);
140 if (info.hi_flags && (ioctl(fd, HPET_EPI, 0) < 0)) {
141 fprintf(stderr, "hpet_poll: HPET_EPI failed\n");
145 if (ioctl(fd, HPET_IE_ON, 0) < 0) {
146 fprintf(stderr, "hpet_poll, HPET_IE_ON failed\n");
153 for (i = 0; i < iterations; i++) {
155 gettimeofday(&stv, &tz);
156 if (poll(&pfd, 1, -1) < 0)
157 fprintf(stderr, "hpet_poll: poll failed\n");
161 gettimeofday(&etv, &tz);
162 usec = stv.tv_sec * 1000000 + stv.tv_usec;
163 usec = (etv.tv_sec * 1000000 + etv.tv_usec) - usec;
166 "hpet_poll: expired time = 0x%lx\n", usec);
168 fprintf(stderr, "hpet_poll: revents = 0x%x\n",
171 if (read(fd, &data, sizeof(data)) != sizeof(data)) {
172 fprintf(stderr, "hpet_poll: read failed\n");
175 fprintf(stderr, "hpet_poll: data 0x%lx\n",
185 static int hpet_sigio_count;
190 fprintf(stderr, "hpet_sigio: called\n");
195 hpet_fasync(int argc, const char **argv)
198 int iterations, i, fd, value;
200 struct hpet_info info;
202 hpet_sigio_count = 0;
205 if ((oldsig = signal(SIGIO, hpet_sigio)) == SIG_ERR) {
206 fprintf(stderr, "hpet_fasync: failed to set signal handler\n");
211 fprintf(stderr, "hpet_fasync: device-name freq iterations\n");
215 fd = open(argv[0], O_RDONLY);
218 fprintf(stderr, "hpet_fasync: failed to open %s\n", argv[0]);
223 if ((fcntl(fd, F_SETOWN, getpid()) == 1) ||
224 ((value = fcntl(fd, F_GETFL)) == 1) ||
225 (fcntl(fd, F_SETFL, value | O_ASYNC) == 1)) {
226 fprintf(stderr, "hpet_fasync: fcntl failed\n");
230 freq = atoi(argv[1]);
231 iterations = atoi(argv[2]);
233 if (ioctl(fd, HPET_IRQFREQ, freq) < 0) {
234 fprintf(stderr, "hpet_fasync: HPET_IRQFREQ failed\n");
238 if (ioctl(fd, HPET_INFO, &info) < 0) {
239 fprintf(stderr, "hpet_fasync: failed to get info\n");
243 fprintf(stderr, "hpet_fasync: info.hi_flags 0x%lx\n", info.hi_flags);
245 if (info.hi_flags && (ioctl(fd, HPET_EPI, 0) < 0)) {
246 fprintf(stderr, "hpet_fasync: HPET_EPI failed\n");
250 if (ioctl(fd, HPET_IE_ON, 0) < 0) {
251 fprintf(stderr, "hpet_fasync, HPET_IE_ON failed\n");
255 for (i = 0; i < iterations; i++) {
257 fprintf(stderr, "hpet_fasync: count = %d\n", hpet_sigio_count);
261 signal(SIGIO, oldsig);