EtherLib/blocking_fifo.h
Epagris 0a6d007c73 - blocking FIFO name collision fixed, by prepending BlockingFifo function names with "eth_"
- CMake integration added
- OS calls got tailored to CMSIS OS2 interface
2024-04-13 16:57:21 +02:00

46 lines
1.3 KiB
C

//
// Created by epagris on 2023.11.22..
//
#ifndef ETHERLIB_TEST_BLOCKING_FIFO_H
#define ETHERLIB_TEST_BLOCKING_FIFO_H
#include <stdint.h>
#include <etherlib_options.h>
/**
* Blocking FIFO
*/
typedef struct {
uint32_t readIdx; ///< Read index
uint32_t absReadIdx; ///< Absolute read index
uint32_t writeIdx; ///< Write index
uint32_t absWriteIdx; ///< Absolute write index
uint32_t size; ///< Size of the storage area
ETHLIB_OS_SEM_TYPE notFull, nonEmpty; ///< Semaphore, protecting read and write operations
uint8_t data[]; ///< Window data storage
} BlockingFifo;
/**
* Create new blocking FIFO.
* @param size size of the FIFO in bytes
* @return newly allocated FIFO
*/
BlockingFifo * eth_bfifo_new(uint32_t size);
void eth_bfifo_destroy(BlockingFifo * bfifo);
uint32_t eth_bfifo_get_used(const BlockingFifo * bfifo);
uint32_t eth_bfifo_get_free(const BlockingFifo * bfifo);
uint32_t eth_bfifo_push(BlockingFifo * bfifo, const uint8_t * data, uint32_t size);
uint32_t eth_bfifo_push_try(BlockingFifo * bfifo, const uint8_t * data, uint32_t size);
uint32_t eth_bfifo_peek(BlockingFifo * bfifo, uint8_t * dst, uint32_t size);
uint32_t eth_bfifo_pop(BlockingFifo *bfifo, uint8_t *dst, uint32_t size);
#endif //ETHERLIB_TEST_BLOCKING_FIFO_H