初始版本
This commit is contained in:
2492
components/libraries/usbd/class/msc/app_usbd_msc.c
Normal file
2492
components/libraries/usbd/class/msc/app_usbd_msc.c
Normal file
File diff suppressed because it is too large
Load Diff
193
components/libraries/usbd/class/msc/app_usbd_msc.h
Normal file
193
components/libraries/usbd/class/msc/app_usbd_msc.h
Normal file
@@ -0,0 +1,193 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* 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, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, 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 Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS 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.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_USBD_MSC_H__
|
||||
#define APP_USBD_MSC_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "nrf_drv_usbd.h"
|
||||
#include "nrf_block_dev.h"
|
||||
#include "app_usbd_class_base.h"
|
||||
#include "app_usbd.h"
|
||||
#include "app_usbd_core.h"
|
||||
#include "app_usbd_descriptor.h"
|
||||
|
||||
#include "app_usbd_msc_types.h"
|
||||
#include "app_usbd_msc_desc.h"
|
||||
#include "app_usbd_msc_scsi.h"
|
||||
#include "app_usbd_msc_internal.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_msc USB MSC class
|
||||
* @ingroup app_usbd
|
||||
*
|
||||
* @brief @tagAPI52840 Module with types, definitions, and API used by the USB MSC class.
|
||||
*
|
||||
* @details References:
|
||||
* - "Universal Serial Bus Mass Storage Class, Specification Overview,"
|
||||
* Revision 1.2, USB Implementer's Forum, June 23, 2003.
|
||||
* - "Universal Serial Bus Mass Storage Class, Bulk-Only Transport,"
|
||||
* Revision 1.0, USB Implementer's Forum, September 31, 1999.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef DOXYGEN
|
||||
/**
|
||||
* @brief Mass storage class instance type.
|
||||
*
|
||||
* @ref APP_USBD_CLASS_TYPEDEF
|
||||
*/
|
||||
typedef struct { } app_usbd_msc_t;
|
||||
#else
|
||||
/*lint -save -e10 -e26 -e123 -e505 */
|
||||
APP_USBD_CLASS_TYPEDEF(app_usbd_msc, \
|
||||
APP_USBD_MSC_CONFIG(0, (NRF_DRV_USBD_EPIN1, NRF_DRV_USBD_EPOUT1)), \
|
||||
APP_USBD_MSC_INSTANCE_SPECIFIC_DEC, \
|
||||
APP_USBD_MSC_DATA_SPECIFIC_DEC \
|
||||
);
|
||||
#endif
|
||||
|
||||
/*lint -restore*/
|
||||
|
||||
|
||||
/*lint -save -e407 */
|
||||
|
||||
/**
|
||||
* @brief Events passed to user event handler.
|
||||
*
|
||||
* @note Example prototype of user event handler:
|
||||
*
|
||||
* void msc_user_ev_handler(app_usbd_class_inst_t const * p_inst,
|
||||
* app_usbd_msc_user_event_t event);
|
||||
*/
|
||||
typedef enum app_usbd_msc_user_event_e {
|
||||
APP_USBD_MSC_USER_EVT_NONE, /**< Dummy event to satisfy compilers. */
|
||||
} app_usbd_msc_user_event_t;
|
||||
|
||||
/*lint -restore*/
|
||||
|
||||
/**
|
||||
* @brief Helper macro for defining MSC endpoints.
|
||||
*
|
||||
* @param in_number Input endpoint number.
|
||||
* @param out_number Output endpoint number.
|
||||
* */
|
||||
#define APP_USBD_MSC_ENDPOINT_LIST(in_number, out_number) ( \
|
||||
CONCAT_2(NRF_DRV_USBD_EPIN, in_number), \
|
||||
CONCAT_2(NRF_DRV_USBD_EPOUT, out_number) \
|
||||
)
|
||||
|
||||
/**
|
||||
* @brief Global definition of app_usbd_msc_t class.
|
||||
*
|
||||
* @param instance_name Name of global instance.
|
||||
* @param interface_number Unique interface number.
|
||||
* @param user_ev_handler User event handler (optional).
|
||||
* @param endpoint_list Input endpoint list (@ref nrf_drv_usbd_ep_t).
|
||||
* @param blockdev_list Block device list.
|
||||
* @param workbuffer_size Work buffer size (need to fit into all block devices from
|
||||
* block device list).
|
||||
*
|
||||
* @note This macro is just simplified version of @ref APP_USBD_MSC_GLOBAL_DEF_INTERNAL
|
||||
*
|
||||
*/
|
||||
#define APP_USBD_MSC_GLOBAL_DEF(instance_name, \
|
||||
interface_number, \
|
||||
user_ev_handler, \
|
||||
endpoint_list, \
|
||||
blockdev_list, \
|
||||
workbuffer_size) \
|
||||
APP_USBD_MSC_GLOBAL_DEF_INTERNAL(instance_name, \
|
||||
interface_number, \
|
||||
user_ev_handler, \
|
||||
endpoint_list, \
|
||||
blockdev_list, \
|
||||
workbuffer_size)
|
||||
|
||||
|
||||
/**
|
||||
* @@brief Helper function to get class instance from MSC.
|
||||
*
|
||||
* @param[in] p_msc MSC instance (declared by @ref APP_USBD_MSC_GLOBAL_DEF).
|
||||
*
|
||||
* @return Base class instance.
|
||||
*/
|
||||
static inline app_usbd_class_inst_t const *
|
||||
app_usbd_msc_class_inst_get(app_usbd_msc_t const * p_msc)
|
||||
{
|
||||
return &p_msc->base;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Helper function to get MSC from base class instance.
|
||||
*
|
||||
* @param[in] p_inst Base class instance.
|
||||
*
|
||||
* @return MSC class handle.
|
||||
*/
|
||||
static inline app_usbd_msc_t const * app_usbd_msc_class_get(app_usbd_class_inst_t const * p_inst)
|
||||
{
|
||||
return (app_usbd_msc_t const *)p_inst;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Synchronization of all block devices pined to MSC.
|
||||
*
|
||||
* @param[in] p_msc MSC instance (declared by @ref APP_USBD_MSC_GLOBAL_DEF).
|
||||
*
|
||||
* @retval true All block devices flushed data.
|
||||
* @retval false At least one block device has not flushed data.
|
||||
*/
|
||||
bool app_usbd_msc_sync(app_usbd_msc_t const * p_msc);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_MSC_H__ */
|
||||
104
components/libraries/usbd/class/msc/app_usbd_msc_desc.h
Normal file
104
components/libraries/usbd/class/msc/app_usbd_msc_desc.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* 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, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, 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 Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS 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.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_USBD_MSC_DESC_H__
|
||||
#define APP_USBD_MSC_DESC_H__
|
||||
|
||||
#include "app_usbd_descriptor.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_msc_desc USB MSC descriptors
|
||||
* @ingroup app_usbd_msc
|
||||
*
|
||||
* @brief @tagAPI52840 Descriptors for the USB MSC class.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initializer of interface descriptor for MSC class.
|
||||
*
|
||||
* @param interface_number Interface number.
|
||||
* @param subclass Subclass, @ref app_usbd_msc_subclass_t
|
||||
* @param protocol Protocol, @ref app_usbd_msc_protocol_t
|
||||
* */
|
||||
#define APP_USBD_MSC_INTERFACE_DSC(interface_number, subclass, protocol) \
|
||||
/*.bLength = */ sizeof(app_usbd_descriptor_iface_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_DESCRIPTOR_INTERFACE, \
|
||||
/*.bInterfaceNumber = */ interface_number, \
|
||||
/*.bAlternateSetting = */ 0x00, \
|
||||
/*.bNumEndpoints = */ 2, \
|
||||
/*.bInterfaceClass = */ APP_USBD_MSC_CLASS, \
|
||||
/*.bInterfaceSubClass = */ subclass, \
|
||||
/*.bInterfaceProtocol = */ protocol, \
|
||||
/*.iInterface = 0, */ 0x00, \
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initializer of endpoint descriptors for MSC class.
|
||||
*
|
||||
* @param endpoint_in IN endpoint.
|
||||
* @param endpoint_out OUT endpoint.
|
||||
* @param ep_size Endpoint size.
|
||||
* */
|
||||
#define APP_USBD_MSC_EP_DSC(endpoint_in, endpoint_out, ep_size) \
|
||||
/*.bLength = */ sizeof(app_usbd_descriptor_ep_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_DESCRIPTOR_ENDPOINT, \
|
||||
/*.bEndpointAddress = */ endpoint_in, \
|
||||
/*.bmAttributes = */ APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_BULK, \
|
||||
/*.wMaxPacketSize = */ APP_USBD_U16_TO_RAW_DSC(ep_size), \
|
||||
/*.bInterval = */ 0, \
|
||||
/*.bLength = */ sizeof(app_usbd_descriptor_ep_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_DESCRIPTOR_ENDPOINT, \
|
||||
/*.bEndpointAddress = */ endpoint_out, \
|
||||
/*.bmAttributes = */ APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_BULK, \
|
||||
/*.wMaxPacketSize = */ APP_USBD_U16_TO_RAW_DSC(ep_size), \
|
||||
/*.bInterval = */ 0, \
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_MSC_DESC_H__ */
|
||||
314
components/libraries/usbd/class/msc/app_usbd_msc_internal.h
Normal file
314
components/libraries/usbd/class/msc/app_usbd_msc_internal.h
Normal file
@@ -0,0 +1,314 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* 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, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, 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 Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS 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.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_USBD_MSC_INTERNAL_H__
|
||||
#define APP_USBD_MSC_INTERNAL_H__
|
||||
|
||||
#include "app_util.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_msc_internals USB MSC internals
|
||||
* @ingroup app_usbd_msc
|
||||
*
|
||||
* @brief @tagAPI52840 Internals of the USB MSC class.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Minimal serial string descriptor length.
|
||||
* */
|
||||
#define APP_USBD_MSC_MINIMAL_SERIAL_STRING_SIZE (12 + 1)
|
||||
|
||||
/**
|
||||
* @brief Number of block buffers
|
||||
*
|
||||
* Number of buffers used for the transfer.
|
||||
* The library is designed to work with double buffering.
|
||||
* Not tested with other configuration.
|
||||
*/
|
||||
#define APP_USBD_MSC_BUFFER_CNT 2
|
||||
|
||||
/**
|
||||
* @brief Create the name of the block buffer
|
||||
*
|
||||
* @param instance_name The name of the MSC instance
|
||||
*
|
||||
* @return The name of the block buffer used with the instance
|
||||
*/
|
||||
#define APP_USBD_MSC_BUFFER_NAME(instance_name) CONCAT_2(instance_name, _block)
|
||||
|
||||
/**
|
||||
* @brief Create the name of the block device list
|
||||
*
|
||||
* @param instance_name The name of the MSC instance
|
||||
*
|
||||
* @return The name of the block device list
|
||||
*/
|
||||
#define APP_USBD_MSC_BLKDEVS_NAME(instance_name) CONCAT_2(instance_name, _blkdevs)
|
||||
|
||||
/**
|
||||
* @brief Forward declaration of Mass Storage Class type.
|
||||
*
|
||||
*/
|
||||
APP_USBD_CLASS_FORWARD(app_usbd_msc);
|
||||
|
||||
/*lint -save -e165*/
|
||||
/**
|
||||
* @brief Forward declaration of @ref app_usbd_msc_user_event_e
|
||||
*
|
||||
*/
|
||||
enum app_usbd_msc_user_event_e;
|
||||
|
||||
/*lint -restore*/
|
||||
|
||||
/**
|
||||
* @brief User event handler.
|
||||
*
|
||||
* @param[in] p_inst Class instance.
|
||||
* @param[in] event User event.
|
||||
*
|
||||
* */
|
||||
typedef void (*app_usbd_msc_user_ev_handler_t)(app_usbd_class_inst_t const * p_inst,
|
||||
enum app_usbd_msc_user_event_e event);
|
||||
|
||||
/**
|
||||
* @brief MSC part of class instance data.
|
||||
*/
|
||||
typedef struct {
|
||||
void * p_block_buff; //!< Block buffer
|
||||
size_t block_buff_size; //!< Block buffer size (typically 512 bytes)
|
||||
size_t block_buff_count; //!< Number of buffers (typically 2)
|
||||
|
||||
nrf_block_dev_t const ** pp_block_devs; //!< Block devices list
|
||||
size_t block_devs_count; //!< Block device list size
|
||||
|
||||
app_usbd_msc_user_ev_handler_t user_ev_handler; //!< User event handler
|
||||
|
||||
app_usbd_msc_subclass_t subclass; //!< MSC subclass
|
||||
app_usbd_msc_protocol_t protocol; //!< MSC protocol
|
||||
} app_usbd_msc_inst_t;
|
||||
|
||||
/**
|
||||
* @brief Internal module state.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_MSC_STATE_DISABLED, /**< Internal module state DISABLED */
|
||||
APP_USBD_MSC_STATE_IDLE, /**< Internal module state IDLE */
|
||||
APP_USBD_MSC_STATE_CBW, /**< Internal module state CBW */
|
||||
APP_USBD_MSC_STATE_CMD_IN, /**< Internal module state CMD_IN */
|
||||
APP_USBD_MSC_STATE_DATA_IN, /**< Internal module state DATA_IN */
|
||||
APP_USBD_MSC_STATE_DATA_OUT, /**< Internal module state DATA_OUT */
|
||||
APP_USBD_MSC_STATE_CSW, /**< Internal module state CSW */
|
||||
APP_USBD_MSC_STATE_UNSUPPORTED, /**< Internal module state UNSUPPORTED */
|
||||
APP_USBD_MSC_STATE_CBW_INVALID, /**< Endpoint is stalled until
|
||||
* the command @ref APP_USBD_MSC_REQ_BULK_RESET */
|
||||
APP_USBD_MSC_STATE_DEVICE_ERROR, /**< Endpoint is stalled and it is required
|
||||
* to send PE error when clearing */
|
||||
} app_usbd_msc_state_t;
|
||||
|
||||
/**
|
||||
* @brief MSC context.
|
||||
*
|
||||
* */
|
||||
typedef struct {
|
||||
app_usbd_msc_state_t state; //!< Internal module state
|
||||
|
||||
app_usbd_msc_cbw_t cbw; //!< SCSI command block wrapper
|
||||
app_usbd_msc_csw_t csw; //!< SCSI Command status wrapper
|
||||
|
||||
/** @brief Currently processed command with data */
|
||||
struct
|
||||
{
|
||||
/** @brief Buffer data */
|
||||
struct
|
||||
{
|
||||
uint8_t rd_idx; //!< Buffer read index
|
||||
uint8_t d_count; //!< Number of blocks inside the buffer ready to process
|
||||
uint8_t a_count; //!< Number of blocks allocated in the buffer
|
||||
} buff;
|
||||
/** @brief Currently transfered block */
|
||||
struct
|
||||
{
|
||||
size_t size_left; //!< Number of bytes left to transfer
|
||||
size_t datalen_left; //!< Number of bytes left that was requested by the host
|
||||
bool pending; //!< The flag marking the pending transfer
|
||||
bool abort; //!< Something fails during reading - abort transfer and mark an error,
|
||||
//!< Used for read access.
|
||||
} transfer;
|
||||
/** @brief The block currently processed by block device */
|
||||
struct
|
||||
{
|
||||
uint8_t lun; //!< The logical unit for current transfer block
|
||||
size_t blk_size; //!< The size of the block of the selected lun
|
||||
size_t size_left; //!< Number of bytes left to be processed by block device
|
||||
size_t datalen_left; //!< Number of bytes left that was requested by the host
|
||||
uint32_t blk_idx; //!< Current block index
|
||||
bool pending; //!< The flag marking the pending transfer
|
||||
bool abort; //!< Something fails during transfer - abort processing and mark an error,
|
||||
//!< Used for write access.
|
||||
} process;
|
||||
} current;
|
||||
|
||||
/** @brief SCSI response container*/
|
||||
union {
|
||||
app_usbd_scsi_cmd_inquiry_resp_t inquiry; //!< @ref APP_USBD_SCSI_CMD_INQUIRY response
|
||||
app_usbd_scsi_cmd_requestsense_resp_t requestsense; //!< @ref APP_USBD_SCSI_CMD_REQUESTSENSE response
|
||||
app_usbd_scsi_cmd_readcapacity10_resp_t readcapacity10; //!< @ref APP_USBD_SCSI_CMD_READCAPACITY10 response
|
||||
app_usbd_scsi_cmd_modesense6_resp_t modesense6; //!< @ref APP_USBD_SCSI_CMD_MODESENSE6 response
|
||||
app_usbd_scsi_cmd_modesense10_resp_t modesense10; //!< @ref APP_USBD_SCSI_CMD_MODESENSE10 response
|
||||
} scsi_resp;
|
||||
|
||||
uint16_t blk_dev_init_mask; //!< Block devices init mask
|
||||
} app_usbd_msc_ctx_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief MSC configuration macro.
|
||||
*
|
||||
* Used by @ref APP_USBD_MSC_GLOBAL_DEF
|
||||
*
|
||||
* @param iface Interface number.
|
||||
* @param endpoints Endpoint list.
|
||||
* */
|
||||
#define APP_USBD_MSC_CONFIG(iface, endpoints) ((iface, BRACKET_EXTRACT(endpoints)))
|
||||
|
||||
|
||||
/**
|
||||
* @brief Specific class constant data for MSC.
|
||||
*
|
||||
* @ref app_usbd_msc_inst_t
|
||||
*/
|
||||
#define APP_USBD_MSC_INSTANCE_SPECIFIC_DEC app_usbd_msc_inst_t inst;
|
||||
|
||||
/**
|
||||
* @brief Configures MSC instance.
|
||||
*
|
||||
* @param p_devs Block devices list that is array of pointers of @ref nrf_block_dev_t type.
|
||||
* @param devs_cnt Number of block devices connected.
|
||||
* @param p_buff Block buffer.
|
||||
* @param block_size Total size of the single block in the buffer.
|
||||
* @param block_cnt Number of available block buffers.
|
||||
* @param user_event_handler User event handler.
|
||||
*/
|
||||
#define APP_USBD_MSC_INST_CONFIG(p_devs, \
|
||||
devs_cnt, \
|
||||
p_buff, \
|
||||
block_size, \
|
||||
block_cnt, \
|
||||
user_event_handler) \
|
||||
.inst = { \
|
||||
.pp_block_devs = (p_devs), \
|
||||
.block_devs_count = (devs_cnt), \
|
||||
.p_block_buff = (p_buff), \
|
||||
.block_buff_size = (block_size), \
|
||||
.block_buff_count = (block_cnt), \
|
||||
.user_ev_handler = (user_event_handler), \
|
||||
.subclass = APP_USBD_MSC_SUBCLASS_TRANSPARENT, \
|
||||
.protocol = APP_USBD_MSC_PROTOCOL_BULK, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Specific class data for MSC.
|
||||
*
|
||||
* @ref app_usbd_msc_ctx_t
|
||||
* */
|
||||
#define APP_USBD_MSC_DATA_SPECIFIC_DEC app_usbd_msc_ctx_t ctx;
|
||||
|
||||
|
||||
/**
|
||||
* @brief MSC descriptors config macro.
|
||||
*
|
||||
* @param interface_number Interface number.
|
||||
* @param ... Extracted endpoint list.
|
||||
* */
|
||||
#define APP_USBD_MSC_DSC_CONFIG(interface_number, ...) { \
|
||||
APP_USBD_MSC_INTERFACE_DSC(interface_number, \
|
||||
APP_USBD_MSC_SUBCLASS_TRANSPARENT, \
|
||||
APP_USBD_MSC_PROTOCOL_BULK) \
|
||||
APP_USBD_MSC_EP_DSC(GET_VA_ARG_1(__VA_ARGS__), \
|
||||
GET_VA_ARG_1(GET_ARGS_AFTER_1(__VA_ARGS__)), \
|
||||
64) \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Public MSC class interface.
|
||||
*
|
||||
* */
|
||||
extern const app_usbd_class_methods_t app_usbd_msc_class_methods;
|
||||
|
||||
/**
|
||||
* @brief Global definition of mass storage class instance.
|
||||
*/
|
||||
#define APP_USBD_MSC_GLOBAL_DEF_INTERNAL(instance_name, \
|
||||
interface_number, \
|
||||
user_ev_handler, \
|
||||
endpoint_list, \
|
||||
blockdev_list, \
|
||||
workbuffer_size) \
|
||||
static const nrf_block_dev_t * APP_USBD_MSC_BLKDEVS_NAME(instance_name)[] = \
|
||||
{ BRACKET_EXTRACT(blockdev_list) }; \
|
||||
static uint32_t APP_USBD_MSC_BUFFER_NAME(instance_name) \
|
||||
[APP_USBD_MSC_BUFFER_CNT * CEIL_DIV(workbuffer_size, sizeof(uint32_t))]; \
|
||||
APP_USBD_CLASS_INST_GLOBAL_DEF( \
|
||||
instance_name, \
|
||||
app_usbd_msc, \
|
||||
&app_usbd_msc_class_methods, \
|
||||
APP_USBD_MSC_CONFIG(interface_number, endpoint_list), \
|
||||
(APP_USBD_MSC_INST_CONFIG(APP_USBD_MSC_BLKDEVS_NAME(instance_name), \
|
||||
ARRAY_SIZE(APP_USBD_MSC_BLKDEVS_NAME(instance_name)), \
|
||||
APP_USBD_MSC_BUFFER_NAME (instance_name), \
|
||||
sizeof(APP_USBD_MSC_BUFFER_NAME(instance_name)) \
|
||||
/ APP_USBD_MSC_BUFFER_CNT, \
|
||||
APP_USBD_MSC_BUFFER_CNT, \
|
||||
user_ev_handler)) \
|
||||
)
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_MSC_INTERNAL_H__ */
|
||||
329
components/libraries/usbd/class/msc/app_usbd_msc_scsi.h
Normal file
329
components/libraries/usbd/class/msc/app_usbd_msc_scsi.h
Normal file
@@ -0,0 +1,329 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* 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, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, 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 Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS 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.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_USBD_MSC_SCSI_H__
|
||||
#define APP_USBD_MSC_SCSI_H__
|
||||
|
||||
#include "app_util.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_msc_scsi USB MSC SCSI data structures
|
||||
* @ingroup app_usbd_msc
|
||||
*
|
||||
* @brief @tagAPI52840 USB MSC SCSI data structures.
|
||||
*
|
||||
* @details Reference specifications:
|
||||
* - "Reduced Block Commands (Revision 10a)" American National Standard
|
||||
* for Information Technology, August 18, 1999
|
||||
* - "SCSI Primary Commands - 4 (SPC-4)," American National Standard
|
||||
* for Information Technology, July 19, 2008
|
||||
* - "SCSI Block Commands -2 (SBC-2)," American National Standard
|
||||
* for Information Technology, November 13, 2004
|
||||
* - NuttX source code - Real-time Operating System: http://nuttx.org/
|
||||
* Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief SCSI command set.
|
||||
*
|
||||
* Mandatory (and some optional) commands required by SBC-2.
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_SCSI_CMD_TESTUNITREADY = 0x00, /**< Test unit ready. */
|
||||
APP_USBD_SCSI_CMD_REQUESTSENSE = 0x03, /**< Request sense. */
|
||||
APP_USBD_SCSI_CMD_FORMAT_UNIT = 0x04, /**< Format unit. */
|
||||
APP_USBD_SCSI_CMD_READ6 = 0x08, /**< Read 6. */
|
||||
APP_USBD_SCSI_CMD_WRITE6 = 0x0A, /**< Write 6. */
|
||||
APP_USBD_SCSI_CMD_INQUIRY = 0x12, /**< Inquiry. */
|
||||
APP_USBD_SCSI_CMD_MODESELECT6 = 0x15, /**< Mode select 6. */
|
||||
APP_USBD_SCSI_CMD_MODESENSE6 = 0x1A, /**< Mode sense 6. */
|
||||
APP_USBD_SCSI_CMD_STARTSTOPUNIT = 0x1B, /**< Start/stop unit. */
|
||||
APP_USBD_SCSI_CMD_SENDDIAGNOSTIC = 0x1D, /**< Send diagnostic. */
|
||||
APP_USBD_SCSI_CMD_PREVENTMEDIAREMOVAL = 0x1E, /**< Prevent media removal. */
|
||||
APP_USBD_SCSI_CMD_READCAPACITY10 = 0x25, /**< Read capacity 10. */
|
||||
APP_USBD_SCSI_CMD_READ10 = 0x28, /**< Read 10. */
|
||||
APP_USBD_SCSI_CMD_WRITE10 = 0x2A, /**< Write 10. */
|
||||
APP_USBD_SCSI_CMD_MODESELECT10 = 0x55, /**< Mode select 10. */
|
||||
APP_USBD_SCSI_CMD_MODESENSE10 = 0x5A, /**< Mode sense 10. */
|
||||
} app_usbd_scsi_cmd_t;
|
||||
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
/**
|
||||
* @brief Payload of @ref APP_USBD_SCSI_CMD_REQUESTSENSE command.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t opcode; //!< @ref APP_USBD_SCSI_CMD_REQUESTSENSE
|
||||
uint8_t flags; //!< Flags
|
||||
uint8_t reserved[2]; //!< Reserved
|
||||
uint8_t alloclen; //!< Allocation length
|
||||
uint8_t control; //!< Control
|
||||
} app_usbd_scsi_cmd_requestsense_t;
|
||||
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_CODE_VALID 0x80 /**< @ref app_usbd_scsi_cmd_requestsense_resp_t::code */
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_CODE_CURRENT 0x70 /**< @ref app_usbd_scsi_cmd_requestsense_resp_t::code */
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_CODE_DEFERRED 0x71 /**< @ref app_usbd_scsi_cmd_requestsense_resp_t::code */
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_CODE_CURRENTDESC 0x72 /**< @ref app_usbd_scsi_cmd_requestsense_resp_t::code */
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_CODE_DEFERREDDESC 0x73 /**< @ref app_usbd_scsi_cmd_requestsense_resp_t::code */
|
||||
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_FLAG_FILEMARK 0x80 /**< Bits 7 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_FLAG_EOM 0x40 /**< Bits 6 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_FLAG_ILI 0x20 /**< Bits 5 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_FLAG_RESERVED 0x10 /**< Bits 4 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
|
||||
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_FLAG_NOSENSE 0x00 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_FLAG_RECOVEREDERROR 0x01 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_FLAG_NOTREADY 0x02 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_FLAG_MEDIUMERROR 0x03 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_FLAG_HARDWAREERROR 0x04 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_FLAG_ILLEGALREQUEST 0x05 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_FLAG_UNITATTENTION 0x06 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_FLAG_DATAPROTECT 0x07 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_FLAG_BLANKCHECK 0x08 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_FLAG_VENDORSPECIFIC 0x09 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
|
||||
#define APP_USBD_SCSI_CMD_REQSENSE_FLAG_ABORTEDCOMMAND 0x0B /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
|
||||
|
||||
|
||||
#define APP_USBD_SCSI_CMD_TESTUNITREADY_LEN 6 /**< @ref APP_USBD_SCSI_CMD_TESTUNITREADY command length*/
|
||||
|
||||
/**
|
||||
* @brief Payload of @ref APP_USBD_SCSI_CMD_REQUESTSENSE response.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t code; //!< Response code: APP_USBD_SCSI_CMD_REQSENSE_CODE_*
|
||||
uint8_t obsolete; //!< Obsolete
|
||||
uint8_t flags; //!< APP_USBD_SCSI_CMD_REQSENSE_FLAG_*
|
||||
uint8_t info[4]; //!< Information
|
||||
uint8_t len; //!< Additional length
|
||||
uint8_t cmdinfo[4]; //!< Command-specific information
|
||||
uint8_t code2; //!< Additional sense code
|
||||
uint8_t qual2; //!< Additional sense code qualifier
|
||||
uint8_t fru; //!< Field replacement unit code
|
||||
uint8_t key[3]; //!< Sense key specific
|
||||
} app_usbd_scsi_cmd_requestsense_resp_t;
|
||||
|
||||
/**
|
||||
* @brief Payload of @ref APP_USBD_SCSI_CMD_INQUIRY command.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t opcode; //!< @ref APP_USBD_SCSI_CMD_INQUIRY
|
||||
uint8_t flags; //!< Command flags
|
||||
uint8_t pagecode; //!< Page code
|
||||
uint8_t alloclen[2]; //!< Allocation length
|
||||
uint8_t control; //!< Control
|
||||
} app_usbd_scsi_cmd_inquiry_t;
|
||||
|
||||
#define APP_USBD_MSC_SCSI_INQ_QUAL_CONNECTED 0x00 /**< Peripheral connected */
|
||||
#define APP_USBD_MSC_SCSI_INQ_QUAL_NOT_CONN 0x20 /**< Peripheral not connected */
|
||||
#define APP_USBD_MSC_SCSI_INQ_QUAL_NOT_SUPP 0x60 /**< Peripheral not supported */
|
||||
|
||||
#define APP_USBD_MSC_SCSI_INQ_TYPE_DIR_ACCESS 0x00 /**< Direct Access (SBC) */
|
||||
#define APP_USBD_MSC_SCSI_INQ_TYPE_SEQ_ACCESS 0x01 /**< Sequential Access */
|
||||
#define APP_USBD_MSC_SCSI_INQ_TYPE_PRINTER 0x02 /**< Printer */
|
||||
#define APP_USBD_MSC_SCSI_INQ_TYPE_PROCESSOR 0x03 /**< Processor device */
|
||||
#define APP_USBD_MSC_SCSI_INQ_TYPE_WRITE_ONCE 0x04 /**< Write-once device */
|
||||
#define APP_USBD_MSC_SCSI_INQ_TYPE_CD_DVD 0x05 /**< CD/DVD device */
|
||||
#define APP_USBD_MSC_SCSI_INQ_TYPE_OPTICAL 0x07 /**< Optical Memory */
|
||||
#define APP_USBD_MSC_SCSI_INQ_TYPE_MC 0x08 /**< Medium Changer */
|
||||
#define APP_USBD_MSC_SCSI_INQ_TYPE_ARRAY 0x0C /**< Storage Array Controller */
|
||||
#define APP_USBD_MSC_SCSI_INQ_TYPE_ENCLOSURE 0x0D /**< Enclosure Services */
|
||||
#define APP_USBD_MSC_SCSI_INQ_TYPE_RBC 0x0E /**< Simplified Direct Access */
|
||||
#define APP_USBD_MSC_SCSI_INQ_TYPE_OCRW 0x0F /**< Optical card reader/writer */
|
||||
#define APP_USBD_MSC_SCSI_INQ_TYPE_BCC 0x10 /**< Bridge Controller Commands */
|
||||
#define APP_USBD_MSC_SCSI_INQ_TYPE_OSD 0x11 /**< Object-based Storage */
|
||||
#define APP_USBD_MSC_SCSI_INQ_TYPE_NONE 0x1F /**< No Peripheral */
|
||||
|
||||
|
||||
#define APP_USBD_MSC_SCSI_INQ_FLAG1_RMB 0x80 /**< Removable Medium */
|
||||
|
||||
#define APP_USBD_SCSI_INQ_VER_NONE 0x00 /**< No standards conformance */
|
||||
#define APP_USBD_SCSI_INQ_VER_SPC 0x03 /**< SCSI Primary Commands (link to SBC) */
|
||||
#define APP_USBD_SCSI_INQ_VER_SPC2 0x04 /**< SCSI Primary Commands - 2 (link to SBC-2)*/
|
||||
#define APP_USBD_SCSI_INQ_VER_SPC3 0x05 /**< SCSI Primary Commands - 3 (link to SBC-2)*/
|
||||
#define APP_USBD_SCSI_INQ_VER_SPC4 0x06 /**< SCSI Primary Commands - 4 (link to SBC-3)*/
|
||||
|
||||
#define APP_USBD_MSC_SCSI_INQ_FLAG2_NORMACA 0x20 /**< Normal ACA Supported */
|
||||
#define APP_USBD_MSC_SCSI_INQ_FLAG2_HISUP 0x10 /**< Hierarchal LUN addressing */
|
||||
#define APP_USBD_MSC_SCSI_INQ_FLAG2_RSP_SPC2 0x02 /**< SPC-2 / SPC-3 response format*/
|
||||
/**
|
||||
* @brief Payload of @ref APP_USBD_SCSI_CMD_INQUIRY response.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t qualtype; //!< Bits 5-7: Peripheral qualifier; Bits 0-4: Peripheral device type
|
||||
uint8_t flags1; //!< Flags 1
|
||||
uint8_t version; //!< Version
|
||||
uint8_t flags2; //!< Flags 2
|
||||
uint8_t len; //!< Additional length
|
||||
uint8_t flags3; //!< Flags 3
|
||||
uint8_t flags4; //!< Flags 4
|
||||
uint8_t flags5; //!< Flags 5
|
||||
uint8_t vendorid[8]; //!< T10 Vendor Identification
|
||||
uint8_t productid[16]; //!< Product Identification
|
||||
uint8_t revision[4]; //!< Product Revision Level
|
||||
} app_usbd_scsi_cmd_inquiry_resp_t;
|
||||
|
||||
/**
|
||||
* @brief Payload of @ref APP_USBD_SCSI_CMD_READ6 command.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t opcode; //!< @ref APP_USBD_SCSI_CMD_READ6
|
||||
uint8_t mslba; //!< Bits 5-7: reserved; Bits 0-6: MS Logical Block Address (LBA)
|
||||
uint8_t lslba[2]; //!< LS Logical Block Address (LBA)
|
||||
uint8_t xfrlen; //!< Transfer length (in contiguous logical blocks)
|
||||
uint8_t control; //!< Control
|
||||
} app_usbd_scsi_cmd_read6_t;
|
||||
|
||||
/**
|
||||
* @brief Payload of @ref APP_USBD_SCSI_CMD_WRITE6 command.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t opcode; //!< @ref APP_USBD_SCSI_CMD_WRITE6
|
||||
uint8_t mslba; //!< Bits 5-7: reserved; Bits 0-6: MS Logical Block Address (LBA)
|
||||
uint8_t lslba[2]; //!< LS Logical Block Address (LBA)
|
||||
uint8_t xfrlen; //!< Transfer length (in contiguous logical blocks)
|
||||
uint8_t control; //!< Control
|
||||
} app_usbd_scsi_cmd_write6_t;
|
||||
|
||||
/**
|
||||
* @brief Payload of @ref APP_USBD_SCSI_CMD_MODESENSE6 command.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t opcode; //!<* @ref APP_USBD_SCSI_CMD_MODESENSE6
|
||||
uint8_t flags; //!<* Flags
|
||||
uint8_t pcpgcode; //!<* Bits 6-7: PC, bits 0-5: page code
|
||||
uint8_t subpgcode; //!<* subpage code
|
||||
uint8_t alloclen; //!<* Allocation length
|
||||
uint8_t control; //!<* Control
|
||||
} app_usbd_scsi_cmd_modesense6_t;
|
||||
|
||||
/**
|
||||
* @brief Payload of @ref APP_USBD_SCSI_CMD_MODESENSE6 response.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t mdlen; //!< Mode data length
|
||||
uint8_t type; //!< Medium type
|
||||
uint8_t param; //!< Device-specific parameter
|
||||
uint8_t bdlen; //!< Block descriptor length
|
||||
} app_usbd_scsi_cmd_modesense6_resp_t;
|
||||
|
||||
/**
|
||||
* @brief Payload of @ref APP_USBD_SCSI_CMD_READCAPACITY10 command.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t opcode; //!< @ref APP_USBD_SCSI_CMD_READCAPACITY10
|
||||
uint8_t reserved1; //!< Reserved field
|
||||
uint8_t lba[4]; //!< Logical block address (LBA)
|
||||
uint8_t reserved2[2]; //!< Reserved field
|
||||
uint8_t pmi; //!< Bits 1-7 Reserved; Bit 0: PMI
|
||||
uint8_t control; //!< Control
|
||||
} app_usbd_scsi_cmd_readcapacity10_t;
|
||||
|
||||
/**
|
||||
* @brief Payload of @ref APP_USBD_SCSI_CMD_READCAPACITY10 response.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t lba[4]; //!< Returned logical block address (LBA)
|
||||
uint8_t blklen[4]; //!< Logical block length (in bytes)
|
||||
} app_usbd_scsi_cmd_readcapacity10_resp_t;
|
||||
|
||||
/**
|
||||
* @brief Payload of @ref APP_USBD_SCSI_CMD_READ10 command.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t opcode; //!< @ref APP_USBD_SCSI_CMD_READ10
|
||||
uint8_t flags; //!< Command flags
|
||||
uint8_t lba[4]; //!< Logical Block Address (LBA)
|
||||
uint8_t groupno; //!< Bits 5-7: reserved; Bits 0-6: group number
|
||||
uint8_t xfrlen[2]; //!< Transfer length (in contiguous logical blocks)
|
||||
uint8_t control; //!< Control
|
||||
} app_usbd_scsi_cmd_read10_t;
|
||||
|
||||
/**
|
||||
* @brief Payload of @ref APP_USBD_SCSI_CMD_WRITE10 command.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t opcode; //!< @ref APP_USBD_SCSI_CMD_WRITE10
|
||||
uint8_t flags; //!< Command flags
|
||||
uint8_t lba[4]; //!< Logical Block Address (LBA)
|
||||
uint8_t groupno; //!< Bits 5-7: reserved; Bits 0-6: group number
|
||||
uint8_t xfrlen[2]; //!< Transfer length (in contiguous logical blocks)
|
||||
uint8_t control; //!< Control
|
||||
} app_usbd_scsi_cmd_write10_t;
|
||||
|
||||
/**
|
||||
* @brief Payload of @ref APP_USBD_SCSI_CMD_MODESENSE10 command.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t opcode; //!< @ref APP_USBD_SCSI_CMD_MODESENSE10
|
||||
uint8_t flags; //!< Flags
|
||||
uint8_t pcpgcode; //!< Bits 6-7: PC, bits 0-5: page code
|
||||
uint8_t subpgcode; //!< Subpage code
|
||||
uint8_t reserved[3]; //!< Reserved
|
||||
uint8_t alloclen[2]; //!< Allocation length
|
||||
uint8_t control; //!< Control
|
||||
} app_usbd_scsi_cmd_modesense10_t;
|
||||
|
||||
/**
|
||||
* @brief Payload of @ref APP_USBD_SCSI_CMD_MODESENSE10 response.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t mdlen[2]; //!< Mode data length
|
||||
uint8_t type; //!< Medium type
|
||||
uint8_t param; //!< Device-specific parameter
|
||||
uint8_t reserved[2]; //!< Reserved
|
||||
uint8_t bdlen[2]; //!< Block descriptor length
|
||||
} app_usbd_scsi_cmd_modesense10_resp_t;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_MSC_SCSI_H__ */
|
||||
148
components/libraries/usbd/class/msc/app_usbd_msc_types.h
Normal file
148
components/libraries/usbd/class/msc/app_usbd_msc_types.h
Normal file
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* 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, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, 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 Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS 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.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_USBD_MSC_TYPES_H__
|
||||
#define APP_USBD_MSC_TYPES_H__
|
||||
|
||||
#include "app_util.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_msc_types USB MSC types
|
||||
* @ingroup app_usbd_msc
|
||||
*
|
||||
* @brief @tagAPI52840 Types used in the USB MSC class.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @brief MSC class definition in interface descriptor
|
||||
*
|
||||
* @ref app_usbd_descriptor_iface_t::bInterfaceClass
|
||||
* */
|
||||
#define APP_USBD_MSC_CLASS 0x08
|
||||
|
||||
/**
|
||||
* @brief MSC subclass possible value.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_MSC_SUBCLASS_NOT_REPORTED = 0x00, /**< Command set not reported */
|
||||
APP_USBD_MSC_SUBCLASS_RBC = 0x01, /**< Reduced Block Commands */
|
||||
APP_USBD_MSC_SUBCLASS_ATAPI = 0x02, /**< CD/DVD devices */
|
||||
APP_USBD_MSC_SUBCLASS_QIC_157 = 0x03, /**< Tape devices */
|
||||
APP_USBD_MSC_SUBCLASS_UFI = 0x04, /**< Floppy disk drives */
|
||||
APP_USBD_MSC_SUBCLASS_SFF_8070I = 0x05, /**< Floppy disk drives */
|
||||
APP_USBD_MSC_SUBCLASS_TRANSPARENT = 0x06, /**< Determined by INQUIRY */
|
||||
APP_USBD_MSC_SUBCLASS_LSD_FS = 0x07, /**< LSD FS specified negitiation */
|
||||
APP_USBD_MSC_SUBCLASS_IEEE_1667 = 0x08, /**< IEEE 1607 */
|
||||
APP_USBD_MSC_SUBCLASS_VENDOR = 0xFF, /**< Vendor specific */
|
||||
} app_usbd_msc_subclass_t;
|
||||
|
||||
/**
|
||||
* @brief MSC protocol possible value.
|
||||
*
|
||||
* @note The USB Mass Storage Class Control/Bulk/Interrupt (CBI) Transport specification is approved
|
||||
* for use only with full-speed floppy disk drives. CBI shall not be used in high-speed
|
||||
* capable devices.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_MSC_PROTOCOL_CBI = 0x00, /**< Command/Bulk/Interrupt */
|
||||
APP_USBD_MSC_PROTOCOL_CBI_ALT = 0x01, /**< W/o command completion */
|
||||
APP_USBD_MSC_PROTOCOL_BULK = 0x50, /**< Bulk-only */
|
||||
APP_USBD_MSC_PROTOCOL_UAS = 0x62, /**< UAS */
|
||||
APP_USBD_MSC_PROTOCOL_VENDOR = 0xFF, /**< Vendor specific */
|
||||
} app_usbd_msc_protocol_t;
|
||||
|
||||
/**
|
||||
* @brief MSC USB requests @ref nrf_drv_usbd_setup_t::bmRequestType
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_MSC_REQ_ADSC = 0x00, /**< Accept Device-Specific Command */
|
||||
APP_USBD_MSC_REQ_GET_REQS = 0xFC, /**< Get Requests */
|
||||
APP_USBD_MSC_REQ_PUT_REQS = 0xFD, /**< Put Requests */
|
||||
APP_USBD_MSC_REQ_GET_MAX_LUN = 0xFE, /**< Get Max LUN */
|
||||
APP_USBD_MSC_REQ_BULK_RESET = 0xFF, /**< Mass Storage Reset */
|
||||
} app_usbd_msc_req_t;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
#define APP_USBD_MSC_CBW_SIGNATURE {'U', 'S', 'B', 'C'} /**< CBW signature */
|
||||
#define APP_USBD_MSC_CBW_DIRECTION_IN (1u << 7) /**< CBW direction flag */
|
||||
|
||||
/**
|
||||
* @brief Command Block Wrapper (CBW).
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t signature[4]; /**< "USBC" (hex: 0x43425355 little-endian) */
|
||||
uint8_t tag[4]; /**< Unique command tag */
|
||||
uint8_t datlen[4]; /**< Number of bytes that host expects to transfer */
|
||||
uint8_t flags; /**< Bit 7: Direction=IN */
|
||||
uint8_t lun; /**< Logical Unit Number, equals to @ref app_usbd_msc_inst_t :: block_devs_count*/
|
||||
uint8_t cdb_length; /**< Length of cdb field */
|
||||
uint8_t cdb[16]; /**< Command Data Block payload */
|
||||
} app_usbd_msc_cbw_t;
|
||||
|
||||
#define APP_USBD_MSC_CSW_SIGNATURE {'U', 'S', 'B', 'S'} /**< CSW signature */
|
||||
|
||||
#define APP_USBD_MSC_CSW_STATUS_PASS 0x00 /**< CSW status: Command Passed */
|
||||
#define APP_USBD_MSC_CSW_STATUS_FAIL 0x01 /**< CSW status: Command Failed */
|
||||
#define APP_USBD_MSC_CSW_STATUS_PE 0x02 /**< CSW status: Phase Error */
|
||||
|
||||
/**
|
||||
* @brief Command Status Wrapper (CSW).
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t signature[4]; /**< "USBS" (hex: 0x53425355 little-endian) */
|
||||
uint8_t tag[4]; /**< Unique command tag (@ref app_usbd_msc_cbw_t :: tag) */
|
||||
uint8_t residue[4]; /**< Amount not transferred */
|
||||
uint8_t status; /**< Status of transfer */
|
||||
} app_usbd_msc_csw_t;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_MSC_TYPES_H__ */
|
||||
Reference in New Issue
Block a user