2 ******************************************************************************
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
7 * As with all modules only the initialize function is exposed all other
8 * interactions with the module take place through the event queue and
10 * @see The GNU Public License (GPL) Version 3
12 *****************************************************************************/
14 /*! \file buffer.h \brief Multipurpose byte buffer structure and methods. */
15 // *****************************************************************************
17 // File Name : 'buffer.h'
18 // Title : Multipurpose byte buffer structure and methods
19 // Author : Pascal Stang - Copyright (C) 2001-2002
20 // Created : 9/23/2001
21 // Revised : 11/16/2002
27 /// \defgroup buffer Circular Byte-Buffer Structure and Function Library (buffer.c)
28 /// \code #include "buffer.h" \endcode
30 /// This byte-buffer structure provides an easy and efficient way to store
31 /// and process a stream of bytes. You can create as many buffers as you
32 /// like (within memory limits), and then use this common set of functions to
33 /// access each buffer. The buffers are designed for FIFO operation (first
34 /// in, first out). This means that the first byte you put in the buffer
35 /// will be the first one you get when you read out the buffer. Supported
36 /// functions include buffer initialize, get byte from front of buffer, add
37 /// byte to end of buffer, check if buffer is full, and flush buffer. The
38 /// buffer uses a circular design so no copying of data is ever necessary.
39 /// This buffer is not dynamically allocated, it has a user-defined fixed
40 /// maximum size. This buffer is used in many places in the avrlib code.
42 // This code is distributed under the GNU Public License
43 // which can be found at http://www.gnu.org/licenses/gpl.txt
45 // *****************************************************************************
53 // ! cBuffer structure
54 typedef struct struct_cBuffer
{
55 unsigned char *dataptr
; ///< the physical memory address where the buffer is stored
56 unsigned short size
; ///< the allocated size of the buffer
57 unsigned short datalength
; ///< the length of the data currently in the buffer
58 unsigned short dataindex
; ///< the index into the buffer where the data starts
61 // function prototypes
63 // ! initialize a buffer to start at a given address and have given size
64 void bufferInit(cBuffer
*buffer
, unsigned char *start
, unsigned short size
);
66 // ! get the first byte from the front of the buffer
67 unsigned char bufferGetFromFront(cBuffer
*buffer
);
69 // ! dump (discard) the first numbytes from the front of the buffer
70 void bufferDumpFromFront(cBuffer
*buffer
, unsigned short numbytes
);
72 // ! get a byte at the specified index in the buffer (kind of like array access)
73 // ** note: this does not remove the byte that was read from the buffer
74 unsigned char bufferGetAtIndex(cBuffer
*buffer
, unsigned short index
);
76 // ! add a byte to the end of the buffer
77 unsigned char bufferAddToEnd(cBuffer
*buffer
, unsigned char data
);
79 // ! check if the buffer is full/not full (returns non-zero value if not full)
80 unsigned char bufferIsNotFull(cBuffer
*buffer
);
82 // ! flush (clear) the contents of the buffer
83 void bufferFlush(cBuffer
*buffer
);
85 #endif // ifndef BUFFER_HPP