\r
/* Succeed the command and update the bytes transferred counter */\r
MSInterfaceInfo->State.CommandBlock.DataTransferLength = 0;\r
- \r
- return;\r
}\r
\r
/** Command processing for an issued SCSI READ (10) or WRITE (10) command. This command reads in the block start address\r
uint32_t BlockAddress;\r
uint16_t TotalBlocks;\r
\r
- /* Load in the 32-bit block address (SCSI uses big-endian, so have to do it byte-by-byte) */\r
- ((uint8_t*)&BlockAddress)[3] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[2];\r
- ((uint8_t*)&BlockAddress)[2] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[3];\r
- ((uint8_t*)&BlockAddress)[1] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[4];\r
- ((uint8_t*)&BlockAddress)[0] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[5];\r
+ /* Load in the 32-bit block address (SCSI uses big-endian, so have to reverse the byte order) */\r
+ BlockAddress = SwapEndian_32(*(uint32_t*)&MSInterfaceInfo->State.CommandBlock.SCSICommandData[2]);\r
\r
- /* Load in the 16-bit total blocks (SCSI uses big-endian, so have to do it byte-by-byte) */\r
- ((uint8_t*)&TotalBlocks)[1] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[7];\r
- ((uint8_t*)&TotalBlocks)[0] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[8];\r
+ /* Load in the 16-bit total blocks (SCSI uses big-endian, so have to reverse the byte order) */\r
+ TotalBlocks = SwapEndian_16(*(uint32_t*)&MSInterfaceInfo->State.CommandBlock.SCSICommandData[7]);\r
\r
/* Check if the block address is outside the maximum allowable value for the LUN */\r
if (BlockAddress >= LUN_MEDIA_BLOCKS)\r
\r
/* Update the bytes transferred counter and succeed the command */\r
MSInterfaceInfo->State.CommandBlock.DataTransferLength -= ((uint32_t)TotalBlocks * VIRTUAL_MEMORY_BLOCK_SIZE);\r
- \r
- return;\r
}\r
Endpoint_ClearSETUP();\r
\r
/* Indicate that the current transfer should be aborted */\r
- IsMassStoreReset = true; \r
+ IsMassStoreReset = true;\r
\r
Endpoint_ClearStatusStage();\r
}\r
\r
/* Return command status block to the host */\r
ReturnCommandStatus();\r
- \r
- /* Check if a Mass Storage Reset occurred */\r
- if (IsMassStoreReset)\r
- {\r
- /* Reset the data endpoint banks */\r
- Endpoint_ResetFIFO(MASS_STORAGE_OUT_EPNUM);\r
- Endpoint_ResetFIFO(MASS_STORAGE_IN_EPNUM);\r
- \r
- Endpoint_SelectEndpoint(MASS_STORAGE_OUT_EPNUM);\r
- Endpoint_ClearStall();\r
- Endpoint_SelectEndpoint(MASS_STORAGE_IN_EPNUM);\r
- Endpoint_ClearStall();\r
- }\r
\r
/* Indicate ready */\r
LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
}\r
}\r
\r
- /* Clear the abort transfer flag */\r
- IsMassStoreReset = false;\r
+ /* Check if a Mass Storage Reset occurred */\r
+ if (IsMassStoreReset)\r
+ {\r
+ /* Reset the data endpoint banks */\r
+ Endpoint_ResetFIFO(MASS_STORAGE_OUT_EPNUM);\r
+ Endpoint_ResetFIFO(MASS_STORAGE_IN_EPNUM);\r
+ \r
+ Endpoint_SelectEndpoint(MASS_STORAGE_OUT_EPNUM);\r
+ Endpoint_ClearStall();\r
+ Endpoint_ResetDataToggle();\r
+ Endpoint_SelectEndpoint(MASS_STORAGE_IN_EPNUM);\r
+ Endpoint_ClearStall();\r
+ Endpoint_ResetDataToggle();\r
+\r
+ /* Clear the abort transfer flag */\r
+ IsMassStoreReset = false;\r
+ }\r
}\r
\r
/** Function to read in a command block from the host, via the bulk data OUT endpoint. This function reads in the next command block\r
*\r
* \param[in] ReportOUTData Buffer containing the report to send to the device\r
* \param[in] ReportIndex Index of the report in the device (zero if the device does not use multiple reports)\r
- * \param[in] ReportType Type of report to send, either HID_REPORTTYPE_OUTPUT or HID_REPORTTYPE_FEATURE\r
+ * \param[in] ReportType Type of report to send, either REPORT_ITEM_TYPE_Out or REPORT_ITEM_TYPE_Feature\r
* \param[in] ReportLength Length of the report to send\r
*/\r
void WriteNextReport(uint8_t* ReportOUTData, uint8_t ReportIndex, uint8_t ReportType, uint16_t ReportLength)\r
{\r
- /* Select and unfreeze HID data OUT pipe */\r
+ /* Select the HID data OUT pipe */\r
Pipe_SelectPipe(HID_DATA_OUT_PIPE);\r
\r
/* Not all HID devices have an OUT endpoint (some require OUT reports to be sent over the\r
\r
/** HID Class specific request to send a HID report to the device. */\r
#define REQ_SetReport 0x09\r
- \r
- /** HID Report type specifier, for output reports to a device */\r
- #define HID_REPORTTYPE_OUTPUT 0x02\r
- \r
- /** HID Report type specifier, for feature reports to a device */\r
- #define HID_REPORTTYPE_FEATURE 0x03\r
\r
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */\r
#define LEDMASK_USB_NOTREADY LEDS_LED1\r
#define INCLUDE_FROM_MS_CLASS_DEVICE_C\r
#include "MassStorage.h"\r
\r
-static USB_ClassInfo_MS_Device_t* CallbackMSInterfaceInfo;\r
+static volatile bool* CallbackIsResetSource;\r
\r
void MS_Device_ProcessControlRequest(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)\r
{\r
\r
Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataOUTEndpointNumber);\r
Endpoint_ClearStall();\r
+ Endpoint_ResetDataToggle();\r
Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataINEndpointNumber);\r
Endpoint_ClearStall();\r
+ Endpoint_ResetDataToggle();\r
\r
MSInterfaceInfo->State.IsMassStoreReset = false;\r
}\r
{\r
Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataOUTEndpointNumber);\r
\r
- CallbackMSInterfaceInfo = MSInterfaceInfo;\r
- Endpoint_Read_Stream_LE(&MSInterfaceInfo->State.CommandBlock,\r
- (sizeof(MS_CommandBlockWrapper_t) - 16),\r
- StreamCallback_MS_Device_AbortOnMassStoreReset);\r
-\r
+ CallbackIsResetSource = &MSInterfaceInfo->State.IsMassStoreReset;\r
+ if (Endpoint_Read_Stream_LE(&MSInterfaceInfo->State.CommandBlock,\r
+ (sizeof(MS_CommandBlockWrapper_t) - 16),\r
+ StreamCallback_MS_Device_AbortOnMassStoreReset))\r
+ {\r
+ return false;\r
+ }\r
+ \r
if ((MSInterfaceInfo->State.CommandBlock.Signature != MS_CBW_SIGNATURE) ||\r
(MSInterfaceInfo->State.CommandBlock.LUN >= MSInterfaceInfo->Config.TotalLUNs) ||\r
(MSInterfaceInfo->State.CommandBlock.Flags & 0x1F) ||\r
return false;\r
}\r
\r
- CallbackMSInterfaceInfo = MSInterfaceInfo;\r
- Endpoint_Read_Stream_LE(&MSInterfaceInfo->State.CommandBlock.SCSICommandData,\r
- MSInterfaceInfo->State.CommandBlock.SCSICommandLength,\r
- StreamCallback_MS_Device_AbortOnMassStoreReset);\r
- \r
+ CallbackIsResetSource = &MSInterfaceInfo->State.IsMassStoreReset;\r
+ if (Endpoint_Read_Stream_LE(&MSInterfaceInfo->State.CommandBlock.SCSICommandData,\r
+ MSInterfaceInfo->State.CommandBlock.SCSICommandLength,\r
+ StreamCallback_MS_Device_AbortOnMassStoreReset))\r
+ {\r
+ return false;\r
+ }\r
+\r
Endpoint_ClearOUT();\r
\r
- return !(MSInterfaceInfo->State.IsMassStoreReset);\r
+ return true;\r
}\r
\r
static void MS_Device_ReturnCommandStatus(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)\r
\r
while (Endpoint_IsStalled())\r
{\r
+ #if !defined(INTERRUPT_CONTROL_ENDPOINT)\r
USB_USBTask();\r
+ #endif\r
\r
if (MSInterfaceInfo->State.IsMassStoreReset)\r
return;\r
\r
while (Endpoint_IsStalled())\r
{\r
+ #if !defined(INTERRUPT_CONTROL_ENDPOINT)\r
USB_USBTask();\r
-\r
+ #endif\r
+ \r
if (MSInterfaceInfo->State.IsMassStoreReset)\r
return;\r
}\r
\r
- CallbackMSInterfaceInfo = MSInterfaceInfo;\r
- Endpoint_Write_Stream_LE(&MSInterfaceInfo->State.CommandStatus, sizeof(MS_CommandStatusWrapper_t),\r
- StreamCallback_MS_Device_AbortOnMassStoreReset);\r
- \r
- Endpoint_ClearIN();\r
+ CallbackIsResetSource = &MSInterfaceInfo->State.IsMassStoreReset;\r
+ if (Endpoint_Write_Stream_LE(&MSInterfaceInfo->State.CommandStatus, sizeof(MS_CommandStatusWrapper_t),\r
+ StreamCallback_MS_Device_AbortOnMassStoreReset))\r
+ {\r
+ return;\r
+ }\r
\r
- if (MSInterfaceInfo->State.IsMassStoreReset)\r
- return;\r
+ Endpoint_ClearIN();\r
}\r
\r
static uint8_t StreamCallback_MS_Device_AbortOnMassStoreReset(void)\r
{\r
- MS_Device_USBTask(CallbackMSInterfaceInfo);\r
+ #if !defined(INTERRUPT_CONTROL_ENDPOINT)\r
+ USB_USBTask();\r
+ #endif\r
\r
- if (CallbackMSInterfaceInfo->State.IsMassStoreReset)\r
+ if (*CallbackIsResetSource)\r
return STREAMCALLBACK_Abort;\r
else\r
return STREAMCALLBACK_Continue;\r
MS_CommandStatusWrapper_t CommandStatus; /**< Mass Storage class command status structure, set elements to indicate\r
* the issued command's success or failure to the host\r
*/\r
- bool IsMassStoreReset; /**< Flag indicating that the host has requested that the Mass Storage interface be reset\r
- * and that all current Mass Storage operations should immediately abort\r
- */\r
+ volatile bool IsMassStoreReset; /**< Flag indicating that the host has requested that the Mass Storage interface be reset\r
+ * and that all current Mass Storage operations should immediately abort\r
+ */\r
} State; /**< State data for the USB class interface within the device. All elements in this section\r
* are reset to their defaults when the interface is enumerated.\r
*/\r