feat(ring_buffer): add ring_buffer struct

This commit is contained in:
aliamelo committed 2021-07-16 18:07:57 +02:00
1 parent b33bf5aef6
commit f7246ffcdb
3 files changed
+38 -1

No files matched your search

+2 -1
View File
@@ -35,7 +35,8 @@ OBJS = \
idt.o \
isr.o \
pic.o \
pic/keyboard.o
pic/keyboard.o \
utils/ring_buffer.o
DEPS = $(OBJS:.o=.d)
+18
View File
@@ -0,0 +1,18 @@
#include "ring_buffer.h"
uint8_t read_entry(struct ring_buffer *buf)
{
if (buf->read >= buf->write)
return 0;
uint8_t data = buf->buffer[buf->read];
buf->read = (buf->read + 1) % RING_BUFFER_SIZE;
return data;
}
void write_entry(struct ring_buffer *buf, uint8_t entry)
{
buf->buffer[buf->write] = entry;
buf->write = (buf->write + 1) % RING_BUFFER_SIZE;
}
+18
View File
@@ -0,0 +1,18 @@
#ifndef RING_BUFFER_H
#define RING_BUFFER_H
#define RING_BUFFER_SIZE 32
#include <stdint.h>
struct ring_buffer
{
uint8_t buffer[RING_BUFFER_SIZE];
uint8_t read;
uint8_t write;
};
uint8_t read_entry(struct ring_buffer *buf);
void write_entry(struct ring_buffer *buf, uint8_t entry);
#endif /* !RING_BUFFER_H */
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.