/* * Test program of ptimer driver (/dev/ptimer). * * Copyright (C) 2001 MontaVista Software Inc. * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * */ #include #include #include #include /* * IOCTL CMD */ #define PTIMER_SET_PERIOD 0 #define PTIMER_GET_PERIOD 1 main() { unsigned long period; int fd = open("/dev/ptimer", O_RDONLY); if (fd < 0) { printf("failed to open /dev/ptimer\n"); exit(-1); } if (ioctl(fd, PTIMER_GET_PERIOD, &period) < 0) { printf("failed to get period\n"); exit(-1); } printf("Initial period is %d\n", period); /* we use 1 sec period */ if (ioctl(fd, PTIMER_SET_PERIOD, 100) < 0) { printf("failed to set period\n"); exit(-1); } ioctl(fd, PTIMER_GET_PERIOD, &period); printf("New period is %d\n", period); printf("loop to read /dev/ptimer ...\n"); for(;;) { int count; int ret; ret = read(fd, &count, sizeof(count)); if (ret == sizeof(count)) { printf("read ok : count=%d, ret=%d\n", count, ret); } else { printf("read failed\n"); } } }