ring_buffer.h File Reference

Ring Buffer. More...

Go to the source code of this file.

Defines

#define RING_BUFFER_NEW(struct_name, size, type,...)
 Creates the struct for a new ring buffer. This just expands to a structure definition and thus should be invoked in the global context.
#define RING_BUFFER_INIT(buf, size)
 Initializes the ring buffer, setting its size to the correct value.
#define RING_BUFFER_CLEAR(buf)
 Sets the specified ring buffer to be empty.
#define RING_BUFFER_EMPTY(buf)   ((buf).start == (buf).end)
 Returns true if the ring buffer specified is empty.
#define RING_BUFFER_FULL(buf)   (((buf).end + 1) % (buf).buffer_size == (buf).start)
 Returns true if the ring buffer specified is full.
#define RING_BUFFER_ADD(buf, val)
 Adds val to ring buffer buf. Note that val must be of the type used in creating the ring buffer to prevent the compiler from spewing confusing errors. Also, this assumes that the ring buffer is not full.
#define RING_BUFFER_REMOVE(buf, val_ret)
 Removes the value at the head of the ring buffer and puts it in val_ret. Note that val_ret must be the same type used in creating the ring buffer to prevent the compiler from spewing confusing errors. Also, this assumes that the ring buffer is not empty.
#define RING_BUFFER_PEEK(buf, val_ret)
 Checks the value at the head of the ring buffer without removing it and puts it into val_ret. Note that val_ret must be the same type used in creating the ring buffer to prevent the compiler from spewing confusing errors. Also, this assumes that the ring buffer is not empty.


Detailed Description

Ring Buffer.

Copyright (c) 2007 Colony Project

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Include macros to create a ring buffer. Originally written for 15-410. Modified for use in ATMega128 serial driver

Author:
Cornell Wright (cgwright)

Jason P. Winters (jpwinter)


Define Documentation

#define RING_BUFFER_ADD ( buf,
val   ) 

Value:

do {                                                            \
                (buf).queue[(buf).end] = val;   \
                (buf).end = ((buf).end + 1) % (buf).buffer_size;        \
        } while (0)
Adds val to ring buffer buf. Note that val must be of the type used in creating the ring buffer to prevent the compiler from spewing confusing errors. Also, this assumes that the ring buffer is not full.

Parameters:
buf The ring buffer to add to.
val The value to add.

#define RING_BUFFER_CLEAR ( buf   ) 

Value:

do {                                            \
                (buf).start = 0;                \
                (buf).end = 0;                  \
        } while (0)
Sets the specified ring buffer to be empty.

Parameters:
buf The ring buffer to make empty.

#define RING_BUFFER_EMPTY ( buf   )     ((buf).start == (buf).end)

Returns true if the ring buffer specified is empty.

Parameters:
buf The buffer to check emptiness of.

#define RING_BUFFER_FULL ( buf   )     (((buf).end + 1) % (buf).buffer_size == (buf).start)

Returns true if the ring buffer specified is full.

Parameters:
buf The buffer to check fullness of.

#define RING_BUFFER_INIT ( buf,
size   ) 

Value:

do {                                                                            \
                (buf).buffer_size = size;                               \
        } while(0)
Initializes the ring buffer, setting its size to the correct value.

Parameters:
buf The ring buffer to initialize.
size The size of the ring buffer (in array elements)

#define RING_BUFFER_NEW ( struct_name,
size,
type,
...   ) 

Value:

struct struct_name {    \
                type queue[size];       \
                uint8_t start;                  \
                uint8_t end;                    \
                uint8_t buffer_size;                    \
        } __VA_ARGS__
Creates the struct for a new ring buffer. This just expands to a structure definition and thus should be invoked in the global context.

Parameters:
struct_name Name of the ring buffer struct.
size The size of the buffer to create.
type The type of object that the queue is to hold.
... Name or names of the instance or instances of the ring buffer(s) to be created.

#define RING_BUFFER_PEEK ( buf,
val_ret   ) 

Value:

do { \
    (val_ret) = (buf).queue[(buf).start]; \
  } while(0)
Checks the value at the head of the ring buffer without removing it and puts it into val_ret. Note that val_ret must be the same type used in creating the ring buffer to prevent the compiler from spewing confusing errors. Also, this assumes that the ring buffer is not empty.

Parameters:
buf The ring buffer to check from
val_ret where to put the value checked from the head of the ring

#define RING_BUFFER_REMOVE ( buf,
val_ret   ) 

Value:

do {    \
                (val_ret) = (buf).queue[(buf).start];   \
                (buf).start = ((buf).start + 1) % (buf).buffer_size;    \
        } while (0)
Removes the value at the head of the ring buffer and puts it in val_ret. Note that val_ret must be the same type used in creating the ring buffer to prevent the compiler from spewing confusing errors. Also, this assumes that the ring buffer is not empty.

Parameters:
buf The ring buffer to remove from.
val_ret Where to put the value removed from the head of the ring buffer.


Generated on Wed Feb 6 20:27:38 2008 for libdragonfly by  doxygen 1.5.3