diff --git a/kernel/include/timer.hpp b/kernel/include/timer.hpp index 784300e0..1d7af4b7 100644 --- a/kernel/include/timer.hpp +++ b/kernel/include/timer.hpp @@ -19,6 +19,16 @@ uint64_t seconds(); void tick(); +/*! + * \brief Return the frequency in Hz of the current timer system. + */ +uint64_t frequency(); + +/*! + * \brief Sets the frequency in Hz of the current timer system. + */ +void frequency(uint64_t freq); + } //end of timer namespace #endif diff --git a/kernel/src/drivers/pit.cpp b/kernel/src/drivers/pit.cpp index eeee9415..d836dab3 100644 --- a/kernel/src/drivers/pit.cpp +++ b/kernel/src/drivers/pit.cpp @@ -28,6 +28,9 @@ bool pit::install(){ out_byte(0x40, static_cast(divisor)); out_byte(0x40, static_cast(divisor >> 8)); + // Indicate the timer frequency + timer::frequency(1000); + if(!interrupt::register_irq_handler(0, timer_handler, nullptr)){ logging::logf(logging::log_level::ERROR, "Unable to register PIT 0\n"); diff --git a/kernel/src/timer.cpp b/kernel/src/timer.cpp index 15ebdb4d..3ff2c2b7 100644 --- a/kernel/src/timer.cpp +++ b/kernel/src/timer.cpp @@ -19,6 +19,7 @@ namespace { uint64_t _timer_ticks = 0; uint64_t _timer_seconds = 0; +uint64_t _timer_frequency = 0; volatile uint64_t _timer_countdown = 0; @@ -74,3 +75,13 @@ uint64_t timer::ticks(){ uint64_t timer::seconds(){ return _timer_seconds; } + +uint64_t timer::frequency(){ + return _timer_frequency; +} + +void timer::frequency(uint64_t freq){ + _timer_frequency = freq; + + logging::logf(logging::log_level::DEBUG, "timer: Frequency set to %u Hz\n", freq); +}