#pragma once

#include <kernel/InterruptController.h>
#include <kernel/Timer/Timer.h>

namespace Kernel
{

	class HPET final : public Timer, public Interruptable
	{
	public:
		static BAN::ErrorOr<BAN::UniqPtr<HPET>> create(bool force_pic);

		virtual uint64_t ms_since_boot() const override;
		virtual uint64_t ns_since_boot() const override;
		virtual timespec time_since_boot() const override;

		virtual void handle_irq() override;

	private:
		HPET() = default;
		BAN::ErrorOr<void> initialize(bool force_pic);

		void write_register(ptrdiff_t reg, uint64_t value) const;
		uint64_t read_register(ptrdiff_t reg) const;

	private:
		uint64_t m_counter_tick_period_fs { 0 };
		vaddr_t m_mmio_base { 0 };
	};

}
