大家好,我在基于官网CH372Device调程序的时候发现,开启2个中断,一个是TIM8 1ms的中断,另一个是USBHS中断,发现USBHS中断标志USBHS_Endp_Busy 一直为 busy 状态,TIM8定时器的中断会干扰USBHS中断,如果只有USBHS中断的话,程序压测能正常运行,一开启TIM8 1ms中断后,程序运行1~2分钟后,相应端点的USBHS_Endp_Busy 一直为busy,就像USBHS中断丢失了一样,各位大佬有遇到过类似问题吗???。下面是部分代码:
TIM8:
void TIM8_UP_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void TIM8_UP_IRQHandler(void)
{
if(TIM_GetFlagStatus(TIM8, TIM_FLAG_Update) != RESET)
{
TIM_ClearFlag(TIM8, TIM_FLAG_Update);
// ledTimerCnt++;
// if(ledTimerCnt > 500)
// {
// ledTimerCnt = 0;
// led_tongle();
// }
//
PeriodMessagesTimer();
}
}
USBHS:
void USBHS_IRQHandler( void )
{
uint8_t intflag, intst, errflag;
uint16_t len, i;
intflag = USBHSD->INT_FG;
intst = USBHSD->INT_ST;
if( intflag & USBHS_UIF_TRANSFER )
{
switch ( intst & USBHS_UIS_TOKEN_MASK )
{
/* data-in stage processing */
case USBHS_UIS_TOKEN_IN:
switch ( intst & ( USBHS_UIS_TOKEN_MASK | USBHS_UIS_ENDP_MASK ) )
{
/* end-point 0 data in interrupt */
case USBHS_UIS_TOKEN_IN | DEF_UEP0:
if( USBHS_SetupReqLen == 0 )
{
USBHSD->UEP0_RX_CTRL = USBHS_UEP_R_TOG_DATA1 | USBHS_UEP_R_RES_ACK;
}
if ( ( USBHS_SetupReqType & USB_REQ_TYP_MASK ) == USB_REQ_TYP_VENDOR )
{
/* Non-standard request endpoint 0 Data upload */
len = USBHS_SetupReqLen >= DEF_USBD_UEP0_SIZE ? DEF_USBD_UEP0_SIZE : USBHS_SetupReqLen;
memcpy(USBHS_EP0_Buf, pUSBHS_Descr, len);
USBHS_SetupReqLen -= len;
pUSBHS_Descr += len;
USBHSD->UEP0_TX_LEN = len;
USBHSD->UEP0_TX_CTRL ^= USBHS_UEP_T_TOG_DATA1;
}
else if( (USBHS_SetupReqType & USB_REQ_TYP_MASK ) == USB_REQ_TYP_STANDARD)
{
/* Standard request endpoint 0 Data upload */
switch( USBHS_SetupReqCode )
{
case USB_GET_DESCRIPTOR:
len = USBHS_SetupReqLen >= DEF_USBD_UEP0_SIZE ? DEF_USBD_UEP0_SIZE : USBHS_SetupReqLen;
memcpy(USBHS_EP0_Buf, pUSBHS_Descr, len);
USBHS_SetupReqLen -= len;
pUSBHS_Descr += len;
USBHSD->UEP0_TX_LEN = len;
USBHSD->UEP0_TX_CTRL ^= USBHS_UEP_T_TOG_DATA1;
break;
case USB_SET_ADDRESS:
USBHSD->DEV_AD = USBHS_DevAddr;
break;
default:
USBHSD->UEP0_TX_LEN = 0;
break;
}
}
break;
/* end-point 1 data in interrupt */
case USBHS_UIS_TOKEN_IN | DEF_UEP1:
USBHSD->UEP1_TX_CTRL = (USBHSD->UEP1_TX_CTRL & ~USBHS_UEP_T_RES_MASK) | USBHS_UEP_T_RES_NAK;
USBHSD->UEP1_TX_CTRL ^= USBHS_UEP_T_TOG_DATA1;
USBHS_Endp_Busy[ DEF_UEP1 ] &= ~DEF_UEP_BUSY;
break;
/* end-point 2 data in interrupt */
case USBHS_UIS_TOKEN_IN | DEF_UEP2:
USBHSD->UEP2_TX_CTRL = (USBHSD->UEP2_TX_CTRL & ~USBHS_UEP_T_RES_MASK) | USBHS_UEP_T_RES_NAK;
USBHSD->UEP2_TX_CTRL ^= USBHS_UEP_T_TOG_DATA1;
USBHS_Endp_Busy[ DEF_UEP2 ] &= ~DEF_UEP_BUSY;
usb_tx_busy_flag = 0;
break;
/* end-point 3 data in interrupt */
case USBHS_UIS_TOKEN_IN | DEF_UEP3:
USBHSD->UEP3_TX_CTRL = (USBHSD->UEP3_TX_CTRL & ~USBHS_UEP_T_RES_MASK) | USBHS_UEP_T_RES_NAK;
USBHSD->UEP3_TX_CTRL ^= USBHS_UEP_T_TOG_DATA1;
USBHS_Endp_Busy[ DEF_UEP3 ] &= ~DEF_UEP_BUSY;
break;
default :
break;
}
break;
/* data-out stage processing */
case USBHS_UIS_TOKEN_OUT:
switch( intst & ( USBHS_UIS_TOKEN_MASK | USBHS_UIS_ENDP_MASK ) )
{
/* end-point 0 data out interrupt */
case USBHS_UIS_TOKEN_OUT | DEF_UEP0:
len = USBHSH->RX_LEN;
if ( intst & USBHS_UIS_TOG_OK )
{
/* if any processing about rx, set it here */
if ( ( USBHS_SetupReqType & USB_REQ_TYP_MASK ) != USB_REQ_TYP_STANDARD )
{
/* Non-standard request end-point 0 Data download */
}
else
{
/* Standard request end-point 0 Data download */
}
USBHS_SetupReqLen -= len;
if( USBHS_SetupReqLen == 0 )
{
USBHSD->UEP0_TX_LEN = 0;
USBHSD->UEP0_TX_CTRL = USBHS_UEP_T_TOG_DATA1 | USBHS_UEP_T_RES_ACK;
}
}
break;
/* end-point 1 data out interrupt */
case USBHS_UIS_TOKEN_OUT | DEF_UEP1:
if ( intst & USBHS_UIS_TOG_OK )
{
/* Write In Buffer */
uint16_t len;
// len = USBHSD->RX_LEN;
// USB_ProcessRxCmdData(USBHS_EP1_Rx_Buf, len);
// USBHSD->UEP1_RX_CTRL ^= USBHS_UEP_R_TOG_DATA1;
USBHSD->UEP1_RX_CTRL ^= USBHS_UEP_R_TOG_DATA1;
USBHSD->UEP1_RX_CTRL = ((USBHSD->UEP1_RX_CTRL) & ~USBHS_UEP_R_RES_MASK) | USBHS_UEP_R_RES_NAK;
len = USBHSD->RX_LEN;
USBHS_Endp_RxDataLen[DEF_UEP1] = len;
USBHS_Endp_RxDataFlag[DEF_UEP1] = 1;
}
break;
/* end-point 2 data out interrupt */
case USBHS_UIS_TOKEN_OUT | DEF_UEP2:
if ( intst & USBHS_UIS_TOG_OK )
{
// USBHSD->UEP2_RX_CTRL = ((USBHSD->UEP2_RX_CTRL) & ~USBHS_UEP_R_RES_MASK) | USBHS_UEP_R_RES_NAK;
// len = (uint16_t)(USBHSD->RX_LEN);
// USB_ProcessRxData(USBHS_EP2_Rx_Buf, len);
// USBHSD->UEP2_RX_CTRL ^= USBHS_UEP_R_TOG_DATA1;
// USBHSD->UEP2_RX_CTRL = (USBHSD->UEP2_RX_CTRL & ~USBHS_UEP_R_RES_MASK) | USBHS_UEP_R_RES_ACK;
//
USBHSD->UEP2_RX_CTRL = ((USBHSD->UEP2_RX_CTRL) & ~USBHS_UEP_R_RES_MASK) | USBHS_UEP_R_RES_NAK;
USBHSD->UEP2_RX_CTRL ^= USBHS_UEP_R_TOG_DATA1;
len = USBHSD->RX_LEN;
USBHS_Endp_RxDataLen[DEF_UEP2] = len;
USBHS_Endp_RxDataFlag[DEF_UEP2] = 1;
}
break;
/* end-point 3 data out interrupt */
case USBHS_UIS_TOKEN_OUT | DEF_UEP3:
if ( intst & USBHS_UIS_TOG_OK )
{
// USBHSD->UEP3_RX_CTRL = ((USBHSD->UEP3_RX_CTRL) & ~USBHS_UEP_R_RES_MASK) | USBHS_UEP_R_RES_NAK;
// len = (uint16_t)(USBHSD->RX_LEN);
// USBHSD->UEP3_RX_CTRL ^= USBHS_UEP_R_TOG_DATA1;
// USB_ProcessRxData(USBHS_EP3_Rx_Buf, len);
// USBHSD->UEP3_RX_CTRL = (USBHSD->UEP3_RX_CTRL & ~USBHS_UEP_R_RES_MASK) | USBHS_UEP_R_RES_ACK;
USBHSD->UEP3_RX_CTRL = ((USBHSD->UEP3_RX_CTRL) & ~USBHS_UEP_R_RES_MASK) | USBHS_UEP_R_RES_NAK;
USBHSD->UEP3_RX_CTRL ^= USBHS_UEP_R_TOG_DATA1;
len = USBHSD->RX_LEN;
USBHS_Endp_RxDataLen[DEF_UEP3] = len;
USBHS_Endp_RxDataFlag[DEF_UEP3] = 1;
}
break;
default:
errflag = 0xFF;
break;
}
break;
/* Sof pack processing */
case USBHS_UIS_TOKEN_SOF:
break;
default :
break;
}
USBHSD->INT_FG = USBHS_UIF_TRANSFER;
}
else if( intflag & USBHS_UIF_SETUP_ACT )
{
USBHSD->UEP0_TX_CTRL = USBHS_UEP_T_TOG_DATA1 | USBHS_UEP_T_RES_NAK;
USBHSD->UEP0_RX_CTRL = USBHS_UEP_R_TOG_DATA1 | USBHS_UEP_R_RES_NAK;
/* Store All Setup Values */
USBHS_SetupReqType = pUSBHS_SetupReqPak->bRequestType;
USBHS_SetupReqCode = pUSBHS_SetupReqPak->bRequest;
USBHS_SetupReqLen = pUSBHS_SetupReqPak->wLength;
USBHS_SetupReqValue = pUSBHS_SetupReqPak->wValue;
USBHS_SetupReqIndex = pUSBHS_SetupReqPak->wIndex;
len = 0;
errflag = 0;
if ( ( USBHS_SetupReqType & USB_REQ_TYP_MASK ) == USB_REQ_TYP_VENDOR )
{
if(USBHS_SetupReqIndex == 4)
{
pUSBHS_Descr = Extend_Compat_ID;
len = Extend_Compat_ID[0];
/* Copy Descriptors to Endp0 DMA buffer */
if( USBHS_SetupReqLen>len )
{
USBHS_SetupReqLen = len;
}
len = (USBHS_SetupReqLen >= DEF_USBD_UEP0_SIZE) ? DEF_USBD_UEP0_SIZE : USBHS_SetupReqLen;
memcpy( USBHS_EP0_Buf, pUSBHS_Descr, len );
pUSBHS_Descr += len;
}
else if(USBHS_SetupReqIndex == 5)
{
pUSBHS_Descr = Extend_Properties;
len = Extend_Properties[0];
/* Copy Descriptors to Endp0 DMA buffer */
if( USBHS_SetupReqLen>len )
{
USBHS_SetupReqLen = len;
}
len = (USBHS_SetupReqLen >= DEF_USBD_UEP0_SIZE) ? DEF_USBD_UEP0_SIZE : USBHS_SetupReqLen;
memcpy( USBHS_EP0_Buf, pUSBHS_Descr, len );
pUSBHS_Descr += len;
}
else
{
errflag = 0xFF;
}
}
else if( ( USBHS_SetupReqType & USB_REQ_TYP_MASK ) == USB_REQ_TYP_STANDARD )
{
/* usb standard request processing */
switch( USBHS_SetupReqCode )
{
/* get device/configuration/string/report/... descriptors */
case USB_GET_DESCRIPTOR:
switch( (uint8_t)(USBHS_SetupReqValue>>8) )
{
/* get usb device descriptor */
case USB_DESCR_TYP_DEVICE:
pUSBHS_Descr = MyDevDescr;
len = DEF_USBD_DEVICE_DESC_LEN;
break;
/* get usb configuration descriptor */
case USB_DESCR_TYP_CONFIG:
/* Query current usb speed */
if( ( USBHSD->SPEED_TYPE & USBHS_SPEED_TYPE_MASK ) == USBHS_SPEED_HIGH )
{
/* High speed mode */
USBHS_DevSpeed = USBHS_SPEED_HIGH;
USBHS_DevMaxPackLen = DEF_USBD_HS_PACK_SIZE;
}
else
{
/* Full speed mode */
USBHS_DevSpeed = USBHS_SPEED_FULL;
USBHS_DevMaxPackLen = DEF_USBD_FS_PACK_SIZE;
}
/* Load usb configuration descriptor by speed */
if( USBHS_DevSpeed == USBHS_SPEED_HIGH )
{
/* High speed mode */
pUSBHS_Descr = MyCfgDescr_HS;
len = DEF_USBD_CONFIG_HS_DESC_LEN;
}
else
{
/* Full speed mode */
pUSBHS_Descr = MyCfgDescr_FS;
len = DEF_USBD_CONFIG_FS_DESC_LEN;
}
break;
/* get usb string descriptor */
case USB_DESCR_TYP_STRING:
switch( (uint8_t)(USBHS_SetupReqValue&0xFF) )
{
/* Descriptor 0, Language descriptor */
case DEF_STRING_DESC_LANG:
pUSBHS_Descr = MyLangDescr;
len = DEF_USBD_LANG_DESC_LEN;
break;
/* Descriptor 1, Manufacturers String descriptor */
case DEF_STRING_DESC_MANU:
pUSBHS_Descr = MyManuInfo;
len = DEF_USBD_MANU_DESC_LEN;
break;
/* Descriptor 2, Product String descriptor */
case DEF_STRING_DESC_PROD:
pUSBHS_Descr = MyProdInfo;
len = DEF_USBD_PROD_DESC_LEN;
break;
/* Descriptor 3, Serial-number String descriptor */
case DEF_STRING_DESC_SERN:
pUSBHS_Descr = MySerNumInfo;
len = DEF_USBD_SN_DESC_LEN;
break;
case 0xEE:
pUSBHS_Descr = OS_DESC;
len = OS_DESC[0];
break;
default:
errflag = 0xFF;
break;
}
break;
/* get usb device qualify descriptor */
case USB_DESCR_TYP_QUALIF:
pUSBHS_Descr = MyQuaDesc;
len = DEF_USBD_QUALFY_DESC_LEN;
break;
/* get usb BOS descriptor */
case USB_DESCR_TYP_BOS:
/* USB 2.00 DO NOT support BOS descriptor */
errflag = 0xFF;
break;
/* get usb other-speed descriptor */
case USB_DESCR_TYP_SPEED:
if( USBHS_DevSpeed == USBHS_SPEED_HIGH )
{
/* High speed mode */
memcpy( &TAB_USB_HS_OSC_DESC[ 2 ], &MyCfgDescr_FS[ 2 ], DEF_USBD_CONFIG_FS_DESC_LEN - 2 );
pUSBHS_Descr = ( uint8_t * )&TAB_USB_HS_OSC_DESC[ 0 ];
len = DEF_USBD_CONFIG_FS_DESC_LEN;
}
else if( USBHS_DevSpeed == USBHS_SPEED_FULL )
{
/* Full speed mode */
memcpy( &TAB_USB_FS_OSC_DESC[ 2 ], &MyCfgDescr_HS[ 2 ], DEF_USBD_CONFIG_HS_DESC_LEN - 2 );
pUSBHS_Descr = ( uint8_t * )&TAB_USB_FS_OSC_DESC[ 0 ];
len = DEF_USBD_CONFIG_HS_DESC_LEN;
}
else
{
errflag = 0xFF;
}
break;
default :
errflag = 0xFF;
break;
}
/* Copy Descriptors to Endp0 DMA buffer */
if( USBHS_SetupReqLen>len )
{
USBHS_SetupReqLen = len;
}
len = (USBHS_SetupReqLen >= DEF_USBD_UEP0_SIZE) ? DEF_USBD_UEP0_SIZE : USBHS_SetupReqLen;
memcpy( USBHS_EP0_Buf, pUSBHS_Descr, len );
pUSBHS_Descr += len;
break;
/* Set usb address */
case USB_SET_ADDRESS:
USBHS_DevAddr = (uint16_t)(USBHS_SetupReqValue&0xFF);
break;
/* Get usb configuration now set */
case USB_GET_CONFIGURATION:
USBHS_EP0_Buf[0] = USBHS_DevConfig;
if ( USBHS_SetupReqLen > 1 )
{
USBHS_SetupReqLen = 1;
}
break;
/* Set usb configuration to use */
case USB_SET_CONFIGURATION:
USBHS_DevConfig = (uint8_t)(USBHS_SetupReqValue&0xFF);
USBHS_DevEnumStatus = 0x01;
break;
/* Clear or disable one usb feature */
case USB_CLEAR_FEATURE:
if( ( USBHS_SetupReqType & USB_REQ_RECIP_MASK ) == USB_REQ_RECIP_DEVICE )
{
/* clear one device feature */
if((uint8_t)(USBHS_SetupReqValue&0xFF) == 0x01)
{
/* clear usb sleep status, device not prepare to sleep */
USBHS_DevSleepStatus &= ~0x01;
}
else
{
errflag = 0xFF;
}
}
else if ( ( USBHS_SetupReqType & USB_REQ_RECIP_MASK ) == USB_REQ_RECIP_ENDP )
{
/* Set End-point Feature */
if( (uint8_t)(USBHS_SetupReqValue&0xFF) == USB_REQ_FEAT_ENDP_HALT )
{
/* Clear End-point Feature */
switch( (uint8_t)(USBHS_SetupReqIndex&0xFF) )
{
case (DEF_UEP1 | DEF_UEP_OUT):
/* Set End-point 1 OUT ACK */
USBHSD->UEP1_RX_CTRL = USBHS_UEP_R_RES_NAK;
break;
case (DEF_UEP1 | DEF_UEP_IN):
/* Set End-point 2 IN NAK */
USBHSD->UEP1_TX_CTRL = USBHS_UEP_T_RES_NAK;
break;
case (DEF_UEP3 | DEF_UEP_OUT):
/* Set End-point 3 OUT ACK */
USBHSD->UEP3_RX_CTRL = USBHS_UEP_R_RES_NAK;
break;
case (DEF_UEP4 | DEF_UEP_IN):
/* Set End-point 4 IN NAK */
USBHSD->UEP4_TX_CTRL = USBHS_UEP_T_RES_NAK;
break;
case (DEF_UEP5 | DEF_UEP_OUT):
/* Set End-point 5 OUT ACK */
USBHSD->UEP5_RX_CTRL = USBHS_UEP_R_RES_NAK;
break;
case (DEF_UEP6 | DEF_UEP_IN):
/* Set End-point 6 IN NAK */
USBHSD->UEP6_TX_CTRL = USBHS_UEP_T_RES_NAK;
break;
default:
errflag = 0xFF;
break;
}
}
else
{
errflag = 0xFF;
}
}
else
{
errflag = 0xFF;
}
break;
/* set or enable one usb feature */
case USB_SET_FEATURE:
if( ( USBHS_SetupReqType & USB_REQ_RECIP_MASK ) == USB_REQ_RECIP_DEVICE )
{
/* Set Device Feature */
if( (uint8_t)(USBHS_SetupReqValue&0xFF) == USB_REQ_FEAT_REMOTE_WAKEUP )
{
if( MyCfgDescr_FS[ 7 ] & 0x20 )
{
/* Set Wake-up flag, device prepare to sleep */
USBHS_DevSleepStatus |= 0x01;
}
else
{
errflag = 0xFF;
}
}
else
{
errflag = 0xFF;
}
}
else if( ( USBHS_SetupReqType & USB_REQ_RECIP_MASK ) == USB_REQ_RECIP_ENDP )
{
/* Set End-point Feature */
if( (uint8_t)(USBHS_SetupReqValue&0xFF) == USB_REQ_FEAT_ENDP_HALT )
{
/* Set end-points status stall */
switch((uint8_t)(USBHS_SetupReqIndex&0xFF) )
{
case (DEF_UEP1 | DEF_UEP_OUT):
/* Set End-point 1 OUT STALL */
USBHSD->UEP1_RX_CTRL = ( USBHSD->UEP1_RX_CTRL & ~USBHS_UEP_R_RES_MASK ) | USBHS_UEP_R_RES_STALL;
break;
case (DEF_UEP1 | DEF_UEP_IN):
/* Set End-point 1 IN STALL */
USBHSD->UEP1_TX_CTRL = ( USBHSD->UEP1_TX_CTRL & ~USBHS_UEP_T_RES_MASK ) | USBHS_UEP_T_RES_STALL;
break;
case (DEF_UEP3 | DEF_UEP_OUT):
/* Set End-point 3 OUT STALL */
USBHSD->UEP3_RX_CTRL = ( USBHSD->UEP3_RX_CTRL & ~USBHS_UEP_R_RES_MASK ) | USBHS_UEP_R_RES_STALL;
break;
case (DEF_UEP4 | DEF_UEP_IN):
/* Set End-point 4 IN STALL */
USBHSD->UEP4_TX_CTRL = ( USBHSD->UEP4_TX_CTRL & ~USBHS_UEP_T_RES_MASK ) | USBHS_UEP_T_RES_STALL;
break;
case (DEF_UEP5 | DEF_UEP_OUT):
/* Set End-point 5 OUT STALL */
USBHSD->UEP5_RX_CTRL = ( USBHSD->UEP5_RX_CTRL & ~USBHS_UEP_R_RES_MASK ) | USBHS_UEP_R_RES_STALL;
break;
case (DEF_UEP6 | DEF_UEP_IN):
/* Set End-point 6 IN STALL */
USBHSD->UEP6_TX_CTRL = ( USBHSD->UEP6_TX_CTRL & ~USBHS_UEP_T_RES_MASK ) | USBHS_UEP_T_RES_STALL;
break;
default:
errflag = 0xFF;
break;
}
}
}
break;
/* This request allows the host to select another setting for the specified interface */
case USB_GET_INTERFACE:
USBHS_EP0_Buf[0] = 0x00;
if ( USBHS_SetupReqLen > 1 )
{
USBHS_SetupReqLen = 1;
}
break;
case USB_SET_INTERFACE:
break;
/* host get status of specified device/interface/end-points */
case USB_GET_STATUS:
USBHS_EP0_Buf[0] = 0x00;
USBHS_EP0_Buf[1] = 0x00;
if( ( USBHS_SetupReqType & USB_REQ_RECIP_MASK ) == USB_REQ_RECIP_ENDP )
{
switch( (uint8_t)( USBHS_SetupReqIndex & 0xFF ) )
{
case ( DEF_UEP_OUT | DEF_UEP1 ):
if( ( (USBHSD->UEP1_RX_CTRL) & USBHS_UEP_R_RES_MASK ) == USBHS_UEP_R_RES_STALL )
{
USBHS_EP0_Buf[ 0 ] = 0x01;
}
break;
case ( DEF_UEP_IN | DEF_UEP1 ):
if( ( (USBHSD->UEP1_TX_CTRL) & USBHS_UEP_T_RES_MASK ) == USBHS_UEP_T_RES_STALL )
{
USBHS_EP0_Buf[ 0 ] = 0x01;
}
break;
case ( DEF_UEP_OUT | DEF_UEP3 ):
if( ( (USBHSD->UEP3_RX_CTRL) & USBHS_UEP_R_RES_MASK ) == USBHS_UEP_R_RES_STALL )
{
USBHS_EP0_Buf[ 0 ] = 0x01;
}
break;
case ( DEF_UEP_IN | DEF_UEP4 ):
if( ( (USBHSD->UEP4_TX_CTRL) & USBHS_UEP_T_RES_MASK ) == USBHS_UEP_T_RES_STALL )
{
USBHS_EP0_Buf[ 0 ] = 0x01;
}
break;
case ( DEF_UEP_OUT | DEF_UEP5 ):
if( ( (USBHSD->UEP5_RX_CTRL) & USBHS_UEP_R_RES_MASK ) == USBHS_UEP_R_RES_STALL )
{
USBHS_EP0_Buf[ 0 ] = 0x01;
}
break;
case ( DEF_UEP_IN | DEF_UEP6 ):
if( ( (USBHSD->UEP6_TX_CTRL) & USBHS_UEP_T_RES_MASK ) == USBHS_UEP_T_RES_STALL )
{
USBHS_EP0_Buf[ 0 ] = 0x01;
}
break;
default:
errflag = 0xFF;
break;
}
}
else if( ( USBHS_SetupReqType & USB_REQ_RECIP_MASK ) == USB_REQ_RECIP_DEVICE )
{
if( USBHS_DevSleepStatus & 0x01 )
{
USBHS_EP0_Buf[ 0 ] = 0x02;
}
}
if ( USBHS_SetupReqLen > 2 )
{
USBHS_SetupReqLen = 2;
}
break;
default:
errflag = 0xFF;
break;
}
}
else
{
/* usb non-standard request processing */
errflag = 0xFF;
}
/* errflag = 0xFF means a request not support or some errors occurred, else correct */
if( errflag == 0xFF )
{
/* if one request not support, return stall */
USBHSD->UEP0_TX_CTRL = USBHS_UEP_T_TOG_DATA1 | USBHS_UEP_T_RES_STALL;
USBHSD->UEP0_RX_CTRL = USBHS_UEP_R_TOG_DATA1 | USBHS_UEP_R_RES_STALL;
}
else
{
/* end-point 0 data Tx/Rx */
if( USBHS_SetupReqType & DEF_UEP_IN )
{
/* tx */
len = (USBHS_SetupReqLen>DEF_USBD_UEP0_SIZE) ? DEF_USBD_UEP0_SIZE : USBHS_SetupReqLen;
USBHS_SetupReqLen -= len;
USBHSD->UEP0_TX_LEN = len;
USBHSD->UEP0_TX_CTRL = USBHS_UEP_T_TOG_DATA1 | USBHS_UEP_T_RES_ACK;
}
else
{
/* rx */
if( USBHS_SetupReqLen == 0 )
{
USBHSD->UEP0_TX_LEN = 0;
USBHSD->UEP0_TX_CTRL = USBHS_UEP_T_TOG_DATA1 | USBHS_UEP_T_RES_ACK;
}
else
{
USBHSD->UEP0_RX_CTRL = USBHS_UEP_R_TOG_DATA1 | USBHS_UEP_R_RES_ACK;
}
}
}
USBHSD->INT_FG = USBHS_UIF_SETUP_ACT;
}
else if( intflag & USBHS_UIF_BUS_RST )
{
/* usb reset interrupt processing */
USBHS_DevConfig = 0;
USBHS_DevAddr = 0;
USBHS_DevSleepStatus = 0;
USBHS_DevEnumStatus = 0;
USBHSD->DEV_AD = 0;
USBHS_Device_Endp_Init( );
USBHSD->INT_FG = USBHS_UIF_BUS_RST;
}
else if( intflag & USBHS_UIF_SUSPEND )
{
USBHSD->INT_FG = USBHS_UIF_SUSPEND;
/* usb suspend interrupt processing */
if ( USBHSD->MIS_ST & USBHS_UMS_SUSPEND )
{
USBHS_DevSleepStatus |= 0x02;
if( USBHS_DevSleepStatus == 0x03 )
{
/* Handling usb sleep here */
}
}
else
{
USBHS_DevSleepStatus &= ~0x02;
}
}
else
{
/* other interrupts */
USBHSD->INT_FG = intflag;
}
}
部分main代码:
if(USBHS_Endp_RxDataFlag[DEF_UEP1] > 0)
{
USB_ProcessRxCmdData(USBHS_EP1_Rx_Buf, USBHS_Endp_RxDataLen[DEF_UEP1]);
USBHS_Endp_RxDataFlag[DEF_UEP1] = 0;
USBHSD->UEP1_RX_CTRL = (USBHSD->UEP1_RX_CTRL & ~USBHS_UEP_R_RES_MASK) | USBHS_UEP_R_RES_ACK;
}
if(USBHS_Endp_RxDataFlag[DEF_UEP2] > 0)
{
USB_ProcessRxData(USBHS_EP2_Rx_Buf, USBHS_Endp_RxDataLen[DEF_UEP2]);
USBHS_Endp_RxDataFlag[DEF_UEP2] = 0;
USBHSD->UEP2_RX_CTRL = (USBHSD->UEP2_RX_CTRL & ~USBHS_UEP_R_RES_MASK) | USBHS_UEP_R_RES_ACK;
}