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

📄 venreq.c

📁 Texas Instruments的TUSB3410芯片接键盘输入的固件程序源码和驱动程序源码。
💻 C
字号:
// (c)2002 by Texas Instruments Incorporated, All Rights Reserved.
/*----------------------------------------------------------------------------+
|                                                                             |
|                              Texas Instruments                              |
|                                                                             |
|                               Vendor Requests                               |
|                                                                             | 
+-----------------------------------------------------------------------------+
|  Source: VenReq.c 00.01 2002/04/19 16:49                                    |
|  Author: Ching-Hua Jim Chen Jim_Chen@ti.com                                 |
|                                                                             |
|  For more information, please contact                                       |
|                                                                             |
|  Jim Chen                                                                   |
|  Texas Instruments                                                          |
|  12500 TI Blvd, MS 8761                                                     |
|  Dallas, TX 75243                                                           |
|  USA                                                                        |
|                                                                             |
|  Tel 214-480-4656                                                           |
|  Fax 214-480-6043                                                           |
|                                                                             |
|  Release Notes:                                                             |
|                                                                             |
|  Logs:                                                                      |
|                                                                             |
|  WHO       WHEN         WHAT                                                |
|  ---       ----------   --------------------------------------------------  |
|  CJH       04/19/2002   born                                                |
|                                                                             |
+----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------+
| 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 "tusb3410.h"
#include "watchdog.h"
#include "sample.h"
#include "VenReq.h"
#include "rs232dbg.h"

/*----------------------------------------------------------------------------+
| External Function Prototype                                                 |
+----------------------------------------------------------------------------*/
VOID usbSendZeroLengthPacketOnIEP0(VOID);
VOID usbSendDataPacketOnEP0(PBYTE pbBuffer);
VOID usbStallEndpoint0(VOID);
/*----------------------------------------------------------------------------+
| External Variables                                                          |
+----------------------------------------------------------------------------*/
/*
#pragma memory = idata
extern BOOL bReboot;
extern BOOL bExecuteFirmware;
extern BYTE bConfigurationNumber; 
extern BYTE bInterfaceNumber;
extern BYTE abUsbRequestReturnData[4];
extern WORD wBytesRemainingOnIEP0;
#pragma memory = default
*/
extern WORD wBytesRemainingOnIEP0;

#ifdef KEIL
  extern xdata tEDB tOutputEndPointDescriptorBlock[3];// _at_ 0xff08; 
  extern xdata tEDB tInputEndPointDescriptorBlock[3];// _at_ 0xff48;

#else

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

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

/*----------------------------------------------------------------------------+
| Internal Type Definition & Macro                                            |
+----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------+
| Internal Constant Definition                                                |
+----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------+
| Internal Variables                                                          |
+----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------+
| Global Variables                                                            |
+----------------------------------------------------------------------------*/
BYTE abDbusConfig[4];
WORD wMonitorTimeout;
BYTE bControlFlags;

/*----------------------------------------------------------------------------+
| Hardware Related Structure Definition                                       |
+----------------------------------------------------------------------------*/
#ifdef KEIL
  extern xdata tDEVICE_REQUEST tSetupPacket;// _at_ 0xff00;

#else

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

#endif
/*----------------------------------------------------------------------------+
| System Initialization Routines                                              |
+----------------------------------------------------------------------------*/
void UsbUserReset(void)
{
    // enable endpoint 1 interrupt
    tInputEndPointDescriptorBlock[0].bEPCNF   = EPCNF_USBIE | EPCNF_UBME ;
    tInputEndPointDescriptorBlock[0].bEPBBAX  = (BYTE)((IEP1_X_BUFFER_ADDRESS >> 3) & 0x00ff);
    tInputEndPointDescriptorBlock[0].bEPBCTX  = EPBCT_NAK; //0x0000;
    tInputEndPointDescriptorBlock[0].bEPSIZXY = MAX_PACKET_SIZE;

    
    // enable endpoint 2 interrupt
    tOutputEndPointDescriptorBlock[1].bEPCNF   = EPCNF_USBIE | EPCNF_UBME ;
    tOutputEndPointDescriptorBlock[1].bEPBBAX  = (BYTE)((OEP2_X_BUFFER_ADDRESS >> 3) & 0x00ff);
    tOutputEndPointDescriptorBlock[1].bEPBCTX  = 0x00;
    tOutputEndPointDescriptorBlock[1].bEPSIZXY = MAX_PACKET_SIZE;
    
    // initialize DBus configuration parameters
    
    // Delay interval in uSecs between Transmit Bytes on DBUS
    abDbusConfig[0] = 0;
    
    // Monitoring interval in uSecs
    abDbusConfig[1] = DBUS_RVDELAY; // default 180 usec
    wMonitorTimeout = abDbusConfig[1]*DELAY10USECONDS/10;
    
    // Number of Bytes to buffer before automatically releasing Bulk-In buffer to pipe
    abDbusConfig[2] = RVRELEASE; // default 32 bytes
    
    // Control Flags
    //	b7(0) = don抰 clear error codes
    //	b7(1) = clear error codes
    //	b0(0) = on transmit error, flush current byte only
    //	b0(1) = on transmit error, flush all local (buffered) bytes on device
    //	b6-b1 : reserved, set to zero (0)
    abDbusConfig[3] = 0;
}    

/*----------------------------------------------------------------------------+
| General Subroutines                                                         |
+----------------------------------------------------------------------------*/
//----------------------------------------------------------------------------
void usbVendorRequest(void)
{
   
  RESET_WATCHDOG;
  
  if (tSetupPacket.bRequest == USB_REQ_SET_DBUS_T) {

    PUTS("VenReq T ");
    
    // set dbus transmitter configurable parameters
    abDbusConfig[0] = tSetupPacket.bValueL;
    
    bControlFlags = tSetupPacket.bValueH;
    // if bit7 of Control flags = 1 then clear bit 6-0 of error codes
    if ((bControlFlags & 0x80) != 0) abDbusConfig[3] &= 0x80;
    // if bit0 of Control flags = 1 then set bit 7 of error codes
    if ((bControlFlags & 1) != 0) abDbusConfig[3] |= 0x80;
    
    usbSendZeroLengthPacketOnIEP0();
    
  } else if (tSetupPacket.bRequest == USB_REQ_SET_DBUS_R) {
  
    PUTS("VenReq R ");
    
    // set dbus receiver configurable parameters
    if (tSetupPacket.bValueH > RVRELEASE) {
      PUTS("Stall All");
      usbStallEndpoint0();
      return;
    }  
    else if (tSetupPacket.bValueH == 0) { // if 0, use default value
      abDbusConfig[2] = RVRELEASE;
    }
    else {
      abDbusConfig[2] = tSetupPacket.bValueH;
      wMonitorTimeout = abDbusConfig[2]*DELAY10USECONDS/10;
    }  

    if (tSetupPacket.bValueL == 0) // if 0, use default
      abDbusConfig[1] = DBUS_RVDELAY;
    else
      abDbusConfig[1] =tSetupPacket.bValueL;
      
    usbSendZeroLengthPacketOnIEP0();
    
  } else if (tSetupPacket.bRequest == USB_REQ_GET_DBUS) {
  
    PUTS("VenReq G ");
    
    // return configurable parameters
    wBytesRemainingOnIEP0 = 4;
    usbSendDataPacketOnEP0((PBYTE) abDbusConfig);
    
  } else {
  
    PUTS("Stall All");
    
    // not supported, stall request
    usbStallEndpoint0();
    
  }
}

/*----------------------------------------------------------------------------+
| Interrupt Sub-routines                                                      |
+----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------+
| Main Routine (none)                                                         |
+----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------+
| End of source file                                                          |
+----------------------------------------------------------------------------*/
/*------------------------ Nothing Below This Line --------------------------*/

⌨️ 快捷键说明

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