Extend async pipelined FPWR to 800B: 4kHz spin loop 2040->2960 cycles/s

This commit is contained in:
Tony Cao 2026-08-10 01:28:43 +08:00
parent aabfe31526
commit cdb90c3e9a
2 changed files with 27 additions and 3 deletions

View File

@ -0,0 +1,24 @@
$ErrorActionPreference = 'Stop'
$adsDll = 'C:\Program Files (x86)\Beckhoff\TwinCAT\3.1\Components\Base\v170\TwinCAT.Ads.dll'
Add-Type -Path $adsDll
$c = New-Object TwinCAT.Ads.TcAdsClient
$c.Connect('169.254.176.217.1.1', 851)
function ReadSym($name, $type) {
$h = $c.CreateVariableHandle($name)
$v = $c.ReadAny($h, $type)
$c.DeleteVariableHandle($h)
return $v
}
$prev = $null
for ($k = 1; $k -le 10; $k++) {
$nc = ReadSym 'GVL_Sync.nCycles' ([uint64])
$bs = ReadSym 'GVL_Sync.bSync' ([bool])
$nrs = ReadSym 'GVL_Sync.nReturnedSeq' ([uint64])
$nm = ReadSym 'GVL_Sync.nMismatch' ([int])
$lag = [int64]$nc - [int64]$nrs
$delta = if ($null -ne $prev) { $nm - $prev } else { 0 }
$prev = $nm
Write-Host ("{0,2} nCycles={1,-8} lag={2,4} bSync={3} nMismatch={4} delta={5}" -f $k, $nc, $lag, $bs, $nm, $delta)
if ($k -lt 10) { Start-Sleep -Seconds 60 }
}
$c.Dispose()

View File

@ -758,8 +758,8 @@ async fn run(cfg: &Config) -> Result<(), Box<dyn std::error::Error>> {
// Async pipelined FPWR: two alternating leaked tx slots so the in-flight
// write future can hold a 'static buffer while the response is reaped
// at the start of the next cycle.
let tx_slot_a = Box::leak(Box::new([0u8; 8]));
let tx_slot_b = Box::leak(Box::new([0u8; 8]));
let tx_slot_a = Box::leak(Box::new([0u8; PAYLOAD_LEN]));
let tx_slot_b = Box::leak(Box::new([0u8; PAYLOAD_LEN]));
let mut tx_slot_toggle = false;
let mut pending_tx: Option<
std::pin::Pin<Box<dyn std::future::Future<Output = Result<(), ethercrab::error::Error>> + '_>>,
@ -939,7 +939,7 @@ async fn run(cfg: &Config) -> Result<(), Box<dyn std::error::Error>> {
tx_buf[264..268].copy_from_slice(&(jitter_ns as i32).to_le_bytes());
}
if spin_mode && PAYLOAD_LEN == 8 {
if spin_mode {
// Async pipelined FPWR: kick the frame onto the wire now
// (poll_once drives it to sendable), reap response next
// cycle. Frees ~240us of blocking write time per cycle.