2013-11-01 12:11:26 +07:00
|
|
|
/**************************************************************************/
|
|
|
|
/*!
|
|
|
|
@file msc_device.h
|
|
|
|
@author hathach (tinyusb.org)
|
|
|
|
|
|
|
|
@section LICENSE
|
|
|
|
|
|
|
|
Software License Agreement (BSD License)
|
|
|
|
|
|
|
|
Copyright (c) 2013, hathach (tinyusb.org)
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
3. Neither the name of the copyright holders nor the
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
|
|
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
This file is part of the tinyusb stack.
|
|
|
|
*/
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _TUSB_MSC_DEVICE_H_
|
|
|
|
#define _TUSB_MSC_DEVICE_H_
|
|
|
|
|
2018-04-18 17:12:58 +07:00
|
|
|
#include "common/tusb_common.h"
|
2013-11-01 12:11:26 +07:00
|
|
|
#include "device/usbd.h"
|
|
|
|
#include "msc.h"
|
|
|
|
|
2018-07-17 16:04:55 +07:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// Class Driver Configuration
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
VERIFY_STATIC(CFG_TUD_MSC_BUFSIZE < UINT16_MAX, "Size is not correct");
|
|
|
|
|
|
|
|
#ifndef CFG_TUD_MSC_MAXLUN
|
|
|
|
#define CFG_TUD_MSC_MAXLUN 1
|
|
|
|
#elif CFG_TUD_MSC_MAXLUN == 0 || CFG_TUD_MSC_MAXLUN > 16
|
|
|
|
#error MSC Device: Incorrect setting of MAX LUN
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CFG_TUD_MSC_BLOCK_NUM
|
|
|
|
#error CFG_TUD_MSC_BLOCK_NUM must be defined
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CFG_TUD_MSC_BLOCK_SZ
|
|
|
|
#error CFG_TUD_MSC_BLOCK_SZ must be defined
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CFG_TUD_MSC_BUFSIZE
|
|
|
|
#error CFG_TUD_MSC_BUFSIZE must be defined, value of CFG_TUD_MSC_BLOCK_SZ should work well, the more the better
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CFG_TUD_MSC_VENDOR
|
|
|
|
#error CFG_TUD_MSC_VENDOR 8-byte name must be defined
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CFG_TUD_MSC_PRODUCT
|
|
|
|
#error CFG_TUD_MSC_PRODUCT 16-byte name must be defined
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CFG_TUD_MSC_PRODUCT_REV
|
|
|
|
#error CFG_TUD_MSC_PRODUCT_REV 4-byte string must be defined
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// TODO highspeed device is 512
|
|
|
|
#ifndef CFG_TUD_MSC_EPSIZE
|
|
|
|
#define CFG_TUD_MSC_EPSIZE 64
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2013-11-01 12:11:26 +07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2013-11-22 15:16:24 +07:00
|
|
|
/** \addtogroup ClassDriver_MSC
|
|
|
|
* @{
|
|
|
|
* \defgroup MSC_Device Device
|
2014-03-31 11:59:43 +07:00
|
|
|
* @{ */
|
2013-11-22 15:16:24 +07:00
|
|
|
|
2018-07-25 12:24:16 +07:00
|
|
|
|
|
|
|
// Check if MSC interface is ready to use
|
|
|
|
bool tud_msc_ready(void);
|
|
|
|
|
2013-11-21 12:47:55 +07:00
|
|
|
//--------------------------------------------------------------------+
|
2018-04-18 17:12:58 +07:00
|
|
|
// APPLICATION CALLBACK API (WEAK is optional)
|
2013-11-21 12:47:55 +07:00
|
|
|
//--------------------------------------------------------------------+
|
2018-04-18 16:55:44 +07:00
|
|
|
/** \brief Callback invoked when received \ref SCSI_CMD_READ_10 command
|
|
|
|
* \param[in] \rhport Root hub port
|
2013-12-01 12:18:26 +07:00
|
|
|
* \param[in] lun Targeted Logical Unit
|
2018-04-10 14:31:11 +07:00
|
|
|
* Must be accessible by USB controller (see \ref CFG_TUSB_ATTR_USBRAM)
|
2013-12-01 12:18:26 +07:00
|
|
|
* \param[in] lba Starting Logical Block Address to be read
|
2018-04-20 20:23:22 +07:00
|
|
|
* \param[in] offset Byte offset from LBA for reading
|
|
|
|
* \param[out] buffer Buffer which application need to update with the response data.
|
|
|
|
* \param[in] bufsize Max bytes can be copied. Application must not return more than this value.
|
2018-04-18 16:55:44 +07:00
|
|
|
*
|
2018-04-20 20:23:22 +07:00
|
|
|
* \retval positive Actual bytes returned, must not be more than \a \b bufsize.
|
|
|
|
* If value less than bufsize is returned, Tinyusb will transfer this amount and afterwards
|
|
|
|
* invoke this callback again with adjusted offset.
|
|
|
|
*
|
|
|
|
* \retval zero Indicate application is not ready yet to response e.g disk I/O is not complete.
|
|
|
|
* Tinyusb will invoke this callback with the same params again some time later.
|
|
|
|
*
|
|
|
|
* \retval negative Indicate error reading disk I/O. Tinyusb will \b STALL the corresponding
|
2013-12-01 12:18:26 +07:00
|
|
|
* endpoint and return failed status in command status wrapper phase.
|
2018-04-18 16:55:44 +07:00
|
|
|
*
|
2013-12-01 12:18:26 +07:00
|
|
|
* \note Host can request dozens of Kbytes in one command e.g \a \b block_count = 128, it is insufficient to require
|
|
|
|
* application to have that much of buffer. Instead, application can return the number of blocks it can processed,
|
|
|
|
* the stack after transferred that amount of data will continue to invoke this callback with adjusted \a \b lba and \a \b block_count.
|
|
|
|
* \n\n Although this callback is called by tinyusb device task (non-isr context), however as all the classes share
|
2018-04-18 16:55:44 +07:00
|
|
|
* the same task (to save resource), any delay in this callback will cause delay in response on other classes.
|
2013-12-01 12:18:26 +07:00
|
|
|
*/
|
2018-04-20 20:23:22 +07:00
|
|
|
int32_t tud_msc_read10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize);
|
2013-12-01 12:18:26 +07:00
|
|
|
|
2018-04-18 16:55:44 +07:00
|
|
|
/** \brief Callback invoked when received \ref SCSI_CMD_WRITE_10 command
|
2018-04-18 13:20:31 +07:00
|
|
|
* \param[in] rhport Root hub port
|
2013-12-01 12:18:26 +07:00
|
|
|
* \param[in] lun Targeted Logical Unit
|
2018-04-10 14:31:11 +07:00
|
|
|
* Must be accessible by USB controller (see \ref CFG_TUSB_ATTR_USBRAM)
|
2013-12-01 12:18:26 +07:00
|
|
|
* \param[in] lba Starting Logical Block Address to be write
|
2018-04-20 20:23:22 +07:00
|
|
|
* \param[out] buffer Buffer which holds written data.
|
|
|
|
* \param[in] bufsize Max bytes in buffer. Application must not return more than this value.
|
|
|
|
*
|
|
|
|
* \retval positive Actual bytes written, must not be more than \a \b bufsize.
|
|
|
|
* If value less than bufsize is returned, Tinyusb will trim off this amount and
|
|
|
|
* invoke this callback again with adjusted offset some time later.
|
|
|
|
*
|
|
|
|
* \retval zero Indicate application is not ready yet e.g disk I/O is not complete.
|
|
|
|
* Tinyusb will invoke this callback with the same params again some time later.
|
2018-04-18 16:55:44 +07:00
|
|
|
*
|
2018-04-20 20:23:22 +07:00
|
|
|
* \retval negative Indicate error writing disk I/O. Tinyusb will \b STALL the corresponding
|
2013-12-01 12:18:26 +07:00
|
|
|
* endpoint and return failed status in command status wrapper phase.
|
2018-04-18 16:55:44 +07:00
|
|
|
*
|
2013-12-01 12:18:26 +07:00
|
|
|
* \note Host can request dozens of Kbytes in one command e.g \a \b block_count = 128, it is insufficient to require
|
|
|
|
* application to have that much of buffer. Instead, application can return the number of blocks it can processed,
|
|
|
|
* the stack after transferred that amount of data will continue to invoke this callback with adjusted \a \b lba and \a \b block_count.
|
|
|
|
* \n\n Although this callback is called by tinyusb device task (non-isr context), however as all the classes share
|
2018-04-18 16:55:44 +07:00
|
|
|
* the same task (to save resource), any delay in this callback will cause delay in response on other classes.
|
2013-12-01 12:18:26 +07:00
|
|
|
*/
|
2018-04-20 20:23:22 +07:00
|
|
|
int32_t tud_msc_write10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize);
|
2018-04-18 16:55:44 +07:00
|
|
|
|
2018-04-18 17:12:58 +07:00
|
|
|
|
2018-04-20 20:23:22 +07:00
|
|
|
/** \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] lun Targeted Logical Unit
|
|
|
|
* \param[in] scsi_cmd SCSI command contents, application should examine this command block to know which command host requested
|
|
|
|
* \param[out] buffer Buffer for SCSI Data Stage.
|
|
|
|
* - For INPUT: application must fill this with response.
|
|
|
|
* - For OUTPUT it holds the Data from host
|
|
|
|
* \param[in] bufsize Buffer's length.
|
2018-04-18 16:55:44 +07:00
|
|
|
*
|
2018-04-20 20:23:22 +07:00
|
|
|
* \retval negative Indicate error e.g accessing disk I/O. Tinyusb will \b STALL the corresponding
|
|
|
|
* endpoint and return failed status in command status wrapper phase.
|
|
|
|
* \retval otherwise Actual bytes processed, must not be more than \a \b bufsize. Can be zero for no-data command.
|
2013-12-01 12:18:26 +07:00
|
|
|
*/
|
2018-05-08 16:30:07 +07:00
|
|
|
int32_t tud_msc_scsi_cb (uint8_t rhport, uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize);
|
2013-11-30 22:29:37 +07:00
|
|
|
|
2018-04-18 17:12:58 +07:00
|
|
|
/*------------- 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);
|
2018-05-08 16:30:07 +07:00
|
|
|
ATTR_WEAK void tud_msc_scsi_complete_cb(uint8_t rhport, uint8_t lun, uint8_t const scsi_cmd[16]);
|
2018-04-18 17:12:58 +07:00
|
|
|
|
2013-11-22 15:16:24 +07:00
|
|
|
/** @} */
|
|
|
|
/** @} */
|
|
|
|
|
2013-11-01 12:11:26 +07:00
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// USBD-CLASS DRIVER API
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
#ifdef _TINY_USB_SOURCE_FILE_
|
|
|
|
|
2013-11-13 12:40:11 +07:00
|
|
|
void mscd_init(void);
|
2018-03-23 12:32:40 +07:00
|
|
|
tusb_error_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length);
|
2018-03-23 12:17:47 +07:00
|
|
|
tusb_error_t mscd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request);
|
|
|
|
tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes);
|
2018-07-13 16:09:26 +07:00
|
|
|
void mscd_reset(uint8_t rhport);
|
2013-11-01 12:11:26 +07:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _TUSB_MSC_DEVICE_H_ */
|
|
|
|
|