diff options
| author | Dean <Dean@d5102386-fcda-11dd-9fdb-3debd5008f28> | 2010-07-09 07:24:34 +0000 |
|---|---|---|
| committer | Dean <Dean@d5102386-fcda-11dd-9fdb-3debd5008f28> | 2010-07-09 07:24:34 +0000 |
| commit | 52e5946d0d02ae854036f5eb15f4040c1f07e271 (patch) | |
| tree | a6010c6defc7a1705f37f9e7107c04a615b05013 /Demos/Device/LowLevel/MassStorage/Lib/SCSI.c | |
| parent | e37bae42e92ef87c5b7fc024c7e25460d93eb67d (diff) | |
Rewrote the implementation of the SwapEndian_16() and SwapEndian_32() functions so that they compile down in most instances to minimal loads and stores rather than complicated shifts.
Fixed SCSI.c implementations of all the demos/projects casting the block count to a 32-bit temporary before calling SwapEndian_16().
git-svn-id: http://lufa-lib.googlecode.com/svn/trunk@1364 d5102386-fcda-11dd-9fdb-3debd5008f28
Diffstat (limited to 'Demos/Device/LowLevel/MassStorage/Lib/SCSI.c')
| -rw-r--r-- | Demos/Device/LowLevel/MassStorage/Lib/SCSI.c | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/Demos/Device/LowLevel/MassStorage/Lib/SCSI.c b/Demos/Device/LowLevel/MassStorage/Lib/SCSI.c index 10e6bc4a..111c3b72 100644 --- a/Demos/Device/LowLevel/MassStorage/Lib/SCSI.c +++ b/Demos/Device/LowLevel/MassStorage/Lib/SCSI.c @@ -159,7 +159,7 @@ static void SCSI_Command_Inquiry(void) uint8_t PadBytes[AllocationLength - BytesTransferred]; /* Pad out remaining bytes with 0x00 */ - Endpoint_Write_Stream_LE(&PadBytes, (AllocationLength - BytesTransferred), StreamCallback_AbortOnMassStoreReset); + Endpoint_Write_Stream_LE(&PadBytes, sizeof(PadBytes), StreamCallback_AbortOnMassStoreReset); /* Finalize the stream transfer to send the last packet */ Endpoint_ClearIN(); @@ -182,7 +182,7 @@ static void SCSI_Command_Request_Sense(void) uint8_t PadBytes[AllocationLength - BytesTransferred]; /* Pad out remaining bytes with 0x00 */ - Endpoint_Write_Stream_LE(&PadBytes, (AllocationLength - BytesTransferred), StreamCallback_AbortOnMassStoreReset); + Endpoint_Write_Stream_LE(&PadBytes, sizeof(PadBytes), StreamCallback_AbortOnMassStoreReset); /* Finalize the stream transfer to send the last packet */ Endpoint_ClearIN(); @@ -256,16 +256,12 @@ static void SCSI_Command_ReadWrite_10(const bool IsDataRead) uint32_t BlockAddress; uint16_t TotalBlocks; - /* Load in the 32-bit block address (SCSI uses big-endian, so have to do it byte-by-byte) */ - ((uint8_t*)&BlockAddress)[3] = CommandBlock.SCSICommandData[2]; - ((uint8_t*)&BlockAddress)[2] = CommandBlock.SCSICommandData[3]; - ((uint8_t*)&BlockAddress)[1] = CommandBlock.SCSICommandData[4]; - ((uint8_t*)&BlockAddress)[0] = CommandBlock.SCSICommandData[5]; - - /* Load in the 16-bit total blocks (SCSI uses big-endian, so have to do it byte-by-byte) */ - ((uint8_t*)&TotalBlocks)[1] = CommandBlock.SCSICommandData[7]; - ((uint8_t*)&TotalBlocks)[0] = CommandBlock.SCSICommandData[8]; - + /* Load in the 32-bit block address (SCSI uses big-endian, so have to reverse the byte order) */ + BlockAddress = SwapEndian_32(*(uint32_t*)&CommandBlock.SCSICommandData[2]); + + /* Load in the 16-bit total blocks (SCSI uses big-endian, so have to reverse the byte order) */ + TotalBlocks = SwapEndian_16(*(uint16_t*)&CommandBlock.SCSICommandData[7]); + /* Check if the block address is outside the maximum allowable value for the LUN */ if (BlockAddress >= LUN_MEDIA_BLOCKS) { |
