api: add cxp api support for CTRL packet

api: DEBUG print in correct endianese
api: add bytes read for XML download
api: add artiq error sample code
This commit is contained in:
morgan 2024-10-15 09:53:22 +08:00
parent 142fccce47
commit facf30252e
3 changed files with 150 additions and 0 deletions

132
src/libksupport/src/cxp.rs Normal file
View File

@ -0,0 +1,132 @@
use byteorder::{ByteOrder, NetworkEndian};
use cslice::CMutSlice;
use libboard_artiq::{cxp::{camera_connected, with_tag},
cxp_ctrl,
cxp_proto::DATA_MAXSIZE};
use log::error;
use crate::artiq_raise;
// for downloading the XML files
// TODO: change this to read bytes and accept TBytearray
pub extern "C" fn cxp_read_words(addr: i32, val: &mut CMutSlice<i32>) {
if camera_connected() {
let mut bytes: [u8; DATA_MAXSIZE] = [0; DATA_MAXSIZE];
match cxp_ctrl::read_bytes(addr as u32, &mut bytes[..val.len() * 4], with_tag()) {
Ok(_) => {}
Err(e) => {
error!("{}", e);
// TODO: add cxp error?
artiq_raise!("UnwrapNoneError", "CXP error");
}
}
for i in 0..val.len() {
val.as_mut_slice()[i] = NetworkEndian::read_u32(&bytes[i * 4..(i + 1) * 4]) as i32;
}
} else {
artiq_raise!("UnwrapNoneError", "Camera is not connected");
}
}
pub extern "C" fn cxp_readu32(addr: i32) -> i32 {
// TODO: add cxp error?
if camera_connected() {
match cxp_ctrl::read_u32(addr as u32, with_tag()) {
Ok(result) => result as i32,
Err(e) => {
error!("{}", e);
artiq_raise!("UnwrapNoneError", "CXP error");
}
}
} else {
artiq_raise!("UnwrapNoneError", "Camera is not connected");
}
}
pub extern "C" fn cxp_readu64(addr: i32) -> i64 {
// TODO: add cxp error?
if camera_connected() {
match cxp_ctrl::read_u64(addr as u32, with_tag()) {
Ok(result) => result as i64,
Err(e) => {
error!("{}", e);
artiq_raise!("UnwrapNoneError", "CXP error");
}
}
} else {
artiq_raise!("UnwrapNoneError", "Camera is not connected");
}
}
pub extern "C" fn cxp_writeu32(addr: i32, val: i32) {
// TODO: add cxp error?
if camera_connected() {
match cxp_ctrl::write_u32(addr as u32, val as u32, with_tag()) {
Ok(_) => {}
Err(e) => {
error!("{}", e);
artiq_raise!("UnwrapNoneError", "CXP error");
}
}
} else {
artiq_raise!("UnwrapNoneError", "Camera is not connected");
}
}
pub extern "C" fn cxp_writeu64(addr: i32, val: i64) {
// TODO: add cxp error?
if camera_connected() {
match cxp_ctrl::write_u64(addr as u32, val as u64, with_tag()) {
Ok(_) => {}
Err(e) => {
error!("{}", e);
artiq_raise!("UnwrapNoneError", "CXP error");
}
}
} else {
artiq_raise!("UnwrapNoneError", "Camera is not connected");
}
}
// DEBUG: ONLY
pub extern "C" fn cxp_debug_frame_print() {
use libboard_zynq::println;
use crate::pl::csr;
unsafe {
// use crate::pl::csr::cxp_frame_pipeline;
if csr::cxp_grabber::parser_crc_error_read() == 1 {
println!("CRC error and clear");
csr::cxp_grabber::parser_crc_error_write(1);
} else {
println!("NO CRC error");
}
println!(
"grabber frame pixel format = {} | x_size = {} | y_size = {}",
csr::cxp_grabber::parser_frame_pixel_format_read(),
csr::cxp_grabber::parser_frame_x_size_read(),
csr::cxp_grabber::parser_frame_y_size_read(),
);
if csr::cxp_grabber::core_rx_heartbeat_read() == 1 {
println!(
"host id = {:#X} | heartbeat = {:#X}",
csr::cxp_grabber::core_rx_host_id_read(),
csr::cxp_grabber::core_rx_device_time_read(),
);
csr::cxp_grabber::core_rx_heartbeat_write(1);
};
if csr::cxp_grabber::core_rx_trigger_ack_read() == 1 {
println!("Trigger ack recv and clear");
csr::cxp_grabber::core_rx_trigger_ack_write(1);
} else {
println!("NO Trigger ack");
}
println!(
"CH#0 Decode error = {}",
csr::cxp_grabber::core_rx_reader_decode_err_read()
);
}
}

View File

@ -11,6 +11,8 @@ use super::{cache,
core1::rtio_get_destination_status,
dma, linalg,
rpc::{rpc_recv, rpc_send, rpc_send_async}};
#[cfg(has_cxp_grabber)]
use crate::cxp;
use crate::{eh_artiq, i2c, rtio};
extern "C" {
@ -126,6 +128,20 @@ pub fn resolve(required: &[u8]) -> Option<u32> {
#[cfg(has_drtio)]
api!(subkernel_await_message = subkernel::await_message),
// CoaXPress
#[cfg(has_cxp_grabber)]
api!(cxp_read_words = cxp::cxp_read_words),
#[cfg(has_cxp_grabber)]
api!(cxp_readu32 = cxp::cxp_readu32),
#[cfg(has_cxp_grabber)]
api!(cxp_readu64 = cxp::cxp_readu64),
#[cfg(has_cxp_grabber)]
api!(cxp_writeu32 = cxp::cxp_writeu32),
#[cfg(has_cxp_grabber)]
api!(cxp_writeu64 = cxp::cxp_writeu64),
#[cfg(has_cxp_grabber)]
api!(cxp_debug_frame_print = cxp::cxp_debug_frame_print),
// Double-precision floating-point arithmetic helper functions
// RTABI chapter 4.1.2, Table 2
api!(__aeabi_dadd),

View File

@ -36,6 +36,8 @@ pub mod rtio;
#[path = "../../../build/pl.rs"]
pub mod pl;
#[cfg(has_cxp_grabber)]
pub mod cxp;
#[derive(Debug, Clone)]
pub struct RPCException {