aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2022-04-20 13:12:54 +0000
committerHarald Welte <laforge@osmocom.org>2022-04-20 15:48:26 +0200
commitd413cbcb4b7a20d209362e6d2b3703ed08fedbbe (patch)
tree3d1e4a65b46a35ae7ae1fe6b13c1b8711175e318 /src
parentce817ca1491390d1f67051a7180ea73c3596a70e (diff)
octoi: Fix frame_rifo_depth() function
We use the 'correct' math in frame_rifo_depth now so the count is accurate down to zero. We need to fixup the logic that drags the 'write pointer' (last_in_fn) along when reading from an empty FIFO. We also need proper init (which was missing alltogether beforehand). Change-Id: I088f181e74358eb2c96a7aab7a7c875b9276d980 Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Diffstat (limited to 'src')
-rw-r--r--src/octoi/frame_rifo.c8
-rw-r--r--src/octoi/frame_rifo.h2
2 files changed, 6 insertions, 4 deletions
diff --git a/src/octoi/frame_rifo.c b/src/octoi/frame_rifo.c
index 94758e9..876f023 100644
--- a/src/octoi/frame_rifo.c
+++ b/src/octoi/frame_rifo.c
@@ -97,6 +97,7 @@ void frame_rifo_init(struct frame_rifo *rifo)
memset(rifo->buf, 0xff, sizeof(rifo->buf));
rifo->next_out = rifo->buf;
rifo->next_out_fn = 0;
+ rifo->last_in_fn = -1;
memset(rifo->bitvec, 0, sizeof(rifo->bitvec));
}
@@ -151,10 +152,11 @@ int frame_rifo_out(struct frame_rifo *rifo, uint8_t *out)
if (rifo->next_out >= RIFO_BUF_END(rifo))
rifo->next_out -= sizeof(rifo->buf);
+ /* if we're empty we 'drag' last_in along to avoid overflows */
+ if (frame_rifo_depth(rifo) == 0)
+ rifo->last_in_fn += 1;
+
rifo->next_out_fn += 1;
- /* make sure that frame_rifo_depth() doing last_in - next_out won't overflow */
- if (rifo->next_out_fn == rifo->last_in_fn + 1)
- rifo->last_in_fn = rifo->next_out_fn;
return rc;
}
diff --git a/src/octoi/frame_rifo.h b/src/octoi/frame_rifo.h
index 401e873..ac97506 100644
--- a/src/octoi/frame_rifo.h
+++ b/src/octoi/frame_rifo.h
@@ -24,7 +24,7 @@ static inline bool frame_rifo_fn_in_range(const struct frame_rifo *ff, uint32_t
/* current depth of RIFO */
static inline unsigned int frame_rifo_depth(struct frame_rifo *rifo)
{
- return rifo->last_in_fn - rifo->next_out_fn;
+ return rifo->last_in_fn - rifo->next_out_fn + 1;
}
void frame_rifo_init(struct frame_rifo *rifo);