add usb msc callback description

This commit is contained in:
hathach 2018-07-27 17:14:49 +07:00
parent 5dd02cbdd3
commit cf6c534c19
2 changed files with 26 additions and 21 deletions

View File

@ -64,8 +64,8 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
{ {
// 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 const* ptr = NULL; void const* response = NULL;
uint16_t len = 0; uint16_t resplen = 0;
// most scsi handled is input // most scsi handled is input
bool in_xfer = true; bool in_xfer = true;
@ -74,39 +74,44 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
{ {
case SCSI_CMD_TEST_UNIT_READY: case SCSI_CMD_TEST_UNIT_READY:
// Command that host uses to check our readiness before sending other commands // Command that host uses to check our readiness before sending other commands
len = 0; resplen = 0;
break; break;
case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL: case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
// Host is about to read/write etc ... better not to disconnect disk // Host is about to read/write etc ... better not to disconnect disk
len = 0; resplen = 0;
break; break;
case SCSI_CMD_START_STOP_UNIT: case SCSI_CMD_START_STOP_UNIT:
// Host try to eject/safe remove/poweroff us. We could safely disconnect with disk storage, or go into lower power // Host try to eject/safe remove/poweroff us. We could safely disconnect with disk storage, or go into lower power
// scsi_start_stop_unit_t const * cmd_start_stop = (scsi_start_stop_unit_t const *) scsi_cmd /* scsi_start_stop_unit_t const * start_stop = (scsi_start_stop_unit_t const *) scsi_cmd;
len = 0; // Start bit = 0 : low power mode, if load_eject = 1 : unmount disk storage as well
// Start bit = 1 : Ready mode, if load_eject = 1 : mount disk storage
start_stop->start;
start_stop->load_eject;
*/
resplen = 0;
break; break;
// negative means error -> tusb could stall and/or response with failed status // negative means error -> tusb could stall and/or response with failed status
default: return -1; default: return -1;
} }
// return len must not larger than bufsize // return resplen must not larger than bufsize
if ( len > bufsize ) len = bufsize; if ( resplen > bufsize ) resplen = bufsize;
if ( ptr && len ) if ( response && resplen )
{ {
if(in_xfer) if(in_xfer)
{ {
memcpy(buffer, ptr, len); memcpy(buffer, response, resplen);
}else }else
{ {
// SCSI output // SCSI output
} }
} }
return len; return resplen;
} }

View File

@ -104,10 +104,10 @@ bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, u
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
/** /**
* Callback invoked when received \ref SCSI_CMD_READ_10 command * Callback invoked when received \ref SCSI_CMD_READ_10 command
* \param[in] lun Logical unit number * \param[in] lun Logical unit number
* \param[in] lba Logical Block Address to be read * \param[in] lba Logical Block Address to be read
* \param[in] offset Byte offset from LBA * \param[in] offset Byte offset from LBA
* \param[out] buffer Buffer which application need to update with the response data. * \param[out] buffer Buffer which application need to update with the response data.
* \param[in] bufsize Requested bytes * \param[in] bufsize Requested bytes
* *
* \return Number of byte read, if it is less than requested bytes by \a \b bufsize. Tinyusb will transfer * \return Number of byte read, if it is less than requested bytes by \a \b bufsize. Tinyusb will transfer
@ -123,10 +123,10 @@ int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buf
/** /**
* Callback invoked when received \ref SCSI_CMD_WRITE_10 command * Callback invoked when received \ref SCSI_CMD_WRITE_10 command
* \param[in] lun Logical unit number * \param[in] lun Logical unit number
* \param[in] lba Logical Block Address to be write * \param[in] lba Logical Block Address to be write
* \param[in] offset Byte offset from LBA * \param[in] offset Byte offset from LBA
* \param[out] buffer Buffer which holds written data. * \param[out] buffer Buffer which holds written data.
* \param[in] bufsize Requested bytes * \param[in] bufsize Requested bytes
* *
* \return Number of byte written, if it is less than requested bytes by \a \b bufsize. Tinyusb will proceed with * \return Number of byte written, if it is less than requested bytes by \a \b bufsize. Tinyusb will proceed with
@ -142,8 +142,8 @@ int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* bu
/** /**
* Callback invoked when received an SCSI command not in built-in list below. * Callback invoked when received an SCSI command not in built-in list below.
* \param[in] lun Logical unit number * \param[in] lun Logical unit number
* \param[in] scsi_cmd SCSI command contents which application must examine to response accordingly * \param[in] scsi_cmd SCSI command contents which application must examine to response accordingly
* \param[out] buffer Buffer for SCSI Data Stage. * \param[out] buffer Buffer for SCSI Data Stage.
* - For INPUT: application must fill this with response. * - For INPUT: application must fill this with response.
* - For OUTPUT it holds the Data from host * - For OUTPUT it holds the Data from host