| 
									
										
										
										
											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-03-12 22:45:35 +07:00
										 |  |  | #include <common/tusb_common.h>
 | 
					
						
							| 
									
										
										
										
											2013-11-01 12:11:26 +07:00
										 |  |  | #include "device/usbd.h"
 | 
					
						
							|  |  |  | #include "msc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-01 12:11:26 +07:00
										 |  |  | //--------------------------------------------------------------------+
 | 
					
						
							|  |  |  | // APPLICATION API
 | 
					
						
							|  |  |  | //--------------------------------------------------------------------+
 | 
					
						
							| 
									
										
										
										
											2013-11-21 12:47:55 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | //--------------------------------------------------------------------+
 | 
					
						
							|  |  |  | // APPLICATION CALLBACK API
 | 
					
						
							|  |  |  | //--------------------------------------------------------------------+
 | 
					
						
							| 
									
										
										
										
											2013-11-01 12:11:26 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-01 12:18:26 +07:00
										 |  |  | /** \brief 			Callback that is invoked when tinyusb stack received \ref SCSI_CMD_READ_10 command from host
 | 
					
						
							| 
									
										
										
										
											2018-03-09 14:29:23 +07:00
										 |  |  |  * \param[in]		port	    USB Controller ID | 
					
						
							| 
									
										
										
										
											2013-12-01 12:18:26 +07:00
										 |  |  |  * \param[in]		lun         Targeted Logical Unit | 
					
						
							|  |  |  |  * \param[out]	pp_buffer   Pointer to buffer which application need to update with the response data's address. | 
					
						
							|  |  |  |  *                          Must be accessible by USB controller (see \ref TUSB_CFG_ATTR_USBRAM) | 
					
						
							|  |  |  |  * \param[in]		lba         Starting Logical Block Address to be read | 
					
						
							|  |  |  |  * \param[in]		block_count Number of requested block | 
					
						
							|  |  |  |  * \retval      non-zero    Actual number of block that application processed, must be less than or equal to \a \b block_count. | 
					
						
							|  |  |  |  * \retval      zero        Indicate error in retrieving data from application. Tinyusb device stack will \b STALL the corresponding | 
					
						
							|  |  |  |  *                          endpoint and return failed status in command status wrapper phase. | 
					
						
							|  |  |  |  * \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 | 
					
						
							|  |  |  |  *              the same task (to save resource), any delay in this callback will cause delay in reponse on other classes. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-03-09 14:29:23 +07:00
										 |  |  | uint16_t tud_msc_read10_cb (uint8_t port, uint8_t lun, void** pp_buffer, uint32_t lba, uint16_t block_count); | 
					
						
							| 
									
										
										
										
											2013-12-01 12:18:26 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** \brief 			Callback that is invoked when tinyusb stack received \ref SCSI_CMD_WRITE_10 command from host
 | 
					
						
							| 
									
										
										
										
											2018-03-09 14:29:23 +07:00
										 |  |  |  * \param[in]		port	    USB Controller ID | 
					
						
							| 
									
										
										
										
											2013-12-01 12:18:26 +07:00
										 |  |  |  * \param[in]		lun         Targeted Logical Unit | 
					
						
							|  |  |  |  * \param[out]	pp_buffer   Pointer to buffer which application need to update with the address to hold data from host | 
					
						
							|  |  |  |  *                          Must be accessible by USB controller (see \ref TUSB_CFG_ATTR_USBRAM) | 
					
						
							|  |  |  |  * \param[in]		lba         Starting Logical Block Address to be write | 
					
						
							|  |  |  |  * \param[in]		block_count Number of requested block | 
					
						
							|  |  |  |  * \retval      non-zero    Actual number of block that application can receive and must be less than or equal to \a \b block_count. | 
					
						
							|  |  |  |  * \retval      zero        Indicate error in retrieving data from application. Tinyusb device stack will \b STALL the corresponding | 
					
						
							|  |  |  |  *                          endpoint and return failed status in command status wrapper phase. | 
					
						
							|  |  |  |  * \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 | 
					
						
							|  |  |  |  *              the same task (to save resource), any delay in this callback will cause delay in reponse on other classes. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-03-09 14:29:23 +07:00
										 |  |  | uint16_t tud_msc_write10_cb(uint8_t port, uint8_t lun, void** pp_buffer, uint32_t lba, uint16_t block_count); | 
					
						
							| 
									
										
										
										
											2013-11-15 12:30:22 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-30 22:29:37 +07:00
										 |  |  | // p_length [in,out] allocated/maximum length, application update with actual length
 | 
					
						
							| 
									
										
										
										
											2013-12-01 12:18:26 +07:00
										 |  |  | /** \brief 			Callback that is invoked when tinyusb stack received an SCSI command other than \ref SCSI_CMD_WRITE_10 and
 | 
					
						
							|  |  |  |  *              \ref SCSI_CMD_READ_10 command from host | 
					
						
							| 
									
										
										
										
											2018-03-09 14:29:23 +07:00
										 |  |  |  * \param[in]		port	    USB Controller ID | 
					
						
							| 
									
										
										
										
											2013-12-01 12:18:26 +07:00
										 |  |  |  * \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 | 
					
						
							| 
									
										
										
										
											2014-03-22 22:50:08 +07:00
										 |  |  |  * \param[out]	pp_buffer   Pointer to buffer which application need to update with the address to transfer data with host. | 
					
						
							|  |  |  |  *                          The buffer address can be anywhere since the stack will copy its contents to a internal USB-accessible buffer. | 
					
						
							| 
									
										
										
										
											2013-12-01 12:18:26 +07:00
										 |  |  |  * \param[in]		p_length    length | 
					
						
							|  |  |  |  * \retval      non-zero    Actual number of block that application can receive and must be less than or equal to \a \b block_count. | 
					
						
							|  |  |  |  * \retval      zero        Indicate error in retrieving data from application. Tinyusb device stack will \b STALL the corresponding | 
					
						
							|  |  |  |  *                          endpoint and return failed status in command status wrapper phase. | 
					
						
							|  |  |  |  * \note        Although this callback is called by tinyusb device task (non-isr context), however as all the classes share | 
					
						
							|  |  |  |  *              the same task (to save resource), any delay in this callback will cause delay in reponse on other classes. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-03-09 14:29:23 +07:00
										 |  |  | msc_csw_status_t tud_msc_scsi_cb (uint8_t port, uint8_t lun, uint8_t scsi_cmd[16], void const ** pp_buffer, uint16_t* p_length); | 
					
						
							| 
									
										
										
										
											2013-11-30 22:29:37 +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-09 14:29:23 +07:00
										 |  |  | tusb_error_t mscd_open(uint8_t port, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length); | 
					
						
							|  |  |  | tusb_error_t mscd_control_request_subtask(uint8_t port, tusb_control_request_t const * p_request); | 
					
						
							| 
									
										
										
										
											2018-03-11 15:31:46 +07:00
										 |  |  | tusb_error_t mscd_xfer_cb(uint8_t port, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes); | 
					
						
							| 
									
										
										
										
											2018-03-09 14:29:23 +07:00
										 |  |  | void mscd_close(uint8_t port); | 
					
						
							| 
									
										
										
										
											2013-11-01 12:11:26 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  |  } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* _TUSB_MSC_DEVICE_H_ */
 | 
					
						
							|  |  |  | 
 |