36#ifndef _RTEMS_RINGBUF_H
37#define _RTEMS_RINGBUF_H
41#ifndef RINGBUF_QUEUE_LENGTH
42#define RINGBUF_QUEUE_LENGTH 128
46 uint8_t buffer[RINGBUF_QUEUE_LENGTH];
52#define Ring_buffer_Initialize( _buffer ) \
54 (_buffer)->head = (_buffer)->tail = 0; \
55 rtems_interrupt_lock_initialize(&(_buffer)->lock, "ring buffer"); \
58#define Ring_buffer_Destory( _buffer ) \
60 rtems_interrupt_lock_destroy(&(_buffer)->lock); \
63#define Ring_buffer_Is_empty( _buffer ) \
64 ( (_buffer)->head == (_buffer)->tail )
66#define Ring_buffer_Is_full( _buffer ) \
67 ( (_buffer)->head == ((_buffer)->tail + 1) % RINGBUF_QUEUE_LENGTH )
69#define Ring_buffer_Add_character( _buffer, _ch ) \
71 rtems_interrupt_lock_context lock_context; \
73 rtems_interrupt_lock_acquire( &(_buffer)->lock, &lock_context ); \
74 (_buffer)->tail = ((_buffer)->tail+1) % RINGBUF_QUEUE_LENGTH; \
75 (_buffer)->buffer[ (_buffer)->tail ] = (_ch); \
76 rtems_interrupt_lock_release( &(_buffer)->lock, &lock_context ); \
79#define Ring_buffer_Remove_character( _buffer, _ch ) \
81 rtems_interrupt_lock_context lock_context; \
83 rtems_interrupt_lock_acquire( &(_buffer)->lock, &lock_context ); \
84 (_buffer)->head = ((_buffer)->head+1) % RINGBUF_QUEUE_LENGTH; \
85 (_ch) = (_buffer)->buffer[ (_buffer)->head ]; \
86 rtems_interrupt_lock_release( &(_buffer)->lock, &lock_context ); \
char rtems_interrupt_lock
This structure represents an ISR lock.
Definition: intr.h:532
This header file defines the RTEMS Classic API.