avr-crypto-lib/test_src/circularbytebuffer.h

84 lines
3.0 KiB
C
Raw Permalink Normal View History

2009-07-29 09:49:57 +00:00
/* circularbytebuffer.h */
/*
This file is part of the AVR-circularbytebuffer.
2015-02-06 02:43:31 +00:00
Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
2009-07-29 09:49:57 +00:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file circularbytebuffer.h
2015-02-06 02:43:31 +00:00
* \email bg@nerilex.org
2012-06-20 21:58:55 +00:00
* \author Daniel Otte
2009-07-29 09:49:57 +00:00
* \date 2009-07-24
* \license GPLv3 or later
2012-06-20 21:58:55 +00:00
* \addtogroup circularbytebuffer
2009-07-29 09:49:57 +00:00
* \brief declaration for circular byte buffer
*/
2012-06-20 21:58:55 +00:00
/*@{*/
2009-07-29 09:49:57 +00:00
#ifndef CIRCULARBYTEBUFFER_H_
#define CIRCULARBYTEBUFFER_H_
#include <stdint.h>
#include <stdlib.h>
#include "config.h"
2012-06-20 21:58:55 +00:00
/**
* \brief type holding the managment information for the buffer
*
* A variable of this type may hold all the information to control the buffer
*/
2009-07-29 09:49:57 +00:00
typedef struct {
2012-06-20 21:58:55 +00:00
uint8_t buffer_size; /**< holds the amount of bytes which may be stored in the buffer */
uint8_t fillcount; /**< holds the amount of bytes actually stored in the buffer */
uint8_t *buffer; /**< pointer to the actual buffer */
uint8_t *head; /**< pointer to the head of the buffer */
uint8_t *tail; /**< pointer to the tail of the buffer */
uint8_t *top; /**< pointer to the last free address in the buffer */
2009-07-29 09:49:57 +00:00
} circularbytebuffer_t;
#if CIRCULARBYTEBUFFER_NO_MALLOC==0
2012-06-20 21:58:55 +00:00
/** \brief buffer initialisation with automatic allocation
*
* This function initializes the given buffer context and allocates memory for
* it by calling malloc.
* \param buffersize size of the buffer to allocate
* \param cb buffer context to be initialized
*/
uint8_t circularbytebuffer_init(uint8_t buffersize, circularbytebuffer_t *cb);
2009-07-29 09:49:57 +00:00
#endif
#if CIRCULARBYTEBUFFER_NO_INIT2==0
2012-06-20 21:58:55 +00:00
/** \brief buffer initialisation without automatic allocation
*
* This function initializes the given buffer context and uses the given buffer
* for storage, so no malloc is needed.
* \param buffersize size of the buffer
* \param cb buffer context to be initialized
* \param buffer buffer for the storage of data (you are responisble for allocation and freeing)
*/
void circularbytebuffer_init2(uint8_t buffersize, circularbytebuffer_t *cb, void *buffer);
2009-07-29 09:49:57 +00:00
#endif
2012-06-20 21:58:55 +00:00
/** \brief
*
*
*/
uint16_t circularbytebuffer_get_lifo(circularbytebuffer_t *cb);
uint16_t circularbytebuffer_get_fifo(circularbytebuffer_t *cb);
uint8_t circularbytebuffer_append(uint8_t, circularbytebuffer_t *cb);
uint8_t circularbytebuffer_push(uint8_t, circularbytebuffer_t *cb);
uint8_t circularbytebuffer_cnt(circularbytebuffer_t *cb);
void circularbytebuffer_free(circularbytebuffer_t *cb);
2009-07-29 09:49:57 +00:00
2012-06-20 21:58:55 +00:00
/*@}*/
2009-07-29 09:49:57 +00:00
#endif /* CIRCULARBYTEBUFFER_H_ */