Skip to content

Commit 0099b62

Browse files
committed
sys/tsrb: use turb.h for c-file implemetation
1 parent 40cca92 commit 0099b62

File tree

1 file changed

+11
-51
lines changed

1 file changed

+11
-51
lines changed

sys/tsrb/tsrb.c

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,100 +19,60 @@
1919

2020
#include "irq.h"
2121
#include "tsrb.h"
22-
23-
static void _push(tsrb_t *rb, uint8_t c)
24-
{
25-
rb->buf[rb->writes++ & (rb->size - 1)] = c;
26-
}
27-
28-
static uint8_t _pop(tsrb_t *rb)
29-
{
30-
return rb->buf[rb->reads++ & (rb->size - 1)];
31-
}
32-
33-
static uint8_t _peek(tsrb_t *rb, unsigned int idx)
34-
{
35-
return rb->buf[(rb->reads + idx) & (rb->size - 1)];
36-
}
22+
#include "turb.h"
3723

3824
int tsrb_get_one(tsrb_t *rb)
3925
{
40-
int retval = -1;
4126
unsigned irq_state = irq_disable();
42-
if (!tsrb_empty(rb)) {
43-
retval = _pop(rb);
44-
}
27+
int retval = turb_get_one(rb);
4528
irq_restore(irq_state);
4629
return retval;
4730
}
4831

4932
int tsrb_peek_one(tsrb_t *rb)
5033
{
51-
int retval = -1;
5234
unsigned irq_state = irq_disable();
53-
if (!tsrb_empty(rb)) {
54-
retval = _peek(rb, 0);
55-
}
35+
int retval = turb_peek_one(rb);
5636
irq_restore(irq_state);
5737
return retval;
5838
}
5939

6040
int tsrb_get(tsrb_t *rb, uint8_t *dst, size_t n)
6141
{
62-
size_t tmp = n;
6342
unsigned irq_state = irq_disable();
64-
while (tmp && !tsrb_empty(rb)) {
65-
*dst++ = _pop(rb);
66-
tmp--;
67-
}
43+
int cnt = turb_get(rb, dst, n);
6844
irq_restore(irq_state);
69-
return (n - tmp);
45+
return cnt;
7046
}
7147

7248
int tsrb_peek(tsrb_t *rb, uint8_t *dst, size_t n)
7349
{
74-
size_t idx = 0;
7550
unsigned irq_state = irq_disable();
76-
unsigned int avail = tsrb_avail(rb);
77-
while (idx < n && idx != avail) {
78-
*dst++ = _peek(rb, idx++);
79-
}
51+
int idx = turb_peek(rb, dst, n);
8052
irq_restore(irq_state);
8153
return idx;
8254
}
8355

8456
int tsrb_drop(tsrb_t *rb, size_t n)
8557
{
86-
size_t tmp = n;
8758
unsigned irq_state = irq_disable();
88-
while (tmp && !tsrb_empty(rb)) {
89-
_pop(rb);
90-
tmp--;
91-
}
59+
int cnt = turb_drop(rb, n);
9260
irq_restore(irq_state);
93-
return (n - tmp);
61+
return cnt;
9462
}
9563

9664
int tsrb_add_one(tsrb_t *rb, uint8_t c)
9765
{
98-
int retval = -1;
9966
unsigned irq_state = irq_disable();
100-
if (!tsrb_full(rb)) {
101-
_push(rb, c);
102-
retval = 0;
103-
}
67+
int retval = turb_add_one(rb, c);
10468
irq_restore(irq_state);
10569
return retval;
10670
}
10771

10872
int tsrb_add(tsrb_t *rb, const uint8_t *src, size_t n)
10973
{
110-
size_t tmp = n;
11174
unsigned irq_state = irq_disable();
112-
while (tmp && !tsrb_full(rb)) {
113-
_push(rb, *src++);
114-
tmp--;
115-
}
75+
int cnt = turb_add(rb, src, n);
11676
irq_restore(irq_state);
117-
return (n - tmp);
77+
return cnt;
11878
}

0 commit comments

Comments
 (0)