|
PatchworkOS
|
High Precision Event Timer. More...
Data Structures | |
| struct | hpet_t |
| High Precision Event Timer structure. More... | |
Macros | |
| #define | HPET_CAP_COUNTER_CLK_PERIOD_SHIFT 32 |
| The bit offset of the clock period in the capabilities register. | |
| #define | HPET_CONF_ENABLE_CNF_BIT (1 << 0) |
| The bit to set to enable the HPET in the configuration register. | |
| #define | HPET_CONF_LEG_RT_CNF_BIT (1 << 1) |
| The bit to set to enable legacy replacement mode in the configuration register. | |
| #define | HPET_ADDRESS_SPACE_MEMORY 0 |
If hpet_t::addressSpaceId is equal to this, the address is in system memory space. | |
| #define | HPET_ADDRESS_SPACE_IO 1 |
If hpet_t::addressSpaceId is equal to this, the address is in system I/O space. | |
| #define | HPET_FEMTOSECONDS_PER_SECOND 1000000000000000ULL |
| The number of femtoseconds in one second. | |
Enumerations | |
| enum | hpet_register_t { HPET_REG_GENERAL_CAPABILITIES_ID = 0x000 , HPET_REG_GENERAL_CONFIG = 0x010 , HPET_REG_GENERAL_INTERRUPT = 0x020 , HPET_REG_MAIN_COUNTER_VALUE = 0x0F0 , HPET_REG_TIMER0_CONFIG_CAP = 0x100 , HPET_REG_TIMER0_COMPARATOR = 0x108 } |
| HPET register offsets. More... | |
Functions | |
| clock_t | hpet_nanoseconds_per_tick (void) |
| Retrieve the number of nanoseconds per HPET tick. | |
| uint64_t | hpet_read_counter (void) |
| Read the current value of the HPET main counter. | |
| void | hpet_reset_counter (void) |
| Reset the HPET main counter to 0 and enable the HPET. | |
| void | hpet_write (uint64_t reg, uint64_t value) |
| Write a value to an HPET register. | |
| uint64_t | hpet_read (uint64_t reg) |
| Read a value from an HPET register. | |
| void | hpet_wait (clock_t nanoseconds) |
| Wait for a specified number of nanoseconds using the HPET. | |
High Precision Event Timer.
The HPET is initalized via the ACPI sdt registration system.
| #define HPET_ADDRESS_SPACE_IO 1 |
If hpet_t::addressSpaceId is equal to this, the address is in system I/O space.
| #define HPET_ADDRESS_SPACE_MEMORY 0 |
If hpet_t::addressSpaceId is equal to this, the address is in system memory space.
| #define HPET_CAP_COUNTER_CLK_PERIOD_SHIFT 32 |
| #define HPET_CONF_ENABLE_CNF_BIT (1 << 0) |
| #define HPET_CONF_LEG_RT_CNF_BIT (1 << 1) |
| #define HPET_FEMTOSECONDS_PER_SECOND 1000000000000000ULL |
| enum hpet_register_t |
| clock_t hpet_nanoseconds_per_tick | ( | void | ) |
Retrieve the number of nanoseconds per HPET tick.
If the HPET is not initialized, this function will return 0.
Definition at line 57 of file hpet.c.
References CLOCKS_PER_SEC, HPET_FEMTOSECONDS_PER_SECOND, isInitialized, and period.
Referenced by timer_accumulate(), and timer_uptime().
Read a value from an HPET register.
| reg | The register to read from |
Definition at line 95 of file hpet.c.
References address, isInitialized, NULL, panic(), and READ_64.
Referenced by hpet_init(), and hpet_read_counter().
| uint64_t hpet_read_counter | ( | void | ) |
Read the current value of the HPET main counter.
If the HPET is not initialized, this function will return 0.
Definition at line 66 of file hpet.c.
References hpet_read(), HPET_REG_MAIN_COUNTER_VALUE, and isInitialized.
Referenced by hpet_wait(), timer_accumulate(), and timer_uptime().
| void hpet_reset_counter | ( | void | ) |
Reset the HPET main counter to 0 and enable the HPET.
If the HPET is not initialized, this function does nothing.
Definition at line 75 of file hpet.c.
References HPET_CONF_ENABLE_CNF_BIT, HPET_REG_GENERAL_CONFIG, HPET_REG_MAIN_COUNTER_VALUE, hpet_write(), and isInitialized.
Referenced by hpet_init(), and timer_accumulate().
| void hpet_wait | ( | clock_t | nanoseconds | ) |
Wait for a specified number of nanoseconds using the HPET.
This function uses a busy-wait loop, meaning its very CPU inefficient, but its usefull during early initialization or when you are unable to block the current thread.
| nanoseconds | The number of nanoseconds to wait |
Definition at line 104 of file hpet.c.
References hpet_read_counter(), isInitialized, NULL, panic(), period, and start().
Referenced by apic_timer_ticks_per_ns(), ps2_device_init(), ps2_drain(), trampoline_send_startup_ipi(), and trampoline_wait_ready().
Write a value to an HPET register.
| reg | The register to write to |
| value | The value to write |
Definition at line 86 of file hpet.c.
References address, isInitialized, NULL, panic(), and WRITE_64.
Referenced by hpet_reset_counter().