/******************************************************************************* * Function Name : PCD_EP_Stall * Description : Stall an endpoint. * Input : Endpoint Address. * Output : None * Return : status *******************************************************************************/ uint32_t PCD_EP_Stall (uint8_t ep_addr) { USB_OTG_EP *ep; if ((0x80 & ep_addr) != 0) { ep = PCD_GetInEP(ep_addr & 0x7F); } else { ep = PCD_GetOutEP(ep_addr & 0x7F); } ep->num = ep_addr & 0x7F; ep->is_in = ((ep_addr & 0x80) == 0x80) ? 1 : 0; OTGD_FS_EPSetStall(ep); return (0); }
/******************************************************************************* * Function Name : OTGD_FS_SetEPStatus * Description : Sets the EP Status * Input : - ep: pointer to the EP structure * - Status: new status to be set * Output : None * Return : None *******************************************************************************/ void OTGD_FS_SetEPStatus(USB_OTG_EP *ep, uint32_t Status) { USB_OTG_DEPCTLx_TypeDef depctl; __IO uint32_t *depctl_addr; depctl.d32 = 0; if (ep->is_in == 1) { depctl_addr = &(USB_OTG_FS_regs.DINEPS[ep->num]->DIEPCTLx); } else { depctl_addr = &(USB_OTG_FS_regs.DOUTEPS[ep->num]->DOEPCTLx); } depctl.d32 = USB_OTG_READ_REG32(depctl_addr); /* Process for IN endpoint */ if (ep->is_in == 1) { if (Status == DEV_EP_TX_STALL) { OTGD_FS_EPSetStall(ep); return; } else if (Status == DEV_EP_TX_NAK) depctl.b.snak = 1; else if (Status == DEV_EP_TX_VALID) { if (depctl.b.stall == 1) { ep->even_odd_frame = 0; OTGD_FS_EPClearStall(ep); return; } depctl.b.cnak = 1; depctl.b.usbactep = 1; depctl.b.epena = 1; } else if (Status == DEV_EP_TX_DIS) depctl.b.usbactep = 0; } else /* Process for OUT endpoint */ { if (Status == DEV_EP_RX_STALL) { depctl.b.stall = 1; } else if (Status == DEV_EP_RX_NAK) depctl.b.snak = 1; else if (Status == DEV_EP_RX_VALID) { if (depctl.b.stall == 1) { ep->even_odd_frame = 0; OTGD_FS_EPClearStall(ep); return; } depctl.b.cnak = 1; depctl.b.usbactep = 1; depctl.b.epena = 1; } else if (Status == DEV_EP_RX_DIS) { depctl.b.usbactep = 0; } } USB_OTG_WRITE_REG32(depctl_addr, depctl.d32); }
/******************************************************************************* * Function Name : OTGD_FS_Dev_SetEPStatus * Description : Sets the EP Status * Input : - ep: pointer to the EP structure * - Status: new status to be set * Output : None * Return : None *******************************************************************************/ void OTGD_FS_Dev_SetEPStatus(USB_OTG_EP *ep, uint32_t Status) { USB_OTG_dev_ep_ctl_data depctl; __IO uint32_t *depctl_addr; if (ep->is_in == 1) { depctl_addr = &(core_regs.inep_regs[ep->num]->dev_in_ep_ctl); } else { depctl_addr = &(core_regs.outep_regs[ep->num]->dev_out_ep_ctl); } depctl.d32 = READ_REG32(depctl_addr); /* Process for IN endpoint */ if (ep->is_in == 1) { if (Status == DEV_EP_TX_STALL) { OTGD_FS_EPSetStall(ep); return; } else if (Status == DEV_EP_TX_NAK) depctl.b.snak = 1; else if (Status == DEV_EP_TX_VALID) { if (depctl.b.stall == 1) { ep->even_odd_frame = 0; OTGD_FS_EPClearStall(ep); return; } depctl.b.cnak = 1; depctl.b.usbactep = 1; depctl.b.epena = 1; } else if (Status == DEV_EP_TX_DIS) depctl.b.usbactep = 0; } else /* Process for OUT endpoint */ { if (Status == DEV_EP_RX_STALL) depctl.b.stall = 1; else if (Status == DEV_EP_RX_NAK) depctl.b.snak = 1; else if (Status == DEV_EP_RX_VALID) { if (depctl.b.stall == 1) { ep->even_odd_frame = 0; OTGD_FS_EPClearStall(ep); return; } depctl.b.cnak = 1; depctl.b.usbactep = 1; depctl.b.epena = 1; } else if (Status == DEV_EP_RX_DIS) { depctl.b.usbactep = 0; } } if (ep->type == EP_TYPE_INTR || ep->type == EP_TYPE_BULK) { depctl.b.setd0pid = 1; /* DATA0 */ } WRITE_REG32(depctl_addr, depctl.d32); }