implement msc device class

usbd auto stall control for not supported return from class control request
usbd implement xfer isr callback mechanism
DCD
- implement dcd multiple qtd support
- dcd dcd_pipe_stall
- implement dcd_pipe_queue_xfer
- xfer_complete_isr
- flush control endpoint if received new setup while previous transfer is not complete
change msc_cmd_block_wrapper_t flags field to dir
force full speed for easy testing

NOTEs: somehow unable to get endpoint IN interrupt with ioc
This commit is contained in:
hathach
2013-11-01 12:11:26 +07:00
parent c760c69d51
commit 3a54ad4c0d
28 changed files with 821 additions and 243 deletions

View File

@@ -0,0 +1,95 @@
/**************************************************************************/
/*!
@file mscd_app.c
@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.
*/
/**************************************************************************/
#include "mscd_app.h"
#if TUSB_CFG_DEVICE_MSC
//--------------------------------------------------------------------+
// INCLUDE
//--------------------------------------------------------------------+
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
static scsi_inquiry_data_t mscd_inquiry_data TUSB_CFG_ATTR_USBRAM =
{
.is_removable = 1,
.version = 2,
.response_data_format = 2,
.vendor_id = "tinyusb",
.product_id = "MSC Example",
.product_revision = "0.01"
} ;
static scsi_read_capacity10_data_t mscd_read_capacity10_data TUSB_CFG_ATTR_USBRAM =
{
.last_lba = (16*1024*1024)/512,
.block_size = 512
};
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
//--------------------------------------------------------------------+
// tinyusb callback (ISR context)
//--------------------------------------------------------------------+
msc_csw_status_t tusbd_msc_scsi_received_isr(uint8_t coreid, uint8_t lun, uint8_t scsi_cmd[16], void ** pp_buffer, uint16_t expected_length)
{
switch(scsi_cmd[0])
{
case SCSI_CMD_INQUIRY:
(*pp_buffer) = &mscd_inquiry_data;
break;
case SCSI_CMD_READ_CAPACITY_10:
break;
default: return MSC_CSW_STATUS_FAILED;
}
return MSC_CSW_STATUS_PASSED;
}
//--------------------------------------------------------------------+
// IMPLEMENTATION
//--------------------------------------------------------------------+
#endif

View File

@@ -0,0 +1,66 @@
/**************************************************************************/
/*!
@file mscd_app.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.
*/
/**************************************************************************/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_MSCD_APP_H_
#define _TUSB_MSCD_APP_H_
#include "boards/board.h"
#include "tusb.h"
#ifdef __cplusplus
extern "C" {
#endif
#if TUSB_CFG_DEVICE_MSC
#endif
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_MSCD_APP_H_ */
/** @} */

View File

@@ -81,6 +81,8 @@
//--------------------------------------------------------------------+
// DEVICE CONFIGURATION
//--------------------------------------------------------------------+
#define TUSB_CFG_DEVICE_FULLSPEED 1 // TODO refractor
#define TUSB_CFG_DEVICE_USE_ROM_DRIVER 0
//------------- descriptors -------------//
@@ -90,13 +92,13 @@
#define TUSB_CFG_DEVICE_VENDORID 0x1FC9 // NXP
//#define TUSB_CFG_DEVICE_PRODUCTID 0x4567
#define TUSB_CFG_DEVICE_CONTROL_PACKET_SIZE 64
#define TUSB_CFG_DEVICE_CONTROL_ENDOINT_SIZE 64
//------------- CLASS -------------//
#define TUSB_CFG_DEVICE_HID_KEYBOARD 1
#define TUSB_CFG_DEVICE_HID_MOUSE 1
#define TUSB_CFG_DEVICE_HID_KEYBOARD 0
#define TUSB_CFG_DEVICE_HID_MOUSE 0
#define TUSB_CFG_DEVICE_HID_GENERIC 0
#define TUSB_CFG_DEVICE_MSC 0
#define TUSB_CFG_DEVICE_MSC 1
#define TUSB_CFG_DEVICE_CDC 0
//--------------------------------------------------------------------+

View File

@@ -138,7 +138,7 @@ tusb_descriptor_device_t app_tusb_desc_device =
.bDeviceSubClass = 0x00,
.bDeviceProtocol = 0x00,
.bMaxPacketSize0 = TUSB_CFG_DEVICE_CONTROL_PACKET_SIZE,
.bMaxPacketSize0 = TUSB_CFG_DEVICE_CONTROL_ENDOINT_SIZE,
.idVendor = TUSB_CFG_DEVICE_VENDORID,
.idProduct = TUSB_CFG_PRODUCT_ID,
@@ -356,7 +356,7 @@ app_descriptor_configuration_t app_tusb_desc_configuration =
{
.bLength = sizeof(tusb_descriptor_interface_t),
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE,
.bInterfaceNumber = 3,
.bInterfaceNumber = INTERFACE_INDEX_MASS_STORAGE,
.bAlternateSetting = 0x00,
.bNumEndpoints = 2,
.bInterfaceClass = TUSB_CLASS_MSC,
@@ -371,7 +371,7 @@ app_descriptor_configuration_t app_tusb_desc_configuration =
.bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
.bEndpointAddress = 0x83,
.bmAttributes = { .xfer = TUSB_XFER_BULK },
.wMaxPacketSize = 512,
.wMaxPacketSize = { .size = 64 /*512*/ },
.bInterval = 1
},
@@ -381,7 +381,7 @@ app_descriptor_configuration_t app_tusb_desc_configuration =
.bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
.bEndpointAddress = 0x03,
.bmAttributes = { .xfer = TUSB_XFER_BULK },
.wMaxPacketSize = 512,
.wMaxPacketSize = { .size = 64 /*512*/ },
.bInterval = 1
},
#endif

View File

@@ -39,7 +39,7 @@
//--------------------------------------------------------------------+
// INCLUDE
//--------------------------------------------------------------------+
#include "mouse_app.h"
#include "msc_app.h"
#if TUSB_CFG_OS != TUSB_OS_NONE
#include "app_os_prio.h"

View File

@@ -46,9 +46,6 @@
#ifndef _TUSB_MSC_APP_H_
#define _TUSB_MSC_APP_H_
#include <stdint.h>
#include <stdbool.h>
#include "boards/board.h"
#include "tusb.h"