SAMA5D3 demo: Add CDC driver code and use CDC to create a simple command console.

This commit is contained in:
Richard Barry 2014-07-23 21:07:03 +00:00
parent 3d007d0b4b
commit 146b46df87
50 changed files with 8851 additions and 509 deletions

View File

@ -7,8 +7,8 @@ define symbol __ICFEDIT_region_RAM_end__ = 0x31FFFF;
/*-Sizes-*/
define symbol __ICFEDIT_size_vectors__ = 0x100;
define symbol __ICFEDIT_size_cstack__ = 0x400;
define symbol __ICFEDIT_size_sysstack__ = 0x60;
define symbol __ICFEDIT_size_irqstack__ = 0x60;
define symbol __ICFEDIT_size_sysstack__ = 0x600;
define symbol __ICFEDIT_size_irqstack__ = 0x600;
define symbol __ICFEDIT_size_heap__ = 0x0;
/*-Exports-*/
export symbol __ICFEDIT_region_RAM_start__;

View File

@ -1,459 +0,0 @@
/* ----------------------------------------------------------------------------
* SAM Software Package License
* ----------------------------------------------------------------------------
* Copyright (c) 2012, 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.
* ----------------------------------------------------------------------------
*/
/** \file */
/**
* \addtogroup cp15_cache Cache Operations
*
* \section Usage
*
* They are performed as MCR instructions and only operate on a level 1 cache associated with
* ATM v7 processor.
* The supported operations are:
* <ul>
* <li> Any of these operations can be applied to
* -# any data cache
* -# any unified cache.
* <li> Invalidate by MVA
* Performs an invalidate of a data or unified cache line based on the address it contains.
* <li> Invalidate by set/way
* Performs an invalidate of a data or unified cache line based on its location in the cache hierarchy.
* <li> Clean by MVA
* Performs a clean of a data or unified cache line based on the address it contains.
* <li> Clean by set/way
* Performs a clean of a data or unified cache line based on its location in the cache hierarchy.
* <li> Clean and Invalidate by MVA
* Performs a clean and invalidate of a data or unified cache line based on the address it contains.
* <li> Clean and Invalidate by set/way
* Performs a clean and invalidate of a data or unified cache line based on its location in the cache hierarchy.
* </ul>
*
* Related files:\n
* \ref cp15.h\n
* \ref cp15_arm_gnu.S \n
*/
/*----------------------------------------------------------------------------
* Functions to access CP15 coprocessor register
*----------------------------------------------------------------------------*/
.global CP15_ReadID
.global CP15_ReadControl
.global CP15_WriteControl
.global CP15_WriteDomainAccessControl
.global CP15_WriteTTB
.global CP15_InvalidateIcacheInnerSharable
.global CP15_InvalidateBTBinnerSharable
.global CP15_InvalidateIcache
.global CP15_InvalidateIcacheByMva
.global CP15_FlushBTB
.global CP15_FlushBTBbyMva
.global CP15_InvalidateDcacheLineByMva
.global CP15_InvalidateDcacheLineBySetWay
.global CP15_CleanDCacheByMva
.global CP15_CleanDCacheBySetWay
.global CP15_CleanDCacheMva
.global CP15_CleanInvalidateDcacheLineByMva
.global CP15_CleanInvalidateDcacheLine
.global CP15_coherent_dcache_for_dma
.global CP15_invalidate_dcache_for_dma
.global CP15_clean_dcache_for_dma
.global CP15_flush_dcache_for_dma
.global CP15_flush_kern_dcache_for_dma
/**
* \brief Register c0 accesses the ID Register, Cache Type Register, and TCM Status Registers.
* Reading from this register returns the device ID, the cache type, or the TCM status
* depending on the value of Opcode_2 used.
*/
.section .CP15_ReadID
.global CP15_ReadID
CP15_ReadID:
mov r0, #0
mrc p15, 0, r0, c0, c0, 0
bx lr
/**
* \brief Register c1 is the Control Register for the ARM926EJ-S processor.
* This register specifies the configuration used to enable and disable the
* caches and MMU. It is recommended that you access this register using a
* read-modify-write sequence
*/
.section .CP15_ReadControl
.global CP15_ReadControl
CP15_ReadControl:
mov r0, #0
mrc p15, 0, r0, c1, c0, 0
bx lr
.section .CP15_WriteControl
.global CP15_WriteControl
CP15_WriteControl:
mcr p15, 0, r0, c1, c0, 0
nop
nop
nop
nop
nop
nop
nop
nop
bx lr
.section .CP15_WriteDomainAccessControl
.global CP15_WriteDomainAccessControl
CP15_WriteDomainAccessControl:
mcr p15, 0, r0, c3, c0, 0
nop
nop
nop
nop
nop
nop
nop
nop
bx lr
/**
* \brief ARMv7A architecture supports two translation tables
* Configure translation table base (TTB) control register cp15,c2
* to a value of all zeros, indicates we are using TTB register 0.
* write the address of our page table base to TTB register 0.
*/
.section .CP15_WriteTTB
.global CP15_WriteTTB
CP15_WriteTTB:
mcr p15, 0, r0, c2, c0, 0
nop
nop
nop
nop
nop
nop
nop
nop
bx lr
/**
* \brief Invalidate I cache predictor array inner Sharable
*/
.section .CP15_InvalidateIcacheInnerSharable
.global CP15_InvalidateIcacheInnerSharable
CP15_InvalidateIcacheInnerSharable:
mov r0, #0
mcr p15, 0, r0, c7, c1, 0
bx lr
/**
* \brief Invalidate entire branch predictor array inner Sharable
*/
.section .CP15_InvalidateBTBinnerSharable
.global CP15_InvalidateBTBinnerSharable
CP15_InvalidateBTBinnerSharable:
mov r0, #0
mcr p15, 0, r0, c7, c1, 6
bx lr
/**
* \brief Invalidate all instruction caches to PoU, also flushes branch target cache
*/
.section .CP15_InvalidateIcache
.global CP15_InvalidateIcache
CP15_InvalidateIcache:
mov r0, #0
mcr p15, 0, r0, c7, c5, 0
bx lr
/**
* \brief Invalidate instruction caches by VA to PoU
*/
.section .CP15_InvalidateIcacheByMva
.global CP15_InvalidateIcacheByMva
CP15_InvalidateIcacheByMva:
mov r0, #0
mcr p15, 0, r0, c7, c5, 1
bx lr
/**
* \brief Flush entire branch predictor array
*/
.section .CP15_FlushBTB
.global CP15_FlushBTB
CP15_FlushBTB:
mov r0, #0
mcr p15, 0, r0, c7, c5, 6
bx lr
/**
* \brief Flush branch predictor array entry by MVA
*/
.section .CP15_FlushBTBbyMva
.global CP15_FlushBTBbyMva
CP15_FlushBTBbyMva:
mov r0, #0
mcr p15, 0, r0, c7, c5, 7
bx lr
/**
* \brief Invalidate data cache line by VA to Poc
*/
.section .CP15_InvalidateDcacheLineByMva
.global CP15_InvalidateDcacheLineByMva
CP15_InvalidateDcacheLineByMva:
mov r0, #0
mcr p15, 0, r0, c7, c6, 1
bx lr
/**
* \brief Invalidate data cache line by set/way
*/
.section .CP15_InvalidateDcacheLineBySetWay
.global CP15_InvalidateDcacheLineBySetWay
CP15_InvalidateDcacheLineBySetWay:
mov r0, #0
mcr p15, 0, r0, c7, c6, 2
bx lr
/**
* \brief Clean data cache line by MVA
*/
.section .CP15_CleanDCacheByMva
.global CP15_CleanDCacheByMva
CP15_CleanDCacheByMva:
mov r0, #0
mcr p15, 0, r0, c7, c10, 1
bx lr
/**
* \brief Clean data cache line by Set/way
*/
.section .CP15_CleanDCacheBySetWay
.global CP15_CleanDCacheBySetWay
CP15_CleanDCacheBySetWay:
mov r0, #0
mcr p15, 0, r0, c7, c10, 2
bx lr
/**
* \brief Clean unified cache line by MVA
*/
.section .CP15_CleanDCacheMva
.global CP15_CleanDCacheMva
CP15_CleanDCacheMva:
mov r0, #0
mcr p15, 0, r0, c7, c11, 1
bx lr
/**
* \brief Clean and invalidate data cache line by VA to PoC
*/
.section .CP15_CleanInvalidateDcacheLineByMva
.global CP15_CleanInvalidateDcacheLineByMva
CP15_CleanInvalidateDcacheLineByMva:
mov r0, #0
mcr p15, 0, r0, c7, c14, 1
bx lr
/**
* \brief Clean and Incalidate data cache line by Set/Way
*/
.section .CP15_CleanInvalidateDcacheLine
.global CP15_CleanInvalidateDcacheLine
CP15_CleanInvalidateDcacheLine:
mov r0, #0
mcr p15, 0, r0, c7, c14, 2
bx lr
/**
* \brief Ensure that the I and D caches are coherent within specified
* region. This is typically used when code has been written to
* a memory region, and will be executed.
* \param start virtual start address of region
* \param end virtual end address of region
*/
.section .CP15_coherent_dcache_for_dma
.global CP15_coherent_dcache_for_dma
CP15_coherent_dcache_for_dma:
mrc p15, 0, r3, c0, c0, 1
lsr r3, r3, #16
and r3, r3, #0xf
mov r2, #4
mov r2, r2, lsl r3
sub r3, r2, #1
bic r12, r0, r3
1:
mcr p15, 0, r12, c7, c11, 1
add r12, r12, r2
cmp r12, r1
blo 1b
dsb
mrc p15, 0, r3, c0, c0, 1
and r3, r3, #0xf
mov r2, #4
mov r2, r2, lsl r3
sub r3, r2, #1
bic r12, r0, r3
2:
mcr p15, 0, r12, c7, c5, 1
add r12, r12, r2
cmp r12, r1
blo 2b
mov r0, #0
mcr p15, 0, r0, c7, c1, 6
mcr p15, 0, r0, c7, c5, 6
dsb
isb
bx lr
/**
* \brief Invalidate the data cache within the specified region; we will
* be performing a DMA operation in this region and we want to
* purge old data in the cache.
* \param start virtual start address of region
* \param end virtual end address of region
*/
.section .CP15_invalidate_dcache_for_dma
.global CP15_invalidate_dcache_for_dma
CP15_invalidate_dcache_for_dma:
mrc p15, 0, r3, c0, c0, 1
lsr r3, r3, #16
and r3, r3, #0xf
mov r2, #4
mov r2, r2, lsl r3
sub r3, r2, #1
tst r0, r3
bic r0, r0, r3
mcrne p15, 0, r0, c7, c14, 1
tst r1, r3
bic r1, r1, r3
mcrne p15, 0, r1, c7, c14, 1
3:
mcr p15, 0, r0, c7, c6, 1
add r0, r0, r2
cmp r0, r1
blo 3b
dsb
bx lr
/**
* \brief Clean the data cache within the specified region
* \param start virtual start address of region
* \param end virtual end address of region
*/
.section .CP15_clean_dcache_for_dma
.global CP15_clean_dcache_for_dma
CP15_clean_dcache_for_dma:
mrc p15, 0, r3, c0, c0, 1
lsr r3, r3, #16
and r3, r3, #0xf
mov r2, #4
mov r2, r2, lsl r3
sub r3, r2, #1
bic r0, r0, r3
4:
mcr p15, 0, r0, c7, c10, 1
add r0, r0, r2
cmp r0, r1
blo 4b
dsb
bx lr
/**
* \brief Flush the data cache within the specified region
* \param start virtual start address of region
* \param end virtual end address of region
*/
.section .CP15_flush_dcache_for_dma
.global CP15_flush_dcache_for_dma
CP15_flush_dcache_for_dma:
mrc p15, 0, r3, c0, c0, 1
lsr r3, r3, #16
and r3, r3, #0xf
mov r2, #4
mov r2, r2, lsl r3
sub r3, r2, #1
bic r0, r0, r3
5:
mcr p15, 0, r0, c7, c14, 1
add r0, r0, r2
cmp r0, r1
blo 5b
dsb
bx lr
/**
* \brief CP15_flush_kern_dcache_for_dma
* Ensure that the data held in the page kaddr is written back to the page in question.
* \param start virtual start address of region
* \param end virtual end address of region
*/
.section .CP15_flush_kern_dcache_for_dma
.global CP15_flush_kern_dcache_for_dma
CP15_flush_kern_dcache_for_dma:
mrc p15, 0, r3, c0, c0, 1
lsr r3, r3, #16
and r3, r3, #0xf
mov r2, #4
mov r2, r2, lsl r3
add r1, r0, r1
sub r3, r2, #1
bic r0, r0, r3
mcr p15, 0, r0, c7, c14, 1
add r0, r0, r2
cmp r0, r1
blo 1b
dsb
bx lr

View File

@ -1,5 +1,5 @@
/* ----------------------------------------------------------------------------
* SAM Software Package License
* SAM Software Package License
* ----------------------------------------------------------------------------
* Copyright (c) 2012, Atmel Corporation
*
@ -26,18 +26,18 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
/** \file */
/** \file */
/**
/**
* \addtogroup cp15_cache Cache Operations
*
* \section Usage
*
* They are performed as MCR instructions and only operate on a level 1 cache associated with
* They are performed as MCR instructions and only operate on a level 1 cache associated with
* ATM v7 processor.
* The supported operations are:
* <ul>
@ -62,7 +62,7 @@
* \ref cp15.h\n
* \ref cp15_arm_iar.s \n
*/
MODULE ?cp15
@ -73,7 +73,6 @@
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
#define __ASSEMBLY__
/*----------------------------------------------------------------------------
@ -103,10 +102,10 @@
PUBLIC CP15_flush_dcache_for_dma
PUBLIC CP15_flush_kern_dcache_for_dma
/**
/**
* \brief Register c0 accesses the ID Register, Cache Type Register, and TCM Status Registers.
* Reading from this register returns the device ID, the cache type, or the TCM status
* depending on the value of Opcode_2 used.
* depending on the value of Opcode_2 used.
*/
SECTION .CP15_ReadID:DATA:NOROOT(2)
PUBLIC CP15_ReadID
@ -115,7 +114,7 @@ CP15_ReadID:
mrc p15, 0, r0, c0, c0, 0
bx lr
/**
/**
* \brief Register c1 is the Control Register for the ARM926EJ-S processor.
* This register specifies the configuration used to enable and disable the
* caches and MMU. It is recommended that you access this register using a
@ -125,7 +124,7 @@ CP15_ReadID:
PUBLIC CP15_ReadControl
CP15_ReadControl:
mov r0, #0
mrc p15, 0, r0, c1, c0, 0
mrc p15, 0, r0, c1, c0, 0
bx lr
SECTION .CP15_WriteControl:CODE:NOROOT(2)
@ -155,8 +154,8 @@ CP15_WriteDomainAccessControl:
nop
nop
bx lr
/**
/**
* \brief ARMv7A architecture supports two translation tables
* Configure translation table base (TTB) control register cp15,c2
* to a value of all zeros, indicates we are using TTB register 0.
@ -277,7 +276,7 @@ CP15_CleanDCacheBySetWay:
bx lr
/**
* \brief Clean unified cache line by MVA
* \brief Clean unified cache line by MVA
*/
SECTION .CP15_CleanDCacheMva:CODE:NOROOT(2)
PUBLIC CP15_CleanDCacheMva
@ -293,7 +292,7 @@ CP15_CleanDCacheMva:
PUBLIC CP15_CleanInvalidateDcacheLineByMva
CP15_CleanInvalidateDcacheLineByMva:
mov r0, #0
mcr p15, 0, r0, c7, c14, 1
mcr p15, 0, r0, c7, c14, 1
bx lr
/**
@ -317,7 +316,7 @@ CP15_CleanInvalidateDcacheLine:
PUBLIC CP15_coherent_dcache_for_dma
CP15_coherent_dcache_for_dma:
// dcache_line_size r2, r3
mrc p15, 0, r3, c0, c0, 1 // read ctr
lsr r3, r3, #16
and r3, r3, #0xf // cache line size encoding

View File

@ -0,0 +1,558 @@
/* ----------------------------------------------------------------------------
* SAM Software Package License
* ----------------------------------------------------------------------------
* Copyright (c) 2011, 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.
* ----------------------------------------------------------------------------
*/
/** \file
* \addtogroup usbd_cdc
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include "board.h"
#include "include/USBD_Config.h"
#include "CDCDSerialDriver.h"
/*------------------------------------------------------------------------------
* Definitions
*------------------------------------------------------------------------------*/
/** \addtogroup usbd_cdc_serial_device_ids CDC Serial Device IDs
* @{
* This page lists the IDs used in the CDC Serial Device Descriptor.
*
* \section IDs
* - CDCDSerialDriverDescriptors_PRODUCTID
* - CDCDSerialDriverDescriptors_VENDORID
* - CDCDSerialDriverDescriptors_RELEASE
*/
/** Device product ID. */
#define CDCDSerialDriverDescriptors_PRODUCTID 0x6119
/** Device vendor ID (Atmel). */
#define CDCDSerialDriverDescriptors_VENDORID 0x03EB
/** Device release number. */
#define CDCDSerialDriverDescriptors_RELEASE 0x0100
/** @}*/
/*------------------------------------------------------------------------------
* Macros
*------------------------------------------------------------------------------*/
/** Returns the minimum between two values. */
#define MIN(a, b) ((a < b) ? a : b)
/*------------------------------------------------------------------------------
* Exported variables
*------------------------------------------------------------------------------*/
/** Standard USB device descriptor for the CDC serial driver */
const USBDeviceDescriptor deviceDescriptor = {
sizeof(USBDeviceDescriptor),
USBGenericDescriptor_DEVICE,
USBDeviceDescriptor_USB2_00,
CDCDeviceDescriptor_CLASS,
CDCDeviceDescriptor_SUBCLASS,
CDCDeviceDescriptor_PROTOCOL,
CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0),
CDCDSerialDriverDescriptors_VENDORID,
CDCDSerialDriverDescriptors_PRODUCTID,
CDCDSerialDriverDescriptors_RELEASE,
0, /* No string descriptor for manufacturer */
1, /* Index of product string descriptor is #1 */
0, /* No string descriptor for serial number */
1 /* Device has 1 possible configuration */
};
/** Standard USB configuration descriptor for the CDC serial driver */
const CDCDSerialDriverConfigurationDescriptors configurationDescriptorsFS = {
/* Standard configuration descriptor */
{
sizeof(USBConfigurationDescriptor),
USBGenericDescriptor_CONFIGURATION,
sizeof(CDCDSerialDriverConfigurationDescriptors),
2, /* There are two interfaces in this configuration */
1, /* This is configuration #1 */
0, /* No string descriptor for this configuration */
USBD_BMATTRIBUTES,
USBConfigurationDescriptor_POWER(100)
},
/* Communication class interface standard descriptor */
{
sizeof(USBInterfaceDescriptor),
USBGenericDescriptor_INTERFACE,
0, /* This is interface #0 */
0, /* This is alternate setting #0 for this interface */
1, /* This interface uses 1 endpoint */
CDCCommunicationInterfaceDescriptor_CLASS,
CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
0 /* No string descriptor for this interface */
},
/* Class-specific header functional descriptor */
{
sizeof(CDCHeaderDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_HEADER,
CDCGenericDescriptor_CDC1_10
},
/* Class-specific call management functional descriptor */
{
sizeof(CDCCallManagementDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_CALLMANAGEMENT,
CDCCallManagementDescriptor_SELFCALLMANAGEMENT,
0 /* No associated data interface */
},
/* Class-specific abstract control management functional descriptor */
{
sizeof(CDCAbstractControlManagementDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT,
CDCAbstractControlManagementDescriptor_LINE
},
/* Class-specific union functional descriptor with one slave interface */
{
sizeof(CDCUnionDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_UNION,
0, /* Number of master interface is #0 */
1 /* First slave interface is #1 */
},
/* Notification endpoint standard descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
CDCDSerialDriverDescriptors_NOTIFICATION),
USBEndpointDescriptor_INTERRUPT,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_NOTIFICATION),
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
10 /* Endpoint is polled every 10ms */
},
/* Data class interface standard descriptor */
{
sizeof(USBInterfaceDescriptor),
USBGenericDescriptor_INTERFACE,
1, /* This is interface #1 */
0, /* This is alternate setting #0 for this interface */
2, /* This interface uses 2 endpoints */
CDCDataInterfaceDescriptor_CLASS,
CDCDataInterfaceDescriptor_SUBCLASS,
CDCDataInterfaceDescriptor_NOPROTOCOL,
0 /* No string descriptor for this interface */
},
/* Bulk-OUT endpoint standard descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
CDCDSerialDriverDescriptors_DATAOUT),
USBEndpointDescriptor_BULK,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_DATAOUT),
USBEndpointDescriptor_MAXBULKSIZE_FS),
0 /* Must be 0 for full-speed bulk endpoints */
},
/* Bulk-IN endpoint descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
CDCDSerialDriverDescriptors_DATAIN),
USBEndpointDescriptor_BULK,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_DATAIN),
USBEndpointDescriptor_MAXBULKSIZE_FS),
0 /* Must be 0 for full-speed bulk endpoints */
}
};
/** Other-speed configuration descriptor (when in full-speed). */
const CDCDSerialDriverConfigurationDescriptors otherSpeedDescriptorsFS = {
/* Standard configuration descriptor */
{
sizeof(USBConfigurationDescriptor),
USBGenericDescriptor_OTHERSPEEDCONFIGURATION,
sizeof(CDCDSerialDriverConfigurationDescriptors),
2, /* There are two interfaces in this configuration */
1, /* This is configuration #1 */
0, /* No string descriptor for this configuration */
BOARD_USB_BMATTRIBUTES,
USBConfigurationDescriptor_POWER(100)
},
/* Communication class interface standard descriptor */
{
sizeof(USBInterfaceDescriptor),
USBGenericDescriptor_INTERFACE,
0, /* This is interface #0 */
0, /* This is alternate setting #0 for this interface */
1, /* This interface uses 1 endpoint */
CDCCommunicationInterfaceDescriptor_CLASS,
CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
0 /* No string descriptor for this interface */
},
/* Class-specific header functional descriptor */
{
sizeof(CDCHeaderDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_HEADER,
CDCGenericDescriptor_CDC1_10
},
/* Class-specific call management functional descriptor */
{
sizeof(CDCCallManagementDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_CALLMANAGEMENT,
CDCCallManagementDescriptor_SELFCALLMANAGEMENT,
0 /* No associated data interface */
},
/* Class-specific abstract control management functional descriptor */
{
sizeof(CDCAbstractControlManagementDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT,
CDCAbstractControlManagementDescriptor_LINE
},
/* Class-specific union functional descriptor with one slave interface */
{
sizeof(CDCUnionDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_UNION,
0, /* Number of master interface is #0 */
1 /* First slave interface is #1 */
},
/* Notification endpoint standard descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
CDCDSerialDriverDescriptors_NOTIFICATION),
USBEndpointDescriptor_INTERRUPT,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_NOTIFICATION),
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
8 /* Endpoint is polled every 16ms */
},
/* Data class interface standard descriptor */
{
sizeof(USBInterfaceDescriptor),
USBGenericDescriptor_INTERFACE,
1, /* This is interface #1 */
0, /* This is alternate setting #0 for this interface */
2, /* This interface uses 2 endpoints */
CDCDataInterfaceDescriptor_CLASS,
CDCDataInterfaceDescriptor_SUBCLASS,
CDCDataInterfaceDescriptor_NOPROTOCOL,
0 /* No string descriptor for this interface */
},
/* Bulk-OUT endpoint standard descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
CDCDSerialDriverDescriptors_DATAOUT),
USBEndpointDescriptor_BULK,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_DATAOUT),
USBEndpointDescriptor_MAXBULKSIZE_HS),
0 /* Must be 0 for full-speed bulk endpoints */
},
/* Bulk-IN endpoint descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
CDCDSerialDriverDescriptors_DATAIN),
USBEndpointDescriptor_BULK,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_DATAIN),
USBEndpointDescriptor_MAXBULKSIZE_HS),
0 /* Must be 0 for full-speed bulk endpoints */
}
};
/** Configuration descriptor (when in high-speed). */
const CDCDSerialDriverConfigurationDescriptors configurationDescriptorsHS = {
/* Standard configuration descriptor */
{
sizeof(USBConfigurationDescriptor),
USBGenericDescriptor_CONFIGURATION,
sizeof(CDCDSerialDriverConfigurationDescriptors),
2, /* There are two interfaces in this configuration */
1, /* This is configuration #1 */
0, /* No string descriptor for this configuration */
BOARD_USB_BMATTRIBUTES,
USBConfigurationDescriptor_POWER(100)
},
/* Communication class interface standard descriptor */
{
sizeof(USBInterfaceDescriptor),
USBGenericDescriptor_INTERFACE,
0, /* This is interface #0 */
0, /* This is alternate setting #0 for this interface */
1, /* This interface uses 1 endpoint */
CDCCommunicationInterfaceDescriptor_CLASS,
CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
0 /* No string descriptor for this interface */
},
/* Class-specific header functional descriptor */
{
sizeof(CDCHeaderDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_HEADER,
CDCGenericDescriptor_CDC1_10
},
/* Class-specific call management functional descriptor */
{
sizeof(CDCCallManagementDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_CALLMANAGEMENT,
CDCCallManagementDescriptor_SELFCALLMANAGEMENT,
0 /* No associated data interface */
},
/* Class-specific abstract control management functional descriptor */
{
sizeof(CDCAbstractControlManagementDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT,
CDCAbstractControlManagementDescriptor_LINE
},
/* Class-specific union functional descriptor with one slave interface */
{
sizeof(CDCUnionDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_UNION,
0, /* Number of master interface is #0 */
1 /* First slave interface is #1 */
},
/* Notification endpoint standard descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
CDCDSerialDriverDescriptors_NOTIFICATION),
USBEndpointDescriptor_INTERRUPT,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_NOTIFICATION),
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
8 /* Endpoint is polled every 16ms */
},
/* Data class interface standard descriptor */
{
sizeof(USBInterfaceDescriptor),
USBGenericDescriptor_INTERFACE,
1, /* This is interface #1 */
0, /* This is alternate setting #0 for this interface */
2, /* This interface uses 2 endpoints */
CDCDataInterfaceDescriptor_CLASS,
CDCDataInterfaceDescriptor_SUBCLASS,
CDCDataInterfaceDescriptor_NOPROTOCOL,
0 /* No string descriptor for this interface */
},
/* Bulk-OUT endpoint standard descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
CDCDSerialDriverDescriptors_DATAOUT),
USBEndpointDescriptor_BULK,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_DATAOUT),
USBEndpointDescriptor_MAXBULKSIZE_HS),
0 /* Must be 0 for full-speed bulk endpoints */
},
/* Bulk-IN endpoint descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
CDCDSerialDriverDescriptors_DATAIN),
USBEndpointDescriptor_BULK,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_DATAIN),
USBEndpointDescriptor_MAXBULKSIZE_HS),
0 /* Must be 0 for full-speed bulk endpoints */
}
};
/** Other-speed configuration descriptor (when in high-speed). */
const CDCDSerialDriverConfigurationDescriptors otherSpeedDescriptorsHS = {
/* Standard configuration descriptor */
{
sizeof(USBConfigurationDescriptor),
USBGenericDescriptor_OTHERSPEEDCONFIGURATION,
sizeof(CDCDSerialDriverConfigurationDescriptors),
2, /* There are two interfaces in this configuration */
1, /* This is configuration #1 */
0, /* No string descriptor for this configuration */
BOARD_USB_BMATTRIBUTES,
USBConfigurationDescriptor_POWER(100)
},
/* Communication class interface standard descriptor */
{
sizeof(USBInterfaceDescriptor),
USBGenericDescriptor_INTERFACE,
0, /* This is interface #0 */
0, /* This is alternate setting #0 for this interface */
1, /* This interface uses 1 endpoint */
CDCCommunicationInterfaceDescriptor_CLASS,
CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
0 /* No string descriptor for this interface */
},
/* Class-specific header functional descriptor */
{
sizeof(CDCHeaderDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_HEADER,
CDCGenericDescriptor_CDC1_10
},
/* Class-specific call management functional descriptor */
{
sizeof(CDCCallManagementDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_CALLMANAGEMENT,
CDCCallManagementDescriptor_SELFCALLMANAGEMENT,
0 /* No associated data interface */
},
/* Class-specific abstract control management functional descriptor */
{
sizeof(CDCAbstractControlManagementDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT,
CDCAbstractControlManagementDescriptor_LINE
},
/* Class-specific union functional descriptor with one slave interface */
{
sizeof(CDCUnionDescriptor),
CDCGenericDescriptor_INTERFACE,
CDCGenericDescriptor_UNION,
0, /* Number of master interface is #0 */
1 /* First slave interface is #1 */
},
/* Notification endpoint standard descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
CDCDSerialDriverDescriptors_NOTIFICATION),
USBEndpointDescriptor_INTERRUPT,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_NOTIFICATION),
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
10 /* Endpoint is polled every 10ms */
},
/* Data class interface standard descriptor */
{
sizeof(USBInterfaceDescriptor),
USBGenericDescriptor_INTERFACE,
1, /* This is interface #1 */
0, /* This is alternate setting #0 for this interface */
2, /* This interface uses 2 endpoints */
CDCDataInterfaceDescriptor_CLASS,
CDCDataInterfaceDescriptor_SUBCLASS,
CDCDataInterfaceDescriptor_NOPROTOCOL,
0 /* No string descriptor for this interface */
},
/* Bulk-OUT endpoint standard descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
CDCDSerialDriverDescriptors_DATAOUT),
USBEndpointDescriptor_BULK,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_DATAOUT),
USBEndpointDescriptor_MAXBULKSIZE_FS),
0 /* Must be 0 for full-speed bulk endpoints */
},
/* Bulk-IN endpoint descriptor */
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
CDCDSerialDriverDescriptors_DATAIN),
USBEndpointDescriptor_BULK,
MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCDSerialDriverDescriptors_DATAIN),
USBEndpointDescriptor_MAXBULKSIZE_FS),
0 /* Must be 0 for full-speed bulk endpoints */
}
};
/** Language ID string descriptor */
const unsigned char languageIdStringDescriptor[] = {
USBStringDescriptor_LENGTH(1),
USBGenericDescriptor_STRING,
USBStringDescriptor_ENGLISH_US
};
/** Product string descriptor */
const unsigned char productStringDescriptor[] = {
USBStringDescriptor_LENGTH(13),
USBGenericDescriptor_STRING,
USBStringDescriptor_UNICODE('A'),
USBStringDescriptor_UNICODE('T'),
USBStringDescriptor_UNICODE('9'),
USBStringDescriptor_UNICODE('1'),
USBStringDescriptor_UNICODE('U'),
USBStringDescriptor_UNICODE('S'),
USBStringDescriptor_UNICODE('B'),
USBStringDescriptor_UNICODE('S'),
USBStringDescriptor_UNICODE('e'),
USBStringDescriptor_UNICODE('r'),
USBStringDescriptor_UNICODE('i'),
USBStringDescriptor_UNICODE('a'),
USBStringDescriptor_UNICODE('l')
};
/** List of string descriptors used by the device */
const unsigned char *stringDescriptors[] = {
languageIdStringDescriptor,
productStringDescriptor,
};
/** List of standard descriptors for the serial driver. */
WEAK const USBDDriverDescriptors cdcdSerialDriverDescriptors = {
&deviceDescriptor,
(USBConfigurationDescriptor *) &(configurationDescriptorsFS),
0, /* No full-speed device qualifier descriptor */
(USBConfigurationDescriptor *) &(otherSpeedDescriptorsFS),
0, /* No high-speed device descriptor (uses FS one) */
(USBConfigurationDescriptor *) &(configurationDescriptorsHS),
0, /* No high-speed device qualifier descriptor */
(USBConfigurationDescriptor *) &(otherSpeedDescriptorsHS),
stringDescriptors,
2 /* 2 string descriptors in list */
};
/**@}*/

View File

@ -0,0 +1,71 @@
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------
*/
/** \file
Implementation of the CDCLineCoding class.
*/
/** \addtogroup usb_cdc
*@{
*/
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
#include <CDCRequests.h>
/*----------------------------------------------------------------------------
* Exported functions
*----------------------------------------------------------------------------*/
/**
* Initializes the bitrate, number of stop bits, parity checking and
* number of data bits of a CDCLineCoding object.
* \param lineCoding Pointer to a CDCLineCoding instance.
* \param bitrate Bitrate of the virtual COM connection.
* \param stopbits Number of stop bits
* (\ref usb_cdc_stop CDC LineCoding StopBits).
* \param parity Parity check type
* (\ref usb_cdc_parity CDC LineCoding ParityChecking).
* \param databits Number of data bits.
*/
void CDCLineCoding_Initialize(CDCLineCoding *lineCoding,
uint32_t bitrate,
uint8_t stopbits,
uint8_t parity,
uint8_t databits)
{
lineCoding->dwDTERate = bitrate;
lineCoding->bCharFormat = stopbits;
lineCoding->bParityType = parity;
lineCoding->bDataBits = databits;
}
/**@}*/

View File

@ -0,0 +1,87 @@
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------
*/
/** \file
*
* Implementation of the CDCSetControlLineStateRequest class.
*/
/** \addtogroup usb_cdc
*@{
*/
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
#include <CDCRequests.h>
/*----------------------------------------------------------------------------
* Exported functions
*----------------------------------------------------------------------------*/
/**
* Notifies if the given request indicates that the DTE signal is present.
* \param request Pointer to a USBGenericRequest instance.
* \return 1 if the DTE signal is present, otherwise 0.
*/
uint8_t CDCSetControlLineStateRequest_IsDtePresent(
const USBGenericRequest *request)
{
if ((USBGenericRequest_GetValue(request) & 0x0001) != 0) {
return 1;
}
else {
return 0;
}
}
/**
* Notifies if the given request indicates that the device carrier should
* be activated.
* \param request Pointer to a USBGenericRequest instance.
* \return 1 is the device should activate its carrier, 0 otherwise.
*/
uint8_t CDCSetControlLineStateRequest_ActivateCarrier(
const USBGenericRequest *request)
{
if ((USBGenericRequest_GetValue(request) & 0x0002) != 0) {
return 1;
}
else {
return 0;
}
}
/**@}*/

View File

@ -0,0 +1,325 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, 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.
* ----------------------------------------------------------------------------
*/
/** \file
*
* Implements for USB descriptor methods described by the USB specification.
*/
/** \addtogroup usb_descriptor
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include "USBDescriptors.h"
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
/**
* Returns the length of a descriptor.
* \param descriptor Pointer to a USBGenericDescriptor instance.
* \return Length of descriptor in bytes.
*/
uint32_t USBGenericDescriptor_GetLength(
const USBGenericDescriptor *descriptor)
{
return descriptor->bLength;
}
/**
* Returns the type of a descriptor.
* \param descriptor Pointer to a USBGenericDescriptor instance.
* \return Type of descriptor.
*/
uint8_t USBGenericDescriptor_GetType(
const USBGenericDescriptor *descriptor)
{
return descriptor->bDescriptorType;
}
/**
* Returns a pointer to the descriptor right after the given one, when
* parsing a Configuration descriptor.
* \param descriptor - Pointer to a USBGenericDescriptor instance.
* \return Pointer to the next descriptor.
*/
USBGenericDescriptor *USBGenericDescriptor_GetNextDescriptor(
const USBGenericDescriptor *descriptor)
{
return (USBGenericDescriptor *)
(((char *) descriptor) + USBGenericDescriptor_GetLength(descriptor));
}
/** Parses the given descriptor list via costomized function.
* \param descriptor Pointer to the start of the whole descriptors list.
* \param totalLength Total size of descriptors in bytes.
* \param parseFunction Function to parse each descriptor scanned.
* Return 0 to continue parsing.
* \param parseArg Argument passed to parse function.
* \return Pointer to USBGenericDescriptor instance for next descriptor.
*/
USBGenericDescriptor *USBGenericDescriptor_Parse(
const USBGenericDescriptor *descriptor,
uint32_t totalLength,
USBDescriptorParseFunction parseFunction,
void *parseArg)
{
int32_t size = totalLength;
if (size == 0)
return 0;
/* Start parsing descriptors */
while (1) {
uint32_t parseRC = 0;
/* Parse current descriptor */
if (parseFunction) {
parseRC = parseFunction((void*)descriptor, parseArg);
}
/* Get next descriptor */
size -= USBGenericDescriptor_GetLength(descriptor);
descriptor = USBGenericDescriptor_GetNextDescriptor(descriptor);
if (size) {
if (parseRC != 0) {
return (USBGenericDescriptor *)descriptor;
}
}
else
break;
}
/* No descriptors remaining */
return 0;
}
/**
* Returns the number of an endpoint given its descriptor.
* \param endpoint Pointer to a USBEndpointDescriptor instance.
* \return Endpoint number.
*/
uint8_t USBEndpointDescriptor_GetNumber(
const USBEndpointDescriptor *endpoint)
{
return endpoint->bEndpointAddress & 0xF;
}
/**
* Returns the direction of an endpoint given its descriptor.
* \param endpoint Pointer to a USBEndpointDescriptor instance.
* \return Endpoint direction (see \ref usb_ep_dir).
*/
uint8_t USBEndpointDescriptor_GetDirection(
const USBEndpointDescriptor *endpoint)
{
if ((endpoint->bEndpointAddress & 0x80) != 0) {
return USBEndpointDescriptor_IN;
}
else {
return USBEndpointDescriptor_OUT;
}
}
/**
* Returns the type of an endpoint given its descriptor.
* \param endpoint Pointer to a USBEndpointDescriptor instance.
* \return Endpoint type (see \ref usb_ep_type).
*/
uint8_t USBEndpointDescriptor_GetType(
const USBEndpointDescriptor *endpoint)
{
return endpoint->bmAttributes & 0x3;
}
/**
* Returns the maximum size of a packet (in bytes) on an endpoint given
* its descriptor.
* \param endpoint - Pointer to a USBEndpointDescriptor instance.
* \return Maximum packet size of endpoint.
*/
uint16_t USBEndpointDescriptor_GetMaxPacketSize(
const USBEndpointDescriptor *endpoint)
{
uint16_t usTemp;
uint8_t *pc1, *pc2;
pc1 = ( uint8_t * ) &( endpoint->wMaxPacketSize );
pc2 = pc1 + 1;
usTemp = ( ( *pc2 ) << 8 ) | *pc1;
return usTemp;
#warning The original code below crashes when build for A5 as endpoint can be misaligned.
//_RB_return endpoint->wMaxPacketSize;
}
/**
* Returns the polling interval on an endpoint given its descriptor.
* \param endpoint - Pointer to a USBEndpointDescriptor instance.
* \return Polling interval of endpoint.
*/
uint8_t USBEndpointDescriptor_GetInterval(
const USBEndpointDescriptor *endpoint)
{
return endpoint->bInterval;
}
/** Returns the total length of a configuration, i.e. including the
* descriptors following it.
* \param configuration Pointer to a USBConfigurationDescriptor instance.
* \return Total length (in bytes) of the configuration.
*/
volatile unsigned long ulCount = 0;
uint32_t USBConfigurationDescriptor_GetTotalLength(
const USBConfigurationDescriptor *configuration)
{
ulCount++;
if( ulCount == 5 )
{
__asm volatile( "NOP" );
}
return configuration->wTotalLength;
}
/** Returns the number of interfaces in a configuration.
* \param configuration Pointer to a USBConfigurationDescriptor instance.
* \return Number of interfaces in configuration.
*/
unsigned char USBConfigurationDescriptor_GetNumInterfaces(
const USBConfigurationDescriptor *configuration)
{
return configuration->bNumInterfaces;
}
/** Indicates if the device is self-powered when in a given configuration.
* \param configuration Pointer to a USBConfigurationDescriptor instance.
* \return 1 if the device is self-powered when in the given configuration;
* otherwise 0.
*/
unsigned char USBConfigurationDescriptor_IsSelfPowered(
const USBConfigurationDescriptor *configuration)
{
if ((configuration->bmAttributes & (1 << 6)) != 0) {
return 1;
}
else {
return 0;
}
}
/** Parses the given Configuration descriptor (followed by relevant
* interface, endpoint and class-specific descriptors) into three arrays.
* *Each array must have its size equal or greater to the number of
* descriptors it stores plus one*. A null-value is inserted after the last
* descriptor of each type to indicate the array end.
*
* Note that if the pointer to an array is null (0), nothing is stored in
* it.
* \param configuration Pointer to the start of the whole Configuration
* descriptor.
* \param interfaces Pointer to the Interface descriptor array.
* \param endpoints Pointer to the Endpoint descriptor array.
* \param others Pointer to the class-specific descriptor array.
*/
void USBConfigurationDescriptor_Parse(
const USBConfigurationDescriptor *configuration,
USBInterfaceDescriptor **interfaces,
USBEndpointDescriptor **endpoints,
USBGenericDescriptor **others)
{
/* Get size of configuration to parse */
int size = USBConfigurationDescriptor_GetTotalLength(configuration);
size -= sizeof(USBConfigurationDescriptor);
/* Start parsing descriptors */
USBGenericDescriptor *descriptor = (USBGenericDescriptor *) configuration;
while (size > 0) {
/* Get next descriptor */
descriptor = USBGenericDescriptor_GetNextDescriptor(descriptor);
size -= USBGenericDescriptor_GetLength(descriptor);
/* Store descriptor in correponding array */
if (USBGenericDescriptor_GetType(descriptor)
== USBGenericDescriptor_INTERFACE) {
if (interfaces) {
*interfaces = (USBInterfaceDescriptor *) descriptor;
interfaces++;
}
}
else if (USBGenericDescriptor_GetType(descriptor)
== USBGenericDescriptor_ENDPOINT) {
if (endpoints) {
*endpoints = (USBEndpointDescriptor *) descriptor;
endpoints++;
}
}
else if (others) {
*others = descriptor;
others++;
}
}
/* Null-terminate arrays */
if (interfaces) {
*interfaces = 0;
}
if (endpoints) {
*endpoints = 0;
}
if (others) {
*others = 0;
}
}
/**@}*/

View File

@ -0,0 +1,244 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, 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.
* ----------------------------------------------------------------------------
*/
/** \file
* \section Purpose
*
* Implements for USB requests described by the USB specification.
*/
/** \addtogroup usb_request
* @{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include <USBRequests.h>
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
/**
* Returns the type of the given request.
* \param request Pointer to a USBGenericRequest instance.
* \return "USB Request Types"
*/
extern uint8_t USBGenericRequest_GetType(const USBGenericRequest *request)
{
return ((request->bmRequestType >> 5) & 0x3);
}
/**
* Returns the request code of the given request.
* \param request Pointer to a USBGenericRequest instance.
* \return Request code.
* \sa "USB Request Codes"
*/
uint8_t USBGenericRequest_GetRequest(const USBGenericRequest *request)
{
return request->bRequest;
}
/**
* Returns the wValue field of the given request.
* \param request - Pointer to a USBGenericRequest instance.
* \return Request value.
*/
uint16_t USBGenericRequest_GetValue(const USBGenericRequest *request)
{
return request->wValue;
}
/**
* Returns the wIndex field of the given request.
* \param request Pointer to a USBGenericRequest instance.
* \return Request index;
*/
uint16_t USBGenericRequest_GetIndex(const USBGenericRequest *request)
{
return request->wIndex;
}
/**
* Returns the expected length of the data phase following a request.
* \param request Pointer to a USBGenericRequest instance.
* \return Length of data phase.
*/
uint16_t USBGenericRequest_GetLength(const USBGenericRequest *request)
{
return request->wLength;
}
/**
* Returns the endpoint number targetted by a given request.
* \param request Pointer to a USBGenericRequest instance.
* \return Endpoint number.
*/
uint8_t USBGenericRequest_GetEndpointNumber(
const USBGenericRequest *request)
{
return USBGenericRequest_GetIndex(request) & 0xF;
}
/**
* Returns the intended recipient of a given request.
* \param request Pointer to a USBGenericRequest instance.
* \return Request recipient.
* \sa "USB Request Recipients"
*/
uint8_t USBGenericRequest_GetRecipient(const USBGenericRequest *request)
{
/* Recipient is in bits [0..4] of the bmRequestType field */
return request->bmRequestType & 0xF;
}
/**
* Returns the direction of the data transfer following the given request.
* \param request Pointer to a USBGenericRequest instance.
* \return Transfer direction.
* \sa "USB Request Directions"
*/
uint8_t USBGenericRequest_GetDirection(const USBGenericRequest *request)
{
/* Transfer direction is located in bit D7 of the bmRequestType field */
if ((request->bmRequestType & 0x80) != 0) {
return USBGenericRequest_IN;
}
else {
return USBGenericRequest_OUT;
}
}
/**
* Returns the type of the descriptor requested by the host given the
* corresponding GET_DESCRIPTOR request.
* \param request Pointer to a USBGenericDescriptor instance.
* \return Type of the requested descriptor.
*/
uint8_t USBGetDescriptorRequest_GetDescriptorType(
const USBGenericRequest *request)
{
/* Requested descriptor type is in the high-byte of the wValue field */
return (USBGenericRequest_GetValue(request) >> 8) & 0xFF;
}
/**
* Returns the index of the requested descriptor, given the corresponding
* GET_DESCRIPTOR request.
* \param request Pointer to a USBGenericDescriptor instance.
* \return Index of the requested descriptor.
*/
uint8_t USBGetDescriptorRequest_GetDescriptorIndex(
const USBGenericRequest *request)
{
/* Requested descriptor index if in the low byte of the wValue field */
return USBGenericRequest_GetValue(request) & 0xFF;
}
/**
* Returns the address that the device must take in response to a
* SET_ADDRESS request.
* \param request Pointer to a USBGenericRequest instance.
* \return New device address.
*/
uint8_t USBSetAddressRequest_GetAddress(const USBGenericRequest *request)
{
return USBGenericRequest_GetValue(request) & 0x7F;
}
/**
* Returns the number of the configuration that should be set in response
* to the given SET_CONFIGURATION request.
* \param request Pointer to a USBGenericRequest instance.
* \return Number of the requested configuration.
*/
uint8_t USBSetConfigurationRequest_GetConfiguration(
const USBGenericRequest *request)
{
return USBGenericRequest_GetValue(request);
}
/**
* Indicates which interface is targetted by a GET_INTERFACE or
* SET_INTERFACE request.
* \param request Pointer to a USBGenericRequest instance.
* \return Interface number.
*/
uint8_t USBInterfaceRequest_GetInterface(const USBGenericRequest *request)
{
return (USBGenericRequest_GetIndex(request) & 0xFF);
}
/**
* Indicates the new alternate setting that the interface targetted by a
* SET_INTERFACE request should use.
* \param request Pointer to a USBGenericRequest instance.
* \return New active setting for the interface.
*/
uint8_t USBInterfaceRequest_GetAlternateSetting(
const USBGenericRequest *request)
{
return (USBGenericRequest_GetValue(request) & 0xFF);
}
/**
* Returns the feature selector of a given CLEAR_FEATURE or SET_FEATURE
* request.
* \param request Pointer to a USBGenericRequest instance.
* \return Feature selector.
*/
uint8_t USBFeatureRequest_GetFeatureSelector(
const USBGenericRequest *request)
{
return USBGenericRequest_GetValue(request);
}
/**
* Indicates the test that the device must undertake following a
* SET_FEATURE request.
* \param request Pointer to a USBGenericRequest instance.
* \return Test selector.
*/
uint8_t USBFeatureRequest_GetTestSelector(
const USBGenericRequest *request)
{
return (USBGenericRequest_GetIndex(request) >> 8) & 0xFF;
}
/**@}*/

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

View File

@ -0,0 +1,228 @@
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------
*/
/**\file
* Implementation of a single CDC serial port function for USB device.
*/
/** \addtogroup usbd_cdc
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include "CDCDSerial.h"
#include <USBLib_Trace.h>
#include <USBDDriver.h>
#include <USBD_HAL.h>
/*------------------------------------------------------------------------------
* Types
*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
* Internal variables
*------------------------------------------------------------------------------*/
/** Serial Port instance list */
static CDCDSerialPort cdcdSerial;
/*------------------------------------------------------------------------------
* Internal functions
*------------------------------------------------------------------------------*/
/**
* USB CDC Serial Port Event Handler.
* \param event Event code.
* \param param Event parameter.
*/
static uint32_t CDCDSerial_EventHandler(uint32_t event,
uint32_t param)
{
switch (event) {
case CDCDSerialPortEvent_SETCONTROLLINESTATE:
{
if (CDCDSerial_ControlLineStateChanged != NULL) {
CDCDSerial_ControlLineStateChanged(
(param & CDCControlLineState_DTR) > 0,
(param & CDCControlLineState_RTS) > 0);
}
}
break;
case CDCDSerialPortEvent_SETLINECODING:
{
if (NULL != CDCDSerial_LineCodingIsToChange) {
event = CDCDSerial_LineCodingIsToChange(
(CDCLineCoding*)param);
if (event != USBRC_SUCCESS)
return event;
}
}
break;
default:
return USBRC_SUCCESS;
}
return USBRC_SUCCESS;
}
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
/**
* Initializes the USB Device CDC serial driver & USBD Driver.
* \param pUsbd Pointer to USBDDriver instance.
* \param bInterfaceNb Interface number for the function.
*/
void CDCDSerial_Initialize(
USBDDriver *pUsbd, uint8_t bInterfaceNb)
{
CDCDSerialPort *pCdcd = &cdcdSerial;
TRACE_INFO("CDCDSerial_Initialize\n\r");
/* Initialize serial port function */
CDCDSerialPort_Initialize(
pCdcd, pUsbd,
(CDCDSerialPortEventHandler)CDCDSerial_EventHandler,
0,
bInterfaceNb, 2);
}
/**
* Invoked whenever the device is changed by the
* host.
* \pDescriptors Pointer to the descriptors for function configure.
* \wLength Length of descriptors in number of bytes.
*/
void CDCDSerial_ConfigureFunction(USBGenericDescriptor *pDescriptors,
uint16_t wLength)
{
CDCDSerialPort *pCdcd = &cdcdSerial;
CDCDSerialPort_ParseInterfaces(pCdcd,
(USBGenericDescriptor*)pDescriptors,
wLength);
}
/**
* Handles CDC-specific SETUP requests. Should be called from a
* re-implementation of USBDCallbacks_RequestReceived() method.
* \param request Pointer to a USBGenericRequest instance.
*/
uint32_t CDCDSerial_RequestHandler(const USBGenericRequest *request)
{
CDCDSerialPort * pCdcd = &cdcdSerial;
TRACE_INFO_WP("Cdcf ");
return CDCDSerialPort_RequestHandler(pCdcd, request);
}
/**
* Receives data from the host through the virtual COM port created by
* the CDC device serial driver. This function behaves like USBD_Read.
* \param data Pointer to the data buffer to put received data.
* \param size Size of the data buffer in bytes.
* \param callback Optional callback function to invoke when the transfer
* finishes.
* \param argument Optional argument to the callback function.
* \return USBD_STATUS_SUCCESS if the read operation has been started normally;
* otherwise, the corresponding error code.
*/
uint32_t CDCDSerial_Read(void *data,
uint32_t size,
TransferCallback callback,
void *argument)
{
CDCDSerialPort * pCdcd = &cdcdSerial;
return CDCDSerialPort_Read(pCdcd, data, size, callback, argument);
}
/**
* Sends a data buffer through the virtual COM port created by the CDC
* device serial driver. This function behaves exactly like USBD_Write.
* \param data Pointer to the data buffer to send.
* \param size Size of the data buffer in bytes.
* \param callback Optional callback function to invoke when the transfer
* finishes.
* \param argument Optional argument to the callback function.
* \return USBD_STATUS_SUCCESS if the read operation has been started normally;
* otherwise, the corresponding error code.
*/
uint32_t CDCDSerial_Write(void *data,
uint32_t size,
TransferCallback callback,
void *argument)
{
CDCDSerialPort * pCdcd = &cdcdSerial;
return CDCDSerialPort_Write(pCdcd, data, size, callback, argument);
}
/**
* Returns the current control line state of the RS-232 line.
*/
uint8_t CDCDSerial_GetControlLineState(void)
{
CDCDSerialPort * pCdcd = &cdcdSerial;
return CDCDSerialPort_GetControlLineState(pCdcd);
}
/**
* Copy current line coding settings to pointered space.
* \param pLineCoding Pointer to CDCLineCoding instance.
*/
void CDCDSerial_GetLineCoding(CDCLineCoding* pLineCoding)
{
CDCDSerialPort * pCdcd = &cdcdSerial;
CDCDSerialPort_GetLineCoding(pCdcd, pLineCoding);
}
/**
* Returns the current status of the RS-232 line.
*/
uint16_t CDCDSerial_GetSerialState(void)
{
CDCDSerialPort * pCdcd = &cdcdSerial;
return CDCDSerialPort_GetSerialState(pCdcd);
}
/**
* Sets the current serial state of the device to the given value.
* \param serialState New device state.
*/
void CDCDSerial_SetSerialState(uint16_t serialState)
{
CDCDSerialPort * pCdcd = &cdcdSerial;
CDCDSerialPort_SetSerialState(pCdcd, serialState);
}
/**@}*/

View File

@ -0,0 +1,116 @@
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------
*/
/**\file
* Title: CDCDSerialDriver implementation
*
* About: Purpose
* Implementation of the CDCDSerialDriver class methods.
*/
/** \addtogroup usbd_cdc
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include "CDCDSerialDriver.h"
#include <USBLib_Trace.h>
#include <USBDDriver.h>
#include <USBD_HAL.h>
/*------------------------------------------------------------------------------
* Types
*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
* Internal variables
*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
* Internal functions
*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
/**
* Initializes the USB Device CDC serial driver & USBD Driver.
* \param pDescriptors Pointer to Descriptors list for CDC Serial Device.
*/
void CDCDSerialDriver_Initialize(const USBDDriverDescriptors *pDescriptors)
{
USBDDriver *pUsbd = USBD_GetDriver();
/* Initialize the standard driver */
USBDDriver_Initialize(pUsbd,
pDescriptors,
0); /* Multiple settings for interfaces not supported */
CDCDSerial_Initialize(pUsbd, CDCDSerialDriver_CC_INTERFACE);
/* Initialize the USB driver */
USBD_Init();
}
/**
* Invoked whenever the active configuration of device is changed by the
* host.
* \param cfgnum Configuration number.
*/
void CDCDSerialDriver_ConfigurationChangedHandler(uint8_t cfgnum)
{
USBDDriver *pUsbd = USBD_GetDriver();
USBConfigurationDescriptor *pDesc;
if (cfgnum) {
pDesc = USBDDriver_GetCfgDescriptors(pUsbd, cfgnum);
CDCDSerial_ConfigureFunction((USBGenericDescriptor *)pDesc,
pDesc->wTotalLength);
}
}
/**
* Handles CDC-specific SETUP requests. Should be called from a
* re-implementation of USBDCallbacks_RequestReceived() method.
* \param request Pointer to a USBGenericRequest instance.
*/
void CDCDSerialDriver_RequestHandler(const USBGenericRequest *request)
{
USBDDriver *pUsbd = USBD_GetDriver();
TRACE_INFO_WP("NewReq ");
if (CDCDSerial_RequestHandler(request))
USBDDriver_RequestHandler(pUsbd, request);
}
/**@}*/

View File

@ -0,0 +1,458 @@
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------
*/
/**\file
* Implementation of the CDCDSerialPort class methods.
*/
/** \addtogroup usbd_cdc
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include <CDCDSerialPort.h>
#include <CDCDescriptors.h>
#include <USBLib_Trace.h>
/*------------------------------------------------------------------------------
* Types
*------------------------------------------------------------------------------*/
/** Parse data extention for descriptor parsing */
typedef struct _CDCDParseData {
/** Pointer to CDCDSerialPort instance */
CDCDSerialPort * pCdcd;
/** Pointer to found interface descriptor */
USBInterfaceDescriptor * pIfDesc;
} CDCDParseData;
/*------------------------------------------------------------------------------
* Internal variables
*------------------------------------------------------------------------------*/
/** Line coding values */
static CDCLineCoding lineCoding;
/*------------------------------------------------------------------------------
* Internal functions
*------------------------------------------------------------------------------*/
/**
* Parse descriptors: Interface, Bulk IN/OUT, Interrupt IN.
* \param desc Pointer to descriptor list.
* \param arg Argument, pointer to AUDDParseData instance.
*/
static uint32_t _Interfaces_Parse(USBGenericDescriptor *pDesc,
CDCDParseData * pArg)
{
CDCDSerialPort *pCdcd = pArg->pCdcd;
/* Not a valid descriptor */
if (pDesc->bLength == 0)
return USBRC_PARAM_ERR;
/* Find interface descriptor */
if (pDesc->bDescriptorType == USBGenericDescriptor_INTERFACE) {
USBInterfaceDescriptor *pIf = (USBInterfaceDescriptor*)pDesc;
/* Obtain interface from descriptor */
if (pCdcd->bInterfaceNdx == 0xFF) {
/* First interface is communication */
if (pIf->bInterfaceClass ==
CDCCommunicationInterfaceDescriptor_CLASS) {
pCdcd->bInterfaceNdx = pIf->bInterfaceNumber;
pCdcd->bNumInterface = 2;
}
/* Only data interface */
else if(pIf->bInterfaceClass == CDCDataInterfaceDescriptor_CLASS) {
pCdcd->bInterfaceNdx = pIf->bInterfaceNumber;
pCdcd->bNumInterface = 1;
}
pArg->pIfDesc = pIf;
}
else if (pCdcd->bInterfaceNdx <= pIf->bInterfaceNumber
&& pCdcd->bInterfaceNdx + pCdcd->bNumInterface
> pIf->bInterfaceNumber) {
pArg->pIfDesc = pIf;
}
}
/* Parse valid interfaces */
if (pArg->pIfDesc == 0)
return 0;
/* Find endpoint descriptors */
if (pDesc->bDescriptorType == USBGenericDescriptor_ENDPOINT) {
USBEndpointDescriptor *pEp = (USBEndpointDescriptor*)pDesc;
switch(pEp->bmAttributes & 0x3) {
case USBEndpointDescriptor_INTERRUPT:
if (pEp->bEndpointAddress & 0x80)
pCdcd->bIntInPIPE = pEp->bEndpointAddress & 0x7F;
break;
case USBEndpointDescriptor_BULK:
if (pEp->bEndpointAddress & 0x80)
pCdcd->bBulkInPIPE = pEp->bEndpointAddress & 0x7F;
else
pCdcd->bBulkOutPIPE = pEp->bEndpointAddress;
}
}
if ( pCdcd->bInterfaceNdx != 0xFF
&& pCdcd->bBulkInPIPE != 0
&& pCdcd->bBulkOutPIPE != 0)
return USBRC_FINISHED;
return 0;
}
/**
* Callback function which should be invoked after the data of a
* SetLineCoding request has been retrieved. Sends a zero-length packet
* to the host for acknowledging the request.
* \param pCdcd Pointer to CDCDSerialPort instance.
*/
static void _SetLineCodingCallback(CDCDSerialPort * pCdcd)
{
uint32_t exec = 1;
if (pCdcd->fEventHandler) {
uint32_t rc = pCdcd->fEventHandler(
CDCDSerialPortEvent_SETLINECODING,
(uint32_t)(&lineCoding),
pCdcd->pArg);
if (rc == USBD_STATUS_SUCCESS) {
pCdcd->lineCoding.dwDTERate = lineCoding.dwDTERate;
pCdcd->lineCoding.bCharFormat = lineCoding.bCharFormat;
pCdcd->lineCoding.bParityType = lineCoding.bParityType;
pCdcd->lineCoding.bDataBits = lineCoding.bDataBits;
}
else
exec = 0;
}
if (exec) USBD_Write(0, 0, 0, 0, 0);
else USBD_Stall(0);
}
/**
* Receives new line coding information from the USB host.
* \param pCdcd Pointer to CDCDSerialPort instance.
*/
static void _SetLineCoding(CDCDSerialPort * pCdcd)
{
TRACE_INFO_WP("sLineCoding ");
USBD_Read(0,
(void *) & (lineCoding),
sizeof(CDCLineCoding),
(TransferCallback)_SetLineCodingCallback,
(void*)pCdcd);
}
/**
* Sends the current line coding information to the host through Control
* endpoint 0.
* \param pCdcd Pointer to CDCDSerialPort instance.
*/
static void _GetLineCoding(CDCDSerialPort * pCdcd)
{
TRACE_INFO_WP("gLineCoding ");
USBD_Write(0,
(void *) &(pCdcd->lineCoding),
sizeof(CDCLineCoding),
0,
0);
}
/**
* Changes the state of the serial driver according to the information
* sent by the host via a SetControlLineState request, and acknowledges
* the request with a zero-length packet.
* \param pCdcd Pointer to CDCDSerialPort instance.
* \param request Pointer to a USBGenericRequest instance.
*/
static void _SetControlLineState(
CDCDSerialPort * pCdcd,
const USBGenericRequest *request)
{
#if (TRACE_LEVEL >= TRACE_LEVEL_INFO)
uint8_t DTR, RTS;
DTR = ((request->wValue & CDCControlLineState_DTR) > 0);
RTS = ((request->wValue & CDCControlLineState_RTS) > 0);
TRACE_INFO_WP("sControlLineState(%d, %d) ", DTR, RTS);
#endif
pCdcd->bControlLineState = (uint8_t)request->wValue;
USBD_Write(0, 0, 0, 0, 0);
if (pCdcd->fEventHandler)
pCdcd->fEventHandler(CDCDSerialPortEvent_SETCONTROLLINESTATE,
(uint32_t)pCdcd->bControlLineState,
pCdcd->pArg);
}
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
/**
* Initializes the USB Device CDC serial port function.
* \param pCdcd Pointer to CDCDSerialPort instance.
* \param pUsbd Pointer to USBDDriver instance.
* \param fEventHandler Pointer to event handler function.
* \param firstInterface First interface index for the function
* (0xFF to parse from descriptors).
* \param numInterface Number of interfaces for the function.
*/
void CDCDSerialPort_Initialize(CDCDSerialPort * pCdcd,
USBDDriver * pUsbd,
CDCDSerialPortEventHandler fEventHandler,
void * pArg,
uint8_t firstInterface,uint8_t numInterface)
{
TRACE_INFO("CDCDSerialPort_Initialize\n\r");
/* Initialize event handler */
pCdcd->fEventHandler = fEventHandler;
pCdcd->pArg = pArg;
/* Initialize USB Device Driver interface */
pCdcd->pUsbd = pUsbd;
pCdcd->bInterfaceNdx = firstInterface;
pCdcd->bNumInterface = numInterface;
pCdcd->bIntInPIPE = 0;
pCdcd->bBulkInPIPE = 0;
pCdcd->bBulkOutPIPE = 0;
/* Initialize Abstract Control Model attributes */
pCdcd->bControlLineState = 0;
pCdcd->wSerialState = 0;
CDCLineCoding_Initialize(&(pCdcd->lineCoding),
115200,
CDCLineCoding_ONESTOPBIT,
CDCLineCoding_NOPARITY,
8);
}
/**
* Parse CDC Serial Port information for CDCDSerialPort instance.
* Accepted interfaces:
* - Communication Interface + Data Interface
* - Data Interface ONLY
* \param pCdcd Pointer to CDCDSerialPort instance.
* \param pDescriptors Pointer to descriptor list.
* \param dwLength Descriptor list size in bytes.
*/
USBGenericDescriptor *CDCDSerialPort_ParseInterfaces(
CDCDSerialPort *pCdcd,
USBGenericDescriptor *pDescriptors,
uint32_t dwLength)
{
CDCDParseData parseData;
parseData.pCdcd = pCdcd;
parseData.pIfDesc = 0;
return USBGenericDescriptor_Parse(
pDescriptors, dwLength,
(USBDescriptorParseFunction)_Interfaces_Parse,
&parseData);
}
/**
* Handles CDC-specific SETUP requests. Should be called from a
* re-implementation of USBDCallbacks_RequestReceived() method.
* \param pCdcd Pointer to CDCDSerialPort instance.
* \param request Pointer to a USBGenericRequest instance.
* \return USBRC_SUCCESS if request handled, otherwise error.
*/
uint32_t CDCDSerialPort_RequestHandler(
CDCDSerialPort *pCdcd,
const USBGenericRequest *request)
{
if (USBGenericRequest_GetType(request) != USBGenericRequest_CLASS)
return USBRC_PARAM_ERR;
TRACE_INFO_WP("Cdcs ");
/* Validate interface */
if (request->wIndex >= pCdcd->bInterfaceNdx &&
request->wIndex < pCdcd->bInterfaceNdx + pCdcd->bNumInterface) {
}
else {
return USBRC_PARAM_ERR;
}
/* Handle the request */
switch (USBGenericRequest_GetRequest(request)) {
case CDCGenericRequest_SETLINECODING:
_SetLineCoding(pCdcd);
break;
case CDCGenericRequest_GETLINECODING:
_GetLineCoding(pCdcd);
break;
case CDCGenericRequest_SETCONTROLLINESTATE:
_SetControlLineState(pCdcd, request);
break;
default:
return USBRC_PARAM_ERR;
}
return USBRC_SUCCESS;
}
/**
* Receives data from the host through the virtual COM port created by
* the CDC device serial driver. This function behaves like USBD_Read.
* \param pCdcd Pointer to CDCDSerialPort instance.
* \param pData Pointer to the data buffer to put received data.
* \param dwSize Size of the data buffer in bytes.
* \param fCallback Optional callback function to invoke when the transfer
* finishes.
* \param pArg Optional argument to the callback function.
* \return USBD_STATUS_SUCCESS if the read operation has been started normally;
* otherwise, the corresponding error code.
*/
uint32_t CDCDSerialPort_Read(const CDCDSerialPort * pCdcd,
void * pData,uint32_t dwSize,
TransferCallback fCallback,void * pArg)
{
if (pCdcd->bBulkOutPIPE == 0)
return USBRC_PARAM_ERR;
return USBD_Read(pCdcd->bBulkOutPIPE,
pData, dwSize,
fCallback, pArg);
}
/**
* Sends a data buffer through the virtual COM port created by the CDC
* device serial driver. This function behaves exactly like USBD_Write.
* \param pCdcd Pointer to CDCDSerialPort instance.
* \param pData Pointer to the data buffer to send.
* \param dwSize Size of the data buffer in bytes.
* \param fCallback Optional callback function to invoke when the transfer
* finishes.
* \param pArg Optional argument to the callback function.
* \return USBD_STATUS_SUCCESS if the read operation has been started normally;
* otherwise, the corresponding error code.
*/
uint32_t CDCDSerialPort_Write(const CDCDSerialPort * pCdcd,
void * pData, uint32_t dwSize,
TransferCallback fCallback, void * pArg)
{
if (pCdcd->bBulkInPIPE == 0)
return USBRC_PARAM_ERR;
return USBD_Write(pCdcd->bBulkInPIPE,
pData, dwSize,
fCallback, pArg);
}
/**
* Returns the current control line state of the RS-232 line.
* \param pCdcd Pointer to CDCDSerialPort instance.
*/
uint8_t CDCDSerialPort_GetControlLineState(const CDCDSerialPort * pCdcd)
{
return pCdcd->bControlLineState;
}
/**
* Copy current line coding settings to pointered space.
* \param pCdcd Pointer to CDCDSerialPort instance.
* \param pLineCoding Pointer to CDCLineCoding instance.
*/
void CDCDSerialPort_GetLineCoding(const CDCDSerialPort * pCdcd,
CDCLineCoding* pLineCoding)
{
if (pLineCoding) {
pLineCoding->dwDTERate = pCdcd->lineCoding.dwDTERate;
pLineCoding->bCharFormat = pCdcd->lineCoding.bCharFormat;
pLineCoding->bParityType = pCdcd->lineCoding.bParityType;
pLineCoding->bDataBits = pCdcd->lineCoding.bDataBits;
}
}
/**
* Returns the current status of the RS-232 line.
* \param pCdcd Pointer to CDCDSerialPort instance.
*/
uint16_t CDCDSerialPort_GetSerialState(const CDCDSerialPort * pCdcd)
{
return pCdcd->wSerialState;
}
/**
* Sets the current serial state of the device to the given value.
* \param pCdcd Pointer to CDCDSerialPort instance.
* \param wSerialState New device state.
*/
void CDCDSerialPort_SetSerialState(CDCDSerialPort * pCdcd,
uint16_t wSerialState)
{
if (pCdcd->bIntInPIPE == 0)
return;
/* If new state is different from previous one, send a notification to the
host */
if (pCdcd->wSerialState != wSerialState) {
pCdcd->wSerialState = wSerialState;
USBD_Write(pCdcd->bIntInPIPE,
&(pCdcd->wSerialState),
2,
0,
0);
/* Reset one-time flags */
pCdcd->wSerialState &= ~(CDCSerialState_OVERRUN
| CDCSerialState_PARITY
| CDCSerialState_FRAMING
| CDCSerialState_RINGSIGNAL
| CDCSerialState_BREAK);
}
}
/**@}*/

View File

@ -0,0 +1,70 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, 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
*---------------------------------------------------------------------------*/
/* These headers were introduced in C99
by working group ISO/IEC JTC1/SC22/WG14. */
#include <stdint.h>
#include "CDCDSerial.h"
/*---------------------------------------------------------------------------
* Default callback functions
*---------------------------------------------------------------------------*/
/**
* Invoked when the CDC LineCoding is requested to changed
* \param port Port number.
* \param pLineCoding Pointer to new LineCoding settings.
* \return USBRC_SUCCESS if ready to receive the line coding.
*/
extern WEAK uint8_t CDCDSerial_LineCodingIsToChange(
CDCLineCoding * pLineCoding)
{
/* Accept any of linecoding settings */
pLineCoding = pLineCoding;
return USBRC_SUCCESS;
}
/**
* Invoked when the CDC ControlLineState is changed
* \param port Port number.
* \param DTR New DTR value.
* \param RTS New RTS value.
*/
extern WEAK void CDCDSerial_ControlLineStateChanged(uint8_t DTR,
uint8_t RTS)
{
/* Do nothing */
DTR = DTR; RTS = RTS;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

View File

@ -0,0 +1,101 @@
;
; Windows USB CDC Driver Setup File for ATMEL AT91SAM products
;
; On Windows 7, right click to update driver software. It may take a while to
; get this option, even if you cancel the auto driver search.
; choose "browse my computer for driver software",
; choose "let me pick from a list of device drivers on my computer",
; Click "have disk" and browse to this .inf file
; If there is a problem, right click and uninstall, checking delete driver software.
;------------------------------------------------------------------------------
[Version]
Signature="$Windows NT$"
Class=Ports
ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318}
Provider=%ATMEL%
LayoutFile=layout.inf
DriverVer= 03/09/2011,2.0.0.0
[Manufacturer]
%ATMEL%=DeviceList,NTamd64
[DestinationDirs]
DefaultDestDir=12
;------------------------------------------------------------------------------
; Windows 2000/XP/Vista32 Support
;------------------------------------------------------------------------------
[DriverInstall.nt]
include=mdmcpq.inf
CopyFiles=DriverCopyFiles.nt
AddReg=DriverInstall.nt.AddReg
[DriverCopyFiles.nt]
usbser.sys,,,0x20
[DriverInstall.nt.AddReg]
HKR,,DevLoader,,*ntkern
HKR,,NTMPDriver,,usbser.sys
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
[DriverInstall.nt.Services]
AddService=usbser, 0x00000002, DriverService.nt
[DriverService.nt]
DisplayName=%USBtoSerialConverter%
ServiceType=1
StartType=3
ErrorControl=1
ServiceBinary=%12%\usbser.sys
;------------------------------------------------------------------------------
; Windows Vista64 Support
;------------------------------------------------------------------------------
[DriverInstall.NTamd64]
include=mdmcpq.inf
CopyFiles=DriverCopyFiles.NTamd64
AddReg=DriverInstall.NTamd64.AddReg
[DriverCopyFiles.NTamd64]
usbser.sys,,,0x20
[DriverInstall.NTamd64.AddReg]
HKR,,DevLoader,,*ntkern
HKR,,NTMPDriver,,usbser.sys
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
[DriverInstall.NTamd64.Services]
AddService=usbser, 0x00000002, DriverService.NTamd64
[DriverService.NTamd64]
DisplayName=%USBtoSerialConverter%
ServiceType=1
StartType=3
ErrorControl=1
ServiceBinary=%12%\usbser.sys
;------------------------------------------------------------------------------
; VID/PID Settings
;------------------------------------------------------------------------------
[SourceDisksFiles]
[SourceDisksNames]
[DeviceList]
%USBtoSerialConverter%=DriverInstall, USB\VID_03EB&PID_6119
[DeviceList.NTamd64]
%USBtoSerialConverter%=DriverInstall, USB\VID_03EB&PID_6119
;------------------------------------------------------------------------------
; String Definitions
;------------------------------------------------------------------------------
[Strings]
ATMEL="ATMEL Corp." ; String value for the ATMEL symbol
USBtoSerialConverter="AT91 USB to Serial Converter" ; String value for the USBtoSerialConverter symbol

View File

@ -0,0 +1,550 @@
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------
*/
/** \file
*
* \section Purpose
*
* Implementation of USB device functions on a UDP controller.
*
* See \ref usbd_api "USBD API Methods".
*/
/** \addtogroup usbd_interface
*@{
*/
/*---------------------------------------------------------------------------
* Headers
*---------------------------------------------------------------------------*/
#include "USBD.h"
#include "USBD_HAL.h"
#include <USBLib_Trace.h>
/*---------------------------------------------------------------------------
* Definitions
*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
* Internal variables
*---------------------------------------------------------------------------*/
/** Device current state. */
static uint8_t deviceState;
/** Indicates the previous device state */
static uint8_t previousDeviceState;
/*---------------------------------------------------------------------------
* Internal Functions
*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
* Exported functions
*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
* USBD: Event handlers
*---------------------------------------------------------------------------*/
/**
* Handle the USB suspend event, should be invoked whenever
* HW reports a suspend signal.
*/
void USBD_SuspendHandler(void)
{
/* Don't do anything if the device is already suspended */
if (deviceState != USBD_STATE_SUSPENDED) {
/* Switch to the Suspended state */
previousDeviceState = deviceState;
deviceState = USBD_STATE_SUSPENDED;
/* Suspend HW interface */
USBD_HAL_Suspend();
/* Invoke the User Suspended callback (Suspend System?) */
if (NULL != USBDCallbacks_Suspended)
USBDCallbacks_Suspended();
}
}
/**
* Handle the USB resume event, should be invoked whenever
* HW reports a resume signal.
*/
void USBD_ResumeHandler(void)
{
/* Don't do anything if the device was not suspended */
if (deviceState == USBD_STATE_SUSPENDED) {
/* Active the device */
USBD_HAL_Activate();
deviceState = previousDeviceState;
if (deviceState >= USBD_STATE_DEFAULT) {
/* Invoke the Resume callback */
if (NULL != USBDCallbacks_Resumed)
USBDCallbacks_Resumed();
}
}
}
/**
* Handle the USB reset event, should be invoked whenever
* HW found USB reset signal on bus, which usually is called
* "end of bus reset" status.
*/
void USBD_ResetHandler()
{
/* The device enters the Default state */
deviceState = USBD_STATE_DEFAULT;
/* Active the USB HW */
USBD_HAL_Activate();
/* Only EP0 enabled */
USBD_HAL_ResetEPs(0xFFFFFFFF, USBD_STATUS_RESET, 0);
USBD_ConfigureEndpoint(0);
/* Invoke the Reset callback */
if (NULL != USBDCallbacks_Reset)
USBDCallbacks_Reset();
}
/**
* Handle the USB setup package received, should be invoked
* when an endpoint got a setup package as request.
* \param bEndpoint Endpoint number.
* \param pRequest Pointer to content of request.
*/
void USBD_RequestHandler(uint8_t bEndpoint,
const USBGenericRequest* pRequest)
{
if (bEndpoint != 0) {
TRACE_WARNING("EP%d request not supported, default EP only",
bEndpoint);
}
else if (NULL != USBDCallbacks_RequestReceived) {
USBDCallbacks_RequestReceived(pRequest);
}
}
/*---------------------------------------------------------------------------
* USBD: Library interface
*---------------------------------------------------------------------------*/
/**
* Configures an endpoint according to its Endpoint Descriptor.
* \param pDescriptor Pointer to an Endpoint descriptor.
*/
void USBD_ConfigureEndpoint(const USBEndpointDescriptor *pDescriptor)
{
USBD_HAL_ConfigureEP(pDescriptor);
}
/**
* Sends data through a USB endpoint. Sets up the transfer descriptor,
* writes one or two data payloads (depending on the number of FIFO bank
* for the endpoint) and then starts the actual transfer. The operation is
* complete when all the data has been sent.
*
* *If the size of the buffer is greater than the size of the endpoint
* (or twice the size if the endpoint has two FIFO banks), then the buffer
* must be kept allocated until the transfer is finished*. This means that
* it is not possible to declare it on the stack (i.e. as a local variable
* of a function which returns after starting a transfer).
*
* \param bEndpoint Endpoint number.
* \param pData Pointer to a buffer with the data to send.
* \param dLength Size of the data buffer.
* \param fCallback Optional callback function to invoke when the transfer is
* complete.
* \param pArgument Optional argument to the callback function.
* \return USBD_STATUS_SUCCESS if the transfer has been started;
* otherwise, the corresponding error status code.
*/
uint8_t USBD_Write( uint8_t bEndpoint,
const void *pData,
uint32_t dLength,
TransferCallback fCallback,
void *pArgument )
{
USBD_HAL_SetTransferCallback(bEndpoint, fCallback, pArgument);
return USBD_HAL_Write(bEndpoint, pData, dLength);
}
#if 0
/**
* Sends data frames through a USB endpoint. Sets up the transfer descriptor
* list, writes one or two data payloads (depending on the number of FIFO bank
* for the endpoint) and then starts the actual transfer. The operation is
* complete when all the data has been sent.
*
* *If the size of the frame is greater than the size of the endpoint
* (or twice the size if the endpoint has two FIFO banks), then the buffer
* must be kept allocated until the frame is finished*. This means that
* it is not possible to declare it on the stack (i.e. as a local variable
* of a function which returns after starting a transfer).
*
* \param bEndpoint Endpoint number.
* \param pMbl Pointer to a frame (USBDTransferBuffer) list that describes
* the buffer list to send.
* \param wListSize Size of the frame list.
* \param bCircList Circle the list.
* \param wStartNdx For circled list only, the first buffer index to transfer.
* \param fCallback Optional callback function to invoke when the transfer is
* complete.
* \param pArgument Optional argument to the callback function.
* \return USBD_STATUS_SUCCESS if the transfer has been started;
* otherwise, the corresponding error status code.
* \see USBDTransferBuffer, MblTransferCallback, USBD_MblReuse
*/
uint8_t USBD_MblWrite( uint8_t bEndpoint,
void *pMbl,
uint16_t wListSize,
uint8_t bCircList,
uint16_t wStartNdx,
MblTransferCallback fCallback,
void *pArgument )
{
Endpoint *pEndpoint = &(endpoints[bEndpoint]);
MblTransfer *pTransfer = (MblTransfer*)&(pEndpoint->transfer);
uint16_t i;
/* EP0 is not suitable for Mbl */
if (bEndpoint == 0) {
return USBD_STATUS_INVALID_PARAMETER;
}
/* Check that the endpoint is in Idle state */
if (pEndpoint->state != UDP_ENDPOINT_IDLE) {
return USBD_STATUS_LOCKED;
}
pEndpoint->state = UDP_ENDPOINT_SENDINGM;
TRACE_DEBUG_WP("WriteM%d(0x%x,%d) ", bEndpoint, pMbl, wListSize);
/* Start from first if not circled list */
if (!bCircList) wStartNdx = 0;
/* Setup the transfer descriptor */
pTransfer->pMbl = (USBDTransferBuffer*)pMbl;
pTransfer->listSize = wListSize;
pTransfer->fCallback = fCallback;
pTransfer->pArgument = pArgument;
pTransfer->currBuffer = wStartNdx;
pTransfer->freedBuffer = 0;
pTransfer->pLastLoaded = &(((USBDTransferBuffer*)pMbl)[wStartNdx]);
pTransfer->circList = bCircList;
pTransfer->allUsed = 0;
/* Clear all buffer */
for (i = 0; i < wListSize; i ++) {
pTransfer->pMbl[i].transferred = 0;
pTransfer->pMbl[i].buffered = 0;
pTransfer->pMbl[i].remaining = pTransfer->pMbl[i].size;
}
/* Send the first packet */
while((UDP->UDP_CSR[bEndpoint]&UDP_CSR_TXPKTRDY)==UDP_CSR_TXPKTRDY);
UDP_MblWriteFifo(bEndpoint);
SET_CSR(bEndpoint, UDP_CSR_TXPKTRDY);
/* If double buffering is enabled and there is data remaining, */
/* prepare another packet */
if ((CHIP_USB_ENDPOINTS_BANKS(bEndpoint) > 1)
&& (pTransfer->pMbl[pTransfer->currBuffer].remaining > 0)) {
UDP_MblWriteFifo(bEndpoint);
}
/* Enable interrupt on endpoint */
UDP->UDP_IER = 1 << bEndpoint;
return USBD_STATUS_SUCCESS;
}
#endif
/**
* Reads incoming data on an USB endpoint This methods sets the transfer
* descriptor and activate the endpoint interrupt. The actual transfer is
* then carried out by the endpoint interrupt handler. The Read operation
* finishes either when the buffer is full, or a short packet (inferior to
* endpoint maximum size) is received.
*
* *The buffer must be kept allocated until the transfer is finished*.
* \param bEndpoint Endpoint number.
* \param pData Pointer to a data buffer.
* \param dLength Size of the data buffer in bytes.
* \param fCallback Optional end-of-transfer callback function.
* \param pArgument Optional argument to the callback function.
* \return USBD_STATUS_SUCCESS if the read operation has been started;
* otherwise, the corresponding error code.
*/
uint8_t USBD_Read(uint8_t bEndpoint,
void *pData,
uint32_t dLength,
TransferCallback fCallback,
void *pArgument)
{
USBD_HAL_SetTransferCallback(bEndpoint, fCallback, pArgument);
return USBD_HAL_Read(bEndpoint, pData, dLength);
}
#if 0
/**
* Reuse first used/released buffer with new buffer address and size to be used
* in transfer again. Only valid when frame list is ringed. Can be used for
* both read & write.
* \param bEndpoint Endpoint number.
* \param pNewBuffer Pointer to new buffer with data to send (0 to keep last).
* \param wNewSize Size of the data buffer
*/
uint8_t USBD_MblReuse( uint8_t bEndpoint,
uint8_t *pNewBuffer,
uint16_t wNewSize )
{
Endpoint *pEndpoint = &(endpoints[bEndpoint]);
MblTransfer *pTransfer = (MblTransfer*)&(pEndpoint->transfer);
USBDTransferBuffer *pBi = &(pTransfer->pMbl[pTransfer->freedBuffer]);
TRACE_DEBUG_WP("MblReuse(%d), st%x, circ%d\n\r",
bEndpoint, pEndpoint->state, pTransfer->circList);
/* Only for Multi-buffer-circle list */
if (bEndpoint != 0
&& (pEndpoint->state == UDP_ENDPOINT_RECEIVINGM
|| pEndpoint->state == UDP_ENDPOINT_SENDINGM)
&& pTransfer->circList) {
}
else {
return USBD_STATUS_WRONG_STATE;
}
/* Check if there is freed buffer */
if (pTransfer->freedBuffer == pTransfer->currBuffer
&& !pTransfer->allUsed) {
return USBD_STATUS_LOCKED;
}
/* Update transfer information */
if ((++ pTransfer->freedBuffer) == pTransfer->listSize)
pTransfer->freedBuffer = 0;
if (pNewBuffer) {
pBi->pBuffer = pNewBuffer;
pBi->size = wNewSize;
}
pBi->buffered = 0;
pBi->transferred = 0;
pBi->remaining = pBi->size;
/* At least one buffer is not processed */
pTransfer->allUsed = 0;
return USBD_STATUS_SUCCESS;
}
#endif
/**
* Sets the HALT feature on the given endpoint (if not already in this state).
* \param bEndpoint Endpoint number.
*/
void USBD_Halt(uint8_t bEndpoint)
{
USBD_HAL_Halt(bEndpoint, 1);
}
/**
* Clears the Halt feature on the given endpoint.
* \param bEndpoint Index of endpoint
*/
void USBD_Unhalt(uint8_t bEndpoint)
{
USBD_HAL_Halt(bEndpoint, 0);
}
/**
* Returns the current Halt status of an endpoint.
* \param bEndpoint Index of endpoint
* \return 1 if the endpoint is currently halted; otherwise 0
*/
uint8_t USBD_IsHalted(uint8_t bEndpoint)
{
return USBD_HAL_Halt(bEndpoint, 0xFF);
}
/**
* Indicates if the device is running in high or full-speed. Always returns 0
* since UDP does not support high-speed mode.
*/
uint8_t USBD_IsHighSpeed(void)
{
return USBD_HAL_IsHighSpeed();
}
/**
* Causes the given endpoint to acknowledge the next packet it receives
* with a STALL handshake.
* \param bEndpoint Endpoint number.
* \return USBD_STATUS_SUCCESS or USBD_STATUS_LOCKED.
*/
uint8_t USBD_Stall(uint8_t bEndpoint)
{
return USBD_HAL_Stall(bEndpoint);
}
/**
* Sets the device address to the given value.
* \param address New device address.
*/
void USBD_SetAddress(uint8_t address)
{
TRACE_INFO_WP("SetAddr(%d) ", address);
USBD_HAL_SetAddress(address);
if (address == 0) deviceState = USBD_STATE_DEFAULT;
else deviceState = USBD_STATE_ADDRESS;
}
/**
* Sets the current device configuration.
* \param cfgnum - Configuration number to set.
*/
void USBD_SetConfiguration(uint8_t cfgnum)
{
TRACE_INFO_WP("SetCfg(%d) ", cfgnum);
USBD_HAL_SetConfiguration(cfgnum);
if (cfgnum != 0) {
deviceState = USBD_STATE_CONFIGURED;
}
else {
deviceState = USBD_STATE_ADDRESS;
/* Reset all endpoints but Control 0 */
USBD_HAL_ResetEPs(0xFFFFFFFE, USBD_STATUS_RESET, 0);
}
}
/*---------------------------------------------------------------------------
* USBD: Library API
*---------------------------------------------------------------------------*/
/**
* Starts a remote wake-up procedure.
*/
void USBD_RemoteWakeUp(void)
{
/* Device is NOT suspended */
if (deviceState != USBD_STATE_SUSPENDED) {
TRACE_INFO("USBD_RemoteWakeUp: Device is not suspended\n\r");
return;
}
USBD_HAL_Activate();
USBD_HAL_RemoteWakeUp();
}
/**
* Connects the pull-up on the D+ line of the USB.
*/
void USBD_Connect(void)
{
USBD_HAL_Connect();
}
/**
* Disconnects the pull-up from the D+ line of the USB.
*/
void USBD_Disconnect(void)
{
USBD_HAL_Disconnect();
/* Device returns to the Powered state */
if (deviceState > USBD_STATE_POWERED) {
deviceState = USBD_STATE_POWERED;
}
if (previousDeviceState > USBD_STATE_POWERED) {
previousDeviceState = USBD_STATE_POWERED;
}
}
/**
* Initializes the USB driver.
*/
void USBD_Init(void)
{
TRACE_INFO_WP("USBD_Init\n\r");
/* HW Layer Initialize */
USBD_HAL_Init();
/* Device is in the Attached state */
deviceState = USBD_STATE_SUSPENDED;
previousDeviceState = USBD_STATE_POWERED;
/* Upper Layer Initialize */
if (NULL != USBDCallbacks_Initialized)
USBDCallbacks_Initialized();
}
/**
* Returns the current state of the USB device.
* \return Device current state.
*/
uint8_t USBD_GetState(void)
{
return deviceState;
}
/**
* Certification test for High Speed device.
* \param bIndex Test to be done
*/
void USBD_Test(uint8_t bIndex)
{
USBD_HAL_Test(bIndex);
}
/**@}*/

View File

@ -0,0 +1,90 @@
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------
*/
/** \file
* Definitions of callbacks used by the USBD API to notify the user
* application of incoming events. These functions are declared as 'weak',
* so they can be re-implemented elsewhere in the application in a
* transparent way.
*
* \addtogroup usbd_interface
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include "USBD.h"
#include "USBDDriver.h"
/*------------------------------------------------------------------------------
* Exported function
*------------------------------------------------------------------------------*/
/**
* Invoked after the USB driver has been initialized. By default, do nothing.
*/
WEAK void USBDCallbacks_Initialized(void)
{
/* Does nothing */
__asm volatile( "NOP" );
}
/**
* Invoked when the USB driver is reset. Does nothing by default.
*/
WEAK void USBDCallbacks_Reset(void)
{
/* Does nothing*/
}
/**
* Invoked when the USB device gets suspended. By default, do nothing.
*/
WEAK void USBDCallbacks_Suspended(void) {}
/**
* Invoked when the USB device leaves the Suspended state. By default,
* Do nothing.
*/
WEAK void USBDCallbacks_Resumed(void) {}
/**
* USBDCallbacks_RequestReceived - Invoked when a new SETUP request is
* received. Does nothing by default.
* \param request Pointer to the request to handle.
*/
WEAK void USBDCallbacks_RequestReceived(const USBGenericRequest *request)
{
/* Does basic enumeration */
USBDDriver_RequestHandler(USBD_GetDriver(), request);
}
/**@}*/

View File

@ -0,0 +1,823 @@
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------
*/
/** \file
* \addtogroup usbd_interface
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include <USBLib_Trace.h>
#include "USBDDriver.h"
#include "USBD.h"
#include "USBD_HAL.h"
#include <string.h>
/*------------------------------------------------------------------------------
* Local variables
*------------------------------------------------------------------------------*/
/** Default device driver instance, for all class drivers in USB Lib. */
static USBDDriver usbdDriver;
/*------------------------------------------------------------------------------
* Local functions
*------------------------------------------------------------------------------*/
/**
* Send a NULL packet
*/
static void TerminateCtrlInWithNull(void *pArg,
uint8_t status,
uint32_t transferred,
uint32_t remaining)
{
pArg = pArg; status = status;
transferred = transferred; remaining = remaining;
USBD_Write(0, /* Endpoint #0 */
0, /* No data buffer */
0, /* No data buffer */
(TransferCallback) 0,
(void *) 0);
}
/**
* Configures the device by setting it into the Configured state and
* initializing all endpoints.
* \param pDriver Pointer to a USBDDriver instance.
* \param cfgnum Configuration number to set.
*/
static void SetConfiguration(USBDDriver *pDriver, uint8_t cfgnum)
{
USBEndpointDescriptor *pEndpoints[17];
const USBConfigurationDescriptor *pConfiguration;
/* Use different descriptor depending on device speed */
if ( USBD_HAL_IsHighSpeed()
&& pDriver->pDescriptors->pHsConfiguration) {
pConfiguration = pDriver->pDescriptors->pHsConfiguration;
}
else {
pConfiguration = pDriver->pDescriptors->pFsConfiguration;
}
/* Set & save the desired configuration */
USBD_SetConfiguration(cfgnum);
pDriver->cfgnum = cfgnum;
pDriver->isRemoteWakeUpEnabled =
((pConfiguration->bmAttributes & 0x20) > 0);
/* If the configuration is not 0, configure endpoints */
if (cfgnum != 0) {
/* Parse configuration to get endpoint descriptors */
USBConfigurationDescriptor_Parse(pConfiguration, 0, pEndpoints, 0);
/* Configure endpoints */
int i = 0;
while (pEndpoints[i] != 0) {
USBD_ConfigureEndpoint(pEndpoints[i]);
i++;
}
}
/* Should be done before send the ZLP */
if (NULL != USBDDriverCallbacks_ConfigurationChanged)
USBDDriverCallbacks_ConfigurationChanged(cfgnum);
/* Acknowledge the request */
USBD_Write(0, /* Endpoint #0 */
0, /* No data buffer */
0, /* No data buffer */
(TransferCallback) 0,
(void *) 0);
}
/**
* Sends the current configuration number to the host.
* \param pDriver Pointer to a USBDDriver instance.
*/
static void GetConfiguration(const USBDDriver *pDriver)
{
unsigned long tmp; // Coud be unsigned char : unsigned long has been chose to avoid any potential alignment issue with DMA
if( USBD_GetState() < USBD_STATE_CONFIGURED)
tmp = 0; // If device is unconfigured, returned configuration must be 0
else
tmp = pDriver->cfgnum;
USBD_Write(0, &tmp, 1, 0, 0);
}
/**
* Sends the current status of the device to the host.
* \param pDriver Pointer to a USBDDriver instance.
*/
static void GetDeviceStatus(const USBDDriver *pDriver)
{
static unsigned short data;
const USBConfigurationDescriptor *pConfiguration;
data = 0;
/* Use different configuration depending on device speed */
if (USBD_IsHighSpeed()) {
pConfiguration = pDriver->pDescriptors->pHsConfiguration;
}
else {
pConfiguration = pDriver->pDescriptors->pFsConfiguration;
}
/* Check current configuration for power mode (if device is configured) */
if (pDriver->cfgnum != 0) {
if (USBConfigurationDescriptor_IsSelfPowered(pConfiguration)) {
data |= 1;
}
}
/* Check if remote wake-up is enabled */
if (pDriver->isRemoteWakeUpEnabled) {
data |= 2;
}
/* Send the device status */
USBD_Write(0, &data, 2, 0, 0);
}
/**
* Sends the current status of an endpoints to the USB host.
* \param bEndpoint Endpoint number.
*/
static void GetEndpointStatus(uint8_t bEndpoint)
{
static unsigned short data;
data = 0;
switch (USBD_HAL_Halt(bEndpoint, 0xFF)) {
case USBD_STATUS_INVALID_PARAMETER: /* the endpoint not exists */
USBD_Stall(0);
break;
case 1:
data = 1;
case 0:
/* Send the endpoint status */
USBD_Write(0, &data, 2, 0, 0);
break;
}
}
/**
* Sends the requested USB descriptor to the host if available, or STALLs the
* request.
* \param pDriver Pointer to a USBDDriver instance.
* \param type Type of the requested descriptor
* \param index Index of the requested descriptor.
* \param length Maximum number of bytes to return.
*/
static void GetDescriptor(
const USBDDriver *pDriver,
uint8_t type,
uint8_t indexRDesc,
uint32_t length)
{
const USBDeviceDescriptor *pDevice;
const USBConfigurationDescriptor *pConfiguration;
const USBDeviceQualifierDescriptor *pQualifier;
const USBConfigurationDescriptor *pOtherSpeed;
const USBGenericDescriptor **pStrings =
(const USBGenericDescriptor **) pDriver->pDescriptors->pStrings;
const USBGenericDescriptor *pString;
uint8_t numStrings = pDriver->pDescriptors->numStrings;
uint8_t terminateWithNull = 0;
/* Use different set of descriptors depending on device speed */
/* By default, we uses full speed values */
pDevice = pDriver->pDescriptors->pFsDevice;
pConfiguration = pDriver->pDescriptors->pFsConfiguration;
/* HS, we try HS values */
if (USBD_HAL_IsHighSpeed()) {
TRACE_DEBUG_WP("HS ");
if (pDriver->pDescriptors->pHsDevice)
pDevice = pDriver->pDescriptors->pHsDevice;
if (pDriver->pDescriptors->pHsConfiguration)
pConfiguration = pDriver->pDescriptors->pHsConfiguration;
pQualifier = pDriver->pDescriptors->pHsQualifier;
pOtherSpeed = pDriver->pDescriptors->pHsOtherSpeed;
}
else {
TRACE_DEBUG_WP("FS ");
pQualifier = pDriver->pDescriptors->pFsQualifier;
pOtherSpeed = pDriver->pDescriptors->pFsOtherSpeed;
}
/* Check the descriptor type */
switch (type) {
case USBGenericDescriptor_DEVICE:
TRACE_INFO_WP("Dev ");
/* Adjust length and send descriptor */
if (length > USBGenericDescriptor_GetLength((USBGenericDescriptor *) pDevice)) {
length = USBGenericDescriptor_GetLength((USBGenericDescriptor *) pDevice);
}
USBD_Write(0, pDevice, length, 0, 0);
break;
case USBGenericDescriptor_CONFIGURATION:
TRACE_INFO_WP("Cfg ");
/* Adjust length and send descriptor */
if (length > USBConfigurationDescriptor_GetTotalLength(pConfiguration)) {
length = USBConfigurationDescriptor_GetTotalLength(pConfiguration);
terminateWithNull = ((length % pDevice->bMaxPacketSize0) == 0);
}
USBD_Write(0,
pConfiguration,
length,
terminateWithNull ? TerminateCtrlInWithNull : 0,
0);
break;
case USBGenericDescriptor_DEVICEQUALIFIER:
TRACE_INFO_WP("Qua ");
/* Check if descriptor exists */
if (!pQualifier) {
USBD_Stall(0);
}
else {
/* Adjust length and send descriptor */
if (length > USBGenericDescriptor_GetLength((USBGenericDescriptor *) pQualifier)) {
length = USBGenericDescriptor_GetLength((USBGenericDescriptor *) pQualifier);
}
USBD_Write(0, pQualifier, length, 0, 0);
}
break;
case USBGenericDescriptor_OTHERSPEEDCONFIGURATION:
TRACE_INFO_WP("OSC ");
/* Check if descriptor exists */
if (!pOtherSpeed) {
USBD_Stall(0);
}
else {
/* Adjust length and send descriptor */
if (length > USBConfigurationDescriptor_GetTotalLength(pOtherSpeed)) {
length = USBConfigurationDescriptor_GetTotalLength(pOtherSpeed);
terminateWithNull = ((length % pDevice->bMaxPacketSize0) == 0);
}
USBD_Write(0,
pOtherSpeed,
length,
terminateWithNull ? TerminateCtrlInWithNull : 0,
0);
}
break;
case USBGenericDescriptor_STRING:
TRACE_INFO_WP("Str%d ", indexRDesc);
/* Check if descriptor exists */
if (indexRDesc >= numStrings) {
USBD_Stall(0);
}
else {
pString = pStrings[indexRDesc];
/* Adjust length and send descriptor */
if (length > USBGenericDescriptor_GetLength(pString)) {
length = USBGenericDescriptor_GetLength(pString);
terminateWithNull = ((length % pDevice->bMaxPacketSize0) == 0);
}
USBD_Write(0,
pString,
length,
terminateWithNull ? TerminateCtrlInWithNull : 0,
0);
}
break;
default:
TRACE_WARNING(
"USBDDriver_GetDescriptor: Unknown descriptor type (%d)\n\r",
type);
USBD_Stall(0);
}
}
/**
* Sets the active setting of the given interface if the configuration supports
* it; otherwise, the control pipe is STALLed. If the setting of an interface
* changes.
* \parma pDriver Pointer to a USBDDriver instance.
* \parma infnum Interface number.
* \parma setting New active setting for the interface.
*/
static void SetInterface(
USBDDriver *pDriver,
uint8_t infnum,
uint8_t setting)
{
/* Make sure alternate settings are supported */
if (!pDriver->pInterfaces) {
USBD_Stall(0);
}
else {
/* Change the current setting of the interface and trigger the callback */
/* if necessary */
if (pDriver->pInterfaces[infnum] != setting) {
pDriver->pInterfaces[infnum] = setting;
if (NULL != USBDDriverCallbacks_InterfaceSettingChanged)
USBDDriverCallbacks_InterfaceSettingChanged(infnum, setting);
}
/* Acknowledge the request */
USBD_Write(0, 0, 0, 0, 0);
}
}
/**
* Sends the currently active setting of the given interface to the USB
* host. If alternate settings are not supported, this function STALLs the
* control pipe.
* \param pDriver Pointer to a USBDDriver instance.
* \param infnum Interface number.
*/
static void GetInterface(
const USBDDriver *pDriver,
uint8_t infnum)
{
/* Make sure alternate settings are supported, or STALL the control pipe */
if (!pDriver->pInterfaces) {
USBD_Stall(0);
}
else {
/* Sends the current interface setting to the host */
USBD_Write(0, &(pDriver->pInterfaces[infnum]), 1, 0, 0);
}
}
/**
* Performs the selected test on the USB device (high-speed only).
* \param test Test selector value.
*/
static void USBDDriver_Test(const USBDDriver *pDriver, uint8_t test)
{
pDriver = pDriver;
TRACE_DEBUG("UDPHS_Test\n\r");
/* the lower byte of wIndex must be zero
the most significant byte of wIndex is used to specify the specific test mode */
switch (test) {
case USBFeatureRequest_TESTPACKET:
/*Test mode Test_Packet: */
/*Upon command, a port must repetitively transmit the following test packet until */
/*the exit action is taken. This enables the testing of rise and fall times, eye */
/*patterns, jitter, and any other dynamic waveform specifications. */
/*The test packet is made up by concatenating the following strings. */
/*(Note: For J/K NRZI data, and for NRZ data, the bit on the left is the first one */
/*transmitted. “S?indicates that a bit stuff occurs, which inserts an “extra?NRZI data bit. */
/*? N?is used to indicate N occurrences of a string of bits or symbols.) */
/*A port in Test_Packet mode must send this packet repetitively. The inter-packet timing */
/*must be no less than the minimum allowable inter-packet gap as defined in Section 7.1.18 and */
/*no greater than 125 us. */
/* Send ZLP */
USBD_Test(USBFeatureRequest_TESTSENDZLP);
/* Tst PACKET */
USBD_Test(USBFeatureRequest_TESTPACKET);
while (1);
/*break; not reached */
case USBFeatureRequest_TESTJ:
/*Test mode Test_J: */
/*Upon command, a ports transceiver must enter the high-speed J state and remain in that */
/*state until the exit action is taken. This enables the testing of the high output drive */
/*level on the D+ line. */
/* Send ZLP */
USBD_Test(USBFeatureRequest_TESTSENDZLP);
/* Tst J */
USBD_Test(USBFeatureRequest_TESTJ);
while (1);
/*break; not reached */
case USBFeatureRequest_TESTK:
/*Test mode Test_K: */
/*Upon command, a ports transceiver must enter the high-speed K state and remain in */
/*that state until the exit action is taken. This enables the testing of the high output drive */
/*level on the D- line. */
/* Send a ZLP */
USBD_Test(USBFeatureRequest_TESTSENDZLP);
USBD_Test(USBFeatureRequest_TESTK);
while (1);
/*break; not reached */
case USBFeatureRequest_TESTSE0NAK:
/*Test mode Test_SE0_NAK: */
/*Upon command, a ports transceiver must enter the high-speed receive mode */
/*and remain in that mode until the exit action is taken. This enables the testing */
/*of output impedance, low level output voltage, and loading characteristics. */
/*In addition, while in this mode, upstream facing ports (and only upstream facing ports) */
/*must respond to any IN token packet with a NAK handshake (only if the packet CRC is */
/*determined to be correct) within the normal allowed device response time. This enables testing of */
/*the device squelch level circuitry and, additionally, provides a general purpose stimulus/response */
/*test for basic functional testing. */
/* Send a ZLP */
USBD_Test(USBFeatureRequest_TESTSENDZLP);
/* Test SE0_NAK */
USBD_Test(USBFeatureRequest_TESTSE0NAK);
while (1);
/*break; not reached */
default:
USBD_Stall(0);
break;
}
/* The exit action is to power cycle the device. */
/* The device must be disconnected from the host */
}
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
/**
* Return USBDDriver instance pointer for global usage.
*/
USBDDriver *USBD_GetDriver(void)
{
return &usbdDriver;
}
/**
* Initializes a USBDDriver instance with a list of descriptors. If
* interfaces can have multiple alternate settings, an array to store the
* current setting for each interface must be provided.
* \param pDriver Pointer to a USBDDriver instance.
* \param pDescriptors Pointer to a USBDDriverDescriptors instance.
* \param pInterfaces Pointer to an array for storing the current alternate
* setting of each interface (optional).
*/
void USBDDriver_Initialize(
USBDDriver *pDriver,
const USBDDriverDescriptors *pDescriptors,
uint8_t *pInterfaces)
{
pDriver->cfgnum = 0;
pDriver->isRemoteWakeUpEnabled = 0;
pDriver->pDescriptors = pDescriptors;
pDriver->pInterfaces = pInterfaces;
/* Initialize interfaces array if not null */
if (pInterfaces != 0) {
memset(pInterfaces, sizeof(pInterfaces), 0);
}
}
/**
* Returns configuration descriptor list.
* \param pDriver Pointer to a USBDDriver instance.
* \param cfgNum Reserved.
*/
USBConfigurationDescriptor *USBDDriver_GetCfgDescriptors(
USBDDriver *pDriver, uint8_t cfgNum)
{
USBDDriverDescriptors *pDescList = (USBDDriverDescriptors *)pDriver->pDescriptors;
USBConfigurationDescriptor *pCfg;
cfgNum = cfgNum;
if (USBD_HAL_IsHighSpeed() && pDescList->pHsConfiguration)
pCfg = (USBConfigurationDescriptor *)pDescList->pHsConfiguration;
else
pCfg = (USBConfigurationDescriptor *)pDescList->pFsConfiguration;
return pCfg;
}
/**
* Handles the given request if it is standard, otherwise STALLs it.
* \param pDriver Pointer to a USBDDriver instance.
* \param pRequest Pointer to a USBGenericRequest instance.
*/
void USBDDriver_RequestHandler(
USBDDriver *pDriver,
const USBGenericRequest *pRequest)
{
uint8_t cfgnum;
uint8_t infnum;
uint8_t eptnum;
uint8_t setting;
uint8_t type;
uint8_t indexDesc;
uint32_t length;
uint32_t address;
TRACE_INFO_WP("Std ");
/* Check request code */
switch (USBGenericRequest_GetRequest(pRequest)) {
case USBGenericRequest_GETDESCRIPTOR:
TRACE_INFO_WP("gDesc ");
/* Send the requested descriptor */
type = USBGetDescriptorRequest_GetDescriptorType(pRequest);
indexDesc = USBGetDescriptorRequest_GetDescriptorIndex(pRequest);
length = USBGenericRequest_GetLength(pRequest);
GetDescriptor(pDriver, type, indexDesc, length);
break;
case USBGenericRequest_SETADDRESS:
TRACE_INFO_WP("sAddr ");
/* Sends a zero-length packet and then set the device address */
address = USBSetAddressRequest_GetAddress(pRequest);
USBD_Write(0, 0, 0, (TransferCallback) USBD_SetAddress, (void *) address);
break;
case USBGenericRequest_SETCONFIGURATION:
TRACE_INFO_WP("sCfg ");
/* Set the requested configuration */
cfgnum = USBSetConfigurationRequest_GetConfiguration(pRequest);
SetConfiguration(pDriver, cfgnum);
break;
case USBGenericRequest_GETCONFIGURATION:
TRACE_INFO_WP("gCfg ");
/* Send the current configuration number */
GetConfiguration(pDriver);
break;
case USBGenericRequest_GETSTATUS:
TRACE_INFO_WP("gSta ");
/* Check who is the recipient */
switch (USBGenericRequest_GetRecipient(pRequest)) {
case USBGenericRequest_DEVICE:
TRACE_INFO_WP("Dev ");
/* Send the device status */
GetDeviceStatus(pDriver);
break;
case USBGenericRequest_ENDPOINT:
TRACE_INFO_WP("Ept ");
/* Send the endpoint status */
eptnum = USBGenericRequest_GetEndpointNumber(pRequest);
GetEndpointStatus(eptnum);
break;
default:
TRACE_WARNING(
"USBDDriver_RequestHandler: Unknown recipient (%d)\n\r",
USBGenericRequest_GetRecipient(pRequest));
USBD_Stall(0);
}
break;
case USBGenericRequest_CLEARFEATURE:
TRACE_INFO_WP("cFeat ");
/* Check which is the requested feature */
switch (USBFeatureRequest_GetFeatureSelector(pRequest)) {
case USBFeatureRequest_ENDPOINTHALT:
TRACE_INFO_WP("Hlt ");
/* Unhalt endpoint and send a zero-length packet */
USBD_Unhalt(USBGenericRequest_GetEndpointNumber(pRequest));
USBD_Write(0, 0, 0, 0, 0);
break;
case USBFeatureRequest_DEVICEREMOTEWAKEUP:
TRACE_INFO_WP("RmWU ");
/* Disable remote wake-up and send a zero-length packet */
pDriver->isRemoteWakeUpEnabled = 0;
USBD_Write(0, 0, 0, 0, 0);
break;
default:
TRACE_WARNING(
"USBDDriver_RequestHandler: Unknown feature selector (%d)\n\r",
USBFeatureRequest_GetFeatureSelector(pRequest));
USBD_Stall(0);
}
break;
case USBGenericRequest_SETFEATURE:
TRACE_INFO_WP("sFeat ");
/* Check which is the selected feature */
switch (USBFeatureRequest_GetFeatureSelector(pRequest)) {
case USBFeatureRequest_DEVICEREMOTEWAKEUP:
TRACE_INFO_WP("RmWU ");
/* Enable remote wake-up and send a ZLP */
pDriver->isRemoteWakeUpEnabled = 1;
USBD_Write(0, 0, 0, 0, 0);
break;
case USBFeatureRequest_ENDPOINTHALT:
TRACE_INFO_WP("Halt ");
/* Halt endpoint */
USBD_Halt(USBGenericRequest_GetEndpointNumber(pRequest));
USBD_Write(0, 0, 0, 0, 0);
break;
case USBFeatureRequest_TESTMODE:
/* 7.1.20 Test Mode Support, 9.4.9 Set Feature */
if ((USBGenericRequest_GetRecipient(pRequest) == USBGenericRequest_DEVICE)
&& ((USBGenericRequest_GetIndex(pRequest) & 0x000F) == 0)) {
/* Handle test request */
USBDDriver_Test(pDriver,
USBFeatureRequest_GetTestSelector(pRequest));
}
else {
USBD_Stall(0);
}
break;
#if 0
case USBFeatureRequest_OTG_B_HNP_ENABLE:
TRACE_INFO_WP("OTG_B_HNP_ENABLE ");
pDriver->otg_features_supported |=
1<<USBFeatureRequest_OTG_B_HNP_ENABLE;
USBD_Write(0, 0, 0, 0, 0);
break;
case USBFeatureRequest_OTG_A_HNP_SUPPORT:
TRACE_INFO_WP("OTG_A_HNP_SUPPORT ");
pDriver->otg_features_supported |=
1<<USBFeatureRequest_OTG_A_HNP_SUPPORT;
USBD_Write(0, 0, 0, 0, 0);
break;
case USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT:
TRACE_INFO_WP("OTG_A_ALT_HNP_SUPPORT ");
pDriver->otg_features_supported |=
1<<USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT;
USBD_Write(0, 0, 0, 0, 0);
break;
#endif
default:
TRACE_WARNING(
"USBDDriver_RequestHandler: Unknown feature selector (%d)\n\r",
USBFeatureRequest_GetFeatureSelector(pRequest));
USBD_Stall(0);
}
break;
case USBGenericRequest_SETINTERFACE:
TRACE_INFO_WP("sInterface ");
infnum = USBInterfaceRequest_GetInterface(pRequest);
setting = USBInterfaceRequest_GetAlternateSetting(pRequest);
SetInterface(pDriver, infnum, setting);
break;
case USBGenericRequest_GETINTERFACE:
TRACE_INFO_WP("gInterface ");
infnum = USBInterfaceRequest_GetInterface(pRequest);
GetInterface(pDriver, infnum);
break;
default:
TRACE_WARNING(
"USBDDriver_RequestHandler: Unknown request code (%d)\n\r",
USBGenericRequest_GetRequest(pRequest));
USBD_Stall(0);
}
}
/**
* Test if RemoteWakeUP feature is enabled
* \param pDriver Pointer to an USBDDriver instance.
* \return 1 if remote wake up has been enabled by the host; otherwise, returns
* 0
*/
uint8_t USBDDriver_IsRemoteWakeUpEnabled(const USBDDriver *pDriver)
{
return pDriver->isRemoteWakeUpEnabled;
}
/**
* Return OTG features supported
* \param pDriver Pointer to an USBDDriver instance.
* \return the OTG features
*/
uint8_t USBDDriver_returnOTGFeatures(const USBDDriver *pDriver)
{
return pDriver->otg_features_supported;
}
/**
* Clear OTG features supported
* \param pDriver Pointer to an USBDDriver instance.
* \return none
*/
void USBDDriver_clearOTGFeatures(USBDDriver *pDriver)
{
pDriver->otg_features_supported = 0;
}
/**@}*/

View File

@ -0,0 +1,84 @@
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------
*/
/** \file
*
* \section Purpose
*
* Definition of several callbacks which are triggered by the USB software
* driver after receiving specific requests.
*
* \section Usage
*
* -# Re-implement the USBDDriverCallbacks_ConfigurationChanged
* callback to know when the hosts changes the active configuration of
* the device.
* -# Re-implement the USBDDriverCallbacks_InterfaceSettingChanged
* callback to get notified whenever the active setting of an interface
* is changed by the host.
*
* \addtogroup usbd_interface
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include "USBDDriver.h"
#include <USBLib_Trace.h>
/*------------------------------------------------------------------------------
* Global functions
*------------------------------------------------------------------------------*/
/**
* Indicates that the current configuration of the device has changed.
* \param cfgnum New device configuration index.
*/
WEAK void USBDDriverCallbacks_ConfigurationChanged(uint8_t cfgnum)
{
cfgnum = cfgnum;
TRACE_INFO_WP("cfgChanged%d ", cfgnum);
}
/**
* Notifies of a change in the currently active setting of an interface.
* \param interface Number of the interface whose setting has changed.
* \param setting New interface setting.
*/
WEAK void USBDDriverCallbacks_InterfaceSettingChanged(
uint8_t interface,
uint8_t setting)
{
interface = interface; setting = setting;
TRACE_INFO_WP("ifSettingChanged%d.%d ", interface, setting);
}
/**@}*/

View File

@ -0,0 +1,307 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, 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.
* ----------------------------------------------------------------------------
*/
/**
* \file
*
* \section Purpose
*
* Definitions and methods for USB composite device implement.
*
*/
#ifndef CDCAUDDDRIVER_H
#define CDCAUDDDRIVER_H
/** \addtogroup usbd_composite_cdcaud
*@{
*/
/*---------------------------------------------------------------------------
* Headers
*---------------------------------------------------------------------------*/
#include <USBRequests.h>
#include <CDCDescriptors.h>
#include <AUDDescriptors.h>
#include "USBD.h"
#include <USBDDriver.h>
/*---------------------------------------------------------------------------
* Definitions
*---------------------------------------------------------------------------*/
/** \addtogroup usbd_cdc_aud_desc USB CDC(Serial) + AUD(Speaker) Definitions
* @{
*/
/** Number of interfaces of the device (5, can be 4 if no mic support */
#define CDCAUDDDriverDescriptors_MaxNumInterfaces 5
/** Number of the CDC interface. */
#define CDCAUDDDriverDescriptors_CDC_INTERFACE 0
/** Number of the Audio interface. */
#define CDCAUDDDriverDescriptors_AUD_INTERFACE 2
/** Number of Audio function channels (M,L,R) */
#define AUDD_NumChannels 3
/** @}*/
/*---------------------------------------------------------------------------
* Types
*---------------------------------------------------------------------------*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/** Audio header descriptor with 1 interface */
typedef struct _AUDHeaderDescriptor1{
/** Header descriptor.*/
AUDHeaderDescriptor header;
/** Id of the first grouped interface.*/
uint8_t bInterface0;
} __attribute__ ((__packed__)) AUDHeaderDescriptor1;
/** Audio header descriptor with 2 interface */
typedef struct _AUDHeaderDescriptor2 {
/** Header descriptor. */
AUDHeaderDescriptor header;
/** Id of the first grouped interface - Speaker. */
uint8_t bInterface0;
/** Id of the second grouped interface - Speakerphone. */
uint8_t bInterface1;
} __attribute__ ((__packed__)) AUDHeaderDescriptor2; /* GCC */
/**
* Feature unit descriptor with 3 channel controls (master, right, left).
*/
typedef struct _AUDFeatureUnitDescriptor3{
/** Feature unit descriptor.*/
AUDFeatureUnitDescriptor feature;
/** Available controls for each channel.*/
uint8_t bmaControls[AUDD_NumChannels];
/** Index of a string descriptor for the feature unit.*/
uint8_t iFeature;
} __attribute__ ((__packed__)) AUDFeatureUnitDescriptor3;
/**
* List of descriptors for detailling the audio control interface of a
* device using a USB audio speaker function.
*/
typedef struct _AUDDSpeakerAcDescriptors{
/** Header descriptor (with one slave interface).*/
AUDHeaderDescriptor1 header;
/** Input terminal descriptor.*/
AUDInputTerminalDescriptor input;
/** Output terminal descriptor.*/
AUDOutputTerminalDescriptor output;
/** Feature unit descriptor.*/
AUDFeatureUnitDescriptor3 feature;
} __attribute__ ((__packed__)) AUDDSpeakerAcDescriptors;
/**
* List of descriptors for detailling the audio control interface of a
* device using a USB Audio Speakerphoneer function.
*/
typedef struct _AUDDSpeakerPhoneAcDescriptors {
/** Header descriptor (with one slave interface). */
AUDHeaderDescriptor2 header;
/** Input terminal descriptor. */
AUDInputTerminalDescriptor inputSpeakerPhone;
/** Output terminal descriptor. */
AUDOutputTerminalDescriptor outputSpeakerPhone;
/** Feature unit descriptor - SpeakerPhone. */
AUDFeatureUnitDescriptor3 featureSpeakerPhone;
/** Input terminal descriptor. */
AUDInputTerminalDescriptor inputRec;
/** Output terminal descriptor. */
AUDOutputTerminalDescriptor outputRec;
/** Feature unit descriptor - SpeakerPhonephone. */
AUDFeatureUnitDescriptor3 featureRec;
} __attribute__ ((__packed__)) AUDDSpeakerPhoneAcDescriptors;
/**
* Format type I descriptor with one discrete sampling frequency.
*/
typedef struct _AUDFormatTypeOneDescriptor1{
/** Format type I descriptor.*/
AUDFormatTypeOneDescriptor formatType;
/** Sampling frequency in Hz.*/
uint8_t tSamFreq[3];
} __attribute__ ((__packed__)) AUDFormatTypeOneDescriptor1;
/**
* Configuration descriptor list for a device implementing
* CDC(Serial) + Audio(Speaker) composite driver.
*/
typedef struct _CdcAudspkdDriverConfigurationDescriptors {
/** Standard configuration descriptor. */
USBConfigurationDescriptor configuration;
/* --- CDC 0 */
/** IAD 0 */
USBInterfaceAssociationDescriptor cdcIAD0;
/** Communication interface descriptor */
USBInterfaceDescriptor cdcCommunication0;
/** CDC header functional descriptor. */
CDCHeaderDescriptor cdcHeader0;
/** CDC call management functional descriptor. */
CDCCallManagementDescriptor cdcCallManagement0;
/** CDC abstract control management functional descriptor. */
CDCAbstractControlManagementDescriptor cdcAbstractControlManagement0;
/** CDC union functional descriptor (with one slave interface). */
CDCUnionDescriptor cdcUnion0;
/** Notification endpoint descriptor. */
USBEndpointDescriptor cdcNotification0;
/** Data interface descriptor. */
USBInterfaceDescriptor cdcData0;
/** Data OUT endpoint descriptor. */
USBEndpointDescriptor cdcDataOut0;
/** Data IN endpoint descriptor. */
USBEndpointDescriptor cdcDataIn0;
/* --- AUDIO (AC) */
/** IAD 1*/
USBInterfaceAssociationDescriptor audIAD;
/** Audio control interface.*/
USBInterfaceDescriptor audInterface;
/** Descriptors for the audio control interface.*/
AUDDSpeakerAcDescriptors audControl;
/* -- AUDIO out (AS) */
/** Streaming out interface descriptor (with no endpoint, required).*/
USBInterfaceDescriptor audStreamingOutNoIsochronous;
/** Streaming out interface descriptor.*/
USBInterfaceDescriptor audStreamingOut;
/** Audio class descriptor for the streaming out interface.*/
AUDStreamingInterfaceDescriptor audStreamingOutClass;
/** Stream format descriptor.*/
AUDFormatTypeOneDescriptor1 audStreamingOutFormatType;
/** Streaming out endpoint descriptor.*/
AUDEndpointDescriptor audStreamingOutEndpoint;
/** Audio class descriptor for the streaming out endpoint.*/
AUDDataEndpointDescriptor audStreamingOutDataEndpoint;
} __attribute__ ((__packed__)) CdcAudspkdDriverConfigurationDescriptors;
/**
* Configuration descriptor list for a device implementing
* CDC(Serial) + Audio(SpeakerPhone) composite driver.
*/
typedef struct _CdcAuddDriverConfigurationDescriptors {
/** Standard configuration descriptor. */
USBConfigurationDescriptor configuration;
/* --- CDC 0 */
/** IAD 0 */
USBInterfaceAssociationDescriptor cdcIAD0;
/** Communication interface descriptor */
USBInterfaceDescriptor cdcCommunication0;
/** CDC header functional descriptor. */
CDCHeaderDescriptor cdcHeader0;
/** CDC call management functional descriptor. */
CDCCallManagementDescriptor cdcCallManagement0;
/** CDC abstract control management functional descriptor. */
CDCAbstractControlManagementDescriptor cdcAbstractControlManagement0;
/** CDC union functional descriptor (with one slave interface). */
CDCUnionDescriptor cdcUnion0;
/** Notification endpoint descriptor. */
USBEndpointDescriptor cdcNotification0;
/** Data interface descriptor. */
USBInterfaceDescriptor cdcData0;
/** Data OUT endpoint descriptor. */
USBEndpointDescriptor cdcDataOut0;
/** Data IN endpoint descriptor. */
USBEndpointDescriptor cdcDataIn0;
/* --- AUDIO (AC) */
/** IAD 1*/
USBInterfaceAssociationDescriptor audIAD;
/** Audio control interface.*/
USBInterfaceDescriptor audInterface;
/** Descriptors for the audio control interface.*/
AUDDSpeakerPhoneAcDescriptors audControl;
/* -- AUDIO out (AS) */
/** Streaming out interface descriptor (with no endpoint, required).*/
USBInterfaceDescriptor audStreamingOutNoIsochronous;
/** Streaming out interface descriptor.*/
USBInterfaceDescriptor audStreamingOut;
/** Audio class descriptor for the streaming out interface.*/
AUDStreamingInterfaceDescriptor audStreamingOutClass;
/** Stream format descriptor.*/
AUDFormatTypeOneDescriptor1 audStreamingOutFormatType;
/** Streaming out endpoint descriptor.*/
AUDEndpointDescriptor audStreamingOutEndpoint;
/** Audio class descriptor for the streaming out endpoint.*/
AUDDataEndpointDescriptor audStreamingOutDataEndpoint;
/*- AUDIO IN */
/** Streaming in interface descriptor (with no endpoint, required). */
USBInterfaceDescriptor streamingInNoIsochronous;
/** Streaming in interface descriptor. */
USBInterfaceDescriptor streamingIn;
/** Audio class descriptor for the streaming in interface. */
AUDStreamingInterfaceDescriptor streamingInClass;
/** Stream format descriptor. */
AUDFormatTypeOneDescriptor1 streamingInFormatType;
/** Streaming in endpoint descriptor. */
AUDEndpointDescriptor streamingInEndpoint;
/** Audio class descriptor for the streaming in endpoint. */
AUDDataEndpointDescriptor streamingInDataEndpoint;
} __attribute__ ((__packed__)) CdcAuddDriverConfigurationDescriptors;
#pragma pack()
/*---------------------------------------------------------------------------
* Exported functions
*---------------------------------------------------------------------------*/
extern void CDCAUDDDriver_Initialize(const USBDDriverDescriptors * pDescriptors);
extern void CDCAUDDDriver_ConfigurationChangedHandler(uint8_t cfgnum);
extern void CDCAUDDDriver_InterfaceSettingChangedHandler(
uint8_t interface, uint8_t setting);
extern void CDCAUDDDriver_RequestHandler(const USBGenericRequest *request);
/**@}*/
#endif //#ifndef CDCHIDDDRIVER_H

View File

@ -0,0 +1,106 @@
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------
*/
/**
* \file
*
* Single CDC Serial Port Function for USB device & composite driver.
*/
#ifndef CDCDSERIAL_H
#define CDCDSERIAL_H
/** \addtogroup usbd_cdc
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
/* These headers were introduced in C99
by working group ISO/IEC JTC1/SC22/WG14. */
#include <stdint.h>
#include <USBRequests.h>
#include <USBDDriver.h>
#include <CDCDSerialPort.h>
/*------------------------------------------------------------------------------
* Definitions
*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
* Types
*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
extern void CDCDSerial_Initialize(
USBDDriver * pUsbd, uint8_t bInterfaceNb);
extern uint32_t CDCDSerial_RequestHandler(
const USBGenericRequest *request);
extern void CDCDSerial_ConfigureFunction(
USBGenericDescriptor * pDescriptors, uint16_t wLength);
extern uint32_t CDCDSerial_Write(
void *data,
uint32_t size,
TransferCallback callback,
void *argument);
extern uint32_t CDCDSerial_Read(
void *data,
uint32_t size,
TransferCallback callback,
void *argument);
extern void CDCDSerial_GetLineCoding(CDCLineCoding * pLineCoding);
extern uint8_t CDCDSerial_GetControlLineState(void);
extern uint16_t CDCDSerial_GetSerialState(void);
extern void CDCDSerial_SetSerialState(uint16_t serialState);
extern uint8_t CDCDSerial_LineCodingIsToChange(
CDCLineCoding * pLineCoding);
extern void CDCDSerial_ControlLineStateChanged(
uint8_t DTR,uint8_t RTS);
/**@}*/
#endif /*#ifndef CDCSERIAL_H*/

View File

@ -0,0 +1,249 @@
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------
*/
/**
* \file
*
* \section Purpose
*
* Definition of a class for implementing a USB device CDC serial driver.
*
* \section Usage
*
* -# Re-implement the USBDCallbacks_RequestReceived method to pass
* received requests to CDCDSerialDriver_RequestHandler. *This is
* automatically done unless the NOAUTOCALLBACK symbol is defined*.
* -# Initialize the CDC serial and USB drivers using
* CDCDSerialDriver_Initialize.
* -# Logically connect the device to the host using USBD_Connect.
* -# Send serial data to the USB host using CDCDSerialDriver_Write.
* -# Receive serial data from the USB host using CDCDSerialDriver_Read.
*/
#ifndef CDCDSERIALDRIVER_H
#define CDCDSERIALDRIVER_H
/** \addtogroup usbd_cdc
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
/* These headers were introduced in C99
by working group ISO/IEC JTC1/SC22/WG14. */
#include <stdint.h>
#include <USBRequests.h>
#include <CDCRequests.h>
#include <CDCDescriptors.h>
#include <CDCNotifications.h>
#include <CDCDSerial.h>
/*------------------------------------------------------------------------------
* Definitions
*------------------------------------------------------------------------------*/
/** \addtogroup usbd_cdc_if USB Device CDC Serial Interface IDs
* @{
*/
/** Communication Class Interface ID */
#define CDCDSerialDriver_CC_INTERFACE 0
/** Data Class Interface ID */
#define CDCDSerialDriver_DC_INTERFACE 1
/** @}*/
/*------------------------------------------------------------------------------
* Types
*------------------------------------------------------------------------------*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/**
* \typedef CDCDSerialDriverConfigurationDescriptors
* \brief Configuration descriptor list for a device implementing a
* CDC serial driver.
*/
typedef struct _CDCDSerialDriverConfigurationDescriptors {
/** Standard configuration descriptor. */
USBConfigurationDescriptor configuration;
/** Communication interface descriptor. */
USBInterfaceDescriptor communication;
/** CDC header functional descriptor. */
CDCHeaderDescriptor header;
/** CDC call management functional descriptor. */
CDCCallManagementDescriptor callManagement;
/** CDC abstract control management functional descriptor. */
CDCAbstractControlManagementDescriptor abstractControlManagement;
/** CDC union functional descriptor (with one slave interface). */
CDCUnionDescriptor union1;
/** Notification endpoint descriptor. */
USBEndpointDescriptor notification;
/** Data interface descriptor. */
USBInterfaceDescriptor data;
/** Data OUT endpoint descriptor. */
USBEndpointDescriptor dataOut;
/** Data IN endpoint descriptor. */
USBEndpointDescriptor dataIn;
} __attribute__ ((__packed__)) CDCDSerialDriverConfigurationDescriptors;
/**
* \typedef CDCDSerialDriverConfigurationDescriptorsOTG
* \brief Configuration descriptor list for a device implementing a
* CDC serial OTG driver.
*/
typedef struct _CDCDSerialDriverConfigurationDescriptorsOTG {
/** Standard configuration descriptor. */
USBConfigurationDescriptor configuration;
/* OTG descriptor */
USBOtgDescriptor otgDescriptor;
/** Communication interface descriptor. */
USBInterfaceDescriptor communication;
/** CDC header functional descriptor. */
CDCHeaderDescriptor header;
/** CDC call management functional descriptor. */
CDCCallManagementDescriptor callManagement;
/** CDC abstract control management functional descriptor. */
CDCAbstractControlManagementDescriptor abstractControlManagement;
/** CDC union functional descriptor (with one slave interface). */
CDCUnionDescriptor union1;
/** Notification endpoint descriptor. */
USBEndpointDescriptor notification;
/** Data interface descriptor. */
USBInterfaceDescriptor data;
/** Data OUT endpoint descriptor. */
USBEndpointDescriptor dataOut;
/** Data IN endpoint descriptor. */
USBEndpointDescriptor dataIn;
} __attribute__ ((__packed__)) CDCDSerialDriverConfigurationDescriptorsOTG;
#pragma pack()
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
extern void CDCDSerialDriver_Initialize(
const USBDDriverDescriptors *pDescriptors);
extern void CDCDSerialDriver_ConfigurationChangedHandler(uint8_t cfgnum);
extern void CDCDSerialDriver_RequestHandler(
const USBGenericRequest *request);
/**
* Sends a data buffer through the virtual COM port created by the CDC
* device serial driver. This function behaves exactly like USBD_Write.
* \param data Pointer to the data buffer to send.
* \param size Size of the data buffer in bytes.
* \param callback Optional callback function to invoke when the transfer
* finishes.
* \param argument Optional argument to the callback function.
* \return USBD_STATUS_SUCCESS if the read operation has been started normally;
* otherwise, the corresponding error code.
*/
static inline uint32_t CDCDSerialDriver_Write(
void *data,
uint32_t size,
TransferCallback callback,
void *argument)
{
return CDCDSerial_Write(data, size, callback, argument);
}
/**
* Receives data from the host through the virtual COM port created by
* the CDC device serial driver. This function behaves like USBD_Read.
* \param data Pointer to the data buffer to put received data.
* \param size Size of the data buffer in bytes.
* \param callback Optional callback function to invoke when the transfer
* finishes.
* \param argument Optional argument to the callback function.
* \return USBD_STATUS_SUCCESS if the read operation has been started normally;
* otherwise, the corresponding error code.
*/
static inline uint32_t CDCDSerialDriver_Read(
void *data,
uint32_t size,
TransferCallback callback,
void *argument)
{
return CDCDSerial_Read(data, size, callback, argument);
}
/**
* Copy current line coding settings to pointered space.
* \param pLineCoding Pointer to CDCLineCoding instance.
*/
static inline void CDCDSerialDriver_GetLineCoding(CDCLineCoding * pLineCoding)
{
CDCDSerial_GetLineCoding(pLineCoding);
}
/**
* Returns the current control line state of the RS-232 line.
*/
static inline uint8_t CDCDSerialDriver_GetControlLineState(void)
{
return CDCDSerial_GetControlLineState();
}
/**
* Returns the current status of the RS-232 line.
*/
static inline uint16_t CDCDSerialDriver_GetSerialState(void)
{
return CDCDSerial_GetSerialState();
}
/**
* Sets the current serial state of the device to the given value.
* \param serialState New device state.
*/
static inline void CDCDSerialDriver_SetSerialState(uint16_t serialState)
{
CDCDSerial_SetSerialState(serialState);
}
/**@}*/
#endif /*#ifndef CDCSERIALDRIVER_H*/

View File

@ -0,0 +1,167 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, 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.
* ----------------------------------------------------------------------------
*/
/** \file
* Definition of a class for implementing a USB device
* CDC serial port function.
*/
#ifndef _CDCDSERIALPORT_H_
#define _CDCDSERIALPORT_H_
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
/* These headers were introduced in C99
by working group ISO/IEC JTC1/SC22/WG14. */
#include <stdint.h>
#include <USBRequests.h>
#include <CDCRequests.h>
#include <CDCNotifications.h>
#include "USBD.h"
#include <USBDDriver.h>
/** \addtogroup usbd_cdc
*@{
*/
/*------------------------------------------------------------------------------
* Defines
*------------------------------------------------------------------------------*/
/** \addtogroup usbd_cdc_serial_desc USB Device Serial Port Descriptor Values
* @{
*/
/** Default CDC interrupt endpoints max packat size (8). */
#define CDCDSerialPort_INTERRUPT_MAXPACKETSIZE 8
/** Default CDC interrupt endpoint polling rate of High Speed (16ms). */
#define CDCDSerialPort_INTERRUPT_INTERVAL_HS 8
/** Default CDC interrupt endpoint polling rate of Full Speed (16ms). */
#define CDCDSerialPort_INTERRUPT_INTERVAL_FS 16
/** Default CDC bulk endpoints max packat size (512, for HS actually). */
#define CDCDSerialPort_BULK_MAXPACKETSIZE_HS 512
/** Default CDC bulk endpoints max packat size (64, for FS actually). */
#define CDCDSerialPort_BULK_MAXPACKETSIZE_FS 64
/** @}*/
/** \addtogroup usbd_cdc_serial_events USB Device Serial Port Events
* @{
*/
/** SetControlLineState event, value is changed */
#define CDCDSerialPortEvent_SETCONTROLLINESTATE 0
/** SetLineCoding event, value is to changed according to return value */
#define CDCDSerialPortEvent_SETLINECODING 1
/** @}*/
/*------------------------------------------------------------------------------
* Types
*------------------------------------------------------------------------------*/
/** Callback function for serial port events */
typedef uint32_t (*CDCDSerialPortEventHandler)(uint32_t dwEvent,
uint32_t dwParam,
void * pArguments);
/**
* Struct for USB CDC virtual COM serial port function.
*/
typedef struct _CDCDSerialPort {
/** USB Driver for the %device */
USBDDriver *pUsbd;
/** Callback for serial port events */
CDCDSerialPortEventHandler fEventHandler;
/** Callback arguments */
void *pArg;
/** USB starting interface index */
uint8_t bInterfaceNdx;
/** USB number of interfaces */
uint8_t bNumInterface;
/** USB interrupt IN endpoint address */
uint8_t bIntInPIPE;
/** USB bulk IN endpoint address */
uint8_t bBulkInPIPE;
/** USB bulk OUT endpoint address */
uint8_t bBulkOutPIPE;
/** Serial port ControlLineState */
uint8_t bControlLineState;
/** Serial port SerialState */
uint16_t wSerialState;
/** Serial port linecoding */
CDCLineCoding lineCoding;
uint8_t bReserved;
} CDCDSerialPort;
/*------------------------------------------------------------------------------
* Functions
*------------------------------------------------------------------------------*/
extern void CDCDSerialPort_Initialize(CDCDSerialPort *pCdcd,
USBDDriver *pUsbd,
CDCDSerialPortEventHandler fCallback,
void *pArg,
uint8_t firstInterface,
uint8_t numInterface);
extern USBGenericDescriptor * CDCDSerialPort_ParseInterfaces(
CDCDSerialPort * pCdcd,
USBGenericDescriptor * pDescriptors, uint32_t dwLength);
extern uint32_t CDCDSerialPort_RequestHandler(
CDCDSerialPort *pCdcd,
const USBGenericRequest *pRequest);
extern uint32_t CDCDSerialPort_Write(
const CDCDSerialPort *pCdcd,
void *pData, uint32_t dwSize,
TransferCallback fCallback, void* pArg);
extern uint32_t CDCDSerialPort_Read(
const CDCDSerialPort *pCdcd,
void *pData, uint32_t dwSize,
TransferCallback fCallback, void* pArg);
extern uint16_t CDCDSerialPort_GetSerialState(
const CDCDSerialPort *pCdcd);
extern void CDCDSerialPort_SetSerialState(
CDCDSerialPort *pCdcd,
uint16_t wSerialState);
extern uint8_t CDCDSerialPort_GetControlLineState(
const CDCDSerialPort * pCdcd);
extern void CDCDSerialPort_GetLineCoding(
const CDCDSerialPort * pCdcd,
CDCLineCoding * pLineCoding);
/**@}*/
#endif /* #ifndef _CDCDSERIALPORT_H_ */

View File

@ -0,0 +1,275 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, 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.
* ----------------------------------------------------------------------------
*/
/** \file
*
* Definitions and classes for USB CDC class descriptors.
*/
#ifndef _CDCDESCRIPTORS_H_
#define _CDCDESCRIPTORS_H_
/** \addtogroup usb_cdc
*@{
*/
/*----------------------------------------------------------------------------
* Includes
*----------------------------------------------------------------------------*/
#include <stdint.h>
/*----------------------------------------------------------------------------
* Definitions
*----------------------------------------------------------------------------*/
/** \addtogroup usb_cdc_ver USB CDC Specification Release Numbers
* @{
* This section list the CDC Spec. Release Numbers.
* - \ref CDCGenericDescriptor_CDC1_10
*/
/** Identify CDC specification version 1.10. */
#define CDCGenericDescriptor_CDC1_10 0x0110
/** @}*/
/** \addtogroup usb_cdc_desc_type CDC Descriptro Types
* @{
* This section lists CDC descriptor types.
* - \ref CDCGenericDescriptor_INTERFACE
* - \ref CDCGenericDescriptor_ENDPOINT
*/
/**Indicates that a CDC descriptor applies to an interface. */
#define CDCGenericDescriptor_INTERFACE 0x24
/** Indicates that a CDC descriptor applies to an endpoint. */
#define CDCGenericDescriptor_ENDPOINT 0x25
/** @}*/
/** \addtogroup usb_cdc_desc_subtype CDC Descriptor Subtypes
* @{
* This section lists CDC descriptor sub types
* - \ref CDCGenericDescriptor_HEADER
* - \ref CDCGenericDescriptor_CALLMANAGEMENT
* - \ref CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT
* - \ref CDCGenericDescriptor_UNION
*/
/** Header functional descriptor subtype. */
#define CDCGenericDescriptor_HEADER 0x00
/** Call management functional descriptor subtype. */
#define CDCGenericDescriptor_CALLMANAGEMENT 0x01
/** Abstract control management descriptor subtype. */
#define CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT 0x02
/** Union descriptor subtype. */
#define CDCGenericDescriptor_UNION 0x06
/** @}*/
/** \addtogroup usb_cdc_descriptor USB CDC Device Descriptor Values
* @{
* This section lists the values for CDC Device Descriptor.
* - \ref CDCDeviceDescriptor_CLASS
* - \ref CDCDeviceDescriptor_SUBCLASS
* - \ref CDCDeviceDescriptor_PROTOCOL
*/
/** Device class code when using the CDC class. */
#define CDCDeviceDescriptor_CLASS 0x02
/** Device subclass code when using the CDC class. */
#define CDCDeviceDescriptor_SUBCLASS 0x00
/** Device protocol code when using the CDC class. */
#define CDCDeviceDescriptor_PROTOCOL 0x00
/** @}*/
/** \addtogroup usb_cdc_if_desc USB CDC Communication Interface Descriptor
* @{
* This section lists the values for CDC Communication Interface Descriptor.
* - \ref CDCCommunicationInterfaceDescriptor_CLASS
* - \ref CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL
* - \ref CDCCommunicationInterfaceDescriptor_NOPROTOCOL
*/
/** Interface class code for a CDC communication class interface. */
#define CDCCommunicationInterfaceDescriptor_CLASS 0x02
/** Interface subclass code for an Abstract Control Model interface descriptor.
*/
#define CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL 0x02
/** Interface protocol code when a CDC communication interface does not
implemenent any particular protocol. */
#define CDCCommunicationInterfaceDescriptor_NOPROTOCOL 0x00
/** @}*/
/** \addtogroup usb_cdc_data_if USB CDC Data Interface Values
* @{
* This section lists the values for CDC Data Interface Descriptor.
* - \ref CDCDataInterfaceDescriptor_CLASS
* - \ref CDCDataInterfaceDescriptor_SUBCLASS
* - \ref CDCDataInterfaceDescriptor_NOPROTOCOL
*/
/** Interface class code for a data class interface. */
#define CDCDataInterfaceDescriptor_CLASS 0x0A
/** Interface subclass code for a data class interface. */
#define CDCDataInterfaceDescriptor_SUBCLASS 0x00
/** Protocol code for a data class interface which does not implement any
particular protocol. */
#define CDCDataInterfaceDescriptor_NOPROTOCOL 0x00
/** @}*/
/** \addtogroup usb_cdc_cb_man_desc USB CDC CallManagement Capabilities
* @{
* This section lists CDC CallManagement Capabilities.
* - \ref CDCCallManagementDescriptor_SELFCALLMANAGEMENT
* - \ref CDCCallManagementDescriptor_DATACALLMANAGEMENT
*/
/** Device handles call management itself. */
#define CDCCallManagementDescriptor_SELFCALLMANAGEMENT (1 << 0)
/** Device can exchange call management information over a Data class interface.
*/
#define CDCCallManagementDescriptor_DATACALLMANAGEMENT (1 << 1)
/** @}*/
/** \addtogroup usb_cdc_acm USB CDC ACM Capabilities
* @{
*
* This section lists the capabilities of the CDC ACM.
* - \ref CDCAbstractControlManagementDescriptor_COMMFEATURE
* - \ref CDCAbstractControlManagementDescriptor_LINE
* - \ref CDCAbstractControlManagementDescriptor_SENDBREAK
* - \ref CDCAbstractControlManagementDescriptor_NETWORKCONNECTION
*/
/** Device supports the request combination of SetCommFeature, ClearCommFeature
and GetCommFeature. */
#define CDCAbstractControlManagementDescriptor_COMMFEATURE (1 << 0)
/** Device supports the request combination of SetLineCoding, GetLineCoding and
SetControlLineState. */
#define CDCAbstractControlManagementDescriptor_LINE (1 << 1)
/** Device supports the SendBreak request. */
#define CDCAbstractControlManagementDescriptor_SENDBREAK (1 << 2)
/** Device supports the NetworkConnection notification. */
#define CDCAbstractControlManagementDescriptor_NETWORKCONNECTION (1 << 3)
/** @}*/
/*----------------------------------------------------------------------------
* Types
*----------------------------------------------------------------------------*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/**
* \typedef CDCHeaderDescriptor
* \brief Marks the beginning of the concatenated set of functional descriptors
* for the interface.
*/
typedef struct _CDCHeaderDescriptor {
/** Size of this descriptor in bytes. */
uint8_t bFunctionLength;
/** Descriptor type . */
uint8_t bDescriptorType;
/** Descriptor sub-type . */
uint8_t bDescriptorSubtype;
/** USB CDC specification release number. */
uint16_t bcdCDC;
} __attribute__ ((__packed__)) CDCHeaderDescriptor; /* GCC */
/**
* \typedef CDCUnionDescriptor
* \brief Describes the relationship between a group of interfaces that can
* be considered to form a functional unit.
*/
typedef struct _CDCUnionDescriptor {
/** Size of the descriptor in bytes. */
uint8_t bFunctionLength;
/** Descriptor type . */
uint8_t bDescriptorType;
/** Descriptor subtype . */
uint8_t bDescriptorSubtype;
/** Number of the master interface for this union. */
uint8_t bMasterInterface;
/** Number of the first slave interface for this union. */
uint8_t bSlaveInterface0;
} __attribute__ ((__packed__)) CDCUnionDescriptor; /* GCC */
/**
* \typedef CDCCallManagementDescriptor
* \brief Describes the processing of calls for the communication class
* interface.
*/
typedef struct _CDCCallManagementDescriptor {
/** Size of this descriptor in bytes. */
uint8_t bFunctionLength;
/** Descriptor type . */
uint8_t bDescriptorType;
/** Descriptor sub-type . */
uint8_t bDescriptorSubtype;
/** Configuration capabilities
\sa usb_cdc_cb_man_desc CDC CallManagement Capabilities. */
uint8_t bmCapabilities;
/** Interface number of the data class interface used for call management
(optional). */
uint8_t bDataInterface;
} __attribute__ ((__packed__)) CDCCallManagementDescriptor; /* GCC */
/**
* \typedef CDCAbstractControlManagementDescriptor
* \brief Describes the command supported by the communication interface class
* with the Abstract Control Model subclass code.
*/
typedef struct _CDCAbstractControlManagementDescriptor {
/** Size of this descriptor in bytes. */
uint8_t bFunctionLength;
/** Descriptor type . */
uint8_t bDescriptorType;
/** Descriptor subtype . */
uint8_t bDescriptorSubtype;
/** Configuration capabilities.
\sa usb_cdc_acm CDC ACM Capabilities. */
uint8_t bmCapabilities;
} __attribute__ ((__packed__)) CDCAbstractControlManagementDescriptor; /* GCC */
#pragma pack()
/*----------------------------------------------------------------------------
* Functions
*----------------------------------------------------------------------------*/
/**@}*/
#endif /* #ifndef _CDCDESCRIPTORS_H_ */

View File

@ -0,0 +1,152 @@
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------
*/
/**
* \file
*
* \section Purpose
*
* Definitions and methods for USB composite device implement.
*
* \section Usage
*
* -# Initialize USB function specified driver ( for MSD currently )
* - MSDDFunctionDriver_Initialize()
*
* -# Initialize USB composite driver and USB driver
* - CDCHIDDDriver_Initialize()
*
* -# Handle and dispach USB requests
* - CDCHIDDDriver_RequestHandler()
*
* -# Try starting a remote wake-up sequence
* - CDCHIDDDriver_RemoteWakeUp()
*/
#ifndef CDCHIDDDRIVER_H
#define CDCHIDDDRIVER_H
/** \addtogroup usbd_composite_cdchid
*@{
*/
/*---------------------------------------------------------------------------
* Headers
*---------------------------------------------------------------------------*/
#include <USBRequests.h>
#include <CDCDescriptors.h>
#include <HIDDescriptors.h>
#include "USBD.h"
#include <USBDDriver.h>
/*---------------------------------------------------------------------------
* Definitions
*---------------------------------------------------------------------------*/
/** \addtogroup usbd_cdc_hid_desc USB CDC(Serial) + HID(Kbd) Descriptors define
* @{
*/
/** Number of interfaces of the device */
#define CDCHIDDDriverDescriptors_NUMINTERFACE 3
/** Number of the CDC interface. */
#define CDCHIDDDriverDescriptors_CDC_INTERFACE 0
/** Number of the HID interface. */
#define CDCHIDDDriverDescriptors_HID_INTERFACE 2
/** @}*/
/*---------------------------------------------------------------------------
* Types
*---------------------------------------------------------------------------*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/**
* \typedef CdcHidDriverConfigurationDescriptors
* \brief Configuration descriptor list for a device implementing a
* composite driver.
*/
typedef struct _CdcHidDriverConfigurationDescriptors {
/** Standard configuration descriptor. */
USBConfigurationDescriptor configuration;
/* --- CDC 0 */
/** IAD 0 */
USBInterfaceAssociationDescriptor cdcIAD0;
/** Communication interface descriptor */
USBInterfaceDescriptor cdcCommunication0;
/** CDC header functional descriptor. */
CDCHeaderDescriptor cdcHeader0;
/** CDC call management functional descriptor. */
CDCCallManagementDescriptor cdcCallManagement0;
/** CDC abstract control management functional descriptor. */
CDCAbstractControlManagementDescriptor cdcAbstractControlManagement0;
/** CDC union functional descriptor (with one slave interface). */
CDCUnionDescriptor cdcUnion0;
/** Notification endpoint descriptor. */
USBEndpointDescriptor cdcNotification0;
/** Data interface descriptor. */
USBInterfaceDescriptor cdcData0;
/** Data OUT endpoint descriptor. */
USBEndpointDescriptor cdcDataOut0;
/** Data IN endpoint descriptor. */
USBEndpointDescriptor cdcDataIn0;
/* --- HID */
USBInterfaceDescriptor hidInterface;
HIDDescriptor1 hid;
USBEndpointDescriptor hidInterruptIn;
USBEndpointDescriptor hidInterruptOut;
} __attribute__ ((__packed__)) CdcHidDriverConfigurationDescriptors;
#pragma pack()
/*---------------------------------------------------------------------------
* Exported functions
*---------------------------------------------------------------------------*/
/* -CDCHID */
extern void CDCHIDDDriver_Initialize(
const USBDDriverDescriptors * pDescriptors);
extern void CDCHIDDDriver_ConfigurationChangedHandler(uint8_t cfgnum);
extern void CDCHIDDDriver_RequestHandler(const USBGenericRequest *request);
extern void CDCHIDDDriver_RemoteWakeUp(void);
/**@}*/
#endif //#ifndef CDCHIDDDRIVER_H

View File

@ -0,0 +1,155 @@
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------
*/
/**
* \file
*
* \section Purpose
*
* Definitions and methods for USB CDCMSD device implement.
*
* \section Usage
*
* -# Initialize USB function specified driver ( for MSD currently )
* - MSDDFunctionDriver_Initialize
*
* -# Initialize USB CDCMSD driver and USB driver
* - CDCMSDDDriver_Initialize
*
* -# Handle and dispach USB requests
* - CDCMSDDDriver_RequestHandler
*
* -# Try starting a remote wake-up sequence
* - CDCMSDDDriver_RemoteWakeUp
*/
#ifndef CDCMSDDDRIVER_H
#define CDCMSDDDRIVER_H
/** \addtogroup usbd_composite_cdcmsd
*@{
*/
/*---------------------------------------------------------------------------
* Headers
*---------------------------------------------------------------------------*/
#include <USBRequests.h>
#include <CDCDescriptors.h>
#include <MSDescriptors.h>
#include <MSDLun.h>
#include "USBD.h"
#include <USBDDriver.h>
/*---------------------------------------------------------------------------
* Consts
*---------------------------------------------------------------------------*/
/** \addtogroup usbd_cdc_msd_desc USB CDC(Serial) + MS Descriptors define
* @{
*/
/** Number of interfaces of the device */
#define CDCMSDDriverDescriptors_NUMINTERFACE 3
/** Number of the CDC interface. */
#define CDCMSDDriverDescriptors_CDC_INTERFACE 0
/** Number of the HID interface. */
#define CDCMSDDriverDescriptors_MSD_INTERFACE 2
/** @}*/
/*---------------------------------------------------------------------------
* Types
*---------------------------------------------------------------------------*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/**
* \typedef CDCMSDDriverConfigurationDescriptors
* \brief Configuration descriptor list for a device implementing
* a CDCMSD driver.
*/
typedef struct _CDCMSDDriverConfigurationDescriptors {
/** Standard configuration descriptor. */
USBConfigurationDescriptor configuration;
/* --- CDC 0 */
/** IAD 0 */
USBInterfaceAssociationDescriptor cdcIAD0;
/** Communication interface descriptor */
USBInterfaceDescriptor cdcCommunication0;
/** CDC header functional descriptor. */
CDCHeaderDescriptor cdcHeader0;
/** CDC call management functional descriptor. */
CDCCallManagementDescriptor cdcCallManagement0;
/** CDC abstract control management functional descriptor. */
CDCAbstractControlManagementDescriptor cdcAbstractControlManagement0;
/** CDC union functional descriptor (with one slave interface). */
CDCUnionDescriptor cdcUnion0;
/** Notification endpoint descriptor. */
USBEndpointDescriptor cdcNotification0;
/** Data interface descriptor. */
USBInterfaceDescriptor cdcData0;
/** Data OUT endpoint descriptor. */
USBEndpointDescriptor cdcDataOut0;
/** Data IN endpoint descriptor. */
USBEndpointDescriptor cdcDataIn0;
/* --- MSD */
/** Mass storage interface descriptor. */
USBInterfaceDescriptor msdInterface;
/** Bulk-out endpoint descriptor. */
USBEndpointDescriptor msdBulkOut;
/** Bulk-in endpoint descriptor. */
USBEndpointDescriptor msdBulkIn;
} __attribute__ ((__packed__)) CDCMSDDriverConfigurationDescriptors;
#pragma pack()
/*---------------------------------------------------------------------------
* Exported functions
*---------------------------------------------------------------------------*/
/* -CDCMSD */
extern void CDCMSDDriver_Initialize(
const USBDDriverDescriptors *pDescriptors,
MSDLun *pLuns, unsigned char numLuns);
extern void CDCMSDDriver_ConfigurationChangedHandler(unsigned char cfgnum);
extern void CDCMSDDriver_RequestHandler(const USBGenericRequest *request);
/**@}*/
#endif /* #ifndef CDCMSDDDRIVER_H */

View File

@ -0,0 +1,111 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, 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.
* ----------------------------------------------------------------------------
*/
/** \file
* Definitions and methods for USB CDC Notifications.
*/
#ifndef _CDCNOTIFICATIONS_H_
#define _CDCNOTIFICATIONS_H_
/** \addtogroup usb_cdc
*@{
*/
/*----------------------------------------------------------------------------
* Includes
*----------------------------------------------------------------------------*/
#include <stdint.h>
/*----------------------------------------------------------------------------
* Definitions
*----------------------------------------------------------------------------*/
/** \addtogroup cdc_serial_states CDC SerialState bits
* @{
* This page lists the bit map for CDC Serial States.
*
* - \ref CDCSerialState_RXDRIVER
* - \ref CDCSerialState_TXCARRIER
* - \ref CDCSerialState_BREAK
* - \ref CDCSerialState_RINGSIGNAL
* - \ref CDCSerialState_FRAMING
* - \ref CDCSerialState_PARITY
* - \ref CDCSerialState_OVERRUN
*/
/** Indicates the receiver carrier signal is present */
#define CDCSerialState_RXDRIVER (1 << 0)
/** Indicates the transmission carrier signal is present */
#define CDCSerialState_TXCARRIER (1 << 1)
/** Indicates a break has been detected */
#define CDCSerialState_BREAK (1 << 2)
/** Indicates a ring signal has been detected */
#define CDCSerialState_RINGSIGNAL (1 << 3)
/** Indicates a framing error has occured */
#define CDCSerialState_FRAMING (1 << 4)
/** Indicates a parity error has occured */
#define CDCSerialState_PARITY (1 << 5)
/** Indicates a data overrun error has occured */
#define CDCSerialState_OVERRUN (1 << 6)
/** @}*/
/*----------------------------------------------------------------------------
* Types
*----------------------------------------------------------------------------*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/** USB CDC SerialState struct (bitmap) */
typedef struct _CDCSerialState {
uint16_t bRxCarrier:1, /**< State of receive carrier detection (V2.4 signal
109 and RS-232 signal DCD) */
bTxCarrier:1, /**< State of transmission carrier */
bBreak:1, /**< State of break detection */
bRingSignal:1, /**< State of ring signal */
bFraming:1, /**< Framing error */
bParity:1, /**< Parity error */
bOverRun:1, /**< Received data discarded due to overrun error */
reserved:9; /**< Reserved */
} __attribute__ ((__packed__)) CDCSerialState;
#pragma pack()
/*----------------------------------------------------------------------------
* Functions
*----------------------------------------------------------------------------*/
/**@}*/
#endif /* #ifndef _CDCNOTIFICATIONS_H_ */

View File

@ -0,0 +1,183 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, 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.
* ----------------------------------------------------------------------------
*/
/** \file
*
* Definitions and classes for USB CDC class requests
* (mostly for ACM).
*
* \section CDCLineCoding
*
* -# Initialize a CDCLineCoding instance using CDCLineCoding_Initialize.
* -# Send a CDCLineCoding object to the host in response to a GetLineCoding
* request.
* -# Receive a CDCLineCoding object from the host after a SetLineCoding
* request.
*
*/
#ifndef _CDCREQUESTS_H_
#define _CDCREQUESTS_H_
/** \addtogroup usb_cdc
*@{
*/
/*----------------------------------------------------------------------------
* Includes
*----------------------------------------------------------------------------*/
#include <stdint.h>
#include <USBRequests.h>
/*----------------------------------------------------------------------------
* Definitions
*----------------------------------------------------------------------------*/
/** \addtogroup usb_cdc_request USB CDC Request Codes
* @{
* This section lists USB CDC Request Codes.
* - \ref CDCGenericRequest_SETLINECODING
* - \ref CDCGenericRequest_GETLINECODING
* - \ref CDCGenericRequest_SETCONTROLLINESTATE
*/
/** SetLineCoding request code. */
#define CDCGenericRequest_SETLINECODING 0x20
/** GetLineCoding request code. */
#define CDCGenericRequest_GETLINECODING 0x21
/** SetControlLineState request code. */
#define CDCGenericRequest_SETCONTROLLINESTATE 0x22
/** @}*/
/** \addtogroup usb_cdc_ctrl_line_state USB CDC ControlLineState bitmap
* @{
* This section lists CDC ControlLineState bitmap.
* - \ref CDCControlLineState_DTR, CDCControlLineState_DTE_PRESENT
* - \ref CDCControlLineState_RTS, CDCControlLineState_CARRIER_ON
*/
/** Indicates to DCE if DTE is present or not. */
#define CDCControlLineState_DTE_PRESENT (1 << 0)
/** RS232 signal DTR: Data Terminal Ready. */
#define CDCControlLineState_DTR (1 << 0)
/** Carrier control for half duplex modems. */
#define CDCControlLineState_CARRIER_ON (1 << 1)
/** RS232 signal RTS: Request to send. */
#define CDCControlLineState_RTS (1 << 1)
/** @}*/
/** \addtogroup usb_cdc_stop USB CDC LineCoding StopBits
* @{
* This section lists Stop Bits for CDC Line Coding.
* - \ref CDCLineCoding_ONESTOPBIT
* - \ref CDCLineCoding_ONE5STOPBIT
* - \ref CDCLineCoding_TWOSTOPBITS
*/
/** The transmission protocol uses one stop bit. */
#define CDCLineCoding_ONESTOPBIT 0
/** The transmission protocol uses 1.5 stop bit. */
#define CDCLineCoding_ONE5STOPBIT 1
/** The transmissin protocol uses two stop bits. */
#define CDCLineCoding_TWOSTOPBITS 2
/** @}*/
/** \addtogroup usb_cdc_parity USB CDC LineCoding ParityCheckings
* @{
* This section lists Parity checkings for CDC Line Coding.
* - \ref CDCLineCoding_NOPARITY
* - \ref CDCLineCoding_ODDPARITY
* - \ref CDCLineCoding_EVENPARITY
* - \ref CDCLineCoding_MARKPARITY
* - \ref CDCLineCoding_SPACEPARITY
*/
/** No parity checking. */
#define CDCLineCoding_NOPARITY 0
/** Odd parity checking. */
#define CDCLineCoding_ODDPARITY 1
/** Even parity checking. */
#define CDCLineCoding_EVENPARITY 2
/** Mark parity checking. */
#define CDCLineCoding_MARKPARITY 3
/** Space parity checking. */
#define CDCLineCoding_SPACEPARITY 4
/** @}*/
/*----------------------------------------------------------------------------
* Types
*----------------------------------------------------------------------------*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/**
* \typedef CDCLineCoding
* \brief Format of the data returned when a GetLineCoding request is received.
*/
typedef struct _CDCLineCoding {
/** Data terminal rate in bits per second. */
uint32_t dwDTERate;
/** Number of stop bits.
\sa usb_cdc_stop CDC LineCoding StopBits. */
uint8_t bCharFormat;
/** Type of parity checking used.
\sa usb_cdc_parity CDC LineCoding ParityCheckings. */
uint8_t bParityType;
/** Number of data bits (5, 6, 7, 8 or 16). */
uint8_t bDataBits;
} __attribute__ ((__packed__)) CDCLineCoding; /* GCC */
#pragma pack()
/*----------------------------------------------------------------------------
* Functions
*----------------------------------------------------------------------------*/
extern uint8_t CDCSetControlLineStateRequest_IsDtePresent(
const USBGenericRequest *request);
extern uint8_t CDCSetControlLineStateRequest_ActivateCarrier(
const USBGenericRequest *request);
extern void CDCLineCoding_Initialize(CDCLineCoding *lineCoding,
uint32_t bitrate,
uint8_t stopbits,
uint8_t parity,
uint8_t databits);
/**@}*/
#endif /* #define _CDCREQUESTS_H_ */

View File

@ -0,0 +1,157 @@
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------
*/
/**
* \file
*
* \section Purpose
*
* Definitions and methods for USB composite device implement.
*
*/
#ifndef DUALCDCDDRIVER_H
#define DUALCDCDDRIVER_H
/** \addtogroup usbd_composite_cdccdc
*@{
*/
/*---------------------------------------------------------------------------
* Headers
*---------------------------------------------------------------------------*/
#include <USBRequests.h>
#include <CDCDescriptors.h>
#include "USBD.h"
#include <CDCDSerialPort.h>
/*---------------------------------------------------------------------------
* Defines
*---------------------------------------------------------------------------*/
/** \addtogroup usbd_composite_cdccdc_desc
* The driver uses these interface numbers in configuration descriptor.
* @{
*/
/** Number of interfaces of the device */
#define DUALCDCDDriverDescriptors_NUMINTERFACE 4
/** Number of the CDC0 interface. */
#define DUALCDCDDriverDescriptors_INTERFACENUM0 0
/** Number of the CDC1 interface. */
#define DUALCDCDDriverDescriptors_INTERFACENUM1 2
/** @}*/
/*---------------------------------------------------------------------------
* Types
*---------------------------------------------------------------------------*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/**
* \typedef DualCdcDriverConfigurationDescriptors
* \brief Configuration descriptor list for a device implementing a
* dual CDC serial composite driver.
*/
typedef struct _DualCdcDriverConfigurationDescriptors {
/** Standard configuration descriptor. */
USBConfigurationDescriptor configuration;
/* --- CDC 0 */
/** IAD 0 */
USBInterfaceAssociationDescriptor cdcIAD0;
/** Communication interface descriptor */
USBInterfaceDescriptor cdcCommunication0;
/** CDC header functional descriptor. */
CDCHeaderDescriptor cdcHeader0;
/** CDC call management functional descriptor. */
CDCCallManagementDescriptor cdcCallManagement0;
/** CDC abstract control management functional descriptor. */
CDCAbstractControlManagementDescriptor cdcAbstractControlManagement0;
/** CDC union functional descriptor (with one slave interface). */
CDCUnionDescriptor cdcUnion0;
/** Notification endpoint descriptor. */
USBEndpointDescriptor cdcNotification0;
/** Data interface descriptor. */
USBInterfaceDescriptor cdcData0;
/** Data OUT endpoint descriptor. */
USBEndpointDescriptor cdcDataOut0;
/** Data IN endpoint descriptor. */
USBEndpointDescriptor cdcDataIn0;
/* --- CDC 1 */
/** IAD 1 */
USBInterfaceAssociationDescriptor cdcIAD1;
/** Communication interface descriptor */
USBInterfaceDescriptor cdcCommunication1;
/** CDC header functional descriptor. */
CDCHeaderDescriptor cdcHeader1;
/** CDC call management functional descriptor. */
CDCCallManagementDescriptor cdcCallManagement1;
/** CDC abstract control management functional descriptor. */
CDCAbstractControlManagementDescriptor cdcAbstractControlManagement1;
/** CDC union functional descriptor (with one slave interface). */
CDCUnionDescriptor cdcUnion1;
/** Notification endpoint descriptor. */
USBEndpointDescriptor cdcNotification1;
/** Data interface descriptor. */
USBInterfaceDescriptor cdcData1;
/** Data OUT endpoint descriptor. */
USBEndpointDescriptor cdcDataOut1;
/** Data IN endpoint descriptor. */
USBEndpointDescriptor cdcDataIn1;
} __attribute__ ((__packed__)) DualCdcDriverConfigurationDescriptors;
#pragma pack()
/*---------------------------------------------------------------------------
* Exported functions
*---------------------------------------------------------------------------*/
/* -DUALCDC */
extern void DUALCDCDDriver_Initialize(
const USBDDriverDescriptors* pDescriptors);
extern void DUALCDCDDriver_ConfigurationChangeHandler(uint8_t cfgnum);
extern void DUALCDCDDriver_RequestHandler(const USBGenericRequest *request);
extern CDCDSerialPort* DUALCDCDDriver_GetSerialPort(uint32_t port);
/**@}*/
#endif /* #ifndef DUALCDCDDRIVER_H */

View File

@ -0,0 +1,678 @@
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------
*/
/** \file
* \section Purpose
*
* SCSI definitions.
*
* \section Usage
*
* -# After command block received, Access and decode the SCSI command block
* with SBCCommand structure.
*/
#ifndef SBC_H
#define SBC_H
/** \addtogroup usbd_msd
*@{
*/
/*------------------------------------------------------------------------------
* Definitions
*------------------------------------------------------------------------------*/
/** \addtogroup usbd_sbc_operation_codes SBC Operation Codes
* @{
* This page lists operation codes of commands described in the SBC-3
* standard.
*
* \note That most commands are actually defined in other standards,
* like SPC-4. Optional commands are not included here.
*
* \see sbc3r07.pdf - Section 5.1 - Table 12
* \see spc4r06.pdf
* \see SBCCommand
*
* \section Codes
* - SBC_INQUIRY
* - SBC_READ_10
* - SBC_READ_CAPACITY_10
* - SBC_REQUEST_SENSE
* - SBC_TEST_UNIT_READY
* - SBC_WRITE_10
*
* \section Optional Codes but required by Windows
* - SBC_PREVENT_ALLOW_MEDIUM_REMOVAL
* - SBC_MODE_SENSE_6
* - SBC_VERIFY_10
* - SBC_READ_FORMAT_CAPACITIES
*/
/** Request information regarding parameters of the target and Logical Unit. */
#define SBC_INQUIRY 0x12
/** Request the transfer data to the host. */
#define SBC_READ_10 0x28
/** Request capacities of the currently installed medium. */
#define SBC_READ_CAPACITY_10 0x25
/** Request that the device server transfer sense data. */
#define SBC_REQUEST_SENSE 0x03
/** Check if the LUN is ready */
#define SBC_TEST_UNIT_READY 0x00
/** Request that the device write the data transferred by the host. */
#define SBC_WRITE_10 0x2A
/** Request that the target enable or disable the removal of the medium in */
/** the Logical Unit. */
#define SBC_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1E
/** Report parameters. */
#define SBC_MODE_SENSE_6 0x1A
/** Request that the %device verify the data on the medium. */
#define SBC_VERIFY_10 0x2F
/** Request a list of the possible capacities that can be formatted on medium */
#define SBC_READ_FORMAT_CAPACITIES 0x23
/** @}*/
/** \addtogroup usbd_sbc_periph_quali SBC Periph. Qualifiers
* @{
* This page lists the peripheral qualifier values specified in the INQUIRY
* data
* \see spc4r06.pdf - Section 6.4.2 - Table 83
* \see SBCInquiryData
*
* \section Qualifiers
* - SBC_PERIPHERAL_DEVICE_CONNECTED
* - SBC_PERIPHERAL_DEVICE_NOT_CONNECTED
* - SBC_PERIPHERAL_DEVICE_NOT_SUPPORTED
*/
#define SBC_PERIPHERAL_DEVICE_CONNECTED 0x00
#define SBC_PERIPHERAL_DEVICE_NOT_CONNECTED 0x01
#define SBC_PERIPHERAL_DEVICE_NOT_SUPPORTED 0x03
/** @}*/
/** \addtogroup usbd_sbc_periph_types SBC Periph. Types
* @{
* This page lists peripheral device types specified in the INQUIRY data
* \see spc4r06.pdf - Section 6.4.2 - Table 84
* \see SBCInquiryData
*
* \section Types
* - SBC_DIRECT_ACCESS_BLOCK_DEVICE
* - SBC_SEQUENTIAL_ACCESS_DEVICE
* - SBC_PRINTER_DEVICE
* - SBC_PROCESSOR_DEVICE
* - SBC_WRITE_ONCE_DEVICE
* - SBC_CD_DVD_DEVICE
* - SBC_SCANNER_DEVICE
* - SBC_OPTICAL_MEMORY_DEVICE
* - SBC_MEDIA_CHANGER_DEVICE
* - SBC_COMMUNICATION_DEVICE
* - SBC_STORAGE_ARRAY_CONTROLLER_DEVICE
* - SBC_ENCLOSURE_SERVICES_DEVICE
* - SBC_SIMPLIFIED_DIRECT_ACCESS_DEVICE
* - SBC_OPTICAL_CARD_READER_WRITER_DEVICE
* - SBC_BRIDGE_CONTROLLER_COMMANDS
* - SBC_OBJECT_BASED_STORAGE_DEVICE
*/
#define SBC_DIRECT_ACCESS_BLOCK_DEVICE 0x00
#define SBC_SEQUENTIAL_ACCESS_DEVICE 0x01
#define SBC_PRINTER_DEVICE 0x02
#define SBC_PROCESSOR_DEVICE 0x03
#define SBC_WRITE_ONCE_DEVICE 0x04
#define SBC_CD_DVD_DEVICE 0x05
#define SBC_SCANNER_DEVICE 0x06
#define SBC_OPTICAL_MEMORY_DEVICE 0x07
#define SBC_MEDIA_CHANGER_DEVICE 0x08
#define SBC_COMMUNICATION_DEVICE 0x09
#define SBC_STORAGE_ARRAY_CONTROLLER_DEVICE 0x0C
#define SBC_ENCLOSURE_SERVICES_DEVICE 0x0D
#define SBC_SIMPLIFIED_DIRECT_ACCESS_DEVICE 0x0E
#define SBC_OPTICAL_CARD_READER_WRITER_DEVICE 0x0F
#define SBC_BRIDGE_CONTROLLER_COMMANDS 0x10
#define SBC_OBJECT_BASED_STORAGE_DEVICE 0x11
/** @}*/
/*------------------------------------------------------------------------------ */
/** \brief Version value for the SBC-3 specification */
/** \see spc4r06.pdf - Section 6.4.2 - Table 85 */
#define SBC_SPC_VERSION_4 0x06
/*------------------------------------------------------------------------------ */
/*------------------------------------------------------------------------------ */
/** \brief Values for the TPGS field returned in INQUIRY data */
/** \see spc4r06.pdf - Section 6.4.2 - Table 86 */
#define SBC_TPGS_NONE 0x0
#define SBC_TPGS_ASYMMETRIC 0x1
#define SBC_TPGS_SYMMETRIC 0x2
#define SBC_TPGS_BOTH 0x3
/*------------------------------------------------------------------------------ */
/*------------------------------------------------------------------------------ */
/** \brief Version descriptor value for the SBC-3 specification */
/** \see spc4r06.pdf - Section 6.4.2 - Table 87 */
#define SBC_VERSION_DESCRIPTOR_SBC_3 0x04C0
/*------------------------------------------------------------------------------ */
/** \addtogroup usbd_sbc_secse_codes SBC Sense Response Codes
* @{
* This page lists sense data response codes returned in REQUEST SENSE data
* \see spc4r06.pdf - Section 4.5.1 - Table 12
*
* \section Codes
* - SBC_SENSE_DATA_FIXED_CURRENT
* - SBC_SENSE_DATA_FIXED_DEFERRED
* - SBC_SENSE_DATA_DESCRIPTOR_CURRENT
* - SBC_SENSE_DATA_DESCRIPTOR_DEFERRED
*/
#define SBC_SENSE_DATA_FIXED_CURRENT 0x70
#define SBC_SENSE_DATA_FIXED_DEFERRED 0x71
#define SBC_SENSE_DATA_DESCRIPTOR_CURRENT 0x72
#define SBC_SENSE_DATA_DESCRIPTOR_DEFERRED 0x73
/** @}*/
/** \addtogroup usbd_sbc_sense_keys SBC Sense Keys
* @{
* This page lists sense key values returned in the REQUEST SENSE data
* \see spc4r06.pdf - Section 4.5.6 - Table 27
*
* \section Keys
* - SBC_SENSE_KEY_NO_SENSE
* - SBC_SENSE_KEY_RECOVERED_ERROR
* - SBC_SENSE_KEY_NOT_READY
* - SBC_SENSE_KEY_MEDIUM_ERROR
* - SBC_SENSE_KEY_HARDWARE_ERROR
* - SBC_SENSE_KEY_ILLEGAL_REQUEST
* - SBC_SENSE_KEY_UNIT_ATTENTION
* - SBC_SENSE_KEY_DATA_PROTECT
* - SBC_SENSE_KEY_BLANK_CHECK
* - SBC_SENSE_KEY_VENDOR_SPECIFIC
* - SBC_SENSE_KEY_COPY_ABORTED
* - SBC_SENSE_KEY_ABORTED_COMMAND
* - SBC_SENSE_KEY_VOLUME_OVERFLOW
* - SBC_SENSE_KEY_MISCOMPARE
*/
/** No specific sense key. Successful command. */
#define SBC_SENSE_KEY_NO_SENSE 0x00
/** Command completed succesfully with some recovery action by the %device. */
#define SBC_SENSE_KEY_RECOVERED_ERROR 0x01
/** The device can not be accessed. */
#define SBC_SENSE_KEY_NOT_READY 0x02
/** Command terminated with a error condition that was probably caused by a */
/** flaw in the medium or an error in the recorded data. */
#define SBC_SENSE_KEY_MEDIUM_ERROR 0x03
/** Hardware failure while performing the command or during a self test. */
#define SBC_SENSE_KEY_HARDWARE_ERROR 0x04
/** Illegal parameter found in the command or additional parameters. */
#define SBC_SENSE_KEY_ILLEGAL_REQUEST 0x05
/** Removable medium may have been changed or the %device has been reset. */
#define SBC_SENSE_KEY_UNIT_ATTENTION 0x06
/** Write on a block that is protected. */
#define SBC_SENSE_KEY_DATA_PROTECT 0x07
/** Indicates that a write-once device or a sequential-access device */
/** encountered blank medium or format-defined end-of-data indication while */
/** reading or a write-once device encountered a non-blank medium while writing. */
#define SBC_SENSE_KEY_BLANK_CHECK 0x08
/** Reporting vendor specific conditions. */
#define SBC_SENSE_KEY_VENDOR_SPECIFIC 0x09
/** EXTENDED COPY command was aborted. */
#define SBC_SENSE_KEY_COPY_ABORTED 0x0A
/** Device aborted the command. */
#define SBC_SENSE_KEY_ABORTED_COMMAND 0x0B
/** A buffered peripheral device is overflow. */
#define SBC_SENSE_KEY_VOLUME_OVERFLOW 0x0D
/** The source data did not match the data read from the medium. */
#define SBC_SENSE_KEY_MISCOMPARE 0x0E
/** @}*/
/** \addtogroup usbd_sbc_sense_additionals SBC Sense Additionals
* @{
* This page lists additional sense code values returned in REQUEST SENSE data
* \see spc4r06.pdf - Section 4.5.6 - Table 28
*
* \section Additional Codes
* - SBC_ASC_LOGICAL_UNIT_NOT_READY
* - SBC_ASC_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE
* - SBC_ASC_INVALID_FIELD_IN_CDB
* - SBC_ASC_WRITE_PROTECTED
* - SBC_ASC_FORMAT_CORRUPTED
* - SBC_ASC_INVALID_COMMAND_OPERATION_CODE
* - SBC_ASC_TOO_MUCH_WRITE_DATA
* - SBC_ASC_NOT_READY_TO_READY_CHANGE
* - SBC_ASC_MEDIUM_NOT_PRESENT
*/
#define SBC_ASC_LOGICAL_UNIT_NOT_READY 0x04
#define SBC_ASC_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x21
#define SBC_ASC_INVALID_FIELD_IN_CDB 0x24
#define SBC_ASC_WRITE_PROTECTED 0x27
#define SBC_ASC_FORMAT_CORRUPTED 0x31
#define SBC_ASC_INVALID_COMMAND_OPERATION_CODE 0x20
#define SBC_ASC_TOO_MUCH_WRITE_DATA 0x26
#define SBC_ASC_NOT_READY_TO_READY_CHANGE 0x28
#define SBC_ASC_MEDIUM_NOT_PRESENT 0x3A
/** @}*/
/*------------------------------------------------------------------------------ */
/** \brief MEDIUM TYPE field value for direct-access block devices */
/** \see sbc3r06.pdf - Section 6.3.1 */
#define SBC_MEDIUM_TYPE_DIRECT_ACCESS_BLOCK_DEVICE 0x00
/*------------------------------------------------------------------------------ */
/*------------------------------------------------------------------------------ */
/** \brief MRIE field values */
/** \see sbc3r06.pdf - Section 7.4.11 - Table 286 */
#define SBC_MRIE_NO_REPORTING 0x00
#define SBC_MRIE_ASYNCHRONOUS 0x01
#define SBC_MRIE_GENERATE_UNIT_ATTENTION 0x02
#define SBC_MRIE_COND_GENERATE_RECOVERED_ERROR 0x03
#define SBC_MRIE_UNCOND_GENERATE_RECOVERED_ERROR 0x04
#define SBC_MRIE_GENERATE_NO_SENSE 0x05
#define SBC_MRIE_ON_REQUEST 0x06
/*------------------------------------------------------------------------------ */
/*------------------------------------------------------------------------------ */
/** \brief Supported mode pages */
/** \see sbc3r06.pdf - Section 6.3.1 - Table 115 */
#define SBC_PAGE_READ_WRITE_ERROR_RECOVERY 0x01
#define SBC_PAGE_INFORMATIONAL_EXCEPTIONS_CONTROL 0x1C
#define SBC_PAGE_RETURN_ALL 0x3F
#define SBC_PAGE_VENDOR_SPECIFIC 0x00
/*------------------------------------------------------------------------------ */
/** \addtogroup usbd_msd_endian_macros MSD Endian Macros
* @{
* This page lists the macros for endianness conversion.
*
* \section Macros
* - WORDB
* - DWORDB
* - STORE_DWORDB
* - STORE_WORDB
*/
/** \brief Converts a byte array to a word value using the big endian format */
#define WORDB(bytes) ((unsigned short) ((bytes[0] << 8) | bytes[1]))
/** \brief Converts a byte array to a dword value using the big endian format */
#define DWORDB(bytes) ((unsigned int) ((bytes[0] << 24) | (bytes[1] << 16) \
| (bytes[2] << 8) | bytes[3]))
/** \brief Stores a dword value in a byte array, in big endian format */
#define STORE_DWORDB(dword, bytes) \
bytes[0] = (unsigned char) (((dword) >> 24) & 0xFF); \
bytes[1] = (unsigned char) (((dword) >> 16) & 0xFF); \
bytes[2] = (unsigned char) (((dword) >> 8) & 0xFF); \
bytes[3] = (unsigned char) ((dword) & 0xFF);
/** \brief Stores a word value in a byte array, in big endian format */
#define STORE_WORDB(word, bytes) \
bytes[0] = (unsigned char) (((word) >> 8) & 0xFF); \
bytes[1] = (unsigned char) ((word) & 0xFF);
/** @}*/
/*------------------------------------------------------------------------------
* Structures
*------------------------------------------------------------------------------*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/**
* \typedef SBCInquiry
* \brief Structure for the INQUIRY command
* \see spc4r06.pdf - Section 6.4.1 - Table 81
*/
typedef struct _SBCInquiry {
unsigned char bOperationCode; /*!< 0x12 : SBC_INQUIRY */
unsigned char isEVPD:1, /*!< Type of requested data */
bReserved1:7; /*!< Reserved bits */
unsigned char bPageCode; /*!< Specifies the VPD to return */
unsigned char pAllocationLength[2]; /*!< Size of host buffer */
unsigned char bControl; /*!< 0x00 */
} __attribute__ ((__packed__)) SBCInquiry; /* GCC */
/**
* \typedef SBCInquiryData
* \brief Standard INQUIRY data format returned by the device
* \see spc4r06.pdf - Section 6.4.2 - Table 82
*/
typedef struct _SBCInquiryData {
unsigned char bPeripheralDeviceType:5, /*!< Peripheral device type */
bPeripheralQualifier :3; /*!< Peripheral qualifier */
unsigned char bReserved1:7, /*!< Reserved bits */
isRMB :1; /*!< Is media removable ? */
unsigned char bVersion; /*!< SPC version used */
unsigned char bResponseDataFormat:4, /*!< Must be 0x2 */
isHIGHSUP :1, /*!< Hierarchical addressing used ? */
isNORMACA :1, /*!< ACA attribute supported ? */
bObsolete1 :2; /*!< Obsolete bits */
unsigned char bAdditionalLength; /*!< Length of remaining INQUIRY data */
unsigned char isSCCS :1, /*!< Embedded SCC ? */
isACC :1, /*!< Access control coordinator ? */
bTPGS :2, /*!< Target port support group */
is3PC :1, /*!< Third-party copy supported ? */
bReserved2:2, /*!< Reserved bits */
isProtect :1; /*!< Protection info supported ? */
unsigned char bObsolete2:1, /*!< Obsolete bit */
isEncServ :1, /*!< Embedded enclosure service comp? */
isVS :1, /*!< ??? */
isMultiP :1, /*!< Multi-port device ? */
bObsolete3:3, /*!< Obsolete bits */
bUnused1 :1; /*!< Unused feature */
unsigned char bUnused2:6, /*!< Unused features */
isCmdQue:1, /*!< Task management model supported ? */
isVS2 :1; /*!< ??? */
unsigned char pVendorID[8]; /*!< T10 vendor identification */
unsigned char pProductID[16]; /*!< Vendor-defined product ID */
unsigned char pProductRevisionLevel[4];/*!< Vendor-defined product revision */
unsigned char pVendorSpecific[20]; /*!< Vendor-specific data */
unsigned char bUnused3; /*!< Unused features */
unsigned char bReserved3; /*!< Reserved bits */
unsigned short pVersionDescriptors[8]; /*!< Standards the device complies to */
unsigned char pReserved4[22]; /*!< Reserved bytes */
} __attribute__ ((__packed__)) SBCInquiryData; /* GCC */
/**
* \typedef SBCRead10
* \brief Data structure for the READ (10) command
* \see sbc3r07.pdf - Section 5.7 - Table 34
*/
typedef struct _SBCRead10 {
unsigned char bOperationCode; /*!< 0x28 : SBC_READ_10 */
unsigned char bObsolete1:1, /*!< Obsolete bit */
isFUA_NV:1, /*!< Cache control bit */
bReserved1:1, /*!< Reserved bit */
isFUA:1, /*!< Cache control bit */
isDPO:1, /*!< Cache control bit */
bRdProtect:3; /*!< Protection information to send */
unsigned char pLogicalBlockAddress[4]; /*!< Index of first block to read */
unsigned char bGroupNumber:5, /*!< Information grouping */
bReserved2:3; /*!< Reserved bits */
unsigned char pTransferLength[2]; /*!< Number of blocks to transmit */
unsigned char bControl; /*!< 0x00 */
} __attribute__ ((__packed__)) SBCRead10; /* GCC */
/**
* \typedef SBCReadCapacity10
* \brief Structure for the READ CAPACITY (10) command
* \see sbc3r07.pdf - Section 5.11.1 - Table 40
*/
typedef struct _SBCReadCapacity10 {
unsigned char bOperationCode; /*!< 0x25 : RBC_READ_CAPACITY */
unsigned char bObsolete1:1, /*!< Obsolete bit */
bReserved1:7; /*!< Reserved bits */
unsigned char pLogicalBlockAddress[4]; /*!< Block to evaluate if PMI is set */
unsigned char pReserved2[2]; /*!< Reserved bytes */
unsigned char isPMI:1, /*!< Partial medium indicator bit */
bReserved3:7; /*!< Reserved bits */
unsigned char bControl; /*!< 0x00 */
} SBCReadCapacity10;
/*------------------------------------------------------------------------------
* \brief Data returned by the device after a READ CAPACITY (10) command
* \see sbc3r07.pdf - Section 5.11.2 - Table 41
*------------------------------------------------------------------------------*/
typedef struct {
unsigned char pLogicalBlockAddress[4]; /*!< Address of last logical block */
unsigned char pLogicalBlockLength[4]; /*!< Length of each logical block */
} SBCReadCapacity10Data;
/*------------------------------------------------------------------------------
* \brief Structure for the REQUEST SENSE command
* \see spc4r06.pdf - Section 6.26 - Table 170
*------------------------------------------------------------------------------*/
typedef struct {
unsigned char bOperationCode; /*!< 0x03 : SBC_REQUEST_SENSE */
unsigned char isDesc :1, /*!< Type of information expected */
bReserved1:7; /*!< Reserved bits */
unsigned char pReserved2[2]; /*!< Reserved bytes */
unsigned char bAllocationLength; /*!< Size of host buffer */
unsigned char bControl; /*!< 0x00 */
} SBCRequestSense;
/*------------------------------------------------------------------------------
* \brief Fixed format sense data returned after a REQUEST SENSE command has
* been received with a DESC bit cleared.
* \see spc4r06.pdf - Section 4.5.3 - Table 26
*------------------------------------------------------------------------------*/
typedef struct {
unsigned char bResponseCode:7, /*!< Sense data format */
isValid :1; /*!< Information field is standard */
unsigned char bObsolete1; /*!< Obsolete byte */
unsigned char bSenseKey :4, /*!< Generic error information */
bReserved1:1, /*!< Reserved bit */
isILI :1, /*!< SSC */
isEOM :1, /*!< SSC */
isFilemark:1; /*!< SSC */
unsigned char pInformation[4]; /*!< Command-specific */
unsigned char bAdditionalSenseLength; /*!< sizeof(SBCRequestSense_data)-8 */
unsigned char pCommandSpecificInformation[4]; /*!< Command-specific */
unsigned char bAdditionalSenseCode; /*!< Additional error information */
unsigned char bAdditionalSenseCodeQualifier; /*!< Further error information */
unsigned char bFieldReplaceableUnitCode; /*!< Specific component code */
unsigned char bSenseKeySpecific:7, /*!< Additional exception info */
isSKSV :1; /*!< Is sense key specific valid? */
unsigned char pSenseKeySpecific[2]; /*!< Additional exception info */
} SBCRequestSenseData;
/**
* \brief SBCTestUnitReady
* Data structure for the TEST UNIT READY command
* \see spc4r06.pdf - Section 6.34 - Table 192
*/
typedef struct _SBCTestUnitReady {
unsigned char bOperationCode; /*!< 0x00 : SBC_TEST_UNIT_READY */
unsigned char pReserved1[4]; /*!< Reserved bits */
unsigned char bControl; /*!< 0x00 */
} __attribute__ ((__packed__)) SBCTestUnitReady; /* GCC */
/**
* \typedef SBCWrite10
* \brief Structure for the WRITE (10) command
* \see sbc3r07.pdf - Section 5.26 - Table 70
*/
typedef struct _SBCWrite10 {
unsigned char bOperationCode; /*!< 0x2A : SBC_WRITE_10 */
unsigned char bObsolete1:1, /*!< Obsolete bit */
isFUA_NV:1, /*!< Cache control bit */
bReserved1:1, /*!< Reserved bit */
isFUA:1, /*!< Cache control bit */
isDPO:1, /*!< Cache control bit */
bWrProtect:3; /*!< Protection information to send */
unsigned char pLogicalBlockAddress[4]; /*!< First block to write */
unsigned char bGroupNumber:5, /*!< Information grouping */
bReserved2:3; /*!< Reserved bits */
unsigned char pTransferLength[2]; /*!< Number of blocks to write */
unsigned char bControl; /*!< 0x00 */
} SBCWrite10;
/**
* \typedef SBCMediumRemoval
* \brief Structure for the PREVENT/ALLOW MEDIUM REMOVAL command
* \see sbc3r07.pdf - Section 5.5 - Table 30
*/
typedef struct _SBCMediumRemoval {
unsigned char bOperationCode; /*!< 0x1E : SBC_PREVENT_ALLOW_MEDIUM_REMOVAL */
unsigned char pReserved1[3]; /*!< Reserved bytes */
unsigned char bPrevent:2, /*!< Accept/prohibit removal */
bReserved2:6; /*!< Reserved bits */
unsigned char bControl; /*!< 0x00 */
} __attribute__ ((__packed__)) SBCMediumRemoval; /* GCC */
/**
* \typedef SBCModeSense6
* \brief Structure for the MODE SENSE (6) command
* \see spc4r06 - Section 6.9.1 - Table 98
*/
typedef struct _SBCModeSense6 {
unsigned char bOperationCode; /*!< 0x1A : SBC_MODE_SENSE_6 */
unsigned char bReserved1:3, /*!< Reserved bits */
isDBD:1, /*!< Disable block descriptors bit */
bReserved2:4; /*!< Reserved bits */
unsigned char bPageCode:6, /*!< Mode page to return */
bPC:2; /*!< Type of parameter values to return */
unsigned char bSubpageCode; /*!< Mode subpage to return */
unsigned char bAllocationLength; /*!< Host buffer allocated size */
unsigned char bControl; /*!< 0x00 */
} __attribute__ ((__packed__)) SBCModeSense6; /* GCC */
/**
* \typedef SBCModeParameterHeader6
* \brief Header for the data returned after a MODE SENSE (6) command
* \see spc4r06.pdf - Section 7.4.3 - Table 268
*/
typedef struct _SBCModeParameterHeader6 {
unsigned char bModeDataLength; /*!< Length of mode data to follow */
unsigned char bMediumType; /*!< Type of medium (SBC_MEDIUM_TYPE_DIRECT_ACCESS_BLOCK_DEVICE) */
unsigned char bReserved1:4, /*!< Reserved bits */
isDPOFUA:1, /*!< DPO/FUA bits supported ? */
bReserved2:2, /*!< Reserved bits */
isWP:1; /*!< Is medium write-protected ? */
unsigned char bBlockDescriptorLength; /*!< Length of all block descriptors */
} __attribute__ ((__packed__)) SBCModeParameterHeader6; /* GCC */
/**
* \typedef SBCInformationalExceptionsControl
* \brief Informational exceptions control mode page
* \see spc4r06.pdf - Section 7.4.11 - Table 285
*/
typedef struct _SBCInformationalExceptionsControl {
unsigned char bPageCode:6, /*!< 0x1C : SBC_PAGE_INFORMATIONAL_EXCEPTIONS_CONTROL */
isSPF:1, /*!< Page or subpage data format */
isPS:1; /*!< Parameters saveable ? */
unsigned char bPageLength; /*!< Length of page data (0x0A) */
unsigned char isLogErr:1, /*!< Should informational exceptions be logged ? */
isEBackErr:1, /*!< Enable background error bit */
isTest:1, /*!< Create a device test failure ? */
isDExcpt:1, /*!< Disable exception control bit */
isEWasc:1, /*!< Report warnings ? */
isEBF:1, /*!< Enable background function bit */
bReserved1:1, /*!< Reserved bit */
isPerf:1; /*!< Delay acceptable when treating exceptions ? */
unsigned char bMRIE:4, /*!< Method of reporting informational exceptions */
bReserved2:4; /*!< Reserved bits */
unsigned char pIntervalTimer[4]; /*!< Error reporting period */
unsigned char pReportCount[4]; /*!< Maximum number of time a report can be issued */
} __attribute__ ((__packed__)) SBCInformationalExceptionsControl; /* GCC */
/**
* \typedef SBCReadWriteErrorRecovery
* \brief Read/write error recovery mode page
* \see sbc3r07.pdf - Section 6.3.5 - Table 122
*/
typedef struct _SBCReadWriteErrorRecovery {
unsigned char bPageCode:6, /*!< 0x01 : SBC_PAGE_READ_WRITE_ERROR_RECOVERY */
isSPF:1, /*!< Page or subpage data format */
isPS:1; /*!< Parameters saveable ? */
unsigned char bPageLength; /*!< Length of page data (0x0A) */
unsigned char isDCR:1, /*!< Disable correction bit */
isDTE:1, /*!< Data terminate on error bit */
isPER:1, /*!< Post error bit */
isEER:1, /*!< Enable early recovery bit */
isRC:1, /*!< Read continuous bit */
isTB:1, /*!< Transfer block bit */
isARRE:1, /*!< Automatic read reallocation enabled bit */
isAWRE:1; /*!< Automatic write reallocation enabled bit */
unsigned char bReadRetryCount; /*!< Number of retries when reading */
unsigned char pObsolete1[3]; /*!< Obsolete bytes */
unsigned char bReserved1; /*!< Reserved byte */
unsigned char bWriteRetryCount; /*!< Number of retries when writing */
unsigned char bReserved2; /*!< Reserved byte */
unsigned char pRecoveryTimeLimit[2]; /*!< Maximum time duration for error recovery */
} __attribute__ ((__packed__)) SBCReadWriteErrorRecovery; /* GCC */
/**
* \typedef SBCCommand
* \brief Generic structure for holding information about SBC commands
* \see SBCInquiry
* \see SBCRead10
* \see SBCReadCapacity10
* \see SBCRequestSense
* \see SBCTestUnitReady
* \see SBCWrite10
* \see SBCMediumRemoval
* \see SBCModeSense6
*/
typedef union _SBCCommand {
unsigned char bOperationCode; /*!< Operation code of the command */
SBCInquiry inquiry; /*!< INQUIRY command */
SBCRead10 read10; /*!< READ (10) command */
SBCReadCapacity10 readCapacity10; /*!< READ CAPACITY (10) command */
SBCRequestSense requestSense; /*!< REQUEST SENSE command */
SBCTestUnitReady testUnitReady; /*!< TEST UNIT READY command */
SBCWrite10 write10; /*!< WRITE (10) command */
SBCMediumRemoval mediumRemoval; /*!< PREVENT/ALLOW MEDIUM REMOVAL command */
SBCModeSense6 modeSense6; /*!< MODE SENSE (6) command */
} SBCCommand;
#pragma pack()
/**@}*/
#endif /*#ifndef SBC_H */

View File

@ -0,0 +1,118 @@
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------
*/
/** \file
* \section Purpose
*
* SCSI commands implementation.
*
* section 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
/** \addtogroup usbd_msd
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
#include "SBC.h"
#include "MSDLun.h"
#include "MSDDStateMachine.h"
/*------------------------------------------------------------------------------
* Definitions
*------------------------------------------------------------------------------*/
/** \addtogroup usbd_sbc_command_state SBC Command States
* @{
* This page lists the possible states of a SBC command.
*
* \section 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 */

View File

@ -0,0 +1,278 @@
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------
*/
/**
* \file
*
* \section Purpose
*
* Collection of methods for using the USB device controller on AT91
* microcontrollers.
*
* \section Usage
*
* Please refer to the corresponding application note.
* - \ref usbd_framework AT91 USB device framework
* - \ref usbd_api USBD API
*
*/
#ifndef USBD_H
#define USBD_H
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
#include "USBDescriptors.h"
#include "USBRequests.h"
#include "USBLib_Types.h"
#include <stdio.h>
/*------------------------------------------------------------------------------
* Definitions
*------------------------------------------------------------------------------*/
/* Define attribute */
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#define WEAK __attribute__ ((weak))
#elif defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */
#define WEAK __weak
#elif defined ( __GNUC__ ) /* GCC CS3 2009q3-68 */
#define WEAK __attribute__ ((weak))
#endif
/* Define NO_INIT attribute */
#if defined ( __CC_ARM )
#define NO_INIT
#elif defined ( __ICCARM__ )
#define NO_INIT __no_init
#elif defined ( __GNUC__ )
#define NO_INIT
#endif
/** \addtogroup usbd_interface
*@{*/
/**
* \addtogroup usbd_rc USB device API return codes
* @{
* This section lists the return codes for the USB device driver API
* - \ref USBD_STATUS_SUCCESS
* - \ref USBD_STATUS_LOCKED
* - \ref USBD_STATUS_ABORTED
* - \ref USBD_STATUS_RESET
*/
/** Indicates the operation was successful. */
#define USBD_STATUS_SUCCESS USBRC_SUCCESS
/** Endpoint/device is already busy. */
#define USBD_STATUS_LOCKED USBRC_BUSY
/** Operation has been aborted (error or stall). */
#define USBD_STATUS_ABORTED USBRC_ABORTED
/** Operation has been canceled (by user). */
#define USBD_STATUS_CANCELED USBRC_CANCELED
/** Operation has been aborted because the device init/reset/un-configure. */
#define USBD_STATUS_RESET USBRC_RESET
/** Part ot operation successfully done. */
#define USBD_STATUS_PARTIAL_DONE USBRC_PARTIAL_DONE
/** Operation failed because parameter error */
#define USBD_STATUS_INVALID_PARAMETER USBRC_PARAM_ERR
/** Operation failed because in unexpected state */
#define USBD_STATUS_WRONG_STATE USBRC_STATE_ERR
/** Operation failed because SW not supported */
#define USBD_STATUS_SW_NOT_SUPPORTED USBRC_SW_NOT_SUPPORTED
/** Operation failed because HW not supported */
#define USBD_STATUS_HW_NOT_SUPPORTED USBRC_HW_NOT_SUPPORTED
/** @}*/
/** \addtogroup usbd_states USB device states
* @{
* This section lists the device states of the USB device driver.
* - \ref USBD_STATE_SUSPENDED
* - \ref USBD_STATE_ATTACHED
* - \ref USBD_STATE_POWERED
* - \ref USBD_STATE_DEFAULT
* - \ref USBD_STATE_ADDRESS
* - \ref USBD_STATE_CONFIGURED
*/
/** The device is currently suspended. */
#define USBD_STATE_SUSPENDED 0
/** USB cable is plugged into the device. */
#define USBD_STATE_ATTACHED 1
/** Host is providing +5V through the USB cable. */
#define USBD_STATE_POWERED 2
/** Device has been reset. */
#define USBD_STATE_DEFAULT 3
/** The device has been given an address on the bus. */
#define USBD_STATE_ADDRESS 4
/** A valid configuration has been selected. */
#define USBD_STATE_CONFIGURED 5
/** @}*/
/*----------------------------------------------------------------------------
* Types
*----------------------------------------------------------------------------*/
/**
* \brief Buffer struct used for multi-buffer-listed transfer.
*
* The driver can process 255 bytes of buffers or buffer list window.
*/
typedef struct _USBDTransferBuffer {
/** Pointer to frame buffer */
uint8_t * pBuffer;
/** Size of the frame (up to 64K-1) */
uint16_t size;
/** Bytes transferred */
uint16_t transferred;
/** Bytes in FIFO */
uint16_t buffered;
/** Bytes remaining */
uint16_t remaining;
} USBDTransferBuffer;
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */
#define __attribute__(...)
#elif defined ( __GNUC__ ) /* GCC CS3 2009q3-68 */
#endif
/**
* \brief Struct used for USBD DMA Link List Transfer Descriptor, must be 16-bytes
* aligned.
*
* (For USB, DMA transfer is linked to EPs and FIFO address is EP defined)
*/
typedef struct _USBDDmaDescriptor {
/** Pointer to Next Descriptor */
void* pNxtDesc;
/** Pointer to data buffer address */
void* pDataAddr;
/** DMA Control setting register value */
uint32_t ctrlSettings:8, /** Control settings */
reserved:8, /** Not used */
bufferLength:16; /** Length of buffer */
/** Loaded to DMA register, OK to modify */
uint32_t used;
} __attribute__((aligned(16))) USBDDmaDescriptor;
#pragma pack()
/**
* Callback used by transfer functions (USBD_Read & USBD_Write) to notify
* that a transaction is complete.
*/
typedef void (*TransferCallback)(void *pArg,
uint8_t status,
uint32_t transferred,
uint32_t remaining);
/**
* Callback used by MBL transfer functions (USBD_Read & USBD_Write) to notify
* that a transaction is complete.
* \param pArg Pointer to callback arguments.
* \param status USBD status.
*/
typedef void (*MblTransferCallback)(void *pArg,
uint8_t status);
/**@}*/
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
//extern void USBD_IrqHandler(void);
extern void USBD_Init(void);
extern void USBD_ConfigureSpeed(uint8_t forceFS);
extern void USBD_Connect(void);
extern void USBD_Disconnect(void);
extern uint8_t USBD_Write(
uint8_t bEndpoint,
const void *pData,
uint32_t size,
TransferCallback callback,
void *pArg);
extern uint8_t USBD_Read(
uint8_t bEndpoint,
void *pData,
uint32_t dLength,
TransferCallback fCallback,
void *pArg);
extern uint8_t USBD_Stall(uint8_t bEndpoint);
extern void USBD_Halt(uint8_t bEndpoint);
extern void USBD_Unhalt(uint8_t bEndpoint);
extern void USBD_ConfigureEndpoint(const USBEndpointDescriptor *pDescriptor);
extern uint8_t USBD_IsHalted(uint8_t bEndpoint);
extern void USBD_RemoteWakeUp(void);
extern void USBD_SetAddress(uint8_t address);
extern void USBD_SetConfiguration(uint8_t cfgnum);
extern uint8_t USBD_GetState(void);
extern uint8_t USBD_IsHighSpeed(void);
extern void USBD_Test(uint8_t bIndex);
extern void USBD_SuspendHandler(void);
extern void USBD_ResumeHandler(void);
extern void USBD_ResetHandler(void);
extern void USBD_RequestHandler(uint8_t bEndpoint,
const USBGenericRequest * pRequest);
extern void USBDCallbacks_Initialized(void);
extern void USBDCallbacks_Reset(void);
extern void USBDCallbacks_Suspended(void);
extern void USBDCallbacks_Resumed(void);
extern void USBDCallbacks_RequestReceived(const USBGenericRequest *request);
#endif /*#ifndef USBD_H*/

View File

@ -0,0 +1,149 @@
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------
*/
/**
* \file
*
* \section Purpose
*
* USB Device Driver class definition.
*
* \section Usage
*
* -# Instanciate a USBDDriver object and initialize it using
* USBDDriver_Initialize.
* -# When a USB SETUP request is received, forward it to the standard
* driver using USBDDriver_RequestHandler.
* -# Check the Remote Wakeup setting via USBDDriver_IsRemoteWakeUpEnabled.
*/
#ifndef USBDDRIVER_H
#define USBDDRIVER_H
/** \addtogroup usbd_interface
*@{
*/
/*------------------------------------------------------------------------------
* Headers
*------------------------------------------------------------------------------*/
/* These headers were introduced in C99 by working group
* ISO/IEC JTC1/SC22/WG14.
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <USBRequests.h>
#include <USBDescriptors.h>
#include <USBLib_Types.h>
/*------------------------------------------------------------------------------
* Types
*------------------------------------------------------------------------------*/
/**
* \typedef USBDDriverDescriptors
* \brief List of all descriptors used by a USB device driver. Each descriptor
* can be provided in two versions: full-speed and high-speed. Devices
* which are not high-speed capable do not need to provided high-speed
* descriptors and the full-speed qualifier & other speed descriptors.
*/
typedef struct _USBDDriverDescriptors {
/** Pointer to the full-speed device descriptor */
const USBDeviceDescriptor *pFsDevice;
/** Pointer to the full-speed configuration descriptor */
const USBConfigurationDescriptor *pFsConfiguration;
/** Pointer to the full-speed qualifier descriptor */
const USBDeviceQualifierDescriptor *pFsQualifier;
/** Pointer to the full-speed other speed configuration descriptor */
const USBConfigurationDescriptor *pFsOtherSpeed;
/** Pointer to the high-speed device descriptor */
const USBDeviceDescriptor *pHsDevice;
/** Pointer to the high-speed configuration descriptor */
const USBConfigurationDescriptor *pHsConfiguration;
/** Pointer to the high-speed qualifier descriptor */
const USBDeviceQualifierDescriptor *pHsQualifier;
/** Pointer to the high-speed other speed configuration descriptor */
const USBConfigurationDescriptor *pHsOtherSpeed;
/** Pointer to the list of string descriptors */
const uint8_t **pStrings;
/** Number of string descriptors in list */
uint8_t numStrings;
} USBDDriverDescriptors;
/**
* \typedef USBDDriver
* \brief USB device driver structure, holding a list of descriptors identifying
* the device as well as the driver current state.
*/
typedef struct _USBDDriver {
/** List of descriptors used by the device. */
const USBDDriverDescriptors *pDescriptors;
/** Current setting for each interface. */
uint8_t *pInterfaces;
/** Current configuration number (0 -> device is not configured). */
uint8_t cfgnum;
/** Indicates if remote wake up has been enabled by the host. */
uint8_t isRemoteWakeUpEnabled;
/** Features supported by OTG */
uint8_t otg_features_supported;
} USBDDriver;
/*------------------------------------------------------------------------------
* Exported functions
*------------------------------------------------------------------------------*/
extern USBDDriver *USBD_GetDriver(void);
extern void USBDDriver_Initialize(
USBDDriver *pDriver,
const USBDDriverDescriptors *pDescriptors,
uint8_t *pInterfaces);
extern USBConfigurationDescriptor* USBDDriver_GetCfgDescriptors(
USBDDriver * pDriver,
uint8_t cfgNum);
extern void USBDDriver_RequestHandler(
USBDDriver *pDriver,
const USBGenericRequest *pRequest);
extern uint8_t USBDDriver_IsRemoteWakeUpEnabled(const USBDDriver *pDriver);
extern uint8_t USBDDriver_returnOTGFeatures(const USBDDriver *pDriver);
extern void USBDDriver_clearOTGFeatures(USBDDriver *pDriver);
extern void USBDDriverCallbacks_ConfigurationChanged(uint8_t cfgnum);
extern void USBDDriverCallbacks_InterfaceSettingChanged(uint8_t interface,
uint8_t setting);
/**@}*/
#endif /*#ifndef USBDDRIVER_H*/

View File

@ -0,0 +1,111 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2009, 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 USBD_HAL_H
#define USBD_HAL_H
/**
* \file
*
* This file defines functions for USB Device Hardware Access Level.
*/
/** \addtogroup usbd_hal
*@{*/
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
/* Introduced in C99 by working group ISO/IEC JTC1/SC22/WG14. */
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "USBD.h"
#include <USBDescriptors.h>
#include <USBRequests.h>
/*----------------------------------------------------------------------------
* Consts
*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
* Macros
*----------------------------------------------------------------------------*/
/** Get bitmap for an endpoint */
#define bmEP(bEP) (1 << (bEP))
/*----------------------------------------------------------------------------
* Types
*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
* Exported functoins
*----------------------------------------------------------------------------*/
extern void USBD_HAL_Init(void);
extern void USBD_HAL_Connect(void);
extern void USBD_HAL_Disconnect(void);
extern void USBD_HAL_RemoteWakeUp(void);
extern void USBD_HAL_SetConfiguration(uint8_t cfgnum);
extern void USBD_HAL_SetAddress(uint8_t address);
extern uint8_t USBD_HAL_IsHighSpeed(void);
extern void USBD_HAL_Suspend(void);
extern void USBD_HAL_Activate(void);
extern void USBD_HAL_ResetEPs(uint32_t bmEPs,uint8_t bStatus, uint8_t bKeepCfg);
extern void USBD_HAL_CancelIo(uint32_t bmEPs);
extern uint8_t USBD_HAL_ConfigureEP(const USBEndpointDescriptor * pDescriptor);
extern uint8_t USBD_HAL_SetTransferCallback(uint8_t bEP,
TransferCallback fCallback,
void * pCbData);
extern uint8_t USBD_HAL_SetupMblTransfer(uint8_t bEndpoint,
USBDTransferBuffer * pMbList,
uint16_t mblSize,
uint16_t startOffset);
extern uint8_t USBD_HAL_Write(uint8_t bEndpoint,
const void * pData,
uint32_t dLength);
extern uint8_t USBD_HAL_WrWithHdr(uint8_t bEndpoint,
const void * pHdr, uint8_t bHdrLen,
const void * pData, uint32_t dLength);
extern uint8_t USBD_HAL_Read(uint8_t bEndpoint,
void * pData,
uint32_t dLength);
extern uint8_t USBD_HAL_Stall(uint8_t bEP);
extern uint8_t USBD_HAL_Halt(uint8_t bEndpoint,uint8_t ctl);
extern void USBD_HAL_Test(uint8_t bIndex);
/**@}*/
#endif // #define USBD_HAL_H

View File

@ -0,0 +1,549 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, 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.
* ----------------------------------------------------------------------------
*/
/** \file
* \section Purpose
*
* Definitions and methods for USB descriptor structures described by the
* USB specification.
*
* \section Usage
*
*/
#ifndef _USBDESCRIPTORS_H_
#define _USBDESCRIPTORS_H_
/** \addtogroup usb_general
* @{
* \addtogroup usb_descriptor USB Descriptors
* @{
*/
/*---------------------------------------------------------------------------
* Headers
*---------------------------------------------------------------------------*/
/* These headers were introduced in C99 by working group
* ISO/IEC JTC1/SC22/WG14.
*/
#include <stdint.h>
/*---------------------------------------------------------------------------
* Definitions
*---------------------------------------------------------------------------*/
/*--------- Generic Descriptors --------*/
/** \addtogroup usb_desc_type USB Descriptor types
* @{
* This section lists the codes of the usb descriptor types
* - \ref USBGenericDescriptor_DEVICE
* - \ref USBGenericDescriptor_CONFIGURATION
* - \ref USBGenericDescriptor_STRING
* - \ref USBGenericDescriptor_INTERFACE
* - \ref USBGenericDescriptor_ENDPOINT
* - \ref USBGenericDescriptor_DEVICEQUALIFIER
* - \ref USBGenericDescriptor_OTHERSPEEDCONFIGURATION
* - \ref USBGenericDescriptor_INTERFACEPOWER
* - \ref USBGenericDescriptor_OTG
* - \ref USBGenericDescriptor_DEBUG
* - \ref USBGenericDescriptor_INTERFACEASSOCIATION
*/
/** Device descriptor type. */
#define USBGenericDescriptor_DEVICE 1
/** Configuration descriptor type. */
#define USBGenericDescriptor_CONFIGURATION 2
/** String descriptor type. */
#define USBGenericDescriptor_STRING 3
/** Interface descriptor type. */
#define USBGenericDescriptor_INTERFACE 4
/** Endpoint descriptor type. */
#define USBGenericDescriptor_ENDPOINT 5
/** Device qualifier descriptor type. */
#define USBGenericDescriptor_DEVICEQUALIFIER 6
/** Other speed configuration descriptor type. */
#define USBGenericDescriptor_OTHERSPEEDCONFIGURATION 7
/** Interface power descriptor type. */
#define USBGenericDescriptor_INTERFACEPOWER 8
/** On-The-Go descriptor type. */
#define USBGenericDescriptor_OTG 9
/** Debug descriptor type. */
#define USBGenericDescriptor_DEBUG 10
/** Interface association descriptor type. */
#define USBGenericDescriptor_INTERFACEASSOCIATION 11
/** @}*/
/*--------- Device Descriptors --------*/
/** \addtogroup usb_release_number USB release numbers
* @{
* This section lists the codes of USB release numbers.
* - \ref USBDeviceDescriptor_USB2_00
*/
/** The device supports USB 2.00. */
#define USBDeviceDescriptor_USB2_00 0x0200
/** @}*/
/*--------- Configuration Descriptors --------*/
/** \addtogroup usb_attributes USB Device Attributes
* @{
* This section lists the codes of the usb attributes.
* - \ref USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP
* - \ref USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP
* - \ref USBConfigurationDescriptor_BUSPOWERED_RWAKEUP
* - \ref USBConfigurationDescriptor_SELFPOWERED_RWAKEUP
* - \ref USBConfigurationDescriptor_POWER
*/
/** Device is bus-powered and not support remote wake-up. */
#define USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP 0x80
/** Device is self-powered and not support remote wake-up. */
#define USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP 0xC0
/** Device is bus-powered and supports remote wake-up. */
#define USBConfigurationDescriptor_BUSPOWERED_RWAKEUP 0xA0
/** Device is self-powered and supports remote wake-up. */
#define USBConfigurationDescriptor_SELFPOWERED_RWAKEUP 0xE0
/** Calculates the value of the power consumption field given the value in mA.
* \param power The power consumption value in mA
* \return The value that should be set to the field in descriptor
*/
#define USBConfigurationDescriptor_POWER(power) (power / 2)
/** @}*/
/*--------- Endpoint Descriptors --------*/
/** \addtogroup usb_ep_define USB Endpoint definitions
* @{
* This section lists definitions and macro for endpoint descriptors.
* - \ref usb_ep_dir USB Endpoint directions
* - \ref USBEndpointDescriptor_OUT
* - \ref USBEndpointDescriptor_IN
*
* - \ref usb_ep_type USB Endpoint types
* - \ref USBEndpointDescriptor_CONTROL
* - \ref USBEndpointDescriptor_ISOCHRONOUS
* - \ref USBEndpointDescriptor_BULK
* - \ref USBEndpointDescriptor_INTERRUPT
*
* - \ref usb_ep_size USB Endpoint maximun sizes
* - \ref USBEndpointDescriptor_MAXCTRLSIZE_FS
* - \ref USBEndpointDescriptor_MAXCTRLSIZE_HS
* - \ref USBEndpointDescriptor_MAXBULKSIZE_FS
* - \ref USBEndpointDescriptor_MAXBULKSIZE_HS
* - \ref USBEndpointDescriptor_MAXINTERRUPTSIZE_FS
* - \ref USBEndpointDescriptor_MAXINTERRUPTSIZE_HS
* - \ref USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS
* - \ref USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS
*
* - \ref usb_ep_addr USB Endpoint address define
* - \ref USBEndpointDescriptor_ADDRESS
*/
/** \addtogroup usb_ep_dir USB Endpoint directions
* @{
* This section lists definitions of USB endpoint directions.
* - USBEndpointDescriptor_OUT
* - USBEndpointDescriptor_IN
*/
/** Endpoint receives data from the host. */
#define USBEndpointDescriptor_OUT 0
/** Endpoint sends data to the host. */
#define USBEndpointDescriptor_IN 1
/** @}*/
/** \addtogroup usb_ep_type USB Endpoint types
* @{
* This section lists definitions of USB endpoint types.
* - \ref USBEndpointDescriptor_CONTROL
* - \ref USBEndpointDescriptor_ISOCHRONOUS
* - \ref USBEndpointDescriptor_BULK
* - \ref USBEndpointDescriptor_INTERRUPT
*/
/** Control endpoint type. */
#define USBEndpointDescriptor_CONTROL 0
/** Isochronous endpoint type. */
#define USBEndpointDescriptor_ISOCHRONOUS 1
/** Bulk endpoint type. */
#define USBEndpointDescriptor_BULK 2
/** Interrupt endpoint type. */
#define USBEndpointDescriptor_INTERRUPT 3
/** @}*/
/** \addtogroup usb_ep_size USB Endpoint maximun sizes
* @{
* This section lists definitions of USB endpoint maximun sizes.
* - \ref USBEndpointDescriptor_MAXCTRLSIZE_FS
* - \ref USBEndpointDescriptor_MAXCTRLSIZE_HS
* - \ref USBEndpointDescriptor_MAXBULKSIZE_FS
* - \ref USBEndpointDescriptor_MAXBULKSIZE_HS
* - \ref USBEndpointDescriptor_MAXINTERRUPTSIZE_FS
* - \ref USBEndpointDescriptor_MAXINTERRUPTSIZE_HS
* - \ref USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS
* - \ref USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS
*/
/** Maximum size for a full-speed control endpoint. */
#define USBEndpointDescriptor_MAXCTRLSIZE_FS 64
/** Maximum size for a high-speed control endpoint. */
#define USBEndpointDescriptor_MAXCTRLSIZE_HS 64
/** Maximum size for a full-speed bulk endpoint. */
#define USBEndpointDescriptor_MAXBULKSIZE_FS 64
/** Maximum size for a high-speed bulk endpoint. */
#define USBEndpointDescriptor_MAXBULKSIZE_HS 512
/** Maximum size for a full-speed interrupt endpoint. */
#define USBEndpointDescriptor_MAXINTERRUPTSIZE_FS 64
/** Maximum size for a high-speed interrupt endpoint. */
#define USBEndpointDescriptor_MAXINTERRUPTSIZE_HS 1024
/** Maximum size for a full-speed isochronous endpoint. */
#define USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS 1023
/** Maximum size for a high-speed isochronous endpoint. */
#define USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS 1024
/** @}*/
/** \addtogroup usb_ep_addr USB Endpoint address define
* @{
* This section lists macro for USB endpoint address definition.
* - \ref USBEndpointDescriptor_ADDRESS
*/
/**
* Calculates the address of an endpoint given its number and direction
* \param direction USB endpoint direction definition
* \param number USB endpoint number
* \return The value used to set the endpoint descriptor based on input number
* and direction
*/
#define USBEndpointDescriptor_ADDRESS(direction, number) \
(((direction & 0x01) << 7) | (number & 0xF))
/** @}*/
/** @}*/
/*--------- Generic Descriptors --------*/
/** \addtogroup usb_string_descriptor USB String Descriptor Definitions
* @{
* This section lists the codes and macros for USB string descriptor definition.
*
* \par Language IDs
* - USBStringDescriptor_ENGLISH_US
*
* \par String Descriptor Length
* - USBStringDescriptor_LENGTH
*
* \par ASCII to UNICODE convertion
* - USBStringDescriptor_UNICODE
*/
/** Language ID for US english. */
#define USBStringDescriptor_ENGLISH_US 0x09, 0x04
/**
* Calculates the length of a string descriptor given the number of ascii
* characters/language IDs in it.
* \param length The ascii format string length.
* \return The actual data length in bytes.
*/
#define USBStringDescriptor_LENGTH(length) ((length) * 2 + 2)
/**
* Converts an ascii character to its unicode representation.
* \param ascii The ASCII character to convert
* \return A 2-byte-array for the UNICODE based on given ASCII
*/
#define USBStringDescriptor_UNICODE(ascii) (ascii), 0
/** @}*/
/*---------------------------------------------------------------------------
* Types
*---------------------------------------------------------------------------*/
/*
* Function types
*/
typedef uint32_t (*USBDescriptorParseFunction)(void *descriptor, void *parseArg);
/*
* Descriptor structs types
*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm */
#define __attribute__(...)
#define __packed__ packed
#elif defined ( __GNUC__ ) /* GCC CS3 */
#define __packed__ aligned(1)
#endif
/**
\typedef USBGenericDescriptor
\brief Holds the few fields shared by all USB descriptors.
*/
typedef struct _USBGenericDescriptor {
/** Length of the descriptor in bytes. */
uint8_t bLength;
/** Descriptor type. */
uint8_t bDescriptorType;
} __attribute__ ((__packed__)) USBGenericDescriptor; /* GCC */
/**
* \typedef USBDeviceDescriptor
* \brief USB standard device descriptor structure.
*/
typedef struct _USBDeviceDescriptor {
/** Size of this descriptor in bytes. */
uint8_t bLength;
/** Descriptor type (USBGenericDescriptor_DEVICE). */
uint8_t bDescriptorType;
/** USB specification release number in BCD format. */
uint16_t bcdUSB;
/** Device class code. */
uint8_t bDeviceClass;
/** Device subclass code. */
uint8_t bDeviceSubClass;
/** Device protocol code. */
uint8_t bDeviceProtocol;
/** Maximum packet size of endpoint 0 (in bytes). */
uint8_t bMaxPacketSize0;
/** Vendor ID. */
uint16_t idVendor;
/** Product ID. */
uint16_t idProduct;
/** Device release number in BCD format. */
uint16_t bcdDevice;
/** Index of the manufacturer string descriptor. */
uint8_t iManufacturer;
/** Index of the product string descriptor. */
uint8_t iProduct;
/** Index of the serial number string descriptor. */
uint8_t iSerialNumber;
/** Number of possible configurations for the device. */
uint8_t bNumConfigurations;
} __attribute__ ((__packed__)) USBDeviceDescriptor; /* GCC */
/**
* \typedef USBOtgDescriptor
* \brief USB On-The-Go descriptor struct.
*/
typedef struct _USBOtgDescriptor {
/** Size of this descriptor in bytes. */
uint8_t bLength;
/** Descriptor type (USBGenericDescriptor_OTG). */
uint8_t bDescriptorType;
/** Attribute Fields D7?: Reserved D1: HNP support D0: SRP support */
uint8_t bmAttributes;
} __attribute__ ((__packed__)) USBOtgDescriptor; /* GCC */
/**
* \typedef USBDeviceQualifierDescriptor
* \brief Alternate device descriptor indicating the capabilities of the device
* in full-speed, if currently in high-speed; or in high-speed, if it is
* currently in full-speed. Only relevant for devices supporting the
* high-speed mode.
*/
typedef struct _USBDeviceQualifierDescriptor {
/** Size of the descriptor in bytes. */
uint8_t bLength;
/** Descriptor type (USBDESC_DEVICE_QUALIFIER or "USB device types"). */
uint8_t bDescriptorType;
/** USB specification release number (in BCD format). */
uint16_t bcdUSB;
/** Device class code. */
uint8_t bDeviceClass;
/** Device subclass code. */
uint8_t bDeviceSubClass;
/** Device protocol code. */
uint8_t bDeviceProtocol;
/** Maximum packet size of endpoint 0. */
uint8_t bMaxPacketSize0;
/** Number of possible configurations for the device. */
uint8_t bNumConfigurations;
/** Reserved. */
uint8_t bReserved;
} __attribute__ ((__packed__)) USBDeviceQualifierDescriptor; /* GCC */
/**
* \typedef USBConfigurationDescriptor
* \brief USB standard configuration descriptor structure.
*/
typedef struct _USBConfigurationDescriptor {
/** Size of the descriptor in bytes. */
uint8_t bLength;
/** Descriptor type
(USBDESC_CONFIGURATION of \ref usb_desc_type USB Descriptor types). */
uint8_t bDescriptorType;
/** Length of all descriptors returned along with this configuration
descriptor. */
uint16_t wTotalLength;
/** Number of interfaces in this configuration. */
uint8_t bNumInterfaces;
/** Value for selecting this configuration. */
uint8_t bConfigurationValue;
/** Index of the configuration string descriptor. */
uint8_t iConfiguration;
/** Configuration characteristics. */
uint8_t bmAttributes;
/** Maximum power consumption of the device when in this configuration. */
uint8_t bMaxPower;
} __attribute__ ((__packed__)) USBConfigurationDescriptor; /* GCC*/
/**
* \typedef USBInterfaceAssociationDescriptor
* \brief
*/
typedef struct _USBInterfaceAssociationDescriptor {
unsigned char bLength;
unsigned char bDescriptorType;
unsigned char bFirstInterface;
unsigned char bInterfaceCount;
unsigned char bFunctionClass;
unsigned char bFunctionSubClass;
unsigned char bFunctionProtocol;
unsigned char iFunction;
} __attribute__ ((__packed__)) USBInterfaceAssociationDescriptor; /* GCC*/
/**
* \typedef USBInterfaceDescriptor
* \brief USB standard interface descriptor structure.
*/
typedef struct _USBInterfaceDescriptor {
/** Size of the descriptor in bytes. */
uint8_t bLength;
/** Descriptor type (USBGenericDescriptor_INTERFACE). */
uint8_t bDescriptorType;
/** Number of the interface in its configuration. */
uint8_t bInterfaceNumber;
/** Value to select this alternate interface setting. */
uint8_t bAlternateSetting;
/** Number of endpoints used by the inteface (excluding endpoint 0). */
uint8_t bNumEndpoints;
/** Interface class code. */
uint8_t bInterfaceClass;
/** Interface subclass code. */
uint8_t bInterfaceSubClass;
/** Interface protocol code. */
uint8_t bInterfaceProtocol;
/** Index of the interface string descriptor. */
uint8_t iInterface;
} __attribute__ ((__packed__)) USBInterfaceDescriptor; /* GCC */
/**
* \typedef USBEndpointDescriptor
* \brief USB standard endpoint descriptor structure.
*/
typedef struct _USBEndpointDescriptor {
/** Size of the descriptor in bytes. */
uint8_t bLength;
/** Descriptor type (\ref USBGenericDescriptor_ENDPOINT). */
uint8_t bDescriptorType;
/** Address and direction of the endpoint. */
uint8_t bEndpointAddress;
/** Endpoint type and additional characteristics
(for isochronous endpoints). */
uint8_t bmAttributes;
/** Maximum packet size (in bytes) of the endpoint. */
uint16_t wMaxPacketSize;
/** Polling rate of the endpoint. */
uint8_t bInterval;
} __attribute__ ((__packed__)) USBEndpointDescriptor; /* GCC*/
#pragma pack()
/*---------------------------------------------------------------------------
* Exported Functions
*---------------------------------------------------------------------------*/
extern uint32_t USBGenericDescriptor_GetLength(
const USBGenericDescriptor *descriptor);
extern uint8_t USBGenericDescriptor_GetType(
const USBGenericDescriptor *descriptor);
extern USBGenericDescriptor *USBGenericDescriptor_GetNextDescriptor(
const USBGenericDescriptor *descriptor);
extern USBGenericDescriptor *USBGenericDescriptor_Parse(
const USBGenericDescriptor * descriptor,
uint32_t totalLength,
USBDescriptorParseFunction parseFunction,
void * parseArg);
extern uint32_t USBConfigurationDescriptor_GetTotalLength(
const USBConfigurationDescriptor *configuration);
extern uint8_t USBConfigurationDescriptor_GetNumInterfaces(
const USBConfigurationDescriptor *configuration);
extern uint8_t USBConfigurationDescriptor_IsSelfPowered(
const USBConfigurationDescriptor *configuration);
extern void USBConfigurationDescriptor_Parse(
const USBConfigurationDescriptor *configuration,
USBInterfaceDescriptor **interfaces,
USBEndpointDescriptor **endpoints,
USBGenericDescriptor **others);
extern uint8_t USBEndpointDescriptor_GetNumber(
const USBEndpointDescriptor *endpoint);
extern uint8_t USBEndpointDescriptor_GetDirection(
const USBEndpointDescriptor *endpoint);
extern uint8_t USBEndpointDescriptor_GetType(
const USBEndpointDescriptor *endpoint);
extern uint16_t USBEndpointDescriptor_GetMaxPacketSize(
const USBEndpointDescriptor *endpoint);
extern uint8_t USBEndpointDescriptor_GetInterval(
const USBEndpointDescriptor *endpoint);
/** @}*/
/**@}*/
#endif /* #ifndef _USBDESCRIPTORS_H_ */

View File

@ -0,0 +1,209 @@
/* ----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------
*/
/**
* \file
*
* \par Purpose
*
* Standard output methods for reporting debug information, warnings and
* errors, which can be easily be turned on/off.
*
* \par Usage
* -# Initialize the debug message port in application, for stdio printf().
* -# Uses the TRACE_DEBUG(), TRACE_INFO(), TRACE_WARNING(), TRACE_ERROR()
* TRACE_FATAL() macros to output traces throughout the program.
* -# Each type of trace has a level : Debug 5, Info 4, Warning 3, Error 2
* and Fatal 1. Disable a group of traces by changing the value of
* TRACE_LEVEL during compilation; traces with a level bigger than TRACE_LEVEL
* are not generated. To generate no trace, use the reserved value 0.
* -# Trace disabling can be static or dynamic. If dynamic disabling is selected
* the trace level can be modified in runtime. If static disabling is selected
* the disabled traces are not compiled.
*
* \par traceLevels Trace level description
* -# TRACE_DEBUG (5): Traces whose only purpose is for debugging the program,
* and which do not produce meaningful information otherwise.
* -# TRACE_INFO (4): Informational trace about the program execution. Should
* enable the user to see the execution flow.
* -# TRACE_WARNING (3): Indicates that a minor error has happened. In most case
* it can be discarded safely; it may even be expected.
* -# TRACE_ERROR (2): Indicates an error which may not stop the program execution,
* but which indicates there is a problem with the code.
* -# TRACE_FATAL (1): Indicates a major error which prevents the program from going
* any further.
*/
#ifndef _USBLIB_TRACE_H
#define _USBLIB_TRACE_H
/*
* Headers
*/
#include <stdio.h>
/*
* Global Definitions
*/
/** Softpack Version */
#define USBLIB_VERSION "0.1"
#define TRACE_LEVEL_DEBUG 5
#define TRACE_LEVEL_INFO 4
#define TRACE_LEVEL_WARNING 3
#define TRACE_LEVEL_ERROR 2
#define TRACE_LEVEL_FATAL 1
#define TRACE_LEVEL_NO_TRACE 0
/* By default, all traces are output except the debug one. */
#if !defined(TRACE_LEVEL)
#define TRACE_LEVEL TRACE_LEVEL_INFO
#endif
/* By default, trace level is static (not dynamic) */
#if !defined(DYN_TRACES)
#define DYN_TRACES 0
#endif
#if defined(NOTRACE)
#error "Error: NOTRACE has to be not defined !"
#endif
#undef NOTRACE
#if (DYN_TRACES==0)
#if (TRACE_LEVEL == TRACE_LEVEL_NO_TRACE)
#define NOTRACE
#endif
#endif
/* ------------------------------------------------------------------------------
* Global Macros
* ------------------------------------------------------------------------------
*/
#ifndef DYNTRACE
#define DYNTRACE 0
#endif
/**
* Outputs a formatted string using 'printf' if the log level is high
* enough. Can be disabled by defining TRACE_LEVEL=0 during compilation.
* \param ... Additional parameters depending on formatted string.
*/
#if defined(NOTRACE)
/* Empty macro */
#define TRACE_DEBUG(...) { }
#define TRACE_INFO(...) { }
#define TRACE_WARNING(...) { }
#define TRACE_ERROR(...) { }
#define TRACE_FATAL(...) { while(1); }
#define TRACE_DEBUG_WP(...) { }
#define TRACE_INFO_WP(...) { }
#define TRACE_WARNING_WP(...) { }
#define TRACE_ERROR_WP(...) { }
#define TRACE_FATAL_WP(...) { while(1); }
#elif (DYN_TRACES == 1)
/* Trace output depends on dwTraceLevel value */
#define TRACE_DEBUG(...) { if (dwTraceLevel >= TRACE_LEVEL_DEBUG) { printf("-D- " __VA_ARGS__); } }
#define TRACE_INFO(...) { if (dwTraceLevel >= TRACE_LEVEL_INFO) { printf("-I- " __VA_ARGS__); } }
#define TRACE_WARNING(...) { if (dwTraceLevel >= TRACE_LEVEL_WARNING) { printf("-W- " __VA_ARGS__); } }
#define TRACE_ERROR(...) { if (dwTraceLevel >= TRACE_LEVEL_ERROR) { printf("-E- " __VA_ARGS__); } }
#define TRACE_FATAL(...) { if (dwTraceLevel >= TRACE_LEVEL_FATAL) { printf("-F- " __VA_ARGS__); while(1); } }
#define TRACE_DEBUG_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_DEBUG) { printf(__VA_ARGS__); } }
#define TRACE_INFO_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_INFO) { printf(__VA_ARGS__); } }
#define TRACE_WARNING_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_WARNING) { printf(__VA_ARGS__); } }
#define TRACE_ERROR_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_ERROR) { printf(__VA_ARGS__); } }
#define TRACE_FATAL_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_FATAL) { printf(__VA_ARGS__); while(1); } }
#else
/* Trace compilation depends on TRACE_LEVEL value */
#if (TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
#define TRACE_DEBUG(...) { printf("-D- " __VA_ARGS__); }
#define TRACE_DEBUG_WP(...) { printf(__VA_ARGS__); }
#else
#define TRACE_DEBUG(...) { }
#define TRACE_DEBUG_WP(...) { }
#endif
#if (TRACE_LEVEL >= TRACE_LEVEL_INFO)
#define TRACE_INFO(...) { printf("-I- " __VA_ARGS__); }
#define TRACE_INFO_WP(...) { printf(__VA_ARGS__); }
#else
#define TRACE_INFO(...) { }
#define TRACE_INFO_WP(...) { }
#endif
#if (TRACE_LEVEL >= TRACE_LEVEL_WARNING)
#define TRACE_WARNING(...) { printf("-W- " __VA_ARGS__); }
#define TRACE_WARNING_WP(...) { printf(__VA_ARGS__); }
#else
#define TRACE_WARNING(...) { }
#define TRACE_WARNING_WP(...) { }
#endif
#if (TRACE_LEVEL >= TRACE_LEVEL_ERROR)
#define TRACE_ERROR(...) { printf("-E- " __VA_ARGS__); }
#define TRACE_ERROR_WP(...) { printf(__VA_ARGS__); }
#else
#define TRACE_ERROR(...) { }
#define TRACE_ERROR_WP(...) { }
#endif
#if (TRACE_LEVEL >= TRACE_LEVEL_FATAL)
#define TRACE_FATAL(...) { printf("-F- " __VA_ARGS__); while(1); }
#define TRACE_FATAL_WP(...) { printf(__VA_ARGS__); while(1); }
#else
#define TRACE_FATAL(...) { while(1); }
#define TRACE_FATAL_WP(...) { while(1); }
#endif
#endif
/**
* Exported variables
*/
/** Depending on DYN_TRACES, dwTraceLevel is a modifable runtime variable or a define */
#if !defined(NOTRACE) && (DYN_TRACES == 1)
extern uint32_t dwTraceLevel ;
#endif
#endif /* #ifndef _USBLIB_TRACE_H */

View File

@ -0,0 +1,81 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, 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.
* ----------------------------------------------------------------------------
*/
/** \file
* Definitions for USB Lib compiling.
*/
#ifndef USBLIB_TYPES_H
#define USBLIB_TYPES_H
/*----------------------------------------------------------------------------
* Includes
*----------------------------------------------------------------------------*/
#include <stdint.h>
/*----------------------------------------------------------------------------
* Defines
*----------------------------------------------------------------------------*/
/* Define WEAK attribute */
#ifndef WEAK
#if defined ( __CC_ARM )
#define WEAK __attribute__ ((weak))
#elif defined ( __ICCARM__ )
#define WEAK __weak
#elif defined ( __GNUC__ )
#define WEAK __attribute__ ((weak))
#endif
#endif
/** USB status ReturnCode */
typedef enum _USBRC {
USBRC_OK = 0, /**< Operation was successful */
USBRC_SUCCESS = 0, /**< Operation was successful */
/* Bool codes */
USBRC_FALSE = 0, /**< As boolean TRUE */
USBRC_TRUE = 1, /**< As boolean FALSE */
/* Error codes */
USBRC_BUSY, /**< EP/Device is already busy */
USBRC_ABORTED, /**< Operation aborted due to error or stall */
USBRC_CANCELED, /**< Operation canceled by user */
USBRC_RESET, /**< Operation aborted due to init/reset/un-configure */
USBRC_PARTIAL_DONE,/**< Part of operation successfully done */
USBRC_FINISHED, /**< All operation successfully done and terminate */
USBRC_PARAM_ERR, /**< Failed due to parameter error */
USBRC_STATE_ERR, /**< Failed due to state error */
USBRC_ERROR, /**< General error */
USBRC_SW_NOT_SUPPORTED = 0xFD, /**< Failed due to SW not supported */
USBRC_HW_NOT_SUPPORTED = 0xFE /**< Failed due to HW not supported */
} USBRC;
#endif /* #define USBLIB_TYPES_H */

View File

@ -0,0 +1,354 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2010, 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.
* ----------------------------------------------------------------------------
*/
/** \file
* \section Purpose
*
* Definitions and methods for USB request structures described by the
* USB specification.
*
* \section Usage
*
*/
#ifndef _USBREQUESTS_H_
#define _USBREQUESTS_H_
/** \addtogroup usb_general
* @{
* \addtogroup usb_request USB Requests
* @{
*/
/*---------------------------------------------------------------------------
* Headers
*---------------------------------------------------------------------------*/
/* These headers were introduced in C99 by working group
* ISO/IEC JTC1/SC22/WG14.
*/
#include <stdint.h>
/*---------------------------------------------------------------------------
* Definitions
*---------------------------------------------------------------------------*/
/*----------- Generic Request ------------*/
/** \addtogroup usb_request_define USB Generic Request definitions
* @{
* This section lists the codes of USB generic request.
*
* - \ref usb_request_code USB Request codes
* - \ref USBGenericRequest_GETSTATUS
* - \ref USBGenericRequest_CLEARFEATURE
* - \ref USBGenericRequest_SETFEATURE
* - \ref USBGenericRequest_SETADDRESS
* - \ref USBGenericRequest_GETDESCRIPTOR
* - \ref USBGenericRequest_SETDESCRIPTOR
* - \ref USBGenericRequest_GETCONFIGURATION
* - \ref USBGenericRequest_SETCONFIGURATION
* - \ref USBGenericRequest_GETINTERFACE
* - \ref USBGenericRequest_SETINTERFACE
* - \ref USBGenericRequest_SYNCHFRAME
*
* - \ref usb_request_recipient USB Request Recipients
* - \ref USBGenericRequest_DEVICE
* - \ref USBGenericRequest_INTERFACE
* - \ref USBGenericRequest_ENDPOINT
* - \ref USBGenericRequest_OTHER
*
* - \ref usb_request_type USB Request Types
* - \ref USBGenericRequest_STANDARD
* - \ref USBGenericRequest_CLASS
* - \ref USBGenericRequest_VENDOR
*
* - \ref usb_request_dir USB Request Directions
* - \ref USBGenericRequest_IN
* - \ref USBGenericRequest_OUT
*/
/** \addtogroup usb_request_code USB Request codes
* @{
* This section lists the USB generic request codes.
* - \ref USBGenericRequest_GETSTATUS
* - \ref USBGenericRequest_CLEARFEATURE
* - \ref USBGenericRequest_SETFEATURE
* - \ref USBGenericRequest_SETADDRESS
* - \ref USBGenericRequest_GETDESCRIPTOR
* - \ref USBGenericRequest_SETDESCRIPTOR
* - \ref USBGenericRequest_GETCONFIGURATION
* - \ref USBGenericRequest_SETCONFIGURATION
* - \ref USBGenericRequest_GETINTERFACE
* - \ref USBGenericRequest_SETINTERFACE
* - \ref USBGenericRequest_SYNCHFRAME
*/
/** GET_STATUS request code. */
#define USBGenericRequest_GETSTATUS 0
/** CLEAR_FEATURE request code. */
#define USBGenericRequest_CLEARFEATURE 1
/** SET_FEATURE request code. */
#define USBGenericRequest_SETFEATURE 3
/** SET_ADDRESS request code. */
#define USBGenericRequest_SETADDRESS 5
/** GET_DESCRIPTOR request code. */
#define USBGenericRequest_GETDESCRIPTOR 6
/** SET_DESCRIPTOR request code. */
#define USBGenericRequest_SETDESCRIPTOR 7
/** GET_CONFIGURATION request code. */
#define USBGenericRequest_GETCONFIGURATION 8
/** SET_CONFIGURATION request code. */
#define USBGenericRequest_SETCONFIGURATION 9
/** GET_INTERFACE request code. */
#define USBGenericRequest_GETINTERFACE 10
/** SET_INTERFACE request code. */
#define USBGenericRequest_SETINTERFACE 11
/** SYNCH_FRAME request code. */
#define USBGenericRequest_SYNCHFRAME 12
/** @}*/
/** \addtogroup usb_request_recipient USB Request Recipients
* @{
* This section lists codes of USB request recipients.
* - \ref USBGenericRequest_DEVICE
* - \ref USBGenericRequest_INTERFACE
* - \ref USBGenericRequest_ENDPOINT
* - \ref USBGenericRequest_OTHER
*/
/** Recipient is the whole device. */
#define USBGenericRequest_DEVICE 0
/** Recipient is an interface. */
#define USBGenericRequest_INTERFACE 1
/** Recipient is an endpoint. */
#define USBGenericRequest_ENDPOINT 2
/** Recipient is another entity. */
#define USBGenericRequest_OTHER 3
/** @}*/
/** \addtogroup usb_request_type USB Request Types
* @{
* This section lists codes of USB request types.
* - \ref USBGenericRequest_STANDARD
* - \ref USBGenericRequest_CLASS
* - \ref USBGenericRequest_VENDOR
*/
/** Request is standard. */
#define USBGenericRequest_STANDARD 0
/** Request is class-specific. */
#define USBGenericRequest_CLASS 1
/** Request is vendor-specific. */
#define USBGenericRequest_VENDOR 2
/** @}*/
/** \addtogroup usb_request_dir USB Request Directions
* @{
* This section lists codes of USB request directions.
* - \ref USBGenericRequest_IN
* - \ref USBGenericRequest_OUT
*/
/** Transfer occurs from device to the host. */
#define USBGenericRequest_OUT 0
/** Transfer occurs from the host to the device. */
#define USBGenericRequest_IN 1
/** @}*/
/** @}*/
/*----------- Feature Request ------------*/
/** \addtogroup usb_feature_def USB Feature Request Definitions
* @{
* This section lists codes of USB Feature Request
*
* - \ref usb_feature_sel USB Feature selectors
* - \ref USBFeatureRequest_ENDPOINTHALT
* - \ref USBFeatureRequest_DEVICEREMOTEWAKEUP
* - \ref USBFeatureRequest_TESTMODE
*
* - \ref usb_test_sel USB Test mode selectors
* - \ref USBFeatureRequest_TESTJ
* - \ref USBFeatureRequest_TESTK
* - \ref USBFeatureRequest_TESTSE0NAK
* - \ref USBFeatureRequest_TESTPACKET
* - \ref USBFeatureRequest_TESTFORCEENABLE
* - \ref USBFeatureRequest_TESTSENDZLP
*/
/** \addtogroup usb_feature_sel USB Feature selectors
* @{
* This section lists codes of USB feature selectors.
* - \ref USBFeatureRequest_ENDPOINTHALT
* - \ref USBFeatureRequest_DEVICEREMOTEWAKEUP
* - \ref USBFeatureRequest_TESTMODE
*/
/** Halt feature of an endpoint. */
#define USBFeatureRequest_ENDPOINTHALT 0
/** Remote wake-up feature of the device. */
#define USBFeatureRequest_DEVICEREMOTEWAKEUP 1
/** Test mode of the device. */
#define USBFeatureRequest_TESTMODE 2
/** OTG set feature */
#define USBFeatureRequest_OTG 0x0B
/** OTG b_hnp_enable */
#define USBFeatureRequest_OTG_B_HNP_ENABLE 3
/** OTG a_hnp_support */
#define USBFeatureRequest_OTG_A_HNP_SUPPORT 4
/** OTG a_alt_hnp_support */
#define USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT 5
/** @}*/
/** \addtogroup usb_test_sel USB Test mode selectors
* @{
* This section lists codes of USB high speed test mode selectors.
* - \ref USBFeatureRequest_TESTJ
* - \ref USBFeatureRequest_TESTK
* - \ref USBFeatureRequest_TESTSE0NAK
* - \ref USBFeatureRequest_TESTPACKET
* - \ref USBFeatureRequest_TESTFORCEENABLE
* - \ref USBFeatureRequest_TESTSENDZLP
*/
/** Tests the high-output drive level on the D+ line. */
#define USBFeatureRequest_TESTJ 1
/** Tests the high-output drive level on the D- line. */
#define USBFeatureRequest_TESTK 2
/** Tests the output impedance, low-level output voltage and loading
characteristics. */
#define USBFeatureRequest_TESTSE0NAK 3
/** Tests rise and fall times, eye patterns and jitter. */
#define USBFeatureRequest_TESTPACKET 4
/** Tests the hub disconnect detection. */
#define USBFeatureRequest_TESTFORCEENABLE 5
/** Send a ZLP in Test Mode. */
#define USBFeatureRequest_TESTSENDZLP 6
/** @}*/
/** @}*/
/*---------------------------------------------------------------------------
* Types
*---------------------------------------------------------------------------*/
/*
* Function types
*/
/*
* Descriptor structs types
*/
#pragma pack(1)
#if defined ( __CC_ARM ) /* Keil ¦ÌVision 4 */
#elif defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */
#define __attribute__(...)
#elif defined ( __GNUC__ ) /* GCC CS3 2009q3-68 */
#endif
/**
* Generic USB SETUP request sent over Control endpoints.
*/
typedef struct {
/** Type of request
* \sa usb_request_recipient "USB Request Recipients"
* \sa usb_request_type "USB Request Types"
* \sa usb_request_dir "USB Request Directions" */
uint8_t bmRequestType:8;
/** Request code
* \sa usb_request_code "USB Request Codes" */
uint8_t bRequest:8;
/** Request-specific value parameter. */
uint16_t wValue:16;
/** Request-specific index parameter. */
uint16_t wIndex:16;
/** Expected length (in bytes) of the data phase. */
uint16_t wLength:16;
} USBGenericRequest;
#pragma pack()
/*---------------------------------------------------------------------------
* Exported Functions
*---------------------------------------------------------------------------*/
extern uint8_t USBGenericRequest_GetType(
const USBGenericRequest *request);
extern uint8_t USBGenericRequest_GetRequest(
const USBGenericRequest *request);
extern uint16_t USBGenericRequest_GetValue(
const USBGenericRequest *request);
extern uint16_t USBGenericRequest_GetIndex(
const USBGenericRequest *request);
extern uint16_t USBGenericRequest_GetLength(
const USBGenericRequest *request);
extern uint8_t USBGenericRequest_GetEndpointNumber(
const USBGenericRequest *request);
extern uint8_t USBGenericRequest_GetRecipient(
const USBGenericRequest *request);
extern uint8_t USBGenericRequest_GetDirection(
const USBGenericRequest *request);
extern uint8_t USBGetDescriptorRequest_GetDescriptorType(
const USBGenericRequest *request);
extern uint8_t USBGetDescriptorRequest_GetDescriptorIndex(
const USBGenericRequest *request);
extern uint8_t USBSetAddressRequest_GetAddress(
const USBGenericRequest *request);
extern uint8_t USBSetConfigurationRequest_GetConfiguration(
const USBGenericRequest *request);
extern uint8_t USBInterfaceRequest_GetInterface(
const USBGenericRequest *request);
extern uint8_t USBInterfaceRequest_GetAlternateSetting(
const USBGenericRequest *request);
extern uint8_t USBFeatureRequest_GetFeatureSelector(
const USBGenericRequest *request);
extern uint8_t USBFeatureRequest_GetTestSelector(
const USBGenericRequest *request);
/** @}*/
/**@}*/
#endif /* #ifndef _USBREQUESTS_H_ */

View File

@ -0,0 +1,500 @@
/*
FreeRTOS V8.0.1 - Copyright (C) 2014 Real Time Engineers Ltd.
All rights reserved
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
***************************************************************************
* *
* FreeRTOS provides completely free yet professionally developed, *
* robust, strictly quality controlled, supported, and cross *
* platform software that has become a de facto standard. *
* *
* Help yourself get started quickly and support the FreeRTOS *
* project by purchasing a FreeRTOS tutorial book, reference *
* manual, or both from: http://www.FreeRTOS.org/Documentation *
* *
* Thank you! *
* *
***************************************************************************
This file is part of the FreeRTOS distribution.
FreeRTOS is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License (version 2) as published by the
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
>>! NOTE: The modification to the GPL is included to allow you to !<<
>>! distribute a combined work that includes FreeRTOS without being !<<
>>! obliged to provide the source code for proprietary components !<<
>>! outside of the FreeRTOS kernel. !<<
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. Full license text is available from the following
link: http://www.freertos.org/a00114.html
1 tab == 4 spaces!
***************************************************************************
* *
* Having a problem? Start by reading the FAQ "My application does *
* not run, what could be wrong?" *
* *
* http://www.FreeRTOS.org/FAQHelp.html *
* *
***************************************************************************
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
license and Real Time Engineers Ltd. contact details.
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
compatible FAT file system, and our tiny thread aware UDP/IP stack.
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
licenses offer ticketed support, indemnification and middleware.
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
engineered and independently SIL3 certified version for use in safety and
mission critical applications that require provable dependability.
1 tab == 4 spaces!
*/
/*
* NOTE: This file uses a third party USB CDC driver.
*/
/* Standard includes. */
#include "string.h"
#include "stdio.h"
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "event_groups.h"
/* Example includes. */
#include "FreeRTOS_CLI.h"
/* Library includes. */
#include "board.h"
#include "chip.h"
#include "USBD.h"
#include "CDCDSerialDriver.h"
/*-----------------------------------------------------------*/
/* Dimensions the buffer into which input characters are placed. */
#define cmdMAX_INPUT_SIZE 50
/* DEL acts as a backspace. */
#define cmdASCII_DEL ( 0x7F )
/* The bits in the event group used to signal USB interrupt events to this
task. */
#define cmdRX_COMPLETE_BIT ( 0x01 )
#define cmdTX_COMPLETE_BIT ( 0x02 )
/*-----------------------------------------------------------*/
/*
* The task that implements the command console processing.
*/
static void prvCDCCommandConsoleTask( void *pvParameters );
/*
* Initialise the USB hardware and driver.
*/
static void prvCDCInit( void );
/*
* Handler installed on the VBUS pin to detect connect() and disconnect()
* events.
*/
static void prvVBusISRHandler( const Pin *pxPin );
/*
* USB handler defined by the driver, installed after the CDC driver has been
* initialised.
*/
extern void USBD_IrqHandler( void );
/*
* The function that creates the CLI task.
*/
void vUARTCommandConsoleStart( uint16_t usStackSize, UBaseType_t uxPriority );
/*
* Send xDataLength bytes from pcData to the CDC port.
*/
static void prvCDCSend( const char *pcData, size_t xDataLenth );
/*
* Initiate a receive into the Rx buffer from the CDC port, then wait for a
* period for characters to be received.
*/
static void prvCDCGetChar( void );
/*
* Configure VBus pins and interrupts, and check for connection.
*/
static void prvConfigureVBus( void );
/*
* Callback which is invoked when a CDC read completes. This callback is
* passed as a parameter to the CDC receive function.
*/
static void prvCDCDataReceivedCallback( uint32_t ulUnused, uint8_t ucStatus, uint32_t ulBytesReceived, uint32_t ulBytesRemaining );
/*
* Callback which is invoked when a CDC write completes. This callback is
* passed as a parameter to the CDC send function.
*/
static void prvCDCDataTransmittedCallback( uint32_t ulUnused, uint8_t ucStatus, uint32_t ulBytesSent, uint32_t ulBytesRemaining );
/*
* Keep trying to initiate an Rx until it is started successfully
*/
static void prvStartRx( void );
/*-----------------------------------------------------------*/
/* Const messages output by the command console. */
static const char * const pcWelcomeMessage = "FreeRTOS command server.\r\nType Help to view a list of registered commands.\r\n\r\n>";
static const char * const pcEndOfOutputMessage = "\r\n[Press ENTER to execute the previous command again]\r\n>";
static const char * const pcNewLine = "\r\n";
/* Buffer into which received characters are placed. */
static char pcRxBuffer[ cmdMAX_INPUT_SIZE ];
/* The number of bytes in pcRxBuffer that have not yet been read. */
static uint32_t ulBytesAvailable = 0;
/* Used to unblock the task when bytes are received and when bytes have
completed sending. */
static EventGroupHandle_t xCDCEventBits;
/*-----------------------------------------------------------*/
void vUARTCommandConsoleStart( uint16_t usStackSize, UBaseType_t uxPriority )
{
/* Event group used to indicate that bytes are available in the Rx buffer
or that bytes have finished sending. */
xCDCEventBits = xEventGroupCreate();
configASSERT( xCDCEventBits );
/* Create the task that handles the console itself. */
xTaskCreate( prvCDCCommandConsoleTask, /* The task that implements the command console. */
"CLI", /* Text name assigned to the task. This is just to assist debugging. The kernel does not use this name itself. */
usStackSize, /* The size of the stack allocated to the task. */
NULL, /* The parameter is not used, so NULL is passed. */
uxPriority, /* The priority allocated to the task. */
NULL ); /* A handle is not required, so just pass NULL. */
}
/*-----------------------------------------------------------*/
static void prvCDCCommandConsoleTask( void *pvParameters )
{
uint8_t ucInputIndex = 0;
char *pcOutputString, cRxedChar;
static char cInputString[ cmdMAX_INPUT_SIZE ], cLastInputString[ cmdMAX_INPUT_SIZE ];
BaseType_t xReturned;
uint32_t ulBufferIndex = 0;
( void ) pvParameters;
/* Obtain the address of the output buffer. Note there is no mutual
exclusion on this buffer as it is assumed only one command console interface
will be used at any one time. */
pcOutputString = FreeRTOS_CLIGetOutputBuffer();
/* Initialise the CDC driver. */
prvCDCInit();
/* Start receiving into the buffer. */
prvStartRx();
/* Send the welcome message. */
prvCDCSend( pcWelcomeMessage, strlen( pcWelcomeMessage ) );
for( ;; )
{
/* Wait for my characters to be available. */
prvCDCGetChar();
/* Process the bytes char for char on the assumption that as input comes
from typing it is unlikely that more than a single byte will be received
at a time anyway. */
while( ulBytesAvailable > 0 )
{
/* Read next byte from the rx buffer. */
cRxedChar = pcRxBuffer[ ulBufferIndex ];
taskENTER_CRITICAL();
{
ulBytesAvailable--;
}
taskEXIT_CRITICAL();
/* Echo the character back. */
prvCDCSend( &cRxedChar, sizeof( cRxedChar ) );
/* Was it the end of the line? */
if( cRxedChar == '\n' || cRxedChar == '\r' )
{
/* Just to space the output from the input. */
prvCDCSend( pcNewLine, strlen( pcNewLine ) );
/* See if the command is empty, indicating that the last command
is to be executed again. */
if( ucInputIndex == 0 )
{
/* Copy the last command back into the input string. */
strcpy( cInputString, cLastInputString );
}
/* Pass the received command to the command interpreter. The
command interpreter is called repeatedly until it returns
pdFALSE (indicating there is no more output) as it might
generate more than one string. */
do
{
/* Get the next output string from the command interpreter. */
xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );
/* Write the generated string to the UART. */
prvCDCSend( pcOutputString, strlen( pcOutputString ) );
} while( xReturned != pdFALSE );
/* All the strings generated by the input command have been
sent. Clear the input string ready to receive the next command.
Remember the command that was just processed first in case it is
to be processed again. */
strcpy( cLastInputString, cInputString );
ucInputIndex = 0;
memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
prvCDCSend( pcEndOfOutputMessage, strlen( pcEndOfOutputMessage ) );
}
else
{
if( cRxedChar == '\r' )
{
/* Ignore the character. */
}
else if( ( cRxedChar == '\b' ) || ( cRxedChar == cmdASCII_DEL ) )
{
/* Backspace was pressed. Erase the last character in the
string - if any. */
if( ucInputIndex > 0 )
{
ucInputIndex--;
cInputString[ ucInputIndex ] = '\0';
}
}
else
{
/* A character was entered. Add it to the string entered so
far. When a \n is entered the complete string will be
passed to the command interpreter. */
if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) )
{
if( ucInputIndex < cmdMAX_INPUT_SIZE )
{
cInputString[ ucInputIndex ] = cRxedChar;
ucInputIndex++;
}
}
}
}
/* Move onto the next byte the next time around. */
ulBufferIndex++;
if( ulBufferIndex >= cmdMAX_INPUT_SIZE )
{
ulBufferIndex = 0;
}
}
}
}
/*-----------------------------------------------------------*/
static void prvCDCInit( void )
{
extern WEAK const USBDDriverDescriptors cdcdSerialDriverDescriptors;
/* If they are present, configure Vbus & Wake-up pins */
PIO_InitializeInterrupts( 0 );
/* CDC serial driver initialization */
CDCDSerialDriver_Initialize( &cdcdSerialDriverDescriptors );
/* Configure VBus pins and interrupts, and check for connection. */
prvConfigureVBus();
}
/*-----------------------------------------------------------*/
static void prvCDCSend( const char *pcData, size_t xDataLength )
{
const TickType_t xTransferCompleteDelay = pdMS_TO_TICKS( 500UL );
( void ) pcData;
( void ) xDataLength;
if( xDataLength > 0 )
{
if( CDCDSerialDriver_Write( ( void * ) pcData, xDataLength, ( TransferCallback ) prvCDCDataTransmittedCallback, 0 ) == USBD_STATUS_SUCCESS )
{
/* Wait for the transfer to complete. */
xEventGroupWaitBits( xCDCEventBits,
cmdTX_COMPLETE_BIT, /* The bit to wait for. */
pdTRUE, /* Clear the bit before exiting the function. */
pdFALSE, /* Only need to wait for one bit anyway. */
xTransferCompleteDelay ); /* The maximum time to wait for the event. */
}
}
}
/*-----------------------------------------------------------*/
static void prvStartRx( void )
{
const TickType_t xFailedReadDelay = pdMS_TO_TICKS( 150UL );
while( CDCDSerialDriver_Read( pcRxBuffer, cmdMAX_INPUT_SIZE, ( TransferCallback ) prvCDCDataReceivedCallback, 0 ) != USBD_STATUS_SUCCESS )
{
/* Maybe the CDC is not connected. */
vTaskDelay( xFailedReadDelay );
}
}
/*-----------------------------------------------------------*/
static void prvCDCGetChar( void )
{
const TickType_t xTransferCompleteDelay = pdMS_TO_TICKS( 750UL );
if( ulBytesAvailable == 0 )
{
/* Wait for a transfer to complete. */
xEventGroupWaitBits( xCDCEventBits,
cmdRX_COMPLETE_BIT, /* The bit to wait for. */
pdTRUE, /* Clear the bit before exiting the function. */
pdFALSE, /* Only need to wait for one bit anyway. */
xTransferCompleteDelay ); /* The maximum time to wait for the event. */
}
}
/*-----------------------------------------------------------*/
static void prvVBusISRHandler( const Pin *pxPin )
{
/* NOTE: As this was written for the XPlained board, which is powered
through the USB and cannot be on without the USB connected, this function
has not been exercised. */
/* Check current level on VBus to detect a connect/disconnect. */
if( PIO_Get( pxPin ) != 0 )
{
USBD_Connect();
}
else
{
USBD_Disconnect();
}
}
/*-----------------------------------------------------------*/
static void prvCDCDataReceivedCallback( uint32_t ulUnused, uint8_t ucStatus, uint32_t ulBytesReceived, uint32_t ulBytesRemaining )
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
static uint32_t ulNextRxPosition = 0;
( void ) ulUnused;
( void ) ucStatus;
( void ) ulBytesRemaining;
/* If bytes were received then store the number of bytes placed into the Rx
buffer. */
if( ucStatus == USBD_STATUS_SUCCESS )
{
ulBytesAvailable += ulBytesReceived;
/* Restart the Rx position from a buffer position past the newly
received data. */
ulNextRxPosition += ulBytesReceived;
if( ulNextRxPosition >= cmdMAX_INPUT_SIZE )
{
ulNextRxPosition = 0;
}
CDCDSerialDriver_Read( pcRxBuffer + ulNextRxPosition, cmdMAX_INPUT_SIZE - ulNextRxPosition, ( TransferCallback ) prvCDCDataReceivedCallback, 0 );
/* Ensure the task knows new data is available. */
xEventGroupSetBitsFromISR( xCDCEventBits, cmdRX_COMPLETE_BIT, &xHigherPriorityTaskWoken );
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
}
/*-----------------------------------------------------------*/
static void prvCDCDataTransmittedCallback( uint32_t ulUnused, uint8_t ucStatus, uint32_t ulBytesSent, uint32_t ulBytesRemaining )
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
( void ) ulUnused;
( void ) ucStatus;
( void ) ulBytesRemaining;
( void ) ulBytesSent;
xEventGroupSetBitsFromISR( xCDCEventBits, cmdTX_COMPLETE_BIT, &xHigherPriorityTaskWoken );
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
/*-----------------------------------------------------------*/
static void prvConfigureVBus( void )
{
const Pin xVBusPin = PIN_USB_VBUS;
/* Configure PIO to generate an interrupt on status change. */
PIO_Configure( &xVBusPin, 1 );
PIO_ConfigureIt( &xVBusPin, prvVBusISRHandler );
PIO_EnableIt( &xVBusPin );
/* Check current level on VBus */
if( PIO_Get( &xVBusPin ) != pdFALSE )
{
/* if VBUS present, force the connect */
USBD_Connect();
}
else
{
USBD_Disconnect();
}
}
/*-----------------------------------------------------------*/
void USBDCallbacks_Initialized( void )
{
/* CDC specific re-implementation of weak callback function. Invoked after
the USB driver has been initialised. By default, configures the UDP/UDPHS
interrupt. */
IRQ_ConfigureIT( ID_UDPHS, 0, USBD_IrqHandler );
IRQ_EnableIT( ID_UDPHS );
}
/*-----------------------------------------------------------*/
void USBDDriverCallbacks_ConfigurationChanged( uint8_t ucConfigNumber )
{
/* CDC specific re-implementation of weak callback function. Invoked when
the configuration of the device changes. Parse used endpoints. */
CDCDSerialDriver_ConfigurationChangedHandler( ucConfigNumber );
}
/*-----------------------------------------------------------*/
void USBDCallbacks_RequestReceived( const USBGenericRequest *pxRequest )
{
/* CDC specific re-implementation of weak callback function. Invoked when
a new SETUP request is received from the host. */
CDCDSerialDriver_RequestHandler( pxRequest );
}
/*-----------------------------------------------------------*/

View File

@ -133,6 +133,8 @@ FreeRTOS/Source/tasks.c for limitations. */
#define configFPU_D32 0
#define configPIT_PIVR ( *( ( volatile uint32_t * ) 0xFFFFFE38UL ) )
#define configINTERRUPT_VECTOR_ADDRESS 0xFFFFF010UL
#define configEOI_ADDRESS 0xFFFFF038UL
#define configCLEAR_TICK_INTERRUPT() ( void ) configPIT_PIVR /* Read PIT_PIVR to clear interrupt. */
/* Prevent C code being included in assembly files when the IAR compiler is

View File

@ -70,6 +70,29 @@
/* Library includes. */
#include "board.h"
/*
* The FreeRTOS tick handler. This function must be installed as the handler
* for the timer used to generate the tick interrupt. Note that the interrupt
* generated by the PIT is shared by other system peripherals, so if the PIT is
* used for Tick generation then FreeRTOS_Tick_Handler() can only be installed
* directly as the PIT handler if no other system interrupts need to be
* serviced. If system interrupts other than the PIT need to be serviced then
* install System_Handler() as the PIT interrupt handler in place of
* FreeRTOS_Tick_Handler() and add additional interrupt processing into the
* implementation of System_Handler().
*/
extern void FreeRTOS_Tick_Handler( void );
static void System_Handler( void );
/*-----------------------------------------------------------*/
static void System_Handler( void )
{
/* See the comments above the function prototype in this file. */
FreeRTOS_Tick_Handler();
}
/*-----------------------------------------------------------*/
/*
* The application must provide a function that configures a peripheral to
* create the FreeRTOS tick interrupt, then define configSETUP_TICK_INTERRUPT()
@ -78,25 +101,31 @@
*/
void vConfigureTickInterrupt( void )
{
extern void FreeRTOS_Tick_Handler( void );
/* NOTE: The PIT interrupt is cleared by the configCLEAR_TICK_INTERRUPT()
macro in FreeRTOSConfig.h. */
/* Enable the PIT clock. */
PMC->PMC_PCER0 = 1 << ID_PIT;
/* Initialize the PIT to the desired frequency - specified in uS. */
PIT_Init( 1000000UL / configTICK_RATE_HZ, BOARD_MCK / 1000000 );
/* Configure interrupt on PIT */
#warning This is on the system interrupt and other interrupts may need processing to.
/* Configure interrupt on PIT. Note this is on the system interrupt, which
is shared with other system peripherals, so System_Handler() must be
installed in place of FreeRTOS_Tick_Handler() if other system handlers are
required. */
IRQ_ConfigureIT( ID_PIT, 0, FreeRTOS_Tick_Handler );
/* See commend directly above IRQ_ConfigureIT( ID_PIT, 0, System_Handler ); */
IRQ_EnableIT( ID_PIT );
PIT_EnableIT();
/* Enable the pit. */
PIT_Enable();
/* Prevent compiler warnings in the case where System_Handler() is not used
as the handler. See the comments above the System_Handler() function
prototype at the top of this file. */
( void ) System_Handler;
}
/*-----------------------------------------------------------*/

View File

@ -248,10 +248,10 @@ void main_full( void )
/* Start the tasks that implements the command console on the UART, as
described above. */
//_RB_ vUARTCommandConsoleStart( mainUART_COMMAND_CONSOLE_STACK_SIZE, mainUART_COMMAND_CONSOLE_TASK_PRIORITY );
vUARTCommandConsoleStart( mainUART_COMMAND_CONSOLE_STACK_SIZE, mainUART_COMMAND_CONSOLE_TASK_PRIORITY );
/* Register the standard CLI commands. */
//_RB_ vRegisterSampleCLICommands();
// vRegisterSampleCLICommands();
/* Create the register check tasks, as described at the top of this file */
xTaskCreate( prvRegTestTaskEntry1, "Reg1", configMINIMAL_STACK_SIZE, mainREG_TEST_TASK_1_PARAMETER, tskIDLE_PRIORITY, NULL );

View File

@ -214,7 +214,7 @@
</option>
<option>
<name>CCDiagSuppress</name>
<state></state>
<state>Pa131</state>
</option>
<option>
<name>CCDiagRemark</name>
@ -312,6 +312,8 @@
<state>$PROJ_DIR$\..\Common\include</state>
<state>$PROJ_DIR$\Full_Demo</state>
<state>$PROJ_DIR$\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-CLI</state>
<state>$PROJ_DIR$\AtmelFiles\usb\device</state>
<state>$PROJ_DIR$\AtmelFiles\usb\include</state>
</option>
<option>
<name>CCStdIncCheck</name>
@ -323,7 +325,7 @@
</option>
<option>
<name>IInterwork2</name>
<state>0</state>
<state>1</state>
</option>
<option>
<name>IProcessorMode2</name>
@ -980,6 +982,15 @@
<file>
<name>$PROJ_DIR$\AtmelFiles\libchip_sama5d3x\source\aic.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\libchip_sama5d3x\cp15\cp15.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\libchip_sama5d3x\cp15\cp15_asm_iar.s</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\libchip_sama5d3x\source\mmu.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\libchip_sama5d3x\source\pio.c</name>
</file>
@ -995,10 +1006,73 @@
<file>
<name>$PROJ_DIR$\AtmelFiles\libchip_sama5d3x\source\tc.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\libchip_sama5d3x\source\USBD_HAL.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\libchip_sama5d3x\source\wdt.c</name>
</file>
</group>
<group>
<name>usb</name>
<group>
<name>common</name>
<group>
<name>cdc</name>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\common\cdc\CDCLineCoding.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\common\cdc\CDCSetControlLineStateRequest.c</name>
</file>
</group>
<group>
<name>core</name>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\common\core\USBDescriptors.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\common\core\USBRequests.c</name>
</file>
</group>
</group>
<group>
<name>device</name>
<group>
<name>cdc-serial</name>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\device\cdc-serial\CDCDSerial.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\device\cdc-serial\CDCDSerial_Callbacks.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\device\cdc-serial\CDCDSerialDriver.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\device\cdc-serial\CDCDSerialPort.c</name>
</file>
</group>
<group>
<name>core</name>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\device\core\USBD.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\device\core\USBDCallbacks.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\device\core\USBDDriver.c</name>
</file>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\device\core\USBDDriverCallbacks.c</name>
</file>
</group>
</group>
<file>
<name>$PROJ_DIR$\AtmelFiles\usb\USBDDriverDescriptors.c</name>
</file>
</group>
</group>
<group>
<name>Blinky Demo</name>
@ -1108,6 +1182,9 @@
<file>
<name>$PROJ_DIR$\atmel_main.c</name>
</file>
<file>
<name>$PROJ_DIR$\CDCCommandConsole.c</name>
</file>
<file>
<name>$PROJ_DIR$\cstartup_with_FreeRTOS_vectors.s</name>
</file>

View File

@ -47,10 +47,6 @@
//------------------------------------------------------------------------------
// Definitions
//------------------------------------------------------------------------------
//_RB_ These definitions can go.
#define AIC 0xFFFFF000
#define AIC_IVR 0x10
#define AIC_EOICR 0x38
#define ARM_MODE_ABT 0x17
#define ARM_MODE_FIQ 0x11

View File

@ -127,6 +127,7 @@ void vApplicationTickHook( void );
/*-----------------------------------------------------------*/
#warning Try re-using the main stack.
int main( void )
{
/* Configure the hardware ready to run the demo. */
@ -150,6 +151,9 @@ int main( void )
static void prvSetupHardware( void )
{
/* Disable watchdog */
WDT_Disable( WDT );
/* Set protect mode in the AIC for easier debugging. */
AIC->AIC_DCR |= AIC_DCR_PROT;

View File

@ -30,16 +30,16 @@
<item>500</item><item>20</item></col-widths>
<DisasmHistory/>
<DisasmHistory><item>0x00302750</item></DisasmHistory>
<PreferedWindows><Position>2</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows><ShowCodeCoverage>1</ShowCodeCoverage><ShowInstrProfiling>1</ShowInstrProfiling></Disassembly>
<Register><PreferedWindows><Position>2</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows></Register><WATCH_1><expressions><item>xTickCount</item><item></item></expressions><col-names><item>Expression</item><item>Location</item><item>Type</item><item>Value</item></col-names><col-widths><item>100</item><item>150</item><item>100</item><item>100</item></col-widths><PreferedWindows><Position>2</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows></WATCH_1><CallStack><PreferedWindows><Position>1</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows><col-names><item>Frame</item><item>_I0</item></col-names><col-widths><item>400</item><item>20</item></col-widths></CallStack><Breakpoints><PreferedWindows><Position>3</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows><col-names><item>Breakpoint</item><item>_I0</item></col-names><col-widths><item>500</item><item>35</item></col-widths></Breakpoints></Static>
<Register><PreferedWindows><Position>2</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows></Register><WATCH_1><expressions><item></item></expressions><col-names><item>Expression</item><item>Location</item><item>Type</item><item>Value</item></col-names><col-widths><item>207</item><item>150</item><item>100</item><item>294</item></col-widths><PreferedWindows><Position>2</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows></WATCH_1><CallStack><PreferedWindows><Position>1</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows><col-names><item>Frame</item><item>_I0</item></col-names><col-widths><item>400</item><item>20</item></col-widths></CallStack><Breakpoints><PreferedWindows><Position>3</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows><col-names><item>Breakpoint</item><item>_I0</item></col-names><col-widths><item>500</item><item>35</item></col-widths></Breakpoints><Find-in-Files><ColumnWidth0>497</ColumnWidth0><ColumnWidth1>82</ColumnWidth1><ColumnWidth2>746</ColumnWidth2><ColumnWidth3>331</ColumnWidth3></Find-in-Files></Static>
<Windows>
<Wnd3>
<Wnd1>
<Tabs>
<Tab>
<Identity>TabID-13925-23874</Identity>
@ -53,9 +53,9 @@
<Factory>Build</Factory>
<Session/>
</Tab>
</Tabs>
<Tab><Identity>TabID-21109-11091</Identity><TabName>Find in Files</TabName><Factory>Find-in-Files</Factory><Session/></Tab></Tabs>
<SelectedTab>0</SelectedTab></Wnd3><Wnd4>
<SelectedTab>0</SelectedTab></Wnd1><Wnd2>
<Tabs>
<Tab>
<Identity>TabID-24673-23877</Identity>
@ -67,20 +67,20 @@
</Tab>
</Tabs>
<SelectedTab>0</SelectedTab></Wnd4><Wnd5><Tabs><Tab><Identity>TabID-23907-13802</Identity><TabName>Disassembly</TabName><Factory>Disassembly</Factory><Session/></Tab></Tabs><SelectedTab>0</SelectedTab></Wnd5></Windows>
<SelectedTab>0</SelectedTab></Wnd2></Windows>
<Editor>
<Pane><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\Full_Demo\main_full.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>134</YPos2><SelStart2>14916</SelStart2><SelEnd2>14916</SelEnd2></Tab><ActiveTab>0</ActiveTab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\..\Source\timers.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>405</YPos2><SelStart2>17615</SelStart2><SelEnd2>17615</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\..\Source\portable\IAR\ARM_CA5_No_GIC\port.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>280</YPos2><SelStart2>12519</SelStart2><SelEnd2>12519</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\Full_Demo\reg_test.S</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>102</YPos2><SelStart2>5571</SelStart2><SelEnd2>5571</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\..\Source\portable\IAR\ARM_CA5_No_GIC\portASM.s</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>113</YPos2><SelStart2>4976</SelStart2><SelEnd2>4979</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\..\Source\portable\IAR\ARM_CA5_No_GIC\portASM.h</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>99</YPos2><SelStart2>3</SelStart2><SelEnd2>3</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\FreeRTOSConfig.h</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>104</YPos2><SelStart2>6016</SelStart2><SelEnd2>6016</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\main.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>109</YPos2><SelStart2>5963</SelStart2><SelEnd2>5963</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\Common\Minimal\EventGroupsDemo.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>960</YPos2><SelStart2>34411</SelStart2><SelEnd2>34411</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\..\Source\event_groups.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>55</YPos2><SelStart2>4726</SelStart2><SelEnd2>4756</SelEnd2></Tab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>
<Pane><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\CDCCommandConsole.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>397</YPos2><SelStart2>14920</SelStart2><SelEnd2>14920</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\main.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>110</YPos2><SelStart2>6002</SelStart2><SelEnd2>6002</SelEnd2></Tab><ActiveTab>1</ActiveTab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\..\Source\portable\IAR\ARM_CA5_No_GIC\port.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>288</YPos2><SelStart2>12369</SelStart2><SelEnd2>12369</SelEnd2></Tab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>
<Positions>
<Top><Row0><Sizes><Toolbar-00D7DC28><key>iaridepm.enu1</key></Toolbar-00D7DC28></Sizes></Row0><Row1><Sizes><Toolbar-142E0530><key>debuggergui.enu1</key></Toolbar-142E0530></Sizes></Row1></Top><Left><Row0><Sizes><Wnd4><Rect><Top>-2</Top><Left>-2</Left><Bottom>718</Bottom><Right>332</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>119048</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>198810</sizeVertCX><sizeVertCY>731707</sizeVertCY></Rect></Wnd4></Sizes></Row0></Left><Right><Row0><Sizes><Wnd5><Rect><Top>-2</Top><Left>-2</Left><Bottom>718</Bottom><Right>198</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>119048</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>119048</sizeVertCX><sizeVertCY>731707</sizeVertCY></Rect></Wnd5></Sizes></Row0></Right><Bottom><Row0><Sizes><Wnd3><Rect><Top>-2</Top><Left>-2</Left><Bottom>198</Bottom><Right>1682</Right><x>-2</x><y>-2</y><xscreen>1684</xscreen><yscreen>200</yscreen><sizeHorzCX>1002381</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>119048</sizeVertCX><sizeVertCY>203252</sizeVertCY></Rect></Wnd3></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>
<Top><Row0><Sizes><Toolbar-00C8A108><key>iaridepm.enu1</key></Toolbar-00C8A108></Sizes></Row0><Row1><Sizes><Toolbar-14AD33B8><key>debuggergui.enu1</key></Toolbar-14AD33B8></Sizes></Row1></Top><Left><Row0><Sizes><Wnd2><Rect><Top>-2</Top><Left>-2</Left><Bottom>718</Bottom><Right>332</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>119048</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>198810</sizeVertCX><sizeVertCY>731707</sizeVertCY></Rect></Wnd2></Sizes></Row0></Left><Right><Row0><Sizes/></Row0></Right><Bottom><Row0><Sizes><Wnd1><Rect><Top>-2</Top><Left>-2</Left><Bottom>198</Bottom><Right>1682</Right><x>-2</x><y>-2</y><xscreen>1684</xscreen><yscreen>200</yscreen><sizeHorzCX>1002381</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>119048</sizeVertCX><sizeVertCY>203252</sizeVertCY></Rect></Wnd1></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>
</Desktop>
</Project>

View File

@ -2,7 +2,7 @@
FillEnabled=0
OverflowWarningsEnabled=1
WarningThreshold=90
SpWarningsEnabled=1
SpWarningsEnabled=0
WarnLogOnly=1
UseTrigger=1
TriggerName=main
@ -14,7 +14,7 @@ Watch0=_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0
Watch1=_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0
CStepIntDis=_ 0
[DebugChecksum]
Checksum=2132507383
Checksum=1771823120
[Exceptions]
StopOnUncaught=_ 0
StopOnThrow=_ 0

View File

@ -12,7 +12,7 @@
<Column0>382</Column0><Column1>27</Column1><Column2>27</Column2><Column3>27</Column3></ColumnWidths>
<Column0>278</Column0><Column1>27</Column1><Column2>27</Column2><Column3>27</Column3></ColumnWidths>
</Workspace>
<CRunMessageRules>
<col-names>
@ -32,11 +32,11 @@
<ColumnWidth0>20</ColumnWidth0><ColumnWidth1>1216</ColumnWidth1><ColumnWidth2>324</ColumnWidth2><ColumnWidth3>81</ColumnWidth3></Build>
<Debug-Log><ColumnWidth0>18</ColumnWidth0><ColumnWidth1>1624</ColumnWidth1></Debug-Log><TerminalIO/><Select-Ambiguous-Definitions><ColumnWidth0>552</ColumnWidth0><ColumnWidth1>78</ColumnWidth1><ColumnWidth2>946</ColumnWidth2></Select-Ambiguous-Definitions><Find-in-Files><ColumnWidth0>497</ColumnWidth0><ColumnWidth1>82</ColumnWidth1><ColumnWidth2>746</ColumnWidth2><ColumnWidth3>331</ColumnWidth3></Find-in-Files></Static>
<Debug-Log><ColumnWidth0>18</ColumnWidth0><ColumnWidth1>1624</ColumnWidth1></Debug-Log><TerminalIO/><Select-Ambiguous-Definitions><ColumnWidth0>552</ColumnWidth0><ColumnWidth1>78</ColumnWidth1><ColumnWidth2>946</ColumnWidth2></Select-Ambiguous-Definitions><Find-in-Files><ColumnWidth0>497</ColumnWidth0><ColumnWidth1>82</ColumnWidth1><ColumnWidth2>746</ColumnWidth2><ColumnWidth3>331</ColumnWidth3></Find-in-Files><Breakpoints><col-names><item>Breakpoint</item><item>_I0</item></col-names><col-widths><item>500</item><item>35</item></col-widths><PreferedWindows><Position>3</Position><ScreenPosX>0</ScreenPosX><ScreenPosY>0</ScreenPosY><Windows/></PreferedWindows></Breakpoints></Static>
<Windows>
<Wnd1>
<Wnd2>
<Tabs>
<Tab>
<Identity>TabID-22351-19008</Identity>
@ -44,11 +44,11 @@
<Factory>Workspace</Factory>
<Session>
<NodeDict><ExpandedNode>RTOSDemo</ExpandedNode><ExpandedNode>RTOSDemo/FreeRTOS Source</ExpandedNode><ExpandedNode>RTOSDemo/FreeRTOS Source/portable</ExpandedNode><ExpandedNode>RTOSDemo/Full Demo</ExpandedNode></NodeDict></Session>
<NodeDict><ExpandedNode>RTOSDemo</ExpandedNode><ExpandedNode>RTOSDemo/FreeRTOS Source</ExpandedNode><ExpandedNode>RTOSDemo/FreeRTOS Source/event_groups.c</ExpandedNode></NodeDict></Session>
</Tab>
</Tabs>
<SelectedTab>0</SelectedTab></Wnd1><Wnd2>
<SelectedTab>0</SelectedTab></Wnd2><Wnd3>
<Tabs>
<Tab>
<Identity>TabID-21076-19237</Identity>
@ -58,20 +58,20 @@
</Tab>
<Tab><Identity>TabID-23502-23081</Identity><TabName>Debug Log</TabName><Factory>Debug-Log</Factory><Session/></Tab><Tab><Identity>TabID-24431-23894</Identity><TabName>Ambiguous Definitions</TabName><Factory>Select-Ambiguous-Definitions</Factory><Session/></Tab><Tab><Identity>TabID-9033-6116</Identity><TabName>Find in Files</TabName><Factory>Find-in-Files</Factory><Session/></Tab></Tabs>
<SelectedTab>0</SelectedTab></Wnd2></Windows>
<SelectedTab>0</SelectedTab></Wnd3></Windows>
<Editor>
<Pane><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\Full_Demo\main_full.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>134</YPos2><SelStart2>14916</SelStart2><SelEnd2>14916</SelEnd2></Tab><ActiveTab>0</ActiveTab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\..\Source\timers.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>405</YPos2><SelStart2>17615</SelStart2><SelEnd2>17615</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\..\Source\portable\IAR\ARM_CA5_No_GIC\port.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>280</YPos2><SelStart2>12519</SelStart2><SelEnd2>12519</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\Full_Demo\reg_test.S</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>102</YPos2><SelStart2>5571</SelStart2><SelEnd2>5571</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\..\Source\portable\IAR\ARM_CA5_No_GIC\portASM.s</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>113</YPos2><SelStart2>4976</SelStart2><SelEnd2>4979</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\..\Source\portable\IAR\ARM_CA5_No_GIC\portASM.h</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>99</YPos2><SelStart2>3</SelStart2><SelEnd2>3</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\FreeRTOSConfig.h</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>104</YPos2><SelStart2>6016</SelStart2><SelEnd2>6016</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\main.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>109</YPos2><SelStart2>5963</SelStart2><SelEnd2>5963</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\Common\Minimal\EventGroupsDemo.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>960</YPos2><SelStart2>34411</SelStart2><SelEnd2>34411</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\..\Source\event_groups.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>55</YPos2><SelStart2>4726</SelStart2><SelEnd2>4756</SelEnd2></Tab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>
<Pane><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\CDCCommandConsole.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>397</YPos2><SelStart2>14920</SelStart2><SelEnd2>14920</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\main.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>110</YPos2><SelStart2>6002</SelStart2><SelEnd2>6002</SelEnd2></Tab><ActiveTab>1</ActiveTab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\..\Source\portable\IAR\ARM_CA5_No_GIC\port.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>288</YPos2><SelStart2>12369</SelStart2><SelEnd2>12369</SelEnd2></Tab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>
<Positions>
<Top><Row0><Sizes><Toolbar-00D7DC28><key>iaridepm.enu1</key></Toolbar-00D7DC28></Sizes></Row0><Row1><Sizes/></Row1></Top><Left><Row0><Sizes><Wnd1><Rect><Top>-2</Top><Left>-2</Left><Bottom>721</Bottom><Right>456</Right><x>-2</x><y>-2</y><xscreen>190</xscreen><yscreen>170</yscreen><sizeHorzCX>113095</sizeHorzCX><sizeHorzCY>172764</sizeHorzCY><sizeVertCX>272619</sizeVertCX><sizeVertCY>734756</sizeVertCY></Rect></Wnd1></Sizes></Row0></Left><Right><Row0><Sizes/></Row0></Right><Bottom><Row0><Sizes><Wnd2><Rect><Top>-2</Top><Left>-2</Left><Bottom>219</Bottom><Right>1682</Right><x>-2</x><y>-2</y><xscreen>1684</xscreen><yscreen>221</yscreen><sizeHorzCX>1002381</sizeHorzCX><sizeHorzCY>224593</sizeHorzCY><sizeVertCX>113095</sizeVertCX><sizeVertCY>172764</sizeVertCY></Rect></Wnd2></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>
<Top><Row0><Sizes><Toolbar-00C8A108><key>iaridepm.enu1</key></Toolbar-00C8A108></Sizes></Row0><Row1><Sizes/></Row1></Top><Left><Row0><Sizes><Wnd2><Rect><Top>-2</Top><Left>-2</Left><Bottom>698</Bottom><Right>352</Right><x>-2</x><y>-2</y><xscreen>190</xscreen><yscreen>170</yscreen><sizeHorzCX>113095</sizeHorzCX><sizeHorzCY>172764</sizeHorzCY><sizeVertCX>210714</sizeVertCX><sizeVertCY>711382</sizeVertCY></Rect></Wnd2></Sizes></Row0></Left><Right><Row0><Sizes/></Row0></Right><Bottom><Row0><Sizes><Wnd3><Rect><Top>-2</Top><Left>-2</Left><Bottom>242</Bottom><Right>1682</Right><x>-2</x><y>-2</y><xscreen>1684</xscreen><yscreen>244</yscreen><sizeHorzCX>1002381</sizeHorzCX><sizeHorzCY>247967</sizeHorzCY><sizeVertCX>113095</sizeVertCX><sizeVertCY>172764</sizeVertCY></Rect></Wnd3></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>
</Desktop>
</Workspace>