2020-04-11 02:39:53 +08:00
|
|
|
|
2020-06-25 07:40:42 +08:00
|
|
|
use crate::println;
|
2020-04-03 03:27:57 +08:00
|
|
|
|
2020-10-01 00:17:47 +08:00
|
|
|
#[cfg(feature = "target_zc706")]
|
2020-04-03 03:27:57 +08:00
|
|
|
mod zc706;
|
2020-10-01 00:17:47 +08:00
|
|
|
#[cfg(feature = "target_redpitaya")]
|
2020-09-26 16:28:08 +08:00
|
|
|
mod redpitaya;
|
2020-11-11 21:21:48 +08:00
|
|
|
#[cfg(not(any(feature = "target_zc706", feature = "target_redpitaya")))]
|
2020-10-01 00:17:47 +08:00
|
|
|
mod none;
|
2020-04-03 03:27:57 +08:00
|
|
|
|
|
|
|
#[cfg(feature = "target_zc706")]
|
|
|
|
use zc706 as target;
|
2020-09-26 16:28:08 +08:00
|
|
|
#[cfg(feature = "target_redpitaya")]
|
|
|
|
use redpitaya as target;
|
2020-11-11 21:21:48 +08:00
|
|
|
#[cfg(not(any(feature = "target_zc706", feature = "target_redpitaya")))]
|
2020-10-01 00:17:47 +08:00
|
|
|
use none as target;
|
2020-04-03 03:27:57 +08:00
|
|
|
|
|
|
|
pub fn report_differences() {
|
|
|
|
for (i, op) in target::INIT_DATA.iter().enumerate() {
|
|
|
|
let address = op.address();
|
|
|
|
let overwritten_later = target::INIT_DATA[(i + 1)..].iter()
|
|
|
|
.any(|later_op| later_op.address() == address);
|
|
|
|
|
|
|
|
if !overwritten_later {
|
|
|
|
op.report_difference();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-25 07:27:02 +08:00
|
|
|
pub fn apply() {
|
|
|
|
for op in target::INIT_DATA {
|
|
|
|
op.apply();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
2020-04-03 03:27:57 +08:00
|
|
|
pub enum InitOp {
|
|
|
|
MaskWrite(usize, usize, usize),
|
|
|
|
MaskPoll(usize, usize),
|
2020-06-25 07:27:02 +08:00
|
|
|
MaskDelay(usize, usize),
|
2020-04-03 03:27:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl InitOp {
|
|
|
|
fn address(&self) -> usize {
|
|
|
|
match self {
|
|
|
|
InitOp::MaskWrite(address, _, _) => *address,
|
|
|
|
InitOp::MaskPoll(address, _) => *address,
|
2020-06-25 07:27:02 +08:00
|
|
|
InitOp::MaskDelay(address, _) => *address,
|
2020-04-03 03:27:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn read(&self) -> usize {
|
|
|
|
unsafe { *(self.address() as *const usize) }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn difference(&self) -> Option<(usize, usize)> {
|
2020-06-25 07:27:02 +08:00
|
|
|
let expected = match self {
|
2020-04-03 03:27:57 +08:00
|
|
|
InitOp::MaskWrite(_, mask, expected) =>
|
2020-06-25 07:27:02 +08:00
|
|
|
Some((*mask, *expected)),
|
2020-04-03 03:27:57 +08:00
|
|
|
InitOp::MaskPoll(_, mask) =>
|
2020-06-25 07:27:02 +08:00
|
|
|
Some((*mask, *mask)),
|
|
|
|
_ => None,
|
2020-04-03 03:27:57 +08:00
|
|
|
};
|
2020-06-25 07:27:02 +08:00
|
|
|
match expected {
|
|
|
|
Some((mask, expected)) => {
|
|
|
|
let actual = self.read();
|
|
|
|
if actual & mask == expected {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some((actual & mask, expected))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None =>
|
|
|
|
None
|
2020-04-03 03:27:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn report_difference(&self) {
|
|
|
|
if let Some((actual, expected)) = self.difference() {
|
|
|
|
println!(
|
|
|
|
"Register {:08X} is {:08X}&={:08X} != {:08X} expected",
|
|
|
|
self.address(),
|
|
|
|
self.read(),
|
|
|
|
actual,
|
|
|
|
expected
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-06-25 07:27:02 +08:00
|
|
|
|
|
|
|
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)
|
2020-04-03 03:27:57 +08:00
|
|
|
}
|