source: rtems/cpukit/libcsupport/include/ringbuf.h @ 4d3017a

4.104.114.84.95
Last change on this file since 4d3017a was 4d3017a, checked in by Ralf Corsepius <ralf.corsepius@…>, on 12/02/04 at 18:04:55

Add doxygen preamble.

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