Zigbee Protocol Controller 1.6.0
ringbuf.h
Go to the documentation of this file.
1
14/*
15 * Copyright (c) 2008, Swedish Institute of Computer Science.
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
26 * 3. Neither the name of the Institute nor the names of its contributors
27 * may be used to endorse or promote products derived from this software
28 * without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * SUCH DAMAGE.
41 *
42 * This file is part of the Contiki operating system.
43 *
44 * $Id: ringbuf.h,v 1.1 2009/03/01 20:23:56 adamdunkels Exp $
45 */
46
54#ifndef __RINGBUF_H__
55#define __RINGBUF_H__
56
57#include "contiki-conf.h"
58
68struct ringbuf {
69 uint8_t *data;
70 uint8_t mask;
71
72 /* XXX these must be 8-bit quantities to avoid race conditions. */
73 uint8_t put_ptr, get_ptr;
74};
75
89void ringbuf_init(struct ringbuf *r, uint8_t *a,
90 uint8_t size_power_of_two);
91
103int ringbuf_put(struct ringbuf *r, uint8_t c);
104
105
116int ringbuf_get(struct ringbuf *r);
117
123int ringbuf_size(struct ringbuf *r);
124
130int ringbuf_elements(struct ringbuf *r);
131
132#endif /* __RINGBUF_H__ */
int ringbuf_size(struct ringbuf *r)
Get the size of a ring buffer.
Definition: ringbuf.c:97
int ringbuf_get(struct ringbuf *r)
Get a byte from the ring buffer.
Definition: ringbuf.c:73
int ringbuf_put(struct ringbuf *r, uint8_t c)
Insert a byte into the ring buffer.
Definition: ringbuf.c:53
void ringbuf_init(struct ringbuf *r, uint8_t *a, uint8_t size_power_of_two)
Initialize a ring buffer.
Definition: ringbuf.c:44
int ringbuf_elements(struct ringbuf *r)
Get the number of elements currently in the ring buffer.
Definition: ringbuf.c:103
Structure that holds the state of a ring buffer.
Definition: ringbuf.h:68
uint8_t mask
Definition: ringbuf.h:70
uint8_t put_ptr
Definition: ringbuf.h:73
uint8_t * data
Definition: ringbuf.h:69
uint8_t get_ptr
Definition: ringbuf.h:73