9#ifndef MAXOS_HARDWARECOMMUNICATION_CLOCK_H
10#define MAXOS_HARDWARECOMMUNICATION_CLOCK_H
14#include <libcommon/time.h>
15#include <libcommon/vector.h>
16#include <libcommon/event.h>
22namespace MaxOS::hardwarecommunication {
52 INTERRUPT_ON_TERMINAL_COUNT,
100 uint64_t m_ticks { 0 };
103 common::Port8Bit m_data_port;
104 common::Port8Bit m_command_port;
111 void handle_interrupt()
final;
112 uint32_t ticks_per_ms();
127 uint64_t m_ticks { 0 };
129 bool m_binary =
true;
130 bool m_24_hour_clock =
true;
133 common::Port8Bit m_data_port { 0x71 };
134 common::Port8Bit m_command_port { 0x70 };
140 uint16_t m_ticks_between_events = 0;
141 uint16_t m_ticks_until_next_event = 1;
142 uint64_t m_pit_ticks_per_ms = 0;
145 void handle_interrupt()
final;
146 uint8_t read_hardware_clock(uint8_t address);
147 [[nodiscard]] uint8_t binary_representation(uint8_t number)
const;
149 inline static Clock* s_active_clock =
nullptr;
158 void delay(uint32_t milliseconds)
const;
160 void calibrate(uint64_t ms_per_tick = 1);
Defines classes and structures for handling the Advanced Programmable Interrupt Controller (APIC) in ...
Handles both the Local APIC (boot core) and IO APIC.
Driver for the APIC clock.
common::time_t get_time()
Reads the current time from the APIC clock (in 24hr time)
uint64_t clock_accuracy
How accurate the clock is in microseconds (how often should an interrupt be raised)
void setup_apic_clock(LocalAPIC *local_apic) const
Sets up the APIC clock to fire interrupts at the desired rate.
void delay(uint32_t milliseconds) const
Delays the program for a specified number of milliseconds (rounded up to the nearest degree of accura...
static Clock * active_clock()
Gets the currently active clock.
void calibrate(uint64_t ms_per_tick=1)
Configures the APIC clock to fire an interrupt at a specified interval in milliseconds.
Handles the IO APIC in the system (one per system)
Handles a certain interrupt number.
Handles the local APIC for the current core.
Driver for the Programmable Interval Timer.
AccessMode
What mode should the PIT use for the selected channel.
BCDMode
Specifies the data encoding mode used by the PIT.
OperatingMode
What should the PIT do.
constexpr uint16_t TICK_CALIBRATE_LENGTH
How many loops to spin for calibration.
Channel
Where should the PIT raise an event to.
Defines a InterruptManager and InterruptHandler for managing hardware and software interrupts.
The command byte to send to the PIT, specifies the channel, access mode, operating mode and BCD mode.
uint8_t channel
Which channel to configure.
uint8_t operating_mode
What mode the PIT should operate in.
uint8_t access_mode
How the data is accessed.
uint8_t bcd_mode
0 = binary, 1 = BCD