ringbuffer.h 1.69 KB
#ifndef _RINGBUF_H_
#define _RINGBUF_H_

#include "cmsis_os.h"

#if !defined(__WINDOWS__) && !defined (FREERTOS) && !defined (LINUX)
#define FREERTOS
#endif

/**
 * Put data in a specific length.
 * @param *buffer	 the position of buffer specified by user.
 * @param len	 the length of data which user wants to put.
 * @return WRITE_SUCCEED if write succeed,FAIL_LACK_OF_SPACE if no enough space to write in.
 */
int8_t RINGBUF_SEND(const char * buffer, uint16_t len);

/**
 * Take data out in a specific length.
 * @param *buffer	 the position of buffer specified by user.
 * @param len	 the length of data which user wants to take.
 * @return RINGBUF_READ if read succeed,FAIL_READ_TOO_FAST if readpoint would pass writepoint.
 */
int8_t RINGBUF_READ(uint8_t * buffer, uint16_t len);

/**
 * Get data from a specific length.
 * @param *buffer	 the position of buffer specified by user.
 * @param len	 the length of data which user wants to get,not take out!!
 * @return RINGBUF_READ if read succeed,FAIL_READ_TOO_FAST if readpoint would pass writepoint.
 */
int8_t RINGBUF_PEEK(uint8_t * buffer, uint16_t len);

/**
 * use buffer specified by user as ringbuffer.
 * @param *buffer	 the position of buffer specified by user.
 * @param len	 the length of buffer which user wants.
 * @return NULL.
 */
void RINGBUF_INIT(uint8_t * ringbuffer, uint16_t len);

/**
 * check if read too fast.
 * @param NULL
 * @return 1 if read gradually,0 if readpoint catch writepoint.
 */
uint8_t RINGBUF_CHECKIO(void);

/**
 * request for space avaliable to write.
 * @param NULL
 * @return len the space avaliable to use of this ringbuffer.
 */
uint16_t RINGBUF_AVALIABLE_SPACE(void);
	
#endif