HPET (High Precision Event Timer) ドライバ /drivers/char/hpet.c の動作を理解するために、実際に動かすアプリケーション・プログラム hpet_example.tar.gz を使います。このプログラムは /Documentation/timers/hpet_example.c を修正して作成してあります。/Documentation/timers/hpet.txt で hpet_example.c について概要が書かれています。情報量は多く有りません。ioctl() API の仕様詳細は書かれていません。
To use HPET device from user context (Linux Application), include header files as follows.
#define _GNU_SOURCE #include <features.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <unistd.h> #include <fcntl.h> #include <linux/hpet.h>
If you wish to use poll(), include optional header file as follows.
#include <poll.h>
If you wish to use select(), include optional header files as follows.
#include <sys/time.h> #include <sys/select.h>
If you wish to use signal(), include optional header file as follows.
#include <signal.h>
If you wish to handle error, include optional header files as follows.
#include <string.h> #include <errno.h>
int ioctl(int fd, HPET_IE_ON);
int ioctl(int fd, HPET_IE_OFF);
struct hpet_info { unsigned long hi_ireqfreq; /* Period or time in Hz */ unsigned long hi_flags; /* Information: 0x0: Not supported periodic int., 0x10: Supported periodic int. */ unsigned short hi_hpet; /* HPET device number, [0..TheNumberOfHPETDevicesInPlatform-1] */ unsigned short hi_timer; /* Timer number in HPET device, [0..31] */ }; int ioctl(int fd, HPET_INFO, /* out */ struct hpet_info *info);
member | description |
hi_ireqfreq | Interrupt frequency in Hz. |
hi_flags | Timer capability. The value will be as follows, 0x00UL This timer doesn't have hardware implemented periodic interrupt. 0x10UL This timer has hardware implemented periodic interrupt. |
hi_hpet | HPET device number on platform. It satisfies (hi_hpet >= 0) && (hi_hpet < M), where M is the number of HPET devices (circuit blocks) on platform. |
hi_timer | Timer number in HPET device. It satisfies (hi_timer >= 0) && (hi_timer < N), where N is the number of timers in HPET device and N <= 32. NOTE: You may see {hi_hpet, hi_timer} == {0, 2} at first opened HPET timer, because the timer 0 and timer 1 replaces PIT(programmable Interval Timer) and RTC(Real Time Clock). |
int ioctl(int fd, HPET_EPI);
int ioctl(int fd, HPET_DPI);
int ioctl(int fd, HPET_IRQFREQ, unsigned long frequency);
In this section shows File System API related to HPET driver. And these APIs have HPET specific behavior. Here shows HPET specific behavior. To see more details and file system specific basic behavior, refer to system call man pages. man 2 fcntl shows about raising signal from file descriptor in detail.
int open(const char *hpet_path, O_RDONLY);
int close(int fd);
int fcntl(int fd, F_GETOWN);
struct f_owner_ex { int type; /* F_OWNER_PID, F_OWNER_PGRP, or F_OWNER_TID */ pid_t pid; /* process id, process group id, or thread id. */ } int fcntl(int fd, F_GETOWN_EX, /* out */ struct f_owner_ex *owner_ex);
int fcntl(int fd, F_SETOWN, int owner);
struct f_owner_ex { int type; /* F_OWNER_PID, F_OWNER_PGRP, or F_OWNER_TID */ pid_t pid; /* process id, process group id, or thread id. */ } int fcntl(int fd, F_GETOWN_EX, /* in */ struct f_owner_ex *owner_ex);
int fcntl(int fd, F_GETFL);
int fcntl(int fd, F_SETFL, int flags);
int fcntl(int fd, F_GETSIG);
int fcntl(int fd, F_SETSIG, int signal);