Skip to content

Commit e158d48

Browse files
committed
[license] Fix the bad license replace.
1 parent 20bc91d commit e158d48

File tree

1 file changed

+8
-79
lines changed

1 file changed

+8
-79
lines changed

components/drivers/include/ipc/ringbuffer.h

Lines changed: 8 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,160 +1,89 @@
1+
/*
2+
* Copyright (c) 2006-2018, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
*/
19
#ifndef RINGBUFFER_H__
2-
#ifndef RINGBUFFER_H__
3-
#define RINGBUFFER_H__
410
#define RINGBUFFER_H__
511

6-
712
#ifdef __cplusplus
8-
#ifdef __cplusplus
9-
extern "C" {
1013
extern "C" {
1114
#endif
12-
#endif
1315

14-
15-
#include <rtthread.h>
1616
#include <rtthread.h>
1717

18-
19-
/* ring buffer */
2018
/* ring buffer */
2119
struct rt_ringbuffer
22-
struct rt_ringbuffer
2320
{
24-
{
25-
rt_uint8_t *buffer_ptr;
2621
rt_uint8_t *buffer_ptr;
2722
/* use the msb of the {read,write}_index as mirror bit. You can see this as
28-
/* use the msb of the {read,write}_index as mirror bit. You can see this as
29-
* if the buffer adds a virtual mirror and the pointers point either to the
3023
* if the buffer adds a virtual mirror and the pointers point either to the
3124
* normal or to the mirrored buffer. If the write_index has the same value
32-
* normal or to the mirrored buffer. If the write_index has the same value
3325
* with the read_index, but in a different mirror, the buffer is full.
34-
* with the read_index, but in a different mirror, the buffer is full.
35-
* While if the write_index and the read_index are the same and within the
3626
* While if the write_index and the read_index are the same and within the
3727
* same mirror, the buffer is empty. The ASCII art of the ringbuffer is:
38-
* same mirror, the buffer is empty. The ASCII art of the ringbuffer is:
39-
*
4028
*
4129
* mirror = 0 mirror = 1
42-
* mirror = 0 mirror = 1
4330
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
44-
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
45-
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 ||| 0 | 1 | 2 | 3 | 4 | 5 | 6 | Full
4631
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 ||| 0 | 1 | 2 | 3 | 4 | 5 | 6 | Full
4732
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
48-
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
49-
* read_idx-^ write_idx-^
5033
* read_idx-^ write_idx-^
5134
*
52-
*
5335
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
54-
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
55-
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 ||| 0 | 1 | 2 | 3 | 4 | 5 | 6 | Empty
5636
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 ||| 0 | 1 | 2 | 3 | 4 | 5 | 6 | Empty
5737
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
58-
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
59-
* read_idx-^ ^-write_idx
6038
* read_idx-^ ^-write_idx
6139
*
62-
*
6340
* The tradeoff is we could only use 32KiB of buffer for 16 bit of index.
64-
* The tradeoff is we could only use 32KiB of buffer for 16 bit of index.
65-
* But it should be enough for most of the cases.
6641
* But it should be enough for most of the cases.
6742
*
68-
*
69-
* Ref: http://en.wikipedia.org/wiki/Circular_buffer#Mirroring */
7043
* Ref: http://en.wikipedia.org/wiki/Circular_buffer#Mirroring */
7144
rt_uint16_t read_mirror : 1;
72-
rt_uint16_t read_mirror : 1;
7345
rt_uint16_t read_index : 15;
74-
rt_uint16_t read_index : 15;
75-
rt_uint16_t write_mirror : 1;
7646
rt_uint16_t write_mirror : 1;
7747
rt_uint16_t write_index : 15;
78-
rt_uint16_t write_index : 15;
79-
/* as we use msb of index as mirror bit, the size should be signed and
8048
/* as we use msb of index as mirror bit, the size should be signed and
8149
* could only be positive. */
82-
* could only be positive. */
8350
rt_int16_t buffer_size;
84-
rt_int16_t buffer_size;
85-
};
8651
};
8752

88-
8953
enum rt_ringbuffer_state
90-
enum rt_ringbuffer_state
91-
{
9254
{
93-
RT_RINGBUFFER_EMPTY,
9455
RT_RINGBUFFER_EMPTY,
9556
RT_RINGBUFFER_FULL,
96-
RT_RINGBUFFER_FULL,
97-
/* half full is neither full nor empty */
9857
/* half full is neither full nor empty */
9958
RT_RINGBUFFER_HALFFULL,
100-
RT_RINGBUFFER_HALFFULL,
101-
};
10259
};
10360

104-
10561
/**
106-
/**
107-
* RingBuffer for DeviceDriver
10862
* RingBuffer for DeviceDriver
10963
*
110-
*
111-
* Please note that the ring buffer implementation of RT-Thread
11264
* Please note that the ring buffer implementation of RT-Thread
11365
* has no thread wait or resume feature.
114-
* has no thread wait or resume feature.
11566
*/
116-
*/
117-
void rt_ringbuffer_init(struct rt_ringbuffer *rb, rt_uint8_t *pool, rt_int16_t size);
11867
void rt_ringbuffer_init(struct rt_ringbuffer *rb, rt_uint8_t *pool, rt_int16_t size);
11968
void rt_ringbuffer_reset(struct rt_ringbuffer *rb);
120-
void rt_ringbuffer_reset(struct rt_ringbuffer *rb);
121-
rt_size_t rt_ringbuffer_put(struct rt_ringbuffer *rb, const rt_uint8_t *ptr, rt_uint16_t length);
12269
rt_size_t rt_ringbuffer_put(struct rt_ringbuffer *rb, const rt_uint8_t *ptr, rt_uint16_t length);
12370
rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb, const rt_uint8_t *ptr, rt_uint16_t length);
124-
rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb, const rt_uint8_t *ptr, rt_uint16_t length);
12571
rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer *rb, const rt_uint8_t ch);
126-
rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer *rb, const rt_uint8_t ch);
127-
rt_size_t rt_ringbuffer_putchar_force(struct rt_ringbuffer *rb, const rt_uint8_t ch);
12872
rt_size_t rt_ringbuffer_putchar_force(struct rt_ringbuffer *rb, const rt_uint8_t ch);
12973
rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb, rt_uint8_t *ptr, rt_uint16_t length);
130-
rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb, rt_uint8_t *ptr, rt_uint16_t length);
131-
rt_size_t rt_ringbuffer_getchar(struct rt_ringbuffer *rb, rt_uint8_t *ch);
13274
rt_size_t rt_ringbuffer_getchar(struct rt_ringbuffer *rb, rt_uint8_t *ch);
13375
rt_size_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb);
134-
rt_size_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb);
13576

136-
137-
#ifdef RT_USING_HEAP
13877
#ifdef RT_USING_HEAP
13978
struct rt_ringbuffer* rt_ringbuffer_create(rt_uint16_t length);
140-
struct rt_ringbuffer* rt_ringbuffer_create(rt_uint16_t length);
141-
void rt_ringbuffer_destroy(struct rt_ringbuffer *rb);
14279
void rt_ringbuffer_destroy(struct rt_ringbuffer *rb);
14380
#endif
144-
#endif
14581

146-
147-
rt_inline rt_uint16_t rt_ringbuffer_get_size(struct rt_ringbuffer *rb)
14882
rt_inline rt_uint16_t rt_ringbuffer_get_size(struct rt_ringbuffer *rb)
14983
{
150-
{
151-
RT_ASSERT(rb != RT_NULL);
15284
RT_ASSERT(rb != RT_NULL);
15385
return rb->buffer_size;
154-
return rb->buffer_size;
15586
}
156-
}
157-
15887

15988
/** return the size of empty space in rb */
16089
#define rt_ringbuffer_space_len(rb) ((rb)->buffer_size - rt_ringbuffer_data_len(rb))

0 commit comments

Comments
 (0)