1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #ifndef __RINGFRAME_H
- #define __RINGFRAME_H
- /**@brief A FIFO instance structure.
- * @details Keeps track of which bytes to read and write next.
- * Also, it keeps the information about which memory is allocated for the buffer
- * and its size. This structure must be initialized by app_fifo_init() before use.
- */
- typedef enum
- {
- ringframe_size_4 = 0x0004U,
- ringframe_size_8 = 0x0008U,
- ringframe_size_16 = 0x0010U,
- ringframe_size_32 = 0x0020U,
- ringframe_size_64 = 0x0040U,
- ringframe_size_128 = 0x0080U,
- ringframe_size_256 = 0x0100U,
- ringframe_size_512 = 0x0200U,
- ringframe_size_1024 = 0x0400U,
- ringframe_size_2048 = 0x0800U,
- ringframe_size_4096 = 0x1000U,
- ringframe_size_8192 = 0x2000U,
- ringframe_size_16384 = 0x4000U,
- ringframe_size_32768 = 0x8000U,
- }ringframe_size_t;
- typedef struct
- {
- volatile unsigned short front; //!< ringframe front index.
- volatile unsigned short back; //!< ringframe back index.
- void * p_buffer; //!< Pointer to the memory that is used as storage.
- ringframe_size_t size; //单位为字节
- unsigned short element_count;
- unsigned short freespace;
- } ringframe_t;
- /******************************API 接口*************************************/
- #define RINGFRAME_DEF( _name, _size) \
- unsigned char _name##_ringframe_buffer[(_size)]; \
- ringframe_t _name= \
- { \
- .front = 0, \
- .back = 0, \
- .p_buffer = _name##_ringframe_buffer, \
- .size = (_size), \
- .element_count = 0, \
- .freespace = (_size)-1, \
- }
- //返回0表示操作成功,否则失败
- unsigned short ringframe_in(ringframe_t * p_ringframe, void * p_data,unsigned char data_size);
- //返回0表示操作成功,否则失败
- unsigned short ringframe_out(ringframe_t * p_ringframe, void * p_data,unsigned char * data_size);
-
- void ringframe_reset(ringframe_t * p_ringframe);
- //返回0表示操作成功,否则失败
- unsigned short ringframe_peek(ringframe_t * p_ringframe, void * p_data,unsigned char * data_size);
- //返回0表示操作成功,否则失败
- unsigned short ringframe_throw(ringframe_t * p_ringframe);
-
-
- #endif
|