Review line ending handling (#4820)
* New line end handling rules * Normalize all the line endings
This commit is contained in:
@@ -1,233 +1,233 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Mass Storage class definitions.
|
||||
///
|
||||
/// See
|
||||
/// - <a
|
||||
/// href="http://www.usb.org/developers/devclass_docs/usb_msc_overview_1.2.pdf">
|
||||
/// USB Mass Storage Class Spec. Overview</a>
|
||||
/// - <a href="http://www.usb.org/developers/devclass_docs/usbmassbulk_10.pdf">
|
||||
/// USB Mass Storage Class Bulk-Only Transport</a>
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# Uses "MSD Requests" to check incoming requests from USB Host.
|
||||
/// -# Uses "MSD Subclass Codes" and "MSD Protocol Codes" to fill %device
|
||||
/// interface descriptors for a MSD %device.
|
||||
/// -# Handle the incoming Bulk data with "MSD CBW Definitions" and MSCbw
|
||||
/// structure.
|
||||
/// -# Prepare the outgoing Bulk data with "MSD CSW Definitions" and MSCsw
|
||||
/// structure.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSD_H
|
||||
#define MSD_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Requests"
|
||||
/// This page lists MSD-specific requests ( Actually for Bulk-only protocol ).
|
||||
///
|
||||
/// !Requests
|
||||
/// - MSD_BULK_ONLY_RESET
|
||||
/// - MSD_GET_MAX_LUN
|
||||
|
||||
/// Reset the mass storage %device and its associated interface.
|
||||
#define MSD_BULK_ONLY_RESET 0xFF
|
||||
/// Return the maximum LUN number supported by the %device.
|
||||
#define MSD_GET_MAX_LUN 0xFE
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Subclass Codes"
|
||||
/// This page lists the Subclass Codes for bInterfaceSubClass field.
|
||||
/// (Table 2.1, USB Mass Storage Class Spec. Overview)
|
||||
///
|
||||
/// !SubClasses
|
||||
/// - MSD_SUBCLASS_RBC
|
||||
/// - MSD_SUBCLASS_SFF_MCC
|
||||
/// - MSD_SUBCLASS_QIC
|
||||
/// - MSD_SUBCLASS_UFI
|
||||
/// - MSD_SUBCLASS_SFF
|
||||
/// - MSD_SUBCLASS_SCSI
|
||||
|
||||
/// Reduced Block Commands (RBC) T10
|
||||
#define MSD_SUBCLASS_RBC 0x01
|
||||
/// C/DVD devices
|
||||
#define MSD_SUBCLASS_SFF_MCC 0x02
|
||||
/// Tape device
|
||||
#define MSD_SUBCLASS_QIC 0x03
|
||||
/// Floppy disk drive (FDD) device
|
||||
#define MSD_SUBCLASS_UFI 0x04
|
||||
/// Floppy disk drive (FDD) device
|
||||
#define MSD_SUBCLASS_SFF 0x05
|
||||
/// SCSI transparent command set
|
||||
#define MSD_SUBCLASS_SCSI 0x06
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Protocol Codes"
|
||||
/// This page lists the Transport Protocol codes for MSD.
|
||||
/// (Table 3.1, USB Mass Storage Class Spec. Overview)
|
||||
///
|
||||
/// !Protocols
|
||||
/// - MSD_PROTOCOL_CBI_COMPLETION
|
||||
/// - MSD_PROTOCOL_CBI
|
||||
/// - MSD_PROTOCOL_BULK_ONLY
|
||||
|
||||
/// Control/Bulk/Interrupt (CBI) Transport (with command complete interrupt)
|
||||
#define MSD_PROTOCOL_CBI_COMPLETION 0x00
|
||||
/// Control/Bulk/Interrupt (CBI) Transport (no command complete interrupt)
|
||||
#define MSD_PROTOCOL_CBI 0x01
|
||||
/// Bulk-Only Transport
|
||||
#define MSD_PROTOCOL_BULK_ONLY 0x50
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Test unit control:
|
||||
#define CTRL_NOT_READY 0x00
|
||||
#define CTRL_GOOD 0x01
|
||||
#define CTRL_BUSY 0x02
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD CBW Definitions"
|
||||
/// This page lists the Command Block Wrapper (CBW) definitions.
|
||||
///
|
||||
/// !Constants
|
||||
/// - MSD_CBW_SIZE
|
||||
/// - MSD_CBW_SIGNATURE
|
||||
///
|
||||
/// !Fields
|
||||
/// - MSD_CBW_DEVICE_TO_HOST
|
||||
|
||||
/// Command Block Wrapper Size
|
||||
#define MSD_CBW_SIZE 31
|
||||
/// 'USBC' 0x43425355
|
||||
#define MSD_CBW_SIGNATURE 0x43425355
|
||||
|
||||
/// CBW bmCBWFlags field
|
||||
#define MSD_CBW_DEVICE_TO_HOST (1 << 7)
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD CSW Definitions"
|
||||
/// This page lists the Command Status Wrapper (CSW) definitions.
|
||||
///
|
||||
/// !Constants
|
||||
/// - MSD_CSW_SIZE
|
||||
/// - MSD_CSW_SIGNATURE
|
||||
///
|
||||
/// !Command Block Status Values
|
||||
/// (Table 5.3 , USB Mass Storage Class Bulk-Only Transport)
|
||||
/// - MSD_CSW_COMMAND_PASSED
|
||||
/// - MSD_CSW_COMMAND_FAILED
|
||||
/// - MSD_CSW_PHASE_ERROR
|
||||
|
||||
/// Command Status Wrapper Size
|
||||
#define MSD_CSW_SIZE 13
|
||||
/// 'USBS' 0x53425355
|
||||
#define MSD_CSW_SIGNATURE 0x53425355
|
||||
|
||||
/// Command Passed (good status)
|
||||
#define MSD_CSW_COMMAND_PASSED 0
|
||||
/// Command Failed
|
||||
#define MSD_CSW_COMMAND_FAILED 1
|
||||
/// Phase Error
|
||||
#define MSD_CSW_PHASE_ERROR 2
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Structures
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Command Block Wrapper (CBW),
|
||||
/// See Table 5.1, USB Mass Storage Class Bulk-Only Transport.
|
||||
///
|
||||
/// The CBW shall start on a packet boundary and shall end as a
|
||||
/// short packet with exactly 31 (1Fh) bytes transferred.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// 'USBC' 0x43425355 (little endian)
|
||||
unsigned int dCBWSignature;
|
||||
/// Must be the same as dCSWTag
|
||||
unsigned int dCBWTag;
|
||||
/// Number of bytes transfer
|
||||
unsigned int dCBWDataTransferLength;
|
||||
/// Indicates the directin of the transfer:
|
||||
/// 0x80=IN=device-to-host,
|
||||
/// 0x00=OUT=host-to-device
|
||||
unsigned char bmCBWFlags;
|
||||
/// bits 0->3: bCBWLUN
|
||||
unsigned char bCBWLUN :4,
|
||||
bReserved1:4; /// reserved
|
||||
/// bits 0->4: bCBWCBLength
|
||||
unsigned char bCBWCBLength:5,
|
||||
bReserved2 :3; /// reserved
|
||||
/// Command block
|
||||
unsigned char pCommand[16];
|
||||
|
||||
} MSCbw;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Command Status Wrapper (CSW),
|
||||
/// See Table 5.2, USB Mass Storage Class Bulk-Only Transport.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct
|
||||
{
|
||||
/// 'USBS' 0x53425355 (little endian)
|
||||
unsigned int dCSWSignature;
|
||||
/// Must be the same as dCBWTag
|
||||
unsigned int dCSWTag;
|
||||
/// For Data-Out the device shall report in the dCSWDataResidue the
|
||||
/// difference between the amount of data expected as stated in the
|
||||
/// dCBWDataTransferLength, and the actual amount of data processed by
|
||||
/// the device. For Data-In the device shall report in the dCSWDataResidue
|
||||
/// the difference between the amount of data expected as stated in the
|
||||
/// dCBWDataTransferLength and the actual amount of relevant data sent by
|
||||
/// the device. The dCSWDataResidue shall not exceed the value sent in the
|
||||
/// dCBWDataTransferLength.
|
||||
unsigned int dCSWDataResidue;
|
||||
/// Indicates the success or failure of the command.
|
||||
unsigned char bCSWStatus;
|
||||
|
||||
} MSCsw;
|
||||
|
||||
#endif //#ifndef MSD_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Mass Storage class definitions.
|
||||
///
|
||||
/// See
|
||||
/// - <a
|
||||
/// href="http://www.usb.org/developers/devclass_docs/usb_msc_overview_1.2.pdf">
|
||||
/// USB Mass Storage Class Spec. Overview</a>
|
||||
/// - <a href="http://www.usb.org/developers/devclass_docs/usbmassbulk_10.pdf">
|
||||
/// USB Mass Storage Class Bulk-Only Transport</a>
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# Uses "MSD Requests" to check incoming requests from USB Host.
|
||||
/// -# Uses "MSD Subclass Codes" and "MSD Protocol Codes" to fill %device
|
||||
/// interface descriptors for a MSD %device.
|
||||
/// -# Handle the incoming Bulk data with "MSD CBW Definitions" and MSCbw
|
||||
/// structure.
|
||||
/// -# Prepare the outgoing Bulk data with "MSD CSW Definitions" and MSCsw
|
||||
/// structure.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSD_H
|
||||
#define MSD_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Requests"
|
||||
/// This page lists MSD-specific requests ( Actually for Bulk-only protocol ).
|
||||
///
|
||||
/// !Requests
|
||||
/// - MSD_BULK_ONLY_RESET
|
||||
/// - MSD_GET_MAX_LUN
|
||||
|
||||
/// Reset the mass storage %device and its associated interface.
|
||||
#define MSD_BULK_ONLY_RESET 0xFF
|
||||
/// Return the maximum LUN number supported by the %device.
|
||||
#define MSD_GET_MAX_LUN 0xFE
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Subclass Codes"
|
||||
/// This page lists the Subclass Codes for bInterfaceSubClass field.
|
||||
/// (Table 2.1, USB Mass Storage Class Spec. Overview)
|
||||
///
|
||||
/// !SubClasses
|
||||
/// - MSD_SUBCLASS_RBC
|
||||
/// - MSD_SUBCLASS_SFF_MCC
|
||||
/// - MSD_SUBCLASS_QIC
|
||||
/// - MSD_SUBCLASS_UFI
|
||||
/// - MSD_SUBCLASS_SFF
|
||||
/// - MSD_SUBCLASS_SCSI
|
||||
|
||||
/// Reduced Block Commands (RBC) T10
|
||||
#define MSD_SUBCLASS_RBC 0x01
|
||||
/// C/DVD devices
|
||||
#define MSD_SUBCLASS_SFF_MCC 0x02
|
||||
/// Tape device
|
||||
#define MSD_SUBCLASS_QIC 0x03
|
||||
/// Floppy disk drive (FDD) device
|
||||
#define MSD_SUBCLASS_UFI 0x04
|
||||
/// Floppy disk drive (FDD) device
|
||||
#define MSD_SUBCLASS_SFF 0x05
|
||||
/// SCSI transparent command set
|
||||
#define MSD_SUBCLASS_SCSI 0x06
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Protocol Codes"
|
||||
/// This page lists the Transport Protocol codes for MSD.
|
||||
/// (Table 3.1, USB Mass Storage Class Spec. Overview)
|
||||
///
|
||||
/// !Protocols
|
||||
/// - MSD_PROTOCOL_CBI_COMPLETION
|
||||
/// - MSD_PROTOCOL_CBI
|
||||
/// - MSD_PROTOCOL_BULK_ONLY
|
||||
|
||||
/// Control/Bulk/Interrupt (CBI) Transport (with command complete interrupt)
|
||||
#define MSD_PROTOCOL_CBI_COMPLETION 0x00
|
||||
/// Control/Bulk/Interrupt (CBI) Transport (no command complete interrupt)
|
||||
#define MSD_PROTOCOL_CBI 0x01
|
||||
/// Bulk-Only Transport
|
||||
#define MSD_PROTOCOL_BULK_ONLY 0x50
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Test unit control:
|
||||
#define CTRL_NOT_READY 0x00
|
||||
#define CTRL_GOOD 0x01
|
||||
#define CTRL_BUSY 0x02
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD CBW Definitions"
|
||||
/// This page lists the Command Block Wrapper (CBW) definitions.
|
||||
///
|
||||
/// !Constants
|
||||
/// - MSD_CBW_SIZE
|
||||
/// - MSD_CBW_SIGNATURE
|
||||
///
|
||||
/// !Fields
|
||||
/// - MSD_CBW_DEVICE_TO_HOST
|
||||
|
||||
/// Command Block Wrapper Size
|
||||
#define MSD_CBW_SIZE 31
|
||||
/// 'USBC' 0x43425355
|
||||
#define MSD_CBW_SIGNATURE 0x43425355
|
||||
|
||||
/// CBW bmCBWFlags field
|
||||
#define MSD_CBW_DEVICE_TO_HOST (1 << 7)
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD CSW Definitions"
|
||||
/// This page lists the Command Status Wrapper (CSW) definitions.
|
||||
///
|
||||
/// !Constants
|
||||
/// - MSD_CSW_SIZE
|
||||
/// - MSD_CSW_SIGNATURE
|
||||
///
|
||||
/// !Command Block Status Values
|
||||
/// (Table 5.3 , USB Mass Storage Class Bulk-Only Transport)
|
||||
/// - MSD_CSW_COMMAND_PASSED
|
||||
/// - MSD_CSW_COMMAND_FAILED
|
||||
/// - MSD_CSW_PHASE_ERROR
|
||||
|
||||
/// Command Status Wrapper Size
|
||||
#define MSD_CSW_SIZE 13
|
||||
/// 'USBS' 0x53425355
|
||||
#define MSD_CSW_SIGNATURE 0x53425355
|
||||
|
||||
/// Command Passed (good status)
|
||||
#define MSD_CSW_COMMAND_PASSED 0
|
||||
/// Command Failed
|
||||
#define MSD_CSW_COMMAND_FAILED 1
|
||||
/// Phase Error
|
||||
#define MSD_CSW_PHASE_ERROR 2
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Structures
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Command Block Wrapper (CBW),
|
||||
/// See Table 5.1, USB Mass Storage Class Bulk-Only Transport.
|
||||
///
|
||||
/// The CBW shall start on a packet boundary and shall end as a
|
||||
/// short packet with exactly 31 (1Fh) bytes transferred.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// 'USBC' 0x43425355 (little endian)
|
||||
unsigned int dCBWSignature;
|
||||
/// Must be the same as dCSWTag
|
||||
unsigned int dCBWTag;
|
||||
/// Number of bytes transfer
|
||||
unsigned int dCBWDataTransferLength;
|
||||
/// Indicates the directin of the transfer:
|
||||
/// 0x80=IN=device-to-host,
|
||||
/// 0x00=OUT=host-to-device
|
||||
unsigned char bmCBWFlags;
|
||||
/// bits 0->3: bCBWLUN
|
||||
unsigned char bCBWLUN :4,
|
||||
bReserved1:4; /// reserved
|
||||
/// bits 0->4: bCBWCBLength
|
||||
unsigned char bCBWCBLength:5,
|
||||
bReserved2 :3; /// reserved
|
||||
/// Command block
|
||||
unsigned char pCommand[16];
|
||||
|
||||
} MSCbw;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Command Status Wrapper (CSW),
|
||||
/// See Table 5.2, USB Mass Storage Class Bulk-Only Transport.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct
|
||||
{
|
||||
/// 'USBS' 0x53425355 (little endian)
|
||||
unsigned int dCSWSignature;
|
||||
/// Must be the same as dCBWTag
|
||||
unsigned int dCSWTag;
|
||||
/// For Data-Out the device shall report in the dCSWDataResidue the
|
||||
/// difference between the amount of data expected as stated in the
|
||||
/// dCBWDataTransferLength, and the actual amount of data processed by
|
||||
/// the device. For Data-In the device shall report in the dCSWDataResidue
|
||||
/// the difference between the amount of data expected as stated in the
|
||||
/// dCBWDataTransferLength and the actual amount of relevant data sent by
|
||||
/// the device. The dCSWDataResidue shall not exceed the value sent in the
|
||||
/// dCBWDataTransferLength.
|
||||
unsigned int dCSWDataResidue;
|
||||
/// Indicates the success or failure of the command.
|
||||
unsigned char bCSWStatus;
|
||||
|
||||
} MSCsw;
|
||||
|
||||
#endif //#ifndef MSD_H
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,264 +1,264 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Definitions, structs, functions required by a Mass Storage device driver
|
||||
/// state machine..
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// - For a USB device:
|
||||
/// -# MSDD_Write, MSDD_Read, MSDD_Halt should be defined for
|
||||
/// usage in the state machine procedure.
|
||||
///
|
||||
/// -# MSDD_StateMachine is invoked to run the MSD state machine.
|
||||
///
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSDDSTATEMACHINE_H
|
||||
#define MSDDSTATEMACHINE_H
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Headers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSD.h"
|
||||
#include "../../../usb/device/massstorage/MSDLun.h"
|
||||
#include "debug.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Driver Possible states"
|
||||
/// ...
|
||||
///
|
||||
/// !States
|
||||
/// - MSDD_STATE_READ_CBW
|
||||
/// - MSDD_STATE_WAIT_CBW
|
||||
/// - MSDD_STATE_PROCESS_CBW
|
||||
/// - MSDD_STATE_WAIT_HALT
|
||||
/// - MSDD_STATE_SEND_CSW
|
||||
/// - MSDD_STATE_WAIT_CSW
|
||||
/// - MSDD_STATE_WAIT_RESET
|
||||
|
||||
//! \brief Driver is expecting a command block wrapper
|
||||
#define MSDD_STATE_READ_CBW (1 << 0)
|
||||
|
||||
//! \brief Driver is waiting for the transfer to finish
|
||||
#define MSDD_STATE_WAIT_CBW (1 << 1)
|
||||
|
||||
//! \brief Driver is processing the received command
|
||||
#define MSDD_STATE_PROCESS_CBW (1 << 2)
|
||||
|
||||
//! \brief Driver is halted because pipe halt or wait reset
|
||||
#define MSDD_STATE_WAIT_HALT (1 << 3)
|
||||
|
||||
//! \brief Driver is starting the transmission of a command status wrapper
|
||||
#define MSDD_STATE_SEND_CSW (1 << 4)
|
||||
|
||||
//! \brief Driver is waiting for the CSW transmission to finish
|
||||
#define MSDD_STATE_WAIT_CSW (1 << 5)
|
||||
|
||||
//! \brief Driver is waiting for the MassStorageReset
|
||||
#define MSDD_STATE_WAIT_RESET (1 << 6)
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Driver Result Codes"
|
||||
/// This page lists result codes for MSD functions.
|
||||
///
|
||||
/// !Codes
|
||||
/// - MSDD_STATUS_SUCCESS
|
||||
/// - MSDD_STATUS_ERROR
|
||||
/// - MSDD_STATUS_INCOMPLETE
|
||||
/// - MSDD_STATUS_PARAMETER
|
||||
/// - MSDD_STATUS_RW
|
||||
|
||||
//! \brief Method was successful
|
||||
#define MSDD_STATUS_SUCCESS 0x00
|
||||
|
||||
//! \brief There was an error when trying to perform a method
|
||||
#define MSDD_STATUS_ERROR 0x01
|
||||
|
||||
//! \brief No error was encountered but the application should call the
|
||||
//! method again to continue the operation
|
||||
#define MSDD_STATUS_INCOMPLETE 0x02
|
||||
|
||||
//! \brief A wrong parameter has been passed to the method
|
||||
#define MSDD_STATUS_PARAMETER 0x03
|
||||
|
||||
//! \brief An error when reading/writing disk (protected or not present)
|
||||
#define MSDD_STATUS_RW 0x04
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Driver Action Cases"
|
||||
/// This page lists actions to perform during the post-processing phase of a
|
||||
/// command.
|
||||
///
|
||||
/// !Actions
|
||||
/// - MSDD_CASE_PHASE_ERROR
|
||||
/// - MSDD_CASE_STALL_IN
|
||||
/// - MSDD_CASE_STALL_OUT
|
||||
|
||||
//! \brief Indicates that the CSW should report a phase error
|
||||
#define MSDD_CASE_PHASE_ERROR (1 << 0)
|
||||
|
||||
//! \brief The driver should halt the Bulk IN pipe after the transfer
|
||||
#define MSDD_CASE_STALL_IN (1 << 1)
|
||||
|
||||
//! \brief The driver should halt the Bulk OUT pipe after the transfer
|
||||
#define MSDD_CASE_STALL_OUT (1 << 2)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Driver Xfr Directions"
|
||||
/// This page lists possible direction values for a data transfer
|
||||
///
|
||||
/// !Directions
|
||||
/// - MSDD_DEVICE_TO_HOST
|
||||
/// - MSDD_HOST_TO_DEVICE
|
||||
/// - MSDD_NO_TRANSFER
|
||||
|
||||
#define MSDD_DEVICE_TO_HOST 0
|
||||
#define MSDD_HOST_TO_DEVICE 1
|
||||
#define MSDD_NO_TRANSFER 2
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Types
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Structure for holding the result of a USB transfer
|
||||
//! \see MSDDriver_Callback
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
volatile unsigned int transferred; /// Number of bytes transferred
|
||||
volatile unsigned int remaining; /// Number of bytes not transferred
|
||||
volatile unsigned short semaphore; /// Semaphore to indicate transfer completion
|
||||
volatile unsigned short status; /// Operation result code
|
||||
|
||||
} MSDTransfer;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Status of an executing command
|
||||
//! \see MSDCbw
|
||||
//! \see MSDCsw
|
||||
//! \see MSDTransfer
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
MSDTransfer transfer; /// Current transfer status (USB)
|
||||
MSDTransfer disktransfer;/// Current transfer status (Disk)
|
||||
unsigned int length; /// Remaining length of command
|
||||
MSCbw cbw; /// Received CBW (31 bytes)
|
||||
unsigned char state; /// Current command state
|
||||
MSCsw csw; /// CSW to send (13 bytes)
|
||||
unsigned char postprocess; /// Actions to perform when command is complete
|
||||
|
||||
} MSDCommandState;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \brief MSD driver state variables
|
||||
/// \see MSDCommandState
|
||||
/// \see MSDLun
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// LUN list for the %device.
|
||||
MSDLun *luns;
|
||||
/// State of the currently executing command
|
||||
MSDCommandState commandState;
|
||||
/// Maximum LUN index
|
||||
unsigned char maxLun;
|
||||
/// Current state of the driver
|
||||
unsigned char state;
|
||||
/// Indicates if the driver is waiting for a reset recovery
|
||||
unsigned char waitResetRecovery;
|
||||
|
||||
} MSDDriver;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inline functions
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
/// This function is to be used as a callback for USB or LUN transfers.
|
||||
/// \param transfer Pointer to the transfer structure to update
|
||||
/// \param status Operation result code
|
||||
/// \param transferred Number of bytes transferred by the command
|
||||
/// \param remaining Number of bytes not transferred
|
||||
//-----------------------------------------------------------------------------
|
||||
static inline void MSDDriver_Callback(MSDTransfer *transfer,
|
||||
unsigned char status,
|
||||
unsigned int transferred,
|
||||
unsigned int remaining)
|
||||
{
|
||||
TRACE_DEBUG("Cbk ");
|
||||
transfer->semaphore++;
|
||||
transfer->status = status;
|
||||
transfer->transferred = transferred;
|
||||
transfer->remaining = remaining;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Driver functions
|
||||
//-----------------------------------------------------------------------------
|
||||
//- MSD General support function
|
||||
extern char MSDD_Read(
|
||||
void* pData,
|
||||
unsigned int dLength,
|
||||
TransferCallback fCallback,
|
||||
void* pArgument);
|
||||
|
||||
extern char MSDD_Write(
|
||||
void* pData,
|
||||
unsigned int dLength,
|
||||
TransferCallback fCallback,
|
||||
void* pArgument);
|
||||
|
||||
extern void MSDD_Halt(unsigned int stallCase);
|
||||
|
||||
extern unsigned int MSDD_IsHalted(void);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
extern void MSDD_StateMachine(MSDDriver * pMsdDriver);
|
||||
|
||||
#endif // #define MSDDSTATEMACHINE_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Definitions, structs, functions required by a Mass Storage device driver
|
||||
/// state machine..
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// - For a USB device:
|
||||
/// -# MSDD_Write, MSDD_Read, MSDD_Halt should be defined for
|
||||
/// usage in the state machine procedure.
|
||||
///
|
||||
/// -# MSDD_StateMachine is invoked to run the MSD state machine.
|
||||
///
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSDDSTATEMACHINE_H
|
||||
#define MSDDSTATEMACHINE_H
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Headers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSD.h"
|
||||
#include "../../../usb/device/massstorage/MSDLun.h"
|
||||
#include "debug.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Driver Possible states"
|
||||
/// ...
|
||||
///
|
||||
/// !States
|
||||
/// - MSDD_STATE_READ_CBW
|
||||
/// - MSDD_STATE_WAIT_CBW
|
||||
/// - MSDD_STATE_PROCESS_CBW
|
||||
/// - MSDD_STATE_WAIT_HALT
|
||||
/// - MSDD_STATE_SEND_CSW
|
||||
/// - MSDD_STATE_WAIT_CSW
|
||||
/// - MSDD_STATE_WAIT_RESET
|
||||
|
||||
//! \brief Driver is expecting a command block wrapper
|
||||
#define MSDD_STATE_READ_CBW (1 << 0)
|
||||
|
||||
//! \brief Driver is waiting for the transfer to finish
|
||||
#define MSDD_STATE_WAIT_CBW (1 << 1)
|
||||
|
||||
//! \brief Driver is processing the received command
|
||||
#define MSDD_STATE_PROCESS_CBW (1 << 2)
|
||||
|
||||
//! \brief Driver is halted because pipe halt or wait reset
|
||||
#define MSDD_STATE_WAIT_HALT (1 << 3)
|
||||
|
||||
//! \brief Driver is starting the transmission of a command status wrapper
|
||||
#define MSDD_STATE_SEND_CSW (1 << 4)
|
||||
|
||||
//! \brief Driver is waiting for the CSW transmission to finish
|
||||
#define MSDD_STATE_WAIT_CSW (1 << 5)
|
||||
|
||||
//! \brief Driver is waiting for the MassStorageReset
|
||||
#define MSDD_STATE_WAIT_RESET (1 << 6)
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Driver Result Codes"
|
||||
/// This page lists result codes for MSD functions.
|
||||
///
|
||||
/// !Codes
|
||||
/// - MSDD_STATUS_SUCCESS
|
||||
/// - MSDD_STATUS_ERROR
|
||||
/// - MSDD_STATUS_INCOMPLETE
|
||||
/// - MSDD_STATUS_PARAMETER
|
||||
/// - MSDD_STATUS_RW
|
||||
|
||||
//! \brief Method was successful
|
||||
#define MSDD_STATUS_SUCCESS 0x00
|
||||
|
||||
//! \brief There was an error when trying to perform a method
|
||||
#define MSDD_STATUS_ERROR 0x01
|
||||
|
||||
//! \brief No error was encountered but the application should call the
|
||||
//! method again to continue the operation
|
||||
#define MSDD_STATUS_INCOMPLETE 0x02
|
||||
|
||||
//! \brief A wrong parameter has been passed to the method
|
||||
#define MSDD_STATUS_PARAMETER 0x03
|
||||
|
||||
//! \brief An error when reading/writing disk (protected or not present)
|
||||
#define MSDD_STATUS_RW 0x04
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Driver Action Cases"
|
||||
/// This page lists actions to perform during the post-processing phase of a
|
||||
/// command.
|
||||
///
|
||||
/// !Actions
|
||||
/// - MSDD_CASE_PHASE_ERROR
|
||||
/// - MSDD_CASE_STALL_IN
|
||||
/// - MSDD_CASE_STALL_OUT
|
||||
|
||||
//! \brief Indicates that the CSW should report a phase error
|
||||
#define MSDD_CASE_PHASE_ERROR (1 << 0)
|
||||
|
||||
//! \brief The driver should halt the Bulk IN pipe after the transfer
|
||||
#define MSDD_CASE_STALL_IN (1 << 1)
|
||||
|
||||
//! \brief The driver should halt the Bulk OUT pipe after the transfer
|
||||
#define MSDD_CASE_STALL_OUT (1 << 2)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Driver Xfr Directions"
|
||||
/// This page lists possible direction values for a data transfer
|
||||
///
|
||||
/// !Directions
|
||||
/// - MSDD_DEVICE_TO_HOST
|
||||
/// - MSDD_HOST_TO_DEVICE
|
||||
/// - MSDD_NO_TRANSFER
|
||||
|
||||
#define MSDD_DEVICE_TO_HOST 0
|
||||
#define MSDD_HOST_TO_DEVICE 1
|
||||
#define MSDD_NO_TRANSFER 2
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Types
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Structure for holding the result of a USB transfer
|
||||
//! \see MSDDriver_Callback
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
volatile unsigned int transferred; /// Number of bytes transferred
|
||||
volatile unsigned int remaining; /// Number of bytes not transferred
|
||||
volatile unsigned short semaphore; /// Semaphore to indicate transfer completion
|
||||
volatile unsigned short status; /// Operation result code
|
||||
|
||||
} MSDTransfer;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Status of an executing command
|
||||
//! \see MSDCbw
|
||||
//! \see MSDCsw
|
||||
//! \see MSDTransfer
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
MSDTransfer transfer; /// Current transfer status (USB)
|
||||
MSDTransfer disktransfer;/// Current transfer status (Disk)
|
||||
unsigned int length; /// Remaining length of command
|
||||
MSCbw cbw; /// Received CBW (31 bytes)
|
||||
unsigned char state; /// Current command state
|
||||
MSCsw csw; /// CSW to send (13 bytes)
|
||||
unsigned char postprocess; /// Actions to perform when command is complete
|
||||
|
||||
} MSDCommandState;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \brief MSD driver state variables
|
||||
/// \see MSDCommandState
|
||||
/// \see MSDLun
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// LUN list for the %device.
|
||||
MSDLun *luns;
|
||||
/// State of the currently executing command
|
||||
MSDCommandState commandState;
|
||||
/// Maximum LUN index
|
||||
unsigned char maxLun;
|
||||
/// Current state of the driver
|
||||
unsigned char state;
|
||||
/// Indicates if the driver is waiting for a reset recovery
|
||||
unsigned char waitResetRecovery;
|
||||
|
||||
} MSDDriver;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inline functions
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
/// This function is to be used as a callback for USB or LUN transfers.
|
||||
/// \param transfer Pointer to the transfer structure to update
|
||||
/// \param status Operation result code
|
||||
/// \param transferred Number of bytes transferred by the command
|
||||
/// \param remaining Number of bytes not transferred
|
||||
//-----------------------------------------------------------------------------
|
||||
static inline void MSDDriver_Callback(MSDTransfer *transfer,
|
||||
unsigned char status,
|
||||
unsigned int transferred,
|
||||
unsigned int remaining)
|
||||
{
|
||||
TRACE_DEBUG("Cbk ");
|
||||
transfer->semaphore++;
|
||||
transfer->status = status;
|
||||
transfer->transferred = transferred;
|
||||
transfer->remaining = remaining;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Driver functions
|
||||
//-----------------------------------------------------------------------------
|
||||
//- MSD General support function
|
||||
extern char MSDD_Read(
|
||||
void* pData,
|
||||
unsigned int dLength,
|
||||
TransferCallback fCallback,
|
||||
void* pArgument);
|
||||
|
||||
extern char MSDD_Write(
|
||||
void* pData,
|
||||
unsigned int dLength,
|
||||
TransferCallback fCallback,
|
||||
void* pArgument);
|
||||
|
||||
extern void MSDD_Halt(unsigned int stallCase);
|
||||
|
||||
extern unsigned int MSDD_IsHalted(void);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
extern void MSDD_StateMachine(MSDDriver * pMsdDriver);
|
||||
|
||||
#endif // #define MSDDSTATEMACHINE_H
|
||||
|
||||
|
||||
@@ -1,342 +1,342 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Includes
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSDDriver.h"
|
||||
|
||||
#include "../../../usb/common/core/USBFeatureRequest.h"
|
||||
#include "../../../usb/device/core/USBDDriver.h"
|
||||
#include "../../../usb/device/massstorage/MSDDriverDescriptors.h"
|
||||
#include "../../../usb/device/massstorage/SBCMethods.h"
|
||||
#include "../../../Media.h"
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
#include "../../../usb/device/core/USBD.h"
|
||||
#include "debug.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Internal variables
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/// Mass storage device driver instance.
|
||||
static MSDDriver msdDriver;
|
||||
|
||||
/// Standard device driver instance.
|
||||
static USBDDriver usbdDriver;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Internal functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Resets the state of the MSD driver
|
||||
//-----------------------------------------------------------------------------
|
||||
static void MSDDriver_Reset(void)
|
||||
{
|
||||
TRACE_INFO_WP("MSDReset ");
|
||||
|
||||
msdDriver.state = MSDD_STATE_READ_CBW;
|
||||
msdDriver.waitResetRecovery = 0;
|
||||
msdDriver.commandState.state = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Callback re-implementation
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Invoked when a new SETUP request is received from the host. Forwards the
|
||||
/// request to the Mass Storage device driver handler function.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
//-----------------------------------------------------------------------------
|
||||
void USBDCallbacks_RequestReceived(const USBGenericRequest *request)
|
||||
{
|
||||
MSDDriver_RequestHandler(request);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Invoked when the configuration of the device changes. Resets the mass
|
||||
/// storage driver.
|
||||
/// \param cfgnum New configuration number.
|
||||
//-----------------------------------------------------------------------------
|
||||
void USBDDriverCallbacks_ConfigurationChanged(unsigned char cfgnum)
|
||||
{
|
||||
if (cfgnum > 0) {
|
||||
|
||||
MSDDriver_Reset();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Driver functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Reads from host through MSD defined bulk OUT pipe. Act as USBD_Read but by
|
||||
/// a fixed OUT endpoint.
|
||||
/// \param data Pointer to the data buffer that contains data read from host.
|
||||
/// \param size The number of bytes should be read (buffer size).
|
||||
/// \param callback Pointer to the function invoked on end of reading.
|
||||
/// \param argument Pointer to additional argument data struct.
|
||||
//-----------------------------------------------------------------------------
|
||||
char MSDD_Read(void *data,
|
||||
unsigned int size,
|
||||
TransferCallback callback,
|
||||
void *argument)
|
||||
|
||||
{
|
||||
return USBD_Read(MSDDriverDescriptors_BULKOUT,
|
||||
data,
|
||||
size,
|
||||
callback,
|
||||
argument);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Writes to host through MSD defined bulk IN pipe. Act as USBD_Write but by
|
||||
/// a fixed IN endpoint.
|
||||
/// \param data Pointer to the data that writes to the host.
|
||||
/// \param size The number of bytes should be write.
|
||||
/// \param callback Pointer to the function invoked on end of writing.
|
||||
/// \param argument Pointer to additional argument data struct.
|
||||
//-----------------------------------------------------------------------------
|
||||
char MSDD_Write(void *data,
|
||||
unsigned int size,
|
||||
TransferCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
return USBD_Write(MSDDriverDescriptors_BULKIN,
|
||||
data,
|
||||
size,
|
||||
callback,
|
||||
argument);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// HALT Specified USB pipe.
|
||||
/// \param stallCASE Case of the stall condition (Bulk In/Out/Both).
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDD_Halt(unsigned int stallCASE)
|
||||
{
|
||||
if (stallCASE & MSDD_CASE_STALL_OUT) {
|
||||
|
||||
USBD_Halt(MSDDriverDescriptors_BULKOUT);
|
||||
}
|
||||
|
||||
if (stallCASE & MSDD_CASE_STALL_IN) {
|
||||
|
||||
USBD_Halt(MSDDriverDescriptors_BULKIN);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Return halted status
|
||||
/// \return stallCASE bitmap, case of the stall condition
|
||||
/// (bit: MSDD_CASE_STALL_OUT or MSDD_CASE_STALL_IN)
|
||||
//-----------------------------------------------------------------------------
|
||||
unsigned int MSDD_IsHalted(void)
|
||||
{
|
||||
unsigned int stallCASE = 0;
|
||||
if (USBD_IsHalted(MSDDriverDescriptors_BULKOUT)) {
|
||||
|
||||
stallCASE |= MSDD_CASE_STALL_OUT;
|
||||
}
|
||||
if (USBD_IsHalted(MSDDriverDescriptors_BULKIN)) {
|
||||
|
||||
stallCASE |= MSDD_CASE_STALL_IN;
|
||||
}
|
||||
return stallCASE;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Initializes the MSD driver and the associated USB driver.
|
||||
/// \param luns Pointer to a list of LUNs
|
||||
/// \param numLuns Number of LUN in list
|
||||
/// \see MSDLun
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDDriver_Initialize(MSDLun *defLuns, unsigned char numLuns)
|
||||
{
|
||||
|
||||
TRACE_INFO("MSD init\n\r");
|
||||
|
||||
// Command state initialization
|
||||
msdDriver.commandState.state = 0;
|
||||
msdDriver.commandState.postprocess = 0;
|
||||
msdDriver.commandState.length = 0;
|
||||
msdDriver.commandState.transfer.semaphore = 0;
|
||||
|
||||
// LUNs
|
||||
msdDriver.luns = defLuns;
|
||||
msdDriver.maxLun = (unsigned char) (numLuns - 1);
|
||||
|
||||
// Reset BOT driver
|
||||
MSDDriver_Reset();
|
||||
|
||||
// Init the USB driver
|
||||
USBDDriver_Initialize(&usbdDriver, &msdDriverDescriptors, 0);
|
||||
USBD_Init();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Handler for incoming SETUP requests on default Control endpoint 0.
|
||||
///
|
||||
/// Standard requests are forwarded to the USBDDriver_RequestHandler
|
||||
/// method.
|
||||
/// \param request Pointer to a USBGenericRequest instance
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDDriver_RequestHandler(const USBGenericRequest *request)
|
||||
{
|
||||
TRACE_INFO_WP("NewReq ");
|
||||
|
||||
// Handle requests
|
||||
switch (USBGenericRequest_GetRequest(request)) {
|
||||
//---------------------
|
||||
case USBGenericRequest_CLEARFEATURE:
|
||||
//---------------------
|
||||
TRACE_INFO_WP("ClrFeat ");
|
||||
|
||||
switch (USBFeatureRequest_GetFeatureSelector(request)) {
|
||||
|
||||
//---------------------
|
||||
case USBFeatureRequest_ENDPOINTHALT:
|
||||
//---------------------
|
||||
TRACE_INFO_WP("Hlt ");
|
||||
|
||||
// Do not clear the endpoint halt status if the device is waiting
|
||||
// for a reset recovery sequence
|
||||
if (!msdDriver.waitResetRecovery) {
|
||||
|
||||
// Forward the request to the standard handler
|
||||
USBDDriver_RequestHandler(&usbdDriver, request);
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_INFO_WP("No ");
|
||||
}
|
||||
|
||||
USBD_Write(0, 0, 0, 0, 0);
|
||||
break;
|
||||
|
||||
//------
|
||||
default:
|
||||
//------
|
||||
// Forward the request to the standard handler
|
||||
USBDDriver_RequestHandler(&usbdDriver, request);
|
||||
}
|
||||
break;
|
||||
|
||||
//-------------------
|
||||
case MSD_GET_MAX_LUN:
|
||||
//-------------------
|
||||
TRACE_INFO_WP("gMaxLun ");
|
||||
|
||||
// Check request parameters
|
||||
if ((request->wValue == 0)
|
||||
&& (request->wIndex == 0)
|
||||
&& (request->wLength == 1)) {
|
||||
|
||||
USBD_Write(0, &(msdDriver.maxLun), 1, 0, 0);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_WARNING(
|
||||
"MSDDriver_RequestHandler: GetMaxLUN(%d,%d,%d)\n\r",
|
||||
request->wValue, request->wIndex, request->wLength);
|
||||
USBD_Stall(0);
|
||||
}
|
||||
break;
|
||||
|
||||
//-----------------------
|
||||
case MSD_BULK_ONLY_RESET:
|
||||
//-----------------------
|
||||
TRACE_INFO_WP("Rst ");
|
||||
|
||||
// Check parameters
|
||||
if ((request->wValue == 0)
|
||||
&& (request->wIndex == 0)
|
||||
&& (request->wLength == 0)) {
|
||||
|
||||
// Reset the MSD driver
|
||||
MSDDriver_Reset();
|
||||
USBD_Write(0, 0, 0, 0, 0);
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_WARNING(
|
||||
"MSDDriver_RequestHandler: Reset(%d,%d,%d)\n\r",
|
||||
request->wValue, request->wIndex, request->wLength);
|
||||
USBD_Stall(0);
|
||||
}
|
||||
break;
|
||||
|
||||
//------
|
||||
default:
|
||||
//------
|
||||
// Forward request to standard handler
|
||||
USBDDriver_RequestHandler(&usbdDriver, request);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// State machine for the MSD driver
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDDriver_StateMachine(void)
|
||||
{
|
||||
if (USBD_GetState() < USBD_STATE_CONFIGURED){}
|
||||
else MSDD_StateMachine(&msdDriver);
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Starts a remote wake-up sequence if the host has explicitely enabled it
|
||||
/// by sending the appropriate SET_FEATURE request.
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDDriver_RemoteWakeUp(void)
|
||||
{
|
||||
// Remote wake-up has been enabled
|
||||
if (USBDDriver_IsRemoteWakeUpEnabled(&usbdDriver)) {
|
||||
|
||||
USBD_RemoteWakeUp();
|
||||
}
|
||||
// Remote wake-up NOT enabled
|
||||
else {
|
||||
|
||||
TRACE_WARNING(
|
||||
"MSD..RemoteWakeUp: Host has not enabled remote wake-up\n\r");
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Includes
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSDDriver.h"
|
||||
|
||||
#include "../../../usb/common/core/USBFeatureRequest.h"
|
||||
#include "../../../usb/device/core/USBDDriver.h"
|
||||
#include "../../../usb/device/massstorage/MSDDriverDescriptors.h"
|
||||
#include "../../../usb/device/massstorage/SBCMethods.h"
|
||||
#include "../../../Media.h"
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
#include "../../../usb/device/core/USBD.h"
|
||||
#include "debug.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Internal variables
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/// Mass storage device driver instance.
|
||||
static MSDDriver msdDriver;
|
||||
|
||||
/// Standard device driver instance.
|
||||
static USBDDriver usbdDriver;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Internal functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Resets the state of the MSD driver
|
||||
//-----------------------------------------------------------------------------
|
||||
static void MSDDriver_Reset(void)
|
||||
{
|
||||
TRACE_INFO_WP("MSDReset ");
|
||||
|
||||
msdDriver.state = MSDD_STATE_READ_CBW;
|
||||
msdDriver.waitResetRecovery = 0;
|
||||
msdDriver.commandState.state = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Callback re-implementation
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Invoked when a new SETUP request is received from the host. Forwards the
|
||||
/// request to the Mass Storage device driver handler function.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
//-----------------------------------------------------------------------------
|
||||
void USBDCallbacks_RequestReceived(const USBGenericRequest *request)
|
||||
{
|
||||
MSDDriver_RequestHandler(request);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Invoked when the configuration of the device changes. Resets the mass
|
||||
/// storage driver.
|
||||
/// \param cfgnum New configuration number.
|
||||
//-----------------------------------------------------------------------------
|
||||
void USBDDriverCallbacks_ConfigurationChanged(unsigned char cfgnum)
|
||||
{
|
||||
if (cfgnum > 0) {
|
||||
|
||||
MSDDriver_Reset();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Driver functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Reads from host through MSD defined bulk OUT pipe. Act as USBD_Read but by
|
||||
/// a fixed OUT endpoint.
|
||||
/// \param data Pointer to the data buffer that contains data read from host.
|
||||
/// \param size The number of bytes should be read (buffer size).
|
||||
/// \param callback Pointer to the function invoked on end of reading.
|
||||
/// \param argument Pointer to additional argument data struct.
|
||||
//-----------------------------------------------------------------------------
|
||||
char MSDD_Read(void *data,
|
||||
unsigned int size,
|
||||
TransferCallback callback,
|
||||
void *argument)
|
||||
|
||||
{
|
||||
return USBD_Read(MSDDriverDescriptors_BULKOUT,
|
||||
data,
|
||||
size,
|
||||
callback,
|
||||
argument);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Writes to host through MSD defined bulk IN pipe. Act as USBD_Write but by
|
||||
/// a fixed IN endpoint.
|
||||
/// \param data Pointer to the data that writes to the host.
|
||||
/// \param size The number of bytes should be write.
|
||||
/// \param callback Pointer to the function invoked on end of writing.
|
||||
/// \param argument Pointer to additional argument data struct.
|
||||
//-----------------------------------------------------------------------------
|
||||
char MSDD_Write(void *data,
|
||||
unsigned int size,
|
||||
TransferCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
return USBD_Write(MSDDriverDescriptors_BULKIN,
|
||||
data,
|
||||
size,
|
||||
callback,
|
||||
argument);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// HALT Specified USB pipe.
|
||||
/// \param stallCASE Case of the stall condition (Bulk In/Out/Both).
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDD_Halt(unsigned int stallCASE)
|
||||
{
|
||||
if (stallCASE & MSDD_CASE_STALL_OUT) {
|
||||
|
||||
USBD_Halt(MSDDriverDescriptors_BULKOUT);
|
||||
}
|
||||
|
||||
if (stallCASE & MSDD_CASE_STALL_IN) {
|
||||
|
||||
USBD_Halt(MSDDriverDescriptors_BULKIN);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Return halted status
|
||||
/// \return stallCASE bitmap, case of the stall condition
|
||||
/// (bit: MSDD_CASE_STALL_OUT or MSDD_CASE_STALL_IN)
|
||||
//-----------------------------------------------------------------------------
|
||||
unsigned int MSDD_IsHalted(void)
|
||||
{
|
||||
unsigned int stallCASE = 0;
|
||||
if (USBD_IsHalted(MSDDriverDescriptors_BULKOUT)) {
|
||||
|
||||
stallCASE |= MSDD_CASE_STALL_OUT;
|
||||
}
|
||||
if (USBD_IsHalted(MSDDriverDescriptors_BULKIN)) {
|
||||
|
||||
stallCASE |= MSDD_CASE_STALL_IN;
|
||||
}
|
||||
return stallCASE;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Initializes the MSD driver and the associated USB driver.
|
||||
/// \param luns Pointer to a list of LUNs
|
||||
/// \param numLuns Number of LUN in list
|
||||
/// \see MSDLun
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDDriver_Initialize(MSDLun *defLuns, unsigned char numLuns)
|
||||
{
|
||||
|
||||
TRACE_INFO("MSD init\n\r");
|
||||
|
||||
// Command state initialization
|
||||
msdDriver.commandState.state = 0;
|
||||
msdDriver.commandState.postprocess = 0;
|
||||
msdDriver.commandState.length = 0;
|
||||
msdDriver.commandState.transfer.semaphore = 0;
|
||||
|
||||
// LUNs
|
||||
msdDriver.luns = defLuns;
|
||||
msdDriver.maxLun = (unsigned char) (numLuns - 1);
|
||||
|
||||
// Reset BOT driver
|
||||
MSDDriver_Reset();
|
||||
|
||||
// Init the USB driver
|
||||
USBDDriver_Initialize(&usbdDriver, &msdDriverDescriptors, 0);
|
||||
USBD_Init();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Handler for incoming SETUP requests on default Control endpoint 0.
|
||||
///
|
||||
/// Standard requests are forwarded to the USBDDriver_RequestHandler
|
||||
/// method.
|
||||
/// \param request Pointer to a USBGenericRequest instance
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDDriver_RequestHandler(const USBGenericRequest *request)
|
||||
{
|
||||
TRACE_INFO_WP("NewReq ");
|
||||
|
||||
// Handle requests
|
||||
switch (USBGenericRequest_GetRequest(request)) {
|
||||
//---------------------
|
||||
case USBGenericRequest_CLEARFEATURE:
|
||||
//---------------------
|
||||
TRACE_INFO_WP("ClrFeat ");
|
||||
|
||||
switch (USBFeatureRequest_GetFeatureSelector(request)) {
|
||||
|
||||
//---------------------
|
||||
case USBFeatureRequest_ENDPOINTHALT:
|
||||
//---------------------
|
||||
TRACE_INFO_WP("Hlt ");
|
||||
|
||||
// Do not clear the endpoint halt status if the device is waiting
|
||||
// for a reset recovery sequence
|
||||
if (!msdDriver.waitResetRecovery) {
|
||||
|
||||
// Forward the request to the standard handler
|
||||
USBDDriver_RequestHandler(&usbdDriver, request);
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_INFO_WP("No ");
|
||||
}
|
||||
|
||||
USBD_Write(0, 0, 0, 0, 0);
|
||||
break;
|
||||
|
||||
//------
|
||||
default:
|
||||
//------
|
||||
// Forward the request to the standard handler
|
||||
USBDDriver_RequestHandler(&usbdDriver, request);
|
||||
}
|
||||
break;
|
||||
|
||||
//-------------------
|
||||
case MSD_GET_MAX_LUN:
|
||||
//-------------------
|
||||
TRACE_INFO_WP("gMaxLun ");
|
||||
|
||||
// Check request parameters
|
||||
if ((request->wValue == 0)
|
||||
&& (request->wIndex == 0)
|
||||
&& (request->wLength == 1)) {
|
||||
|
||||
USBD_Write(0, &(msdDriver.maxLun), 1, 0, 0);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_WARNING(
|
||||
"MSDDriver_RequestHandler: GetMaxLUN(%d,%d,%d)\n\r",
|
||||
request->wValue, request->wIndex, request->wLength);
|
||||
USBD_Stall(0);
|
||||
}
|
||||
break;
|
||||
|
||||
//-----------------------
|
||||
case MSD_BULK_ONLY_RESET:
|
||||
//-----------------------
|
||||
TRACE_INFO_WP("Rst ");
|
||||
|
||||
// Check parameters
|
||||
if ((request->wValue == 0)
|
||||
&& (request->wIndex == 0)
|
||||
&& (request->wLength == 0)) {
|
||||
|
||||
// Reset the MSD driver
|
||||
MSDDriver_Reset();
|
||||
USBD_Write(0, 0, 0, 0, 0);
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_WARNING(
|
||||
"MSDDriver_RequestHandler: Reset(%d,%d,%d)\n\r",
|
||||
request->wValue, request->wIndex, request->wLength);
|
||||
USBD_Stall(0);
|
||||
}
|
||||
break;
|
||||
|
||||
//------
|
||||
default:
|
||||
//------
|
||||
// Forward request to standard handler
|
||||
USBDDriver_RequestHandler(&usbdDriver, request);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// State machine for the MSD driver
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDDriver_StateMachine(void)
|
||||
{
|
||||
if (USBD_GetState() < USBD_STATE_CONFIGURED){}
|
||||
else MSDD_StateMachine(&msdDriver);
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Starts a remote wake-up sequence if the host has explicitely enabled it
|
||||
/// by sending the appropriate SET_FEATURE request.
|
||||
//-----------------------------------------------------------------------------
|
||||
void MSDDriver_RemoteWakeUp(void)
|
||||
{
|
||||
// Remote wake-up has been enabled
|
||||
if (USBDDriver_IsRemoteWakeUpEnabled(&usbdDriver)) {
|
||||
|
||||
USBD_RemoteWakeUp();
|
||||
}
|
||||
// Remote wake-up NOT enabled
|
||||
else {
|
||||
|
||||
TRACE_WARNING(
|
||||
"MSD..RemoteWakeUp: Host has not enabled remote wake-up\n\r");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,75 +1,75 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Mass storage %device driver implementation.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# Enable and setup USB related pins (see pio & board.h).
|
||||
/// -# Configure the memory interfaces used for Mass Storage LUNs
|
||||
/// (see memories, MSDLun.h).
|
||||
/// -# Configure the USB MSD %driver using MSDDriver_Initialize.
|
||||
/// -# Invoke MSDDriver_StateMachine in main loop to handle all Mass Storage
|
||||
/// operations.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSDDRIVER_H
|
||||
#define MSDDRIVER_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSD.h"
|
||||
#include "../../../usb/device/massstorage/MSDLun.h"
|
||||
// #include <utility/trace.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void MSDDriver_Initialize(MSDLun *luns, unsigned char numLuns);
|
||||
|
||||
extern void MSDDriver_RequestHandler(const USBGenericRequest *request);
|
||||
|
||||
extern void MSDDriver_StateMachine(void);
|
||||
|
||||
extern void MSDDriver_RemoteWakeUp(void);
|
||||
|
||||
extern void MSDDriver_DataCallback(unsigned char isRead,
|
||||
unsigned int dataLength,
|
||||
unsigned int nullCnt,
|
||||
unsigned int fullCnt);
|
||||
|
||||
#endif // #ifndef MSDDRIVER_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Mass storage %device driver implementation.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# Enable and setup USB related pins (see pio & board.h).
|
||||
/// -# Configure the memory interfaces used for Mass Storage LUNs
|
||||
/// (see memories, MSDLun.h).
|
||||
/// -# Configure the USB MSD %driver using MSDDriver_Initialize.
|
||||
/// -# Invoke MSDDriver_StateMachine in main loop to handle all Mass Storage
|
||||
/// operations.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSDDRIVER_H
|
||||
#define MSDDRIVER_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSD.h"
|
||||
#include "../../../usb/device/massstorage/MSDLun.h"
|
||||
// #include <utility/trace.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void MSDDriver_Initialize(MSDLun *luns, unsigned char numLuns);
|
||||
|
||||
extern void MSDDriver_RequestHandler(const USBGenericRequest *request);
|
||||
|
||||
extern void MSDDriver_StateMachine(void);
|
||||
|
||||
extern void MSDDriver_RemoteWakeUp(void);
|
||||
|
||||
extern void MSDDriver_DataCallback(unsigned char isRead,
|
||||
unsigned int dataLength,
|
||||
unsigned int nullCnt,
|
||||
unsigned int fullCnt);
|
||||
|
||||
#endif // #ifndef MSDDRIVER_H
|
||||
|
||||
|
||||
@@ -1,469 +1,469 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSDDriverDescriptors.h"
|
||||
|
||||
#include "../../../usb/common/core/USBStringDescriptor.h"
|
||||
#include "../../../usb/common/massstorage/MSDeviceDescriptor.h"
|
||||
#include "../../../usb/common/massstorage/MSInterfaceDescriptor.h"
|
||||
#include "board_lowlevel.h"
|
||||
#include "../../../usb/common/core/USBConfigurationDescriptor.h"
|
||||
#include "../../../usb/common/core/USBDeviceDescriptor.h"
|
||||
#include "../../../usb/common/core/USBEndpointDescriptor.h"
|
||||
#include "../../../usb/common/core/USBGenericDescriptor.h"
|
||||
#include "../../../usb/common/core/USBInterfaceDescriptor.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Device Descriptor IDs"
|
||||
/// ...
|
||||
/// !IDs
|
||||
/// - MSDDriverDescriptors_VENDORID
|
||||
/// - MSDDriverDescriptors_PRODUCTID
|
||||
/// - MSDDriverDescriptors_RELEASE
|
||||
|
||||
/// Vendor ID for the Mass Storage device driver.
|
||||
#define MSDDriverDescriptors_VENDORID 0x03EB
|
||||
/// Product ID for the Mass Storage device driver.
|
||||
#define MSDDriverDescriptors_PRODUCTID 0x6129
|
||||
/// Device release number for the Mass Storage device driver.
|
||||
#define MSDDriverDescriptors_RELEASE 0x0100
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Macros
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Returns the minimum between two values.
|
||||
#define MIN(a, b) ((a < b) ? a : b)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// List of configuration descriptors used by a Mass Storage device driver.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Standard configuration descriptor.
|
||||
USBConfigurationDescriptor configuration;
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
USBOtgDescriptor otgDescriptor;
|
||||
#endif
|
||||
/// Mass storage interface descriptor.
|
||||
USBInterfaceDescriptor interface;
|
||||
/// Bulk-out endpoint descriptor.
|
||||
USBEndpointDescriptor bulkOut;
|
||||
/// Bulk-in endpoint descriptor.
|
||||
USBEndpointDescriptor bulkIn;
|
||||
|
||||
} __attribute__ ((packed)) MSDConfigurationDescriptors;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Local variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Mass storage driver device descriptor.
|
||||
static const USBDeviceDescriptor deviceDescriptor = {
|
||||
|
||||
sizeof(USBDeviceDescriptor),
|
||||
USBGenericDescriptor_DEVICE,
|
||||
USBDeviceDescriptor_USB2_00,
|
||||
MSDeviceDescriptor_CLASS,
|
||||
MSDeviceDescriptor_SUBCLASS,
|
||||
MSDeviceDescriptor_PROTOCOL,
|
||||
CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0),
|
||||
MSDDriverDescriptors_VENDORID,
|
||||
MSDDriverDescriptors_PRODUCTID,
|
||||
MSDDriverDescriptors_RELEASE,
|
||||
1, // Manufacturer string descriptor index.
|
||||
2, // Product string descriptor index.
|
||||
3, // Serial number string descriptor index.
|
||||
1 // Device has one possible configuration.
|
||||
};
|
||||
|
||||
#if defined(CHIP_USB_UDPHS) || defined(CHIP_USB_OTGHS)
|
||||
/// Device qualifier descriptor.
|
||||
static const USBDeviceQualifierDescriptor qualifierDescriptor = {
|
||||
|
||||
sizeof(USBDeviceQualifierDescriptor),
|
||||
USBGenericDescriptor_DEVICEQUALIFIER,
|
||||
USBDeviceDescriptor_USB2_00,
|
||||
MSDeviceDescriptor_CLASS,
|
||||
MSDeviceDescriptor_SUBCLASS,
|
||||
MSDeviceDescriptor_PROTOCOL,
|
||||
CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0),
|
||||
1, // Device has one possible configuration.
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
/// Full-speed configuration descriptor.
|
||||
static const MSDConfigurationDescriptors configurationDescriptorsFS = {
|
||||
|
||||
// Standard configuration descriptor.
|
||||
{
|
||||
sizeof(USBConfigurationDescriptor),
|
||||
USBGenericDescriptor_CONFIGURATION,
|
||||
sizeof(MSDConfigurationDescriptors),
|
||||
1, // Configuration has one interface.
|
||||
1, // This is configuration #1.
|
||||
0, // No string descriptor for configuration.
|
||||
BOARD_USB_BMATTRIBUTES,
|
||||
USBConfigurationDescriptor_POWER(100)
|
||||
},
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
{
|
||||
sizeof(USBOtgDescriptor),
|
||||
USBGenericDescriptor_OTG,
|
||||
USBOTGDescriptor_HNP_SRP
|
||||
},
|
||||
#endif
|
||||
// Mass Storage interface descriptor.
|
||||
{
|
||||
sizeof(USBInterfaceDescriptor),
|
||||
USBGenericDescriptor_INTERFACE,
|
||||
0, // This is interface #0.
|
||||
0, // This is alternate setting #0.
|
||||
2, // Interface uses two endpoints.
|
||||
MSInterfaceDescriptor_CLASS,
|
||||
MSInterfaceDescriptor_SCSI,
|
||||
MSInterfaceDescriptor_BULKONLY,
|
||||
0 // No string descriptor for interface.
|
||||
},
|
||||
// Bulk-OUT endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_OUT,
|
||||
MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||
0 // Must be 0 for full-speed Bulk endpoints.
|
||||
},
|
||||
// Bulk-IN endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_IN,
|
||||
MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||
0 // Must be 0 for full-speed Bulk endpoints.
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(CHIP_USB_UDPHS) || defined(CHIP_USB_OTGHS)
|
||||
/// Full-speed other speed configuration descriptor.
|
||||
static const MSDConfigurationDescriptors otherSpeedDescriptorsFS = {
|
||||
|
||||
// Standard configuration descriptor.
|
||||
{
|
||||
sizeof(USBConfigurationDescriptor),
|
||||
USBGenericDescriptor_OTHERSPEEDCONFIGURATION,
|
||||
sizeof(MSDConfigurationDescriptors),
|
||||
1, // Configuration has one interface.
|
||||
1, // This is configuration #1.
|
||||
0, // No string descriptor for configuration.
|
||||
BOARD_USB_BMATTRIBUTES,
|
||||
USBConfigurationDescriptor_POWER(100)
|
||||
},
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
{
|
||||
sizeof(USBOtgDescriptor),
|
||||
USBGenericDescriptor_OTG,
|
||||
USBOTGDescriptor_HNP_SRP
|
||||
},
|
||||
#endif
|
||||
// Mass Storage interface descriptor.
|
||||
{
|
||||
sizeof(USBInterfaceDescriptor),
|
||||
USBGenericDescriptor_INTERFACE,
|
||||
0, // This is interface #0.
|
||||
0, // This is alternate setting #0.
|
||||
2, // Interface uses two endpoints.
|
||||
MSInterfaceDescriptor_CLASS,
|
||||
MSInterfaceDescriptor_SCSI,
|
||||
MSInterfaceDescriptor_BULKONLY,
|
||||
0 // No string descriptor for interface.
|
||||
},
|
||||
// Bulk-OUT endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_OUT,
|
||||
MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_HS),
|
||||
0 // No string descriptor for endpoint.
|
||||
},
|
||||
// Bulk-IN endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_IN,
|
||||
MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_HS),
|
||||
0 // No string descriptor for endpoint.
|
||||
}
|
||||
};
|
||||
|
||||
/// High-speed configuration descriptor.
|
||||
static const MSDConfigurationDescriptors configurationDescriptorsHS = {
|
||||
|
||||
// Standard configuration descriptor.
|
||||
{
|
||||
sizeof(USBConfigurationDescriptor),
|
||||
USBGenericDescriptor_CONFIGURATION,
|
||||
sizeof(MSDConfigurationDescriptors),
|
||||
1, // Configuration has one interface.
|
||||
1, // This is configuration #1.
|
||||
0, // No string descriptor for configuration.
|
||||
BOARD_USB_BMATTRIBUTES,
|
||||
USBConfigurationDescriptor_POWER(100)
|
||||
},
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
{
|
||||
sizeof(USBOtgDescriptor),
|
||||
USBGenericDescriptor_OTG,
|
||||
USBOTGDescriptor_HNP_SRP
|
||||
},
|
||||
#endif
|
||||
// Mass Storage interface descriptor.
|
||||
{
|
||||
sizeof(USBInterfaceDescriptor),
|
||||
USBGenericDescriptor_INTERFACE,
|
||||
0, // This is interface #0.
|
||||
0, // This is alternate setting #0.
|
||||
2, // Interface uses two endpoints.
|
||||
MSInterfaceDescriptor_CLASS,
|
||||
MSInterfaceDescriptor_SCSI,
|
||||
MSInterfaceDescriptor_BULKONLY,
|
||||
0 // No string descriptor for interface.
|
||||
},
|
||||
// Bulk-OUT endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_OUT,
|
||||
MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_HS),
|
||||
0 // No string descriptor for endpoint.
|
||||
},
|
||||
// Bulk-IN endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_IN,
|
||||
MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_HS),
|
||||
0 // No string descriptor for endpoint.
|
||||
}
|
||||
};
|
||||
|
||||
/// High-speed other speed configuration descriptor.
|
||||
static const MSDConfigurationDescriptors otherSpeedDescriptorsHS = {
|
||||
|
||||
// Standard configuration descriptor.
|
||||
{
|
||||
sizeof(USBConfigurationDescriptor),
|
||||
USBGenericDescriptor_OTHERSPEEDCONFIGURATION,
|
||||
sizeof(MSDConfigurationDescriptors),
|
||||
1, // Configuration has one interface.
|
||||
1, // This is configuration #1.
|
||||
0, // No string descriptor for configuration.
|
||||
BOARD_USB_BMATTRIBUTES,
|
||||
USBConfigurationDescriptor_POWER(100)
|
||||
},
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
{
|
||||
sizeof(USBOtgDescriptor),
|
||||
USBGenericDescriptor_OTG,
|
||||
USBOTGDescriptor_HNP_SRP
|
||||
},
|
||||
#endif
|
||||
// Mass Storage interface descriptor.
|
||||
{
|
||||
sizeof(USBInterfaceDescriptor),
|
||||
USBGenericDescriptor_INTERFACE,
|
||||
0, // This is interface #0.
|
||||
0, // This is alternate setting #0.
|
||||
2, // Interface uses two endpoints.
|
||||
MSInterfaceDescriptor_CLASS,
|
||||
MSInterfaceDescriptor_SCSI,
|
||||
MSInterfaceDescriptor_BULKONLY,
|
||||
0 // No string descriptor for interface.
|
||||
},
|
||||
// Bulk-OUT endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_OUT,
|
||||
MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||
0 // No string descriptor for endpoint.
|
||||
},
|
||||
// Bulk-IN endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_IN,
|
||||
MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||
0 // No string descriptor for endpoint.
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
/// Language ID string descriptor.
|
||||
static const unsigned char languageIdDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(1),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_ENGLISH_US
|
||||
};
|
||||
|
||||
/// Manufacturer string descriptor.
|
||||
static const unsigned char manufacturerDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(7),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_UNICODE('9'),
|
||||
USBStringDescriptor_UNICODE('X'),
|
||||
USBStringDescriptor_UNICODE(' '),
|
||||
USBStringDescriptor_UNICODE('T'),
|
||||
USBStringDescriptor_UNICODE('E'),
|
||||
USBStringDescriptor_UNICODE('A'),
|
||||
USBStringDescriptor_UNICODE('M'),
|
||||
};
|
||||
|
||||
/// Product string descriptor.
|
||||
static const unsigned char productDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(5),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_UNICODE('S'),
|
||||
USBStringDescriptor_UNICODE('K'),
|
||||
USBStringDescriptor_UNICODE('Y'),
|
||||
USBStringDescriptor_UNICODE('9'),
|
||||
USBStringDescriptor_UNICODE('X'),
|
||||
};
|
||||
|
||||
/// Serial number string descriptor. The serial number must be at least 12
|
||||
/// characters long and made up of only letters & numbers to be compliant with
|
||||
/// the MSD specification.
|
||||
static const unsigned char serialNumberDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(12),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_UNICODE('0'),
|
||||
USBStringDescriptor_UNICODE('1'),
|
||||
USBStringDescriptor_UNICODE('2'),
|
||||
USBStringDescriptor_UNICODE('3'),
|
||||
USBStringDescriptor_UNICODE('4'),
|
||||
USBStringDescriptor_UNICODE('5'),
|
||||
USBStringDescriptor_UNICODE('6'),
|
||||
USBStringDescriptor_UNICODE('7'),
|
||||
USBStringDescriptor_UNICODE('8'),
|
||||
USBStringDescriptor_UNICODE('9'),
|
||||
USBStringDescriptor_UNICODE('A'),
|
||||
USBStringDescriptor_UNICODE('B')
|
||||
};
|
||||
|
||||
/// List of all string descriptors used.
|
||||
static const unsigned char *stringDescriptors[] = {
|
||||
|
||||
languageIdDescriptor,
|
||||
manufacturerDescriptor,
|
||||
productDescriptor,
|
||||
serialNumberDescriptor
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// List of the standard descriptors used by the Mass Storage driver.
|
||||
const USBDDriverDescriptors msdDriverDescriptors = {
|
||||
|
||||
&deviceDescriptor,
|
||||
(USBConfigurationDescriptor *) &configurationDescriptorsFS,
|
||||
#if defined(CHIP_USB_UDPHS) || defined(CHIP_USB_OTGHS)
|
||||
&qualifierDescriptor,
|
||||
(USBConfigurationDescriptor *) &otherSpeedDescriptorsFS,
|
||||
&deviceDescriptor,
|
||||
(USBConfigurationDescriptor *) &configurationDescriptorsHS,
|
||||
&qualifierDescriptor,
|
||||
(USBConfigurationDescriptor *) &otherSpeedDescriptorsHS,
|
||||
#else
|
||||
0, // No full-speed device qualifier descriptor
|
||||
0, // No full-speed other speed configuration
|
||||
0, // No high-speed device descriptor
|
||||
0, // No high-speed configuration descriptor
|
||||
0, // No high-speed device qualifier descriptor
|
||||
0, // No high-speed other speed configuration descriptor
|
||||
#endif
|
||||
stringDescriptors,
|
||||
4 // Four string descriptors in array
|
||||
};
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSDDriverDescriptors.h"
|
||||
|
||||
#include "../../../usb/common/core/USBStringDescriptor.h"
|
||||
#include "../../../usb/common/massstorage/MSDeviceDescriptor.h"
|
||||
#include "../../../usb/common/massstorage/MSInterfaceDescriptor.h"
|
||||
#include "board_lowlevel.h"
|
||||
#include "../../../usb/common/core/USBConfigurationDescriptor.h"
|
||||
#include "../../../usb/common/core/USBDeviceDescriptor.h"
|
||||
#include "../../../usb/common/core/USBEndpointDescriptor.h"
|
||||
#include "../../../usb/common/core/USBGenericDescriptor.h"
|
||||
#include "../../../usb/common/core/USBInterfaceDescriptor.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD Device Descriptor IDs"
|
||||
/// ...
|
||||
/// !IDs
|
||||
/// - MSDDriverDescriptors_VENDORID
|
||||
/// - MSDDriverDescriptors_PRODUCTID
|
||||
/// - MSDDriverDescriptors_RELEASE
|
||||
|
||||
/// Vendor ID for the Mass Storage device driver.
|
||||
#define MSDDriverDescriptors_VENDORID 0x03EB
|
||||
/// Product ID for the Mass Storage device driver.
|
||||
#define MSDDriverDescriptors_PRODUCTID 0x6129
|
||||
/// Device release number for the Mass Storage device driver.
|
||||
#define MSDDriverDescriptors_RELEASE 0x0100
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Macros
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Returns the minimum between two values.
|
||||
#define MIN(a, b) ((a < b) ? a : b)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// List of configuration descriptors used by a Mass Storage device driver.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Standard configuration descriptor.
|
||||
USBConfigurationDescriptor configuration;
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
USBOtgDescriptor otgDescriptor;
|
||||
#endif
|
||||
/// Mass storage interface descriptor.
|
||||
USBInterfaceDescriptor interface;
|
||||
/// Bulk-out endpoint descriptor.
|
||||
USBEndpointDescriptor bulkOut;
|
||||
/// Bulk-in endpoint descriptor.
|
||||
USBEndpointDescriptor bulkIn;
|
||||
|
||||
} __attribute__ ((packed)) MSDConfigurationDescriptors;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Local variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Mass storage driver device descriptor.
|
||||
static const USBDeviceDescriptor deviceDescriptor = {
|
||||
|
||||
sizeof(USBDeviceDescriptor),
|
||||
USBGenericDescriptor_DEVICE,
|
||||
USBDeviceDescriptor_USB2_00,
|
||||
MSDeviceDescriptor_CLASS,
|
||||
MSDeviceDescriptor_SUBCLASS,
|
||||
MSDeviceDescriptor_PROTOCOL,
|
||||
CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0),
|
||||
MSDDriverDescriptors_VENDORID,
|
||||
MSDDriverDescriptors_PRODUCTID,
|
||||
MSDDriverDescriptors_RELEASE,
|
||||
1, // Manufacturer string descriptor index.
|
||||
2, // Product string descriptor index.
|
||||
3, // Serial number string descriptor index.
|
||||
1 // Device has one possible configuration.
|
||||
};
|
||||
|
||||
#if defined(CHIP_USB_UDPHS) || defined(CHIP_USB_OTGHS)
|
||||
/// Device qualifier descriptor.
|
||||
static const USBDeviceQualifierDescriptor qualifierDescriptor = {
|
||||
|
||||
sizeof(USBDeviceQualifierDescriptor),
|
||||
USBGenericDescriptor_DEVICEQUALIFIER,
|
||||
USBDeviceDescriptor_USB2_00,
|
||||
MSDeviceDescriptor_CLASS,
|
||||
MSDeviceDescriptor_SUBCLASS,
|
||||
MSDeviceDescriptor_PROTOCOL,
|
||||
CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0),
|
||||
1, // Device has one possible configuration.
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
/// Full-speed configuration descriptor.
|
||||
static const MSDConfigurationDescriptors configurationDescriptorsFS = {
|
||||
|
||||
// Standard configuration descriptor.
|
||||
{
|
||||
sizeof(USBConfigurationDescriptor),
|
||||
USBGenericDescriptor_CONFIGURATION,
|
||||
sizeof(MSDConfigurationDescriptors),
|
||||
1, // Configuration has one interface.
|
||||
1, // This is configuration #1.
|
||||
0, // No string descriptor for configuration.
|
||||
BOARD_USB_BMATTRIBUTES,
|
||||
USBConfigurationDescriptor_POWER(100)
|
||||
},
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
{
|
||||
sizeof(USBOtgDescriptor),
|
||||
USBGenericDescriptor_OTG,
|
||||
USBOTGDescriptor_HNP_SRP
|
||||
},
|
||||
#endif
|
||||
// Mass Storage interface descriptor.
|
||||
{
|
||||
sizeof(USBInterfaceDescriptor),
|
||||
USBGenericDescriptor_INTERFACE,
|
||||
0, // This is interface #0.
|
||||
0, // This is alternate setting #0.
|
||||
2, // Interface uses two endpoints.
|
||||
MSInterfaceDescriptor_CLASS,
|
||||
MSInterfaceDescriptor_SCSI,
|
||||
MSInterfaceDescriptor_BULKONLY,
|
||||
0 // No string descriptor for interface.
|
||||
},
|
||||
// Bulk-OUT endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_OUT,
|
||||
MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||
0 // Must be 0 for full-speed Bulk endpoints.
|
||||
},
|
||||
// Bulk-IN endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_IN,
|
||||
MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||
0 // Must be 0 for full-speed Bulk endpoints.
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(CHIP_USB_UDPHS) || defined(CHIP_USB_OTGHS)
|
||||
/// Full-speed other speed configuration descriptor.
|
||||
static const MSDConfigurationDescriptors otherSpeedDescriptorsFS = {
|
||||
|
||||
// Standard configuration descriptor.
|
||||
{
|
||||
sizeof(USBConfigurationDescriptor),
|
||||
USBGenericDescriptor_OTHERSPEEDCONFIGURATION,
|
||||
sizeof(MSDConfigurationDescriptors),
|
||||
1, // Configuration has one interface.
|
||||
1, // This is configuration #1.
|
||||
0, // No string descriptor for configuration.
|
||||
BOARD_USB_BMATTRIBUTES,
|
||||
USBConfigurationDescriptor_POWER(100)
|
||||
},
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
{
|
||||
sizeof(USBOtgDescriptor),
|
||||
USBGenericDescriptor_OTG,
|
||||
USBOTGDescriptor_HNP_SRP
|
||||
},
|
||||
#endif
|
||||
// Mass Storage interface descriptor.
|
||||
{
|
||||
sizeof(USBInterfaceDescriptor),
|
||||
USBGenericDescriptor_INTERFACE,
|
||||
0, // This is interface #0.
|
||||
0, // This is alternate setting #0.
|
||||
2, // Interface uses two endpoints.
|
||||
MSInterfaceDescriptor_CLASS,
|
||||
MSInterfaceDescriptor_SCSI,
|
||||
MSInterfaceDescriptor_BULKONLY,
|
||||
0 // No string descriptor for interface.
|
||||
},
|
||||
// Bulk-OUT endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_OUT,
|
||||
MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_HS),
|
||||
0 // No string descriptor for endpoint.
|
||||
},
|
||||
// Bulk-IN endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_IN,
|
||||
MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_HS),
|
||||
0 // No string descriptor for endpoint.
|
||||
}
|
||||
};
|
||||
|
||||
/// High-speed configuration descriptor.
|
||||
static const MSDConfigurationDescriptors configurationDescriptorsHS = {
|
||||
|
||||
// Standard configuration descriptor.
|
||||
{
|
||||
sizeof(USBConfigurationDescriptor),
|
||||
USBGenericDescriptor_CONFIGURATION,
|
||||
sizeof(MSDConfigurationDescriptors),
|
||||
1, // Configuration has one interface.
|
||||
1, // This is configuration #1.
|
||||
0, // No string descriptor for configuration.
|
||||
BOARD_USB_BMATTRIBUTES,
|
||||
USBConfigurationDescriptor_POWER(100)
|
||||
},
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
{
|
||||
sizeof(USBOtgDescriptor),
|
||||
USBGenericDescriptor_OTG,
|
||||
USBOTGDescriptor_HNP_SRP
|
||||
},
|
||||
#endif
|
||||
// Mass Storage interface descriptor.
|
||||
{
|
||||
sizeof(USBInterfaceDescriptor),
|
||||
USBGenericDescriptor_INTERFACE,
|
||||
0, // This is interface #0.
|
||||
0, // This is alternate setting #0.
|
||||
2, // Interface uses two endpoints.
|
||||
MSInterfaceDescriptor_CLASS,
|
||||
MSInterfaceDescriptor_SCSI,
|
||||
MSInterfaceDescriptor_BULKONLY,
|
||||
0 // No string descriptor for interface.
|
||||
},
|
||||
// Bulk-OUT endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_OUT,
|
||||
MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_HS),
|
||||
0 // No string descriptor for endpoint.
|
||||
},
|
||||
// Bulk-IN endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_IN,
|
||||
MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_HS),
|
||||
0 // No string descriptor for endpoint.
|
||||
}
|
||||
};
|
||||
|
||||
/// High-speed other speed configuration descriptor.
|
||||
static const MSDConfigurationDescriptors otherSpeedDescriptorsHS = {
|
||||
|
||||
// Standard configuration descriptor.
|
||||
{
|
||||
sizeof(USBConfigurationDescriptor),
|
||||
USBGenericDescriptor_OTHERSPEEDCONFIGURATION,
|
||||
sizeof(MSDConfigurationDescriptors),
|
||||
1, // Configuration has one interface.
|
||||
1, // This is configuration #1.
|
||||
0, // No string descriptor for configuration.
|
||||
BOARD_USB_BMATTRIBUTES,
|
||||
USBConfigurationDescriptor_POWER(100)
|
||||
},
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
// OTG descriptor
|
||||
{
|
||||
sizeof(USBOtgDescriptor),
|
||||
USBGenericDescriptor_OTG,
|
||||
USBOTGDescriptor_HNP_SRP
|
||||
},
|
||||
#endif
|
||||
// Mass Storage interface descriptor.
|
||||
{
|
||||
sizeof(USBInterfaceDescriptor),
|
||||
USBGenericDescriptor_INTERFACE,
|
||||
0, // This is interface #0.
|
||||
0, // This is alternate setting #0.
|
||||
2, // Interface uses two endpoints.
|
||||
MSInterfaceDescriptor_CLASS,
|
||||
MSInterfaceDescriptor_SCSI,
|
||||
MSInterfaceDescriptor_BULKONLY,
|
||||
0 // No string descriptor for interface.
|
||||
},
|
||||
// Bulk-OUT endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_OUT,
|
||||
MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||
0 // No string descriptor for endpoint.
|
||||
},
|
||||
// Bulk-IN endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT,
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_IN,
|
||||
MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_BULK,
|
||||
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
|
||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||
0 // No string descriptor for endpoint.
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
/// Language ID string descriptor.
|
||||
static const unsigned char languageIdDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(1),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_ENGLISH_US
|
||||
};
|
||||
|
||||
/// Manufacturer string descriptor.
|
||||
static const unsigned char manufacturerDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(7),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_UNICODE('9'),
|
||||
USBStringDescriptor_UNICODE('X'),
|
||||
USBStringDescriptor_UNICODE(' '),
|
||||
USBStringDescriptor_UNICODE('T'),
|
||||
USBStringDescriptor_UNICODE('E'),
|
||||
USBStringDescriptor_UNICODE('A'),
|
||||
USBStringDescriptor_UNICODE('M'),
|
||||
};
|
||||
|
||||
/// Product string descriptor.
|
||||
static const unsigned char productDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(5),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_UNICODE('S'),
|
||||
USBStringDescriptor_UNICODE('K'),
|
||||
USBStringDescriptor_UNICODE('Y'),
|
||||
USBStringDescriptor_UNICODE('9'),
|
||||
USBStringDescriptor_UNICODE('X'),
|
||||
};
|
||||
|
||||
/// Serial number string descriptor. The serial number must be at least 12
|
||||
/// characters long and made up of only letters & numbers to be compliant with
|
||||
/// the MSD specification.
|
||||
static const unsigned char serialNumberDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(12),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_UNICODE('0'),
|
||||
USBStringDescriptor_UNICODE('1'),
|
||||
USBStringDescriptor_UNICODE('2'),
|
||||
USBStringDescriptor_UNICODE('3'),
|
||||
USBStringDescriptor_UNICODE('4'),
|
||||
USBStringDescriptor_UNICODE('5'),
|
||||
USBStringDescriptor_UNICODE('6'),
|
||||
USBStringDescriptor_UNICODE('7'),
|
||||
USBStringDescriptor_UNICODE('8'),
|
||||
USBStringDescriptor_UNICODE('9'),
|
||||
USBStringDescriptor_UNICODE('A'),
|
||||
USBStringDescriptor_UNICODE('B')
|
||||
};
|
||||
|
||||
/// List of all string descriptors used.
|
||||
static const unsigned char *stringDescriptors[] = {
|
||||
|
||||
languageIdDescriptor,
|
||||
manufacturerDescriptor,
|
||||
productDescriptor,
|
||||
serialNumberDescriptor
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Global variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// List of the standard descriptors used by the Mass Storage driver.
|
||||
const USBDDriverDescriptors msdDriverDescriptors = {
|
||||
|
||||
&deviceDescriptor,
|
||||
(USBConfigurationDescriptor *) &configurationDescriptorsFS,
|
||||
#if defined(CHIP_USB_UDPHS) || defined(CHIP_USB_OTGHS)
|
||||
&qualifierDescriptor,
|
||||
(USBConfigurationDescriptor *) &otherSpeedDescriptorsFS,
|
||||
&deviceDescriptor,
|
||||
(USBConfigurationDescriptor *) &configurationDescriptorsHS,
|
||||
&qualifierDescriptor,
|
||||
(USBConfigurationDescriptor *) &otherSpeedDescriptorsHS,
|
||||
#else
|
||||
0, // No full-speed device qualifier descriptor
|
||||
0, // No full-speed other speed configuration
|
||||
0, // No high-speed device descriptor
|
||||
0, // No high-speed configuration descriptor
|
||||
0, // No high-speed device qualifier descriptor
|
||||
0, // No high-speed other speed configuration descriptor
|
||||
#endif
|
||||
stringDescriptors,
|
||||
4 // Four string descriptors in array
|
||||
};
|
||||
|
||||
|
||||
@@ -1,83 +1,83 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Definitions of the descriptors required by a Mass Storage device driver.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// - For a USB %device:
|
||||
/// -# When initializing a USBDDriver instance, use msdDriverDescriptors as
|
||||
/// the list of standard descriptors.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSDDRIVERDESCRIPTORS_H
|
||||
#define MSDDRIVERDESCRIPTORS_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/core/USBDDriverDescriptors.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD endpoint addresses"
|
||||
/// This page lists the addresses used by the Mass Storage driver %endpoints.
|
||||
///
|
||||
/// !Addresses
|
||||
///
|
||||
/// - MSDDriverDescriptors_BULKOUT
|
||||
/// - MSDDriverDescriptors_BULKIN
|
||||
|
||||
/// Address of the Mass Storage bulk-out endpoint.
|
||||
#define MSDDriverDescriptors_BULKOUT 1
|
||||
|
||||
/// Address of the Mass Storage bulk-in endpoint.
|
||||
#if defined(at91sam9m10)
|
||||
#define MSDDriverDescriptors_BULKIN 6
|
||||
#else
|
||||
#define MSDDriverDescriptors_BULKIN 2
|
||||
#endif
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern const USBDDriverDescriptors msdDriverDescriptors;
|
||||
|
||||
#endif //#ifndef MSDDRIVERDESCRIPTORS_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Definitions of the descriptors required by a Mass Storage device driver.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// - For a USB %device:
|
||||
/// -# When initializing a USBDDriver instance, use msdDriverDescriptors as
|
||||
/// the list of standard descriptors.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSDDRIVERDESCRIPTORS_H
|
||||
#define MSDDRIVERDESCRIPTORS_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/core/USBDDriverDescriptors.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "MSD endpoint addresses"
|
||||
/// This page lists the addresses used by the Mass Storage driver %endpoints.
|
||||
///
|
||||
/// !Addresses
|
||||
///
|
||||
/// - MSDDriverDescriptors_BULKOUT
|
||||
/// - MSDDriverDescriptors_BULKIN
|
||||
|
||||
/// Address of the Mass Storage bulk-out endpoint.
|
||||
#define MSDDriverDescriptors_BULKOUT 1
|
||||
|
||||
/// Address of the Mass Storage bulk-in endpoint.
|
||||
#if defined(at91sam9m10)
|
||||
#define MSDDriverDescriptors_BULKIN 6
|
||||
#else
|
||||
#define MSDDriverDescriptors_BULKIN 2
|
||||
#endif
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern const USBDDriverDescriptors msdDriverDescriptors;
|
||||
|
||||
#endif //#ifndef MSDDRIVERDESCRIPTORS_H
|
||||
|
||||
|
||||
@@ -1,135 +1,135 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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 _MSDIOFIFO_H
|
||||
#define _MSDIOFIFO_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Idle state, do nothing
|
||||
#define MSDIO_IDLE 0
|
||||
/// Start, to start IO operation
|
||||
#define MSDIO_START 1
|
||||
/// Wait, waiting for IO operation done
|
||||
#define MSDIO_WAIT 2
|
||||
/// Next, to check if the next block can be performed
|
||||
#define MSDIO_NEXT 3
|
||||
/// Pause, to pause the process for buffer full or null
|
||||
#define MSDIO_PAUSE 4
|
||||
/// Abort, to abort the process
|
||||
#define MSDIO_ABORT 5
|
||||
/// Done, finish without error
|
||||
#define MSDIO_DONE 6
|
||||
/// Error, any error happens
|
||||
#define MSDIO_ERROR 7
|
||||
|
||||
/// FIFO offset before USB transmit start
|
||||
//#define MSDIO_FIFO_OFFSET (4*512)
|
||||
|
||||
/// FIFO trunk size (in each transfer, large amount of data)
|
||||
#if !defined(MSD_OP_BUFFER)
|
||||
#define MSDIO_READ10_CHUNK_SIZE (4*512)
|
||||
#define MSDIO_WRITE10_CHUNK_SIZE (4*512)
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// FIFO buffer for READ/WRITE (disk) operation of a mass storage device
|
||||
typedef struct _MSDIOFifo {
|
||||
|
||||
/// Pointer to the ring buffer allocated for read/write
|
||||
unsigned char * pBuffer;
|
||||
/// The size of the buffer allocated
|
||||
unsigned int bufferSize;
|
||||
#ifdef MSDIO_FIFO_OFFSET
|
||||
/// The offset to start USB transfer (READ10)
|
||||
unsigned int bufferOffset;
|
||||
#endif
|
||||
/// The index of input data (loaded to fifo buffer)
|
||||
unsigned int inputNdx;
|
||||
/// The total size of the loaded data
|
||||
unsigned int inputTotal;
|
||||
/// The index of output data (sent from the fifo buffer)
|
||||
unsigned int outputNdx;
|
||||
/// The total size of the output data
|
||||
unsigned int outputTotal;
|
||||
|
||||
/// The total size of the data
|
||||
unsigned int dataTotal;
|
||||
/// The size of the block in bytes
|
||||
unsigned short blockSize;
|
||||
#if defined(MSDIO_READ10_CHUNK_SIZE) || defined(MSDIO_WRITE10_CHUNK_SIZE)
|
||||
/// The size of one chunk
|
||||
/// (1 block, or several blocks for large amount data R/W)
|
||||
unsigned int chunkSize;
|
||||
#endif
|
||||
/// State of input & output
|
||||
unsigned char inputState;
|
||||
unsigned char outputState;
|
||||
|
||||
//- Statistics
|
||||
/// Times when fifo has no data to send
|
||||
unsigned short nullCnt;
|
||||
/// Times when fifo can not load more input data
|
||||
unsigned short fullCnt;
|
||||
} MSDIOFifo, *PMSDIOFifo;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// MACROS
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Increase the index, by defined block size, in the ring buffer
|
||||
/// \param ndx The index to be increased
|
||||
/// \param sectSize The defined block size
|
||||
/// \param bufSize The ring buffer size
|
||||
//------------------------------------------------------------------------------
|
||||
#define MSDIOFifo_IncNdx(ndx, sectSize, bufSize) \
|
||||
if ((ndx) >= (bufSize) - (sectSize)) (ndx) = 0; \
|
||||
else (ndx) += (sectSize)
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported Functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
extern void MSDIOFifo_Init(MSDIOFifo *pFifo,
|
||||
void * pBuffer, unsigned short bufferSize);
|
||||
|
||||
#endif // _MSDIOFIFO_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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 _MSDIOFIFO_H
|
||||
#define _MSDIOFIFO_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Idle state, do nothing
|
||||
#define MSDIO_IDLE 0
|
||||
/// Start, to start IO operation
|
||||
#define MSDIO_START 1
|
||||
/// Wait, waiting for IO operation done
|
||||
#define MSDIO_WAIT 2
|
||||
/// Next, to check if the next block can be performed
|
||||
#define MSDIO_NEXT 3
|
||||
/// Pause, to pause the process for buffer full or null
|
||||
#define MSDIO_PAUSE 4
|
||||
/// Abort, to abort the process
|
||||
#define MSDIO_ABORT 5
|
||||
/// Done, finish without error
|
||||
#define MSDIO_DONE 6
|
||||
/// Error, any error happens
|
||||
#define MSDIO_ERROR 7
|
||||
|
||||
/// FIFO offset before USB transmit start
|
||||
//#define MSDIO_FIFO_OFFSET (4*512)
|
||||
|
||||
/// FIFO trunk size (in each transfer, large amount of data)
|
||||
#if !defined(MSD_OP_BUFFER)
|
||||
#define MSDIO_READ10_CHUNK_SIZE (4*512)
|
||||
#define MSDIO_WRITE10_CHUNK_SIZE (4*512)
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// FIFO buffer for READ/WRITE (disk) operation of a mass storage device
|
||||
typedef struct _MSDIOFifo {
|
||||
|
||||
/// Pointer to the ring buffer allocated for read/write
|
||||
unsigned char * pBuffer;
|
||||
/// The size of the buffer allocated
|
||||
unsigned int bufferSize;
|
||||
#ifdef MSDIO_FIFO_OFFSET
|
||||
/// The offset to start USB transfer (READ10)
|
||||
unsigned int bufferOffset;
|
||||
#endif
|
||||
/// The index of input data (loaded to fifo buffer)
|
||||
unsigned int inputNdx;
|
||||
/// The total size of the loaded data
|
||||
unsigned int inputTotal;
|
||||
/// The index of output data (sent from the fifo buffer)
|
||||
unsigned int outputNdx;
|
||||
/// The total size of the output data
|
||||
unsigned int outputTotal;
|
||||
|
||||
/// The total size of the data
|
||||
unsigned int dataTotal;
|
||||
/// The size of the block in bytes
|
||||
unsigned short blockSize;
|
||||
#if defined(MSDIO_READ10_CHUNK_SIZE) || defined(MSDIO_WRITE10_CHUNK_SIZE)
|
||||
/// The size of one chunk
|
||||
/// (1 block, or several blocks for large amount data R/W)
|
||||
unsigned int chunkSize;
|
||||
#endif
|
||||
/// State of input & output
|
||||
unsigned char inputState;
|
||||
unsigned char outputState;
|
||||
|
||||
//- Statistics
|
||||
/// Times when fifo has no data to send
|
||||
unsigned short nullCnt;
|
||||
/// Times when fifo can not load more input data
|
||||
unsigned short fullCnt;
|
||||
} MSDIOFifo, *PMSDIOFifo;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// MACROS
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Increase the index, by defined block size, in the ring buffer
|
||||
/// \param ndx The index to be increased
|
||||
/// \param sectSize The defined block size
|
||||
/// \param bufSize The ring buffer size
|
||||
//------------------------------------------------------------------------------
|
||||
#define MSDIOFifo_IncNdx(ndx, sectSize, bufSize) \
|
||||
if ((ndx) >= (bufSize) - (sectSize)) (ndx) = 0; \
|
||||
else (ndx) += (sectSize)
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported Functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
extern void MSDIOFifo_Init(MSDIOFifo *pFifo,
|
||||
void * pBuffer, unsigned short bufferSize);
|
||||
|
||||
#endif // _MSDIOFIFO_H
|
||||
|
||||
|
||||
@@ -1,367 +1,367 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include "../../../usb/device/massstorage/MSDLun.h"
|
||||
#include "board_lowlevel.h"
|
||||
#include "../../../usb/device/core/USBD.h"
|
||||
#include "debug.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Constants
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Default LUN block size in bytes
|
||||
#define DEFAULT_LUN_BLOCK_SIZE BLOCK_SIZE
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Inquiry data to return to the host for the Lun.
|
||||
static SBCInquiryData inquiryData = {
|
||||
|
||||
SBC_DIRECT_ACCESS_BLOCK_DEVICE, // Direct-access block device
|
||||
SBC_PERIPHERAL_DEVICE_CONNECTED,// Peripheral device is connected
|
||||
0x00, // Reserved bits
|
||||
0x01, // Media is removable
|
||||
0x02, // SBC_SPC_VERSION_4, // SPC-4 supported
|
||||
0x2, // Response data format, must be 0x2
|
||||
0, // Hierarchical addressing not supported
|
||||
0, // ACA not supported
|
||||
0x0, // Obsolete bits
|
||||
sizeof(SBCInquiryData) - 5, // Additional length
|
||||
0, // No embedded SCC
|
||||
0, // No access control coordinator
|
||||
SBC_TPGS_NONE, // No target port support group
|
||||
0, // Third-party copy not supported
|
||||
0x0, // Reserved bits
|
||||
0, // Protection information not supported
|
||||
0x0, // Obsolete bit
|
||||
0, // No embedded enclosure service component
|
||||
0x0, // ???
|
||||
0, // Device is not multi-port
|
||||
0x0, // Obsolete bits
|
||||
0x0, // Unused feature
|
||||
0x0, // Unused features
|
||||
0, // Task management model not supported
|
||||
0x0, // ???
|
||||
{'A','T','M','E','L',' ',' ',' '},
|
||||
{'M','a','s','s',' ',
|
||||
'S','t','o','r','a','g','e',' ',
|
||||
'M','S','D'},
|
||||
{'0','.','0','1'},
|
||||
{'M','a','s','s',' ',
|
||||
'S','t','o','r','a','g','e',' ',
|
||||
'E','x','a','m','p','l','e'},
|
||||
0x00, // Unused features
|
||||
0x00, // Reserved bits
|
||||
{SBC_VERSION_DESCRIPTOR_SBC_3}, // SBC-3 compliant device
|
||||
{0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0} // Reserved
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Initializes a LUN instance. Must be invoked at least once even no
|
||||
//! Media is linked.
|
||||
//! \param lun Pointer to the MSDLun instance to initialize
|
||||
//! \param media Media on which the LUN is constructed, set to 0 to
|
||||
//! disconnect the Media or initialize an ejected LUN.
|
||||
//! \param ioBuffer Pointer to a buffer used for read/write operation and
|
||||
//! which must be blockSize bytes long.
|
||||
//! \param ioBufferSize Size of the allocated IO buffer.
|
||||
//! \param baseAddress Base address of the LUN in number of media blocks
|
||||
//! \param size Total size of the LUN in number of media blocks
|
||||
//! \param blockSize One block of the LUN in number of media blocks
|
||||
//! \param protected The LUN area is forced to readonly even the media
|
||||
//! is writable
|
||||
//! \param dataMonitor Pointer to a Monitor Function to analyze the flow of
|
||||
//! this LUN.
|
||||
//------------------------------------------------------------------------------
|
||||
void LUN_Init(MSDLun *lun,
|
||||
Media *media,
|
||||
unsigned char *ioBuffer,
|
||||
unsigned int ioBufferSize,
|
||||
unsigned int baseAddress,
|
||||
unsigned int size,
|
||||
unsigned short blockSize,
|
||||
unsigned char protected,
|
||||
void (*dataMonitor)(unsigned char flowDirection,
|
||||
unsigned int dataLength,
|
||||
unsigned int fifoNullCount,
|
||||
unsigned int fifoFullCount))
|
||||
{
|
||||
unsigned int logicalBlockAddress;
|
||||
TRACE_INFO("LUN init\n\r");
|
||||
|
||||
// Initialize inquiry data
|
||||
lun->inquiryData = &inquiryData;
|
||||
|
||||
// Initialize request sense data
|
||||
lun->requestSenseData.bResponseCode = SBC_SENSE_DATA_FIXED_CURRENT;
|
||||
lun->requestSenseData.isValid = 1;
|
||||
lun->requestSenseData.bObsolete1 = 0;
|
||||
lun->requestSenseData.bSenseKey = SBC_SENSE_KEY_NO_SENSE;
|
||||
lun->requestSenseData.bReserved1 = 0;
|
||||
lun->requestSenseData.isILI = 0;
|
||||
lun->requestSenseData.isEOM = 0;
|
||||
lun->requestSenseData.isFilemark = 0;
|
||||
lun->requestSenseData.pInformation[0] = 0;
|
||||
lun->requestSenseData.pInformation[1] = 0;
|
||||
lun->requestSenseData.pInformation[2] = 0;
|
||||
lun->requestSenseData.pInformation[3] = 0;
|
||||
lun->requestSenseData.bAdditionalSenseLength
|
||||
= sizeof(SBCRequestSenseData) - 8;
|
||||
lun->requestSenseData.bAdditionalSenseCode = 0;
|
||||
lun->requestSenseData.bAdditionalSenseCodeQualifier = 0;
|
||||
lun->requestSenseData.bFieldReplaceableUnitCode = 0;
|
||||
lun->requestSenseData.bSenseKeySpecific = 0;
|
||||
lun->requestSenseData.pSenseKeySpecific[0] = 0;
|
||||
lun->requestSenseData.pSenseKeySpecific[0] = 0;
|
||||
lun->requestSenseData.isSKSV = 0;
|
||||
|
||||
STORE_DWORDB(0, lun->readCapacityData.pLogicalBlockAddress);
|
||||
STORE_DWORDB(0, lun->readCapacityData.pLogicalBlockLength);
|
||||
|
||||
// Initialize LUN
|
||||
lun->media = media;
|
||||
if (media == 0) {
|
||||
lun->status = LUN_NOT_PRESENT;
|
||||
return;
|
||||
}
|
||||
|
||||
lun->baseAddress = baseAddress;
|
||||
|
||||
// Customized block size
|
||||
if (blockSize) {
|
||||
lun->blockSize = blockSize;
|
||||
}
|
||||
else {
|
||||
if (media->blockSize < DEFAULT_LUN_BLOCK_SIZE)
|
||||
lun->blockSize = DEFAULT_LUN_BLOCK_SIZE / media->blockSize;
|
||||
else
|
||||
lun->blockSize = 1;
|
||||
}
|
||||
|
||||
if (size) {
|
||||
lun->size = size;
|
||||
}
|
||||
else {
|
||||
lun->size = media->size;
|
||||
//if (blockSize)
|
||||
// lun->size = media->size / blockSize;
|
||||
//else {
|
||||
// if (media->blockSize < DEFAULT_LUN_BLOCK_SIZE)
|
||||
// lun->size = media->size / lun->blockSize;
|
||||
// else
|
||||
// lun->size = media->size;
|
||||
//}
|
||||
}
|
||||
|
||||
TRACE_INFO("LUN: blkSize %d, size %d\n\r", (int)lun->blockSize, (int)lun->size);
|
||||
if (protected) lun->protected = 1;
|
||||
else lun->protected = media->protected;
|
||||
|
||||
lun->ioFifo.pBuffer = ioBuffer;
|
||||
lun->ioFifo.bufferSize = ioBufferSize;
|
||||
|
||||
lun->dataMonitor = dataMonitor;
|
||||
|
||||
// Initialize read capacity data
|
||||
logicalBlockAddress = lun->size / lun->blockSize - 1;
|
||||
STORE_DWORDB(logicalBlockAddress,
|
||||
lun->readCapacityData.pLogicalBlockAddress);
|
||||
STORE_DWORDB(lun->blockSize * media->blockSize,
|
||||
lun->readCapacityData.pLogicalBlockLength);
|
||||
|
||||
// Indicate media change
|
||||
lun->status = LUN_CHANGED;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Eject the media from a LUN
|
||||
//! \param lun Pointer to the MSDLun instance to initialize
|
||||
//! \return Operation result code
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char LUN_Eject(MSDLun *lun)
|
||||
{
|
||||
if (lun->media) {
|
||||
|
||||
// Avoid any LUN R/W in progress
|
||||
if (lun->media->state == MED_STATE_BUSY) {
|
||||
|
||||
return USBD_STATUS_LOCKED;
|
||||
}
|
||||
|
||||
// Remove the link of the media
|
||||
lun->media = 0;
|
||||
}
|
||||
// LUN is removed
|
||||
lun->status = LUN_NOT_PRESENT;
|
||||
|
||||
return USBD_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Writes data on the a LUN starting at the specified block address.
|
||||
//! \param lun Pointer to a MSDLun instance
|
||||
//! \param blockAddress First block address to write
|
||||
//! \param data Pointer to the data to write
|
||||
//! \param length Number of blocks to write
|
||||
//! \param callback Optional callback to invoke when the write finishes
|
||||
//! \return Operation result code
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char LUN_Write(MSDLun *lun,
|
||||
unsigned int blockAddress,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
TransferCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
unsigned int medBlk, medLen;
|
||||
unsigned char status;
|
||||
|
||||
TRACE_INFO_WP("LUNWrite(%u) ", blockAddress);
|
||||
|
||||
// Check that the data is not too big
|
||||
if ((length + blockAddress) * lun->blockSize > lun->size) {
|
||||
|
||||
TRACE_WARNING("LUN_Write: Data too big\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else if (lun->media == 0 || lun->status != LUN_READY) {
|
||||
|
||||
TRACE_WARNING("LUN_Write: Media not ready\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else if (lun->protected) {
|
||||
TRACE_WARNING("LUN_Write: LUN is readonly\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else {
|
||||
|
||||
// Compute write start address
|
||||
medBlk = lun->baseAddress + blockAddress * lun->blockSize;
|
||||
medLen = length * lun->blockSize;
|
||||
|
||||
// Start write operation
|
||||
status = MED_Write(lun->media,
|
||||
medBlk,
|
||||
data,
|
||||
medLen,
|
||||
(MediaCallback) callback,
|
||||
argument);
|
||||
|
||||
// Check operation result code
|
||||
if (status == MED_STATUS_SUCCESS) {
|
||||
|
||||
status = USBD_STATUS_SUCCESS;
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_WARNING("LUN_Write: Cannot write media\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Reads data from a LUN, starting at the specified block address.
|
||||
//! \param lun Pointer to a MSDLun instance
|
||||
//! \param blockAddress First block address to read
|
||||
//! \param data Pointer to a data buffer in which to store the data
|
||||
//! \param length Number of blocks to read
|
||||
//! \param callback Optional callback to invoke when the read finishes
|
||||
//! \return Operation result code
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char LUN_Read(MSDLun *lun,
|
||||
unsigned int blockAddress,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
TransferCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
unsigned int medBlk, medLen;
|
||||
unsigned char status;
|
||||
|
||||
// Check that the data is not too big
|
||||
if ((length + blockAddress) * lun->blockSize > lun->size) {
|
||||
|
||||
TRACE_WARNING("LUN_Read: Area: (%d + %d)*%d > %d\n\r",
|
||||
(int)length, (int)blockAddress, (int)lun->blockSize, (int)lun->size);
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else if (lun->media == 0 || lun->status != LUN_READY) {
|
||||
|
||||
TRACE_WARNING("LUN_Read: Media not present\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_INFO_WP("LUNRead(%u) ", blockAddress);
|
||||
|
||||
// Compute read start address
|
||||
medBlk = lun->baseAddress + (blockAddress * lun->blockSize);
|
||||
medLen = length * lun->blockSize;
|
||||
|
||||
// Start write operation
|
||||
status = MED_Read(lun->media,
|
||||
medBlk,
|
||||
data,
|
||||
medLen,
|
||||
(MediaCallback) callback,
|
||||
argument);
|
||||
|
||||
// Check result code
|
||||
if (status == MED_STATUS_SUCCESS) {
|
||||
|
||||
status = USBD_STATUS_SUCCESS;
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_WARNING("LUN_Read: Cannot read media\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include "../../../usb/device/massstorage/MSDLun.h"
|
||||
#include "board_lowlevel.h"
|
||||
#include "../../../usb/device/core/USBD.h"
|
||||
#include "debug.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Constants
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Default LUN block size in bytes
|
||||
#define DEFAULT_LUN_BLOCK_SIZE BLOCK_SIZE
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Inquiry data to return to the host for the Lun.
|
||||
static SBCInquiryData inquiryData = {
|
||||
|
||||
SBC_DIRECT_ACCESS_BLOCK_DEVICE, // Direct-access block device
|
||||
SBC_PERIPHERAL_DEVICE_CONNECTED,// Peripheral device is connected
|
||||
0x00, // Reserved bits
|
||||
0x01, // Media is removable
|
||||
0x02, // SBC_SPC_VERSION_4, // SPC-4 supported
|
||||
0x2, // Response data format, must be 0x2
|
||||
0, // Hierarchical addressing not supported
|
||||
0, // ACA not supported
|
||||
0x0, // Obsolete bits
|
||||
sizeof(SBCInquiryData) - 5, // Additional length
|
||||
0, // No embedded SCC
|
||||
0, // No access control coordinator
|
||||
SBC_TPGS_NONE, // No target port support group
|
||||
0, // Third-party copy not supported
|
||||
0x0, // Reserved bits
|
||||
0, // Protection information not supported
|
||||
0x0, // Obsolete bit
|
||||
0, // No embedded enclosure service component
|
||||
0x0, // ???
|
||||
0, // Device is not multi-port
|
||||
0x0, // Obsolete bits
|
||||
0x0, // Unused feature
|
||||
0x0, // Unused features
|
||||
0, // Task management model not supported
|
||||
0x0, // ???
|
||||
{'A','T','M','E','L',' ',' ',' '},
|
||||
{'M','a','s','s',' ',
|
||||
'S','t','o','r','a','g','e',' ',
|
||||
'M','S','D'},
|
||||
{'0','.','0','1'},
|
||||
{'M','a','s','s',' ',
|
||||
'S','t','o','r','a','g','e',' ',
|
||||
'E','x','a','m','p','l','e'},
|
||||
0x00, // Unused features
|
||||
0x00, // Reserved bits
|
||||
{SBC_VERSION_DESCRIPTOR_SBC_3}, // SBC-3 compliant device
|
||||
{0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0} // Reserved
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Initializes a LUN instance. Must be invoked at least once even no
|
||||
//! Media is linked.
|
||||
//! \param lun Pointer to the MSDLun instance to initialize
|
||||
//! \param media Media on which the LUN is constructed, set to 0 to
|
||||
//! disconnect the Media or initialize an ejected LUN.
|
||||
//! \param ioBuffer Pointer to a buffer used for read/write operation and
|
||||
//! which must be blockSize bytes long.
|
||||
//! \param ioBufferSize Size of the allocated IO buffer.
|
||||
//! \param baseAddress Base address of the LUN in number of media blocks
|
||||
//! \param size Total size of the LUN in number of media blocks
|
||||
//! \param blockSize One block of the LUN in number of media blocks
|
||||
//! \param protected The LUN area is forced to readonly even the media
|
||||
//! is writable
|
||||
//! \param dataMonitor Pointer to a Monitor Function to analyze the flow of
|
||||
//! this LUN.
|
||||
//------------------------------------------------------------------------------
|
||||
void LUN_Init(MSDLun *lun,
|
||||
Media *media,
|
||||
unsigned char *ioBuffer,
|
||||
unsigned int ioBufferSize,
|
||||
unsigned int baseAddress,
|
||||
unsigned int size,
|
||||
unsigned short blockSize,
|
||||
unsigned char protected,
|
||||
void (*dataMonitor)(unsigned char flowDirection,
|
||||
unsigned int dataLength,
|
||||
unsigned int fifoNullCount,
|
||||
unsigned int fifoFullCount))
|
||||
{
|
||||
unsigned int logicalBlockAddress;
|
||||
TRACE_INFO("LUN init\n\r");
|
||||
|
||||
// Initialize inquiry data
|
||||
lun->inquiryData = &inquiryData;
|
||||
|
||||
// Initialize request sense data
|
||||
lun->requestSenseData.bResponseCode = SBC_SENSE_DATA_FIXED_CURRENT;
|
||||
lun->requestSenseData.isValid = 1;
|
||||
lun->requestSenseData.bObsolete1 = 0;
|
||||
lun->requestSenseData.bSenseKey = SBC_SENSE_KEY_NO_SENSE;
|
||||
lun->requestSenseData.bReserved1 = 0;
|
||||
lun->requestSenseData.isILI = 0;
|
||||
lun->requestSenseData.isEOM = 0;
|
||||
lun->requestSenseData.isFilemark = 0;
|
||||
lun->requestSenseData.pInformation[0] = 0;
|
||||
lun->requestSenseData.pInformation[1] = 0;
|
||||
lun->requestSenseData.pInformation[2] = 0;
|
||||
lun->requestSenseData.pInformation[3] = 0;
|
||||
lun->requestSenseData.bAdditionalSenseLength
|
||||
= sizeof(SBCRequestSenseData) - 8;
|
||||
lun->requestSenseData.bAdditionalSenseCode = 0;
|
||||
lun->requestSenseData.bAdditionalSenseCodeQualifier = 0;
|
||||
lun->requestSenseData.bFieldReplaceableUnitCode = 0;
|
||||
lun->requestSenseData.bSenseKeySpecific = 0;
|
||||
lun->requestSenseData.pSenseKeySpecific[0] = 0;
|
||||
lun->requestSenseData.pSenseKeySpecific[0] = 0;
|
||||
lun->requestSenseData.isSKSV = 0;
|
||||
|
||||
STORE_DWORDB(0, lun->readCapacityData.pLogicalBlockAddress);
|
||||
STORE_DWORDB(0, lun->readCapacityData.pLogicalBlockLength);
|
||||
|
||||
// Initialize LUN
|
||||
lun->media = media;
|
||||
if (media == 0) {
|
||||
lun->status = LUN_NOT_PRESENT;
|
||||
return;
|
||||
}
|
||||
|
||||
lun->baseAddress = baseAddress;
|
||||
|
||||
// Customized block size
|
||||
if (blockSize) {
|
||||
lun->blockSize = blockSize;
|
||||
}
|
||||
else {
|
||||
if (media->blockSize < DEFAULT_LUN_BLOCK_SIZE)
|
||||
lun->blockSize = DEFAULT_LUN_BLOCK_SIZE / media->blockSize;
|
||||
else
|
||||
lun->blockSize = 1;
|
||||
}
|
||||
|
||||
if (size) {
|
||||
lun->size = size;
|
||||
}
|
||||
else {
|
||||
lun->size = media->size;
|
||||
//if (blockSize)
|
||||
// lun->size = media->size / blockSize;
|
||||
//else {
|
||||
// if (media->blockSize < DEFAULT_LUN_BLOCK_SIZE)
|
||||
// lun->size = media->size / lun->blockSize;
|
||||
// else
|
||||
// lun->size = media->size;
|
||||
//}
|
||||
}
|
||||
|
||||
TRACE_INFO("LUN: blkSize %d, size %d\n\r", (int)lun->blockSize, (int)lun->size);
|
||||
if (protected) lun->protected = 1;
|
||||
else lun->protected = media->protected;
|
||||
|
||||
lun->ioFifo.pBuffer = ioBuffer;
|
||||
lun->ioFifo.bufferSize = ioBufferSize;
|
||||
|
||||
lun->dataMonitor = dataMonitor;
|
||||
|
||||
// Initialize read capacity data
|
||||
logicalBlockAddress = lun->size / lun->blockSize - 1;
|
||||
STORE_DWORDB(logicalBlockAddress,
|
||||
lun->readCapacityData.pLogicalBlockAddress);
|
||||
STORE_DWORDB(lun->blockSize * media->blockSize,
|
||||
lun->readCapacityData.pLogicalBlockLength);
|
||||
|
||||
// Indicate media change
|
||||
lun->status = LUN_CHANGED;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Eject the media from a LUN
|
||||
//! \param lun Pointer to the MSDLun instance to initialize
|
||||
//! \return Operation result code
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char LUN_Eject(MSDLun *lun)
|
||||
{
|
||||
if (lun->media) {
|
||||
|
||||
// Avoid any LUN R/W in progress
|
||||
if (lun->media->state == MED_STATE_BUSY) {
|
||||
|
||||
return USBD_STATUS_LOCKED;
|
||||
}
|
||||
|
||||
// Remove the link of the media
|
||||
lun->media = 0;
|
||||
}
|
||||
// LUN is removed
|
||||
lun->status = LUN_NOT_PRESENT;
|
||||
|
||||
return USBD_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Writes data on the a LUN starting at the specified block address.
|
||||
//! \param lun Pointer to a MSDLun instance
|
||||
//! \param blockAddress First block address to write
|
||||
//! \param data Pointer to the data to write
|
||||
//! \param length Number of blocks to write
|
||||
//! \param callback Optional callback to invoke when the write finishes
|
||||
//! \return Operation result code
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char LUN_Write(MSDLun *lun,
|
||||
unsigned int blockAddress,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
TransferCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
unsigned int medBlk, medLen;
|
||||
unsigned char status;
|
||||
|
||||
TRACE_INFO_WP("LUNWrite(%u) ", blockAddress);
|
||||
|
||||
// Check that the data is not too big
|
||||
if ((length + blockAddress) * lun->blockSize > lun->size) {
|
||||
|
||||
TRACE_WARNING("LUN_Write: Data too big\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else if (lun->media == 0 || lun->status != LUN_READY) {
|
||||
|
||||
TRACE_WARNING("LUN_Write: Media not ready\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else if (lun->protected) {
|
||||
TRACE_WARNING("LUN_Write: LUN is readonly\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else {
|
||||
|
||||
// Compute write start address
|
||||
medBlk = lun->baseAddress + blockAddress * lun->blockSize;
|
||||
medLen = length * lun->blockSize;
|
||||
|
||||
// Start write operation
|
||||
status = MED_Write(lun->media,
|
||||
medBlk,
|
||||
data,
|
||||
medLen,
|
||||
(MediaCallback) callback,
|
||||
argument);
|
||||
|
||||
// Check operation result code
|
||||
if (status == MED_STATUS_SUCCESS) {
|
||||
|
||||
status = USBD_STATUS_SUCCESS;
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_WARNING("LUN_Write: Cannot write media\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Reads data from a LUN, starting at the specified block address.
|
||||
//! \param lun Pointer to a MSDLun instance
|
||||
//! \param blockAddress First block address to read
|
||||
//! \param data Pointer to a data buffer in which to store the data
|
||||
//! \param length Number of blocks to read
|
||||
//! \param callback Optional callback to invoke when the read finishes
|
||||
//! \return Operation result code
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char LUN_Read(MSDLun *lun,
|
||||
unsigned int blockAddress,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
TransferCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
unsigned int medBlk, medLen;
|
||||
unsigned char status;
|
||||
|
||||
// Check that the data is not too big
|
||||
if ((length + blockAddress) * lun->blockSize > lun->size) {
|
||||
|
||||
TRACE_WARNING("LUN_Read: Area: (%d + %d)*%d > %d\n\r",
|
||||
(int)length, (int)blockAddress, (int)lun->blockSize, (int)lun->size);
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else if (lun->media == 0 || lun->status != LUN_READY) {
|
||||
|
||||
TRACE_WARNING("LUN_Read: Media not present\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_INFO_WP("LUNRead(%u) ", blockAddress);
|
||||
|
||||
// Compute read start address
|
||||
medBlk = lun->baseAddress + (blockAddress * lun->blockSize);
|
||||
medLen = length * lun->blockSize;
|
||||
|
||||
// Start write operation
|
||||
status = MED_Read(lun->media,
|
||||
medBlk,
|
||||
data,
|
||||
medLen,
|
||||
(MediaCallback) callback,
|
||||
argument);
|
||||
|
||||
// Check result code
|
||||
if (status == MED_STATUS_SUCCESS) {
|
||||
|
||||
status = USBD_STATUS_SUCCESS;
|
||||
}
|
||||
else {
|
||||
|
||||
TRACE_WARNING("LUN_Read: Cannot read media\n\r");
|
||||
status = USBD_STATUS_ABORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -1,161 +1,161 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Logical Unit Number (LUN) used by the Mass Storage driver and the SCSI
|
||||
/// protocol. Represents a logical hard-drive.
|
||||
///
|
||||
/// !Usage
|
||||
/// -# Initialize Memory related pins (see pio & board.h).
|
||||
/// -# Initialize a Media instance for the LUN (see memories).
|
||||
/// -# Initlalize the LUN with LUN_Init, and link to the initialized Media.
|
||||
/// -# To read data from the LUN linked media, uses LUN_Read.
|
||||
/// -# To write data to the LUN linked media, uses LUN_Write.
|
||||
/// -# To unlink the media, uses LUN_Eject.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSDLUN_H
|
||||
#define MSDLUN_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../Media.h"
|
||||
#include "../../../usb/device/core/USBD.h"
|
||||
#include "../../../usb/device/massstorage/MSDIOFifo.h"
|
||||
#include "../../../usb/device/massstorage/SBC.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// LUN RC: success
|
||||
#define LUN_STATUS_SUCCESS 0x00
|
||||
/// LUN RC: error
|
||||
#define LUN_STATUS_ERROR 0x02
|
||||
|
||||
/// Media of LUN is removed
|
||||
#define LUN_NOT_PRESENT 0x00
|
||||
/// LUN is ejected by host
|
||||
#define LUN_EJECTED 0x01
|
||||
/// Media of LUN is changed
|
||||
#define LUN_CHANGED 0x10
|
||||
/// LUN Not Ready to Ready transition
|
||||
#define LUN_TRANS_READY LUN_CHANGED
|
||||
/// Media of LUN is ready
|
||||
#define LUN_READY 0x11
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Structures
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// LUN structure
|
||||
typedef struct {
|
||||
|
||||
/// Pointer to a SBCInquiryData instance.
|
||||
SBCInquiryData *inquiryData;
|
||||
/// Fifo for USB transfer, must be assigned.
|
||||
MSDIOFifo ioFifo;
|
||||
/// Pointer to Media instance for the LUN.
|
||||
Media *media;
|
||||
/// Pointer to a Monitor Function to analyze the flow of LUN.
|
||||
/// \param flowDirection 1 - device to host (READ10)
|
||||
/// 0 - host to device (WRITE10)
|
||||
/// \param dataLength Length of data transferred in bytes.
|
||||
/// \param fifoNullCount Times that FIFO is NULL to wait
|
||||
/// \param fifoFullCount Times that FIFO is filled to wait
|
||||
void (*dataMonitor)(unsigned char flowDirection,
|
||||
unsigned int dataLength,
|
||||
unsigned int fifoNullCount,
|
||||
unsigned int fifoFullCount);
|
||||
/// The start position of the media (blocks) allocated to the LUN.
|
||||
unsigned int baseAddress;
|
||||
/// The size of the media (blocks) allocated to the LUN.
|
||||
unsigned int size;
|
||||
/// Sector size of the media in number of media blocks
|
||||
unsigned short blockSize;
|
||||
/// The LUN can be readonly even the media is writable
|
||||
#ifdef __cplusplus
|
||||
unsigned char protectd;
|
||||
#else
|
||||
unsigned char protected;
|
||||
#endif
|
||||
|
||||
/// The LUN status (Ejected/Changed/)
|
||||
unsigned char status;
|
||||
|
||||
/// Data for the RequestSense command.
|
||||
SBCRequestSenseData requestSenseData;
|
||||
/// Data for the ReadCapacity command.
|
||||
SBCReadCapacity10Data readCapacityData;
|
||||
|
||||
} MSDLun;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
extern void LUN_Init(MSDLun *lun,
|
||||
Media *media,
|
||||
unsigned char *ioBuffer,
|
||||
unsigned int ioBufferSize,
|
||||
unsigned int baseAddress,
|
||||
unsigned int size,
|
||||
unsigned short blockSize,
|
||||
#ifdef __cplusplus
|
||||
unsigned char protectd,
|
||||
#else
|
||||
unsigned char protected,
|
||||
#endif
|
||||
void (*dataMonitor)(unsigned char flowDirection,
|
||||
unsigned int dataLength,
|
||||
unsigned int fifoNullCount,
|
||||
unsigned int fifoFullCount));
|
||||
|
||||
extern unsigned char LUN_Eject(MSDLun *lun);
|
||||
|
||||
extern unsigned char LUN_Write(MSDLun *lun,
|
||||
unsigned int blockAddress,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
TransferCallback callback,
|
||||
void *argument);
|
||||
|
||||
extern unsigned char LUN_Read(MSDLun *lun,
|
||||
unsigned int blockAddress,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
TransferCallback callback,
|
||||
void *argument);
|
||||
|
||||
#endif //#ifndef MSDLUN_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Logical Unit Number (LUN) used by the Mass Storage driver and the SCSI
|
||||
/// protocol. Represents a logical hard-drive.
|
||||
///
|
||||
/// !Usage
|
||||
/// -# Initialize Memory related pins (see pio & board.h).
|
||||
/// -# Initialize a Media instance for the LUN (see memories).
|
||||
/// -# Initlalize the LUN with LUN_Init, and link to the initialized Media.
|
||||
/// -# To read data from the LUN linked media, uses LUN_Read.
|
||||
/// -# To write data to the LUN linked media, uses LUN_Write.
|
||||
/// -# To unlink the media, uses LUN_Eject.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MSDLUN_H
|
||||
#define MSDLUN_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../Media.h"
|
||||
#include "../../../usb/device/core/USBD.h"
|
||||
#include "../../../usb/device/massstorage/MSDIOFifo.h"
|
||||
#include "../../../usb/device/massstorage/SBC.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// LUN RC: success
|
||||
#define LUN_STATUS_SUCCESS 0x00
|
||||
/// LUN RC: error
|
||||
#define LUN_STATUS_ERROR 0x02
|
||||
|
||||
/// Media of LUN is removed
|
||||
#define LUN_NOT_PRESENT 0x00
|
||||
/// LUN is ejected by host
|
||||
#define LUN_EJECTED 0x01
|
||||
/// Media of LUN is changed
|
||||
#define LUN_CHANGED 0x10
|
||||
/// LUN Not Ready to Ready transition
|
||||
#define LUN_TRANS_READY LUN_CHANGED
|
||||
/// Media of LUN is ready
|
||||
#define LUN_READY 0x11
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Structures
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// LUN structure
|
||||
typedef struct {
|
||||
|
||||
/// Pointer to a SBCInquiryData instance.
|
||||
SBCInquiryData *inquiryData;
|
||||
/// Fifo for USB transfer, must be assigned.
|
||||
MSDIOFifo ioFifo;
|
||||
/// Pointer to Media instance for the LUN.
|
||||
Media *media;
|
||||
/// Pointer to a Monitor Function to analyze the flow of LUN.
|
||||
/// \param flowDirection 1 - device to host (READ10)
|
||||
/// 0 - host to device (WRITE10)
|
||||
/// \param dataLength Length of data transferred in bytes.
|
||||
/// \param fifoNullCount Times that FIFO is NULL to wait
|
||||
/// \param fifoFullCount Times that FIFO is filled to wait
|
||||
void (*dataMonitor)(unsigned char flowDirection,
|
||||
unsigned int dataLength,
|
||||
unsigned int fifoNullCount,
|
||||
unsigned int fifoFullCount);
|
||||
/// The start position of the media (blocks) allocated to the LUN.
|
||||
unsigned int baseAddress;
|
||||
/// The size of the media (blocks) allocated to the LUN.
|
||||
unsigned int size;
|
||||
/// Sector size of the media in number of media blocks
|
||||
unsigned short blockSize;
|
||||
/// The LUN can be readonly even the media is writable
|
||||
#ifdef __cplusplus
|
||||
unsigned char protectd;
|
||||
#else
|
||||
unsigned char protected;
|
||||
#endif
|
||||
|
||||
/// The LUN status (Ejected/Changed/)
|
||||
unsigned char status;
|
||||
|
||||
/// Data for the RequestSense command.
|
||||
SBCRequestSenseData requestSenseData;
|
||||
/// Data for the ReadCapacity command.
|
||||
SBCReadCapacity10Data readCapacityData;
|
||||
|
||||
} MSDLun;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
extern void LUN_Init(MSDLun *lun,
|
||||
Media *media,
|
||||
unsigned char *ioBuffer,
|
||||
unsigned int ioBufferSize,
|
||||
unsigned int baseAddress,
|
||||
unsigned int size,
|
||||
unsigned short blockSize,
|
||||
#ifdef __cplusplus
|
||||
unsigned char protectd,
|
||||
#else
|
||||
unsigned char protected,
|
||||
#endif
|
||||
void (*dataMonitor)(unsigned char flowDirection,
|
||||
unsigned int dataLength,
|
||||
unsigned int fifoNullCount,
|
||||
unsigned int fifoFullCount));
|
||||
|
||||
extern unsigned char LUN_Eject(MSDLun *lun);
|
||||
|
||||
extern unsigned char LUN_Write(MSDLun *lun,
|
||||
unsigned int blockAddress,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
TransferCallback callback,
|
||||
void *argument);
|
||||
|
||||
extern unsigned char LUN_Read(MSDLun *lun,
|
||||
unsigned int blockAddress,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
TransferCallback callback,
|
||||
void *argument);
|
||||
|
||||
#endif //#ifndef MSDLUN_H
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,110 +1,110 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// SCSI commands implementation.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# After a CBW is received from host, use SBC_GetCommandInformation to check
|
||||
/// if the command is supported, and get the command length and type
|
||||
/// information before processing it.
|
||||
/// -# Then SBC_ProcessCommand can be used to handle a valid command, to
|
||||
/// perform the command operations.
|
||||
/// -# SBC_UpdateSenseData is used to update the sense data that will be sent
|
||||
/// to host.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef SBCMETHODS_H
|
||||
#define SBCMETHODS_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSDDStateMachine.h"
|
||||
#include "../../../usb/device/massstorage/SBC.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "SBC Command States"
|
||||
/// This page lists the possible states of a SBC command.
|
||||
///
|
||||
/// !States
|
||||
/// - SBC_STATE_READ
|
||||
/// - SBC_STATE_WAIT_READ
|
||||
/// - SBC_STATE_WRITE
|
||||
/// - SBC_STATE_WAIT_WRITE
|
||||
/// - SBC_STATE_NEXT_BLOCK
|
||||
|
||||
/// Start of reading bulk data
|
||||
#define SBC_STATE_READ 0x01
|
||||
/// Waiting for the bulk data reading complete
|
||||
#define SBC_STATE_WAIT_READ 0x02
|
||||
/// Read error state
|
||||
#define SBC_STATE_READ_ERROR 0x03
|
||||
/// Start next read block
|
||||
#define SBC_STATE_NEXT_READ 0x04
|
||||
/// Start writing bulk data to host
|
||||
#define SBC_STATE_WRITE 0x05
|
||||
/// Waiting for the bulk data sending complete
|
||||
#define SBC_STATE_WAIT_WRITE 0x06
|
||||
/// Write error state
|
||||
#define SBC_STATE_WRITE_ERROR 0x07
|
||||
/// Start next write block
|
||||
#define SBC_STATE_NEXT_WRITE 0x08
|
||||
/// Start next command block
|
||||
#define SBC_STATE_NEXT_BLOCK 0x09
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void SBC_UpdateSenseData(SBCRequestSenseData *requestSenseData,
|
||||
unsigned char senseKey,
|
||||
unsigned char additionalSenseCode,
|
||||
unsigned char additionalSenseCodeQualifier);
|
||||
|
||||
unsigned char SBC_GetCommandInformation(void *command,
|
||||
unsigned int *length,
|
||||
unsigned char *type,
|
||||
MSDLun *lun);
|
||||
|
||||
unsigned char SBC_ProcessCommand(MSDLun *lun,
|
||||
MSDCommandState *commandState);
|
||||
|
||||
#endif //#ifndef SBCMETHODS_H
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// SCSI commands implementation.
|
||||
///
|
||||
/// !Usage
|
||||
///
|
||||
/// -# After a CBW is received from host, use SBC_GetCommandInformation to check
|
||||
/// if the command is supported, and get the command length and type
|
||||
/// information before processing it.
|
||||
/// -# Then SBC_ProcessCommand can be used to handle a valid command, to
|
||||
/// perform the command operations.
|
||||
/// -# SBC_UpdateSenseData is used to update the sense data that will be sent
|
||||
/// to host.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef SBCMETHODS_H
|
||||
#define SBCMETHODS_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/device/massstorage/MSDDStateMachine.h"
|
||||
#include "../../../usb/device/massstorage/SBC.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "SBC Command States"
|
||||
/// This page lists the possible states of a SBC command.
|
||||
///
|
||||
/// !States
|
||||
/// - SBC_STATE_READ
|
||||
/// - SBC_STATE_WAIT_READ
|
||||
/// - SBC_STATE_WRITE
|
||||
/// - SBC_STATE_WAIT_WRITE
|
||||
/// - SBC_STATE_NEXT_BLOCK
|
||||
|
||||
/// Start of reading bulk data
|
||||
#define SBC_STATE_READ 0x01
|
||||
/// Waiting for the bulk data reading complete
|
||||
#define SBC_STATE_WAIT_READ 0x02
|
||||
/// Read error state
|
||||
#define SBC_STATE_READ_ERROR 0x03
|
||||
/// Start next read block
|
||||
#define SBC_STATE_NEXT_READ 0x04
|
||||
/// Start writing bulk data to host
|
||||
#define SBC_STATE_WRITE 0x05
|
||||
/// Waiting for the bulk data sending complete
|
||||
#define SBC_STATE_WAIT_WRITE 0x06
|
||||
/// Write error state
|
||||
#define SBC_STATE_WRITE_ERROR 0x07
|
||||
/// Start next write block
|
||||
#define SBC_STATE_NEXT_WRITE 0x08
|
||||
/// Start next command block
|
||||
#define SBC_STATE_NEXT_BLOCK 0x09
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void SBC_UpdateSenseData(SBCRequestSenseData *requestSenseData,
|
||||
unsigned char senseKey,
|
||||
unsigned char additionalSenseCode,
|
||||
unsigned char additionalSenseCodeQualifier);
|
||||
|
||||
unsigned char SBC_GetCommandInformation(void *command,
|
||||
unsigned int *length,
|
||||
unsigned char *type,
|
||||
MSDLun *lun);
|
||||
|
||||
unsigned char SBC_ProcessCommand(MSDLun *lun,
|
||||
MSDCommandState *commandState);
|
||||
|
||||
#endif //#ifndef SBCMETHODS_H
|
||||
|
||||
|
||||
Reference in New Issue
Block a user