void handle_usb(u32 clkn) { u8 epstat; /* write queued packets to USB if possible */ epstat = USBHwEPGetStatus(BULK_IN_EP); if (!(epstat & EPSTAT_B1FULL)) { dequeue_send(clkn); } if (!(epstat & EPSTAT_B2FULL)) { dequeue_send(clkn); } /* polled "interrupt" */ USBHwISR(); }
/** Local function to handle a standard endpoint request @param [in] pSetup The setup packet @param [in,out] *piLen Pointer to data length @param [in] ppbData Data buffer. @return TRUE if the request was handled successfully */ static int HandleStdEndPointReq(TSetupPacket *pSetup, int *piLen, unsigned char **ppbData) { unsigned char *pbData = *ppbData; switch (pSetup->bRequest) { case REQ_GET_STATUS: // bit 0 = endpointed halted or not pbData[0] = (USBHwEPGetStatus(pSetup->wIndex) & EP_STATUS_STALLED) ? 1 : 0; pbData[1] = 0; *piLen = 2; break; case REQ_CLEAR_FEATURE: if (pSetup->wValue == FEA_ENDPOINT_HALT) { // clear HALT by unstalling USBHwEPStall(pSetup->wIndex, FALSE); break; } // only ENDPOINT_HALT defined for endpoints return FALSE; case REQ_SET_FEATURE: if (pSetup->wValue == FEA_ENDPOINT_HALT) { // set HALT by stalling USBHwEPStall(pSetup->wIndex, TRUE); break; } // only ENDPOINT_HALT defined for endpoints return FALSE; case REQ_SYNCH_FRAME: DBG("EP req %d not implemented\n", pSetup->bRequest); return FALSE; default: DBG("Illegal EP req %d\n", pSetup->bRequest); return FALSE; } return TRUE; }