File size: 868 Bytes
433dc73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// ==============================================================================
// VYRON Micro-OS - Timer Interrupt & Preemption Subsystem
// Layer 6: Timer-Driven Scheduling
// ==============================================================================

pub struct HardwareTimer {
    pub tick_interval_ms: u32,
    pub ticks_fired: u64,
    pub is_enabled: bool,
}

impl HardwareTimer {
    pub fn new(interval_ms: u32) -> Self {
        Self {
            tick_interval_ms: interval_ms,
            ticks_fired: 0,
            is_enabled: true,
        }
    }

    pub fn trigger_interrupt(&mut self) -> u64 {
        if self.is_enabled {
            self.ticks_fired += 1;
        }
        self.ticks_fired
    }

    pub fn disable(&mut self) {
        self.is_enabled = false;
    }

    pub fn enable(&mut self) {
        self.is_enabled = true;
    }
}