11//! Clock configuration
2- use crate :: core:: clint:: MTIME ;
32use crate :: time:: Hertz ;
4- use e310x:: { Aonclk as AONCLK , Prci as PRCI } ;
3+ use e310x:: { Aonclk as AONCLK , Prci as PRCI , CLINT } ;
54use riscv:: interrupt;
65use riscv:: register:: mcycle;
76
@@ -175,10 +174,10 @@ impl CoreClk {
175174 /// The resulting frequency may differ by 0-2% from the requested
176175 fn configure_pll ( & self , pllref_freq : Hertz , divout_freq : Hertz ) -> Hertz {
177176 let pllref_freq = pllref_freq. 0 ;
178- assert ! ( ( PLLREF_MIN ..= PLLREF_MAX ) . contains ( & pllref_freq) ) ;
177+ assert ! ( PLLREF_MIN <= pllref_freq && pllref_freq <= PLLREF_MAX ) ;
179178
180179 let divout_freq = divout_freq. 0 ;
181- assert ! ( ( DIVOUT_MIN ..= DIVOUT_MAX ) . contains ( & divout_freq) ) ;
180+ assert ! ( DIVOUT_MIN <= divout_freq && divout_freq <= DIVOUT_MAX ) ;
182181
183182 // Calculate PLL Output Divider settings
184183 let divider_div;
@@ -205,7 +204,7 @@ impl CoreClk {
205204 2 * ( divider_div + 1 )
206205 } ;
207206 let pllout_freq = divout_freq * d;
208- assert ! ( ( PLLOUT_MIN ..= PLLOUT_MAX ) . contains ( & pllout_freq) ) ;
207+ assert ! ( PLLOUT_MIN <= pllout_freq && pllout_freq <= PLLOUT_MAX ) ;
209208
210209 // Calculate PLL R ratio
211210 let r = match pllref_freq {
@@ -218,7 +217,7 @@ impl CoreClk {
218217
219218 // Calculate refr frequency
220219 let refr_freq = pllref_freq / r;
221- assert ! ( ( REFR_MIN ..= REFR_MAX ) . contains ( & refr_freq) ) ;
220+ assert ! ( REFR_MIN <= refr_freq && refr_freq <= REFR_MAX ) ;
222221
223222 // Calculate PLL Q ratio
224223 let q = match pllout_freq {
@@ -230,7 +229,7 @@ impl CoreClk {
230229
231230 // Calculate the desired vco frequency
232231 let target_vco_freq = pllout_freq * q;
233- assert ! ( ( VCO_MIN ..= VCO_MAX ) . contains ( & target_vco_freq) ) ;
232+ assert ! ( VCO_MIN <= target_vco_freq && target_vco_freq <= VCO_MAX ) ;
234233
235234 // Calculate PLL F ratio
236235 let f = target_vco_freq / refr_freq;
@@ -249,15 +248,15 @@ impl CoreClk {
249248 } else {
250249 ( f_lo, vco_lo)
251250 } ;
252- assert ! ( ( VCO_MIN ..= VCO_MAX ) . contains ( & vco_freq) ) ;
251+ assert ! ( VCO_MIN <= vco_freq && vco_freq <= VCO_MAX ) ;
253252
254253 // Calculate actual pllout frequency
255254 let pllout_freq = vco_freq / q;
256- assert ! ( ( PLLOUT_MIN ..= PLLOUT_MAX ) . contains ( & pllout_freq) ) ;
255+ assert ! ( PLLOUT_MIN <= pllout_freq && pllout_freq <= PLLOUT_MAX ) ;
257256
258257 // Calculate actual divout frequency
259258 let divout_freq = pllout_freq / d;
260- assert ! ( ( DIVOUT_MIN ..= DIVOUT_MAX ) . contains ( & divout_freq) ) ;
259+ assert ! ( DIVOUT_MIN <= divout_freq && divout_freq <= DIVOUT_MAX ) ;
261260
262261 // Calculate bit-values
263262 let r: u8 = ( r - 1 ) as u8 ;
@@ -291,9 +290,9 @@ impl CoreClk {
291290 // Need to wait 100 us
292291 // RTC is running at 32kHz.
293292 // So wait 4 ticks of RTC.
294- let mtime = MTIME ;
295- let time = mtime. mtime ( ) + 4 ;
296- while mtime. mtime ( ) < time { }
293+ let mtime = CLINT :: mtimer ( ) . mtime ;
294+ let time = mtime. read ( ) + 4 ;
295+ while mtime. read ( ) < time { }
297296 // Now it is safe to check for PLL Lock
298297 while !prci. pllcfg ( ) . read ( ) . lock ( ) . bit_is_set ( ) { }
299298
@@ -385,19 +384,19 @@ impl Clocks {
385384
386385 /// Measure the coreclk frequency by counting the number of aonclk ticks.
387386 fn _measure_coreclk ( & self , min_ticks : u64 ) -> Hertz {
388- let mtime = MTIME ;
387+ let mtime = CLINT :: mtimer ( ) . mtime ;
389388 interrupt:: free ( || {
390389 // Don't start measuring until we see an mtime tick
391- while mtime. mtime ( ) == mtime. mtime ( ) { }
390+ while mtime. read ( ) == mtime. read ( ) { }
392391
393392 let start_cycle = mcycle:: read64 ( ) ;
394- let start_time = mtime. mtime ( ) ;
393+ let start_time = mtime. read ( ) ;
395394
396395 // Wait for min_ticks to pass
397- while start_time + min_ticks > mtime. mtime ( ) { }
396+ while start_time + min_ticks > mtime. read ( ) { }
398397
399398 let end_cycle = mcycle:: read64 ( ) ;
400- let end_time = mtime. mtime ( ) ;
399+ let end_time = mtime. read ( ) ;
401400
402401 let delta_cycle: u64 = end_cycle - start_cycle;
403402 let delta_time: u64 = end_time - start_time;
0 commit comments