2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-26 03:38:25 +08:00

si5324: kasli support

This commit is contained in:
Sebastien Bourdeauducq 2018-01-23 13:16:34 +08:00
parent 649deccd9b
commit cfffd9e13d

View File

@ -1,5 +1,7 @@
use core::result;
use board::{csr, clock};
use board::clock;
#[cfg(not(si5324_soft_reset))]
use board::csr;
use i2c;
type Result<T> = result::Result<T, &'static str>;
@ -7,23 +9,27 @@ type Result<T> = result::Result<T, &'static str>;
const BUSNO: u8 = 0;
const ADDRESS: u8 = 0x68;
#[cfg(any(soc_platform = "sayma_amc", soc_platform = "kc705"))]
fn pca9548_select(address: u8, channel: u8) -> Result<()> {
#[cfg(any(soc_platform = "kasli",
soc_platform = "sayma_amc",
soc_platform = "kc705"))]
fn pca9548_select(address: u8, channels: u8) -> Result<()> {
i2c::start(BUSNO).unwrap();
if !i2c::write(BUSNO, (address << 1)).unwrap() {
return Err("PCA9548 failed to ack write address")
}
if !i2c::write(BUSNO, 1 << channel).unwrap() {
if !i2c::write(BUSNO, channels).unwrap() {
return Err("PCA9548 failed to ack control word")
}
i2c::stop(BUSNO).unwrap();
Ok(())
}
fn reset(en: bool) {
unsafe {
csr::si5324_rst_n::out_write(if en { 0 } else { 1 })
}
#[cfg(not(si5324_soft_reset))]
fn hard_reset() {
unsafe { csr::si5324_rst_n::out_write(0); }
clock::spin_us(1_000);
unsafe { csr::si5324_rst_n::out_write(1); }
clock::spin_us(10_000);
}
// NOTE: the logical parameters DO NOT MAP to physical values written
@ -127,6 +133,13 @@ fn ident() -> Result<u16> {
Ok(((read(134)? as u16) << 8) | (read(135)? as u16))
}
#[cfg(si5324_soft_reset)]
fn soft_reset() -> Result<()> {
write(136, read(136)? | 0x80)?;
clock::spin_us(10_000);
Ok(())
}
fn has_xtal() -> Result<bool> {
Ok((read(129)? & 0x01) == 0) // LOSX_INT=0
}
@ -154,20 +167,26 @@ fn monitor_lock() -> Result<()> {
pub fn setup(settings: &FrequencySettings) -> Result<()> {
let s = map_frequency_settings(settings)?;
reset(true);
clock::spin_us(1_000);
reset(false);
clock::spin_us(10_000);
#[cfg(not(si5324_soft_reset))]
hard_reset();
#[cfg(soc_platform = "kc705")]
pca9548_select(0x74, 7)?;
#[cfg(soc_platform = "kasli")]
{
pca9548_select(0x70, 0)?;
pca9548_select(0x71, 1 << 3)?;
}
#[cfg(soc_platform = "sayma_amc")]
pca9548_select(0x70, 4)?;
pca9548_select(0x70, 1 << 4)?;
#[cfg(soc_platform = "kc705")]
pca9548_select(0x74, 1 << 7)?;
if ident()? != 0x0182 {
return Err("Si5324 does not have expected product number");
}
#[cfg(si5324_soft_reset)]
soft_reset()?;
write(0, read(0)? | 0x40)?; // FREE_RUN=1
write(2, (read(2)? & 0x0f) | (s.bwsel << 4))?;
write(21, read(21)? & 0xfe)?; // CKSEL_PIN=0