Using the PDIUSBD12 USB system firmware program design

Introduction PDIUSBD12--USB interface device:
Summary
   PDIUSBD12 is a highly cost-effective USB device. It is commonly used as a micro controller system and microcontroller communication high speed general parallel interface. It also supports the local DMA transmission. The realization of USB interface standard assembly so that the designer can in a variety of different types of micro controller to choose the most suitable micro controller. This flexibility reduces development time, risk and costs ( through the use of the existing structure and reduce the firmware on investment ), to use the most efficient method to achieve the most economic USB peripheral solutions.
  PDIUSBD12 in full compliance with the USB1.1 version of the specification. It is also compatible with most devices classification specifications: imaging, mass storage device, communication device, a printing device and interface device. Similarly, PDIUSBD12 ideally suited for many peripherals, such as: printer, scanner, an external storage device ( Zip drive ) and digital camera etc. It makes use of the current SCSI system can immediately reduce cost. PDIUSBD12 has low hang power together with LazyClock output can meet the use of ACPI, OnNOW and USB power management requirements. Low operating power consumption can be applied using a bus-powered peripheral. It also incorporates many features, including SoftConnetTM, GoodLinkTM, programmable clock output, low frequency oscillator and termination of register sets. All these properties are significant cost savings for the system, and makes USB function in peripheral applications become easy.
Characteristic
Consistent with the universal serial bus ( USB ) version 1.1 specification;
High performance USB interface device, integrated the SIE, memory, FIFO transceiver and voltage regulator;
Compatible with most devices classification specifications;
Can be used with any external microcontroller / micro processing to realize the parallel interface ( 2M bytes / sec );
Fully autonomous direct memory access ( DMA ) operation;
Integration of multiple structure of FIFO memory 320 bytes;
The main endpoint of the double buffer is configured to increase the data throughput and easy to realize real-time data transmission;
In the batch mode and the synchronous mode can realize 1M byte / s data transfer rate;
With good characteristics of the EMI bus power supply capability;
When suspending control LazyClock output;
By software control with USB connection;
Using the technology of GoodLink connection indicator in communication, the LED flashes;
Programmable clock output;
With ACPI, OnNOW and USB power management requirements;
Internal power on reset and low voltage reset circuit;
SO28 and TSSOP28 package;
Industrial operating temperature: 40 DEG C to + 85 c;
Higher than the 8kV in slices of electrostatic protection circuit, reduce the cost of additional components;High error recovery rate ( > 99% ) of the full scan design to ensure a high quality;
Dual power operational: 3.3 + 0.3V or extension of the 5V power, range of 3.6 ~ 5.5V;Multiple interrupt mode to realize batch and synchronous transmission.
   Abstract: in the design of USB system, the firmware program is very important, it directly affects the development of product data transmission speed. With Phillips's USB control core sleep PDIUSBD12 as an example, introduced in the design and development of USB peripherals. The firmware and the role of the firmware program flow, and gives the corresponding program.
Key word.
  USB ( Universal Serial Bus ) universal serial bus, is now very popular a kind of fast, cheap, can be bidirectional, hot plug interface, now in each PC machine can be found on the USB interface. In the USB1.1 specification based on USB interface, maximum transmission speed of up to 12Mb / s: in the latest USB2.0 standard, can reach 480Mb / S. At the same time it can connect 127 USB devices, and the connection way is flexible, not only can use the serial connection, can also use the hub ( Hub ) a plurality of devices connected together, again with the PC USB interface is connected. In addition, it can also direct current is drawn from the system, without requiring a separate power supply system . USB these characteristics make it has obtained the widespread application. But convenient means development complex, mainly programming complexity greatly increased.
  In the design and development of a USB peripherals, developers need to write the three part of the main procedures : 1 firmware; the USB driver; client application. This article mainly elaborates the firmware program.
The 1 firmware to complete the main work
The firmware is FIREWARE corresponding Chinese words, it is actually a microcomputer program file, the language can be used C language or assembly language. Its mode of operation and hardware in close contact, including USB devices to be connected to USB protocol, interrupt processing, it is not a simple software, but a combination of software and hardware, the developers need on the port, interruption and hardware structure are very familiar with. The firmware program in MCU, when the device is connected to the host ( USB connecting wire is inserted into the jack ), the PC can be found in new equipment, and then establish a connection. Therefore. Written firmware program is one of the most primary purpose is to let Windows can detect and recognition device.
 2 PDIUSBD12 chip features
PDIUSBD12 is a performance optimization of USB device, usually for a microcontroller based system, and through the high-speed universal parallel interface and micro controller to communicate, and support the local DMA transmission. The device uses a modular approach to achieve a USB interface, allowing many available microcontroller and choose the most suitable as the system microcontroller, allow the use of existing architecture allows the firmware investment is reduced to the minimum. This flexibility reduces development time, cost and risk. The device enables the development of low cost and high performance USB peripheral equipment is an effective way. PDIUSDB12 completely accords with USB1.1 standard, can adapt to most equipment design specifications, such as imaging, large capacity storage, communications, printing and manual input device. Therefore, PDIUSBD12 is very suitable for many peripheral devices, such as printers, scanners, external memory (Zip drive) and digital cameras etc.. Now a lot of using SCSI to achieve a lot of equipment if used to achieve USB can directly reduce the cost.
PDIUSBD12 is also integrated with SoftConnect, GoodLink, programmable clock output, low frequency oscillator and a terminal resistance. All of these properties can be realized in a system to save cost, at the same time in the peripheral device is easy to achieve the more advanced features of USB.
  3 PDIUSBD12 firmware programUSB equipment start-up process is as follows:
( 1) the USB device to access USB port, send connection command USB;
( 2) the host sends a read device descriptor two;
( 3) the host according to device descriptor -- ID manufacturers, product ID, start the corresponding device drivers;
( 4) the device driver initialization of USB equipment;The reading device descriptor;In reading the configuration descriptor;The choice of interface, the endpoint (pipeline), determine the transmission mode.
  USB firmware procedure consists of three parts : 1 initialize microcontroller and all the peripheral circuits ( including PDIUSBD12 ); the portion of the main loop, its task is to can be interrupted; the interrupt service program, the task is sensitive to time, must be performed immediately. According to USB agreement, any transmission is by the host ( Host ) began. Single chip microcomputer as its working, wait for interrupt. The host must first send the token packet to the USB equipment ( this is the PDIUSBD12 ), PDIUSBD12 receives the token packet to send interrupt singlechip. Enter the interrupt service program, first read interrupt register to determine PDIUSBD12, USB token packet type, and then performs the corresponding operation. In the USB microcontroller program, to be completed on a token packet response, which is difficult to deal with is the SETUP package, is the main port 0 programming.
  SCM and PDIUSBD12 communication is mainly depending on the chip to send PDIUSBD12 commands and data to achieve. The PDIUSBD12 command word is divided into three kinds: ICW, data stream command word and general command word. PDIUSBD12 data handbook gives a command code and address. MCU to PDIUSBD12 command address orders, according to the different orders to send or read different data. Therefore, each command can be made with the function to achieve the function, each command, after a direct call function can be.
  The following procedure is to deal with host standard control request of a template:
  Unsigned char ENDPOINT_A0_FIFO [8 ]; / / determine the input is an SETUP request, and then read into the buffer ENDPOINT_A0_FIFO ... If ( ( ENDPOINT_A0_FIFO [0 ] & 0b011000000 ) = = 0x00 ) {if ( ENDPOINT_A0_FIFO [1 ] < = 0C ( ) { StandardFunctionTable [ ENDPOINT_A0_FIFO [1 ] ] ) ( return ); } } ... Const void ( StandardFunctionTable [ ] ) ( void ) = {GetSatus, ClearFeature, USB_Reserved, SetFeature, USB_Reserved, SetAddress, GetDescriptor, SetDescriptor, GetConfiguration, SetConfiguration, GetInterface, SetInterface, SynchFrame};
  USB equipment used in normal before, must by the host device configuration. The host will generally from the USB device to obtain configuration information and then determine the equipment which function.
  As configured to operate as part of, a host will equipment configuration values, if necessary will choose the proper interface optional equipment. The initialization function:
  Void D12_int ( ) {XmtBuff.pNum = 16; D12_COMMAND = 0xf4; / / read interrupt register ist = D12_DATA; ist = D12_DATA; if ( IST & 0x01 ) { / / ENDP0_OUT XmtBuff.out = 0; XmtBuff.in = 1; D12_COMMAND = 0x40; / / OUT ist last state = D12_DATA; if ( IST & 0x20 ) / / received SETUP packet {Setup_read ( ); Setup_control ( ); } else {Setup_read ( ); } } else if ( IST & 0x02 ) { / / ENDP0_IN XmtBuff.in = 1; D12_COMMAND = 0x41; / / in ist = D12_DATA USB_submit last state; ( ); } else if ( IST & 0x04 ) / / ENDP1_OUT {XmtBuff.out = 2; XmtBuff.in = 3; D12_COMMAND = 0x42; / / out ist = D12_DATA read_out last state; ( ); } else if ( IST & 0x08 ) { / / ENDP1_IN XmtBuff.in = 3; D12_COMMAND = 0x43; / / in ist = D12_DATA XmtBuff.b last state [0 ]; = 5; XmtBuff.wrLength = 1; XmtBuff.p = XmtBuff.b; USB_submit ( ); } ... ...
  In a connected USB command, the host reads device descriptor, then sends a set USB address SETUP package, set the USB address of host, client driver and device initialization. The rest of the endpoint ( ENDPOINT ) and so on.
  In its header file defined in the USB specification of various descriptor format, including equipment description table, configuration description table, interface description table, endpoint descriptor table, string description table and table types. Thus, in sending configuration, interface ( 1 ), the endpoint (1 ), interface ( 2 ), points ( 2), ... ,, and other manufacturers ] United description table, host USBD according to describe the type of identification of various description table.
  The following is a firmware program portion of the main loop:
  # include / / point to external access address # define D12_COMMAND ( D12 * ( unsigned char XDATA ) define D12_DATA ( 0xff01 ) # * ( unsigned char XDATA ) 0x7f02 ) extern void D12_int ( ); sbit D12_suspend = P1 ^ 0; sbit D12_int_n = P1 ^ 1; sbit D12_eot_n = P1 ^ 2 sbit D12_DMAck_n; = P1 ^ 3; sbit D12_DMAreq = P1 ^ 4; void main ( void ) {unsigned char ist; P1 = 0xff; D12_COMMAND = 0xf3; D12_DATA = 0x06; / / set the pattern for 0 D12_DATA = 0x03; / / initialize frequency 12MHz D12_COMMAND = 0xd0; D12_DATA = 0x80; / / set the address 0 enable D12_COMMAND = 0xf3; / / connection to host D12_DATA = 0x16; while ( 1) {if (! D12_int_n ) {D12_int ( ); } } }