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
//! Board-specific clock configuration

use e310x_hal::{
    e310x::{PRCI, AONCLK},
    clock::{Clocks, PrciExt, AonExt},
    time::Hertz,
};

#[cfg(any(feature = "board-hifive1", feature = "board-hifive1-revb"))]
/// Configures clock generation system.
///
/// For HiFive1 and HiFive1 Rev B boards external oscillators are enabled for
/// both high-frequency and low-frequency clocks.
pub fn configure(prci: PRCI, aonclk: AONCLK, target_coreclk: Hertz) -> Clocks {
    let coreclk = prci.constrain();
    let coreclk = coreclk.use_external(Hertz(16_000_000)).coreclk(target_coreclk);

    let aonclk = aonclk.constrain();
    let aonclk = aonclk.use_external(Hertz(32_768));

    Clocks::freeze(coreclk, aonclk)
}

#[cfg(any(feature = "board-lofive", feature = "board-lofive-r1"))]
/// Configures clock generation system.
///
/// For the LoFive and LoFive R1 boards, external oscillator is enabled for
/// high-frequency clock. For low-frequency clock internal oscillator is used.
pub fn configure(prci: PRCI, aonclk: AONCLK, target_coreclk: Hertz) -> Clocks {
    let coreclk = prci.constrain();
    let coreclk = coreclk.use_external(Hertz(16_000_000)).coreclk(target_coreclk);

    let aonclk = aonclk.constrain();

    Clocks::freeze(coreclk, aonclk)
}