Debian Codegraph @

drivers/dahdi/trunkdev/frame_fifo.h

raw symbols SCIP
1 #pragma once
2
3 #include <linux/spinlock.h>
4
5 #define BYTES_PER_FRAME 32
6 #define FRAMES_PER_FIFO 800 /* 100ms @ 8000 frames per second */
7
8 struct frame_fifo {
9 spinlock_t lock;
10 uint8_t *next_in; /* where to write next input into FIFO */
11 uint8_t *next_out; /* where to read next output from FIFO */
12 uint8_t threshold; /* number of frames that should trigger */
13 void (*threshold_cb)(struct frame_fifo *fifo, unsigned int frames, void *priv);
14 void *priv;
15
16 uint8_t buf[BYTES_PER_FRAME * FRAMES_PER_FIFO];
17 };
18
19 void frame_fifo_init(struct frame_fifo *fifo, unsigned int threshold,
20 void (*threshold_cb)(struct frame_fifo *fifo, unsigned int frames, void *priv),
21 void *priv);
22
23 void frame_fifo_flush(struct frame_fifo *fifo);
24
25 /* number of frames currently available in FIFO */
26 static inline unsigned int __frame_fifo_frames(struct frame_fifo *fifo)
27 {
28 return ((fifo->next_in + sizeof(fifo->buf) - fifo->next_out) % sizeof(fifo->buf)) / BYTES_PER_FRAME;
29 }
30 static inline unsigned int frame_fifo_frames(struct frame_fifo *fifo)
31 {
32 unsigned long flags;
33 unsigned int ret;
34
35 spin_lock_irqsave(&fifo->lock, flags);
36 ret = __frame_fifo_frames(fifo);
37 spin_unlock_irqrestore(&fifo->lock, flags);
38
39 return ret;
40 }
41
42 /* for how many frames do we have space in the FIFO? */
43 static inline unsigned int frame_fifo_space(struct frame_fifo *fifo)
44 {
45 return FRAMES_PER_FIFO - frame_fifo_frames(fifo);
46 }
47
48 /* put a received frame into the FIFO */
49 int frame_fifo_in(struct frame_fifo *fifo, const uint8_t *frame);
50
51 /* put multiple received frames into the FIFO */
52 int frame_fifo_in_multi(struct frame_fifo *fifo, const uint8_t *frame, size_t count);
53
54 /* pull one frame out of the FIFO */
55 int frame_fifo_out(struct frame_fifo *fifo, uint8_t *out);
56
57 /* pull multiple frames out of the FIFO */
58 int frame_fifo_out_multi(struct frame_fifo *fifo, uint8_t *out, size_t count);
59
60 /* dump FIFO state to kernel log */
61 void fifo_dump(struct frame_fifo *fifo);