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

📄 usb.c

📁 Texas Instruments的TUSB3410芯片接键盘输入的固件程序源码和驱动程序源码。
💻 C
📖 第 1 页 / 共 4 页
字号:
// (c)2002 by Texas Instruments Incorporated, All Rights Reserved.
/*----------------------------------------------------------------------------+
|                                                                             |
|                              Texas Instruments                              |
|                                                                             |
|                                     Usb                                     |
|                                                                             | 
+-----------------------------------------------------------------------------+
|  Source: usb.c, v00.01 2002/04/24 11:17                                     |
|  Author: Horng-Ming Lobo Tai lobotai@ti.com                                 |
|                                                                             |
|  For more information, please contact                                       |
|                                                                             |
|  Lobo Tai                                                                   |
|  Texas Instruments                                                          |
|  12500 TI Blvd, MS 8761                                                     |
|  Dallas, TX 75243                                                           |
|  USA                                                                        |
|                                                                             |
|  Tel 214-480-3145                                                           |
|  Fax 214-480-3443                                                           |
|                                                                             |
|  Release Notes:                                                             |
|  Logs:                                                                      |
|                                                                             |
|  WHO       WHEN         WHAT                                                |
|  ---       ----------   --------------------------------------------------  |
|  HMT       08/02/2000   born                                                |
|  HMT       02/14/2001   add i2c support, modified Set Endpoint and Get      |
|                         Endpoint routine. if endpoint is not supported,     |
|                         bootcode does not response (charpter 8)             |
|  HMT       03/02/2001   Optimized usbDecodeAndProcessUsbRequest() routine   |
|  HMT       03/07/2001   removed setup overwirte inteerupt                   |
|  HMT       09/28/2001   NAK both input and output endpoint 0 when setup     |
|                         packet is received.                                 |
|                                                                             |
+----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------+
| Include files                                                               |
+----------------------------------------------------------------------------*/
#ifdef KEIL
#include <reg51.h>      // for KEIL compiler 8051 sfr definition
#else
#include <io51.h>       // for IAR compiler 8051 sfr definition
#endif

#include "types.h"      // Basic Type declarations
#include "usb.h"        // USB-specific Data Structures
#include "i2c.h"
#include "tusb3410.h"
#include "delay.h"
#include "header.h"
#include "watchdog.h"
#include "VenReq.h"
#include "rs232dbg.h"
#include "sample.h"

/*----------------------------------------------------------------------------+
| External Function Prototype                                                 |
+----------------------------------------------------------------------------*/
VOID usbVendorRequest(VOID);

/*----------------------------------------------------------------------------+
| External Variables                                                          |
+----------------------------------------------------------------------------*/
extern idata WORD wCurrentUploadPointer;      // in header.c
extern idata BYTE bi2cDeviceAddress;          // in header.c
extern idata BYTE bCurrentDataType;           // in header.c

#include "descriptors.c" // must use include to prevent warning or error

/*
extern BYTE code abromDeviceDescriptor[SIZEOF_DEVICE_DESCRIPTOR];
extern BYTE code abromConfigurationDescriptorGroup[];

#ifdef RAW_STRING_DESCRIPTOR       
extern BYTE code *abromStringDescriptor;
#endif

//extern char code *mfgDescription;
//extern char code *prodDescription;
//extern char code *serialNumber;

//char code mfgDescription[]="Texas Instruments Incorporated";
//char code prodDescription[]="TI-GRAPH LINK USB";
//char code serialNumber[]="";
*/

/*----------------------------------------------------------------------------+
| Internal Type Definition & Macro                                            |
+----------------------------------------------------------------------------*/
typedef struct _tDEVICE_REQUEST_COMPARE
{
    BYTE    bmRequestType;              // See bit definitions below
    BYTE    bRequest;                   // See value definitions below
    BYTE    bValueL;                    // Meaning varies with request type
    BYTE    bValueH;                    // Meaning varies with request type
    BYTE    bIndexL;                    // Meaning varies with request type
    BYTE    bIndexH;                    // Meaning varies with request type
    BYTE    bLengthL;                   // Number of bytes of data to transfer (LSByte)
    BYTE    bLengthH;                   // Number of bytes of data to transfer (MSByte)
    BYTE    bCompareMask;               // MSB is bRequest, if set 1, bRequest should be matched
    VOID    (*pUsbFunction)(VOID);      // function pointer
} tDEVICE_REQUEST_COMPARE, *ptDEVICE_REQUEST_COMPARE;

//----------------------------------------------------------------------------
typedef enum
{
    STATUS_ACTION_NOTHING,
    STATUS_ACTION_DATA_IN,
    STATUS_ACTION_DATA_OUT
} tSTATUS_ACTION_LIST;

/*----------------------------------------------------------------------------+
| Internal Constant Definition                                                |
+----------------------------------------------------------------------------*/
#define NO_MORE_DATA 0xFFFF
#define USB_RETURN_DATA_LENGTH 4

//#include "descriptors.c"

/*
BYTE code abromDeviceDescriptor[SIZEOF_DEVICE_DESCRIPTOR] = {
    SIZEOF_DEVICE_DESCRIPTOR,       // Length of this descriptor (12h bytes)
    DESC_TYPE_DEVICE,               // Type code of this descriptor (01h)
    0x10,0x01,                      // Release of USB spec (Rev 1.1)
    0xff,                           // Device's base class code - vendor specific
    0,                              // Device's sub class code
    0,                              // Device's protocol type code
    EP0_PACKET_SIZE,                // End point 0's packet size = 8
    FUNCTION_VID_L,FUNCTION_VID_H,  // Vendor ID for device, TI=0x0451
#ifdef UMPDBG
    FUNCTION_PID_L+1,FUNCTION_PID_H,// Product ID for device, 0x3411 for debug on UMP board
#else    
    FUNCTION_PID_L,FUNCTION_PID_H,  // Product ID for device, 0x3410
#endif    
    0x00,0x01,                      // Revision level of device, Rev=1.0
    1,                              // Index of manufacturer name string desc
    2,                              // Index of product name string desc
    3,                              // Index of serial number string desc
    1                               // Number of configurations supported
};

BYTE code abromConfigurationDescriptorGroup[SIZEOF_BOOTCODE_CONFIG_DESC_GROUP] =
{
    // Configuration  Descriptor, size=0x09
    SIZEOF_CONFIG_DESCRIPTOR,        // bLength
    DESC_TYPE_CONFIG,                // bDescriptorType
    SIZEOF_BOOTCODE_CONFIG_DESC_GROUP, 0x00, // wTotalLength
    0x01,                            // bNumInterfaces
    0x01,                            // bConfigurationValue
    0x00,                            // iConfiguration
    0x80,                            // bmAttributes, bus bootcode
    0x32,                            // Max. Power Consumption at 2mA unit

    // Interface Descriptor, size = 0x09
    SIZEOF_INTERFACE_DESCRIPTOR,    // bLength
    DESC_TYPE_INTERFACE,            // bDescriptorType
    0x00,                           // bInterfaceNumber
    0x00,                           // bAlternateSetting
    1,                              // bNumEndpoints
    0xFF,                           // bInterfaceClass - vendor-specific
    0,                              // bInterfaceSubClass, zero for hub
    0,                              // bInterfaceProtocol
    0x00,                           // iInterface

    // Endpoint Descriptor, size = 0x07 for OEP1
    SIZEOF_ENDPOINT_DESCRIPTOR,     // bLength
    DESC_TYPE_ENDPOINT,             // bDescriptorType
    0x01 ,                          // bEndpointAddress; bit7=1 for IN, bits 3-0=1 for ep1
    EP_DESC_ATTR_TYPE_BULK,         // bmAttributes, bulk transfer
    0x40, 0x00,                     // wMaxPacketSize, 64 bytes
    0x00                            // bInterval
};

BYTE code abromStringDescriptor[SIZEOF_BOOTCODE_STRING_DESC_GROUP] = {
    // string index 0, language support
    4,
    3,
    0x09,0x04,                      // 0x0409 for English

    // string index 1, manufacture
    36,                             // Length of this string descriptor
    DESC_TYPE_STRING,
    'T',0x00,'e',0x00,'x',0x00,'a',0x00,'s',0x00,' ',0x00,
    'I',0x00,'n',0x00,'s',0x00,'t',0x00,'r',0x00,'u',0x00,
    'm',0x00,'e',0x00,'n',0x00,'t',0x00,'s',0x00,
    
    // string index 2, product
    42,                             // Length of this string descriptor
    DESC_TYPE_STRING,
    'T',0x00,'U',0x00,'S',0x00,'B',0x00,'3',0x00,'4',0x00,'1',0x00,'0',0x00,' ',0x00,
    'B',0x00,'o',0x00,'o',0x00,'t',0x00,' ',0x00,
    'D',0x00,'e',0x00,'v',0x00,'i',0x00,'c',0x00,'e',0x00,

    // string index 3, serial number
    34,                             // Length of this string descriptor
    DESC_TYPE_STRING,
    'T',0x00,'U',0x00,'S',0x00,'B',0x00,
    '3',0x00,'4',0x00,'1',0x00,'0',0x00,
    ' ',0x00,' ',0x00,' ',0x00,' ',0x00,
    ' ',0x00,' ',0x00,' ',0x00,' ',0x00
};
*/

/*----------------------------------------------------------------------------+
| Internal Variables                                                          |
+----------------------------------------------------------------------------*/
idata BYTE bConfigurationNumber;      // Set to 1 when USB device has been
                                // configured, set to 0 when unconfigured
idata BYTE bInterfaceNumber;          // interface number
WORD wBytesRemainingOnIEP0;     // For endpoint zero transmitter only
                                // Holds count of bytes remaining to be
                                // transmitted by endpoint 0.  A value
                                // of 0 means that a 0-length data packet
                                // A value of 0xFFFF means that transfer
                                // is complete.
idata WORD wBytesRemainingOnOEP0;     // For endpoint zero transmitter only
                                // Holds count of bytes remaining to be
                                // received by endpoint 0.  A value
                                // of 0 means that a 0-length data packet
                                // A value of 0xFFFF means that transfer
                                // is complete.
idata BOOL bHostAskMoreDataThanAvailable;
                                // If host ask more data then function has
                                // It will send one zero-length packet
                                // if the asked lenght is a multiple of
                                // max. size of endpoint 0
idata PBYTE pbIEP0Buffer;             // A buffer pointer to input end point 0
                                // Data sent back to host is copied from
                                // this pointed memory location
idata PBYTE pbOEP0Buffer;             // A buffer pointer to output end point 0
                                // Data sent from host is copied to
                                // this pointed memory location

idata BYTE abUsbRequestReturnData[USB_RETURN_DATA_LENGTH];


// for firmware download
//WORD wCurrentFirmwareAddress;   // for firmware downloading
//WORD wFirmwareLength;
//BYTE bFirmwareChecksum;
//BYTE bRAMChecksum;
//BOOL bExecuteFirmware;          // flag set by USB request to run the firmware
//BOOL bReboot;
idata BYTE bStatusAction;
//BYTE bLoadFirmwareFromI2C;
idata BYTE bFunctionSuspended=FALSE;        // TRUE if function is suspended

idata BYTE bRemoteWakeup;

/*----------------------------------------------------------------------------+
| Global Variables                                                            |
+----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------+
| Hardware Related Structure Definition                                       |
+----------------------------------------------------------------------------*/
#ifdef KEIL

//#pragma memory = dataseg(TUSB3410_EP0_EDB_SEG)
//tEDB0 tEndPoint0DescriptorBlock;
//#pragma memory = default
xdata tEDB0 tEndPoint0DescriptorBlock _at_ 0xff80;

//#pragma memory = dataseg(TUSB3410_SETUPPACKET_SEG)
//tDEVICE_REQUEST tSetupPacket;
//#pragma memory = default
xdata tDEVICE_REQUEST tSetupPacket _at_ 0xff00;

//#pragma memory = dataseg(TUSB3410_OEP_EDB_SEG)
//tEDB tOutputEndPointDescriptorBlock[3];
//#pragma memory = default
xdata tEDB tOutputEndPointDescriptorBlock[3] _at_ 0xff08;

//#pragma memory = dataseg(TUSB3410_IEP_EDB_SEG)
//tEDB tInputEndPointDescriptorBlock[3];
//#pragma memory = default
xdata tEDB tInputEndPointDescriptorBlock[3] _at_ 0xff48;

//#pragma memory = dataseg(TUSB3410_IEP0BUFFER_SEG)
//BYTE abIEP0Buffer[EP0_PACKET_SIZE];
//#pragma memory = default
xdata BYTE abIEP0Buffer[EP0_PACKET_SIZE] _at_ 0xfef8;

//#pragma memory = dataseg(TUSB3410_OEP0BUFFER_SEG)
//BYTE abOEP0Buffer[EP0_PACKET_SIZE];
//#pragma memory = default
xdata BYTE abOEP0Buffer[EP0_PACKET_SIZE] _at_ 0xfef0;

//#pragma memory = dataseg(TUSB3410_OEP1_X_BUFFER_SEG)
//BYTE pbXBufferAddress[0x40];
//#pragma memory = default

// User defined segment
//#pragma memory = dataseg(TUSB3410_DESC_SEG)
//BYTE abDescriptor[MAX_DESC_SIZE]; 
//#pragma memory = default
xdata BYTE abDescriptor[MAX_DESC_SIZE] _at_ 0xf840; 

#else

//#pragma memory = dataseg(TUSB3410_EXTERNAL_RAM_SEG)
//BYTE abDownloadFirmware[1024*16];
//#pragma memory = default

#pragma memory = dataseg(TUSB3410_EP0_EDB_SEG)
tEDB0 tEndPoint0DescriptorBlock;
#pragma memory = default

#pragma memory = dataseg(TUSB3410_SETUPPACKET_SEG)
tDEVICE_REQUEST tSetupPacket;
#pragma memory = default

#pragma memory = dataseg(TUSB3410_OEP_EDB_SEG)
tEDB tOutputEndPointDescriptorBlock[3];
#pragma memory = default

#pragma memory = dataseg(TUSB3410_IEP_EDB_SEG)
tEDB tInputEndPointDescriptorBlock[3];
#pragma memory = default

#pragma memory = dataseg(TUSB3410_IEP0BUFFER_SEG)
BYTE abIEP0Buffer[EP0_PACKET_SIZE];
#pragma memory = default

#pragma memory = dataseg(TUSB3410_OEP0BUFFER_SEG)
BYTE abOEP0Buffer[EP0_PACKET_SIZE];
#pragma memory = default

//#pragma memory = dataseg(TUSB3410_OEP1_X_BUFFER_SEG)
//BYTE pbXBufferAddress[0x40];
//#pragma memory = default

// User defined segment
#pragma memory = dataseg(TUSB3410_DESC_SEG)
BYTE abDescriptor[MAX_DESC_SIZE]; 
#pragma memory = default

//#pragma memory = dataseg(TUSB3410_XDATA_SEG)
//BYTE abStringDescriptor[sizeof(abromStringDescriptor)];
//#pragma memory = default

#endif
/*----------------------------------------------------------------------------+
| System Initialization Routines                                              |
+----------------------------------------------------------------------------*/
VOID UsbReset(VOID)
{
    RESET_WATCHDOG;

    wBytesRemainingOnIEP0   = NO_MORE_DATA;
    wBytesRemainingOnOEP0   = NO_MORE_DATA;
    bStatusAction           = STATUS_ACTION_NOTHING;

    pbIEP0Buffer            = (PBYTE)0x0000;
    pbOEP0Buffer            = (PBYTE)0x0000;
    bConfigurationNumber    = 0x00;         // device unconfigured
    bInterfaceNumber        = 0x00;         
//    bExecuteFirmware        = FALSE;        // a flag set by USB request
                                            // before bootocode hands over
                                            // control to firmware
//    wCurrentFirmwareAddress = 0x0000;
//    bRAMChecksum            = 0x00;
//    wFirmwareLength         = 0x0000;


    bFunctionSuspended      = FALSE;    
//    bReboot                 = FALSE;
//    bLoadFirmwareFromI2C    = FALSE;
//    bExecuteFirmware        = FALSE;

    // NAK both 0 endpoints and enable endpoint 0 interrupt
    tEndPoint0DescriptorBlock.bIEPBCNT = EPBCT_NAK;
    tEndPoint0DescriptorBlock.bOEPBCNT = EPBCT_NAK;
    tEndPoint0DescriptorBlock.bIEPCNFG = EPCNF_USBIE | EPCNF_UBME | EPCNF_STALL;    // 8 byte data packet
    tEndPoint0DescriptorBlock.bOEPCNFG = EPCNF_USBIE | EPCNF_UBME | EPCNF_STALL;    // 8 byte data packet
    
    // call user defined USB Reset routines
    UsbUserReset();

}

/*
//----------------------------------------------------------------------------
BYTE GetBCD(BYTE bByte)
{
    RESET_WATCHDOG;
    if(bByte > 9) return (bByte+('A'-10));
    else return (bByte + '0');
}
*/

//----------------------------------------------------------------------------
VOID UsbDataInitialization(VOID)
{
//    BYTE bTemp;

⌨️ 快捷键说明

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