]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/circularbytebuffer.h
fixing E-Mail-Address & Copyright
[avr-crypto-lib.git] / test_src / circularbytebuffer.h
1 /* circularbytebuffer.h */
2 /*
3     This file is part of the AVR-circularbytebuffer.
4     Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 /**
20  * \file     circularbytebuffer.h
21  * \email    bg@nerilex.org
22  * \author   Daniel Otte
23  * \date     2009-07-24
24  * \license  GPLv3 or later
25  * \addtogroup  circularbytebuffer
26  * \brief    declaration for circular byte buffer
27  */
28 /*@{*/
29 #ifndef CIRCULARBYTEBUFFER_H_
30 #define CIRCULARBYTEBUFFER_H_
31
32 #include <stdint.h>
33 #include <stdlib.h>
34 #include "config.h"
35  /**
36   * \brief type holding the managment information for the buffer
37   *
38   * A variable of this type may hold all the information to control the buffer
39   */
40  typedef struct {
41          uint8_t buffer_size; /**< holds the amount of bytes which may be stored in the buffer */
42          uint8_t fillcount; /**< holds the amount of bytes actually stored in the buffer */
43          uint8_t *buffer; /**< pointer to the actual  buffer */
44          uint8_t *head; /**< pointer to the head of the buffer */
45          uint8_t *tail; /**< pointer to the tail of the buffer */
46          uint8_t *top; /**< pointer to the last free address in the buffer */
47 } circularbytebuffer_t;
48
49
50 #if CIRCULARBYTEBUFFER_NO_MALLOC==0
51 /** \brief buffer initialisation with automatic allocation
52  *
53  * This function initializes the given buffer context and allocates memory for
54  * it by calling malloc.
55  * \param buffersize size of the buffer to allocate
56  * \param cb buffer context to be initialized
57  */
58 uint8_t circularbytebuffer_init(uint8_t buffersize, circularbytebuffer_t *cb);
59 #endif
60 #if CIRCULARBYTEBUFFER_NO_INIT2==0
61 /** \brief buffer initialisation without automatic allocation
62  *
63  * This function initializes the given buffer context and uses the given buffer
64  * for storage, so no malloc is needed.
65  * \param buffersize size of the buffer
66  * \param cb buffer context to be initialized
67  * \param buffer buffer for the storage of data (you are responisble for allocation and freeing)
68  */
69 void    circularbytebuffer_init2(uint8_t buffersize, circularbytebuffer_t *cb, void *buffer);
70 #endif
71 /** \brief
72  *
73  *
74  */
75 uint16_t circularbytebuffer_get_lifo(circularbytebuffer_t *cb);
76 uint16_t circularbytebuffer_get_fifo(circularbytebuffer_t *cb);
77 uint8_t circularbytebuffer_append(uint8_t, circularbytebuffer_t *cb);
78 uint8_t circularbytebuffer_push(uint8_t, circularbytebuffer_t *cb);
79 uint8_t circularbytebuffer_cnt(circularbytebuffer_t *cb);
80 void circularbytebuffer_free(circularbytebuffer_t *cb);
81
82 /*@}*/
83 #endif /* CIRCULARBYTEBUFFER_H_ */