1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef BUF_FIFO_H 10 #define BUF_FIFO_H 11 12 #include <stdint.h> 13 #include <stdbool.h> 14 15 struct BufferFifo { 16 volatile uint32_t readPosition; 17 volatile uint32_t writePosition; 18 uint16_t bufSizeMask; 19 uint8_t *buffer; 20 }; 21 BufferFifoGetDataSize(struct BufferFifo * fifo)22static inline uint16_t BufferFifoGetDataSize(struct BufferFifo *fifo) 23 { 24 return (fifo->writePosition - fifo->readPosition); 25 } 26 IsPowerOfTwo(int num)27static inline bool IsPowerOfTwo(int num) 28 { 29 return (num > 0) && (num & (num - 1)) == 0; 30 } 31 32 bool BufferFifoInit(struct BufferFifo *fifo, uint8_t *buf, uint16_t bufSize); 33 34 #endif // BUF_FIFO_H 35 36