source: rtems/c/src/lib/include/ringbuf.h @ df25c998

4.104.114.84.95
Last change on this file since df25c998 was 9700578, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 30, 1995 at 9:54:45 PM

SPARC port passes all tests

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