Digi XBee(R) ANSI C Host Library
cbuf.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2012 Digi International Inc.,
3  * All rights not expressly granted are reserved.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
7  * You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
10  * =======================================================================
11  */
12 
22 #ifndef XBEE_CBUF_H
23 #define XBEE_CBUF_H
24 
25 #include "xbee/platform.h"
26 #include <stddef.h>
28 
31 typedef struct xbee_cbuf_t {
32  unsigned int head; // front, or head index of data
33  unsigned int tail; // back, or tail index of data
34  unsigned int mask; // 2^n - 1
35  uint8_t data[1]; // variable length (<mask> bytes + 1 separator byte)
36 } xbee_cbuf_t;
37 
65 #define XBEE_CBUF_OVERHEAD sizeof(xbee_cbuf_t)
66 
89 int xbee_cbuf_init( xbee_cbuf_t FAR *cbuf, unsigned int datasize);
90 
104 int xbee_cbuf_putch( xbee_cbuf_t FAR *cbuf, uint_fast8_t ch);
105 
106 
119 int xbee_cbuf_getch( xbee_cbuf_t FAR *cbuf);
120 
121 
133 #define xbee_cbuf_length(cbuf) ((cbuf)->mask)
134 
135 
147 unsigned int xbee_cbuf_used( xbee_cbuf_t FAR *cbuf);
148 
149 
162 unsigned int xbee_cbuf_free( xbee_cbuf_t FAR *cbuf);
163 
164 
172 void xbee_cbuf_flush( xbee_cbuf_t FAR *cbuf);
173 
174 
186 unsigned int xbee_cbuf_put( xbee_cbuf_t FAR *cbuf, const void FAR *buffer,
187  unsigned int length);
199 unsigned int xbee_cbuf_get( xbee_cbuf_t *cbuf, void FAR *buffer,
200  unsigned int length);
201 
203 
204 // If compiling in Dynamic C, automatically #use the appropriate C file.
205 #ifdef __DC__
206  #use "xbee_cbuf.c"
207 #endif
208 
209 #endif // XBEE_CBUF_H defined
210 
#define FAR
On platforms with "far" pointers, define to the proper keyword; empty definition if not required...
Definition: platform.h:396
unsigned int xbee_cbuf_put(xbee_cbuf_t FAR *cbuf, const void FAR *buffer, unsigned int length)
Append multiple bytes to the end of a circular buffer.
Definition: xbee_cbuf.c:102
#define XBEE_BEGIN_DECLS
Macro defined to.
Definition: platform.h:41
Common header for Hardware Abstraction Layer.
unsigned int xbee_cbuf_get(xbee_cbuf_t *cbuf, void FAR *buffer, unsigned int length)
Read (and remove) multiple bytes from circular buffer.
Definition: xbee_cbuf.c:136
void xbee_cbuf_flush(xbee_cbuf_t FAR *cbuf)
Flush the contents of the circular buffer.
Definition: xbee_cbuf.c:95
unsigned int xbee_cbuf_free(xbee_cbuf_t FAR *cbuf)
Returns the number of additional bytes that can be stored in the circular buffer. ...
Definition: xbee_cbuf.c:88
int xbee_cbuf_getch(xbee_cbuf_t FAR *cbuf)
Remove and return the first byte of the circular buffer.
Definition: xbee_cbuf.c:63
int xbee_cbuf_putch(xbee_cbuf_t FAR *cbuf, uint_fast8_t ch)
Append a single byte to the circular buffer (if not full).
Definition: xbee_cbuf.c:46
unsigned char uint8_t
8-bit unsigned integer
Definition: platform_config.h:39
int xbee_cbuf_init(xbee_cbuf_t FAR *cbuf, unsigned int datasize)
Initialize the fields of the circular buffer.
Definition: xbee_cbuf.c:32
#define XBEE_END_DECLS
Macro defined to.
Definition: platform.h:42
unsigned int xbee_cbuf_used(xbee_cbuf_t FAR *cbuf)
Returns the number of bytes stored in the circular buffer.
Definition: xbee_cbuf.c:81
Circular buffer used by transparent serial cluster handler.
Definition: cbuf.h:31