RTEMS: cpukit/include/rtems/ringbuf.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
ringbuf.h
Go to the documentation of this file.
1
10#ifndef _RTEMS_RINGBUF_H
11#define _RTEMS_RINGBUF_H
12
13#include <rtems.h>
14
15#ifndef RINGBUF_QUEUE_LENGTH
16#define RINGBUF_QUEUE_LENGTH 128
17#endif
18
19 typedef struct {
20 uint8_t buffer[RINGBUF_QUEUE_LENGTH];
21 volatile int head;
22 volatile int tail;
23 rtems_interrupt_lock lock;
24} Ring_buffer_t;
25
26#define Ring_buffer_Initialize( _buffer ) \
27 do { \
28 (_buffer)->head = (_buffer)->tail = 0; \
29 rtems_interrupt_lock_initialize(&(_buffer)->lock, "ring buffer"); \
30 } while ( 0 )
31
32#define Ring_buffer_Destory( _buffer ) \
33 do { \
34 rtems_interrupt_lock_destroy(&(_buffer)->lock); \
35 } while ( 0 )
36
37#define Ring_buffer_Is_empty( _buffer ) \
38 ( (_buffer)->head == (_buffer)->tail )
39
40#define Ring_buffer_Is_full( _buffer ) \
41 ( (_buffer)->head == ((_buffer)->tail + 1) % RINGBUF_QUEUE_LENGTH )
42
43#define Ring_buffer_Add_character( _buffer, _ch ) \
44 do { \
45 rtems_interrupt_lock_context lock_context; \
46 \
47 rtems_interrupt_lock_acquire( &(_buffer)->lock, &lock_context ); \
48 (_buffer)->tail = ((_buffer)->tail+1) % RINGBUF_QUEUE_LENGTH; \
49 (_buffer)->buffer[ (_buffer)->tail ] = (_ch); \
50 rtems_interrupt_lock_release( &(_buffer)->lock, &lock_context ); \
51 } while ( 0 )
52
53#define Ring_buffer_Remove_character( _buffer, _ch ) \
54 do { \
55 rtems_interrupt_lock_context lock_context; \
56 \
57 rtems_interrupt_lock_acquire( &(_buffer)->lock, &lock_context ); \
58 (_buffer)->head = ((_buffer)->head+1) % RINGBUF_QUEUE_LENGTH; \
59 (_ch) = (_buffer)->buffer[ (_buffer)->head ]; \
60 rtems_interrupt_lock_release( &(_buffer)->lock, &lock_context ); \
61 } while ( 0 )
62
63#endif
rtems.h
ISR_lock_Control
ISR lock control.
Definition: isrlock.h:56
Ring_buffer_t
Definition: ringbuf.h:19