RTEMS: cpukit/libmisc/capture/capture_buffer.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
capture_buffer.h
Go to the documentation of this file.
1
9/*
10 ------------------------------------------------------------------------
11
12 COPYRIGHT (c) 2014.
13 On-Line Applications Research Corporation (OAR).
14
15 Copyright 2016 Chris Johns <chrisj@rtems.org>.
16 All rights reserved.
17
18 The license and distribution terms for this file may be
19 found in the file LICENSE in this distribution.
20
21 This software with is provided ``as is'' and with NO WARRANTY.
22
23 ------------------------------------------------------------------------
24*/
25
26#ifndef __CAPTURE_BUFFER_H_
27#define __CAPTURE_BUFFER_H_
28
29#include <stdlib.h>
30
32#ifdef __cplusplus
33extern "C" {
34#endif
35
39 typedef struct rtems_capture_buffer {
40 uint8_t* buffer;
41 size_t size;
42 size_t count;
43 size_t head;
44 size_t tail;
45 size_t end;
46 size_t max_rec;
47} rtems_capture_buffer;
48
49static inline void
50rtems_capture_buffer_flush (rtems_capture_buffer* buffer)
51{
52 buffer->end = buffer->size;
53 buffer->head = buffer->tail = 0;
54 buffer->count = 0;
55 buffer->max_rec = 0;
56}
57
58static inline void
59rtems_capture_buffer_create (rtems_capture_buffer* buffer, size_t size)
60{
61 buffer->buffer = malloc(size);
62 buffer->size = size;
63 rtems_capture_buffer_flush (buffer);
64}
65
66static inline void
67rtems_capture_buffer_destroy (rtems_capture_buffer* buffer)
68{
69 rtems_capture_buffer_flush (buffer);
70 free (buffer->buffer);
71 buffer->buffer = NULL;
72}
73
74static inline bool
75rtems_capture_buffer_is_empty (rtems_capture_buffer* buffer)
76{
77 return buffer->count == 0;
78}
79
80static inline bool
81rtems_capture_buffer_is_full (rtems_capture_buffer* buffer)
82{
83 return buffer->count == buffer->size;
84}
85
86static inline bool
87rtems_capture_buffer_has_wrapped (rtems_capture_buffer* buffer)
88{
89 if (buffer->tail > buffer->head)
90 return true;
91
92 return false;
93}
94
95static inline void*
96rtems_capture_buffer_peek (rtems_capture_buffer* buffer, size_t* size)
97{
98 if (rtems_capture_buffer_is_empty (buffer))
99 {
100 *size = 0;
101 return NULL;
102 }
103
104 if (buffer->tail > buffer->head)
105 *size = buffer->end - buffer->tail;
106 else
107 *size = buffer->head - buffer->tail;
108
109 return &buffer->buffer[buffer->tail];
110}
111
112void* rtems_capture_buffer_allocate (rtems_capture_buffer* buffer, size_t size);
113
114void* rtems_capture_buffer_free (rtems_capture_buffer* buffer, size_t size);
115
116#ifdef __cplusplus
117}
118#endif
119
120#endif
NULL
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77
rtems_capture_buffer
Definition: capture_buffer.h:39
rtems_capture_buffer::head
size_t head
Definition: capture_buffer.h:43
rtems_capture_buffer::max_rec
size_t max_rec
Definition: capture_buffer.h:46
rtems_capture_buffer::tail
size_t tail
Definition: capture_buffer.h:44
rtems_capture_buffer::count
size_t count
Definition: capture_buffer.h:42
rtems_capture_buffer::size
size_t size
Definition: capture_buffer.h:41
rtems_capture_buffer::buffer
uint8_t * buffer
Definition: capture_buffer.h:40
rtems_capture_buffer::end
size_t end
Definition: capture_buffer.h:45