📄 td1120p.c
字号:
** endpoint --- presuming only endpoint 0 will be used as a control
** endpoint
*/
/* Clear the OUT threshold interrupt before the OUT data is copied out of the FIFO */
if (readOutThreshold & 0x01)
{
/* Clear the OUT threshold available interrupt */
SYS_Write1120P_Register(pc->ioBase, TD1120_DEV_EP_OUT_THRSHLD_AVAIL_REG, 1);
}
/* OUT Transfer Received Handler */
TD1120P_DoEpTransfer(pc, 0, ISOUT);
if (readOutRx & 0x01)
{
/* Clear the xfer recved interrupt */
SYS_Write1120P_Register(pc->ioBase, TD1120_DEV_EP_OUT_XFER_RCVD_REG, 1);
}
if (readInThreshold & 0x01)
{
SYS_Write1120P_Register(pc->ioBase, TD1120_DEV_EP_IN_THRSHLD_AVAIL_REG, 1);
if (pc->testModePending)
{
TD1120P_SetTestMode((TdiPeriphController *)pc, pc->testModePending);
pc->testModePending = 0;
return;
}
}
TD1120P_DoEpTransfer(pc, 0, ISIN);
if (readInSent & 0x01)
{
SYS_Write1120P_Register(pc->ioBase, TD1120_DEV_EP_IN_FIFO_CLEAR_REG, 1);
SYS_Write1120P_Register(pc->ioBase, TD1120_DEV_EP_IN_XFER_SENT_REG, 1);
}
}
else
{
for (i=0; i<16; i++)
{
/* Process OUT interrupts */
if ((readOutThreshold | readOutRx) & (1 << i))
{
/* Clear the threshold interrupt before copying the data out of the FIFO */
if (readOutThreshold & (1 << i))
{
/* Clear the OUT threshold available interrupt */
SYS_Write1120P_Register(pc->ioBase, TD1120_DEV_EP_OUT_THRSHLD_AVAIL_REG, (1 << i));
}
TD1120P_DoEpTransfer(pc, i, ISOUT);
if (readOutRx & (1 << i))
{
TD1120P_EpTransferDone(pc, i, ISOUT);
/* Clear the xfer recved interrupt */
SYS_Write1120P_Register(pc->ioBase, TD1120_DEV_EP_OUT_XFER_RCVD_REG, (1 << i));
}
}
/* Process IN interrupts */
if (readInThreshold & (1 << i))
{
/* IN Threshold emptied */
SYS_Write1120P_Register(pc->ioBase, TD1120_DEV_EP_IN_THRSHLD_AVAIL_REG, (1 << i));
TD1120P_DoEpTransfer(pc, i, ISIN);
if (pc->testModePending)
{
TD1120P_SetTestMode((TdiPeriphController *)pc, pc->testModePending);
pc->testModePending = 0;
return;
}
}
if (readInSent & (1 << i))
{
/* IN Transfer sent */
SYS_Write1120P_Register(pc->ioBase, TD1120_DEV_EP_IN_XFER_SENT_REG, (1 << i));
TD1120P_EpTransferDone(pc, i, ISIN);
}
}
}
}
/* Make sure that you clear the interrupt now, else system deadlocks */
SYS_Write1120P_Register(pc->ioBase, TD1120_INTR_ENABLE_SET,
TD1120_INTR_ENABLE_PERIPHERAL);
}
/*------------------------------------------------------------------------------
Name : TD1120P_Start
Purpose : Start the controller operation
Arguments : pc - peripheral controller handle
Return : SctStatus
Notes :
------------------------------------------------------------------------------*/
SctStatus TD1120P_Start(TdiPeriphController* pc)
{
/* Enable Peripheral Clock */
SYS_Write1120P_Register(pc->ioBase, TD1120_CLOCL_SET,
TD1120_CLOCK_SET_PERIPHERAL);
TD1120P_PeripheralInit(pc);
/* Enable Voltage Comparator and make otg port peripheral */
SYS_Write1120P_Register(pc->ioBase, TD1120_HARDWARE_MODE_SET,
TD1120_HARDWARE_MODE_COMPARATOR |
TD1120_HARDWARE_MODE_HOST_ONLY);
/* Enable System Interrupt on peripheral */
SYS_Write1120P_Register(pc->ioBase, TD1120_INTR_ENABLE_SET,
TD1120_INTR_ENABLE_PERIPHERAL);
return(SCS_SUCCESS);
}
/*------------------------------------------------------------------------------
Name : TD1120P_Stop
Purpose : opposited to start
Arguments : pc - peripheral controller handle
Return : SctStatus
Notes :
------------------------------------------------------------------------------*/
SctStatus TD1120P_Stop(TdiPeriphController* pc)
{
return (SCS_SUCCESS);
}
/*------------------------------------------------------------------------------
Name : TD1120P_DisableControllerIntr
Purpose : Disable interrupts on the controller
Arguments : pc - peripheral controller handle
Returns : SctStatus
-----------------------------------------------------------------------------*/
SctStatus TD1120P_DisableControllerIntr(TdiPeriphController* pc)
{
if (pc == NULL)
{
PRINTF1(("\nTD1120P_DisableControllerIntr: Invalid handle."));
return SCS_ERROR_INVALID_HANDLE;
}
/* Disable System Interrupt on peripheral */
SYS_Write1120P_Register(pc->ioBase, TD1120_INTR_ENABLE_CLEAR,
TD1120_INTR_ENABLE_PERIPHERAL);
return (SCS_SUCCESS);
}
/*------------------------------------------------------------------------------
Name : TD1120P_EnableControllerIntr
Purpose : Enable interrupts on the controller
Arguments : pc - peripheral controller handle
Returns : SctStatus
-----------------------------------------------------------------------------*/
SctStatus TD1120P_EnableControllerIntr(TdiPeriphController* pc)
{
if (pc == NULL)
{
PRINTF1(("\nTD1120P_EnableControllerIntr: Invalid handle."));
return SCS_ERROR_INVALID_HANDLE;
}
/* Enable System Interrupt on peripheral */
SYS_Write1120P_Register(pc->ioBase, TD1120_INTR_ENABLE_SET,
TD1120_INTR_ENABLE_PERIPHERAL);
return (SCS_SUCCESS);
}
/*------------------------------------------------------------------------------
Name : TD1120P_SetDeviceConfig
Purpose : Set the configuration and do any controller-specific work
for the same
Arguments : pc - peripheral controller handle
configNumber - configuration number
Returns : SctStatus
-----------------------------------------------------------------------------*/
SctStatus TD1120P_SetDeviceConfig(TdiPeriphController* pc, U32 configNumber)
{
if (pc == NULL)
{
PRINTF1(("\nTD1120P_SetDeviceConfig: Invalid handle."));
return SCS_ERROR_INVALID_HANDLE;
}
/* Nothing to do for TD1120 */
return (SCS_SUCCESS);
}
/*------------------------------------------------------------------------------
Name : TD1120P_ClearDeviceConfig
Purpose : Clear the current configuration and do any controller-specific work
for the same
Arguments : pc - peripheral controller handle
Returns : SctStatus
-----------------------------------------------------------------------------*/
SctStatus TD1120P_ClearDeviceConfig(TdiPeriphController* pc)
{
if (pc == NULL)
{
PRINTF1(("\nTD1120P_ClearDeviceConfig: Invalid handle."));
return SCS_ERROR_INVALID_HANDLE;
}
/* Nothing to do for TD1120 */
return (SCS_SUCCESS);
}
/*------------------------------------------------------------------------------
Name : TD1120P_EpNakSet
Purpose : Set the endpoint NAK so that it is ready to handle the transaction
Arguments : pc - peripheral controller handle
epNumber - endpoint number
Returns : SctStatus
-----------------------------------------------------------------------------*/
SctStatus TD1120P_EpNakSet(TdiPeriphController* pc, U32 epNumber)
{
/* Set OUT NAK so that we don't receive anything before the software wants to */
SYS_Write1120P_Register(pc->ioBase, TD1120_DEV_EP_OUT_NAK_SET_REG, \
(1 << epNumber));
return (SCS_SUCCESS);
}
/*------------------------------------------------------------------------------
Name : TD1120P_EpNakClear
Purpose : Clear the endpoint NAK so that it is ready to handle the transaction
Arguments : pc - peripheral controller handle
epNumber - endpoint number
Returns : SctStatus
-----------------------------------------------------------------------------*/
SctStatus TD1120P_EpNakClear(TdiPeriphController* pc, U32 epNumber)
{
/* Clear OUT NAK so that we can receive packets */
SYS_Write1120P_Register(pc->ioBase, TD1120_DEV_EP_OUT_NAK_CLEAR_REG, \
(1 << epNumber));
return (SCS_SUCCESS);
}
/*------------------------------------------------------------------------------
Name : TD1120P_EpErrorsClear
Purpose : Clear the errors on specified endpoint
Arguments : pc - peripheral controller handle
ep - endpoint structure pointer
Returns : SctStatus
-----------------------------------------------------------------------------*/
SctStatus TD1120P_EpErrorsClear(TdiPeriphController* pc, TdiPeriphEp* ep)
{
if (ep == NULL)
{
PRINTF1(("\nTD1120P_EpErrorsClear: Invalid EP handle."));
return SCS_EP_INVALID;
}
/* Nothing to do for TD1120 */
return (SCS_SUCCESS);
}
/*------------------------------------------------------------------------------
Name : TD1120P_ConfigEp
Purpose : Set the endpoint NAK so that it is ready to handle the transaction
Arguments : pc - peripheral controller handle
epNumber - endpoint number
epCommand - set NAK, clear NAK, set Ep Halt, etc
ep - endpoint structure pointer
Returns : SctStatus
-----------------------------------------------------------------------------*/
SctStatus TD1120P_ConfigEp(TdiPeriphController* pc, U32 epNumber, \
U32 epCommand, TdiPeriphEp* ep)
{
SctStatus status = SCS_ERROR;
if (pc == NULL)
{
PRINTF1(("\nTD1120P_ConfigEp: Invalid handle."));
return SCS_ERROR_INVALID_HANDLE;
}
switch (epCommand)
{
case EP_NAK_SET:
status = TD1120P_EpNakSet(pc, epNumber);
break;
case EP_NAK_CLEAR:
status = TD1120P_EpNakClear(pc, epNumber);
break;
case EP_ERRORS_CLEAR:
status = TD1120P_EpErrorsClear(pc, ep);
break;
case EP_HALT_SET:
status = TD1120P_EpHaltSet(pc, ep);
break;
case EP_HALT_CLEAR:
status = TD1120P_EpHaltClear(pc, ep);
break;
case EP_DISABLE:
status = TD1120P_EpDisable(pc, ep);
break;
case EP_ENABLE:
status = TD1120P_EpEnable(pc, ep);
break;
}
return (SCS_SUCCESS);
}
/*------------------------------------------------------------------------------
Name : TD1120P_InitSetupPhase
Purpose : This function will take controller-specific action to receive
a SETUP packet
Arguments : pc - peripheral controller handle
epNumber - endpoint number
setupPacketBuffer - buffer for holding setup packet
Returns : SctStatus
-----------------------------------------------------------------------------*/
SctStatus TD1120P_InitSetupPhase(TdiPeriphController* pc, U32 epNumber, \
U8* setupPacketBuffer)
{
if (pc == NULL)
{
PRINTF1(("\nTD1120P_InitSetupPhase: Invalid handle."));
return SCS_ERROR_INVALID_HANDLE;
}
/* Init the OUT Fifo on specified endpoint. We only need to init for
one packet because SETUP packet is always 8 bytes */
SYS_Write1120P_Register(pc->ioBase, TD1120_DEV_EP_OUT_PKT_COUNT_REG(epNumber), 1);
return (SCS_SUCCESS);
}
/*------------------------------------------------------------------------------
Name : TD1120P_GetSetupPacket
Purpose : Get SETUP packet from the controller
Arguments : pc - peripheral controller handle
epNumber - endpoint number
periphSetupPacket - setup packet
Returns : SctStatus
-----------------------------------------------------------------------------*/
SctStatus TD1120P_GetSetupPacket(TdiPeriphController* pc, U32 epNumber, \
PeriphSetupRequest* periphSetupPacket)
{
if (pc == NULL)
{
PRINTF1(("\nTD1120P_GetSetupPacket: Invalid handle."));
return SCS_ERROR_INVALID_HANDLE;
}
if (pc->ep[epNumber]->type != USB_CONTROL_ENDPOINT)
{
return (SCS_ERROR);
}
/* Set OUT NAK so that we don't receive anything else */
SYS_Write1120P_Register(pc->ioBase, TD1120_DEV_EP_OUT_NAK_SET_REG, \
(1 << epNumber));
/* Unlock the FIFO */
SYS_Write1120P_Register(pc->ioBase, TD1120_DEV_EP_SETUP_RCVD_REG, \
(1 << epNumber));
/* Read setup packet */
TD1120P_Read1120Buffer(pc->ioBase, \
TD1120_DEV_EP_OUT_FIFO_READ(epNumber), epNumber, (U8*)periphSetupPacket, \
USB_SIZE_SETUP_REQUEST);
/* Clear OUT NAK so that we can receive packets */
SYS_Write1120P_Register(pc->ioBase, TD1120_DEV_EP_OUT_NAK_CLEAR_REG, \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -