strat9_kernel/hardware/timer/mod.rs
1/*
2 * This file is part of strat9-os.
3 *
4 * strat9-os is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * strat9-os is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with strat9-os. If not, see <https://www.gnu.org/licenses/>.
16 *
17 * Website: https://www.strat9-os.org
18 * Repository: https://github.com/strat9-os/strat9-os
19 *
20 * Copyright (C) 2023-26 Guillaume Gielly
21 */
22
23// Timer subsystem
24//
25// Provides:
26// - HPET (High Precision Event Timer)
27// - RTC (Real Time Clock)
28// - PIT (Programmable Interval Timer) - legacy
29
30pub mod hpet;
31pub mod rtc;
32
33use core::sync::atomic::{AtomicBool, Ordering};
34
35/// `hardware::init()` and the component graph both run the hardware stage.
36static INITIALIZED: AtomicBool = AtomicBool::new(false);
37
38/// Performs the init operation.
39///
40/// Idempotent: the component `timer_init` runs after `hardware::init()` has
41/// already probed HPET and RTC.
42pub fn init() {
43 if INITIALIZED.swap(true, Ordering::AcqRel) {
44 return;
45 }
46 log::info!("[TIMER] Initializing timers...");
47
48 // Initialize HPET first (high precision)
49 if let Err(e) = hpet::init() {
50 log::warn!("[TIMER] HPET init failed: {}", e);
51 }
52
53 // Initialize RTC (real-time clock)
54 if let Err(e) = rtc::init() {
55 log::warn!("[TIMER] RTC init failed: {}", e);
56 }
57
58 log::info!("[TIMER] Timer subsystem initialized");
59}