forked from M-Labs/artiq-zynq
ctrl FW: update csr
This commit is contained in:
parent
77d3ef6da0
commit
c21d07b4d4
@ -4,7 +4,7 @@ use byteorder::{ByteOrder, NetworkEndian};
|
|||||||
use io::Cursor;
|
use io::Cursor;
|
||||||
use libboard_zynq::{println, time::Milliseconds, timer::GlobalTimer};
|
use libboard_zynq::{println, time::Milliseconds, timer::GlobalTimer};
|
||||||
|
|
||||||
use crate::{cxp_proto::{print_packet, DownConnPacket, Error, UpConnPacket, DATA_MAXSIZE},
|
use crate::{cxp_proto::{print_packet, Error, RXPacket, TXPacket, DATA_MAXSIZE},
|
||||||
mem::mem::CXP_MEM,
|
mem::mem::CXP_MEM,
|
||||||
pl::csr::CXP};
|
pl::csr::CXP};
|
||||||
|
|
||||||
@ -12,28 +12,28 @@ const BUF_LEN: usize = 0x800;
|
|||||||
const TRANSMISSION_TIMEOUT: u64 = 200;
|
const TRANSMISSION_TIMEOUT: u64 = 200;
|
||||||
|
|
||||||
fn packet_pending(channel: u8) -> bool {
|
fn packet_pending(channel: u8) -> bool {
|
||||||
unsafe { (CXP[channel as usize].downconn_pending_packet_read)() == 1 }
|
unsafe { (CXP[channel as usize].rx_pending_packet_read)() == 1 }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn receive(channel: u8) -> Result<Option<DownConnPacket>, Error> {
|
fn receive(channel: u8) -> Result<Option<RXPacket>, Error> {
|
||||||
if packet_pending(channel) {
|
if packet_pending(channel) {
|
||||||
let channel = channel as usize;
|
let channel = channel as usize;
|
||||||
unsafe {
|
unsafe {
|
||||||
let read_buffer_ptr = (CXP[channel].downconn_read_ptr_read)() as usize;
|
let read_buffer_ptr = (CXP[channel].rx_read_ptr_read)() as usize;
|
||||||
println!("buffer ptr = {}", read_buffer_ptr);
|
println!("buffer ptr = {}", read_buffer_ptr);
|
||||||
let ptr = (CXP_MEM[channel].base + CXP_MEM[channel].size / 2 + read_buffer_ptr * BUF_LEN) as *mut u32;
|
let ptr = (CXP_MEM[channel].base + CXP_MEM[channel].size / 2 + read_buffer_ptr * BUF_LEN) as *mut u32;
|
||||||
|
|
||||||
let mut reader = Cursor::new(slice::from_raw_parts_mut(ptr as *mut u8, 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].rx_packet_type_read)();
|
||||||
println!("packet_type = {}", packet_type);
|
println!("packet_type = {}", packet_type);
|
||||||
// DEBUG:
|
// DEBUG:
|
||||||
// println!("RX MEM before reading");
|
// println!("RX MEM before reading");
|
||||||
// print_packet(&reader.get_ref()[0..40]);
|
// print_packet(&reader.get_ref()[0..40]);
|
||||||
|
|
||||||
let packet = DownConnPacket::read_from(&mut reader, packet_type);
|
let packet = RXPacket::read_from(&mut reader, packet_type);
|
||||||
println!("{:X?}", packet);
|
println!("{:X?}", packet);
|
||||||
|
|
||||||
(CXP[channel].downconn_pending_packet_write)(1);
|
(CXP[channel].rx_pending_packet_write)(1);
|
||||||
Ok(Some(packet?))
|
Ok(Some(packet?))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -41,7 +41,7 @@ fn receive(channel: u8) -> Result<Option<DownConnPacket>, Error> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn receive_timeout(channel: u8, timeout_ms: u64) -> Result<DownConnPacket, Error> {
|
fn receive_timeout(channel: u8, timeout_ms: u64) -> Result<RXPacket, Error> {
|
||||||
// assume timer was initialized successfully
|
// assume timer was initialized successfully
|
||||||
let timer = unsafe { GlobalTimer::get() };
|
let timer = unsafe { GlobalTimer::get() };
|
||||||
let limit = timer.get_time() + Milliseconds(timeout_ms);
|
let limit = timer.get_time() + Milliseconds(timeout_ms);
|
||||||
@ -54,11 +54,11 @@ fn receive_timeout(channel: u8, timeout_ms: u64) -> Result<DownConnPacket, Error
|
|||||||
Err(Error::TimedOut)
|
Err(Error::TimedOut)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_data_packet(channel: u8, packet: &UpConnPacket) -> Result<(), Error> {
|
fn send_data_packet(channel: u8, packet: &TXPacket) -> Result<(), Error> {
|
||||||
// assume upconn tx is enabled
|
// assume tx is enabled
|
||||||
let channel = channel as usize;
|
let channel = channel as usize;
|
||||||
unsafe {
|
unsafe {
|
||||||
while (CXP[channel].upconn_bootstrap_tx_busy_read)() == 1 {}
|
while (CXP[channel].tx_bootstrap_tx_busy_read)() == 1 {}
|
||||||
let ptr = CXP_MEM[channel].base as *mut u32;
|
let ptr = CXP_MEM[channel].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));
|
||||||
|
|
||||||
@ -67,19 +67,19 @@ fn send_data_packet(channel: u8, packet: &UpConnPacket) -> Result<(), Error> {
|
|||||||
// println!("TX MEM after writing");
|
// println!("TX MEM after writing");
|
||||||
// print_packet(&writer.get_ref()[0..40]);
|
// print_packet(&writer.get_ref()[0..40]);
|
||||||
|
|
||||||
(CXP[channel].upconn_bootstrap_tx_word_len_write)(writer.position() as u16 / 4);
|
(CXP[channel].tx_bootstrap_tx_word_len_write)(writer.position() as u16 / 4);
|
||||||
(CXP[channel].upconn_bootstrap_tx_write)(1);
|
(CXP[channel].tx_bootstrap_tx_write)(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_test_packet(channel: u8) -> Result<(), Error> {
|
pub fn send_test_packet(channel: u8) -> Result<(), Error> {
|
||||||
// assume upconn tx is enabled
|
// assume tx is enabled
|
||||||
let channel = channel as usize;
|
let channel = channel as usize;
|
||||||
unsafe {
|
unsafe {
|
||||||
while (CXP[channel].upconn_bootstrap_tx_busy_read)() == 1 {}
|
while (CXP[channel].tx_bootstrap_tx_busy_read)() == 1 {}
|
||||||
(CXP[channel].upconn_bootstrap_tx_testseq_write)(1);
|
(CXP[channel].tx_bootstrap_tx_testseq_write)(1);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ pub fn send_test_packet(channel: u8) -> Result<(), Error> {
|
|||||||
// DEBUG:
|
// DEBUG:
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
pub fn downconn_debug_mem_print(channel: u8) {
|
pub fn rx_debug_mem_print(channel: u8) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = CXP_MEM[channel as usize].base as *mut u32;
|
let ptr = CXP_MEM[channel as usize].base as *mut u32;
|
||||||
let arr = slice::from_raw_parts_mut(ptr as *mut u8, BUF_LEN * 4);
|
let arr = slice::from_raw_parts_mut(ptr as *mut u8, BUF_LEN * 4);
|
||||||
@ -102,7 +102,7 @@ pub fn print_decode_error(channel: u8) {
|
|||||||
println!(
|
println!(
|
||||||
"CH#{} Decode error = {}",
|
"CH#{} Decode error = {}",
|
||||||
channel,
|
channel,
|
||||||
(CXP[channel as usize].downconn_bootstrap_decoder_err_read)()
|
(CXP[channel as usize].rx_bootstrap_decoder_err_read)()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,11 +145,11 @@ fn check_length(length: u32) -> Result<(), Error> {
|
|||||||
|
|
||||||
fn process_ack_packet(channel: u8, timeout: u64) -> Result<(), Error> {
|
fn process_ack_packet(channel: u8, timeout: u64) -> Result<(), Error> {
|
||||||
match receive_timeout(channel, timeout) {
|
match receive_timeout(channel, timeout) {
|
||||||
Ok(DownConnPacket::CtrlAck { tag }) => {
|
Ok(RXPacket::CtrlAck { tag }) => {
|
||||||
check_tag(tag)?;
|
check_tag(tag)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Ok(DownConnPacket::CtrlDelay { tag, time }) => {
|
Ok(RXPacket::CtrlDelay { tag, time }) => {
|
||||||
check_tag(tag)?;
|
check_tag(tag)?;
|
||||||
|
|
||||||
// info!("delaying by {} ms ....", time);
|
// info!("delaying by {} ms ....", time);
|
||||||
@ -162,7 +162,7 @@ fn process_ack_packet(channel: u8, timeout: u64) -> Result<(), Error> {
|
|||||||
|
|
||||||
fn process_reply_packet(channel: u8, timeout: u64, expected_length: u32) -> Result<[u8; DATA_MAXSIZE], Error> {
|
fn process_reply_packet(channel: u8, timeout: u64, expected_length: u32) -> Result<[u8; DATA_MAXSIZE], Error> {
|
||||||
match receive_timeout(channel, timeout) {
|
match receive_timeout(channel, timeout) {
|
||||||
Ok(DownConnPacket::CtrlReply { tag, length, data }) => {
|
Ok(RXPacket::CtrlReply { tag, length, data }) => {
|
||||||
check_tag(tag)?;
|
check_tag(tag)?;
|
||||||
|
|
||||||
if length != expected_length {
|
if length != expected_length {
|
||||||
@ -171,7 +171,7 @@ fn process_reply_packet(channel: u8, timeout: u64, expected_length: u32) -> Resu
|
|||||||
|
|
||||||
Ok(data)
|
Ok(data)
|
||||||
}
|
}
|
||||||
Ok(DownConnPacket::CtrlDelay { tag, time }) => {
|
Ok(RXPacket::CtrlDelay { tag, time }) => {
|
||||||
check_tag(tag)?;
|
check_tag(tag)?;
|
||||||
|
|
||||||
// info!("delaying by {} ms ....", time);
|
// info!("delaying by {} ms ....", time);
|
||||||
@ -192,7 +192,7 @@ pub fn write_bytes_no_ack(channel: u8, addr: u32, val: &[u8], with_tag: bool) ->
|
|||||||
let tag: Option<u8> = if with_tag { Some(unsafe { TAG }) } else { None };
|
let tag: Option<u8> = if with_tag { Some(unsafe { TAG }) } else { None };
|
||||||
send_data_packet(
|
send_data_packet(
|
||||||
channel,
|
channel,
|
||||||
&UpConnPacket::CtrlWrite {
|
&TXPacket::CtrlWrite {
|
||||||
tag,
|
tag,
|
||||||
addr,
|
addr,
|
||||||
length,
|
length,
|
||||||
@ -225,7 +225,7 @@ pub fn write_u64(channel: u8, addr: u32, val: u64, with_tag: bool) -> Result<(),
|
|||||||
fn read(channel: u8, addr: u32, length: u32, with_tag: bool) -> Result<(), Error> {
|
fn read(channel: u8, addr: u32, length: u32, with_tag: bool) -> Result<(), Error> {
|
||||||
check_length(length)?;
|
check_length(length)?;
|
||||||
let tag: Option<u8> = if with_tag { Some(unsafe { TAG }) } else { None };
|
let tag: Option<u8> = if with_tag { Some(unsafe { TAG }) } else { None };
|
||||||
send_data_packet(channel, &UpConnPacket::CtrlRead { tag, addr, length })
|
send_data_packet(channel, &TXPacket::CtrlRead { tag, addr, length })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_bytes(channel: u8, addr: u32, bytes: &mut [u8], with_tag: bool) -> Result<(), Error> {
|
pub fn read_bytes(channel: u8, addr: u32, bytes: &mut [u8], with_tag: bool) -> Result<(), Error> {
|
||||||
|
Loading…
Reference in New Issue
Block a user