source: rtems/cpukit/libcsupport/include/ringbuf.h @ d2b4fcd

4.104.114.84.95
Last change on this file since d2b4fcd was 4d3017a, checked in by Ralf Corsepius <ralf.corsepius@…>, on Dec 2, 2004 at 6:04:55 PM

Add doxygen preamble.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/**
2 *  @file rtems/ringbuf.h
3 *
4 *  This file provides simple ring buffer functionality.
5 */
6
7/*
8 *  $Id$
9 */
10
11#ifndef __RINGBUF_H__
12#define __RINGBUF_H__
13
14#ifndef RINGBUF_QUEUE_LENGTH
15#define RINGBUF_QUEUE_LENGTH 128
16#endif
17
18typedef struct {
19  char buffer[RINGBUF_QUEUE_LENGTH];
20  volatile int  head;
21  volatile int  tail;
22} Ring_buffer_t;
23
24#define Ring_buffer_Initialize( _buffer ) \
25  do { \
26    (_buffer)->head = (_buffer)->tail = 0; \
27  } while ( 0 )
28
29#define Ring_buffer_Is_empty( _buffer ) \
30   ( (_buffer)->head == (_buffer)->tail )
31
32#define Ring_buffer_Is_full( _buffer ) \
33   ( (_buffer)->head == ((_buffer)->tail + 1) % RINGBUF_QUEUE_LENGTH )
34
35#define Ring_buffer_Add_character( _buffer, _ch ) \
36  do { \
37    uint32_t   isrlevel; \
38    \
39    rtems_interrupt_disable( isrlevel ); \
40      (_buffer)->tail = ((_buffer)->tail+1) % RINGBUF_QUEUE_LENGTH; \
41      (_buffer)->buffer[ (_buffer)->tail ] = (_ch); \
42    rtems_interrupt_enable( isrlevel ); \
43  } while ( 0 )
44
45#define Ring_buffer_Remove_character( _buffer, _ch ) \
46  do { \
47    uint32_t   isrlevel; \
48    \
49    rtems_interrupt_disable( isrlevel ); \
50      (_buffer)->head = ((_buffer)->head+1) % RINGBUF_QUEUE_LENGTH; \
51      (_ch) = (_buffer)->buffer[ (_buffer)->head ]; \
52    rtems_interrupt_enable( isrlevel ); \
53  } while ( 0 )
54
55#endif
Note: See TracBrowser for help on using the repository browser.