buffer.h File Reference

Fixed-length 'ring' buffer (circular queue). More...

#include <inttypes.h>

Go to the source code of this file.

Data Structures

struct  buffer
 The 'ring' buffer. More...

Defines

#define BUFFER_BITS   7
 Default buffer size is 2^7 = 128 bytes.
#define buffer_init(b)   b.head = b.tail = 0
 Initialize the buffer's indexes.

Functions

char buffer_put (struct buffer *b, char c)
 Insert a byte into a buffer.
char buffer_get (struct buffer *b)
 Take a byte out of a buffer.
uint8_t buffer_size (struct buffer *b)
 Get the buffer occupancy.


Detailed Description

Fixed-length 'ring' buffer (circular queue).

Author:
Andrey Yurovsky <yurovsky@gmail.com>
Note:
Define BUFFER_BITS in your compiler flags to set the buffer length. The length is computed as 2^BUFFER_BITS. BUFFER_BITS may be less than or equal to 8. The maximum occupancy for the buffer is length-1.

Define Documentation

#define BUFFER_BITS   7

Default buffer size is 2^7 = 128 bytes.

#define buffer_init (  )     b.head = b.tail = 0

Initialize the buffer's indexes.


Function Documentation

char buffer_get ( struct buffer b  ) 

Take a byte out of a buffer.

This function removes a byte from the buffer, adjusting the buffer indexes as needed.

Parameters:
[in] b The buffer from which to read.
[out] c Where to store the byte that was read.
Return values:
char 1 on success, 0 if the buffer was empty and nothing was read.

char buffer_put ( struct buffer b,
char  c 
)

Insert a byte into a buffer.

This function inserts a byte into the buffer, adjusting the buffer indexes as needed.

Parameters:
[in] b The buffer to insert into.
[in] c The byte to insert.
Return values:
char 1 on success, 0 if there was no room in the buffer.

uint8_t buffer_size ( struct buffer b  ) 

Get the buffer occupancy.

Parameters:
[in] b The buffer to check the occupancy of.
Return values:
uint8_t The number of bytes currently stored in the buffer.


Generated on Mon Mar 26 00:29:13 2007 for UARTDriver by  doxygen 1.5.1