12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- #ifndef __QUEUE_H
- #define __QUEUE_H
- typedef enum
- {
- QUEUE_MODE_OVERFLOW,
- QUEUE_MODE_NO_OVERFLOW,
- } queue_mode_t;
- typedef enum
- {
- size_4 = 0x0004U,
- size_8 = 0x0008U,
- size_16 = 0x0010U,
- size_32 = 0x0020U,
- size_64 = 0x0040U,
- size_128 = 0x0080U,
- size_256 = 0x0100U,
- size_512 = 0x0200U,
- size_1024 = 0x0400U,
- size_2048 = 0x0800U,
- size_4096 = 0x1000U,
- size_8192 = 0x2000U,
- size_16384 = 0x4000U,
- size_32768 = 0x8000U,
- } queue_size_t;
- typedef struct
- {
- volatile unsigned short front;
- volatile unsigned short back;
- void * p_buffer;
- queue_size_t size;
- unsigned short element_count;
- unsigned short element_size;
- queue_mode_t mode;
- } queue_t;
- #define QUEUE_DEF(element_type, _name, _size, _mode) \
- element_type _name##_queue_buffer[(_size)]; \
- queue_t _name= \
- { \
- .front = 0, \
- .back = 0, \
- .p_buffer = _name##_queue_buffer, \
- .size = (_size), \
- .element_count = 0, \
- .element_size = sizeof(element_type), \
- .mode = _mode, \
- }
- unsigned short queue_in(queue_t * p_queue, void const * p_element);
- unsigned short queue_out(queue_t * p_queue, void * p_element);
- unsigned short queue_peek(queue_t * p_queue, void * p_element);
- void queue_reset(queue_t * p_queue);
- unsigned short queue_element_count(queue_t * p_queue);
- unsigned short queue_read(queue_t * p_queue, void * p_element ,int index);
- unsigned short queue_throw_element(queue_t * p_queue);
- #endif
|