/*-----------------------------------------------------------------------------------
!
!                              COPYRIGHT 2015 BY
!                            MegaChips Corporation
!
!------------------------------------------------------------------------------------
! These coded instructions, statements, and computer programs include
! intellectual property and know-how belonging to MegaChips
! Corporaiton ("MCC") and its partner companies.
! Therefore, do not use these specifications for any purpose other than
! the purpose
! expressly agreed to by MCCs customer and MCC.  Also, do not duplicate,
! copy,
! or reproduce these specifications, nor reveal these specifications to
! any third party
! without MCCs prior written consent.
!
*/

/*-----------------------------------------------------------------------------------
  FILE        : fifo.h
  DESCRIPTION : fifo.c header
  Revision    : $Rev: 4 $
  Author      : $Author: shirait $
  Date        : $Date: 2015-09-09 15:19:58 +0900 (豌ｴ, 09 9 2015) $
-----------------------------------------------------------------------------------*/

#ifndef __FIFO_H__
#define __FIFO_H__

/********************************************************************************************
include
********************************************************************************************/
#include <stdio.h>
#include <stdint.h>
#include "fifo_reg.h"


/********************************************************************************************
macro
********************************************************************************************/
//
//
// BootCodeサイズを抑えるため、一部マクロ化しています
//
//
#define FIFO_SIZE  (1024)

/*---------------------------------------------------------------------------
  function  : FIFO EmptyFlagの取得
  arguments : type : I  : 接続タイプ
  return    : void
  detail    : none
--------------------------------------------------------------------------*/
#define FIFO_GetEmptyFlag() (FIFOR.status & FIFO_EMPTY_MASK)


/*---------------------------------------------------------------------------
  function  : FIFO FullFlagの取得
  arguments : type : I  : 接続タイプ
  return    : void
  detail    : none
--------------------------------------------------------------------------*/
#define FIFO_GetFullFlag() (FIFOR.status & FIFO_FULL_MASK)


/*---------------------------------------------------------------------------
  function  : 接続タイプの設定
  arguments : type : I  : 接続タイプ
  return    : void
  detail    : none
--------------------------------------------------------------------------*/
#define FIFO_SetConnection(type) (FIFOR.sel = (type))


/*---------------------------------------------------------------------------
  function  : AlmostFull出力レベルの設定
  arguments : lvl : I  : AlmostFull出力レベル
  return    : void
  detail    : none
--------------------------------------------------------------------------*/
#define FIFO_SetAlmostFull(lvl)  (FIFOR.amf_lvl = (lvl))


/*---------------------------------------------------------------------------
  function  : FIFOのWriteに関するステータス取得
  arguments : none
  return    : 0(!AlmostEmpty), !0(AlmostEmpty)
  detail    : none
--------------------------------------------------------------------------*/
#define  FIFO_GetWriteStatus()  (FIFOR.status & FIFO_ALE_MASK)


/*---------------------------------------------------------------------------
  function  : FIFOのReadに関するステータス取得
  arguments : none
  return    : 0(ReadDataなし), !0(ReadDataあり)
  detail    : none
--------------------------------------------------------------------------*/
#define  FIFO_GetReadStatus()  (FIFOR.status & FIFO_ALF_MASK)



/********************************************************************************************
prottype
********************************************************************************************/
void FIFO_Init(void);
int FIFO_ReadDataF2D(uint32_t* pBuff, int len);
int FIFO_ReadDataF2P(volatile uint32_t* pBuff, int len);


#endif // __FIFO_H__
