#include <ti/csl/cslr_cpintc.h>
#include "arm_cpintc.h"

static CSL_CPINTCRegs *arm_cpintc;

/******************************************************************************
*  Function Name    : Arm_Cpintc_Map_SysInttoHostInt
*  Description      : Initializes module
******************************************************************************/
void Arm_Cpintc_Init(void)
{
    arm_cpintc = (CSL_CPINTCRegs *) 0x2608000;
    arm_cpintc->GLOBAL_ENABLE_HINT_REG = 1;
}

/******************************************************************************
*  Function Name    : Arm_Cpintc_Map_SysInttoHostInt
*  Description      : Generic Function to map interrupts in cpintc
*  Parameters       : sysEvt= Event Inputs of CP_INTC for GEMs
*                     hostEvt= host event number
*  Return           : None
******************************************************************************/

void Arm_Cpintc_MapSysToHostInt(unsigned int sysEvt, 
                                 arm_cpintc_gic_event hostEvt)
{
    Uint32  channel = (Uint32)hostEvt;

    /* Set the corresponding bits in the Host Interrupt Map Register. */
    arm_cpintc->CH_MAP[sysEvt] |= (channel & 0xFF);
}

/******************************************************************************
*  Function Name    : Arm_Cpintc_Enable_Channel
*  Description      : Enables System and Host interrupts.
*  Parameters       : sysEvt= Event Inputs of CP_INTC for GEMs
*                     hostEvt= host event number
*  Return           : None
******************************************************************************/

void Arm_Cpintc_EnableChannel(unsigned int sysEvt, 
                               arm_cpintc_gic_event hostEvt)
{
	//Enable the the host interrupt. 
    arm_cpintc->HINT_ENABLE_SET_INDEX_REG = (unsigned int)hostEvt & 0x3FF;

    //Enable system interrupt
    arm_cpintc->ENABLE_SET_INDEX_REG = (sysEvt & 0x3FF);
}


/******************************************************************************
*  Function Name    : Arm_Cpintc_SetSysInterrupt
*  Description      : Sets the status of the interrupt in CPINTC
*  Parameters       : sysEvt= Event Inputs of CP_INTC for GEMs
*					  
*  Return           : None
******************************************************************************/

void Arm_Cpintc_SetSysInterrupt(unsigned int sysEvt)
{
    arm_cpintc->STATUS_SET_INDEX_REG = (sysEvt & 0x3FF);
}

/******************************************************************************
*  Function Name    : Arm_Cpintc_ClearSysInterrupt
*  Description      : Clear the status of the interrupt in CPINTC
*  Parameters       : sysEvt= Event Inputs of CP_INTC for GEMs
*					  
*  Return           : None
******************************************************************************/
void Arm_Cpintc_ClearSysInterrupt(unsigned int sysEvt)
{
    arm_cpintc->STATUS_CLR_INDEX_REG = (sysEvt & 0x3FF);
}

