-
Notifications
You must be signed in to change notification settings - Fork 0
/
circBufT.h
executable file
·53 lines (46 loc) · 1.78 KB
/
circBufT.h
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef CIRCBUFT_H_
#define CIRCBUFT_H_
// *******************************************************
//
// circBufT.h
//
// Support for a circular buffer of uint32_t values on the
// Tiva processor.
// P.J. Bones UCECE
// Last modified: 7.3.2017
//
// *******************************************************
#include <stdint.h>
// *******************************************************
// Buffer structure
typedef struct {
uint32_t size; // Number of entries in buffer
uint32_t windex; // index for writing, mod(size)
uint32_t rindex; // index for reading, mod(size)
uint32_t *data; // pointer to the data
} circBuf_t;
// *******************************************************
// initCircBuf: Initialise the circBuf instance. Reset both indices to
// the start of the buffer. Dynamically allocate and clear the the
// memory and return a pointer for the data. Return NULL if
// allocation fails.
uint32_t *
initCircBuf (circBuf_t *buffer, uint32_t size);
// *******************************************************
// writeCircBuf: insert entry at the current windex location,
// advance windex, modulo (buffer size).
void
writeCircBuf (circBuf_t *buffer, uint32_t entry);
// *******************************************************
// readCircBuf: return entry at the current rindex location,
// advance rindex, modulo (buffer size). The function deos not check
// if reading has advanced ahead of writing.
uint32_t
readCircBuf (circBuf_t *buffer);
// *******************************************************
// freeCircBuf: Releases the memory allocated to the buffer data,
// sets pointer to NULL and other fields to 0. The buffer can
// re initialised by another call to initCircBuf().
void
freeCircBuf (circBuf_t *buffer);
#endif /*CIRCBUFT_H_*/