aarch32_cpu/generic_timer/
el2.rs1use core::marker::PhantomData;
4
5use crate::register;
6
7use super::{El1PhysicalTimer, El1VirtualTimer, GenericTimer};
8
9pub struct El2PhysicalTimer(El1PhysicalTimer);
17
18impl El2PhysicalTimer {
19 pub unsafe fn new() -> El2PhysicalTimer {
27 unsafe { El2PhysicalTimer(El1PhysicalTimer::new()) }
28 }
29
30 pub fn frequency_hz_set(&mut self, new_frequency_hz: u32) {
37 register::Cntfrq::write(register::Cntfrq(new_frequency_hz))
38 }
39}
40
41impl GenericTimer for El2PhysicalTimer {
42 fn frequency_hz(&self) -> u32 {
43 self.0.frequency_hz()
44 }
45
46 fn counter(&self) -> u64 {
47 self.0.counter()
48 }
49
50 fn counter_compare(&self) -> u64 {
51 self.0.counter_compare()
52 }
53
54 fn counter_compare_set(&mut self, value: u64) {
55 self.0.counter_compare_set(value)
56 }
57
58 fn countdown(&self) -> u32 {
59 self.0.countdown()
60 }
61
62 fn countdown_set(&mut self, duration_ticks: u32) {
63 self.0.countdown_set(duration_ticks)
64 }
65
66 fn enabled(&self) -> bool {
67 self.0.enabled()
68 }
69
70 fn enable(&self, enabled: bool) {
71 self.0.enable(enabled)
72 }
73
74 fn interrupt_masked(&self) -> bool {
75 self.0.interrupt_masked()
76 }
77
78 fn interrupt_mask(&mut self, mask: bool) {
79 self.0.interrupt_mask(mask)
80 }
81
82 fn interrupt_status(&self) -> bool {
83 self.0.interrupt_status()
84 }
85}
86
87pub struct El2VirtualTimer(El1VirtualTimer);
95
96impl El2VirtualTimer {
97 pub unsafe fn new() -> El2VirtualTimer {
105 unsafe { El2VirtualTimer(El1VirtualTimer::new()) }
106 }
107
108 pub fn frequency_hz_set(&mut self, new_frequency_hz: u32) {
115 register::Cntfrq::write(register::Cntfrq(new_frequency_hz))
116 }
117}
118
119impl GenericTimer for El2VirtualTimer {
120 fn frequency_hz(&self) -> u32 {
121 self.0.frequency_hz()
122 }
123
124 fn counter(&self) -> u64 {
125 self.0.counter()
126 }
127
128 fn counter_compare(&self) -> u64 {
129 self.0.counter_compare()
130 }
131
132 fn counter_compare_set(&mut self, value: u64) {
133 self.0.counter_compare_set(value)
134 }
135
136 fn countdown(&self) -> u32 {
137 self.0.countdown()
138 }
139
140 fn countdown_set(&mut self, duration_ticks: u32) {
141 self.0.countdown_set(duration_ticks)
142 }
143
144 fn enabled(&self) -> bool {
145 self.0.enabled()
146 }
147
148 fn enable(&self, enabled: bool) {
149 self.0.enable(enabled)
150 }
151
152 fn interrupt_masked(&self) -> bool {
153 self.0.interrupt_masked()
154 }
155
156 fn interrupt_mask(&mut self, mask: bool) {
157 self.0.interrupt_mask(mask)
158 }
159
160 fn interrupt_status(&self) -> bool {
161 self.0.interrupt_status()
162 }
163}
164
165pub struct El2HypPhysicalTimer {
173 _phantom: PhantomData<*const u8>,
174}
175
176impl El2HypPhysicalTimer {
177 pub unsafe fn new() -> El2HypPhysicalTimer {
186 El2HypPhysicalTimer {
187 _phantom: PhantomData,
188 }
189 }
190}
191
192impl super::GenericTimer for El2HypPhysicalTimer {
193 fn frequency_hz(&self) -> u32 {
194 register::Cntfrq::read().0
195 }
196
197 fn counter(&self) -> u64 {
198 register::CntPct::read().0
199 }
200
201 fn counter_compare(&self) -> u64 {
202 register::CnthpCval::read().0
203 }
204
205 fn counter_compare_set(&mut self, value: u64) {
206 register::CnthpCval::write(register::CnthpCval(value))
207 }
208
209 fn countdown(&self) -> u32 {
210 register::CnthpTval::read().0
211 }
212
213 fn countdown_set(&mut self, duration_ticks: u32) {
214 register::CnthpTval::write(register::CnthpTval(duration_ticks))
215 }
216
217 fn enabled(&self) -> bool {
218 register::CnthpCtl::read().enable()
219 }
220
221 fn enable(&self, enabled: bool) {
222 register::CnthpCtl::modify(|r| {
223 r.set_enable(enabled);
224 });
225 }
226
227 fn interrupt_masked(&self) -> bool {
228 register::CnthpCtl::read().imask()
229 }
230
231 fn interrupt_mask(&mut self, mask: bool) {
232 register::CnthpCtl::modify(|r| {
233 r.set_imask(mask);
234 });
235 }
236
237 fn interrupt_status(&self) -> bool {
238 register::CnthpCtl::read().istatus()
239 }
240}