OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [include/] [ringbuf.h] - Blame information for rev 593

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 *  ringbuf.h
3
 *
4
 *  This file provides simple ring buffer functionality.
5
 *
6
 *  $Id: ringbuf.h,v 1.2 2001-09-27 11:59:35 chris Exp $
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
 
16
typedef 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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.