mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
Merge pull request #1099 from Kijewski/issue-1011
sys: rename ringbuffer functions
This commit is contained in:
commit
750b237f8d
@ -113,7 +113,7 @@ void chardev_loop(ringbuffer_t *rb)
|
|||||||
int state = disableIRQ();
|
int state = disableIRQ();
|
||||||
int nbytes = min(r->nbytes, rb->avail);
|
int nbytes = min(r->nbytes, rb->avail);
|
||||||
DEBUG("uart0_thread [%i]: sending %i bytes received from %i to pid %i\n", pid, nbytes, m.sender_pid, reader_pid);
|
DEBUG("uart0_thread [%i]: sending %i bytes received from %i to pid %i\n", pid, nbytes, m.sender_pid, reader_pid);
|
||||||
rb_get_elements(rb, r->buffer, nbytes);
|
ringbuffer_get(rb, r->buffer, nbytes);
|
||||||
r->nbytes = nbytes;
|
r->nbytes = nbytes;
|
||||||
|
|
||||||
m.sender_pid = reader_pid;
|
m.sender_pid = reader_pid;
|
||||||
|
@ -27,9 +27,9 @@ typedef struct ringbuffer {
|
|||||||
} ringbuffer_t;
|
} ringbuffer_t;
|
||||||
|
|
||||||
void ringbuffer_init(ringbuffer_t *rb, char *buffer, unsigned int bufsize);
|
void ringbuffer_init(ringbuffer_t *rb, char *buffer, unsigned int bufsize);
|
||||||
void rb_add_element(ringbuffer_t *rb, char c);
|
void ringbuffer_add_one(ringbuffer_t *rb, char c);
|
||||||
void rb_add_elements(ringbuffer_t *rb, char *buf, int n);
|
void ringbuffer_add(ringbuffer_t *rb, char *buf, int n);
|
||||||
int rb_get_element(ringbuffer_t *rb);
|
int ringbuffer_get_one(ringbuffer_t *rb);
|
||||||
int rb_get_elements(ringbuffer_t *rb, char *buf, int n);
|
int ringbuffer_get(ringbuffer_t *rb, char *buf, int n);
|
||||||
|
|
||||||
#endif /* __RINGBUFFER_H */
|
#endif /* __RINGBUFFER_H */
|
||||||
|
@ -39,17 +39,17 @@ void ringbuffer_init(ringbuffer_t *rb, char *buffer, unsigned int bufsize)
|
|||||||
rb->avail = 0;
|
rb->avail = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_add_elements(ringbuffer_t *rb, char *buf, int n)
|
void ringbuffer_add(ringbuffer_t *rb, char *buf, int n)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
rb_add_element(rb, buf[i]);
|
ringbuffer_add_one(rb, buf[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_add_element(ringbuffer_t *rb, char c)
|
void ringbuffer_add_one(ringbuffer_t *rb, char c)
|
||||||
{
|
{
|
||||||
if (rb->avail == rb->size) {
|
if (rb->avail == rb->size) {
|
||||||
rb_get_element(rb);
|
ringbuffer_get_one(rb);
|
||||||
}
|
}
|
||||||
|
|
||||||
rb->buf[rb->end++] = c;
|
rb->buf[rb->end++] = c;
|
||||||
@ -61,7 +61,7 @@ void rb_add_element(ringbuffer_t *rb, char c)
|
|||||||
rb->avail++;
|
rb->avail++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rb_get_element(ringbuffer_t *rb)
|
int ringbuffer_get_one(ringbuffer_t *rb)
|
||||||
{
|
{
|
||||||
if (rb->avail == 0) {
|
if (rb->avail == 0) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -78,12 +78,12 @@ int rb_get_element(ringbuffer_t *rb)
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rb_get_elements(ringbuffer_t *rb, char *buf, int n)
|
int ringbuffer_get(ringbuffer_t *rb, char *buf, int n)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
while (rb->avail && (count < n)) {
|
while (rb->avail && (count < n)) {
|
||||||
buf[count++] = rb_get_element(rb);
|
buf[count++] = ringbuffer_get_one(rb);
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
@ -95,51 +95,51 @@ int main(int argc, char *argv[] ){
|
|||||||
char buffer[5];
|
char buffer[5];
|
||||||
ringbuffer_init(&r, buffer, sizeof(buffer));
|
ringbuffer_init(&r, buffer, sizeof(buffer));
|
||||||
|
|
||||||
rb_add_element(&r, 1);
|
ringbuffer_add_one(&r, 1);
|
||||||
rb_add_element(&r, 2);
|
ringbuffer_add_one(&r, 2);
|
||||||
rb_add_element(&r, 3);
|
ringbuffer_add_one(&r, 3);
|
||||||
rb_add_element(&r, 4);
|
ringbuffer_add_one(&r, 4);
|
||||||
rb_add_element(&r, 5);
|
ringbuffer_add_one(&r, 5);
|
||||||
rb_add_element(&r, 6);
|
ringbuffer_add_one(&r, 6);
|
||||||
rb_add_element(&r, 7);
|
ringbuffer_add_one(&r, 7);
|
||||||
rb_add_element(&r, 8);
|
ringbuffer_add_one(&r, 8);
|
||||||
rb_add_element(&r, 9);
|
ringbuffer_add_one(&r, 9);
|
||||||
rb_add_element(&r, 10);
|
ringbuffer_add_one(&r, 10);
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
while ( r.avail ) {
|
while ( r.avail ) {
|
||||||
c = rb_get_element(&r);
|
c = ringbuffer_get_one(&r);
|
||||||
if (c == -1) break;
|
if (c == -1) break;
|
||||||
printf("c=%i\n", (int)c);
|
printf("c=%i\n", (int)c);
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_add_element(&r, 1);
|
ringbuffer_add_one(&r, 1);
|
||||||
rb_add_element(&r, 2);
|
ringbuffer_add_one(&r, 2);
|
||||||
rb_add_element(&r, 3);
|
ringbuffer_add_one(&r, 3);
|
||||||
rb_add_element(&r, 4);
|
ringbuffer_add_one(&r, 4);
|
||||||
rb_add_element(&r, 5);
|
ringbuffer_add_one(&r, 5);
|
||||||
|
|
||||||
char buffer2[10];
|
char buffer2[10];
|
||||||
|
|
||||||
int n = rb_get_elements(&r, buffer2, sizeof(buffer2));
|
int n = ringbuffer_get(&r, buffer2, sizeof(buffer2));
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
printf("%i\n", buffer2[i]);
|
printf("%i\n", buffer2[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_add_element(&r, 1);
|
ringbuffer_add_one(&r, 1);
|
||||||
rb_add_element(&r, 2);
|
ringbuffer_add_one(&r, 2);
|
||||||
rb_add_element(&r, 3);
|
ringbuffer_add_one(&r, 3);
|
||||||
rb_add_element(&r, 4);
|
ringbuffer_add_one(&r, 4);
|
||||||
rb_add_element(&r, 5);
|
ringbuffer_add_one(&r, 5);
|
||||||
rb_add_element(&r, 6);
|
ringbuffer_add_one(&r, 6);
|
||||||
rb_add_element(&r, 7);
|
ringbuffer_add_one(&r, 7);
|
||||||
rb_add_element(&r, 8);
|
ringbuffer_add_one(&r, 8);
|
||||||
rb_add_element(&r, 9);
|
ringbuffer_add_one(&r, 9);
|
||||||
rb_add_element(&r, 10);
|
ringbuffer_add_one(&r, 10);
|
||||||
|
|
||||||
while ( r.avail ) {
|
while ( r.avail ) {
|
||||||
c = rb_get_element(&r);
|
c = ringbuffer_get_one(&r);
|
||||||
if (c == -1) break;
|
if (c == -1) break;
|
||||||
printf("c=%i\n", (int)c);
|
printf("c=%i\n", (int)c);
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ void board_uart0_init(void)
|
|||||||
|
|
||||||
void uart0_handle_incoming(int c)
|
void uart0_handle_incoming(int c)
|
||||||
{
|
{
|
||||||
rb_add_element(&uart0_ringbuffer, c);
|
ringbuffer_add_one(&uart0_ringbuffer, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uart0_notify_thread(void)
|
void uart0_notify_thread(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user