/********************************************************************//**
 * @brief
 * @param
 * @return
 *********************************************************************/
void DcdIrqHandler (uint8_t DeviceID)
{
	uint32_t DevIntSt, DMAIntSt;
        uint32_t tmp;
        
        (void)DeviceID;

	tmp = LPC_USB->DevIntEn;
	DevIntSt = LPC_USB->DevIntSt & tmp;                      /* Device Interrupt Status */
	LPC_USB->DevIntClr = DevIntSt;

	/* Device Status Interrupt (Reset, Connect change, Suspend/Resume) */
	if (DevIntSt & DEV_STAT_INT)
	{
          //debug_hard_string("DevIntSt & DEV_STAT_INT\r\n");
		uint32_t SIEDeviceStatus;
		SIE_WriteCommamd(CMD_GET_DEV_STAT);
		SIEDeviceStatus = SIE_ReadCommandData(DAT_GET_DEV_STAT);       /* Device Status */
		if (SIEDeviceStatus & DEV_RST)	                    /* Reset */
		{
			HAL_Reset();
			USB_DeviceState = DEVICE_STATE_Default;
			Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, 0, ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize,0);
			Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, 0, ENDPOINT_DIR_IN, USB_Device_ControlEndpointSize,0);
                        //debug_hard_string("SIEDeviceStatus & DEV_RST\r\n");
		}
		if (SIEDeviceStatus & DEV_CON_CH)	                /* Connect change */
		{
		}
		if (SIEDeviceStatus & DEV_SUS_CH)                   /* Suspend/Resume */
		{
			if (SIEDeviceStatus & DEV_SUS)                  /* Suspend */
			{
			}
			else                                /* Resume */
			{
			}
		}
	}

	if (DevIntSt & FRAME_INT)
	{

	}

	if (DevIntSt & ERR_INT)
	{
		volatile uint32_t SIEErrorStatus;
		SIE_WriteCommamd(CMD_RD_ERR_STAT);
		SIEErrorStatus = SIE_ReadCommandData(DAT_RD_ERR_STAT);
	}

	/* SLAVE mode : Endpoint's Slow Interrupt */
	if ( (DevIntSt & EP_SLOW_INT) || (DevIntSt & EP_FAST_INT) )
	{
          //debug_hard_string("DevIntSt & EP_SLOW_INT\r\n");
		SlaveEndpointISR();
	}

	/* DMA mode */
        uint32_t tmp2 = LPC_USB->DMAIntEn;
	DMAIntSt = LPC_USB->DMAIntSt & tmp2;
	
	if (DMAIntSt & EOT_INT)            /* End of Transfer Interrupt */
	{
          //debug_hard_string("DMAIntSt & EOT_INT\r\n");
		DMAEndTransferISR();

	}

	if (DMAIntSt & NDD_REQ_INT)            /* New DD Request Interrupt */
	{
          //debug_hard_string("DMAIntSt & NDD_REQ_INT\r\n");
		DMANewTransferRequestISR();

	}

	if (DMAIntSt & SYS_ERR_INT)            /* System Error Interrupt */
	{
		// DMASysErrISR();
		LPC_USB->SysErrIntClr = LPC_USB->SysErrIntSt;
	}
}
void DcdIrqHandler(uint8_t DeviceID)
{
	uint32_t DevIntSt, DMAIntSt;

	DevIntSt = USB_REG(DeviceID)->DevIntEn;						/* Device Interrupt Status */
        DevIntSt &= USB_REG(DeviceID)->DevIntEn;
        
	USB_REG(DeviceID)->DevIntClr = DevIntSt;

	/* Device Status Interrupt (Reset, Connect change, Suspend/Resume) */
	if (DevIntSt & DEV_STAT_INT) {
		uint32_t SIEDeviceStatus;
		SIE_WriteCommand(CMD_GET_DEV_STAT);
		SIEDeviceStatus = SIE_ReadCommandData(DAT_GET_DEV_STAT);		/* Device Status */
		if (SIEDeviceStatus & DEV_RST) {					/* Reset */
			HAL_Reset(DeviceID);
			USB_DeviceState[DeviceID] = DEVICE_STATE_Default;
			Endpoint_ConfigureEndpoint(DeviceID, ENDPOINT_CONTROLEP, 0, ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize, 0);
			Endpoint_ConfigureEndpoint(DeviceID, ENDPOINT_CONTROLEP, 0, ENDPOINT_DIR_IN, USB_Device_ControlEndpointSize, 0);
		}
		if (SIEDeviceStatus & DEV_CON_CH) {					/* Connect change */
		}
		if (SIEDeviceStatus & DEV_SUS_CH) {					/* Suspend/Resume */
			if (SIEDeviceStatus & DEV_SUS) {				/* Suspend */
			}
			else {								/* Resume */
			}
		}
	}

	if (DevIntSt & FRAME_INT) {}

	if (DevIntSt & ERR_INT) {
		volatile uint32_t SIEErrorStatus;
		SIE_WriteCommand(CMD_RD_ERR_STAT);
		SIEErrorStatus = SIE_ReadCommandData(DAT_RD_ERR_STAT);
	}

	/* SLAVE mode : Endpoint's Slow Interrupt */
	if ( (DevIntSt & EP_SLOW_INT) || (DevIntSt & EP_FAST_INT) ) {
		SlaveEndpointISR();
	}

	/* DMA mode */
	DMAIntSt = LPC_USB->DMAIntSt;
        DMAIntSt &= USB_REG(DeviceID)->DMAIntEn;

	if (DMAIntSt & EOT_INT) {			/* End of Transfer Interrupt */
		DMAEndTransferISR();
	}

	if (DMAIntSt & NDD_REQ_INT) {			/* New DD Request Interrupt */
		DMANewTransferRequestISR();

	}

	if (DMAIntSt & SYS_ERR_INT) {			/* System Error Interrupt */
		// DMASysErrISR();
		USB_REG(DeviceID)->SysErrIntClr = USB_REG(DeviceID)->SysErrIntSt;
	}
}