Simple char ring buffer for microcontrollers. More...
Go to the source code of this file.
Functions | |
CharRingBuf * | CharRing_new (int16_t len) |
Allocates and returns a pointer to a new CharRingBuf buffer object. | |
void | CharRing_free (CharRingBuf *b) |
Destroys a character ring buffer. | |
void | CharRing_putchar (CharRingBuf *b, char c) |
Writes a character to buffer. | |
char | CharRing_getchar (CharRingBuf *b) |
Reads a character from buffer. |
Simple char ring buffer for microcontrollers.
CharRing is a simple character ring/circular buffer designed for microcontrollers.
Definition in file charring.c.
void CharRing_free | ( | CharRingBuf * | b | ) |
Destroys a character ring buffer.
Properly frees all memory that was allocated in the creation of CharRingBuf b.
b | CharRingBuf buffer to be destroyed |
Definition at line 43 of file charring.c.
char CharRing_getchar | ( | CharRingBuf * | b | ) |
Reads a character from buffer.
If there are no chars available in the buffer, this will always return '\0' (null char). But thats what CharRing_available() and CharRing_empty() are for:
if (CharRing_available(my_buf)) { // do stuff } if (!CharRing_empty(my_buf)) { // do stuff }
b | CharRingBuf buffer to read |
Definition at line 98 of file charring.c.
CharRingBuf* CharRing_new | ( | int16_t | len | ) |
Allocates and returns a pointer to a new CharRingBuf buffer object.
len | size of buffer to be created |
Definition at line 26 of file charring.c.
void CharRing_putchar | ( | CharRingBuf * | b, |
char | c | ||
) |
Writes a character to buffer.
If losing data is unacceptable then you need to check on the buffer before writing to it. CharRing_free_space() will give you the free space in the buffer and you can check to see if the buffer is full with CharRing_full():
while (CharRing_full(my_buf)); // wait for buffer to open up
b | CharRingBuf buffer to write |
c | character to write |
Definition at line 66 of file charring.c.