Lines Matching full:fifo

2  * Generic FIFO component, implemented as a circular buffer.
19 void fifo8_reset(Fifo8 *fifo) in fifo8_reset() argument
21 fifo->num = 0; in fifo8_reset()
22 fifo->head = 0; in fifo8_reset()
25 void fifo8_create(Fifo8 *fifo, uint32_t capacity) in fifo8_create() argument
27 fifo->data = g_new(uint8_t, capacity); in fifo8_create()
28 fifo->capacity = capacity; in fifo8_create()
29 fifo8_reset(fifo); in fifo8_create()
32 void fifo8_destroy(Fifo8 *fifo) in fifo8_destroy() argument
34 g_free(fifo->data); in fifo8_destroy()
37 void fifo8_push(Fifo8 *fifo, uint8_t data) in fifo8_push() argument
39 assert(fifo->num < fifo->capacity); in fifo8_push()
40 fifo->data[(fifo->head + fifo->num) % fifo->capacity] = data; in fifo8_push()
41 fifo->num++; in fifo8_push()
44 void fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num) in fifo8_push_all() argument
48 assert(fifo->num + num <= fifo->capacity); in fifo8_push_all()
50 start = (fifo->head + fifo->num) % fifo->capacity; in fifo8_push_all()
52 if (start + num <= fifo->capacity) { in fifo8_push_all()
53 memcpy(&fifo->data[start], data, num); in fifo8_push_all()
55 avail = fifo->capacity - start; in fifo8_push_all()
56 memcpy(&fifo->data[start], data, avail); in fifo8_push_all()
57 memcpy(&fifo->data[0], &data[avail], num - avail); in fifo8_push_all()
60 fifo->num += num; in fifo8_push_all()
63 uint8_t fifo8_pop(Fifo8 *fifo) in fifo8_pop() argument
67 assert(fifo->num > 0); in fifo8_pop()
68 ret = fifo->data[fifo->head++]; in fifo8_pop()
69 fifo->head %= fifo->capacity; in fifo8_pop()
70 fifo->num--; in fifo8_pop()
74 uint8_t fifo8_peek(Fifo8 *fifo) in fifo8_peek() argument
76 assert(fifo->num > 0); in fifo8_peek()
77 return fifo->data[fifo->head]; in fifo8_peek()
80 static const uint8_t *fifo8_peekpop_bufptr(Fifo8 *fifo, uint32_t max, in fifo8_peekpop_bufptr() argument
87 assert(max > 0 && max <= fifo->num); in fifo8_peekpop_bufptr()
88 assert(skip <= fifo->num); in fifo8_peekpop_bufptr()
89 head = (fifo->head + skip) % fifo->capacity; in fifo8_peekpop_bufptr()
90 num = MIN(fifo->capacity - head, max); in fifo8_peekpop_bufptr()
91 ret = &fifo->data[head]; in fifo8_peekpop_bufptr()
94 fifo->head = head + num; in fifo8_peekpop_bufptr()
95 fifo->head %= fifo->capacity; in fifo8_peekpop_bufptr()
96 fifo->num -= num; in fifo8_peekpop_bufptr()
104 const uint8_t *fifo8_peek_bufptr(Fifo8 *fifo, uint32_t max, uint32_t *numptr) in fifo8_peek_bufptr() argument
106 return fifo8_peekpop_bufptr(fifo, max, 0, numptr, false); in fifo8_peek_bufptr()
109 const uint8_t *fifo8_pop_bufptr(Fifo8 *fifo, uint32_t max, uint32_t *numptr) in fifo8_pop_bufptr() argument
111 return fifo8_peekpop_bufptr(fifo, max, 0, numptr, true); in fifo8_pop_bufptr()
114 static uint32_t fifo8_peekpop_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen, in fifo8_peekpop_buf() argument
126 buf = fifo8_peekpop_bufptr(fifo, len, 0, &n1, do_pop); in fifo8_peekpop_buf()
131 /* Add FIFO wraparound if needed */ in fifo8_peekpop_buf()
133 len = MIN(len, fifo8_num_used(fifo)); in fifo8_peekpop_buf()
135 buf = fifo8_peekpop_bufptr(fifo, len, do_pop ? 0 : n1, &n2, do_pop); in fifo8_peekpop_buf()
144 uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen) in fifo8_pop_buf() argument
146 return fifo8_peekpop_buf(fifo, dest, destlen, true); in fifo8_pop_buf()
149 uint32_t fifo8_peek_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen) in fifo8_peek_buf() argument
151 return fifo8_peekpop_buf(fifo, dest, destlen, false); in fifo8_peek_buf()
154 void fifo8_drop(Fifo8 *fifo, uint32_t len) in fifo8_drop() argument
156 len -= fifo8_pop_buf(fifo, NULL, len); in fifo8_drop()
160 bool fifo8_is_empty(Fifo8 *fifo) in fifo8_is_empty() argument
162 return (fifo->num == 0); in fifo8_is_empty()
165 bool fifo8_is_full(Fifo8 *fifo) in fifo8_is_full() argument
167 return (fifo->num == fifo->capacity); in fifo8_is_full()
170 uint32_t fifo8_num_free(Fifo8 *fifo) in fifo8_num_free() argument
172 return fifo->capacity - fifo->num; in fifo8_num_free()
175 uint32_t fifo8_num_used(Fifo8 *fifo) in fifo8_num_used() argument
177 return fifo->num; in fifo8_num_used()