+ \r
+ /* All pending data has been processed - reset the data abort flags */\r
+ IsTMCBulkINReset = false;\r
+ IsTMCBulkOUTReset = false;\r
+}\r
+\r
+/** Attempts to read in the TMC message header from the TMC interface.\r
+ *\r
+ * \param[out] MessageHeader Pointer to a location where the read header (if any) should be stored\r
+ *\r
+ * \return Boolean true if a header was read, false otherwise\r
+ */\r
+bool ReadTMCHeader(TMC_MessageHeader_t* const MessageHeader)\r
+{\r
+ /* Select the Data Out endpoint */\r
+ Endpoint_SelectEndpoint(TMC_OUT_EPNUM);\r
+ \r
+ /* Abort if no command has been sent from the host */\r
+ if (!(Endpoint_IsOUTReceived()))\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
+\r
+ /* Store the new command tag value for later use */\r
+ CurrentTransferTag = MessageHeader->Tag;\r
+ \r
+ /* Indicate if the command has been aborted or not */\r
+ return !(IsTMCBulkOUTReset);\r
+}\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
+\r
+ /* Set the message tag of the command header */\r
+ MessageHeader->Tag = CurrentTransferTag;\r
+ MessageHeader->InverseTag = ~CurrentTransferTag;\r
+\r
+ /* Select the Data In endpoint */\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
+\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