feat(asym): --rx-bytes/--tx-bytes frame sizing; experiments prove SM3 partial-read freezes bridge mirror (1400B full read mandatory) and cycle floor is RFM-ring-bound (563us) not EtherCAT wire (tx 400B leaves period unchanged)
This commit is contained in:
parent
aadb889b91
commit
988f4bac9d
24
src/main.rs
24
src/main.rs
|
|
@ -152,6 +152,10 @@ struct Config {
|
||||||
dc_align: bool,
|
dc_align: bool,
|
||||||
/// rfm-async DC alignment: FPWR grid phase (ns into 250us grid).
|
/// rfm-async DC alignment: FPWR grid phase (ns into 250us grid).
|
||||||
dc_wphase_ns: i64,
|
dc_wphase_ns: i64,
|
||||||
|
/// Per-frame exchange sizes (bytes of each SM buffer carried per frame).
|
||||||
|
/// SM buffers stay 1400B; only the frame payload shrinks.
|
||||||
|
rx_bytes: usize,
|
||||||
|
tx_bytes: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_args() -> Result<Config, String> {
|
fn parse_args() -> Result<Config, String> {
|
||||||
|
|
@ -183,6 +187,8 @@ fn parse_args() -> Result<Config, String> {
|
||||||
sync_offset_ns: 0,
|
sync_offset_ns: 0,
|
||||||
dc_align: false,
|
dc_align: false,
|
||||||
dc_wphase_ns: 125_000,
|
dc_wphase_ns: 125_000,
|
||||||
|
rx_bytes: 1400,
|
||||||
|
tx_bytes: 1400,
|
||||||
};
|
};
|
||||||
let mut args = std::env::args().skip(1).peekable();
|
let mut args = std::env::args().skip(1).peekable();
|
||||||
if let Some(a) = args.peek() {
|
if let Some(a) = args.peek() {
|
||||||
|
|
@ -240,6 +246,8 @@ fn parse_args() -> Result<Config, String> {
|
||||||
"--sync-offset-ns" => { cfg.sync_offset_ns = val("--sync-offset-ns")?.parse().map_err(|_| "bad --sync-offset-ns")?; },
|
"--sync-offset-ns" => { cfg.sync_offset_ns = val("--sync-offset-ns")?.parse().map_err(|_| "bad --sync-offset-ns")?; },
|
||||||
"--dc-align" => cfg.dc_align = true,
|
"--dc-align" => cfg.dc_align = true,
|
||||||
"--dc-wphase-ns" => { cfg.dc_wphase_ns = val("--dc-wphase-ns")?.parse().map_err(|_| "bad --dc-wphase-ns")?; },
|
"--dc-wphase-ns" => { cfg.dc_wphase_ns = val("--dc-wphase-ns")?.parse().map_err(|_| "bad --dc-wphase-ns")?; },
|
||||||
|
"--rx-bytes" => { cfg.rx_bytes = val("--rx-bytes")?.parse().map_err(|_| "bad --rx-bytes")?; },
|
||||||
|
"--tx-bytes" => { cfg.tx_bytes = val("--tx-bytes")?.parse().map_err(|_| "bad --tx-bytes")?; },
|
||||||
"--el2202" => cfg.el2202 = true,
|
"--el2202" => cfg.el2202 = true,
|
||||||
"--el2202-dual" => {
|
"--el2202-dual" => {
|
||||||
cfg.el2202 = true;
|
cfg.el2202 = true;
|
||||||
|
|
@ -1663,7 +1671,7 @@ async fn run(cfg: &Config) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// ---- rfm-async: event-driven forwarder, no tick ----
|
// ---- rfm-async: event-driven forwarder, no tick ----
|
||||||
if cfg.mode == Mode::RfmAsync {
|
if cfg.mode == Mode::RfmAsync {
|
||||||
let rfm = rfm_ctx.take().expect("rfm not opened");
|
let rfm = rfm_ctx.take().expect("rfm not opened");
|
||||||
return rfm_async_loop(&maindevice, station, rfm, cfg.duration_sec, cfg.fprd_gate_us, cfg.dc_discipline, &sd, cfg.dc_align, cfg.sync_offset_ns, cfg.dc_wphase_ns).await;
|
return rfm_async_loop(&maindevice, station, rfm, cfg.duration_sec, cfg.fprd_gate_us, cfg.dc_discipline, &sd, cfg.dc_align, cfg.sync_offset_ns, cfg.dc_wphase_ns, cfg.rx_bytes, cfg.tx_bytes).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- rfm-lrw: single-frame read+write loop ----
|
// ---- rfm-lrw: single-frame read+write loop ----
|
||||||
|
|
@ -2520,9 +2528,9 @@ async fn rfm_lrw_loop(
|
||||||
let mut last_rep_seq: u64 = 0;
|
let mut last_rep_seq: u64 = 0;
|
||||||
let mut req_seq: u64 = 0;
|
let mut req_seq: u64 = 0;
|
||||||
let mut tx_latest = vec![0u8; PAYLOAD_LEN];
|
let mut tx_latest = vec![0u8; PAYLOAD_LEN];
|
||||||
// Frame-limited LRW: span 1466B (Ethernet frame <=1518B with headers) =
|
// Asym test: span 2000B (write SM2 head 600 + read SM3 head 600 in current
|
||||||
// write SM2 full 1400B + read SM3 head 66B (tc_seq for freshness).
|
// logical layout) -> frame ~2030B, expected to exceed Ethernet limit.
|
||||||
let lrw_span: usize = 1466;
|
let lrw_span: usize = 2000;
|
||||||
let mut frame = vec![0u8; lrw_span + 8];
|
let mut frame = vec![0u8; lrw_span + 8];
|
||||||
let (mut n_iter, mut n_fresh, mut n_req, mut n_rep, mut n_err) = (0u64, 0u64, 0u64, 0u64, 0u64);
|
let (mut n_iter, mut n_fresh, mut n_req, mut n_rep, mut n_err) = (0u64, 0u64, 0u64, 0u64, 0u64);
|
||||||
let (mut lrw_sum, mut hop_sum, mut cx2j_sum) = (0u64, 0u64, 0u64);
|
let (mut lrw_sum, mut hop_sum, mut cx2j_sum) = (0u64, 0u64, 0u64);
|
||||||
|
|
@ -2641,6 +2649,8 @@ async fn rfm_async_loop(
|
||||||
dc_align: bool,
|
dc_align: bool,
|
||||||
sync_offset_ns: i64,
|
sync_offset_ns: i64,
|
||||||
dc_wphase_ns: i64,
|
dc_wphase_ns: i64,
|
||||||
|
rx_bytes: usize,
|
||||||
|
tx_bytes: usize,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
use el6695_rt::rfm::*;
|
use el6695_rt::rfm::*;
|
||||||
println!("rfm-async: event-driven forwarding, no tick (Ctrl-C to stop)");
|
println!("rfm-async: event-driven forwarding, no tick (Ctrl-C to stop)");
|
||||||
|
|
@ -2825,7 +2835,7 @@ async fn rfm_async_loop(
|
||||||
{
|
{
|
||||||
let fut = async move {
|
let fut = async move {
|
||||||
ethercrab::Command::fprd(station, SM_RX_ADDR)
|
ethercrab::Command::fprd(station, SM_RX_ADDR)
|
||||||
.receive_slice(maindevice, SM_RX_LEN as u16)
|
.receive_slice(maindevice, rx_bytes as u16)
|
||||||
.await
|
.await
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
let mut v = Vec::with_capacity(SM_RX_LEN);
|
let mut v = Vec::with_capacity(SM_RX_LEN);
|
||||||
|
|
@ -3034,7 +3044,7 @@ async fn rfm_async_loop(
|
||||||
tx_slot_toggle = !tx_slot_toggle;
|
tx_slot_toggle = !tx_slot_toggle;
|
||||||
let slot: &'static mut [u8] =
|
let slot: &'static mut [u8] =
|
||||||
unsafe { std::slice::from_raw_parts_mut(p, PAYLOAD_LEN) };
|
unsafe { std::slice::from_raw_parts_mut(p, PAYLOAD_LEN) };
|
||||||
slot.copy_from_slice(&tx_latest[..PAYLOAD_LEN]);
|
slot[..tx_bytes].copy_from_slice(&tx_latest[..tx_bytes]);
|
||||||
// Phase A stamps: aIn1[264..271]=t_d2k_ns, aIn1[272..279]=plc_ts_echo
|
// Phase A stamps: aIn1[264..271]=t_d2k_ns, aIn1[272..279]=plc_ts_echo
|
||||||
slot[264..272].copy_from_slice(&now_ns().to_le_bytes());
|
slot[264..272].copy_from_slice(&now_ns().to_le_bytes());
|
||||||
slot[272..280].copy_from_slice(&plc_ts_echo.to_le_bytes());
|
slot[272..280].copy_from_slice(&plc_ts_echo.to_le_bytes());
|
||||||
|
|
@ -3043,7 +3053,7 @@ async fn rfm_async_loop(
|
||||||
last_wkick = Some(Instant::now());
|
last_wkick = Some(Instant::now());
|
||||||
let fut = async move {
|
let fut = async move {
|
||||||
ethercrab::Command::fpwr(station, SM_TX_ADDR)
|
ethercrab::Command::fpwr(station, SM_TX_ADDR)
|
||||||
.send_receive_slice(maindevice, &slot[..PAYLOAD_LEN])
|
.send_receive_slice(maindevice, &slot[..tx_bytes])
|
||||||
.await
|
.await
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user