/** Last used tag value for data transfers */\r
uint8_t CurrentTransferTag = 0;\r
\r
+/** Length of last data transfer, for reporting to the host in case an in-progress tranfer is aborted */\r
+uint32_t LastTransferLength = 0;\r
\r
/** Main program entry point. This routine contains the overall program flow, including initial\r
* setup of all components and the main program loop.\r
/* Write the request response bytes */\r
Endpoint_Write_Byte(TMCRequestStatus);\r
Endpoint_Write_Word_LE(0);\r
- Endpoint_Write_DWord_LE(0); // TODO - Last transfer length\r
+ Endpoint_Write_DWord_LE(LastTransferLength);\r
\r
Endpoint_ClearIN();\r
Endpoint_ClearStatusStage(); \r
/* Write the request response bytes */\r
Endpoint_Write_Byte(TMCRequestStatus);\r
Endpoint_Write_Word_LE(0);\r
- Endpoint_Write_DWord_LE(0); // TODO - Last transfer length\r
+ Endpoint_Write_DWord_LE(LastTransferLength);\r
\r
Endpoint_ClearIN();\r
Endpoint_ClearStatusStage();\r
return;\r
\r
TMC_MessageHeader_t MessageHeader;\r
+ uint16_t BytesTransferred;\r
\r
/* Try to read in a TMC message from the interface, process if one is available */\r
if (ReadTMCHeader(&MessageHeader))\r
switch (MessageHeader.MessageID)\r
{\r
case TMC_MESSAGEID_DEV_DEP_MSG_OUT:\r
- Endpoint_Discard_Stream(MessageHeader.TransferSize, StreamCallback_AbortOUTOnRequest);\r
+ BytesTransferred = 0;\r
+ while (Endpoint_Discard_Stream(MessageHeader.TransferSize, &BytesTransferred) ==\r
+ ENDPOINT_RWSTREAM_IncompleteTransfer)\r
+ {\r
+ if (IsTMCBulkOUTReset)\r
+ break;\r
+ }\r
+ LastTransferLength = BytesTransferred;\r
+ \r
Endpoint_ClearOUT();\r
break;\r
case TMC_MESSAGEID_DEV_DEP_MSG_IN:\r
Endpoint_ClearOUT();\r
\r
MessageHeader.TransferSize = 3;\r
+ MessageHeader.MessageIDSpecific.DeviceOUT.LastMessageTransaction = true;\r
WriteTMCHeader(&MessageHeader);\r
\r
- Endpoint_Write_Stream_LE("TMC", 3, StreamCallback_AbortINOnRequest);\r
+ BytesTransferred = 0;\r
+ while (Endpoint_Write_Stream_LE("TMC", MessageHeader.TransferSize, &BytesTransferred) ==\r
+ ENDPOINT_RWSTREAM_IncompleteTransfer)\r
+ {\r
+ if (IsTMCBulkINReset)\r
+ break;\r
+ }\r
+ LastTransferLength = BytesTransferred;\r
+\r
Endpoint_ClearIN();\r
break;\r
default:\r
*/\r
bool ReadTMCHeader(TMC_MessageHeader_t* const MessageHeader)\r
{\r
+ uint16_t BytesTransferred;\r
+\r
/* Select the Data Out endpoint */\r
Endpoint_SelectEndpoint(TMC_OUT_EPNUM);\r
\r
return false;\r
\r
/* Read in the header of the command from the host */\r
- Endpoint_Read_Stream_LE(MessageHeader, sizeof(TMC_MessageHeader_t), StreamCallback_AbortOUTOnRequest);\r
+ BytesTransferred = 0;\r
+ while (Endpoint_Read_Stream_LE(MessageHeader, sizeof(TMC_MessageHeader_t), &BytesTransferred) ==\r
+ ENDPOINT_RWSTREAM_IncompleteTransfer)\r
+ {\r
+ if (IsTMCBulkOUTReset)\r
+ break;\r
+ }\r
\r
/* Store the new command tag value for later use */\r
CurrentTransferTag = MessageHeader->Tag;\r
\r
bool WriteTMCHeader(TMC_MessageHeader_t* const MessageHeader)\r
{\r
- /* Compute the next transfer tag value, must be between 1 and 254 */\r
- if (++CurrentTransferTag == 0xFF)\r
- CurrentTransferTag = 1;\r
+ uint16_t BytesTransferred;\r
\r
/* Set the message tag of the command header */\r
MessageHeader->Tag = CurrentTransferTag;\r
Endpoint_SelectEndpoint(TMC_IN_EPNUM);\r
\r
/* Send the command header to the host */\r
- Endpoint_Write_Stream_LE(MessageHeader, sizeof(TMC_MessageHeader_t), StreamCallback_AbortINOnRequest);\r
+ BytesTransferred = 0;\r
+ while (Endpoint_Write_Stream_LE(MessageHeader, sizeof(TMC_MessageHeader_t), &BytesTransferred) ==\r
+ ENDPOINT_RWSTREAM_IncompleteTransfer)\r
+ {\r
+ if (IsTMCBulkINReset)\r
+ break;\r
+ }\r
\r
/* Indicate if the command has been aborted or not */\r
return !(IsTMCBulkINReset);\r
}\r
-\r
-/** Stream callback function for the Endpoint stream write functions. This callback will abort the current stream transfer\r
- * if a TMC Abort Bulk IN request has been issued to the control endpoint.\r
- */\r
-uint8_t StreamCallback_AbortINOnRequest(void)\r
-{ \r
- /* Abort if a TMC Bulk Data IN abort was received */\r
- if (IsTMCBulkINReset)\r
- return STREAMCALLBACK_Abort;\r
- \r
- /* Continue with the current stream operation */\r
- return STREAMCALLBACK_Continue;\r
-}\r
-\r
-/** Stream callback function for the Endpoint stream read functions. This callback will abort the current stream transfer\r
- * if a TMC Abort Bulk OUT request has been issued to the control endpoint.\r
- */\r
-uint8_t StreamCallback_AbortOUTOnRequest(void)\r
-{ \r
- /* Abort if a TMC Bulk Data IN abort was received */\r
- if (IsTMCBulkOUTReset)\r
- return STREAMCALLBACK_Abort;\r
- \r
- /* Continue with the current stream operation */\r
- return STREAMCALLBACK_Continue;\r
-}\r
-