void WriteControlEndpoint(uint8_t *pData, uint32_t cnt)
{
	uint32_t n;
	uint32_t count;

	isInReady = false;
	if (cnt >= USB_Device_ControlEndpointSize) {
		if (cnt == USB_Device_ControlEndpointSize) {
			shortpacket = true;
		}
		count = USB_Device_ControlEndpointSize;
		DataInRemainCount = cnt - USB_Device_ControlEndpointSize;
		DataInRemainOffset += count;
	}
	else {
		count = cnt;
		DataInRemainCount = 0;
		DataInRemainOffset = 0;
	}
	USB_REG(0)->Ctrl = CTRL_WR_EN;
	USB_REG(0)->TxPLen = count;

	for (n = 0; n < (count + 3) / 4; n++) {
		USB_REG(0)->TxData = *((uint32_t *) pData);
		pData += 4;
	}

	USB_REG(0)->Ctrl = 0;

	SIE_WriteCommand(CMD_SEL_EP(ENDPOINT_CONTROLEP + 1));
	SIE_WriteCommand(CMD_VALID_BUF);
}
/********************************************************************//**
 * @brief
 * @param
 * @return
 *********************************************************************/
void WriteControlEndpoint( uint8_t *pData, uint32_t cnt )
{
	uint32_t n;
	uint32_t count;

	isInReady = false;
	if(cnt >= USB_Device_ControlEndpointSize)
	{
		if(cnt == USB_Device_ControlEndpointSize)
		{
			shortpacket = true;
		}
		count = USB_Device_ControlEndpointSize;
		DataInRemainCount = cnt - USB_Device_ControlEndpointSize;
		DataInRemainOffset += count;
	}
	else
	{
		count = cnt;
		DataInRemainCount = 0;
		DataInRemainOffset = 0;
                ///HACK: patch for get ready after last packet equal to USB_Device_ControlEndpointSize
                isInReady = true;
	}
	LPC_USB->Ctrl = CTRL_WR_EN;
	LPC_USB->TxPLen = count;

	for (n = 0; n < (count + 3) / 4; n++)
	{
		LPC_USB->TxData = *((uint32_t *)pData);
		pData += 4;
	}

	LPC_USB->Ctrl = 0;

	SIE_WriteCommamd(CMD_SEL_EP(ENDPOINT_CONTROLEP+1));
	SIE_WriteCommamd(CMD_VALID_BUF);
}