#ifndef RINGBUFFER_H
#define RINGBUFFER_H

#include <stdint.h>
#include <stddef.h>

#define RING_BUFFER_SIZE  512U

/* Single-producer/single-consumer ring buffer.
 *
 * Use one execution context to call RingBuff_Write() (for example, a UART ISR)
 * and one other context to call RingBuff_Read() (for example, the main loop).
 */
typedef struct {
	volatile uint16_t head;
	volatile uint16_t tail;
	uint8_t data[RING_BUFFER_SIZE];
} ringBuffer_t;

// Returns 0 after storing data; returns 1 for an invalid pointer or full buffer
uint8_t RingBuff_Write(ringBuffer_t *buffer, uint8_t data);

// Returns 0 and writes *data when a byte is available; returns 1 when empty
uint8_t RingBuff_Read(ringBuffer_t *buffer, uint8_t *data);


#endif
