forked from M-Labs/zynq-rs
experiments: implement ps7_init::apply()
This commit is contained in:
parent
eea042e2ee
commit
1e4be13869
|
@ -42,6 +42,8 @@ const HWADDR: [u8; 6] = [0, 0x23, 0xde, 0xea, 0xbe, 0xef];
|
||||||
pub fn main_core0() {
|
pub fn main_core0() {
|
||||||
// zynq::clocks::CpuClocks::enable_io(1_250_000_000);
|
// zynq::clocks::CpuClocks::enable_io(1_250_000_000);
|
||||||
println!("\nzc706 main");
|
println!("\nzc706 main");
|
||||||
|
ps7_init::apply();
|
||||||
|
libboard_zynq::stdio::drop_uart();
|
||||||
|
|
||||||
libboard_zynq::logger::init().unwrap();
|
libboard_zynq::logger::init().unwrap();
|
||||||
log::set_max_level(log::LevelFilter::Trace);
|
log::set_max_level(log::LevelFilter::Trace);
|
||||||
|
|
|
@ -22,9 +22,17 @@ pub fn report_differences() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn apply() {
|
||||||
|
for op in target::INIT_DATA {
|
||||||
|
op.apply();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
pub enum InitOp {
|
pub enum InitOp {
|
||||||
MaskWrite(usize, usize, usize),
|
MaskWrite(usize, usize, usize),
|
||||||
MaskPoll(usize, usize),
|
MaskPoll(usize, usize),
|
||||||
|
MaskDelay(usize, usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InitOp {
|
impl InitOp {
|
||||||
|
@ -32,6 +40,7 @@ impl InitOp {
|
||||||
match self {
|
match self {
|
||||||
InitOp::MaskWrite(address, _, _) => *address,
|
InitOp::MaskWrite(address, _, _) => *address,
|
||||||
InitOp::MaskPoll(address, _) => *address,
|
InitOp::MaskPoll(address, _) => *address,
|
||||||
|
InitOp::MaskDelay(address, _) => *address,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,12 +49,15 @@ impl InitOp {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn difference(&self) -> Option<(usize, usize)> {
|
fn difference(&self) -> Option<(usize, usize)> {
|
||||||
let (mask, expected) = match self {
|
let expected = match self {
|
||||||
InitOp::MaskWrite(_, mask, expected) =>
|
InitOp::MaskWrite(_, mask, expected) =>
|
||||||
(*mask, *expected),
|
Some((*mask, *expected)),
|
||||||
InitOp::MaskPoll(_, mask) =>
|
InitOp::MaskPoll(_, mask) =>
|
||||||
(*mask, *mask),
|
Some((*mask, *mask)),
|
||||||
|
_ => None,
|
||||||
};
|
};
|
||||||
|
match expected {
|
||||||
|
Some((mask, expected)) => {
|
||||||
let actual = self.read();
|
let actual = self.read();
|
||||||
if actual & mask == expected {
|
if actual & mask == expected {
|
||||||
None
|
None
|
||||||
|
@ -53,6 +65,10 @@ impl InitOp {
|
||||||
Some((actual & mask, expected))
|
Some((actual & mask, expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
None =>
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn report_difference(&self) {
|
pub fn report_difference(&self) {
|
||||||
if let Some((actual, expected)) = self.difference() {
|
if let Some((actual, expected)) = self.difference() {
|
||||||
|
@ -65,4 +81,28 @@ impl InitOp {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn apply(&self) {
|
||||||
|
let reg = self.address() as *mut usize;
|
||||||
|
println!("apply {:?}", self);
|
||||||
|
match self {
|
||||||
|
InitOp::MaskWrite(_, mask, val) =>
|
||||||
|
unsafe {
|
||||||
|
*reg = (val & mask) | (*reg & !mask);
|
||||||
|
},
|
||||||
|
InitOp::MaskPoll(_, mask) =>
|
||||||
|
while unsafe { *reg } & mask == 0 {},
|
||||||
|
InitOp::MaskDelay(_, mask) => {
|
||||||
|
let delay = get_number_of_cycles_for_delay(*mask);
|
||||||
|
while unsafe { *reg } < delay {
|
||||||
|
println!("W");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_number_of_cycles_for_delay(delay: usize) -> usize {
|
||||||
|
const APU_FREQ: usize = 666666687;
|
||||||
|
APU_FREQ * delay/ (2 * 1000)
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue