/**
 * @file hv_drv_TypecInternalGlobals.c
 * @brief  File contains definitions of globals used internally within the PSF stack
 * @details This file provides the following functions: \n
 *          (1) \n
 *          (2) \n
 *          (3) \n
 *
 * 
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2022-08-25
 * @copyright Copyright(c),2022-8, Hiview Software. All rights reserved.
 * @par History:
 * <table>
 * <tr><th>Author                         <th>Date         <th>Change Description
 * <tr><td>Hiview SoC Software Team       <td>2022-08-25   <td>init
 * </table>
*/

#include <hv_drv_TypecStdInc.h>

/*******************************************************************/
/******************* Global variables********************************/
/*******************************************************************/

/*Timer module globals*/
PDTIMER gasPDTimers[MAX_CONCURRENT_TIMERS];

/*Type C module globals*/
TYPEC_CONTROL  gasTypeCcontrol[CONFIG_PD_PORT_COUNT];

/****************************Protocol Layer globals************************************/
/* PRL State variables */
PROTOCOL_LAYER_STRUCT gasPRL [CONFIG_PD_PORT_COUNT];

 /* PRL receiver Struct*/
PRL_RECVBUFF gasPRLRecvBuff [CONFIG_PD_PORT_COUNT];

#if (HV_TRUE == INCLUDE_PD_3_0)
    /* PRL extended message buffer for Tx & Rx*/
    PRL_EXTMSG_BUFF gasExtendedMsgBuff [CONFIG_PD_PORT_COUNT];

    /* PRL chunk state variable struct*/
    PRL_CHUNK_STRUCT gasChunkSM [CONFIG_PD_PORT_COUNT];

#endif 
/***************************************************************************************/
    
/*Policy Engine globals*/
POLICY_ENGINE_STATUS gasPolicyEngine[CONFIG_PD_PORT_COUNT];

/*Policy manager globals*/
DEVICE_POLICY_MANAGER gasDPM[CONFIG_PD_PORT_COUNT];

/********************Power Management Control globals************************************/
#if (HV_TRUE == INCLUDE_POWER_MANAGEMENT_CTRL)
    /*State of the port whether IDLE or Active*/
    UINT8 gau8ISRPortState [CONFIG_PD_PORT_COUNT];
    /*Timer ID of IDLE Timer*/
    UINT8 gau8PortIdleTimerID [CONFIG_PD_PORT_COUNT];
    /*MCU Idle flag*/
    UINT8 gu8SetMCUIdle;

#endif
/***************************************************************************************/

/*PDFU globals*/
#if (HV_FALSE != INCLUDE_PDFU)    
    UINT8 gu8PDFUResBuffer[PRL_MAX_EXTN_MSG_LEN_IN_BYTES] = {SET_TO_ZERO};
#endif

/**************************************************************************************************/

/********************Power Balancing globals************************************/
#if (HV_TRUE == INCLUDE_POWER_BALANCING) 
    /* Power Balancing Internal System Parameters */
    PB_INT_SYS_PARAM gsPBIntSysParam; 
    /* Power Balancing Internal Port Parameters */
    PB_INT_PORT_PARAM gasPBIntPortParam[CONFIG_PD_PORT_COUNT]; 
    /* Sequence in which ports are attached */
    UINT8 gu8AttachSeq; 
    /* Timer used to wait for Asynchronous request from the Sink */
    UINT8 gu8PBTimerID; 
#endif 
/**************************************************************************************************/ 
    
/********************Power Throttling globals************************************/
#if (HV_TRUE == INCLUDE_POWER_THROTTLING)
    /* Power Throttling Port Parameters */
    UINT8 gau8PTPrevBank[CONFIG_PD_PORT_COUNT];  
#endif 
/**************************************************************************************************/  
    
/********************Configuration and Status register ************************************/    
GLOBAL_CFG_STATUS_DATA gasCfgStatusData = {SET_TO_ZERO};
/**************************************************************************************************/ 

#if (HV_TRUE == INCLUDE_UPD_HPD)
  HPD_CONTROL gu16HPDStsISR[CONFIG_PD_PORT_COUNT];    /*BIT[7:0] -> HPD Event Queue
                                                            BIT[7:6] -> HPD event 3
                                                            BIT[5:4] -> HPD event 2
                                                            BIT[3:2] -> HPD event 1
                                                            BIT[1:0] -> HPD event 0
                                                            00b: HPD event field is empty
                                                            01b: HPD_HIGH Detected
                                                            10b: HPD_LOW Detected
                                                            11b: HPD_IRQ Detected 
                                                        BIT[8] -> HPD Event occurred*/
UINT8 gu8HPDNextIndex[CONFIG_PD_PORT_COUNT];

#endif

/*******************************************************************/
/******************* Functions**************************************/
/*******************************************************************/

void IntGlobals_PDInitialization (void)
{
    UINT8 u8PortNum;
    for (u8PortNum = SET_TO_ZERO; u8PortNum < CONFIG_PD_PORT_COUNT; u8PortNum++)
    {
#if (HV_TRUE == INCLUDE_POWER_MANAGEMENT_CTRL)
        UPD_InitPwrManagement(u8PortNum);        
#endif
        DPM_Init (u8PortNum);

        PE_InitPort (u8PortNum);
        
#if (HV_FALSE != INCLUDE_PDFU)
        PE_FwUpdtInitialize ();
#endif
        
#if (HV_TRUE == INCLUDE_POWER_THROTTLING)
        PT_Init (u8PortNum); 
#endif 
    }
    
#if (HV_TRUE == INCLUDE_POWER_BALANCING)
    /* Initialize PB System and Port Parameters */
    PB_Init ();     
#endif 
}

/**************************************************************************************************/
