aversive_10-03-12/modules/base/cirbuf/cirbuf.h File Reference

#include <aversive.h>
#include <stdio.h>

Go to the source code of this file.

Data Structures

struct  cirbuf

Defines

#define dprintf(args...)   do {} while(0)
#define CIRBUF_IS_FULL(cirbuf)   ((cirbuf)->maxlen == (cirbuf)->len)
#define CIRBUF_IS_EMPTY(cirbuf)   ((cirbuf)->len == 0)
#define CIRBUF_GET_LEN(cirbuf)   ((cirbuf)->len)
#define CIRBUF_GET_MAXLEN(cirbuf)   ((cirbuf)->maxlen)
#define CIRBUF_GET_FREELEN(cirbuf)   ((cirbuf)->maxlen - (cirbuf)->len)
#define CIRBUF_FOREACH(c, i, e)

Typedefs

typedef signed char cirbuf_int
typedef unsigned char cirbuf_uint

Functions

void cirbuf_init (struct cirbuf *cbuf, char *buf, cirbuf_uint start, cirbuf_uint maxlen)
cirbuf_int cirbuf_add_head_safe (struct cirbuf *cbuf, char c)
void cirbuf_add_head (struct cirbuf *cbuf, char c)
cirbuf_int cirbuf_add_tail_safe (struct cirbuf *cbuf, char c)
void cirbuf_add_tail (struct cirbuf *cbuf, char c)
cirbuf_int cirbuf_del_head_safe (struct cirbuf *cbuf)
void cirbuf_del_head (struct cirbuf *cbuf)
cirbuf_int cirbuf_del_tail_safe (struct cirbuf *cbuf)
void cirbuf_del_tail (struct cirbuf *cbuf)
char cirbuf_get_head (struct cirbuf *cbuf)
char cirbuf_get_tail (struct cirbuf *cbuf)
cirbuf_int cirbuf_add_buf_head (struct cirbuf *cbuf, const char *c, cirbuf_uint n)
cirbuf_int cirbuf_add_buf_tail (struct cirbuf *cbuf, const char *c, cirbuf_uint n)
cirbuf_int cirbuf_del_buf_head (struct cirbuf *cbuf, cirbuf_uint size)
cirbuf_int cirbuf_del_buf_tail (struct cirbuf *cbuf, cirbuf_uint size)
cirbuf_int cirbuf_get_buf_head (struct cirbuf *cbuf, char *c, cirbuf_uint size)
cirbuf_int cirbuf_get_buf_tail (struct cirbuf *cbuf, char *c, cirbuf_uint size)
void cirbuf_align_left (struct cirbuf *cbuf)
void cirbuf_align_right (struct cirbuf *cbuf)


Define Documentation

#define CIRBUF_FOREACH ( c,
i,
 ) 

Value:

for ( i=0, e=(c)->buf[(c)->start] ;                     \
              i<((c)->len) ;                                    \
              i ++,  e=(c)->buf[((c)->start+i)%((c)->maxlen)])
Iterator for a circular buffer c: struct cirbuf pointer i: an integer type (cirbuf_uint is enough) internally used in the macro e: char that takes the value for each iteration

Definition at line 104 of file cirbuf.h.

Referenced by rdline_redisplay().

#define CIRBUF_GET_FREELEN ( cirbuf   )     ((cirbuf)->maxlen - (cirbuf)->len)

return the number of free elts

Definition at line 96 of file cirbuf.h.

Referenced by cirbuf_add_buf_head(), cirbuf_add_buf_tail(), and uart_send_9bits_nowait().

#define CIRBUF_GET_LEN ( cirbuf   )     ((cirbuf)->len)

return current size of the circular buffer (number of used elements)

Definition at line 86 of file cirbuf.h.

Referenced by cirbuf_del_buf_head(), cirbuf_del_buf_tail(), cirbuf_get_buf_head(), cirbuf_get_buf_tail(), rdline_char_in(), rdline_get_buffer(), uart_9bits_recv_nowait(), and uart_send_next_char().

#define CIRBUF_GET_MAXLEN ( cirbuf   )     ((cirbuf)->maxlen)

return size of the circular buffer (used + free elements)

Definition at line 91 of file cirbuf.h.

#define CIRBUF_IS_EMPTY ( cirbuf   )     ((cirbuf)->len == 0)

#define CIRBUF_IS_FULL ( cirbuf   )     ((cirbuf)->maxlen == (cirbuf)->len)

Return 1 if the circular buffer is full

Definition at line 76 of file cirbuf.h.

Referenced by cirbuf_add_head_safe(), cirbuf_add_tail_safe(), and uart_send_nowait().

#define dprintf ( args...   )     do {} while(0)


Typedef Documentation

typedef signed char cirbuf_int

Circular buffer implementation. You should not use a circular buffer size > 127.

Funcs are not atomic, so if * necessary, each call should be protected by IRQ_LOCKs.

Definition at line 43 of file cirbuf.h.

typedef unsigned char cirbuf_uint

Definition at line 44 of file cirbuf.h.


Function Documentation

cirbuf_int cirbuf_add_buf_head ( struct cirbuf cbuf,
const char *  c,
cirbuf_uint  n 
)

Add a buffer at head of the circular buffer. 'c' is a pointer to a buffer, and n is the number of char to add. Return the number of copied bytes on success, or a negative value on error.

Definition at line 31 of file cirbuf_add_buf_head.c.

References cirbuf::buf, CIRBUF_GET_FREELEN, CIRBUF_IS_EMPTY, dprintf, EINVAL, cirbuf::len, cirbuf::maxlen, and cirbuf::start.

Referenced by uart_send_9bits(), and uart_send_9bits_nowait().

cirbuf_int cirbuf_add_buf_tail ( struct cirbuf cbuf,
const char *  c,
cirbuf_uint  n 
)

Add a buffer at tail of the circular buffer. 'c' is a pointer to a buffer, and n is the number of char to add. Return the number of copied bytes on success, or a negative value on error.

Definition at line 31 of file cirbuf_add_buf_tail.c.

References cirbuf::buf, CIRBUF_GET_FREELEN, CIRBUF_IS_EMPTY, dprintf, EINVAL, cirbuf::end, cirbuf::len, and cirbuf::maxlen.

Referenced by rdline_char_in().

void cirbuf_add_head ( struct cirbuf cbuf,
char  c 
)

Add a character at head of the circular buffer. You _must_ check that you have enough free space in the buffer before calling this func.

Definition at line 52 of file cirbuf_add_head.c.

Referenced by rdline_char_in(), uart_send(), and uart_send_nowait().

cirbuf_int cirbuf_add_head_safe ( struct cirbuf cbuf,
char  c 
)

Add a character at head of the circular buffer. Return 0 on success, or a negative value on error.

Definition at line 42 of file cirbuf_add_head.c.

References CIRBUF_IS_FULL, and EINVAL.

void cirbuf_add_tail ( struct cirbuf cbuf,
char  c 
)

Add a character at tail of the circular buffer. You _must_ check that you have enough free space in the buffer before calling this func.

Definition at line 53 of file cirbuf_add_tail.c.

Referenced by rdline_char_in().

cirbuf_int cirbuf_add_tail_safe ( struct cirbuf cbuf,
char  c 
)

Add a character at tail of the circular buffer. Return 0 on success, or a negative value on error.

Definition at line 43 of file cirbuf_add_tail.c.

References CIRBUF_IS_FULL, and EINVAL.

Referenced by rdline_char_in().

void cirbuf_align_left ( struct cirbuf cbuf  ) 

Set the start of the data to the index 0 of the internal buffer.

Definition at line 62 of file cirbuf_align.c.

References cirbuf::maxlen, and cirbuf::start.

Referenced by rdline_char_in(), and rdline_get_buffer().

void cirbuf_align_right ( struct cirbuf cbuf  ) 

Set the end of the data to the last index of the internal buffer.

Definition at line 77 of file cirbuf_align.c.

References cirbuf::end, cirbuf::maxlen, and cirbuf::start.

cirbuf_int cirbuf_del_buf_head ( struct cirbuf cbuf,
cirbuf_uint  size 
)

Remove chars at the head of the circular buffer. Return 0 on success, or a negative value on error.

Definition at line 30 of file cirbuf_del_buf_head.c.

References CIRBUF_GET_LEN, CIRBUF_IS_EMPTY, EINVAL, cirbuf::len, cirbuf::maxlen, and cirbuf::start.

Referenced by rdline_char_in().

cirbuf_int cirbuf_del_buf_tail ( struct cirbuf cbuf,
cirbuf_uint  size 
)

Remove chars at the tail of the circular buffer. Return 0 on success, or a negative value on error.

Definition at line 30 of file cirbuf_del_buf_tail.c.

References CIRBUF_GET_LEN, CIRBUF_IS_EMPTY, EINVAL, cirbuf::end, cirbuf::len, and cirbuf::maxlen.

Referenced by uart_9bits_recv_nowait(), and uart_send_next_char().

void cirbuf_del_head ( struct cirbuf cbuf  ) 

Remove a char at the head of the circular buffer. You _must_ check that buffer is not empty before calling the function.

Definition at line 50 of file cirbuf_del_head.c.

Referenced by rdline_char_in().

cirbuf_int cirbuf_del_head_safe ( struct cirbuf cbuf  ) 

Remove a char at the head of the circular buffer. Return 0 on success, or a negative value on error.

Definition at line 40 of file cirbuf_del_head.c.

References CIRBUF_IS_EMPTY, and EINVAL.

Referenced by rdline_char_in().

void cirbuf_del_tail ( struct cirbuf cbuf  ) 

Remove a char at the tail of the circular buffer. You _must_ check that buffer is not empty before calling the function.

Definition at line 51 of file cirbuf_del_tail.c.

Referenced by rdline_char_in(), uart_recv_nowait(), and uart_send_next_char().

cirbuf_int cirbuf_del_tail_safe ( struct cirbuf cbuf  ) 

Remove a char at the tail of the circular buffer. Return 0 on success, or a negative value on error.

Definition at line 41 of file cirbuf_del_tail.c.

References CIRBUF_IS_EMPTY, and EINVAL.

Referenced by rdline_char_in().

cirbuf_int cirbuf_get_buf_head ( struct cirbuf cbuf,
char *  c,
cirbuf_uint  size 
)

Copy a maximum of 'size' characters from the head of the circular buffer to a flat one pointed by 'c'. Return the number of copied chars.

Definition at line 30 of file cirbuf_get_buf_head.c.

References cirbuf::buf, CIRBUF_GET_LEN, dprintf, cirbuf::end, cirbuf::maxlen, and cirbuf::start.

Referenced by rdline_char_in().

cirbuf_int cirbuf_get_buf_tail ( struct cirbuf cbuf,
char *  c,
cirbuf_uint  size 
)

Copy a maximum of 'size' characters from the tail of the circular buffer to a flat one pointed by 'c'. Return the number of copied chars.

Definition at line 31 of file cirbuf_get_buf_tail.c.

References cirbuf::buf, CIRBUF_GET_LEN, dprintf, cirbuf::end, cirbuf::maxlen, and cirbuf::start.

Referenced by uart_9bits_recv_nowait(), and uart_send_next_char().

char cirbuf_get_head ( struct cirbuf cbuf  ) 

Return the head of the circular buffer. You _must_ check that buffer is not empty before calling the function.

Definition at line 30 of file cirbuf_get_head.c.

References cirbuf::buf, and cirbuf::start.

Referenced by rdline_char_in().

char cirbuf_get_tail ( struct cirbuf cbuf  ) 

Return the tail of the circular buffer. You _must_ check that buffer is not empty before calling the function.

Definition at line 30 of file cirbuf_get_tail.c.

References cirbuf::buf, and cirbuf::end.

Referenced by rdline_char_in(), uart_recv_nowait(), and uart_send_next_char().

void cirbuf_init ( struct cirbuf cbuf,
char *  buf,
cirbuf_uint  start,
cirbuf_uint  maxlen 
)

Init the circular buffer

Definition at line 29 of file cirbuf.c.

References cirbuf::buf, cirbuf::end, cirbuf::len, cirbuf::maxlen, and cirbuf::start.

Referenced by rdline_char_in(), rdline_init(), rdline_newline(), and uart_setconf().


Generated on Fri Mar 12 06:32:05 2010 for AVR by  doxygen 1.5.6