| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <linux/spinlock.h> |
| 4 |
|
| 5 |
#define BYTES_PER_FRAME 32 |
| 6 |
#define FRAMES_PER_FIFO 800 |
| 7 |
|
| 8 |
struct frame_fifo { |
| 9 |
spinlock_t lock; |
| 10 |
uint8_t *next_in; |
| 11 |
uint8_t *next_out; |
| 12 |
uint8_t threshold; |
| 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 |
|
| 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 |
|
| 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 |
|
| 49 |
int frame_fifo_in(struct frame_fifo *fifo, const uint8_t *frame); |
| 50 |
|
| 51 |
|
| 52 |
int frame_fifo_in_multi(struct frame_fifo *fifo, const uint8_t *frame, size_t count); |
| 53 |
|
| 54 |
|
| 55 |
int frame_fifo_out(struct frame_fifo *fifo, uint8_t *out); |
| 56 |
|
| 57 |
|
| 58 |
int frame_fifo_out_multi(struct frame_fifo *fifo, uint8_t *out, size_t count); |
| 59 |
|
| 60 |
|
| 61 |
void fifo_dump(struct frame_fifo *fifo); |