2010-03-20 16:45:15 +01:00
|
|
|
|
/**
|
|
|
|
|
******************************************************************************
|
2010-07-16 21:53:35 +02:00
|
|
|
|
* @addtogroup OpenPilotModules OpenPilot Modules
|
|
|
|
|
* @{
|
|
|
|
|
* @addtogroup GSPModule GPS Module
|
|
|
|
|
* @brief Process GPS information
|
|
|
|
|
* @{
|
2010-03-20 16:45:15 +01:00
|
|
|
|
*
|
|
|
|
|
* @file buffer.c
|
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
|
* @brief see below
|
|
|
|
|
* As with all modules only the initialize function is exposed all other
|
|
|
|
|
* interactions with the module take place through the event queue and
|
|
|
|
|
* objects.
|
|
|
|
|
* @see The GNU Public License (GPL) Version 3
|
|
|
|
|
*
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
|
//
|
|
|
|
|
// File Name : 'buffer.h'
|
|
|
|
|
// Title : Multipurpose byte buffer structure and methods
|
|
|
|
|
// Author : Pascal Stang - Copyright (C) 2001-2002
|
|
|
|
|
// Created : 9/23/2001
|
|
|
|
|
// Revised : 11/16/2002
|
|
|
|
|
// Version : 1.1
|
|
|
|
|
// Target MCU : any
|
|
|
|
|
// Editor Tabs : 4
|
|
|
|
|
//
|
|
|
|
|
/// \code #include "buffer.h" \endcode
|
|
|
|
|
/// \par Overview
|
|
|
|
|
/// This byte-buffer structure provides an easy and efficient way to store
|
|
|
|
|
/// and process a stream of bytes.<2E> You can create as many buffers as you
|
|
|
|
|
/// like (within memory limits), and then use this common set of functions to
|
|
|
|
|
/// access each buffer.<2E> The buffers are designed for FIFO<46>operation (first
|
|
|
|
|
/// in, first out).<2E> This means that the first byte you put in the buffer
|
|
|
|
|
/// will be the first one you get when you read out the buffer.<2E> Supported
|
|
|
|
|
/// functions include buffer initialize, get byte from front of buffer, add
|
|
|
|
|
/// byte to end of buffer, check if buffer is full, and flush buffer.<2E> The
|
|
|
|
|
/// buffer uses a circular design so no copying of data is ever necessary.
|
|
|
|
|
/// This buffer is not dynamically allocated, it has a user-defined fixed
|
|
|
|
|
/// maximum size.<2E> This buffer is used in many places in the avrlib code.
|
|
|
|
|
//
|
|
|
|
|
// This code is distributed under the GNU Public License
|
|
|
|
|
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
|
|
|
|
//
|
|
|
|
|
//*****************************************************************************
|
|
|
|
|
//@{
|
|
|
|
|
|
|
|
|
|
#ifndef BUFFER_H
|
|
|
|
|
#define BUFFER_H
|
|
|
|
|
|
2010-08-25 07:32:52 +02:00
|
|
|
|
#include "stdint.h"
|
|
|
|
|
|
2010-03-20 16:45:15 +01:00
|
|
|
|
// structure/typdefs
|
|
|
|
|
|
|
|
|
|
//! cBuffer structure
|
|
|
|
|
typedef struct struct_cBuffer
|
|
|
|
|
{
|
|
|
|
|
unsigned char *dataptr; ///< the physical memory address where the buffer is stored
|
|
|
|
|
unsigned short size; ///< the allocated size of the buffer
|
|
|
|
|
unsigned short datalength; ///< the length of the data currently in the buffer
|
|
|
|
|
unsigned short dataindex; ///< the index into the buffer where the data starts
|
|
|
|
|
} cBuffer;
|
|
|
|
|
|
|
|
|
|
// function prototypes
|
|
|
|
|
|
|
|
|
|
//! initialize a buffer to start at a given address and have given size
|
2010-08-25 07:32:52 +02:00
|
|
|
|
void bufferInit(cBuffer* buffer, uint8_t *start, uint32_t size);
|
|
|
|
|
|
|
|
|
|
//! check free space in buffer
|
|
|
|
|
uint32_t bufferRemainingSpace(cBuffer* buffer);
|
2010-03-20 16:45:15 +01:00
|
|
|
|
|
|
|
|
|
//! get the first byte from the front of the buffer
|
2010-08-25 07:32:52 +02:00
|
|
|
|
uint8_t bufferGetFromFront(cBuffer* buffer);
|
|
|
|
|
|
|
|
|
|
//! get the number of bytes buffered
|
|
|
|
|
uint32_t bufferBufferedData(cBuffer* buffer);
|
|
|
|
|
|
|
|
|
|
//! copy number of elements into another buffer
|
|
|
|
|
uint8_t bufferGetChunkFromFront(cBuffer* buffer, uint8_t * dest, uint32_t size);
|
2010-03-20 16:45:15 +01:00
|
|
|
|
|
|
|
|
|
//! dump (discard) the first numbytes from the front of the buffer
|
2010-08-25 07:32:52 +02:00
|
|
|
|
void bufferDumpFromFront(cBuffer* buffer, uint32_t numbytes);
|
2010-03-20 16:45:15 +01:00
|
|
|
|
|
|
|
|
|
//! get a byte at the specified index in the buffer (kind of like array access)
|
|
|
|
|
// ** note: this does not remove the byte that was read from the buffer
|
2010-08-25 07:32:52 +02:00
|
|
|
|
uint8_t bufferGetAtIndex(cBuffer* buffer, uint32_t index);
|
2010-03-20 16:45:15 +01:00
|
|
|
|
|
|
|
|
|
//! add a byte to the end of the buffer
|
2010-08-25 07:32:52 +02:00
|
|
|
|
uint8_t bufferAddToEnd(cBuffer* buffer, uint8_t data);
|
|
|
|
|
|
|
|
|
|
//! queue a block of character to end of buffer
|
|
|
|
|
uint8_t bufferAddChunkToEnd(cBuffer* buffer, const uint8_t * data, uint32_t size);
|
2010-03-20 16:45:15 +01:00
|
|
|
|
|
|
|
|
|
//! check if the buffer is full/not full (returns non-zero value if not full)
|
2010-08-25 07:32:52 +02:00
|
|
|
|
uint8_t bufferIsNotFull(cBuffer* buffer);
|
2010-03-20 16:45:15 +01:00
|
|
|
|
|
|
|
|
|
//! flush (clear) the contents of the buffer
|
|
|
|
|
void bufferFlush(cBuffer* buffer);
|
|
|
|
|
|
|
|
|
|
#endif
|
2010-07-16 21:53:35 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @}
|
|
|
|
|
*/
|