update msc to match new API in tinyusb

This commit is contained in:
hathach 2018-04-19 16:56:25 +07:00
parent 29b6e9de61
commit 512f7a5fce
4 changed files with 49 additions and 26 deletions

@ -1 +1 @@
Subproject commit 0e62cb1425f704ee3ac334f92992d5b0cfd2817d Subproject commit ba223b2a05d88901f3255a218329b7ff4c7d6128

View File

@ -98,47 +98,62 @@ 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 const ** pp_buffer, uint16_t* p_length) 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 // read10 & write10 has their own callback and MUST not be handled here
void* bufptr = NULL;
uint16_t buflen = 0;
switch (scsi_cmd[0]) switch (scsi_cmd[0])
{ {
case SCSI_CMD_INQUIRY: case SCSI_CMD_INQUIRY:
(*pp_buffer) = &mscd_inquiry_data; bufptr = &mscd_inquiry_data;
(*p_length) = sizeof(scsi_inquiry_data_t); buflen = sizeof(scsi_inquiry_data_t);
break; break;
case SCSI_CMD_READ_CAPACITY_10: case SCSI_CMD_READ_CAPACITY_10:
(*pp_buffer) = &mscd_read_capacity10_data; bufptr = &mscd_read_capacity10_data;
(*p_length) = sizeof(scsi_read_capacity10_data_t); buflen = sizeof(scsi_read_capacity10_data_t);
break; break;
case SCSI_CMD_REQUEST_SENSE: case SCSI_CMD_REQUEST_SENSE:
(*pp_buffer) = &mscd_sense_data; bufptr = &mscd_sense_data;
(*p_length) = sizeof(scsi_sense_fixed_data_t); buflen = sizeof(scsi_sense_fixed_data_t);
break; break;
case SCSI_CMD_READ_FORMAT_CAPACITY: case SCSI_CMD_READ_FORMAT_CAPACITY:
(*pp_buffer) = &mscd_format_capacity_data; bufptr = &mscd_format_capacity_data;
(*p_length) = sizeof(scsi_read_format_capacity_data_t); buflen = sizeof(scsi_read_format_capacity_data_t);
break; break;
case SCSI_CMD_MODE_SENSE_6: case SCSI_CMD_MODE_SENSE_6:
(*pp_buffer) = &msc_dev_mode_para; bufptr = &msc_dev_mode_para;
(*p_length) = sizeof(msc_dev_mode_para); buflen = sizeof(msc_dev_mode_para);
break; break;
case SCSI_CMD_TEST_UNIT_READY: case SCSI_CMD_TEST_UNIT_READY:
(*pp_buffer) = NULL; bufptr = NULL;
(*p_length) = 0; buflen= 0;
break; break;
case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL: case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
(*pp_buffer) = NULL; bufptr = NULL;
(*p_length) = 0; buflen= 0;
break; break;
default: return MSC_CSW_STATUS_FAILED; default:
(*p_len) = 0;
return false;
}
if ( bufptr && buflen )
{
// Response len must not larger than expected from host
TU_ASSERT( (*p_len) >= buflen );
memcpy(buffer, bufptr, buflen);
(*p_len) = buflen;
} }
//------------- clear sense data if it is not request sense command -------------// //------------- clear sense data if it is not request sense command -------------//
@ -149,7 +164,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; mscd_sense_data.additional_sense_qualifier = 0;
} }
return MSC_CSW_STATUS_PASSED; return true;
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+

View File

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

View File

@ -49,11 +49,11 @@
#define CFG_TUSB_MCU OPT_MCU_NRF5X #define CFG_TUSB_MCU OPT_MCU_NRF5X
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE #define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
#define CFG_TUSB_DEBUG 1
#define CFG_TUSB_OS OPT_OS_NONE #define CFG_TUSB_OS OPT_OS_NONE
//#define CFG_TUD_TASK_PRIO 0 //#define CFG_TUD_TASK_PRIO 0
#define CFG_TUSB_DEBUG 0
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// DEVICE CONFIGURATION // DEVICE CONFIGURATION
// Note: TUD Stand for Tiny Usb Device // Note: TUD Stand for Tiny Usb Device
@ -79,6 +79,12 @@
// If not enabled, application must call tud_cdc_flush() periodically // If not enabled, application must call tud_cdc_flush() periodically
#define CFG_TUD_CDC_FLUSH_ON_SOF 1 #define CFG_TUD_CDC_FLUSH_ON_SOF 1
// Number of supported Logical Unit Number
#define CFG_TUD_MSC_MAXLUN 1
// Buffer size of Device Mass storage
#define CFG_TUD_MSC_BUFSIZE 512
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// USB RAM PLACEMENT // USB RAM PLACEMENT
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+