/*
 * @file hv_pm51_app_Mailbox.h
 * @brief Header file of mailbox module.
 *
 * @verbatim
 * ==============================================================================
 *                        ##### How to use #####
 * ==============================================================================
 * (+) Use ()
 *
 * @endverbatim
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2023-03-01
 */
 
#ifndef __HV_PM51_APP_MAILBOX_H__
#define __HV_PM51_APP_MAILBOX_H__

#include "hv_pm51_Base.h"
#include "hv_pm51_Reg.h"

typedef enum _MsgType
{
    E_MAILBOX_CMD_NULL = 0,
    E_MAILBOX_CMD_PM_TO_RISC_KEY_VAL = 1,
    E_MAILBOX_CMD_PM_TO_RISC_KEY_UPSPRING = 2,
    E_MAILBOX_CMD_PM_TO_RISC_KEY_COMBO = 3,
    E_MAILBOX_CMD_PM_TO_RISC_WAKEUP = 4,
    E_MAILBOX_CMD_RISC_TO_PM_POWER_OFF_ACK = 5,
    E_MAILBOX_CMD_RISC_TO_PM_STAND_BY = 6,
    E_MAILBOX_CMD_RISC_TO_PM_NORMAL = 7,
    E_MAILBOX_CMD_PM_TO_RISC_IR_VAL = 8,
    E_MAILBOX_CMD_PM_TO_RISC_IR_REPEAT = 9,
    E_MAILBOX_CMD_PM_TO_RISC_POWER_OFF = 10,
    E_MAILBOX_CMD_PM_TO_RISC_HEART_MONITOR = 11,
    E_MAILBOX_CMD_PM_TO_RISC_FACTORY_MODE = 12,
    E_MAILBOX_CMD_RISC_TO_PM_LED_MODE_OFF = 13,
    E_MAILBOX_CMD_RISC_TO_PM_LED_MODE_ON = 14,
    E_MAILBOX_CMD_RISC_TO_PM_FIX_MODE_OFF = 15,
    E_MAILBOX_CMD_RISC_TO_PM_FIX_MODE_ON = 16,
    E_MAILBOX_CMD_RISC_TO_PM_CUR_MAIN_CHANNEL_HDMI0 = 17,
    E_MAILBOX_CMD_RISC_TO_PM_CUR_MAIN_CHANNEL_HDMI1 = 18,
    E_MAILBOX_CMD_RISC_TO_PM_CUR_MAIN_CHANNEL_DP0 = 19,
    E_MAILBOX_CMD_RISC_TO_PM_CUR_MAIN_CHANNEL_DP1 = 20,
    E_MAILBOX_CMD_RISC_TO_PM_FACTORY_OFF = 21,
    E_MAILBOX_CMD_RISC_TO_PM_FACTORY_ON = 22,
    E_MAILBOX_CMD_RISC_TO_PM_CUR_SUB_CHANNEL_HDMI0 = 23,
    E_MAILBOX_CMD_RISC_TO_PM_CUR_SUB_CHANNEL_HDMI1 = 24,
    E_MAILBOX_CMD_RISC_TO_PM_CUR_SUB_CHANNEL_DP0 = 25,
    E_MAILBOX_CMD_RISC_TO_PM_CUR_SUB_CHANNEL_DP1 = 26,
    E_MAILBOX_CMD_RISC_TO_PM_SET_LED_OFF = 27,
    E_MAILBOX_CMD_RISC_TO_PM_SET_LED_ON = 28,
    E_MAILBOX_CMD_RISC_TO_PM_SET_LED_BREATH = 29,
    E_MAILBOX_CMD_RISC_TO_PM_SET_LED_ON1 = 30,
    E_MAILBOX_CMD_RISC_TO_PM_SET_LED_ON2 = 31,
    E_MAILBOX_CMD_RISC_TO_PM_SET_LED_ON3 = 32,
    E_MAILBOX_CMD_PM_TO_RISC_LOCK_MODE   = 33,
    E_MAILBOX_CMD_PM_TO_RISC_DP0_AUXN_INT = 34,
    E_MAILBOX_CMD_PM_TO_RISC_DP1_AUXN_INT = 35,
    E_MAILBOX_CMD_MAX = 127
}MsgType;

typedef enum _WakeUPType
{
    E_WAKE_UP_TYPE_POWER_ON = 0,
    E_WAKE_UP_TYPE_HDMI_CABLE,
    E_WAKE_UP_TYPE_DP_CABLE,
    E_WAKE_UP_TYPE_TYPE_C_CABLE,

    E_WAKE_UP_TYPE_HDMI_TMDS,
    E_WAKE_UP_TYPE_HDMI_CEC,
    E_WAKE_UP_TYPE_DP_AUX,
    E_WAKE_UP_TYPE_TYPE_C_CC_CMD,

    E_WAKE_UP_TYPE_KEY,
    E_WAKE_UP_TYPE_IR,
    E_WAKE_UP_TYPE_DP_GPIO,
    E_WAKE_UP_TYPE_STANDBY_TO_POWEROFF,
}WakeUPType;

typedef struct _MsgHeader
{
    UCHAR8         u8MsgType;
    UCHAR8         pu8MsgLen[2];  /* low byte in pu8MsgLen[0], high byte in pu8MsgLen[1] */
    UCHAR8         u8Crc;
}MsgHeader;

typedef struct _Msg
{
    MsgHeader  stMsgHeader;
    UCHAR8     u8Val[12];
} Msg;

typedef struct _MsgPoolItem
{
    Msg  stMsg;   /* the msg */
    BOOL bIsUsed; /* the item is used or free */
}MsgPoolItem;

typedef struct _SendMsgPoolMgr
{
    MsgPoolItem      *pStMsgPool;          /* pointer to the reserved msg pool */
    USHORT16         u16TotalNumOfItems; /* the total number of MsgPoolItem in the MsgPool */
    USHORT16         u16NumOfFreeItems;  /* the free number of MsgPoolItem in the MsgPool */
    USHORT16         u16CurSendingItem;  /* the index of current sending item */
    USHORT16         u16CurWritableItem; /* the index of current writable item */
}SendMsgPoolMgr;

/**
 * @brief Get status of message poll empty or not.
  * @return HV_TRUE: empty  HV_FALSE: not empty.
 */
BOOL Hv_PM51_Mailbox_MsgPoolIsEmpty(void);
    
/**
 * @brief Mailbox initialization.
 * @return None.
 */
void Hv_PM51_Mailbox_Init(void);

/**
 * @brief Send mailbox message to message pool. 
 * @param[in] pstMsg: Pointer to the mailbox message structure.
 * @return 1: send successfully  0: send failed.
 */
xUCHAR8 Hv_PM51_Mailbox_Send(Msg *pstMsg);

/**
 * @brief Handling messages triggered by interrupts from MIPS.
 * @return None.
 */
void Hv_PM51_Mailbox_RecvHandler(void);

/**
 * @brief Send mailbox message to MIPS.
 * @return None.
 */
void Hv_PM51_Mailbox_SendHandler(void);

#endif 
