/******************************************************************************
 *
 * Copyright 2013, Silicon Image, Inc.  All rights reserved.
 * No part of this work may be reproduced, modified, distributed, transmitted,
 * transcribed, or translated into any language or computer format, in any form
 * or by any means without written permission of
 * Silicon Image, Inc., 1140 East Arques Avenue, Sunnyvale, California 94085
 *
 *****************************************************************************/
/**
 * @file si_drv_ipc_api.h
 *
 * @brief IPC message protocol
 *
 *****************************************************************************/
#ifndef SI_DRV_IPC_API_H
#define SI_DRV_IPC_API_H

/***** #include statements ***************************************************/

#include "si_datatypes.h"

/***** public macro definitions **********************************************/

#define SII_DRV_IPC_EVENT__MESSAGE_SENT          0x01
#define SII_DRV_IPC_EVENT__MESSAGE_RECEIVED      0x02

#define SII_DRV_IPC_ISR_FLAG__PACKET_RDY         0x01
#define SII_DRV_IPC_ISR_FLAG__ACK                0x02
#define SII_DRV_IPC_ISR_FLAG__NACK               0x04

/***** public type definitions ***********************************************/

typedef SiiInst_t  SiiDrvIpcInst_t;
typedef SiiInst_t  SiiDrvIpcMesInst_t;
typedef uint8_t    SiiDrvIpcIsrFlags_t;
typedef uint32_t   SiiDrvIpcEvent_t;
typedef uint16_t   SiiDrvIpcOpCode_t;
typedef uint8_t    SiiDrvIpcTagCode_t;

typedef enum
{
    SII_DRV_IPC_TYPE__NONE,
    SII_DRV_IPC_TYPE__REQUEST,
    SII_DRV_IPC_TYPE__RESPONSE,
    SII_DRV_IPC_TYPE__NOTIFY
} SiiDrvIpcType_t;

typedef struct
{
    SiiPlatformDevId_t devId;
} SiiDrvIpcConfig_t;

/***** call-back functions ********************************************** *****/

extern void SiiDrvIpcCallBack( SiiDrvIpcInst_t ipcInst, SiiDrvIpcEvent_t eventFlags );

/***** public functions ******************************************************/

SiiDrvIpcInst_t SiiDrvIpcCreate( const char *pNameStr, SiiInst_t parentInst, SiiDrvIpcConfig_t *pConfig );
void SiiDrvIpcDelete( SiiDrvIpcInst_t ipcInst  );
void SiiDrvIpcHandler( SiiDrvIpcInst_t ipcInst, SiiDrvIpcIsrFlags_t flags );
void SiiDrvIpcMessageSend( SiiDrvIpcInst_t ipcInst, SiiDrvIpcMesInst_t mesInst );
void SiiDrvIpcMessageReceive( SiiDrvIpcInst_t ipcInst, SiiDrvIpcMesInst_t mesInst );
bool_t SiiDrvIpcMessageSent( SiiDrvIpcInst_t ipcInst );
bool_t SiiDrvIpcMessageReceived( SiiDrvIpcInst_t ipcInst );
void SiiDrvIpcTxReset( SiiDrvIpcInst_t ipcInst );

SiiDrvIpcMesInst_t SiiDrvIpcMessageCreate( void );
void SiiDrvIpcMessageDelete( SiiDrvIpcMesInst_t ipcInst );
void SiiDrvIpcMessageClear( SiiDrvIpcMesInst_t mesInst );
void SiiDrvIpcMessageCopy( SiiDrvIpcMesInst_t mesDesInst, SiiDrvIpcMesInst_t mesSrcInst );

void SiiDrvIpcTypeSet( SiiDrvIpcMesInst_t mesInst, SiiDrvIpcType_t type );
SiiDrvIpcType_t SiiDrvIpcTypeGet( SiiDrvIpcMesInst_t mesInst );

void SiiDrvIpcOpCodeSet( SiiDrvIpcMesInst_t mesInst, SiiDrvIpcOpCode_t opCode );
SiiDrvIpcOpCode_t SiiDrvIpcOpCodeGet( SiiDrvIpcMesInst_t mesInst );

void SiiDrvIpcTagCodeSet( SiiDrvIpcMesInst_t mesInst, SiiDrvIpcTagCode_t tagCode );
SiiDrvIpcTagCode_t SiiDrvIpcTagCodeGet( SiiDrvIpcMesInst_t mesInst );

void SiiDrvIpcBoolPush( SiiDrvIpcMesInst_t mesInst, bool_t par );
bool_t SiiDrvIpcBoolPop( SiiDrvIpcMesInst_t mesInst );

void SiiDrvIpcBytePush( SiiDrvIpcMesInst_t mesInst, uint8_t par );
uint8_t SiiDrvIpcBytePop( SiiDrvIpcMesInst_t mesInst );

void SiiDrvIpcWordPush( SiiDrvIpcMesInst_t mesInst, uint16_t par );
uint16_t SiiDrvIpcWordPop( SiiDrvIpcMesInst_t mesInst );

void SiiDrvIpcLongPush( SiiDrvIpcMesInst_t mesInst, uint32_t par );
uint32_t SiiDrvIpcLongPop( SiiDrvIpcMesInst_t mesInst );

void SiiDrvIpcArrayPush( SiiDrvIpcMesInst_t mesInst, const uint8_t* pPar, uint16_t size );
void SiiDrvIpcArrayPop( SiiDrvIpcMesInst_t mesInst, uint8_t* pPar, uint16_t size );

#endif // SI_DRV_IPC_API_H

/***** end of file ***********************************************************/
