void JIG_Task(void) { static int bytes_out = 0, bytes_in = 0; Endpoint_SelectEndpoint(2); if (Endpoint_IsReadWriteAllowed()) { Endpoint_Discard_Stream(8, NO_STREAM_CALLBACK); Endpoint_ClearOUT(); bytes_out += 8; if (bytes_out >= 64) { state = p5_challenged; expire = 50; // was 90 } } Endpoint_SelectEndpoint(1); if (Endpoint_IsReadWriteAllowed() && state == p5_challenged && expire == 0) { if (bytes_in < 64) { Endpoint_Write_PStream_LE(&jig_response[bytes_in], 8, NO_STREAM_CALLBACK); Endpoint_ClearIN(); bytes_in += 8; if (bytes_in >= 64) { state = p5_responded; expire = 15; } } } }
void usbIoDone(void) { // Finalize any outstanding transactions if (usbDataDir == ENDPOINT_DIR_IN) { /* * If the transfer left an incomplete endpoint (mod endpoint size) * or possibly never transferred any data (error or timeout case), * flush the buffer back to the host. */ if (Endpoint_BytesInEndpoint() != 0 || usbDataLen != 0) { Endpoint_ClearIN(); } } else if (usbDataDir == ENDPOINT_DIR_OUT) { /* * If we didn't consume all data from the host, then discard it now. * Just clearing the endpoint (below) works fine if the remaining * data is less than the endpoint size, but would leave data in * the buffer if there was more. */ if (usbDataLen != 0) Endpoint_Discard_Stream(usbDataLen, AbortOnReset); /* * Request another buffer from the host. If it has one, it will * be ready when we start the next transfer. */ if (!Endpoint_IsReadWriteAllowed()) Endpoint_ClearOUT(); } else { DEBUGF(DBG_ERROR, "done: bad io dir %d\n", usbDataDir); } usbDataDir = XUM_DATA_DIR_NONE; usbDataLen = 0; }
/** Function to manage TMC data transmission and reception to and from the host. */ void TMC_Task(void) { /* Device must be connected and configured for the task to run */ if (USB_DeviceState != DEVICE_STATE_Configured) return; TMC_MessageHeader_t MessageHeader; uint16_t BytesTransferred; /* Try to read in a TMC message from the interface, process if one is available */ if (ReadTMCHeader(&MessageHeader)) { /* Indicate busy */ LEDs_SetAllLEDs(LEDMASK_USB_BUSY); switch (MessageHeader.MessageID) { case TMC_MESSAGEID_DEV_DEP_MSG_OUT: BytesTransferred = 0; while (Endpoint_Discard_Stream(MessageHeader.TransferSize, &BytesTransferred) == ENDPOINT_RWSTREAM_IncompleteTransfer) { if (IsTMCBulkOUTReset) break; } LastTransferLength = BytesTransferred; Endpoint_ClearOUT(); break; case TMC_MESSAGEID_DEV_DEP_MSG_IN: Endpoint_ClearOUT(); MessageHeader.TransferSize = 3; MessageHeader.MessageIDSpecific.DeviceOUT.LastMessageTransaction = true; WriteTMCHeader(&MessageHeader); BytesTransferred = 0; while (Endpoint_Write_Stream_LE("TMC", MessageHeader.TransferSize, &BytesTransferred) == ENDPOINT_RWSTREAM_IncompleteTransfer) { if (IsTMCBulkINReset) break; } LastTransferLength = BytesTransferred; Endpoint_ClearIN(); break; default: Endpoint_StallTransaction(); break; } LEDs_SetAllLEDs(LEDMASK_USB_READY); } /* All pending data has been processed - reset the data abort flags */ IsTMCBulkINReset = false; IsTMCBulkOUTReset = false; }
bool SideShow_AddSimpleContent(SideShow_PacketHeader_t* const PacketHeader, SideShow_Application_t* const Application) { uint32_t ContentSize; uint32_t ContentID; Endpoint_Read_Stream_LE(&ContentID, sizeof(uint32_t), NULL); PacketHeader->Length -= sizeof(uint32_t); if (Application->CurrentContentID != ContentID) { Endpoint_Discard_Stream(PacketHeader->Length, NULL); return false; } Endpoint_Read_Stream_LE(&ContentSize, sizeof(uint32_t), NULL); Endpoint_Read_Stream_LE(&Application->CurrentContent, (sizeof(XML_START_TAG) - 1), NULL); PacketHeader->Length -= sizeof(uint32_t) + (sizeof(XML_START_TAG) - 1); if (!(memcmp(&Application->CurrentContent, XML_START_TAG, (sizeof(XML_START_TAG) - 1)))) { SideShow_ProcessXMLContent(&Application->CurrentContent, (ContentSize - (sizeof(XML_END_TAG) - 1))); Endpoint_Discard_Stream((sizeof(XML_END_TAG) - 1), NULL); Application->HaveContent = true; } else { printf(" BINARY"); Endpoint_Discard_Stream(ContentSize, NULL); } return true; }
/** Function to manage TMC data transmission and reception to and from the host. */ void TMC_Task(void) { /* Device must be connected and configured for the task to run */ if (USB_DeviceState != DEVICE_STATE_Configured) return; TMC_MessageHeader_t MessageHeader; /* Try to read in a TMC message from the interface, process if one is available */ if (ReadTMCHeader(&MessageHeader)) { /* Indicate busy */ LEDs_SetAllLEDs(LEDMASK_USB_BUSY); switch (MessageHeader.MessageID) { case TMC_MESSAGEID_DEV_DEP_MSG_OUT: Endpoint_Discard_Stream(MessageHeader.TransferSize, StreamCallback_AbortOUTOnRequest); Endpoint_ClearOUT(); break; case TMC_MESSAGEID_DEV_DEP_MSG_IN: Endpoint_ClearOUT(); MessageHeader.TransferSize = 3; WriteTMCHeader(&MessageHeader); Endpoint_Write_Stream_LE("TMC", 3, StreamCallback_AbortINOnRequest); Endpoint_ClearIN(); break; default: Endpoint_StallTransaction(); break; } LEDs_SetAllLEDs(LEDMASK_USB_READY); } /* All pending data has been processed - reset the data abort flags */ IsTMCBulkINReset = false; IsTMCBulkOUTReset = false; }
static void SideShow_ProcessXMLContent(void* ContentData, uint32_t ContentSize) { printf(" XML"); Endpoint_Discard_Stream(ContentSize, NULL); }