From 8a2e82560cda0727fb468add0a5117782fe463b4 Mon Sep 17 00:00:00 2001 From: Sylvain Munaut Date: Sun, 17 Apr 2022 07:41:52 +0000 Subject: [PATCH] octoi: Simple RX priming / pre-filling This was not an issue with the original FIFO code, which dynamically substituted frames and always created the minimal required backlog. The RIFO can by principle not operate this way, so we really have to prime / pre-fill it with a number of TDM frames. That initial fill level has to be sufficient to cover RTT jitter of the OCTOI link as well as clock drift between (GPS synced) receiver and transmitter. Signed-off-by: Sylvain Munaut Change-Id: I3a4b3846d3dbd1c99989e994ad95e609f2757219 --- src/octoi/e1oip.c | 3 ++- src/octoi/e1oip.h | 1 + src/octoi/octoi.c | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/octoi/e1oip.c b/src/octoi/e1oip.c index 5dd3bbf..6a5a240 100644 --- a/src/octoi/e1oip.c +++ b/src/octoi/e1oip.c @@ -286,7 +286,7 @@ struct e1oip_line *e1oip_line_alloc(struct octoi_peer *peer) e1oip_line_set_name(iline, peer->name); iline->cfg.batching_factor = 32; - iline->cfg.prefill_frame_count = 400; /* 50ms */ + iline->cfg.prefill_frame_count = 200; /* 25ms */ e1oip_line_reset(iline); @@ -305,6 +305,7 @@ void e1oip_line_reset(struct e1oip_line *iline) frame_rifo_init(&iline->e1t.rifo); memset(&iline->e1t.last_frame, 0xff, sizeof(iline->e1t.last_frame)); iline->e1t.next_fn32 = 0; + iline->e1t.primed_rx_tdm = false; } void e1oip_line_destroy(struct e1oip_line *iline) diff --git a/src/octoi/e1oip.h b/src/octoi/e1oip.h index 70e1bbb..1a184d2 100644 --- a/src/octoi/e1oip.h +++ b/src/octoi/e1oip.h @@ -53,6 +53,7 @@ struct e1oip_line { struct frame_rifo rifo; uint8_t last_frame[BYTES_PER_FRAME]; /* last frame on the E1 side */ uint32_t next_fn32; /* next expected frame number */ + bool primed_rx_tdm; /* Was RX RIFO primed */ } e1t; /* TODO: statistics (RTT, frame loss, std deviation, alarms */ diff --git a/src/octoi/octoi.c b/src/octoi/octoi.c index d2960ac..8585f0d 100644 --- a/src/octoi/octoi.c +++ b/src/octoi/octoi.c @@ -118,6 +118,12 @@ void octoi_peer_e1t_out(struct octoi_peer *peer, uint8_t *buf, int fts) if (!peer->tdm_permitted) return; + if (!iline->e1t.primed_rx_tdm) { + if (frame_rifo_frames(&iline->e1t.rifo) > iline->cfg.prefill_frame_count) + iline->e1t.primed_rx_tdm = true; + return; + } + for (int i = 0; i < fts; i++) { uint8_t *cur = buf + BYTES_PER_FRAME*i; rc = frame_rifo_out(&iline->e1t.rifo, cur);