/** 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; uint8_t MessagePayload[128]; /* 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: LastTransferLength = 0; while (Endpoint_Read_Stream_LE(MessagePayload, MIN(MessageHeader.TransferSize, sizeof(MessagePayload)), &LastTransferLength) == ENDPOINT_RWSTREAM_IncompleteTransfer) { if (IsTMCBulkOUTReset) break; } Endpoint_ClearOUT(); ProcessSentMessage(MessagePayload, LastTransferLength); break; case TMC_MESSAGEID_DEV_DEP_MSG_IN: Endpoint_ClearOUT(); MessageHeader.TransferSize = GetNextMessage(MessagePayload); MessageHeader.MessageIDSpecific.DeviceOUT.LastMessageTransaction = true; WriteTMCHeader(&MessageHeader); LastTransferLength = 0; while (Endpoint_Write_Stream_LE(MessagePayload, MessageHeader.TransferSize, &LastTransferLength) == ENDPOINT_RWSTREAM_IncompleteTransfer) { if (IsTMCBulkINReset) break; } 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; }
/** 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; }