Here shows HPET driver API. Using man page like format with some modifications. Following lines shows modifications,
HPET driver provides following features.
To know more details refer to HPET specification.
Most linux distributions enable HPET driver and prepare access node /dev/hpet. /dev/hpet is the character device node associated to major=10, minor=228 one of "misc device".
To use HPET device, open /dev/hpet with file mode O_RDONLY. If there is a unused(free) HPET timer, assign a timer to opened file descriptor. A timer is one of timer circuit block in HPET block. HPET driver's ioctl() calls manipulate the timer assigned to file descriptor.
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 use mmap(), include optional header file as follows.
#include <sys/mman.h>
If you wish to handle error, include optional header files as follows.
#include <string.h> /* strerror() */ #include <errno.h> /* errno, Exxx macros. */
In this section shows HPET driver ioctl() API. HPET driver provides following ioctl() API.
ioctl request number | description |
HPET_INFO | Get Information int ioctl(int fd, HPET_INFO, /* out */ struct hpet_info *info); |
HPET_IRQFREQ | Set Interrupt Frequency in Hz int ioctl(int fd, HPET_IRQFREQ, unsigned long frequency); |
HPET_EPI | Enable hardware periodic interrupt int ioctl(int fd, HPET_EPI); |
HPET_DPI | Disable hardware periodic interrupt int ioctl(int fd, HPET_DPI); |
HPET_IE_ON | Interrupt On int ioctl(int fd, HPET_IE_ON); |
HPET_IE_OFF | Interrupt Off int ioctl(int fd, HPET_IE_OFF); |
Here shows HPET driver specific behaviors. To see basic file system ioctl() behaviors refer to man 2 ioctl.
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_IRQFREQ, unsigned long frequency);
int ioctl(int fd, HPET_EPI);
int ioctl(int fd, HPET_DPI);
int ioctl(int fd, HPET_IE_ON);
int ioctl(int fd, HPET_IE_OFF);
In this section shows File System and Memory Mapping API related to HPET driver. When using open(), close(), read(), mmap(), munmap(), fcntl(), and these alternate functions to access HPET, these API have HPET specific behaviour. Here shows HPET specific behavior. To see file system specific basic behavior and details, refer to system call man pages. man 2 fcntl shows about sending signal from file descriptor in detail.
int open(const char *hpet_path, /* open mode */ O_RDONLY);
int close(int fd);
int read(int fd, unsigned long *buf, /* size */ sizeof(unsigned long));
void *mmap(void *addr, size_t length, int prot, int flags, int fd, /* offset */ 0); int munmap(void *addr, size_t length);
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);