1 /*!
2  * \file      fifo.h
3  *
4  * \brief     FIFO buffer implementation
5  *
6  * \copyright Revised BSD License, see section \ref LICENSE.
7  *
8  * \code
9  *                ______                              _
10  *               / _____)             _              | |
11  *              ( (____  _____ ____ _| |_ _____  ____| |__
12  *               \____ \| ___ |    (_   _) ___ |/ ___)  _ \
13  *               _____) ) ____| | | || |_| ____( (___| | | |
14  *              (______/|_____)_|_|_| \__)_____)\____)_| |_|
15  *              (C)2013-2017 Semtech
16  *
17  * \endcode
18  *
19  * \author    Miguel Luis ( Semtech )
20  *
21  * \author    Gregory Cristian ( Semtech )
22  */
23 #ifndef __FIFO_H__
24 #define __FIFO_H__
25 
26 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30 
31 #include <stdbool.h>
32 #include <stdint.h>
33 
34 /*!
35  * FIFO structure
36  */
37 typedef struct Fifo_s
38 {
39     uint16_t Begin;
40     uint16_t End;
41     uint8_t *Data;
42     uint16_t Size;
43 }Fifo_t;
44 
45 /*!
46  * Initializes the FIFO structure
47  *
48  * \param [IN] fifo   Pointer to the FIFO object
49  * \param [IN] buffer Buffer to be used as FIFO
50  * \param [IN] size   Size of the buffer
51  */
52 void FifoInit( Fifo_t *fifo, uint8_t *buffer, uint16_t size );
53 
54 /*!
55  * Pushes data to the FIFO
56  *
57  * \param [IN] fifo Pointer to the FIFO object
58  * \param [IN] data Data to be pushed into the FIFO
59  */
60 void FifoPush( Fifo_t *fifo, uint8_t data );
61 
62 /*!
63  * Pops data from the FIFO
64  *
65  * \param [IN] fifo Pointer to the FIFO object
66  * \retval data     Data popped from the FIFO
67  */
68 uint8_t FifoPop( Fifo_t *fifo );
69 
70 /*!
71  * Flushes the FIFO
72  *
73  * \param [IN] fifo   Pointer to the FIFO object
74  */
75 void FifoFlush( Fifo_t *fifo );
76 
77 /*!
78  * Checks if the FIFO is empty
79  *
80  * \param [IN] fifo   Pointer to the FIFO object
81  * \retval isEmpty    true: FIFO is empty, false FIFO is not empty
82  */
83 bool IsFifoEmpty( Fifo_t *fifo );
84 
85 /*!
86  * Checks if the FIFO is full
87  *
88  * \param [IN] fifo   Pointer to the FIFO object
89  * \retval isFull     true: FIFO is full, false FIFO is not full
90  */
91 bool IsFifoFull( Fifo_t *fifo );
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 
97 #endif // __FIFO_H__
98