Compare commits

...

3 Commits

Author SHA1 Message Date
newell 463efcf194 Clean up warning take 2 2024-11-01 17:28:53 -07:00
newell b3ab7a7950 Clean up comments and warning 2024-11-01 17:26:46 -07:00
newell 7bb74f83ee Set fclk0 for ebaz4205 2024-11-01 17:22:05 -07:00
1 changed files with 58 additions and 0 deletions

View File

@ -15,6 +15,8 @@ use libconfig::Config;
#[cfg(not(feature = "target_ebaz4205"))]
use log::info;
use log::warn;
#[cfg(feature = "target_ebaz4205")]
use {libboard_zynq::slcr, libregister::RegisterRW};
#[derive(Debug, PartialEq, Copy, Clone)]
#[allow(non_camel_case_types)]
@ -410,6 +412,52 @@ fn get_si549_setting(clk: RtioClock) -> si549::FrequencySetting {
}
}
#[cfg(feature = "target_ebaz4205")]
fn set_fclk0_freq(clk: RtioClock, cfg: &Config) {
let io_pll_freq: u32 = 1_000_000_000; // Hardcoded in zynq-rs
let mut target_freq = 0;
match clk {
RtioClock::Int_100 => {
target_freq = 100_000_000;
}
RtioClock::Int_125 => {
target_freq = 125_000_000;
}
RtioClock::Int_150 => {
target_freq = 150_000_000;
}
_ => {}
}
let mut divisor0 = 1u8; // Start with divisor0 at 1
let mut divisor1 = 1u8; // Default value for divisor1
// Calculate the smallest valid divisor0 and divisor1 pair
while divisor0 < 64 && io_pll_freq / u32::from(divisor0) > target_freq {
divisor0 += 1;
}
// If divisor0 alone isn't enough, adjust divisor1 as well
if io_pll_freq / (u32::from(divisor0) * u32::from(divisor1)) > target_freq {
divisor1 += 1;
divisor0 = 1;
while divisor1 < 64 && io_pll_freq / (u32::from(divisor0) * u32::from(divisor1)) > target_freq {
divisor1 += 1;
}
}
// Ensure the calculated divisors achieve the target frequency
if io_pll_freq / (u32::from(divisor0) * u32::from(divisor1)) == target_freq {
slcr::RegisterBlock::unlocked(|slcr| {
slcr.fpga0_clk_ctrl
.modify(|_, w| w.divisor0(divisor0).divisor1(divisor1));
});
} else {
warn!("Could not set fclk0 for target frequency: '{:?}'", target_freq);
}
}
pub fn init(timer: &mut GlobalTimer, cfg: &Config) {
let clk = get_rtio_clock_cfg(cfg);
#[cfg(has_si5324)]
@ -436,6 +484,16 @@ pub fn init(timer: &mut GlobalTimer, cfg: &Config) {
#[cfg(not(any(has_drtio, feature = "target_ebaz4205")))]
init_rtio(timer);
#[cfg(feature = "target_ebaz4205")]
{
match clk {
RtioClock::Int_100 | RtioClock::Int_125 | RtioClock::Int_150 => {
set_fclk0_freq(clk, cfg);
}
_ => {} // Not set for external clocks
}
}
#[cfg(all(has_si549, has_wrpll))]
{
// SYS CLK switch will reset CSRs that are used by WRPLL