X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/f555ad7ced743a19eb1eefaf5eaf536fcbe58d80..77a9df36a77d2523dd2bc24fa17f9f04c6c175c5:/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c diff --git a/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c b/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c index 3c5cf47d5..08c50c736 100644 --- a/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c +++ b/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c @@ -53,19 +53,19 @@ TMC_Capabilities_t Capabilities = }; /** Current TMC control request that is being processed */ -uint8_t RequestInProgress = 0; +static uint8_t RequestInProgress = 0; /** Stream callback abort flag for bulk IN data */ -bool IsTMCBulkINReset = false; +static bool IsTMCBulkINReset = false; /** Stream callback abort flag for bulk OUT data */ -bool IsTMCBulkOUTReset = false; +static bool IsTMCBulkOUTReset = false; /** Last used tag value for data transfers */ -uint8_t CurrentTransferTag = 0; +static uint8_t CurrentTransferTag = 0; -/** Length of last data transfer, for reporting to the host in case an in-progress tranfer is aborted */ -uint32_t LastTransferLength = 0; +/** Length of last data transfer, for reporting to the host in case an in-progress transfer is aborted */ +static uint32_t LastTransferLength = 0; /** Main program entry point. This routine contains the overall program flow, including initial * setup of all components and the main program loop. @@ -169,7 +169,7 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearSETUP(); /* Write the request response byte */ - Endpoint_Write_Byte(TMCRequestStatus); + Endpoint_Write_8(TMCRequestStatus); Endpoint_ClearIN(); Endpoint_ClearStatusStage(); @@ -190,9 +190,9 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearSETUP(); /* Write the request response bytes */ - Endpoint_Write_Byte(TMCRequestStatus); - Endpoint_Write_Word_LE(0); - Endpoint_Write_DWord_LE(LastTransferLength); + Endpoint_Write_8(TMCRequestStatus); + Endpoint_Write_16_LE(0); + Endpoint_Write_32_LE(LastTransferLength); Endpoint_ClearIN(); Endpoint_ClearStatusStage(); @@ -223,8 +223,8 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearSETUP(); /* Write the request response bytes */ - Endpoint_Write_Byte(TMCRequestStatus); - Endpoint_Write_Byte(CurrentTransferTag); + Endpoint_Write_8(TMCRequestStatus); + Endpoint_Write_8(CurrentTransferTag); Endpoint_ClearIN(); Endpoint_ClearStatusStage(); @@ -245,9 +245,9 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearSETUP(); /* Write the request response bytes */ - Endpoint_Write_Byte(TMCRequestStatus); - Endpoint_Write_Word_LE(0); - Endpoint_Write_DWord_LE(LastTransferLength); + Endpoint_Write_8(TMCRequestStatus); + Endpoint_Write_16_LE(0); + Endpoint_Write_32_LE(LastTransferLength); Endpoint_ClearIN(); Endpoint_ClearStatusStage(); @@ -260,7 +260,7 @@ void EVENT_USB_Device_ControlRequest(void) /* Check that no split transaction is already in progress */ if (RequestInProgress != 0) { - Endpoint_Write_Byte(TMC_STATUS_SPLIT_IN_PROGRESS); + Endpoint_Write_8(TMC_STATUS_SPLIT_IN_PROGRESS); } else { @@ -275,7 +275,7 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearSETUP(); /* Write the request response byte */ - Endpoint_Write_Byte(TMCRequestStatus); + Endpoint_Write_8(TMCRequestStatus); Endpoint_ClearIN(); Endpoint_ClearStatusStage(); @@ -296,8 +296,8 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearSETUP(); /* Write the request response bytes */ - Endpoint_Write_Byte(TMCRequestStatus); - Endpoint_Write_Byte(0); + Endpoint_Write_8(TMCRequestStatus); + Endpoint_Write_8(0); Endpoint_ClearIN(); Endpoint_ClearStatusStage(); @@ -350,13 +350,15 @@ void TMC_Task(void) break; case TMC_MESSAGEID_DEV_DEP_MSG_IN: Endpoint_ClearOUT(); + + char MessageData[] = "TMC Class Test"; - MessageHeader.TransferSize = 3; + MessageHeader.TransferSize = strlen(MessageData); MessageHeader.MessageIDSpecific.DeviceOUT.LastMessageTransaction = true; WriteTMCHeader(&MessageHeader); BytesTransferred = 0; - while (Endpoint_Write_Stream_LE("TMC", MessageHeader.TransferSize, &BytesTransferred) == + while (Endpoint_Write_Stream_LE(MessageData, MessageHeader.TransferSize, &BytesTransferred) == ENDPOINT_RWSTREAM_IncompleteTransfer) { if (IsTMCBulkINReset) @@ -388,6 +390,7 @@ void TMC_Task(void) bool ReadTMCHeader(TMC_MessageHeader_t* const MessageHeader) { uint16_t BytesTransferred; + uint8_t ErrorCode; /* Select the Data Out endpoint */ Endpoint_SelectEndpoint(TMC_OUT_EPNUM); @@ -398,7 +401,7 @@ bool ReadTMCHeader(TMC_MessageHeader_t* const MessageHeader) /* Read in the header of the command from the host */ BytesTransferred = 0; - while (Endpoint_Read_Stream_LE(MessageHeader, sizeof(TMC_MessageHeader_t), &BytesTransferred) == + while ((ErrorCode = Endpoint_Read_Stream_LE(MessageHeader, sizeof(TMC_MessageHeader_t), &BytesTransferred)) == ENDPOINT_RWSTREAM_IncompleteTransfer) { if (IsTMCBulkOUTReset) @@ -409,12 +412,13 @@ bool ReadTMCHeader(TMC_MessageHeader_t* const MessageHeader) CurrentTransferTag = MessageHeader->Tag; /* Indicate if the command has been aborted or not */ - return !(IsTMCBulkOUTReset); + return (!(IsTMCBulkOUTReset) && (ErrorCode == ENDPOINT_RWSTREAM_NoError)); } bool WriteTMCHeader(TMC_MessageHeader_t* const MessageHeader) { uint16_t BytesTransferred; + uint8_t ErrorCode; /* Set the message tag of the command header */ MessageHeader->Tag = CurrentTransferTag; @@ -425,7 +429,7 @@ bool WriteTMCHeader(TMC_MessageHeader_t* const MessageHeader) /* Send the command header to the host */ BytesTransferred = 0; - while (Endpoint_Write_Stream_LE(MessageHeader, sizeof(TMC_MessageHeader_t), &BytesTransferred) == + while ((ErrorCode = Endpoint_Write_Stream_LE(MessageHeader, sizeof(TMC_MessageHeader_t), &BytesTransferred)) == ENDPOINT_RWSTREAM_IncompleteTransfer) { if (IsTMCBulkINReset) @@ -433,5 +437,5 @@ bool WriteTMCHeader(TMC_MessageHeader_t* const MessageHeader) } /* Indicate if the command has been aborted or not */ - return !(IsTMCBulkINReset); + return (!(IsTMCBulkINReset) && (ErrorCode == ENDPOINT_RWSTREAM_NoError)); }