-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfifo.h
79 lines (61 loc) · 2.17 KB
/
fifo.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/** \file utils.h
* \brief FIFO library header file
* This library enables use of buffers as circular FIFOs
*
* \date 01/12/2020
* \author Felipe Glaria
*/
#ifndef _FIFO_H_
#define _FIFO_H_
#include <stdint.h>
#include <stdbool.h>
//*****************************************************************************
// defines
//*****************************************************************************
//*****************************************************************************
// typedefs
//*****************************************************************************
/** \struct fifo8_t
* Structure to use uint8_t buffer as FIFO
*/
typedef struct {
volatile uint8_t *buffer;
volatile uint8_t *first;
volatile uint8_t *last;
volatile uint8_t queued;
volatile uint8_t max_size;
} fifo8_t;
//*****************************************************************************
// globals
//*****************************************************************************
//*****************************************************************************
// the function prototypes
//*****************************************************************************
/** \brief Function to initialize fifo8_t to use uint8_t buffer as FIFO
*
* \param fifo Pointer to fifo8_t structure
* \param buffer Buffer to uint8_t buffer to use as FIFO
* \param max_size Size of buffer
*/
void fifo8_init(volatile fifo8_t * const fifo, volatile uint8_t * const buffer, const uint8_t size);
/** \brief Function to get byte on FIFO
*
* \param fifo Pointer to fifo8_t structure
* \param byte Pointer to byte to write output
*
* \return true if byte was pulled from FIFO; false if no byte on FIFO
*/
bool fifo8_pull(volatile fifo8_t * const fifo, volatile uint8_t *byte);
/** \brief Function to push byte on FIFO
*
* \param fifo Pointer to fifo8_t structure
* \param byte Byte to push on FIFO
*/
void fifo8_push(volatile fifo8_t * const fifo, const uint8_t byte);
/** \brief Function to flush fifo
*
* \param fifo Pointer to fifo8_t structure to flush
*/
void fifo8_flush(volatile fifo8_t * const fifo);
#endif /* _FIFO_H_ */
/*** end of file ***/