Skip to content

EmperorTransisthor/ringbuffer_C

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Ring buffer

Ring buffer is a mechanism, which is very useful in asynchronous systems. Basically, it is FIFO register, which is storing data until they are read.
There are 3 crucial things you need to know about it:

  • char* buffer is a pointer to the beggining of string, where data is strored
  • int head is a pointer to the place, where next variable will be stored
  • int tail is a pointer to the place, where first variable of the buffer, which has to be read

Equasions
As we now know, that char* buffer is pointer to the beggining of our ring buffer, head and tail variables are pointing to places in memory, where we want to write / read accordingly, the equasions for operations in ring buffer would look like:

  • Read: buffer + tail
  • Write: buffer + head

Example
Writing information to the buffer

RingBuffer_Write (RingBuffer* ringBuffer, char c)      // Simplified RingBuffer_PutChar function (idea behind it)
{
     *(ringBuffer->buffer + ringBuffer->head) = c;
     
     /*
     head operations
     */
}

Reading information from the buffer

RingBuffer_Read (RingBuffer* ringBuffer, char* c)       // Simplified RingBuffer_GetChar function (idea behind it)
{
     *c = *(ringBuffer->buffer + ringBuffer->tail);
     
     /*
     tail operations
     */
}

More about the concept: https://www.embedded.com/ring-buffer-basics/

This is homework for Microcontroller Applications subject. Feel free to use it.

About

This is homework for Microcontroller Applications subject. Feel free to use it.

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages