#ifndef _Cirule_Buffer_h__
#define _Cirule_Buffer_h__

#include <stdint.h>
#include "os/os_types.h"
#include "libs/utils.h"

#define CBUFF_SUCCESS 0
#define CBUFF_FULL -1
#define CBUFF_EMPTY -2

typedef struct {
	u8 * buffer;
	int16_t buffer_len;
	int16_t w_pos;
	int16_t r_pos;
}c_buffer_t;

//used by dma
static __inline__ void circle_update_write_position(c_buffer_t *cbuff, int pos){
	cbuff->w_pos = pos;
}

static __inline__ int circle_get_read_position(c_buffer_t *cbuff){
	return cbuff->r_pos;
}

c_buffer_t *circle_buffer_init(c_buffer_t *cbuff, u8 *buffer, int16_t max_len);
void circle_reset(c_buffer_t *cbuff);
int circle_put_one_data(c_buffer_t *cbuff, u8 data);
int circle_put_data(c_buffer_t *cbuff, u8 *data, int16_t len);
int circle_get_one_data(c_buffer_t *cbuff, u8 *data);
int circle_get_data(c_buffer_t *cbuffer, u8 *data, int16_t len);

#endif /* _Cirule_Buffer_h__ */

