Kévin Redon | 9a12d68 | 2018-07-08 13:21:16 +0200 | [diff] [blame] | 1 | /* Ring buffer |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
| 16 | */ |
Christina Quast | 4db82e0 | 2015-04-11 18:14:41 +0200 | [diff] [blame] | 17 | #ifndef SIMTRACE_RINGBUF_H |
| 18 | #define SIMTRACE_RINGBUF_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <stdbool.h> |
| 22 | #include <sys/types.h> |
| 23 | |
Harald Welte | c7173bc | 2020-01-17 16:32:22 +0100 | [diff] [blame] | 24 | #define RING_BUFLEN 1024 |
Christina Quast | 4db82e0 | 2015-04-11 18:14:41 +0200 | [diff] [blame] | 25 | |
| 26 | typedef struct ringbuf { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 27 | uint8_t buf[RING_BUFLEN]; |
| 28 | size_t ird; |
| 29 | size_t iwr; |
Christina Quast | 4db82e0 | 2015-04-11 18:14:41 +0200 | [diff] [blame] | 30 | } ringbuf; |
| 31 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 32 | void rbuf_reset(volatile ringbuf * rb); |
| 33 | uint8_t rbuf_read(volatile ringbuf * rb); |
| 34 | uint8_t rbuf_peek(volatile ringbuf * rb); |
Harald Welte | 05cc7f6 | 2018-07-04 04:39:40 +0200 | [diff] [blame] | 35 | int rbuf_write(volatile ringbuf * rb, uint8_t item); |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 36 | bool rbuf_is_empty(volatile ringbuf * rb); |
| 37 | bool rbuf_is_full(volatile ringbuf * rb); |
Christina Quast | 4db82e0 | 2015-04-11 18:14:41 +0200 | [diff] [blame] | 38 | |
| 39 | #endif /* end of include guard: SIMTRACE_RINGBUF_H */ |