aboutsummaryrefslogtreecommitdiffstats
path: root/Demos/Device/LowLevel/MassStorage/MassStorage.c
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-07-28 09:17:22 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-07-28 09:17:22 +0000
commit9a97f16b07ea15e327b0d01be238b06623b033d6 (patch)
tree95de8087639f7d18295079d18a74f0e40f8be39c /Demos/Device/LowLevel/MassStorage/MassStorage.c
parent059307d89cbdd7a45170566f469eb9e02c20b3e1 (diff)
downloadlufa-9a97f16b07ea15e327b0d01be238b06623b033d6.tar.gz
lufa-9a97f16b07ea15e327b0d01be238b06623b033d6.tar.bz2
lufa-9a97f16b07ea15e327b0d01be238b06623b033d6.zip
Add TMC header read and write functions, so that TMC data can now be exchanged in both directions.
Minor update to the LowLevel MassStorage device demo, so that the ReadInCommandBlock() performs the data OUT endpoint selection and packet arrival test.
Diffstat (limited to 'Demos/Device/LowLevel/MassStorage/MassStorage.c')
-rw-r--r--Demos/Device/LowLevel/MassStorage/MassStorage.c60
1 files changed, 26 insertions, 34 deletions
diff --git a/Demos/Device/LowLevel/MassStorage/MassStorage.c b/Demos/Device/LowLevel/MassStorage/MassStorage.c
index 9f13ff927..93b7c6102 100644
--- a/Demos/Device/LowLevel/MassStorage/MassStorage.c
+++ b/Demos/Device/LowLevel/MassStorage/MassStorage.c
@@ -173,47 +173,35 @@ void MassStorage_Task(void)
/* Device must be connected and configured for the task to run */
if (USB_DeviceState != DEVICE_STATE_Configured)
return;
-
- /* Select the Data Out Endpoint */
- Endpoint_SelectEndpoint(MASS_STORAGE_OUT_EPNUM);
-
- /* Check to see if a command from the host has been issued */
- if (Endpoint_IsReadWriteAllowed())
+
+ /* Process sent command block from the host if one has been sent */
+ if (ReadInCommandBlock())
{
/* Indicate busy */
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
- /* Process sent command block from the host */
- if (ReadInCommandBlock())
- {
- /* Check direction of command, select Data IN endpoint if data is from the device */
- if (CommandBlock.Flags & COMMAND_DIRECTION_DATA_IN)
- Endpoint_SelectEndpoint(MASS_STORAGE_IN_EPNUM);
+ /* Check direction of command, select Data IN endpoint if data is from the device */
+ if (CommandBlock.Flags & COMMAND_DIRECTION_DATA_IN)
+ Endpoint_SelectEndpoint(MASS_STORAGE_IN_EPNUM);
- /* Decode the received SCSI command, set returned status code */
- CommandStatus.Status = SCSI_DecodeSCSICommand() ? Command_Pass : Command_Fail;
+ /* Decode the received SCSI command, set returned status code */
+ CommandStatus.Status = SCSI_DecodeSCSICommand() ? Command_Pass : Command_Fail;
- /* Load in the CBW tag into the CSW to link them together */
- CommandStatus.Tag = CommandBlock.Tag;
+ /* Load in the CBW tag into the CSW to link them together */
+ CommandStatus.Tag = CommandBlock.Tag;
- /* Load in the data residue counter into the CSW */
- CommandStatus.DataTransferResidue = CommandBlock.DataTransferLength;
-
- /* Stall the selected data pipe if command failed (if data is still to be transferred) */
- if ((CommandStatus.Status == Command_Fail) && (CommandStatus.DataTransferResidue))
- Endpoint_StallTransaction();
-
- /* Return command status block to the host */
- ReturnCommandStatus();
-
- /* Indicate ready */
- LEDs_SetAllLEDs(LEDMASK_USB_READY);
- }
- else
- {
- /* Indicate error reading in the command block from the host */
- LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
- }
+ /* Load in the data residue counter into the CSW */
+ CommandStatus.DataTransferResidue = CommandBlock.DataTransferLength;
+
+ /* Stall the selected data pipe if command failed (if data is still to be transferred) */
+ if ((CommandStatus.Status == Command_Fail) && (CommandStatus.DataTransferResidue))
+ Endpoint_StallTransaction();
+
+ /* Return command status block to the host */
+ ReturnCommandStatus();
+
+ /* Indicate ready */
+ LEDs_SetAllLEDs(LEDMASK_USB_READY);
}
/* Check if a Mass Storage Reset occurred */
@@ -244,6 +232,10 @@ static bool ReadInCommandBlock(void)
{
/* Select the Data Out endpoint */
Endpoint_SelectEndpoint(MASS_STORAGE_OUT_EPNUM);
+
+ /* Abort if no command has been sent from the host */
+ if (!(Endpoint_IsOUTReceived()))
+ return false;
/* Read in command block header */
Endpoint_Read_Stream_LE(&CommandBlock, (sizeof(CommandBlock) - sizeof(CommandBlock.SCSICommandData)),