High Precision Event Timer.
More...
High Precision Event Timer.
- Note
- Since the HPET might be 32bit it could overflow rather quickly, so we implement a system for checking roughly when it will overflow and accumulate the counter into a 64 bit nanosecond counter.
- See also
- OSDev HPET
◆ HPET_CAP_COUNTER_CLK_PERIOD_SHIFT
| #define HPET_CAP_COUNTER_CLK_PERIOD_SHIFT 32 |
The bit offset of the clock period in the capabilities register.
Definition at line 45 of file hpet.c.
◆ HPET_CONF_ENABLE_CNF_BIT
| #define HPET_CONF_ENABLE_CNF_BIT (1 << 0) |
The bit to set to enable the HPET in the configuration register.
Definition at line 50 of file hpet.c.
◆ HPET_CONF_LEG_RT_CNF_BIT
| #define HPET_CONF_LEG_RT_CNF_BIT (1 << 1) |
The bit to set to enable legacy replacement mode in the configuration register.
Definition at line 55 of file hpet.c.
◆ HPET_ADDRESS_SPACE_MEMORY
| #define HPET_ADDRESS_SPACE_MEMORY 0 |
◆ HPET_ADDRESS_SPACE_IO
| #define HPET_ADDRESS_SPACE_IO 1 |
◆ HPET_FEMTOSECONDS_PER_SECOND
| #define HPET_FEMTOSECONDS_PER_SECOND 1000000000000000ULL |
The number of femtoseconds in one second.
Definition at line 70 of file hpet.c.
◆ hpet_register_t
HPET register offsets.
| Enumerator |
|---|
| HPET_REG_GENERAL_CAPABILITIES_ID | |
| HPET_REG_GENERAL_CONFIG | |
| HPET_REG_GENERAL_INTERRUPT | |
| HPET_REG_MAIN_COUNTER_VALUE | |
| HPET_REG_TIMER0_CONFIG_CAP | |
| HPET_REG_TIMER0_COMPARATOR | |
Definition at line 32 of file hpet.c.
◆ hpet_write()
Write to an HPET register.
- Parameters
-
| reg | The register to write to. |
| value | The value to write. |
Definition at line 112 of file hpet.c.
◆ hpet_read()
Read from an HPET register.
- Parameters
-
| reg | The register to read from. |
- Returns
- The value read from the register.
Definition at line 123 of file hpet.c.
◆ hpet_ns_per_tick()
| static clock_t hpet_ns_per_tick |
( |
void |
| ) |
|
|
inlinestatic |
Get the HPET clock period in nanoseconds.
- Returns
- The HPET clock period in nanoseconds.
Definition at line 133 of file hpet.c.
◆ hpet_read_ns_counter()
| static clock_t hpet_read_ns_counter |
( |
void |
| ) |
|
|
static |
Safely read the HPET counter value in nanoseconds.
- Returns
- The current value of the HPET counter in nanoseconds.
Definition at line 143 of file hpet.c.
◆ hpet_reset_counter()
| static void hpet_reset_counter |
( |
void |
| ) |
|
|
inlinestatic |
Reset the HPET main counter to zero and enable the HPET.
Definition at line 158 of file hpet.c.
◆ hpet_overflow_thread()
| static void hpet_overflow_thread |
( |
void * |
arg | ) |
|
|
static |
Thread function that periodically accumulates the HPET counter to prevent overflow.
- Parameters
-
Definition at line 170 of file hpet.c.
◆ hpet_init()
Initialize the HPET.
- Returns
- On success,
0. On failure, ERR.
Definition at line 205 of file hpet.c.
◆ hpet_deinit()
| static void hpet_deinit |
( |
void |
| ) |
|
|
static |
Deinitialize the HPET.
Definition at line 264 of file hpet.c.
◆ hpet
Pointer to the HPET ACPI table.
Definition at line 95 of file hpet.c.
◆ address
Mapped virtual address of the HPET registers.
Definition at line 96 of file hpet.c.
◆ period
Main counter tick period in femtoseconds (10^-15 s).
Definition at line 97 of file hpet.c.
◆ counter
Accumulated nanosecond counter, used to avoid overflows.
Definition at line 99 of file hpet.c.
◆ counterLock
Seqlock for the accumulated counter.
Definition at line 100 of file hpet.c.
◆ overflowThreadTid
| tid_t overflowThreadTid = 0 |
|
static |
Thread ID of the overflow thread.
Definition at line 102 of file hpet.c.
◆ overflowQueue
Wait queue for the overflow thread.
Definition at line 103 of file hpet.c.
◆ overflowShouldStop
Flag to signal the overflow thread to stop.
Definition at line 104 of file hpet.c.
◆ source
Initial value:= {
.name = "HPET",
.precision = 0,
}
static clock_t hpet_read_ns_counter(void)
Safely read the HPET counter value in nanoseconds.
#define NULL
Pointer error value.
Structure to describe the HPET to the sys time subsystem.
Definition at line 193 of file hpet.c.