RTEMS 6.1-rc6
Loading...
Searching...
No Matches
ringbuf.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
11/*
12 * COPYRIGHT (C) 1989-1999 On-Line Applications Research Corporation (OAR).
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef _RTEMS_RINGBUF_H
37#define _RTEMS_RINGBUF_H
38
39#include <rtems.h>
40
41#ifndef RINGBUF_QUEUE_LENGTH
42#define RINGBUF_QUEUE_LENGTH 128
43#endif
44
45typedef struct {
46 uint8_t buffer[RINGBUF_QUEUE_LENGTH];
47 volatile int head;
48 volatile int tail;
51
52#define Ring_buffer_Initialize( _buffer ) \
53 do { \
54 (_buffer)->head = (_buffer)->tail = 0; \
55 rtems_interrupt_lock_initialize(&(_buffer)->lock, "ring buffer"); \
56 } while ( 0 )
57
58#define Ring_buffer_Destory( _buffer ) \
59 do { \
60 rtems_interrupt_lock_destroy(&(_buffer)->lock); \
61 } while ( 0 )
62
63#define Ring_buffer_Is_empty( _buffer ) \
64 ( (_buffer)->head == (_buffer)->tail )
65
66#define Ring_buffer_Is_full( _buffer ) \
67 ( (_buffer)->head == ((_buffer)->tail + 1) % RINGBUF_QUEUE_LENGTH )
68
69#define Ring_buffer_Add_character( _buffer, _ch ) \
70 do { \
71 rtems_interrupt_lock_context lock_context; \
72 \
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 ); \
77 } while ( 0 )
78
79#define Ring_buffer_Remove_character( _buffer, _ch ) \
80 do { \
81 rtems_interrupt_lock_context lock_context; \
82 \
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 ); \
87 } while ( 0 )
88
89#endif
char rtems_interrupt_lock
This structure represents an ISR lock.
Definition: intr.h:532
This header file defines the RTEMS Classic API.
Definition: ringbuf.h:45