summaryrefslogtreecommitdiff
path: root/src/class
diff options
context:
space:
mode:
authorhathach <[email protected]>2021-04-26 17:42:49 +0700
committerhathach <[email protected]>2021-04-26 17:42:49 +0700
commitc26875e70d120f564f4e68c1dc79d9e7e3642b70 (patch)
treeb90741836c731cb9be1c6b3326f05a05068bc7bd /src/class
parenta8e109cb3d2af7a54cc5694e1507f21127d36028 (diff)
add TUP_MCU_STRICT_ALIGN macro that manually pick bytes for lpc55 port1 that is m4 but cannot unaligned acces on usb ram
Diffstat (limited to 'src/class')
-rw-r--r--src/class/msc/msc_device.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c
index 194f4d3cb..539941935 100644
--- a/src/class/msc/msc_device.c
+++ b/src/class/msc/msc_device.c
@@ -77,28 +77,19 @@ static void proc_write10_cmd(uint8_t rhport, mscd_interface_t* p_msc);
static inline uint32_t rdwr10_get_lba(uint8_t const command[])
{
- // read10 & write10 has the same format
- scsi_write10_t* p_rdwr10 = (scsi_write10_t*) command;
+ // use offsetof to avoid pointer to the odd/unaligned address
+ uint32_t const lba = tu_unaligned_read32(command + offsetof(scsi_write10_t, lba));
- // copy first to prevent mis-aligned access
- uint32_t lba;
- // use offsetof to avoid pointer to the odd/misaligned address
- memcpy(&lba, (uint8_t*) p_rdwr10 + offsetof(scsi_write10_t, lba), 4);
-
- // lba is in Big Endian format
+ // lba is in Big Endian
return tu_ntohl(lba);
}
static inline uint16_t rdwr10_get_blockcount(uint8_t const command[])
{
- // read10 & write10 has the same format
- scsi_write10_t* p_rdwr10 = (scsi_write10_t*) command;
-
- // copy first to prevent mis-aligned access
- uint16_t block_count;
// use offsetof to avoid pointer to the odd/misaligned address
- memcpy(&block_count, (uint8_t*) p_rdwr10 + offsetof(scsi_write10_t, block_count), 2);
+ uint16_t const block_count = tu_unaligned_read16(command + offsetof(scsi_write10_t, block_count));
+ // block count is in Big Endian
return tu_ntohs(block_count);
}