⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serial_driver.c

📁 AT91系列芯片的USB虚拟串口的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ----------------------------------------------------------------------------
 *         ATMEL Microcontroller Software Support  -  ROUSSET  -
 * ----------------------------------------------------------------------------
 * Copyright (c) 2006, 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 disclaiimer below.
 *
 * - Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the disclaimer below in the documentation and/or
 * other materials provided with the distribution.
 *
 * 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.
 * ----------------------------------------------------------------------------
 */

/*
$Id: serial_driver.c 107 2006-10-16 08:28:50Z jjoannic $
*/

//------------------------------------------------------------------------------
//      Includes
//------------------------------------------------------------------------------

#include "core/common.h"
#include "core/device.h"
#include "core/board.h"
#include "core/trace.h"
#include "core/usb.h"
#include "core/standard.h"
#include "cdc.h"
#include "serial_driver.h"

//------------------------------------------------------------------------------
//      Global variables
//------------------------------------------------------------------------------

// Descriptors
//------------------------------------------------------------------------------
//! \brief  Standard USB device descriptor
//! \see    S_usb_device_descriptor
const S_usb_device_descriptor sDevice = {

    sizeof(S_usb_device_descriptor), // Size of this descriptor
    USB_DEVICE_DESCRIPTOR,           // DEVICE Descriptor Type
    USB2_00,                         // USB 2.0 specification
    USB_CLASS_COMMUNICATION,         // USB Communication class code
    0x00,                            // No device subclass code
    0x00,                            // No device protocol code
    USB_ENDPOINT0_MAXPACKETSIZE,     // Maximum packet size for endpoint zero
    USB_VENDOR_ATMEL,                // ATMEL Vendor ID
    SER_PRODUCT_ID,                  // Product ID (6119)
    0x0001,                          // Device release number 0.01
    0x01,                            // Index of manufacturer description
    0x02,                            // Index of product description
    0x03,                            // Index of serial number description
    0x01                             // One possible configuration
};

//! \brief  Device configuration descriptor
//! \see    S_ser_configuration_descriptor
const S_ser_configuration_descriptor sConfiguration = {

    // Standard configuration descriptor
    {
        // Size of this descriptor
        sizeof(S_usb_configuration_descriptor),
        // CONFIGURATION descriptor type
        USB_CONFIGURATION_DESCRIPTOR,
        // Total size of this configuration (including other descriptors)
        sizeof(S_ser_configuration_descriptor),
        // Two interfaces are used by this configuration
        0x02,
        // Value 0x01 is used to select this configuration
        0x01,
        // No string is used to describe this configuration
        0x00,
        // Device is self-powered and does not support remote wakeup
        USB_CONFIG_SELF_WAKEUP,
        // Maximum power consumption of the device is 100mA
        USB_POWER_MA(100)
    },
    // Communication class interface descriptor
    {
        sizeof(S_usb_interface_descriptor), // Size of this descriptor in bytes
        USB_INTERFACE_DESCRIPTOR,           // INTERFACE Descriptor Type
        0x00,                               // Interface 0
        0x00,                               // No alternate settings
        0x01,                               // One endpoint used
        CDC_INTERFACE_COMMUNICATION,        // Communication interface class
        CDC_ABSTRACT_CONTROL_MODEL,         // Abstract control model subclass
        0x01,                               // No protocol code
        0x00                                // No associated string descriptor
    },
    // Header functional descriptor
    {
        sizeof(S_cdc_header_descriptor), // Size of this descriptor in bytes
        CDC_CS_INTERFACE,                // CS_INTERFACE descriptor type
        CDC_HEADER,                      // Header functional descriptor
        CDC1_10,                         // CDC version 1.10
    },
    // Call management functional descriptor
    {
        sizeof(S_cdc_call_management_descriptor), // Size of this descriptor
        CDC_CS_INTERFACE,                         // CS_INTERFACE type
        CDC_CALL_MANAGEMENT,                      // Call management descriptor
        0x01,                                     // Call management is
                                                  // handled by the device
        0x01                                      // Data interface is 0x01
    },
    // Abstract control management functional descriptor
    {
        // Size of this descriptor in bytes
        sizeof(S_cdc_abstract_control_management_descriptor),
        // CS_INTERFACE descriptor type
        CDC_CS_INTERFACE,
        // Abstract control management functional descriptor
        CDC_ABSTRACT_CONTROL_MANAGEMENT,
        // Every notification/request except NetworkConnection supported
        0x07
    },
    // Union functional descriptor with one slave interface
    {
        // Union functional descriptor
        {
            sizeof(S_cdc_union_descriptor)+1, // Size of this descriptor
            CDC_CS_INTERFACE,                 // CS_INTERFACE descriptor type
            CDC_UNION,                        // Union functional descriptor
            0x00,                             // Master interface is 0x00
        },                                    // (Communication class interface)
        0x01                                  // First slave interface is 0x01
    },                                        // (Data class interface)
    // Notification endpoint descriptor
    {
        sizeof(S_usb_endpoint_descriptor),  // Size of this descriptor in bytes
        USB_ENDPOINT_DESCRIPTOR,            // ENDPOINT descriptor type
        USB_ENDPOINT_IN | SER_EPT_NOTIFICATION, // IN endpoint, address = 0x03
        ENDPOINT_TYPE_INTERRUPT,            // INTERRUPT endpoint type
        64,                                 // Maximum packet size is 64 bytes
        0x10                                // Endpoint polled every 10ms
    },
    // Data class interface descriptor
    {
        sizeof(S_usb_interface_descriptor), // Size of this descriptor in bytes
        USB_INTERFACE_DESCRIPTOR,           // INTERFACE descriptor type
        0x01,                               // Interface 0x01
        0x00,                               // No alternate settings
        0x02,                               // Two endpoints used
        CDC_INTERFACE_DATA,                 // Data class code
        0x00,                               // No subclass code
        0x00,                               // No protocol code
        0x00                                // No description string
    },
    // Bulk-OUT endpoint descriptor
    {
        sizeof(S_usb_endpoint_descriptor), // Size of this descriptor in bytes
        USB_ENDPOINT_DESCRIPTOR,           // ENDPOINT descriptor type
        USB_ENDPOINT_OUT | SER_EPT_DATA_OUT,   // OUT endpoint, address = 0x01
        ENDPOINT_TYPE_BULK,                // Bulk endpoint
        64,                                // Endpoint size is 64 bytes
        0x00                               // Must be 0x00 for full-speed bulk
    },                                     // endpoints
    // Bulk-IN endpoint descriptor
    {
        sizeof(S_usb_endpoint_descriptor), // Size of this descriptor in bytes
        USB_ENDPOINT_DESCRIPTOR,           // ENDPOINT descriptor type
        USB_ENDPOINT_IN | SER_EPT_DATA_IN,     // IN endpoint, address = 0x02
        ENDPOINT_TYPE_BULK,                // Bulk endpoint
        64,                                // Endpoint size is 64 bytes
        0x00                               // Must be 0x00 for full-speed bulk
    },                                     // endpoints
};

//! \brief  Language ID string descriptor
const S_usb_language_id sLanguageID = {

    USB_STRING_DESCRIPTOR_SIZE(1),
    USB_STRING_DESCRIPTOR,
    USB_LANGUAGE_ENGLISH_US
};

//! \brief  Manufacturer string descriptor
const char pManufacturer[] = {

    USB_STRING_DESCRIPTOR_SIZE(5),
    USB_STRING_DESCRIPTOR,
    USB_UNICODE('A'),
    USB_UNICODE('T'),
    USB_UNICODE('M'),
    USB_UNICODE('E'),
    USB_UNICODE('L')
};

//! \brief  Product string descriptor
const char pProduct[] = {

    USB_STRING_DESCRIPTOR_SIZE(13),
    USB_STRING_DESCRIPTOR,
    USB_UNICODE('A'),
    USB_UNICODE('T'),
    USB_UNICODE('9'),
    USB_UNICODE('1'),
    USB_UNICODE('U'),
    USB_UNICODE('S'),
    USB_UNICODE('B'),
    USB_UNICODE('S'),
    USB_UNICODE('e'),
    USB_UNICODE('r'),
    USB_UNICODE('i'),
    USB_UNICODE('a'),
    USB_UNICODE('l')
};

//! \brief  Serial number string descriptor
const char pSerialNumber[] = {

    USB_STRING_DESCRIPTOR_SIZE(12),
    USB_STRING_DESCRIPTOR,
    USB_UNICODE('0'),
    USB_UNICODE('1'),

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -