1
1
//! Clock configuration
2
- use crate :: core:: clint:: MTIME ;
3
2
use crate :: time:: Hertz ;
4
- use e310x:: { Aonclk as AONCLK , Prci as PRCI } ;
3
+ use e310x:: { Aonclk as AONCLK , Prci as PRCI , CLINT } ;
5
4
use riscv:: interrupt;
6
5
use riscv:: register:: mcycle;
7
6
@@ -175,10 +174,10 @@ impl CoreClk {
175
174
/// The resulting frequency may differ by 0-2% from the requested
176
175
fn configure_pll ( & self , pllref_freq : Hertz , divout_freq : Hertz ) -> Hertz {
177
176
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 ) ;
179
178
180
179
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 ) ;
182
181
183
182
// Calculate PLL Output Divider settings
184
183
let divider_div;
@@ -205,7 +204,7 @@ impl CoreClk {
205
204
2 * ( divider_div + 1 )
206
205
} ;
207
206
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 ) ;
209
208
210
209
// Calculate PLL R ratio
211
210
let r = match pllref_freq {
@@ -218,7 +217,7 @@ impl CoreClk {
218
217
219
218
// Calculate refr frequency
220
219
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 ) ;
222
221
223
222
// Calculate PLL Q ratio
224
223
let q = match pllout_freq {
@@ -230,7 +229,7 @@ impl CoreClk {
230
229
231
230
// Calculate the desired vco frequency
232
231
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 ) ;
234
233
235
234
// Calculate PLL F ratio
236
235
let f = target_vco_freq / refr_freq;
@@ -249,15 +248,15 @@ impl CoreClk {
249
248
} else {
250
249
( f_lo, vco_lo)
251
250
} ;
252
- assert ! ( ( VCO_MIN ..= VCO_MAX ) . contains ( & vco_freq) ) ;
251
+ assert ! ( VCO_MIN <= vco_freq && vco_freq <= VCO_MAX ) ;
253
252
254
253
// Calculate actual pllout frequency
255
254
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 ) ;
257
256
258
257
// Calculate actual divout frequency
259
258
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 ) ;
261
260
262
261
// Calculate bit-values
263
262
let r: u8 = ( r - 1 ) as u8 ;
@@ -291,9 +290,9 @@ impl CoreClk {
291
290
// Need to wait 100 us
292
291
// RTC is running at 32kHz.
293
292
// 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 { }
297
296
// Now it is safe to check for PLL Lock
298
297
while !prci. pllcfg ( ) . read ( ) . lock ( ) . bit_is_set ( ) { }
299
298
@@ -385,19 +384,19 @@ impl Clocks {
385
384
386
385
/// Measure the coreclk frequency by counting the number of aonclk ticks.
387
386
fn _measure_coreclk ( & self , min_ticks : u64 ) -> Hertz {
388
- let mtime = MTIME ;
387
+ let mtime = CLINT :: mtimer ( ) . mtime ;
389
388
interrupt:: free ( || {
390
389
// Don't start measuring until we see an mtime tick
391
- while mtime. mtime ( ) == mtime. mtime ( ) { }
390
+ while mtime. read ( ) == mtime. read ( ) { }
392
391
393
392
let start_cycle = mcycle:: read64 ( ) ;
394
- let start_time = mtime. mtime ( ) ;
393
+ let start_time = mtime. read ( ) ;
395
394
396
395
// Wait for min_ticks to pass
397
- while start_time + min_ticks > mtime. mtime ( ) { }
396
+ while start_time + min_ticks > mtime. read ( ) { }
398
397
399
398
let end_cycle = mcycle:: read64 ( ) ;
400
- let end_time = mtime. mtime ( ) ;
399
+ let end_time = mtime. read ( ) ;
401
400
402
401
let delta_cycle: u64 = end_cycle - start_cycle;
403
402
let delta_time: u64 = end_time - start_time;
0 commit comments