summaryrefslogtreecommitdiff
path: root/kernel/ringbuffer.h
blob: bb2b875c3b061bff4e7abb4d29516071860a35c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef RINGBUFFER_H
#define RINGBUFFER_H

#include <stdint.h>
#include <stdbool.h>

// Simple FIRST IN FIRST OUT
// requires kballoc - block allocation

typedef volatile struct ringbuffer_struct
{
    uint32_t size;
    uint32_t front;
    uint32_t back;

    uint8_t *data;

}ringbuffer;

// create new fifo/ringbuffer of given size (in blocks)
ringbuffer ringbuffer_init(uint32_t blocks); 

// true on success
bool	ringbuffer_put(ringbuffer*,uint8_t);
uint8_t ringbuffer_get(ringbuffer*);	    // non-blocking please check first
bool	ringbuffer_has(ringbuffer*);	    // check if somehting waiting?

#endif