/******************************************************************************
 * file    include/fifo.h 
 * author  YuLiang
 * version 1.0.0
 * date    21-Feb-2023
 * brief   This file provides all the headers of the fifo functions.
 ******************************************************************************
 * Attention
 *
 * <h2><center>&copy; COPYRIGHT(c) 2021 LandPower</center></h2>
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *   1. Redistributions of source code must retain the above copyright notice,
 *      this list of conditions and the following disclaimer.
 *   2. Redistributions in binary form must reproduce the above copyright notice,
 *      this list of conditions and the following disclaimer in the documentation
 *      and/or other materials provided with the distribution.
 *   3. Neither the name of LandPower nor the names of its contributors may be used to 
 *      endorse or promote products derived from this software without specific
 *      prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 ******************************************************************************/

#ifndef _FIFO_H_
#define _FIFO_H_

/* Includes ------------------------------------------------------------------*/
#include <semaphore.h>

/* Define --------------------------------------------------------------------*/
#define FIFO_NAME_LEN 32

/* Exported types ------------------------------------------------------------*/

/* . */
typedef struct _fifo_t
{
    char name[FIFO_NAME_LEN];                   // fifo 名字.
    uint32_t size;                              // fifo 大小.
    uint32_t cur;                               // 当前的数据位置.
    uint32_t valid;                             // 当前读取的数据位置.
    uint32_t used;                              // fifo 使用数量.
    uint32_t max;                               // fifo 最大使用数量.
    pthread_mutex_t mutex;                      // 多线程同时操作的信号量.
    sem_t sem;                                  // 读取有效互斥锁.
    void **data;                                // 数据数组.
} fifo_t;

/* Exported macro ------------------------------------------------------------*/

/* Extern global variables ---------------------------------------------------*/

/* Extern functions ----------------------------------------------------------*/
extern int32_t fifo_init(void);
extern int32_t fifo_create(char* name, uint32_t size);
extern int32_t fifo_write(uint32_t id, void *data, int32_t len);
extern int32_t fifo_read(uint32_t id, void **data);
extern int32_t fifo_push(uint32_t id);
extern void fifo_show(uint32_t id);
#endif
/************************ (C) COPYRIGHT LandPower ***** END OF FILE ****************/
