Texas Instruments TUSB5052 User Manual

Texas Instruments TUSB5052 User Manual

Usb/serial bridge controller
Hide thumbs Also See for TUSB5052:

Advertisement

Quick Links

Bootcode Document for
TUSB5052 USB/Serial Bridge
Controller
User's Guide
February 2004
MSDS Bus Solutions
SLLU021A

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the TUSB5052 and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Summary of Contents for Texas Instruments TUSB5052

  • Page 1 Bootcode Document for TUSB5052 USB/Serial Bridge Controller User’s Guide February 2004 MSDS Bus Solutions SLLU021A...
  • Page 2 TI product or service and is an unfair and deceptive business practice. TI is not responsible or liable for any such statements. Following are URLs where you can obtain information on other Texas Instruments products and application solutions:...
  • Page 3 TUSB5052. How to Use This Manual This document contains the following chapters: Chapter 1—Introduction Chapter 2—TUSB5052 USB Firmware Flow Chapter 3—Function Chapter 4—Bootcode Defaults Chapter 5—Header Format and Vendor USB Request Chapter 6—Programming Considerations and Bootcode File List Notational Conventions This document uses the following conventions.
  • Page 4 FCC Warning In syntax descriptions, the instruction, command, or directive is in a bold typeface font and parameters are in an italic typeface. Portions of a syntax that are in bold should be entered as shown; portions of a syntax that are in italics describe the type of information that should be entered.
  • Page 5: Table Of Contents

    ........... TUSB5052 USB Firmware Flow .
  • Page 6 ..........6-32 tusb5052.h UMP-Related Header File .
  • Page 7 Contents Figures 1−1 Main Routine ..............1−2 Interrupt Service Routine .
  • Page 8 viii...
  • Page 9: Introduction

    Introduction Chapter 1 illustrates the bootcode process with bootcode flow charts. It contains a description of the TUSB5052 bootcode document main program and a flow chart of the interrupt service routine, control (setup) endpoint handler, input endpoint 0 interrupt handler, output endpoint 0 handler, and the output endpoint 1 handler.
  • Page 10: Bootcode Main Program

    Bootcode Main Program 1.1 Bootcode Main Program After power-on reset, the bootcode copies predefined USB descriptors to the shared RAM. The first USB descriptor is the device descriptor. It describes the embedded function class, vendor ID, product ID, etc. The second USB descriptor is the configuration descriptor, which contains information such as how the device is powered, the number of configurations available, type and number of interfaces, and end-point descriptors.
  • Page 11: Main Routine

    Does EEPROM Download firmware to xdata RAM contain firmware? Read and copy VID and PID from EEPROM to TUSB5052 USB data initialization Is firmware Load firmware loaded and ready from USB to run? Disable all interrupts and switch...
  • Page 12: Interrupt Service Routine

    Interrupt Service Routine 1.2 Interrupt Service Routine Interrupt service is generated from external interrupt 0. TUSB5052 uses this interrupt for internal peripherals. This interrupt consists of input/output endpoints, setup packet, I C, UART, printer port, and DMA. The main service routine confirms the source of interrupt then notifies corresponding functions.
  • Page 13: Interrupt Service Routine

    Interrupt Service Routine Figure 1−2. Interrupt Service Routine Disable global interrupt Is output endpoint 0 Output endpoint 0 handler interrupt? Is output endpoint 1 Output endpoint 1 handler interrupt? Is input endpoint 0 Input endpoint 0 handler interrupt? Is setup packet received Setup packet interrupt handler interrupt?
  • Page 14: Control (Setup) Endpoint Handler

    Control (Setup) Endpoint Handler 1.3 Control (Setup) Endpoint Handler Once bootcode receives a setup packet from the host, a control packet interrupt handler acquires control from the interrupt service routine. This handler processes the incoming packet, performs the appropriate action, then returns control to the interrupt service routine, as shown in Figure 1−3.
  • Page 15: Output Endpoint 0 Handler

    Output Endpoint 0 Handler 1.5 Output Endpoint 0 Handler Figure 1−5 demonstrates the process bootcode uses to deal with an output endpoint 0 interrupt. Because bootcode does not support control write with a data stage, it merely clears the NAK bit in the handler. Figure 1−5.
  • Page 17: Tusb5052 Usb Firmware Flow

    Chapter 2 TUSB5052 USB Firmware Flow There are three types of control transfers in standard USB requests. Figure 2−1 through Figure 2−3 and Table 2−1 and Table 2−2 demonstrate the process bootcode uses to respond to each control transfer. Topic...
  • Page 18: Control Write Transfer With Data

    Control Write Transfer With Data (Bootcode does not support this) 2.1 Control Write Transfer With Data (Bootcode does not support this) Figure 2−1. Control Write Transfer With Data Setup stage Data stage Status stage More SETUP(0) OUT(1) OUT(0) OUT(0/1) IN(1) packets 1.
  • Page 19: Control Read Transfer

    Get descriptor of string Illegal requests, stall endpoint Get descriptor of interface Illegal requests, stall endpoint Get descriptor of endpoint Illegal requests, stall endpoint Get configuration Return bConfiguredFlag value Get interface No action and return zero TUSB5052 USB Firmware Flow...
  • Page 20 Control Read Transfer Figure 2−3. Control Read Setup stage Data stage Status stage More SETUP(0) IN(1) IN(0) IN(0/1) OUT(1) packets 1. Hardware generates interrupt 1. Hardware generates interrupt to 1. Hardware handles this but to MCU. MCU. does not generate interrupt 2.
  • Page 21: Function

    Chapter 3 Function Chapter 3 contains a bootcode module list with a functional description of each bootcode module. Topic Page Bootcode Functional Module List ......Function...
  • Page 22: Bootcode Functional Module List

    Bootcode Functional Module List 3.1 Bootcode Functional Module List 3.1.1 Bootcode.c File VOID FillEp0TxWithNextDataPacket (VOID) This function is alerted by an interrupt service routine if there is an IN token addressed to endpoint 0 from the host. This routine packetizes the remainder of the data and sends one packet to the host.
  • Page 23: I2C.c File

    Bootcode Functional Module List Interrupt [0x03] VOID EX0_int(VOID) All UMP-related interrupts are performed in this routine. It reads in vector numbers in order to determine the type of interrupt and notifies the appropriate functions. VOID main(VOID) This is performed by the interrupt service routine when a setup packet is received.
  • Page 25: Bootcode Defaults

    Chapter 4 Bootcode Defaults Chapter 4 lists the defaults used for hub and bootcode settings. There are tables in each category that list the offset, field, size, and value, and provide short descriptions for the hub, device, configuration, interface, and interrupt endpoint1 descriptors.
  • Page 26: Default Hub Settings

    Default Hub Settings 4.1 Default Hub Settings Table 4−1. Hub Descriptor Offset Field Size Value Description bLength 0x09 Size of this descriptor in bytes bDescriptorType 0x29 Device descriptor type bNbrPorts Number of downstream ports wHubCharacteristics 0x0D [1:0] Power switching = 01 (individual) [2] compound device = 1 [4:3] over-current protection mode = 01 (individual) [15:5] reserved = 0...
  • Page 27: Configuration Descriptor

    Default Hub Settings Table 4−3. Configuration Descriptor Offset Field Size Value Description bLlength Size of this descriptor in bytes bDescriptorType Configuration descriptor type wTotalLength 25 = 9 + 9 + 7 Total length of data returned for this configuration. Includes the combined length of all descriptors (configuration, interface, endpoint, and class- or vendor-specific) returned for this configuration.
  • Page 28: Default Bootcode Settings

    Max packet size for endpoint zero ID Vendor 0x0451 USB assigned vendor ID = TI ID Product 0x5052 TI part number=TUSB5052 BCD Device 0x0100 Device release number = 1.0 iManufacturer Index of string descriptor describing manufacturer iProduct Index of string descriptor describing product...
  • Page 29: Configuration Descriptor

    Default Bootcode Settings Table 4−7. Configuration Descriptor Offset Field Size Value Description bLlength Size of this descriptor in bytes bDescriptorType Configuration descriptor type wTotalLength 25 = 9 + 9 + 7 Total length of data returned for this configuration. Includes the combined length of all descriptors (configuration, interface, endpoint, and class- or vendor-specific) returned for this configuration.
  • Page 30: Output Endpoint 1 Descriptor

    Default Bootcode Settings Table 4−9. Output Endpoint 1 Descriptor Offset Field Size Value Description bLength Size of this descriptor in bytes bDescriptorType Endpoint descriptor type bEndpointAddress 0x01 Bits 3−0: The endpoint number Bit 7: Direction 0 = OUT endpoint 1 = IN endpoint bmAttributes Bits 1−0: Transfer type 10 = Bulk...
  • Page 31: External Memory Write

    Chapter 5 Header Format and Vendor USB Request Chapter 5 explains the header format. It describes the product signature and descriptors and gives examples for ease of understanding. There are also tables that list the offset, field, size, value, and description for the USB info basic descriptor, as well as the USB info basic and firmware basic descriptor.
  • Page 32: Header Format

    5.1.1 Product Signature There are two bytes for a signature field. They are identical to the product number. For example, UMP (TUSB5052) is 0x5052. TUSB2136 is 0x2136. Numerical order is LSB first. 5.1.2 Descriptor Each descriptor contains a prefix and content.
  • Page 33: Examples

    Examples 5.2 Examples 5.2.1 USB Info Basic Descriptor Table 5−1 contains generic USB information for the bootcode. Once the bootcode loads the data and verifies the checksum, it then copies information to corresponding registers. The last byte is a zero, which indicates the end of the descriptor.
  • Page 34: Usb Info Basic And Firmware Basic Descriptor

    Examples Table 5−2. USB Info Basic and Firmware Basic Descriptor Offset Type Size Value Description Signature0 0x52 FUNCTION_PID_L Signature1 0x51 FUNCTION_PID_H Data type 0x01 USB info basic Data size (low byte) 0x08 Size of descriptor content (8 bytes total) Data size (high byte) 0x00 Check sum 0x45...
  • Page 35: Built-In Vendor-Specific Usb Requests

    Built-In Vendor-Specific USB Requests † 5.3 Built-In Vendor-Specific USB Requests 5.3.1 Get Bootcode Status bmRequestType USB_REQ_TYPE_DEVICE | 1100 0000b USB_REQ_TYPE_VENDOR | USB_REQ_TYPE_IN bRequest BTC_GET_BOOTCODE_STATUS 0x80 wValue None 0x0000 wIndex None 0x0000 wLength Size of the status 0x0004 Data Bootcode status data 0xNNNN Bootcode returns the 4-byte status value.
  • Page 36: Prepare For Header Update

    Update Header 5.3.4 Prepare for Header Update bmRequestType USB_REQ_TYPE_DEVICE | 0100 0000b USB_REQ_TYPE_VENDOR | USB_REQ_TYPE_OUT bRequest BTC_PRE_UPDATE_HEADER 0x83 wValue None 0x0000 wIndex None 0x0000 wLength None 0x0000 Data None This command tells bootcode that pending data downloaded through the output endpoint 1 is a header file rather than firmware. The following procedures update the header file.
  • Page 37: Reboot

    Reboot 5.5 Reboot bmRequestType USB_REQ_TYPE_DEVICE | 0100 0000b USB_REQ_TYPE_VENDOR | USB_REQ_TYPE_OUT bRequest BTC_REBOOT 0x85 wValue None 0x0000 wIndex None 0x0000 wLength None 0x0000 Data None This command forces bootcode to reboot (start over). bRequest values from 0x86 to 0x8E are reserved. 5.6 Force Execute Firmware bmRequestType USB_REQ_TYPE_DEVICE |...
  • Page 38 External Memory Write 5.8 External Memory Write bmRequestType USB_REQ_TYPE_DEVICE | 0100 0000b USB_REQ_TYPE_VENDOR | USB_REQ_TYPE_OUT bRequest BTC_EXTERNAL_MEMORY_WRITE 0x91 wValue HI: 0x00 0x00NN LO: Data wIndex Data address 0xNNNN (from 0x0000 to 0xFFFF) wLength None 0x0000 Data None This command instructs bootcode to write data to the specified address. 5.9 I C Memory Read bmRequestType...
  • Page 39 I2C Memory Write 5.10 I C Memory Write bmRequestType USB_REQ_TYPE_DEVICE | 0100 0000b USB_REQ_TYPE_VENDOR | USB_REQ_TYPE_OUT bRequest BTC_I2C_MEMORY_WRITE 0x93 wValue HI: I C device number 0xNNNN LO: Data wIndex Data address 0xNNNN (from 0x0000 to 0xFFFF) wLength None 0x0000 Data None This command instructs the bootcode to write data to the specified address.
  • Page 40 5-10...
  • Page 41 ....... 6-32 tusb5052.h UMP-Related Header File ......
  • Page 42: Vector Interrupt Values And Sources

    Programming Considerations 6.1 Programming Considerations 6.1.1 USB Requests For each USB request the firmware follows these steps, which ensure proper hardware operation. 1) Firmware first sets NAK bit on both input data endpoint 0 and output data endpoint 0, clears the interrupt sources, then clears the VECINT register. For example, for a setup packet, the firmware must clear the USB- STA_SETUP bit by writing a 1 to the bit of the register.
  • Page 43 Programming Considerations Table 6−1. Vector Interrupt Values and Sources (Continued) G[3:0] I[2:0] VECTOR Interrupt Source Interrupt Source should be (Hex) (Hex) (Hex) cleared I2C TXE interrupt I2CSTA/VECINT registers I2C RXF interrupt I2CSTA/VECINT registers Input endpoint 0 VECINT register Output endpoint 0 VECINT register 4−7 48−4E...
  • Page 44 0x02 = Application Code 0x03..0xEF Reserved 0xff = Reserved for Extended Data | Data Size Size of Data 9 for TUSB5052 & TUSB2136 Usb Info| Check Sum Check Sum of Data Section Bit Setting Bit 0: Bus/self power in bUSBCRL...
  • Page 45 // End point 0’s max packet size = 8 HUB_VID_L,HUB_VID_H, // Vendor ID for device, TI=0x0451 FUNCTION_PID_L,FUNCTION_PID_H, // Product ID for device, TUSB5052 0x00,0x01, // Revision level of device, Rev=1.0 // Index of manufacturer name string desc // Index of product name string desc...
  • Page 46 WORD wCurrentUploadPointer; // in header.c extern BYTE bi2cDeviceAddress; // in header.c #pragma memory = default /*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+ TUSB5052 Register Structure Definition +−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*/ #pragma memory = dataseg(TUSB5052_SETUPPACKET_SEG) // 0xff00 tDEVICE_REQUEST tSetupPacket; #pragma memory = default #pragma memory = dataseg(TUSB5052_EP0_EDB_SEG) // 0xff80 tEDB0 tEndPoint0DescriptorBlock;...
  • Page 47 File List tEDB tOutputEndPointDescriptorBlock[1]; #pragma memory = default #pragma memory = dataseg(TUSB5052_IEP0BUFFER_SEG) // 0xfef8 BYTE abIEP0Buffer[EP0_MAX_PACKET_SIZE]; #pragma memory = default #pragma memory = dataseg(TUSB5052_OEP0BUFFER_SEG) // 0xfef0 BYTE abOEP0Buffer[EP0_MAX_PACKET_SIZE]; #pragma memory = default #pragma memory = dataseg(TUSB5052_DESC_SEG) // 0xfc00 BYTE abDeviceDescriptor[SIZEOF_DEVICE_DESCRIPTOR]; BYTE abConfigurationDescriptorGroup[SIZEOF_BOOTCODE_CONFIG_DESC_GROUP];...
  • Page 48 File List //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− VOID TransmitBufferOnEp0(PBYTE pbBuffer) pbEp0Buffer = pbBuffer; // Limit wLength to FEh if (tSetupPacket.bLengthH != 0){ tSetupPacket.bLengthH = 0; tSetupPacket.bLengthL = 0xFE; // Limit transfer size to wLength if needed // this prevent USB device sending ’more than require’ data back to the host if (bEp0TxBytesRemaining >...
  • Page 49 File List // while firmware still in the previous transfer. tEndPoint0DescriptorBlock.bIEPCNFG &= ~EPCNF_STALL; tEndPoint0DescriptorBlock.bOEPCNFG &= ~EPCNF_STALL; abReturnBuffer[0] = 0; abReturnBuffer[1] = 0; abReturnBuffer[2] = 0; switch(tSetupPacket.bmRequestType & USB_REQ_TYPE_MASK) case USB_REQ_TYPE_STANDARD: // check if high byte of wIndex is p184 of spec 1.1 if((tSetupPacket.bIndexH != 0x00)){ StallEndPoint0();...
  • Page 50 File List break; case USB_REQ_TYPE_ENDPOINT: // Endpoint number is in low byte of wIndex bTemp = tSetupPacket.bIndexL & EP_DESC_ADDR_EP_NUM; if(bTemp==0){ // EndPoint 0 if(tSetupPacket.bIndexL & EP_DESC_ADDR_DIR_IN) // input endpoint abReturnBuffer[0] = (BYTE) (tEndPoint0DescriptorBlock.bIEPCNFG & EPCNF_STALL); else // output endpoint abReturnBuffer[0] = (BYTE) (tEndPoint0DescriptorBlock.bOEPCNFG &...
  • Page 51 File List case USB_REQ_TYPE_ENDPOINT: // Endpoint number is in low byte of wIndex if(tSetupPacket.bValueL == FEATURE_ENDPOINT_STALL){ bTemp = tSetupPacket.bIndexL & EP_DESC_ADDR_EP_NUM; if(bTemp){ if(bTemp > MAX_ENDPOINT_NUMBER){ StallEndPoint0(); return; bTemp−−; // EP is from EP1 to EP7 while C language start from 0 if(tSetupPacket.bIndexL &...
  • Page 52 File List tEndPoint0DescriptorBlock.bOEPCNFG |= EPCNF_STALL; switch (tSetupPacket.bmRequestType & USB_REQ_TYPE_RECIP_MASK) // Feature selector is in wValue case USB_REQ_TYPE_ENDPOINT: // Endpoint number is in low byte of wIndex if (tSetupPacket.bValueL == FEATURE_ENDPOINT_STALL){ bTemp = tSetupPacket.bIndexL & EP_DESC_ADDR_EP_NUM; // Ignore EP0 STALL, no reaon to have EP0 STALL if(bTemp){ // other endpoints if(bTemp >...
  • Page 53 File List // check if it is a write command if(InTransaction == TRUE){ // control write but direction is IN StallEndPoint0(); return; // control write, stall output endpoint 0 // wLength should be 0 in all cases tEndPoint0DescriptorBlock.bOEPCNFG |= EPCNF_STALL; if(tSetupPacket.bValueL <...
  • Page 54 File List if((tSetupPacket.bmRequestType & USB_REQ_TYPE_RECIP_MASK) != USB_REQ_TYPE_DEVICE){ StallEndPoint0(); return; // check if it is a read command if(InTransaction == FALSE){ // control read but direction is OUT StallEndPoint0(); return; // check if wIndex = 0x00 if(tSetupPacket.bIndexL != 0x00){ StallEndPoint0(); return; // check if wValue = 0x00 if((tSetupPacket.bValueL != 0x00) || (tSetupPacket.bValueH != 0x00)){ StallEndPoint0();...
  • Page 55 File List // check if bValueL is greater than 1 if(tSetupPacket.bValueL > 0x01){ StallEndPoint0(); return; bConfiguredFlag = tSetupPacket.bValueL; TransmitNullResponseOnEp0(); return; case USB_REQ_GET_INTERFACE: // check if recipient is interface if((tSetupPacket.bmRequestType & USB_REQ_TYPE_RECIP_MASK) != USB_REQ_TYPE_INTERFACE){ StallEndPoint0(); return; if(tSetupPacket.bIndexL != 0x00){ StallEndPoint0(); return; // check if it is a read command if(InTransaction == FALSE){ // control read but direction is OUT...
  • Page 56 File List // check if wLength = 0x00 if((tSetupPacket.bLengthL != 0x00) || (tSetupPacket.bLengthH != 0x00)){ StallEndPoint0(); return; // check if wValue = 0x00 if((tSetupPacket.bValueL != 0x00) || (tSetupPacket.bValueH != 0x00)){ StallEndPoint0(); return; // control write, stall output endpoint 0 // wLength should be 0 in all cases tEndPoint0DescriptorBlock.bOEPCNFG |= EPCNF_STALL;...
  • Page 57: I2C Memory Read

    File List wFirmwareLength = 0xffff; // skip firmware length/checksum TransmitNullResponseOnEp0(); break; case 0x84: // Update Header // bIndexH(BlockSize) // bIndexL(wait time) // wValueH(device type) // wValueL(device id) i2cSetMemoryType(tSetupPacket.bValueH); bi2cDeviceAddress = tSetupPacket.bValueL; if(UpdateHeader(wCurrentFirmwareAddress, tSetupPacket.bIndexH,tSetupPacket.bIndexL)==ERROR) StallEndPoint0(); else TransmitNullResponseOnEp0(); break; case 0x85: // reboot bExecuteFirmware = TRUE;...
  • Page 58: I2C Memory Write

    File List break; case 0x93: // i2c memory write wIndex = (WORD)(tSetupPacket.bIndexH << 0x08) + (WORD)tSetupPacket.bIndexL; // address write, bValueL(data), bValueH(device number) abReturnBuffer[0] = tSetupPacket.bValueL; if(i2cWrite(tSetupPacket.bValueH & MASK_I2C_DEVICE_ADDRESS,wIndex,1,&abReturnBuffer[0])== NO_ERROR){ DelaymSecond(0x05); TransmitNullResponseOnEp0(); }else StallEndPoint0(); break; case 0x94: // internal ROM memory read wIndex = (WORD)(tSetupPacket.bIndexH <<...
  • Page 59: Programming Considerations And Bootcode File List

    File List // wValueL(device id) i2cSetMemoryType(tSetupPacket.bValueH); bi2cDeviceAddress = tSetupPacket.bValueL; wIndex = (WORD)(tSetupPacket.bIndexH << 0x08) + (WORD)tSetupPacket.bIndexL; lcdI2cDump(wIndex,4); TransmitNullResponseOnEp0(); break; #endif default: // stall input and output endpoint 0 StallEndPoint0(); return; break; case USB_REQ_TYPE_CLASS: default: StallEndPoint0(); return; //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− VOID UsbDataInitialization(VOID) bFUNADR = 0x00;...
  • Page 60 File List //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− VOID CopyDefaultSettings(VOID) BYTE bTemp; // clear out status bits abBootCodeStatus[0] = 0x00; abBootCodeStatus[1] = 0x00; abBootCodeStatus[2] = 0x00; abBootCodeStatus[3] = 0x00; // disconnect from USB bUSBCTL = 0x00; // Disable endpoints EP1 tOutputEndPointDescriptorBlock[0].bEPCNF = 0x00; // set default values for hub bHUBPIDL = HUB_PID_L;...
  • Page 61 File List //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− VOID Ep0OutputInterruptHandler(VOID) // happened only in status stage // Bootrom doesn’t handle data stage of control write. // stall for any OUT, this is cleared in the setup stage. tEndPoint0DescriptorBlock.bOEPCNFG |= EPCNF_STALL; //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− VOID Ep1OutputInterruptHandler(VOID) BYTE bTemp,bSize,bCode; // check if it is the first packet if(wFirmwareLength == 0x0000){ wFirmwareLength...
  • Page 62 File List // check if firmware is ready if((WORD)wCurrentFirmwareAddress >= wFirmwareLength){ // check is checksum is correct if(bRAMChecksum == bFirmwareChecksum){ #ifdef SIMULATION lcdPutString(”USB Checksum Correct!”); DelaymSecond(2000); #endif bRAMChecksumCorrect = TRUE; bExecuteFirmware = TRUE; }else{ #ifdef SIMULATION lcdPutString(”USB Checksum Incorrect!”); DelaymSecond(2000); #endif bRAMChecksumCorrect = FALSE;...
  • Page 63 File List // clear reset flag bUSBSTA = USBSTA_RSTR; bVECINT = 0x00; break; default:break; // unknown interrupt ID = ENABLE; // Enable the interrupts again //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− #ifdef SIMULATION BYTE code abTestHeader[16] = { 0x52,0x51, // product ID 0x01, // Data Type (USB Info) 0x09,0x00, // Data Size (9 bytes) 0x80,...
  • Page 64 File List if(headerProcessCurrentDataType()==MSG_HEADER_NO_ERROR){ #ifdef SIMULATION lcdPutString(”usbinfo”); #endif bRAMChecksumCorrect = TRUE; if(headerGetDataType(2) == DATA_TYPE_HEADER_FIRMWARE_BASIC){ if(headerProcessCurrentDataType()==MSG_HEADER_NO_ERROR){ #ifdef SIMULATION lcdPutString(”firmware”); #endif bRAMChecksumCorrect = TRUE; bExecuteFirmware = TRUE; if(bExecuteFirmware == FALSE){ // use default value = ENABLE; // Enable global interrupt = ENABLE; // Enable interrupt 0 bUSBCTL |= USBCTL_CONT;...
  • Page 65 20000630 Bug fixed on wait for read for last byte in high speed. uC is too slow to set SRD bit. +−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*/ #include ”types.h” #include ”i2c.h” #include ”tusb5052.h” #ifdef I2C_TEST #include ”delay.h” #include ”gpio.h” #endif static BYTE bDeviceCategory; //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−...
  • Page 66 File List if( bType > I2C_CATEGORY_LAST) return; // invalid memory type else bDeviceCategory = bType; //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− BYTE i2cWaitForRead(VOID) // wait until data is ready or ERR=1 while((bI2CSTA & I2CSTA_RXF) != I2CSTA_RXF) if((bI2CSTA & I2CSTA_ERR) == I2CSTA_ERR){ bI2CSTA |= I2CSTA_ERR; // clear error flag return ERROR;...
  • Page 67 File List bI2CADR = (bTemp | BIT_I2C_READ); // setup read bI2CDAO = 0x00; // start read // SRD should be cleared if(wNumber > 1){ while(wNumber > 1){ if(i2cWaitForRead() != NO_ERROR) return ERROR; // bus error if(wNumber == 2) bI2CSTA |= I2CSTA_SRD; *pbDataArray++ = bI2CDAI;...
  • Page 68 File List // write the last byte bI2CSTA |= I2CSTA_SWR; // set SWR bit bI2CDAO = *pbDataArray; // write out the data if(i2cWaitForWrite() != NO_ERROR) return ERROR; // bus error return NO_ERROR; #ifdef I2C_TEST #define TEST_PATTERN_SIZE #define TEST_PAGE_SIZE #define TEST_SIZE_CAT3 0x4000 #define TEST_SIZE_CAT2 0x0100...
  • Page 69 File List for(wAddress = 0;wAddress < wSize;wAddress+=bTestPassternSize){ lcdPutStringXY(0,1,”Address : ”); lcdPutWord(wAddress); i2cWrite(0x00,wAddress,bTestPassternSize,&abTestPatternClear[0]); DelaymSecond(5); i2cWrite(0x00,wAddress,bTestPassternSize,&abTestPattern[0]); DelaymSecond(5); for(bTemp=0;bTemp<0x25;bTemp++) abRc[bTemp]=0x00; i2cRead(0x00,wAddress,bTestPassternSize,&abRc[0]); for(bTemp=0;bTemp<bTestPassternSize;bTemp++){ if(abRc[bTemp] != abTestPattern[bTemp]){ lcdPutStringXY(0,3,”ERROR!!”); lcdPutString(”read(”); lcdPutByte(abRc[bTemp]); lcdPutString(”)”); lcdPutString(”write(”); lcdPutByte(abTestPattern[bTemp]); lcdPutString(”)”); while(1); //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− VOID TestCat3Random(VOID) gpioInitialization(); lcdPutString(”Test i2c memory”); lcdPutString(”:Random R/W Test on CAT3”); TestRandom(I2C_CATEGORY_3,TEST_SIZE_CAT3);...
  • Page 70 File List //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− VOID LargePageReadPrepare(BYTE bCat,WORD wSize) WORD wAddress; BYTE bTemp; gpioInitialization(); lcdPutString(”Test i2c memory”); lcdPutString(”:Large Page Test”); i2cSetBusSpeed(I2C_400KHZ); i2cSetMemoryType(bCat); // write test pattern to i2c for(wAddress = 0;wAddress < wSize;wAddress++){ bTemp = (BYTE)(wAddress & 0xff); i2cWrite(0x00,wAddress,1,&bTemp); lcdPutStringXY(0,1,”Address : ”); lcdPutWord(wAddress);...
  • Page 71 File List //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− VOID main(VOID) DelaymSecond(10); gpioInitialization(); TestCat3Random(); TestCat3Page(); TestCat2Random(); TestCat2Page(); LargePageReadPrepare(I2C_CATEGORY_3,0x400); while(1); LargePageRead(I2C_CATEGORY_3,0x1010); lcdPutStringXY(0,3,”Done!”); while(1); #endif //−−−−−−−−−−−−−−−−−−−−−−−−−−−−− Cut along the line −−−−−−−−−−−−−−−−−−−−−−−−−−−− Programming Considerations and Bootcode File List 6-31...
  • Page 72: Header.c

    Fax 214−480−3443 Logs: WHEN WHAT 20000528 born +−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*/ #include <io51.h> // 8051 sfr definition #include ”types.h” #include ”tusb5052.h” #include ”header.h” #include ”i2c.h” #include ”usb.h” #include ”delay.h” #ifdef SIMULATION #include ”gpio.h” #endif #pragma memory = dataseg(TUSB5052_DESC_SEG) // 0xfc00 extern BYTE abDeviceDescriptor[SIZEOF_DEVICE_DESCRIPTOR];...
  • Page 73 header.c C Header Routines /*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+ Sub−routines go here... +−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*/ BYTE headerCheckProductIDonI2c(VOID) // in simulation, if error, abEepromHeader could be xx. abEepromHeader[0] = 0x00; abEepromHeader[1] = 0x00; abEepromHeader[2] = 0x00; abEepromHeader[3] = 0x00; if(i2cRead(bi2cDeviceAddress, 0x0000, 0x02, &abEepromHeader[0]) == NO_ERROR){ if((abEepromHeader[0] == FUNCTION_PID_L) && (abEepromHeader[1] == FUNCTION_PID_H)){ bCurrentHeaderMediumType = DATA_MEDIUM_HEADER_I2C;...
  • Page 74 header.c C Header Routines // only support i2c due to memory size BYTE headerGetDataType(WORD wNumber) WORD wAddress; tHeaderPrefix tData; bCurrentDataType = DATA_TYPE_HEADER_END; wAddress = OFFSET_HEADER_FIRST_DATA_SECTION; if(bCurrentHeaderMediumType == DATA_MEDIUM_HEADER_I2C){ while(wNumber != 0x0000){ i2cRead(bi2cDeviceAddress, wAddress, sizeof(tHeaderPrefix),(PBYTE)&tData); bCurrentDataType = tData.bDataType; wCurrentDataSize = (WORD)tData.bDataSize_L; wCurrentDataSize += (WORD)(tData.bDataSize_H <<...
  • Page 75 header.c C Header Routines WORD wTemp,wAddress; tHeaderUsbInfoBasic *ptUsbInfoBasic; wAddress = ulCurrentHeaderPointer; ptUsbInfoBasic = (tHeaderUsbInfoBasic *)abEepromHeader; if(i2cRead(bi2cDeviceAddress,wAddress, wCurrentDataSize, &abEepromHeader[0x0000]) != NO_ERROR) return ERROR; // get check sum bChecksum = 0x00; for(wTemp=0x0000;wTemp<wCurrentDataSize;wTemp++) bChecksum += abEepromHeader[wTemp]; // check if the data is for hub info if(bChecksum == bCurrentDataChecksum){ // download VID and VIP Information from EEPROM bHUBVIDL = ptUsbInfoBasic−>bVID_L;...
  • Page 76 header.c C Header Routines }else{ #ifdef SIMULATION lcdPutString(”Bus!”); #endif }else{ #ifdef SIMULATION lcdPutString(”IDCSERR!”); //lcdPutByte(bCurrentDataChecksum); //lcdPutByte(bChecksum); //lcdExternalMemoryDump((WORD)&abEepromHeader[0],4); //while(1); #endif return ERROR; return NO_ERROR; //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− // only support i2c due to memory size BYTE headerProcessCurrentDataType(VOID) if(bCurrentHeaderMediumType == DATA_MEDIUM_HEADER_I2C){ if(bCurrentDataType == DATA_TYPE_HEADER_HUB_INFO_BASIC){ if(LoadUsbInfoBasicFromI2c() == ERROR) return MSG_HEADER_CHECKSUM_ERROR; }else if(bCurrentDataType == DATA_TYPE_HEADER_FIRMWARE_BASIC){ if(LoadFirmwareBasicFromI2c() == ERROR) return MSG_HEADER_CHECKSUM_ERROR;...
  • Page 77 header.c C Header Routines if(wHeaderSize >= (WORD)bBlockSize){ // writer each block if(i2cWrite(bi2cDeviceAddress,wCurrentUploadPointer, (WORD)bBlockSize,(PBYTE)&abDownloadFirmware[wAddress]) != NO_ERROR) return ERROR; wCurrentUploadPointer = wCurrentUploadPointer + (WORD)bBlockSize; wAddress = wAddress + (WORD)bBlockSize; DelaymSecond((WORD)bWaitTime); }while((wAddress + (WORD)bBlockSize) <= wHeaderSize); // writer partial block while(wAddress < wHeaderSize){ if(i2cWrite(bi2cDeviceAddress,wCurrentUploadPointer,0x0001, (PBYTE)&abDownloadFirmware[wAddress]) != NO_ERROR) return ERROR;...
  • Page 78 UMP-Related Header File 6.4 tusb5052.h UMP-Related Header File /*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+ Texas Instruments TUSB5052 Header File +−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+ Source: tusb5052.h, v 1.0 2000/01/21 15:12:03 Author: Horng−Ming Lobo Tai lobotai@ti.com Header: (none) For more information, contact Lobo Tai Texas Instruments 8505 Forest Lane, MS 8761 Dallas, TX 75243 Tel 972−480−3145...
  • Page 79 // char *pbExternalRAM = (char *)0x010000; #define pbExternalRAM ((char xdata *)0x0000) // use this for the future design #define pbInternalROM ((char code *)0x0000) // TUSB5052 VID and PID Definition #define HUB_VID_L 0x51 // TI = 0x0451 #define HUB_VID_H 0x04 #define HUB_PID_L...
  • Page 80 UMP-Related Header File #define IEP5_X_BUFFER_ADDRESS 0xFC00 // Input Endpoint 5 X Buffer Base−address #define IEP5_Y_BUFFER_ADDRESS 0xFC40 // Input Endpoint 5 Y Buffer Base−address #define OEP5_X_BUFFER_ADDRESS 0xFC80 // Output Endpoint 5 X Buffer Base−address #define OEP5_Y_BUFFER_ADDRESS 0xFCC0 // Output Endpoint 5 Y Buffer Base−address...
  • Page 81 // Function Reset Interrupt Enable Bit // 0: disable, 1:enable #define USBCTL_DIR 0x01 // USB traffic direction 0: USB out packet, 1:in // packet (from TUSB5052 to The host) #define USBCTL_SIR 0x02 // Setup interrupt status bit // 0: SETUP interrupt is not served.
  • Page 82 UMP-Related Header File #define HUBCNF1_P3A 0x20 // Hub Port 3 connection bit // 0: removable, 1:fixed #define HUBCNF1_P4E 0x40 // Hub Port 4 enable/disable control bit // 0: disable, 1:enable #define HUBCNF1_P4A 0x80 // Hub Port 4 connection bit...
  • Page 83 UMP-Related Header File #define DMACSR_TIMEOUT_6MS 0x14 // Select Timeout 6ms Value #define DMACSR_TIMEOUT_7MS 0x18 // Select Timeout 7ms Value #define DMACSR_TIMEOUT_8MS 0x1C // Select Timeout 8ms Value #define DMACSR_TIMEOUT_9MS 0x20 // Select Timeout 9ms Value #define DMACSR_TIMEOUT_10MS 0x24 // Select Timeout 10ms Value...
  • Page 84 UMP-Related Header File #define BaudRate2000_DLH 0x00 #define BaudRate2400_DLL 0xC0 #define BaudRate2400_DLH 0x00 #define BaudRate3600_DLL 0x80 #define BaudRate3600_DLH 0x00 #define BaudRate4800_DLL 0x60 #define BaudRate4800_DLH 0x00 #define BaudRate7200_DLL 0x40 #define BaudRate7200_DLH 0x00 #define BaudRate9600_DLL 0x30 #define BaudRate9600_DLH 0x00 #define BaudRate19200_DLL 0x18...
  • Page 85 UMP-Related Header File #define FCRL_485E 0x80 // RS485 enable bit // 0:normal, full duplex, 1:for RS485 #define MCR_URST 0x01 // UART Soft Reset // 0:Mornal operation, 1:UART Reset #define MCR_RCVE 0x02 // receiver enable bit // 0:disable, 1:enable #define MCR_LOOP...
  • Page 86 UMP-Related Header File #define MASK_TRIE 0x04 // TxRx interrupt // IEEE 1284 Registers #define PPMCR_MODE_SLECT_MASK 0x03 // Mode Select Mask #define PPMCR_CENTRONICS_MODE 0x00 // Select Centronics Mode #define PPMCR_SPP_MODE 0x01 // Select SPP Mode #define PPMCR_ECP_MODE 0x02 // Select ECP Mode...
  • Page 87 UMP-Related Header File #define IEPINT_ENDPOINT4_ENABLE 0x10 // Enable IEndpoint 4 Interrupt #define IEPINT_ENDPOINT5_ENABLE 0x20 // Enable IEndpoint 5 Interrupt #define IEPINT_ENDPOINT6_ENABLE 0x40 // Enable IEndpoint 6 Interrupt #define IEPINT_ENDPOINT7_ENABLE 0x80 // Enable IEndpoint 7 Interrupt #define IEPINT_ALL_DISABLE 0x00 // Disable All IEndpoint Interrupts...
  • Page 88 UMP-Related Header File // 0:disable, 1:enable #define I2CSTA_TIE 0x04 // I2C Transmitter Empty Interrupt Enable // 0:disable, 1:enable #define I2CSTA_TXE 0x08 // I2C Transmitter Empty // 0:full, 1:empty #define I2CSTA_400K 0x10 // I2C Speed Select // 0:100kHz, 1:400kHz #define I2CSTA_ERR...
  • Page 89 UMP-Related Header File #define bOEPBCTY3 (* (char xdata *)0xFF1E) // Output Endpoint 3 Y Byte Count #define bOEPBCTY4 (* (char xdata *)0xFF26) // Output Endpoint 4 Y Byte Count #define bOEPBCTY5 (* (char xdata *)0xFF2E) // Output Endpoint 5 Y Byte Count...
  • Page 90 UMP-Related Header File // Endpoint 0 Descriptor Registers #define bIEPCNFG0 (* (char xdata *)0xFF80) // Input Endpoint Configuration Register #define bIEPBCNT0 (* (char xdata *)0xFF81) // Input Endpoint 0 Byte Count #define bOEPCNFG0 (* (char xdata *)0xFF82) // Output Endpoint Configuration Register...
  • Page 91 UMP-Related Header File #define bDMACDR3 (* (char xdata *)0xFFE4) // DMA Channel 3 Definition Register // for UART 1 Receiver #define bDMACSR3 (* (char xdata *)0xFFE5) // DMA Channel 3 Control & Status Register #define bDMACDR4 (* (char xdata *)0xFFE6)
  • Page 92: Usb.h Usb-Related Header File

    USB-Related Header File 6.5 usb.h USB-Related Header File /*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+ Texas Instruments USB Header File +−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+ Source: usb.h, v 1.0 99/02/01 10:05:58 Author: Horng−Ming Lobo Tai lobotai@ti.com Header: (none) For more information, contact Lobo Tai Texas Instruments 8505 Forest Lane, MS 8761 Dallas, TX 75243 Tel 972−480−3145...
  • Page 93 usb.h USB-Related Header File // Standard Device Requests #define USB_REQ_GET_STATUS #define USB_REQ_CLEAR_FEATURE #define USB_REQ_SET_FEATURE #define USB_REQ_SET_ADDRESS #define USB_REQ_GET_DESCRIPTOR #define USB_REQ_SET_DESCRIPTOR #define USB_REQ_GET_CONFIGURATION #define USB_REQ_SET_CONFIGURATION #define USB_REQ_GET_INTERFACE #define USB_REQ_SET_INTERFACE #define USB_REQ_SYNCH_FRAME Descriptor Type Values #define DESC_TYPE_DEVICE // Device Descriptor (Type 1) #define DESC_TYPE_CONFIG // Configuration Descriptor (Type 2) #define DESC_TYPE_STRING...
  • Page 94 usb.h USB-Related Header File BYTE bLength; // Length of this descriptor (9h bytes) BYTE bDescriptorType; // Type code of this descriptor (02h) WORD wTotalLength; // Size of this config desc plus all interface, // endpoint, class, and vendor descriptors BYTE bNumInterfaces;...
  • Page 95: Types.h Type Definition Header File

    Type Definition Header File 6.6 types.h Type Definition Header File /*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+ Texas Instruments USB to Multiport Controller Type definition +−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+ Source: types.h, v 1.0 99/01/26 14:34:34 Author: Horng−Ming Lobo Tai lobotai@ti.com Header: (none) For more information, contact Lobo Tai...
  • Page 96 C-Related Header File 6.7 i2c.h C-Related Header File /*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+ Texas Instruments I2C Header File +−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+ Source: i2c.h, v 1.0 1999/11/24 16:01:49 Author: Horng−Ming Lobo Tai lobotai@ti.com Header: (none) For more information, contact Lobo Tai Texas Instruments 12500 TI Blvd, MS 8761 Dallas, TX 75243 Tel 214−480−3145...
  • Page 97 i2c.h C-Related Header File #define I2C_CATEGORY_3 #define I2C_CATEGORY_LAST #define BIT_I2C_READ #define BIT_I2C_DEVICE_TYPE_MEMORY 0xA0 #define MASK_I2C_DEVICE_ADDRESS 0x07 #ifdef __cplusplus #endif #endif //−−−−−−−−−−−−−−−−−−−−−−−−−−−−− Cut along the line −−−−−−−−−−−−−−−−−−−−−−−−−−−− Programming Considerations and Bootcode File List 6-57...
  • Page 98: Header.h

    Keyboard Hub Micro−Controller Header +−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+ Source: header.h, v 1.0 2000/05/28 12:59:29 Author: Horng−Ming Lobo Tai lobotai@ti.com Header: (none) For more information, contact Lobo Tai Texas Instruments 12500 TI BLVD, MS8761 Dallas, TX 75243 Tel 214−480−3145 Fax 214−480−3443 Logs: WHEN WHAT...
  • Page 99 header.h C Header-Process-Related Header File } tFirmwareRevision, *ptFirmwareRevision; typedef struct _tHeaderUsbInfoBasic BYTE bBitSetting; // Bit 0: Bus/self power in bUSBCRL // Bit 6: Individual/Gang Power Control // Bit 7: PWRSW BYTE bVID_L; // Vendor ID BYTE bVID_H; BYTE bPID_HUB_L; // Hub Product ID BYTE bPID_HUB_H;...
  • Page 100 6-60...

Table of Contents