From f23dab96d2651c2a4cbd903e5cceaa0b0ce263e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= Date: Sat, 3 May 2014 16:39:39 +0200 Subject: [PATCH] sys: rename ringbuffer functions Closes #1011. --- sys/chardev_thread.c | 2 +- sys/include/ringbuffer.h | 8 ++--- sys/lib/ringbuffer.c | 70 ++++++++++++++++++++-------------------- sys/uart0/uart0.c | 2 +- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/sys/chardev_thread.c b/sys/chardev_thread.c index 343ebba544..d85639c6b4 100644 --- a/sys/chardev_thread.c +++ b/sys/chardev_thread.c @@ -113,7 +113,7 @@ void chardev_loop(ringbuffer_t *rb) int state = disableIRQ(); 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); - rb_get_elements(rb, r->buffer, nbytes); + ringbuffer_get(rb, r->buffer, nbytes); r->nbytes = nbytes; m.sender_pid = reader_pid; diff --git a/sys/include/ringbuffer.h b/sys/include/ringbuffer.h index 17c120946d..97bccb5544 100644 --- a/sys/include/ringbuffer.h +++ b/sys/include/ringbuffer.h @@ -27,9 +27,9 @@ typedef struct ringbuffer { } ringbuffer_t; void ringbuffer_init(ringbuffer_t *rb, char *buffer, unsigned int bufsize); -void rb_add_element(ringbuffer_t *rb, char c); -void rb_add_elements(ringbuffer_t *rb, char *buf, int n); -int rb_get_element(ringbuffer_t *rb); -int rb_get_elements(ringbuffer_t *rb, char *buf, int n); +void ringbuffer_add_one(ringbuffer_t *rb, char c); +void ringbuffer_add(ringbuffer_t *rb, char *buf, int n); +int ringbuffer_get_one(ringbuffer_t *rb); +int ringbuffer_get(ringbuffer_t *rb, char *buf, int n); #endif /* __RINGBUFFER_H */ diff --git a/sys/lib/ringbuffer.c b/sys/lib/ringbuffer.c index b43ec37f77..ea60f6b2a8 100644 --- a/sys/lib/ringbuffer.c +++ b/sys/lib/ringbuffer.c @@ -39,17 +39,17 @@ void ringbuffer_init(ringbuffer_t *rb, char *buffer, unsigned int bufsize) 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++) { - 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) { - rb_get_element(rb); + ringbuffer_get_one(rb); } rb->buf[rb->end++] = c; @@ -61,7 +61,7 @@ void rb_add_element(ringbuffer_t *rb, char c) rb->avail++; } -int rb_get_element(ringbuffer_t *rb) +int ringbuffer_get_one(ringbuffer_t *rb) { if (rb->avail == 0) { return -1; @@ -78,12 +78,12 @@ int rb_get_element(ringbuffer_t *rb) 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; while (rb->avail && (count < n)) { - buf[count++] = rb_get_element(rb); + buf[count++] = ringbuffer_get_one(rb); } return count; @@ -95,51 +95,51 @@ int main(int argc, char *argv[] ){ char buffer[5]; ringbuffer_init(&r, buffer, sizeof(buffer)); - rb_add_element(&r, 1); - rb_add_element(&r, 2); - rb_add_element(&r, 3); - rb_add_element(&r, 4); - rb_add_element(&r, 5); - rb_add_element(&r, 6); - rb_add_element(&r, 7); - rb_add_element(&r, 8); - rb_add_element(&r, 9); - rb_add_element(&r, 10); + ringbuffer_add_one(&r, 1); + ringbuffer_add_one(&r, 2); + ringbuffer_add_one(&r, 3); + ringbuffer_add_one(&r, 4); + ringbuffer_add_one(&r, 5); + ringbuffer_add_one(&r, 6); + ringbuffer_add_one(&r, 7); + ringbuffer_add_one(&r, 8); + ringbuffer_add_one(&r, 9); + ringbuffer_add_one(&r, 10); int c; while ( r.avail ) { - c = rb_get_element(&r); + c = ringbuffer_get_one(&r); if (c == -1) break; printf("c=%i\n", (int)c); } - rb_add_element(&r, 1); - rb_add_element(&r, 2); - rb_add_element(&r, 3); - rb_add_element(&r, 4); - rb_add_element(&r, 5); + ringbuffer_add_one(&r, 1); + ringbuffer_add_one(&r, 2); + ringbuffer_add_one(&r, 3); + ringbuffer_add_one(&r, 4); + ringbuffer_add_one(&r, 5); 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++) { printf("%i\n", buffer2[i]); } - rb_add_element(&r, 1); - rb_add_element(&r, 2); - rb_add_element(&r, 3); - rb_add_element(&r, 4); - rb_add_element(&r, 5); - rb_add_element(&r, 6); - rb_add_element(&r, 7); - rb_add_element(&r, 8); - rb_add_element(&r, 9); - rb_add_element(&r, 10); + ringbuffer_add_one(&r, 1); + ringbuffer_add_one(&r, 2); + ringbuffer_add_one(&r, 3); + ringbuffer_add_one(&r, 4); + ringbuffer_add_one(&r, 5); + ringbuffer_add_one(&r, 6); + ringbuffer_add_one(&r, 7); + ringbuffer_add_one(&r, 8); + ringbuffer_add_one(&r, 9); + ringbuffer_add_one(&r, 10); while ( r.avail ) { - c = rb_get_element(&r); + c = ringbuffer_get_one(&r); if (c == -1) break; printf("c=%i\n", (int)c); } diff --git a/sys/uart0/uart0.c b/sys/uart0/uart0.c index fae86a2ed5..23d8e573ff 100644 --- a/sys/uart0/uart0.c +++ b/sys/uart0/uart0.c @@ -68,7 +68,7 @@ void board_uart0_init(void) void uart0_handle_incoming(int c) { - rb_add_element(&uart0_ringbuffer, c); + ringbuffer_add_one(&uart0_ringbuffer, c); } void uart0_notify_thread(void)