forked from M-Labs/artiq-zynq
proto FW: add read/write u32
proto FW: general cleanup & update csr names
This commit is contained in:
parent
501f9b7074
commit
4286820f4d
|
@ -249,9 +249,9 @@ pub fn receive(channel: usize) -> Result<Option<DownConnPacket>, Error> {
|
||||||
if (CXP[channel].downconn_pending_packet_read)() == 1 {
|
if (CXP[channel].downconn_pending_packet_read)() == 1 {
|
||||||
let read_buffer_ptr = (CXP[channel].downconn_read_ptr_read)() as usize;
|
let read_buffer_ptr = (CXP[channel].downconn_read_ptr_read)() as usize;
|
||||||
println!("buffer ptr = {}", read_buffer_ptr);
|
println!("buffer ptr = {}", read_buffer_ptr);
|
||||||
let ptr = (CXP_RX_MEM[channel].base + read_buffer_ptr * BUF_LEN) as *mut u8;
|
let ptr = (CXP_RX_MEM[channel].base + read_buffer_ptr * BUF_LEN) as *mut u32;
|
||||||
|
|
||||||
let mut reader = Cursor::new(slice::from_raw_parts_mut(ptr, BUF_LEN));
|
let mut reader = Cursor::new(slice::from_raw_parts_mut(ptr as *mut u8, BUF_LEN));
|
||||||
let packet_type = (CXP[channel].downconn_packet_type_read)();
|
let packet_type = (CXP[channel].downconn_packet_type_read)();
|
||||||
|
|
||||||
let packet = DownConnPacket::read_from(&mut reader, packet_type);
|
let packet = DownConnPacket::read_from(&mut reader, packet_type);
|
||||||
|
@ -460,15 +460,14 @@ pub fn send(channel: usize, packet: &UpConnPacket) -> Result<(), Error> {
|
||||||
|
|
||||||
fn send_data_packet(channel: usize, packet: &UpConnPacket) -> Result<(), Error> {
|
fn send_data_packet(channel: usize, packet: &UpConnPacket) -> Result<(), Error> {
|
||||||
unsafe {
|
unsafe {
|
||||||
// TODO: put this in mem group
|
while (CXP[channel].upconn_bootstrap_tx_busy_read)() == 1 {}
|
||||||
while (CXP[channel].upconn_command_tx_read)() == 1 {}
|
|
||||||
let ptr = CXP_TX_MEM[0].base as *mut u32;
|
let ptr = CXP_TX_MEM[0].base as *mut u32;
|
||||||
let mut writer = Cursor::new(slice::from_raw_parts_mut(ptr as *mut u8, BUF_LEN));
|
let mut writer = Cursor::new(slice::from_raw_parts_mut(ptr as *mut u8, BUF_LEN));
|
||||||
|
|
||||||
packet.write_to(&mut writer)?;
|
packet.write_to(&mut writer)?;
|
||||||
|
|
||||||
(CXP[channel].upconn_command_tx_word_len_write)(writer.position() as u16 / 4);
|
(CXP[channel].upconn_bootstrap_tx_word_len_write)(writer.position() as u16 / 4);
|
||||||
(CXP[channel].upconn_command_tx_write)(1);
|
(CXP[channel].upconn_bootstrap_tx_write)(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -476,50 +475,44 @@ fn send_data_packet(channel: usize, packet: &UpConnPacket) -> Result<(), Error>
|
||||||
|
|
||||||
fn send_test_packet(channel: usize) -> Result<(), Error> {
|
fn send_test_packet(channel: usize) -> Result<(), Error> {
|
||||||
unsafe {
|
unsafe {
|
||||||
while (CXP[channel].upconn_testseq_tx_read)() == 1 {}
|
while (CXP[channel].upconn_bootstrap_tx_busy_read)() == 1 {}
|
||||||
(CXP[channel].upconn_tx_testmode_en_write)(1);
|
(CXP[channel].upconn_bootstrap_tx_testseq_write)(1);
|
||||||
(CXP[channel].upconn_testseq_tx_write)(1);
|
|
||||||
|
|
||||||
// wait till all test packet is out before switching back
|
|
||||||
while (CXP[channel].upconn_testseq_tx_read)() == 1 {}
|
|
||||||
(CXP[channel].upconn_tx_testmode_en_write)(0);
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
pub fn write_u32(channel: u8, addr: u32, val: u32) -> Result<(), Error> {
|
||||||
// DEBUG: use only
|
// TODO: add tags after connection & verify it's CXPv2
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// pub fn write_u32(channel: usize, addr: u32, data: u32) -> Result<(), Error> {
|
|
||||||
// let mut data_slice: [u8; DATA_MAXSIZE] = [0; DATA_MAXSIZE];
|
|
||||||
// data_slice[..4].clone_from_slice(&data.to_be_bytes());
|
|
||||||
// send(
|
|
||||||
// channel,
|
|
||||||
// &UpConnPacket::CtrlWrite {
|
|
||||||
// tag: None,
|
|
||||||
// addr,
|
|
||||||
// length: 4,
|
|
||||||
// data: data_slice,
|
|
||||||
// },
|
|
||||||
// )?;
|
|
||||||
|
|
||||||
// Ok(())
|
let mut data: [u8; DATA_MAXSIZE] = [0; DATA_MAXSIZE];
|
||||||
// }
|
NetworkEndian::write_u32(&mut data[..4], val);
|
||||||
|
send(
|
||||||
|
channel as usize,
|
||||||
|
&UpConnPacket::CtrlWrite {
|
||||||
|
tag: None,
|
||||||
|
addr,
|
||||||
|
length: 4,
|
||||||
|
data,
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
|
||||||
// pub fn read_u32(channel: usize, addr: u32) -> Result<(), Error> {
|
Ok(())
|
||||||
// send(
|
}
|
||||||
// channel,
|
|
||||||
// &UpConnPacket::CtrlRead {
|
|
||||||
// tag: None,
|
|
||||||
// addr,
|
|
||||||
// length: 4,
|
|
||||||
// },
|
|
||||||
// )?;
|
|
||||||
|
|
||||||
// Ok(())
|
pub fn read_u32(channel: u8, addr: u32) -> Result<(), Error> {
|
||||||
// }
|
// TODO: add tags after connection & verify it's CXPv2
|
||||||
|
|
||||||
|
send(
|
||||||
|
channel as usize,
|
||||||
|
&UpConnPacket::CtrlRead {
|
||||||
|
tag: None,
|
||||||
|
addr,
|
||||||
|
length: 4,
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
// pub fn write_u64(channel: usize, addr: u32, data: u64) -> Result<(), Error> {
|
// pub fn write_u64(channel: usize, addr: u32, data: u64) -> Result<(), Error> {
|
||||||
// let mut data_slice: [u8; DATA_MAXSIZE] = [0; DATA_MAXSIZE];
|
// let mut data_slice: [u8; DATA_MAXSIZE] = [0; DATA_MAXSIZE];
|
||||||
|
@ -537,6 +530,11 @@ fn send_test_packet(channel: usize) -> Result<(), Error> {
|
||||||
// Ok(())
|
// Ok(())
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
//
|
||||||
|
// DEBUG: use only
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
pub fn print_packet(pak: &[u8]) {
|
pub fn print_packet(pak: &[u8]) {
|
||||||
println!("pak = [");
|
println!("pak = [");
|
||||||
for i in 0..(pak.len() / 4) {
|
for i in 0..(pak.len() / 4) {
|
||||||
|
@ -573,14 +571,14 @@ pub fn print_packetu32(pak: &[u32], k: &[u8]) {
|
||||||
|
|
||||||
pub fn downconn_debug_send(channel: usize, packet: &UpConnPacket) -> Result<(), Error> {
|
pub fn downconn_debug_send(channel: usize, packet: &UpConnPacket) -> Result<(), Error> {
|
||||||
unsafe {
|
unsafe {
|
||||||
while (CXP[channel].downconn_command_tx_read)() == 1 {}
|
while (CXP[channel].downconn_bootstrap_loopback_tx_busy_read)() == 1 {}
|
||||||
let ptr = CXP_LOOPBACK_MEM[0].base as *mut u32;
|
let ptr = CXP_LOOPBACK_MEM[0].base as *mut u32;
|
||||||
let mut writer = Cursor::new(slice::from_raw_parts_mut(ptr as *mut u8, BUF_LEN));
|
let mut writer = Cursor::new(slice::from_raw_parts_mut(ptr as *mut u8, BUF_LEN));
|
||||||
|
|
||||||
packet.write_to(&mut writer)?;
|
packet.write_to(&mut writer)?;
|
||||||
|
|
||||||
(CXP[channel].downconn_command_tx_word_len_write)(writer.position() as u16 / 4);
|
(CXP[channel].downconn_bootstrap_loopback_tx_word_len_write)(writer.position() as u16 / 4);
|
||||||
(CXP[channel].downconn_command_tx_write)(1);
|
(CXP[channel].downconn_bootstrap_loopback_tx_write)(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -588,8 +586,8 @@ pub fn downconn_debug_send(channel: usize, packet: &UpConnPacket) -> Result<(),
|
||||||
|
|
||||||
pub fn downconn_debug_mem_print(channel: usize) {
|
pub fn downconn_debug_mem_print(channel: usize) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = CXP_RX_MEM[channel].base as *mut u8;
|
let ptr = CXP_RX_MEM[channel].base as *mut u32;
|
||||||
let arr = slice::from_raw_parts_mut(ptr, BUF_LEN * 4);
|
let arr = slice::from_raw_parts_mut(ptr as *mut u8, BUF_LEN * 4);
|
||||||
print_packet(arr);
|
print_packet(arr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -602,12 +600,7 @@ pub fn downconn_debug_send_trig_ack(channel: usize) {
|
||||||
|
|
||||||
pub fn downconn_send_test_packet(channel: usize) {
|
pub fn downconn_send_test_packet(channel: usize) {
|
||||||
unsafe {
|
unsafe {
|
||||||
while (CXP[channel].downconn_testseq_tx_read)() == 1 {}
|
while (CXP[channel].downconn_bootstrap_loopback_tx_busy_read)() == 1 {}
|
||||||
(CXP[channel].downconn_mux_sel_write)(1);
|
(CXP[channel].downconn_bootstrap_loopback_tx_testseq_write)(1);
|
||||||
(CXP[channel].downconn_testseq_tx_write)(1);
|
|
||||||
|
|
||||||
// wait till all test packet is out before switching back
|
|
||||||
while (CXP[channel].downconn_testseq_tx_read)() == 1 {}
|
|
||||||
(CXP[channel].downconn_mux_sel_write)(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue