add msc device optional callbacks

- tud_msc_read10_complete_cb()
- tud_msc_write10_complete_cb()
- tud_msc_scsi_complete_cb()
This commit is contained in:
hathach 2018-04-18 17:12:58 +07:00
parent 9aaf86bffd
commit a9ada8ea5e
2 changed files with 22 additions and 11 deletions

View File

@ -83,7 +83,7 @@ CFG_TUSB_ATTR_USBRAM CFG_TUSB_MEM_ALIGN STATIC_VAR mscd_interface_t mscd_data;
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION // INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
static bool read10_write10_data_xfer(uint8_t rhport, mscd_interface_t* p_msc); static void read10_write10_data_xfer(uint8_t rhport, mscd_interface_t* p_msc);
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// USBD-CLASS API // USBD-CLASS API
@ -267,6 +267,18 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
if ( p_msc->stage == MSC_STAGE_STATUS ) if ( p_msc->stage == MSC_STAGE_STATUS )
{ {
// Invoke Complete Callback if defined
if ( SCSI_CMD_READ_10 == p_cbw->command[0])
{
if ( tud_msc_read10_complete_cb ) tud_msc_read10_complete_cb(rhport, p_cbw->lun);
}else if ( SCSI_CMD_WRITE_10 == p_cbw->command[0] )
{
if ( tud_msc_write10_complete_cb ) tud_msc_write10_complete_cb(rhport, p_cbw->lun);
}else
{
if ( tud_msc_scsi_complete_cb ) tud_msc_scsi_complete_cb(rhport, p_cbw->lun, p_cbw->command);
}
// Move to default CMD stage after sending status // Move to default CMD stage after sending status
p_msc->stage = MSC_STAGE_CMD; p_msc->stage = MSC_STAGE_CMD;
@ -279,8 +291,7 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
return TUSB_ERROR_NONE; return TUSB_ERROR_NONE;
} }
// return true if data phase is complete, false if not yet complete static void read10_write10_data_xfer(uint8_t rhport, mscd_interface_t* p_msc)
static bool read10_write10_data_xfer(uint8_t rhport, mscd_interface_t* p_msc)
{ {
msc_cbw_t* const p_cbw = &p_msc->cbw; msc_cbw_t* const p_cbw = &p_msc->cbw;
msc_csw_t* const p_csw = &p_msc->csw; msc_csw_t* const p_csw = &p_msc->csw;
@ -320,14 +331,10 @@ static bool read10_write10_data_xfer(uint8_t rhport, mscd_interface_t* p_msc)
p_csw->status = MSC_CSW_STATUS_FAILED; p_csw->status = MSC_CSW_STATUS_FAILED;
dcd_edpt_stall(rhport, ep_data); dcd_edpt_stall(rhport, ep_data);
return true;
}else }else
{ {
TU_ASSERT( dcd_edpt_xfer(rhport, ep_data, p_buffer, xfer_block * block_size) ); TU_ASSERT( dcd_edpt_xfer(rhport, ep_data, p_buffer, xfer_block * block_size) );
} }
return true;
} }
#endif #endif

View File

@ -39,7 +39,7 @@
#ifndef _TUSB_MSC_DEVICE_H_ #ifndef _TUSB_MSC_DEVICE_H_
#define _TUSB_MSC_DEVICE_H_ #define _TUSB_MSC_DEVICE_H_
#include <common/tusb_common.h> #include "common/tusb_common.h"
#include "device/usbd.h" #include "device/usbd.h"
#include "msc.h" #include "msc.h"
@ -58,7 +58,7 @@
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// APPLICATION CALLBACK API // APPLICATION CALLBACK API (WEAK is optional)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
/** \brief Callback invoked when received \ref SCSI_CMD_READ_10 command /** \brief Callback invoked when received \ref SCSI_CMD_READ_10 command
* \param[in] \rhport Root hub port * \param[in] \rhport Root hub port
@ -80,8 +80,6 @@
*/ */
uint16_t tud_msc_read10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint16_t block_count, void** pp_buffer); uint16_t tud_msc_read10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint16_t block_count, void** pp_buffer);
//void tud_msc_read10_cmpl_cb(uint8_t rhport, uint8_t lun);
/** \brief Callback invoked when received \ref SCSI_CMD_WRITE_10 command /** \brief Callback invoked when received \ref SCSI_CMD_WRITE_10 command
* \param[in] rhport Root hub port * \param[in] rhport Root hub port
* \param[in] lun Targeted Logical Unit * \param[in] lun Targeted Logical Unit
@ -102,6 +100,7 @@ uint16_t tud_msc_read10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint16_t
*/ */
uint16_t tud_msc_write10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint16_t block_count, void** pp_buffer); uint16_t tud_msc_write10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint16_t block_count, void** pp_buffer);
/** \brief Callback invoked when received an SCSI command other than \ref SCSI_CMD_WRITE_10 and \ref SCSI_CMD_READ_10 /** \brief Callback invoked when received an SCSI command other than \ref SCSI_CMD_WRITE_10 and \ref SCSI_CMD_READ_10
* \param[in] rhport Root hub port * \param[in] rhport Root hub port
* \param[in] lun Targeted Logical Unit * \param[in] lun Targeted Logical Unit
@ -115,6 +114,11 @@ uint16_t tud_msc_write10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint16_t
*/ */
bool 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);
/*------------- Optional callbacks : Could be used by application to free up resources -------------*/
ATTR_WEAK void tud_msc_read10_complete_cb(uint8_t rhport, uint8_t lun);
ATTR_WEAK void tud_msc_write10_complete_cb(uint8_t rhport, uint8_t lun);
ATTR_WEAK void tud_msc_scsi_complete_cb(uint8_t rhport, uint8_t lun, uint8_t scsi_cmd[16]);
/** @} */ /** @} */
/** @} */ /** @} */