2021-11-29 11:17:59 +08:00
|
|
|
use embedded_hal::blocking::delay::DelayMs;
|
2023-09-04 16:04:42 +08:00
|
|
|
#[cfg(has_si5324)]
|
2023-09-05 16:21:39 +08:00
|
|
|
use ksupport::i2c;
|
2021-11-29 11:17:59 +08:00
|
|
|
use libboard_artiq::pl;
|
|
|
|
#[cfg(has_si5324)]
|
2023-02-22 11:02:43 +08:00
|
|
|
use libboard_artiq::si5324;
|
2024-03-11 15:04:05 +08:00
|
|
|
#[cfg(has_si549)]
|
|
|
|
use libboard_artiq::si549;
|
2023-02-22 11:02:43 +08:00
|
|
|
#[cfg(has_si5324)]
|
2021-11-29 11:17:59 +08:00
|
|
|
use libboard_zynq::i2c::I2c;
|
2023-02-22 11:02:43 +08:00
|
|
|
use libboard_zynq::timer::GlobalTimer;
|
|
|
|
use libconfig::Config;
|
|
|
|
use log::{info, warn};
|
|
|
|
|
2021-11-29 11:17:59 +08:00
|
|
|
#[derive(Debug, PartialEq, Copy, Clone)]
|
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
pub enum RtioClock {
|
|
|
|
Default,
|
|
|
|
Int_125,
|
|
|
|
Int_100,
|
|
|
|
Int_150,
|
|
|
|
Ext0_Bypass,
|
|
|
|
Ext0_Synth0_10to125,
|
2023-04-13 12:03:40 +08:00
|
|
|
Ext0_Synth0_80to125,
|
2021-11-29 11:17:59 +08:00
|
|
|
Ext0_Synth0_100to125,
|
|
|
|
Ext0_Synth0_125to125,
|
|
|
|
}
|
|
|
|
|
2021-12-03 17:19:42 +08:00
|
|
|
#[allow(unreachable_code)]
|
2021-11-29 11:17:59 +08:00
|
|
|
fn get_rtio_clock_cfg(cfg: &Config) -> RtioClock {
|
|
|
|
let mut res = RtioClock::Default;
|
|
|
|
if let Ok(clk) = cfg.read_str("rtio_clock") {
|
|
|
|
res = match clk.as_ref() {
|
|
|
|
"int_125" => RtioClock::Int_125,
|
|
|
|
"int_100" => RtioClock::Int_100,
|
|
|
|
"int_150" => RtioClock::Int_150,
|
|
|
|
"ext0_bypass" => RtioClock::Ext0_Bypass,
|
|
|
|
"ext0_bypass_125" => RtioClock::Ext0_Bypass,
|
|
|
|
"ext0_bypass_100" => RtioClock::Ext0_Bypass,
|
|
|
|
"ext0_synth0_10to125" => RtioClock::Ext0_Synth0_10to125,
|
2023-04-13 12:03:40 +08:00
|
|
|
"ext0_synth0_80to125" => RtioClock::Ext0_Synth0_80to125,
|
2021-11-29 11:17:59 +08:00
|
|
|
"ext0_synth0_100to125" => RtioClock::Ext0_Synth0_100to125,
|
|
|
|
"ext0_synth0_125to125" => RtioClock::Ext0_Synth0_125to125,
|
2023-02-22 11:02:43 +08:00
|
|
|
_ => {
|
2021-11-29 11:17:59 +08:00
|
|
|
warn!("Unrecognised rtio_clock setting. Falling back to default.");
|
2023-02-22 11:02:43 +08:00
|
|
|
RtioClock::Default
|
2021-11-29 11:17:59 +08:00
|
|
|
}
|
|
|
|
};
|
2023-02-22 11:02:43 +08:00
|
|
|
} else {
|
2021-11-29 11:17:59 +08:00
|
|
|
warn!("error reading configuration. Falling back to default.");
|
|
|
|
}
|
|
|
|
if res == RtioClock::Default {
|
2023-02-22 11:02:43 +08:00
|
|
|
#[cfg(rtio_frequency = "100.0")]
|
2021-12-03 17:19:42 +08:00
|
|
|
{
|
|
|
|
warn!("Using default configuration - internal 100MHz RTIO clock.");
|
|
|
|
return RtioClock::Int_100;
|
|
|
|
}
|
2023-02-22 11:02:43 +08:00
|
|
|
#[cfg(rtio_frequency = "125.0")]
|
2021-12-03 17:19:42 +08:00
|
|
|
{
|
|
|
|
warn!("Using default configuration - internal 125MHz RTIO clock.");
|
|
|
|
return RtioClock::Int_125;
|
|
|
|
}
|
|
|
|
// anything else
|
|
|
|
{
|
|
|
|
warn!("Using default configuration - internal 125MHz RTIO clock.");
|
|
|
|
return RtioClock::Int_125;
|
|
|
|
}
|
2021-11-29 11:17:59 +08:00
|
|
|
}
|
|
|
|
res
|
|
|
|
}
|
|
|
|
|
2023-02-17 15:52:43 +08:00
|
|
|
#[cfg(not(has_drtio))]
|
|
|
|
fn init_rtio(timer: &mut GlobalTimer) {
|
|
|
|
info!("Switching SYS clocks...");
|
2022-04-12 13:33:52 +08:00
|
|
|
unsafe {
|
2023-02-17 15:52:43 +08:00
|
|
|
pl::csr::sys_crg::clock_switch_write(1);
|
2022-04-12 13:33:52 +08:00
|
|
|
}
|
2023-02-17 15:52:43 +08:00
|
|
|
// if it's not locked, it will hang at the CSR.
|
|
|
|
|
2023-10-05 12:17:43 +08:00
|
|
|
timer.delay_ms(50); // wait for CPLL/QPLL/SYS PLL lock
|
2023-02-17 15:52:43 +08:00
|
|
|
let clk = unsafe { pl::csr::sys_crg::current_clock_read() };
|
|
|
|
if clk == 1 {
|
|
|
|
info!("SYS CLK switched successfully");
|
2022-04-12 13:33:52 +08:00
|
|
|
} else {
|
2023-02-17 15:52:43 +08:00
|
|
|
panic!("SYS CLK did not switch");
|
2021-11-29 11:17:59 +08:00
|
|
|
}
|
|
|
|
unsafe {
|
|
|
|
pl::csr::rtio_core::reset_phy_write(1);
|
|
|
|
}
|
2023-02-17 15:52:43 +08:00
|
|
|
info!("SYS PLL locked");
|
2021-11-29 11:17:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(has_drtio)]
|
2023-02-22 11:02:43 +08:00
|
|
|
fn init_drtio(timer: &mut GlobalTimer) {
|
2021-11-29 11:17:59 +08:00
|
|
|
unsafe {
|
2023-08-28 13:05:40 +08:00
|
|
|
pl::csr::gt_drtio::stable_clkin_write(1);
|
2021-11-29 11:17:59 +08:00
|
|
|
}
|
2023-02-22 11:02:43 +08:00
|
|
|
|
2023-10-05 12:17:43 +08:00
|
|
|
timer.delay_ms(50); // wait for CPLL/QPLL/SYS PLL lock
|
2023-02-17 15:52:43 +08:00
|
|
|
let clk = unsafe { pl::csr::sys_crg::current_clock_read() };
|
|
|
|
if clk == 1 {
|
|
|
|
info!("SYS CLK switched successfully");
|
|
|
|
} else {
|
|
|
|
panic!("SYS CLK did not switch");
|
|
|
|
}
|
2021-11-29 11:17:59 +08:00
|
|
|
unsafe {
|
2023-02-17 15:52:43 +08:00
|
|
|
pl::csr::rtio_core::reset_phy_write(1);
|
2023-08-28 13:05:40 +08:00
|
|
|
pl::csr::gt_drtio::txenable_write(0xffffffffu32 as _);
|
2023-10-10 10:47:24 +08:00
|
|
|
|
|
|
|
#[cfg(has_drtio_eem)]
|
|
|
|
pl::csr::eem_transceiver::txenable_write(0xffffffffu32 as _);
|
2021-11-29 11:17:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-13 07:17:49 +08:00
|
|
|
// Si5324 input to select for locking to an external clock.
|
|
|
|
#[cfg(has_si5324)]
|
|
|
|
const SI5324_EXT_INPUT: si5324::Input = si5324::Input::Ckin1;
|
|
|
|
|
2021-11-29 11:17:59 +08:00
|
|
|
#[cfg(has_si5324)]
|
|
|
|
fn setup_si5324(i2c: &mut I2c, timer: &mut GlobalTimer, clk: RtioClock) {
|
2022-12-17 09:31:14 +08:00
|
|
|
let (si5324_settings, si5324_ref_input) = match clk {
|
2023-02-22 11:02:43 +08:00
|
|
|
RtioClock::Ext0_Synth0_10to125 => {
|
|
|
|
// 125 MHz output from 10 MHz CLKINx reference, 504 Hz BW
|
2021-11-29 11:17:59 +08:00
|
|
|
info!("using 10MHz reference to make 125MHz RTIO clock with PLL");
|
2022-12-17 09:31:14 +08:00
|
|
|
(
|
|
|
|
si5324::FrequencySettings {
|
2023-02-22 11:02:43 +08:00
|
|
|
n1_hs: 10,
|
|
|
|
nc1_ls: 4,
|
|
|
|
n2_hs: 10,
|
|
|
|
n2_ls: 300,
|
|
|
|
n31: 6,
|
|
|
|
n32: 6,
|
|
|
|
bwsel: 4,
|
|
|
|
crystal_as_ckin2: false,
|
2022-12-17 09:31:14 +08:00
|
|
|
},
|
2023-02-22 11:02:43 +08:00
|
|
|
SI5324_EXT_INPUT,
|
2023-04-13 12:03:40 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
RtioClock::Ext0_Synth0_80to125 => {
|
|
|
|
// 125 MHz output from 80 MHz CLKINx reference, 611 Hz BW
|
|
|
|
info!("using 80MHz reference to make 125MHz RTIO clock with PLL");
|
|
|
|
(
|
|
|
|
si5324::FrequencySettings {
|
|
|
|
n1_hs: 4,
|
|
|
|
nc1_ls: 10,
|
|
|
|
n2_hs: 10,
|
|
|
|
n2_ls: 250,
|
|
|
|
n31: 40,
|
|
|
|
n32: 40,
|
|
|
|
bwsel: 4,
|
|
|
|
crystal_as_ckin2: false,
|
|
|
|
},
|
|
|
|
SI5324_EXT_INPUT,
|
2022-12-17 09:31:14 +08:00
|
|
|
)
|
2023-02-22 11:02:43 +08:00
|
|
|
}
|
|
|
|
RtioClock::Ext0_Synth0_100to125 => {
|
|
|
|
// 125MHz output, from 100MHz CLKINx reference, 586 Hz loop bandwidth
|
2022-03-03 10:24:13 +08:00
|
|
|
info!("using 100MHz reference to make 125MHz RTIO clock with PLL");
|
2022-12-17 09:31:14 +08:00
|
|
|
(
|
|
|
|
si5324::FrequencySettings {
|
2023-02-22 11:02:43 +08:00
|
|
|
n1_hs: 10,
|
|
|
|
nc1_ls: 4,
|
|
|
|
n2_hs: 10,
|
|
|
|
n2_ls: 260,
|
|
|
|
n31: 52,
|
|
|
|
n32: 52,
|
|
|
|
bwsel: 4,
|
|
|
|
crystal_as_ckin2: false,
|
2022-12-17 09:31:14 +08:00
|
|
|
},
|
2023-02-22 11:02:43 +08:00
|
|
|
SI5324_EXT_INPUT,
|
2022-12-17 09:31:14 +08:00
|
|
|
)
|
2023-02-22 11:02:43 +08:00
|
|
|
}
|
|
|
|
RtioClock::Ext0_Synth0_125to125 => {
|
|
|
|
// 125MHz output, from 125MHz CLKINx reference, 606 Hz loop bandwidth
|
2022-03-03 10:24:13 +08:00
|
|
|
info!("using 125MHz reference to make 125MHz RTIO clock with PLL");
|
2022-12-17 09:31:14 +08:00
|
|
|
(
|
|
|
|
si5324::FrequencySettings {
|
2023-02-22 11:02:43 +08:00
|
|
|
n1_hs: 5,
|
|
|
|
nc1_ls: 8,
|
|
|
|
n2_hs: 7,
|
|
|
|
n2_ls: 360,
|
|
|
|
n31: 63,
|
|
|
|
n32: 63,
|
|
|
|
bwsel: 4,
|
|
|
|
crystal_as_ckin2: false,
|
2022-12-17 09:31:14 +08:00
|
|
|
},
|
2023-02-22 11:02:43 +08:00
|
|
|
SI5324_EXT_INPUT,
|
2022-12-17 09:31:14 +08:00
|
|
|
)
|
2023-02-22 11:02:43 +08:00
|
|
|
}
|
|
|
|
RtioClock::Int_150 => {
|
|
|
|
// 150MHz output, from crystal
|
2021-11-29 11:17:59 +08:00
|
|
|
info!("using internal 150MHz RTIO clock");
|
2022-12-17 09:31:14 +08:00
|
|
|
(
|
|
|
|
si5324::FrequencySettings {
|
2023-02-22 11:02:43 +08:00
|
|
|
n1_hs: 9,
|
|
|
|
nc1_ls: 4,
|
|
|
|
n2_hs: 10,
|
|
|
|
n2_ls: 33732,
|
|
|
|
n31: 7139,
|
|
|
|
n32: 7139,
|
|
|
|
bwsel: 3,
|
|
|
|
crystal_as_ckin2: true,
|
2022-12-17 09:31:14 +08:00
|
|
|
},
|
2023-02-22 11:02:43 +08:00
|
|
|
si5324::Input::Ckin2,
|
2022-12-17 09:31:14 +08:00
|
|
|
)
|
2023-02-22 11:02:43 +08:00
|
|
|
}
|
|
|
|
RtioClock::Int_100 => {
|
|
|
|
// 100MHz output, from crystal
|
2021-11-29 11:17:59 +08:00
|
|
|
info!("using internal 100MHz RTIO clock");
|
2022-12-17 09:31:14 +08:00
|
|
|
(
|
|
|
|
si5324::FrequencySettings {
|
2023-02-22 11:02:43 +08:00
|
|
|
n1_hs: 9,
|
|
|
|
nc1_ls: 6,
|
|
|
|
n2_hs: 10,
|
|
|
|
n2_ls: 33732,
|
|
|
|
n31: 7139,
|
|
|
|
n32: 7139,
|
|
|
|
bwsel: 3,
|
|
|
|
crystal_as_ckin2: true,
|
2022-12-17 09:31:14 +08:00
|
|
|
},
|
2023-02-22 11:02:43 +08:00
|
|
|
si5324::Input::Ckin2,
|
2022-12-17 09:31:14 +08:00
|
|
|
)
|
2023-02-22 11:02:43 +08:00
|
|
|
}
|
|
|
|
RtioClock::Int_125 => {
|
|
|
|
// 125MHz output, from crystal, 7 Hz
|
2021-11-29 11:17:59 +08:00
|
|
|
info!("using internal 125MHz RTIO clock");
|
2022-12-17 09:31:14 +08:00
|
|
|
(
|
|
|
|
si5324::FrequencySettings {
|
2023-02-22 11:02:43 +08:00
|
|
|
n1_hs: 10,
|
|
|
|
nc1_ls: 4,
|
|
|
|
n2_hs: 10,
|
|
|
|
n2_ls: 19972,
|
|
|
|
n31: 4565,
|
|
|
|
n32: 4565,
|
|
|
|
bwsel: 4,
|
|
|
|
crystal_as_ckin2: true,
|
2022-12-17 09:31:14 +08:00
|
|
|
},
|
2023-02-22 11:02:43 +08:00
|
|
|
si5324::Input::Ckin2,
|
2022-12-17 09:31:14 +08:00
|
|
|
)
|
2023-02-22 11:02:43 +08:00
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
// same setting as Int_125, but fallback to default
|
|
|
|
warn!(
|
|
|
|
"rtio_clock setting '{:?}' is unsupported. Falling back to default internal 125MHz RTIO clock.",
|
|
|
|
clk
|
|
|
|
);
|
2022-12-17 09:31:14 +08:00
|
|
|
(
|
|
|
|
si5324::FrequencySettings {
|
2023-02-22 11:02:43 +08:00
|
|
|
n1_hs: 10,
|
|
|
|
nc1_ls: 4,
|
|
|
|
n2_hs: 10,
|
|
|
|
n2_ls: 19972,
|
|
|
|
n31: 4565,
|
|
|
|
n32: 4565,
|
|
|
|
bwsel: 4,
|
|
|
|
crystal_as_ckin2: true,
|
2022-12-17 09:31:14 +08:00
|
|
|
},
|
2023-02-22 11:02:43 +08:00
|
|
|
si5324::Input::Ckin2,
|
2022-12-17 09:31:14 +08:00
|
|
|
)
|
2021-11-29 11:17:59 +08:00
|
|
|
}
|
|
|
|
};
|
2022-12-17 09:31:14 +08:00
|
|
|
si5324::setup(i2c, &si5324_settings, si5324_ref_input, timer).expect("cannot initialize Si5324");
|
2021-11-29 11:17:59 +08:00
|
|
|
}
|
|
|
|
|
2024-03-11 15:04:05 +08:00
|
|
|
#[cfg(has_si549)]
|
|
|
|
fn wrpll_setup(timer: &mut GlobalTimer, clk: RtioClock, si549_settings: &si549::FrequencySetting) {
|
|
|
|
// register values are directly copied from preconfigured mmcm
|
|
|
|
let (mmcm_setting, mmcm_bypass) = match clk {
|
|
|
|
RtioClock::Ext0_Synth0_10to125 => (
|
|
|
|
si549::wrpll_refclk::MmcmSetting {
|
|
|
|
// CLKFBOUT_MULT = 62.5, DIVCLK_DIVIDE = 1 , CLKOUT0_DIVIDE = 5
|
|
|
|
clkout0_reg1: 0x1083,
|
|
|
|
clkout0_reg2: 0x0080,
|
|
|
|
clkfbout_reg1: 0x179e,
|
|
|
|
clkfbout_reg2: 0x4c00,
|
|
|
|
div_reg: 0x1041,
|
|
|
|
lock_reg1: 0x00fa,
|
|
|
|
lock_reg2: 0x7c01,
|
|
|
|
lock_reg3: 0xffe9,
|
|
|
|
power_reg: 0x9900,
|
|
|
|
filt_reg1: 0x0808,
|
|
|
|
filt_reg2: 0x0800,
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
RtioClock::Ext0_Synth0_80to125 => (
|
|
|
|
si549::wrpll_refclk::MmcmSetting {
|
|
|
|
// CLKFBOUT_MULT = 15.625, DIVCLK_DIVIDE = 1 , CLKOUT0_DIVIDE = 10
|
|
|
|
clkout0_reg1: 0x1145,
|
|
|
|
clkout0_reg2: 0x0000,
|
|
|
|
clkfbout_reg1: 0x11c7,
|
|
|
|
clkfbout_reg2: 0x5880,
|
|
|
|
div_reg: 0x1041,
|
|
|
|
lock_reg1: 0x028a,
|
|
|
|
lock_reg2: 0x7c01,
|
|
|
|
lock_reg3: 0xffe9,
|
|
|
|
power_reg: 0x9900,
|
|
|
|
filt_reg1: 0x0808,
|
|
|
|
filt_reg2: 0x9800,
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
RtioClock::Ext0_Synth0_100to125 => (
|
|
|
|
si549::wrpll_refclk::MmcmSetting {
|
|
|
|
// CLKFBOUT_MULT = 12.5, DIVCLK_DIVIDE = 1 , CLKOUT0_DIVIDE = 10
|
|
|
|
clkout0_reg1: 0x1145,
|
|
|
|
clkout0_reg2: 0x0000,
|
|
|
|
clkfbout_reg1: 0x1145,
|
|
|
|
clkfbout_reg2: 0x4c00,
|
|
|
|
div_reg: 0x1041,
|
|
|
|
lock_reg1: 0x0339,
|
|
|
|
lock_reg2: 0x7c01,
|
|
|
|
lock_reg3: 0xffe9,
|
|
|
|
power_reg: 0x9900,
|
|
|
|
filt_reg1: 0x0808,
|
|
|
|
filt_reg2: 0x9800,
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
RtioClock::Ext0_Synth0_125to125 => (
|
|
|
|
si549::wrpll_refclk::MmcmSetting {
|
|
|
|
// CLKFBOUT_MULT = 10, DIVCLK_DIVIDE = 1 , CLKOUT0_DIVIDE = 10
|
|
|
|
clkout0_reg1: 0x1145,
|
|
|
|
clkout0_reg2: 0x0000,
|
|
|
|
clkfbout_reg1: 0x1145,
|
|
|
|
clkfbout_reg2: 0x0000,
|
|
|
|
div_reg: 0x1041,
|
|
|
|
lock_reg1: 0x03e8,
|
|
|
|
lock_reg2: 0x7001,
|
|
|
|
lock_reg3: 0xf3e9,
|
|
|
|
power_reg: 0x0100,
|
|
|
|
filt_reg1: 0x0808,
|
|
|
|
filt_reg2: 0x1100,
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
|
|
|
si549::wrpll::helper_setup(timer, &si549_settings).expect("cannot initialize helper Si549");
|
|
|
|
si549::wrpll_refclk::setup(timer, mmcm_setting, mmcm_bypass).expect("cannot initialize ref clk for wrpll");
|
|
|
|
si549::wrpll::select_recovered_clock(true, timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(has_si549)]
|
|
|
|
fn get_si549_setting(clk: RtioClock) -> si549::FrequencySetting {
|
|
|
|
match clk {
|
|
|
|
RtioClock::Ext0_Synth0_10to125 => {
|
|
|
|
info!("using 10MHz reference to make 125MHz RTIO clock with WRPLL");
|
|
|
|
}
|
|
|
|
RtioClock::Ext0_Synth0_80to125 => {
|
|
|
|
info!("using 80MHz reference to make 125MHz RTIO clock with WRPLL");
|
|
|
|
}
|
|
|
|
RtioClock::Ext0_Synth0_100to125 => {
|
|
|
|
info!("using 100MHz reference to make 125MHz RTIO clock with WRPLL");
|
|
|
|
}
|
|
|
|
RtioClock::Ext0_Synth0_125to125 => {
|
|
|
|
info!("using 125MHz reference to make 125MHz RTIO clock with WRPLL");
|
|
|
|
}
|
|
|
|
RtioClock::Int_100 => {
|
|
|
|
info!("using internal 100MHz RTIO clock");
|
|
|
|
}
|
|
|
|
RtioClock::Int_125 => {
|
|
|
|
info!("using internal 125MHz RTIO clock");
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
warn!(
|
|
|
|
"rtio_clock setting '{:?}' is unsupported. Falling back to default internal 125MHz RTIO clock.",
|
|
|
|
clk
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
match clk {
|
|
|
|
RtioClock::Int_100 => {
|
|
|
|
si549::FrequencySetting {
|
|
|
|
main: si549::DividerConfig {
|
|
|
|
hsdiv: 0x06C,
|
|
|
|
lsdiv: 0,
|
|
|
|
fbdiv: 0x046C5F49797,
|
|
|
|
},
|
|
|
|
helper: si549::DividerConfig {
|
|
|
|
// 100Mhz*32767/32768
|
|
|
|
hsdiv: 0x06C,
|
|
|
|
lsdiv: 0,
|
|
|
|
fbdiv: 0x046C5670BBD,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
// Everything else use 125Mhz
|
|
|
|
si549::FrequencySetting {
|
|
|
|
main: si549::DividerConfig {
|
|
|
|
hsdiv: 0x058,
|
|
|
|
lsdiv: 0,
|
|
|
|
fbdiv: 0x04815791F25,
|
|
|
|
},
|
|
|
|
helper: si549::DividerConfig {
|
|
|
|
// 125Mhz*32767/32768
|
|
|
|
hsdiv: 0x058,
|
|
|
|
lsdiv: 0,
|
|
|
|
fbdiv: 0x04814E8F442,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-29 11:17:59 +08:00
|
|
|
pub fn init(timer: &mut GlobalTimer, cfg: &Config) {
|
|
|
|
let clk = get_rtio_clock_cfg(cfg);
|
|
|
|
#[cfg(has_si5324)]
|
|
|
|
{
|
|
|
|
let i2c = unsafe { (&mut i2c::I2C_BUS).as_mut().unwrap() };
|
|
|
|
match clk {
|
2023-10-06 15:21:51 +08:00
|
|
|
RtioClock::Ext0_Bypass => {
|
|
|
|
info!("bypassing the PLL for RTIO clock");
|
|
|
|
si5324::bypass(i2c, SI5324_EXT_INPUT, timer).expect("cannot bypass Si5324")
|
|
|
|
}
|
2021-11-29 11:17:59 +08:00
|
|
|
_ => setup_si5324(i2c, timer, clk),
|
|
|
|
}
|
|
|
|
}
|
2023-02-17 15:52:43 +08:00
|
|
|
|
2024-03-11 15:04:05 +08:00
|
|
|
#[cfg(has_si549)]
|
|
|
|
let si549_settings = get_si549_setting(clk);
|
|
|
|
|
|
|
|
#[cfg(has_si549)]
|
|
|
|
si549::main_setup(timer, &si549_settings).expect("cannot initialize main Si549");
|
|
|
|
|
2021-11-29 11:17:59 +08:00
|
|
|
#[cfg(has_drtio)]
|
|
|
|
init_drtio(timer);
|
|
|
|
|
2023-02-17 15:52:43 +08:00
|
|
|
#[cfg(not(has_drtio))]
|
|
|
|
init_rtio(timer);
|
2024-03-11 15:04:05 +08:00
|
|
|
|
|
|
|
#[cfg(has_si549)]
|
|
|
|
{
|
|
|
|
// SYS CLK switch will reset CSRs that are used by WRPLL
|
|
|
|
match clk {
|
|
|
|
RtioClock::Ext0_Synth0_10to125
|
|
|
|
| RtioClock::Ext0_Synth0_80to125
|
|
|
|
| RtioClock::Ext0_Synth0_100to125
|
|
|
|
| RtioClock::Ext0_Synth0_125to125 => {
|
|
|
|
wrpll_setup(timer, clk, &si549_settings);
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
2023-02-22 11:02:43 +08:00
|
|
|
}
|