improve msc device

- change tud_msc_scsi_cb return type to simply bool
- change tud_msc_write10_cb, tud_msc_read10_cb params order
This commit is contained in:
hathach
2018-04-18 16:55:44 +07:00
parent 6280c50ad7
commit 9aaf86bffd
5 changed files with 41 additions and 45 deletions

View File

@@ -59,8 +59,8 @@ static scsi_inquiry_data_t const mscd_inquiry_data =
static scsi_read_capacity10_data_t const mscd_read_capacity10_data =
{
.last_lba = ENDIAN_BE(DISK_BLOCK_NUM-1), // read capacity
.block_size = ENDIAN_BE(DISK_BLOCK_SIZE)
.last_lba = ENDIAN_BE(DISK_BLOCK_NUM-1), // Big Endian
.block_size = ENDIAN_BE(DISK_BLOCK_SIZE) // Big Endian
};
static scsi_sense_fixed_data_t mscd_sense_data =
@@ -99,7 +99,7 @@ void msc_app_umount(uint8_t rhport)
}
msc_csw_status_t tud_msc_scsi_cb (uint8_t rhport, uint8_t lun, uint8_t scsi_cmd[16], void* buffer, uint16_t* p_len)
bool tud_msc_scsi_cb (uint8_t rhport, uint8_t lun, uint8_t scsi_cmd[16], void* buffer, uint16_t* p_len)
{
// read10 & write10 has their own callback and MUST not be handled here
@@ -145,13 +145,13 @@ msc_csw_status_t tud_msc_scsi_cb (uint8_t rhport, uint8_t lun, uint8_t scsi_cmd[
default:
(*p_len) = 0;
return MSC_CSW_STATUS_FAILED;
return false;
}
if ( bufptr && buflen )
{
// Response len must not larger than expected from host
TU_ASSERT( (*p_len) >= buflen, MSC_CSW_STATUS_FAILED);
TU_ASSERT( (*p_len) >= buflen );
memcpy(buffer, bufptr, buflen);
(*p_len) = buflen;
@@ -165,7 +165,7 @@ msc_csw_status_t tud_msc_scsi_cb (uint8_t rhport, uint8_t lun, uint8_t scsi_cmd[
mscd_sense_data.additional_sense_qualifier = 0;
}
return MSC_CSW_STATUS_PASSED;
return true;
}
//--------------------------------------------------------------------+

View File

@@ -91,13 +91,13 @@ uint8_t msc_device_ramdisk[DISK_BLOCK_NUM][DISK_BLOCK_SIZE] =
//--------------------------------------------------------------------+
// IMPLEMENTATION
//--------------------------------------------------------------------+
uint16_t tud_msc_read10_cb (uint8_t rhport, uint8_t lun, void** pp_buffer, uint32_t lba, uint16_t block_count)
uint16_t tud_msc_read10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint16_t block_count, void** pp_buffer)
{
(*pp_buffer) = msc_device_ramdisk[lba];
return min16_of(block_count, DISK_BLOCK_NUM);
}
uint16_t tud_msc_write10_cb(uint8_t rhport, uint8_t lun, void** pp_buffer, uint32_t lba, uint16_t block_count)
uint16_t tud_msc_write10_cb(uint8_t rhport, uint8_t lun, uint32_t lba, uint16_t block_count, void** pp_buffer)
{
(*pp_buffer) = msc_device_ramdisk[lba];

View File

@@ -97,7 +97,7 @@ static uint8_t sector_buffer[DISK_BLOCK_SIZE];
//--------------------------------------------------------------------+
// IMPLEMENTATION
//--------------------------------------------------------------------+
uint16_t tusbd_msc_read10_cb (uint8_t rhport, uint8_t lun, void** pp_buffer, uint32_t lba, uint16_t block_count)
uint16_t tusbd_msc_read10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint16_t block_count, void** pp_buffer)
{
memcpy(sector_buffer, msc_device_app_rommdisk[lba], DISK_BLOCK_SIZE);
(*pp_buffer) = sector_buffer;
@@ -106,7 +106,7 @@ uint16_t tusbd_msc_read10_cb (uint8_t rhport, uint8_t lun, void** pp_buffer, uin
}
// Stall write10 by return 0, as this is readonly disk
uint16_t tusbd_msc_write10_cb(uint8_t rhport, uint8_t lun, void** pp_buffer, uint32_t lba, uint16_t block_count)
uint16_t tusbd_msc_write10_cb(uint8_t rhport, uint8_t lun, uint32_t lba, uint16_t block_count, void** pp_buffer)
{
(*pp_buffer) = NULL;