forked from M-Labs/artiq-zynq
cxp upconn fw: refactor
upconn: refactor buffer printout into one function upconn: refactor buffer write function upconn: packet writter proto
This commit is contained in:
parent
bcfd599c69
commit
d77086e733
|
@ -10,7 +10,7 @@ pub fn trigger_test(timer: &mut GlobalTimer, linktrig_mode: u8) {
|
|||
unsafe {
|
||||
csr::cxp::upconn_trig_delay_write(0x05);
|
||||
csr::cxp::upconn_linktrigger_write(linktrig_mode);
|
||||
csr::cxp::upconn_trig_stb_write(1); // send trig
|
||||
csr::cxp::upconn_trig_stb_write(1); // send trig
|
||||
timer.delay_us(1);
|
||||
|
||||
let mut i: usize = 0;
|
||||
|
@ -22,19 +22,7 @@ pub fn trigger_test(timer: &mut GlobalTimer, linktrig_mode: u8) {
|
|||
}
|
||||
|
||||
println!("trigger packet | linktrigger = {}", linktrig_mode);
|
||||
println!("arr = [");
|
||||
for i in 0..(LEN / 4) {
|
||||
println!(
|
||||
"{:#03} {:#04X} {:#04X} {:#04X} {:#04X},",
|
||||
i + 1,
|
||||
pak_arr[i * 4],
|
||||
pak_arr[i * 4 + 1],
|
||||
pak_arr[i * 4 + 2],
|
||||
pak_arr[i * 4 + 3]
|
||||
)
|
||||
}
|
||||
println!("]");
|
||||
println!("============================================");
|
||||
print_packet(&pak_arr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +31,7 @@ pub fn trigger_ack_test(timer: &mut GlobalTimer) {
|
|||
let mut pak_arr: [u8; LEN] = [0; LEN];
|
||||
|
||||
unsafe {
|
||||
csr::cxp::upconn_ack_write(1); // send IO ack
|
||||
csr::cxp::upconn_ack_write(1); // send IO ack
|
||||
|
||||
let mut i: usize = 0;
|
||||
while csr::cxp::upconn_trig_ack_dout_valid_read() == 1 {
|
||||
|
@ -54,42 +42,22 @@ pub fn trigger_ack_test(timer: &mut GlobalTimer) {
|
|||
}
|
||||
|
||||
println!("trigger ack packet");
|
||||
println!("arr = [");
|
||||
for i in 0..(LEN / 4) {
|
||||
println!(
|
||||
"{:#03} {:#04X} {:#04X} {:#04X} {:#04X},",
|
||||
i + 1,
|
||||
pak_arr[i * 4],
|
||||
pak_arr[i * 4 + 1],
|
||||
pak_arr[i * 4 + 2],
|
||||
pak_arr[i * 4 + 3]
|
||||
)
|
||||
}
|
||||
println!("]");
|
||||
println!("============================================");
|
||||
print_packet(&pak_arr);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pipeline_test(timer: &mut GlobalTimer) {
|
||||
let arr = [
|
||||
// 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
|
||||
0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, // CXP CRC-32
|
||||
// 0x56, 0x86, 0x5D, 0x6f,
|
||||
0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
|
||||
// 0x56, 0x86, 0x5D, 0x6f, // CXP CRC-32
|
||||
];
|
||||
|
||||
const LEN: usize = 4 * 8;
|
||||
let mut pak_arr: [u8; LEN] = [0; LEN];
|
||||
|
||||
unsafe {
|
||||
// eop = 1 (End of packet) at the last data input
|
||||
csr::cxp::upconn_command_din_len_write(arr.len() as u8);
|
||||
csr::cxp::upconn_command_packet_type_write(0x02); // read control command
|
||||
|
||||
for a in arr.iter() {
|
||||
while csr::cxp::upconn_command_din_ready_read() == 0 {}
|
||||
// println!("{:#04X}", *a);
|
||||
csr::cxp::upconn_command_din_data_write(*a);
|
||||
}
|
||||
write(0x02, &arr); // read control command
|
||||
|
||||
// wait for pipelining
|
||||
timer.delay_us(1);
|
||||
|
@ -100,22 +68,13 @@ pub fn pipeline_test(timer: &mut GlobalTimer) {
|
|||
// println!("received {:#04X}", pak_arr[i]);
|
||||
csr::cxp::upconn_command_inc_write(1);
|
||||
i += 1;
|
||||
if i == LEN {
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
println!("data packet");
|
||||
println!("arr = [");
|
||||
for i in 0..(LEN / 4) {
|
||||
println!(
|
||||
"{:#03} {:#04X} {:#04X} {:#04X} {:#04X},",
|
||||
i + 1,
|
||||
pak_arr[i * 4],
|
||||
pak_arr[i * 4 + 1],
|
||||
pak_arr[i * 4 + 2],
|
||||
pak_arr[i * 4 + 3]
|
||||
)
|
||||
}
|
||||
println!("]");
|
||||
println!("============================================");
|
||||
print_packet(&pak_arr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,20 +115,48 @@ pub fn tx_test(timer: &mut GlobalTimer) {
|
|||
}
|
||||
}
|
||||
|
||||
println!("arr = [");
|
||||
for i in 0..(LEN / 4) {
|
||||
println!(
|
||||
"{:#03} {:#04X} {:#04X} {:#04X} {:#04X},",
|
||||
i + 1,
|
||||
pak_arr[i * 4],
|
||||
pak_arr[i * 4 + 1],
|
||||
pak_arr[i * 4 + 2],
|
||||
pak_arr[i * 4 + 3]
|
||||
)
|
||||
}
|
||||
println!("]");
|
||||
println!("============================================");
|
||||
print_packet(&pak_arr);
|
||||
timer.delay_us(2_000_000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write(packet_type: u8, buf: &[u8]) {
|
||||
unsafe {
|
||||
// eop = 1 (End of packet) at the last data input
|
||||
csr::cxp::upconn_command_din_len_write(buf.len() as u8);
|
||||
csr::cxp::upconn_command_packet_type_write(packet_type);
|
||||
for data in buf.iter() {
|
||||
while csr::cxp::upconn_command_din_ready_read() == 0 {}
|
||||
csr::cxp::upconn_command_din_data_write(*data);
|
||||
println!("{:#04X}", *data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn CXP_Control(timer: &mut GlobalTimer) {
|
||||
let addr: u32 = 0x0000_00FF;
|
||||
let tag: u8 = 0x44;
|
||||
let d0: u32 = 0x0000_0032;
|
||||
let d1: u64 = 0x0000_0064;
|
||||
|
||||
// TODO: reference drtioaux_proto.rs
|
||||
|
||||
// TODO: add firmware CRC & packet type
|
||||
}
|
||||
|
||||
fn print_packet(pak: &[u8]) {
|
||||
println!("pak = [");
|
||||
for i in 0..(pak.len() / 4) {
|
||||
println!(
|
||||
"{:#03} {:#04X} {:#04X} {:#04X} {:#04X},",
|
||||
i + 1,
|
||||
pak[i * 4],
|
||||
pak[i * 4 + 1],
|
||||
pak[i * 4 + 2],
|
||||
pak[i * 4 + 3]
|
||||
)
|
||||
}
|
||||
println!("]");
|
||||
println!("============================================");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue