Summary of the invention
The technical problem to be solved in the present invention is, at the above-mentioned defective of prior art, provides a kind of FPGA of use to realize device and the LPC-USB and the USB-LPC data transfer device of LPC-USB two-way communication.
The technical solution adopted for the present invention to solve the technical problems is: construct a kind of device that uses FPGA to realize the LPC-USB two-way communication, comprise lpc bus, usb bus, field programmable logic device and USB module; The control of described field programmable logic device is finished by protocol conversion and the transmission of lpc bus to the LPC data of usb bus to usb data, and finishes by protocol conversion and the transmission of usb bus to the usb data of lpc bus to the LPC data; Described USB module is used to realize the exchanges data of described field programmable logic device and usb bus;
Described field programmable logic device comprises: LPC-USB protocol conversion module, USB-LPC protocol conversion module, first buffer zone and second buffer zone;
Wherein, the LPC-USB protocol conversion module is used to receive the LPC data that lpc bus sends, and it is carried out sending to first buffer zone after the protocol conversion;
First buffer zone is used for by the buffer memory of LPC data to usb data protocol conversion and transport process data, and has played a good clock zone buffer action;
Second buffer zone is used to receive the usb data that the USB module sends, and is used for by the buffer memory of usb data to conversion of LPC data protocol and transport process data, and has played a good clock zone buffer action;
The USB-LPC protocol conversion module is used to receive the usb data of second buffer zone output, and it is carried out sending lpc bus after the protocol conversion.
Realize that at use FPGA of the present invention described first buffer zone and second buffer zone all are the fifo buffers that can carry out 16K byte reading and writing data in the device of LPC-USB two-way communication.
Realize in the device of LPC-USB two-way communication that at use of the present invention FPGA the enable signal of writing of described first buffer zone links to each other, reads that enable signal links to each other with the control end of described USB module, clock signal links to each other with the control end of described lpc bus with the USB module respectively with the control end of described lpc bus.
Realize in the device of LPC-USB two-way communication that at use of the present invention FPGA the enable signal of reading of described second buffer zone links to each other, writes that enable signal links to each other with the control end of described USB module, clock signal links to each other with the control end of described lpc bus with the USB module respectively with the control end of described lpc bus.
Realize in the device of LPC-USB two-way communication at use FPGA of the present invention, described field programmable logic device also comprises: the clock control administration module, it comprises input end, first output terminal and second output terminal, wherein, input end links to each other with outside global clock pin, the clock same-phase of the output of first output terminal and input end, the clock antiphase of the output of second output terminal and input end.
According to another aspect of the present invention, provide a kind of at using FPGA to realize the LPC-USB data transfer device of the device of LPC-USB two-way communication, it may further comprise the steps:
S11, current state is set is initial state;
S12, when the Senior Three position of described lpc bus is 011 and frame signal when being 1, it is address state that current state is set;
S13, reception 32 bit address, it is data mode that current state is set;
S14, reception 8 bit data, it is the TAR1 state that current state is set;
S15, when described lpc bus is 1111 and frame signal when being 1, judge whether low 20 of described 32 bit address are 0XD0000, if it is sync state that current state is set, otherwise, enter step S1:
S16, described 8 bit data are sent to first buffer zone;
S17, end LPC-USB data-switching.
In LPC-USB data transfer device of the present invention, also comprise between step S11 and S12: it is high-impedance state that described lpc bus is set, and the enable signal of writing of first buffer zone puts 0;
In LPC-USB data transfer device of the present invention, in step S13, receive 4 bit address in each LPC_CLK clock period, through 8 LPC_CLK clock period, receive described 32 bit address.
In LPC-USB data transfer device of the present invention, in step S14, receive 4 bit data in each LPC_CLK clock period, through 2 LPC_CLK clock period, receive described 8 bit data.
In LPC-USB data transfer device of the present invention, in step S16, before sending described 8 bit data, comprise that also the enable signal of writing that first buffer zone is set is 1, and described lpc bus is set is 0000.
According to a further aspect of the invention, provide a kind of at using FPGA to realize the USB-LPC data transfer device of the device of LPC-USB two-way communication, it may further comprise the steps:
S21, current state is set is initial state;
S22, when the Senior Three position of described lpc bus is 010 and frame signal when being 1, it is address state that current state is set;
S23, reception 32 bit address, it is the TAR1 state that current state is set;
S24, when described lpc bus is 1111 and frame signal when being 1, judge whether low 20 of described 32 bit address are 0XD0001 or 0XD0002, if it is sync state that current state is set, and described lpc bus is set is 0101, otherwise, enter step S21;
S25, judge whether low 20 of described 32 bit address are 0XD0001, if enter step S26; Otherwise, enter step S27;
S26, the data of described second buffer zone output are sent in 8 the data register;
S27, current state is set is data mode, be provided with described lpc bus be 0000 and the enable signal of reading that described second buffer zone is set be 0;
S28, judge whether low 20 of described 32 bit address are 0XD0001, if enter step S29; Otherwise, enter step S210;
S29, the data that will be stored in described 8 data register send to described USB-LPC protocol conversion module;
S210, the 1st LPC_CLK clock period, high 2 positions 11 of described lpc bus, the empty marking signal assignment of described second buffer zone is given described lpc bus the 1st, the full scale will signal assignment of described first buffer zone is given described lpc bus the 0th, the 2nd LPC_CLK clock period, it is 1111 that described lpc bus is set;
S211, end USB-LPC data-switching.
In USB-LPC data transfer device of the present invention, also comprise between described step S21 and S22: it is high-impedance state that described lpc bus is set, and the enable signal of reading of second buffer zone puts 0.
In USB-LPC data transfer device of the present invention, in step S23, receive 4 bit address in each LPC_CLK clock period, through 8 LPC_CLK clock period, receive described 32 bit address.
In USB-LPC data transfer device of the present invention, in step S29, the 1st LPC_CLK clock period, low 4 of being stored in data in described 8 data register are sent to described USB-LPC protocol conversion module, the 2nd LPC_CLK clock period, high 4 of being stored in data in described 8 data register are sent to described USB-LPC protocol conversion module
Implement device and LPC-USB and USB-LPC data transfer device that use FPGA of the present invention realizes the LPC-USB two-way communication, has following beneficial effect: utilize FPGA to realize the full-duplex communication of lpc bus and usb bus, satisfy some particular application, two or many computing machine short-range communication problems, and do not need by realizing by other media.This device is set up two FIFO by FPGA and USB control chip scheme in FPGA inside, substitute plug-in FIFO, and reached high integrated, therefore the integrated circuit board area is accomplished minimum, and the while power consumption is accomplished minimum, and cost is accomplished minimum.In addition, utilize FIFO to have and take the few characteristic of port, make it in PC, only need take address space, thereby save address space greatly less than 2 bytes.Simultaneously, utilized the characteristic of FPGA parallel high-speed, made this programme can satisfy the high speed full-duplex communication.
Embodiment
Realize device one application-specific of LPC-USB two-way communication for use FPGA of the present invention, mainly be between device A and equipment B, to carry out exchanges data, wherein device A is carried out the transmitting-receiving of data by lpc bus, and equipment B is carried out the transmitting-receiving of data by usb bus.As shown in Figure 1, use FPGA to realize comprising lpc bus, usb bus, field programmable logic device and USB module among this embodiment of device of LPC-USB two-way communication in the present invention; The control of this field programmable logic device is finished by protocol conversion and the transmission of lpc bus to the LPC data of usb bus to usb data, and finishes by protocol conversion and the transmission of usb bus to the usb data of lpc bus to the LPC data; The USB module is used to realize the exchanges data of field programmable logic device and usb bus; Comprise for this field programmable logic device: LPC-USB protocol conversion module, USB-LPC protocol conversion module, first buffer zone (FIF01) and second buffer zone (FIFO2); Wherein, the LPC-USB protocol conversion module is used to receive the LPC data that lpc bus sends, and it is carried out sending to first buffer zone after the protocol conversion; First buffer zone is used for by the buffer memory of LPC data to usb data protocol conversion and transport process data, and has played a good clock zone buffer action; Second buffer zone is used to receive the usb data that the USB module sends, and is used for by the buffer memory of usb data to conversion of LPC data protocol and transport process data, and has played a good clock zone buffer action; The USB-LPC protocol conversion module is used to receive the usb data of second buffer zone output, and it is carried out sending lpc bus after the protocol conversion.As shown in Figure 6, first buffer zone and second buffer zone all are the fifo buffers that can carry out the 16K reading and writing data.In addition, this field programmable logic device also comprises CLKV module (clock control administration module), and this CLKV module mainly realizes the control and management to clock.The outside is sent to the clock of FPGA by the global clock pin, divides two-way output, the one tunnel with the clock same-phase of input, the one tunnel with the clock antiphase of input, as the reference clock of FPGA program design.In specific design, the device of the present patent application is also to claim the TOP module by utilization top layer software, IO interface with the definition whole procedure, and the input and output of external interface and each realized that the sub-module of concrete function is connected, realizing the logical relation between them, and realized mutual with the USB module simultaneously.
In concrete work, device A is sent to FPGA to data by lpc bus, and produces check code simultaneously, through the processing of FPGA, protocol conversion, give USB module data,, give USB interface data by the processing of USB module, this moment the equipment B reading of data, and check its correctness, to determine whether to need to start retransmission mechanism, this process realizes the communication of lpc bus data to USB.Reverse direction, equipment B is given USB module data by USB interface, through the processing of USB module, carries out transmitted in packets, be sent to FPGA and generate check code, through the processing of FPGA module, protocol conversion is given lpc bus data, the device A reading of data, and check its correctness, to determine whether to need to start retransmission mechanism, this process realizes the communication of usb data to lpc bus.Thereby realized the full-duplex communication between lpc bus and the USB.
After system powers on, lpc bus sends data to USB if desired, then device A sends data to FPGA by lpc bus, produces check code simultaneously, through the processing of FPGA, carry out protocol conversion, data are sent to the USB module, and through the processing of USB module, equipment B is by the USB interface sense data, and check its correctness, to determine whether to need to start retransmission mechanism; USB sends data to lpc bus if desired, equipment B is given USB module data by USB interface, produces check code simultaneously, after the processing through the USB module, send data to FPGA,, carry out protocol conversion through the processing of FPGA module, data are sent to lpc bus, again by the device A sense data, and check its correctness, to determine whether to need to start retransmission mechanism.Lpc bus and USB be transceive data simultaneously, to realize the full-duplex communication between them.Whole data exchange process is the transmission data of a frame one frame, and receiving data also is the reception of a frame one frame; Some information that include this frame in each frame data simultaneously comprise the information of verification and error correction aspect; After reading of data, also read simultaneously the information aspect the verification,, then sent an information, started retransmission mechanism, allowed transmit leg resend this frame data, till transmission is correct if find in this frame that certain or some data are wrong.
In concrete the enforcement, fpga chip adopts the chip of the SPARTAN3A series of XILINX company, and concrete model is XC3S200A-4FT256C, and development platform is ISE9.2.It mainly contains three groups of signals: the lpc bus desired signal of communicating by letter with FPGA, the USB module desired signal of communicating by letter with FPGA, shared data line; The definition of concrete interface signal, as following table 1:
Signal name |
Direction |
Describe |
LPC_FRAME_IO |
IN |
The FRAME pin position of LPC |
LPC_RST_N_IO |
IN |
The LPC reset signal |
LPC_CLK_IO |
IN |
The LPC clock signal |
LPC_LAD_IO |
INOUT |
LPC data and address shared bus |
USB_CLK |
IN |
The USB clock signal |
F_FLAGA |
IN |
USB writes marking signal |
F_FLAGB |
IN |
USB reads marking signal |
F_SLOE |
OUT |
|
F_SLRD |
OUT |
|
F_SLWR |
OUT |
|
UD_D |
INOUT |
The shared data line |
Table 1
For the LPC-USB protocol conversion module, it is mainly according to the LPC standard, and the lpc bus write data is come, and in FPGA inside, by protocol conversion, the data that recognize is sent into first buffer zone of FPGA inside.There are various modes, this modular design mainly to utilize Memory Target WriteMode transmission data during lpc bus transmission data.Lpc bus has multiple different state when the transmission data, this module mainly realizes the conversion of different conditions with state machine, to realize that terminal computer is write FIFO1 by the data that lpc bus sends through after the protocol conversion.
Shown in Fig. 2 and 3, behind electrification reset, state machine enters initial state, and promptly current state is an initial state;
When each LPC_CLK rising edge clock comes to begin the judgement to current state temporarily;
When current state is initial state, at first make the data line of lpc bus place high-impedance state, the enable signal of writing of first buffer zone puts 0, when the data line that determines lpc bus is 0000 and frame signal when being 0, state machine is transferred to the DIR state, be that current state changes to the DIR state, otherwise allow current state be in initial state;
When current state is the DIR state, at first make the data line of lpc bus place high-impedance state, the enable signal of writing of first buffer zone puts 0, when the data line signal that determines lpc bus is 011 and frame signal when being 1, state machine is transferred to address state, be that current state changes to address state, otherwise allow its current state be in initial state;
When current state is address state, at first make the data line of lpc bus place high-impedance state, the enable signal of writing of first buffer zone puts 0, and each LPC_CLK clock period is transmitted 4 bit address, through 8 LPC_CLK clock period, the data line of 32 addresses by lpc bus sent, wherein high 12 ignore need not, low 20 effectively, state machine is transferred to data mode afterwards, be that current state changes to data mode, otherwise allow its current state be in address state;
When current state is data mode, at first make the data line of lpc bus place high-impedance state, the enable signal of writing of first buffer zone puts 0, each LPC_CLK clock period is transmitted 4 bit data, through 2 LPC_CLK clock period, the data line of 8 data by lpc bus sent, and state machine is transferred to the TAR1 state afterwards, and promptly current state changes to the TAR1 state;
When current state is the TAR1 state, the enable signal of writing of first buffer zone puts 0, when the data line that determines lpc bus is 1111 and frame signal when being 1, wait for 4 LPC_CLK clock period,, begin 20 bit address that address state sends are judged as the 5th LPC_CLK during the clock period, when being 0XD0000, state machine is transferred to sync state, and promptly current state changes to sync state, otherwise allows its current state be in initial state;
When current state is sync state, 8 bit data that send during data mode write the data input pin of FIF01, and the enable signal of writing of first buffer zone is put 1, and the data line of lpc bus puts 0000, state machine is transferred to the TAR2 state afterwards, and promptly current state changes to the TAR2 state;
When current state is the TAR2 state, the enable signal of writing of first buffer zone is put 0, the data line of lpc bus puts 1111, and state machine is transferred to the END state afterwards, and promptly current state changes to the END state;
When current state is the END state, the enable signal of writing of first buffer zone is put 0, the data line of lpc bus is put high-impedance state, and state machine is transferred to initial state afterwards, and promptly current state changes to initial state;
When other situations, the current state of state machine remains initial state.
For the USB-LPC protocol conversion module, this module is mainly according to the lpc bus standard, and in FPGA inside, through protocol conversion, the lpc bus reading of data is to terminal computer the data in second buffer zone.Various modes is arranged during the LPC reading of data, and what this design mainly utilized is Memory Target reading mode transmission data.Lpc bus has multiple different state when the transmission data, this module mainly realizes the conversion of different conditions with state machine, to realize the data read in second buffer zone to terminal computer.
Shown in Figure 4 and 5, behind electrification reset, state machine enters initial state, and promptly current state is an initial state;
When each LPC_CLK rising edge clock comes to begin the judgement to current state temporarily;
When current state is initial state, at first make the data line of lpc bus place high-impedance state, the enable signal of reading of second buffer zone puts 0, when the data line that determines lpc bus is 0000 and FRAME signal when being 0, state machine is transferred to the DIR state, be that current state changes to the DIR state, otherwise allow current state be in initial state;
When current state is the DIR state, the enable signal of reading of second buffer zone puts 0, and when the Senior Three position of the data line line that determines lpc bus is 010 and frame signal when being 1, state machine is transferred to address state, be that current state changes to address state, otherwise allow its current state be in initial state;
When current state is address state, at first make the data line line of lpc bus place high-impedance state, the enable signal of reading of second buffer zone puts 0, and each LPC_CLK clock period is transmitted 4 bit address, through 8 LPC_CLK clock period, the data line of 32 addresses by lpc bus transmitted, wherein high 12 ignore need not, low 20 effectively, state machine is transferred to the TAR1 state afterwards, be that current state changes to data mode, otherwise allow its current state be in address state;
When current state is the TAR1 state, the enable signal of reading of second buffer zone puts 0, when the bidirectional data line that determines lpc bus is 1111 and frame signal when being 1, wait for 1 LPC_CLK clock period, as the 2nd LPC_CLK during the clock period, begin 20 bit address that address state transmits are judged, when being 0XD0001 or when the 0XD0002, state machine is transferred to sync state and the data line of lpc bus is changed to 0101, be that current state changes to sync state and the data line of lpc bus is changed to 0101, otherwise allow its current state be in initial state;
When current state is sync state, operate as follows: when the address that determines the address state transmission is 0XD0001, preceding 2 LPC_CLK clock period, the enable signal of reading of second buffer zone puts 0, current state remains on sync state, the data line of lpc bus puts 0101, as the 3rd LPC_CLK during the clock period, the enable signal of reading of second buffer zone puts 1, the state machine current state remains on sync state, the data line of lpc bus is changed to 0101, the 4 LPC_CLK during the clock period, the data storage of the data output end of FIFO2 output in 8 data register, the enable signal of reading of second buffer zone puts 0, state machine is transferred to data mode, and promptly current state changes to data mode, and the data line of lpc bus is changed to 0000; When the address that determines the address state transmission is 0XD0002, at first the enable signal of reading of second buffer zone puts 0, preceding 3 LPC_CLK clock period, current state remains sync state, the data line signal of lpc bus is changed to 0101, the 4 LPC_CLK in the clock period, and state machine is transferred to data mode, be that current state is changed into data mode, the data line of lpc bus is changed to 0000; When the address that determines the address state transmission was other situations, the data line of lpc bus was changed to high-impedance state, and the enable signal of reading of second buffer zone puts 0, and state machine is transferred to initial state, and promptly current state is changed into initial state;
When current state is data mode, the enable signal of reading of second buffer zone puts 0, when the address that determines the address state transmission is 0XD0001, the 1st LPC_CLK clock period, low 4 bidirectional data lines that send lpc bus to that are stored in the data in 8 bit data register when the sync state, current state remains data mode simultaneously, the 2nd LPC_CLK clock period, high 4 data lines that send lpc bus to that are stored in the data in 8 bit data register when the sync state, state machine is transferred to the TAR2 state, and promptly current state is changed into the TAR2 state; When the address that determines the address state transmission is 0XD0002, the 1st LPC_CLK clock period, high 2 positions 11 of the data line of lpc bus, the empty marking signal assignment of FIFO2 is given bidirectional data line the 1st, the full scale will signal assignment of FIFO1 is given the 0th of data line of lpc bus, current state remains data mode simultaneously, the 2nd LPC_CLK clock period, the data line of lpc bus is changed to 1111, state machine is transferred to the TAR2 state, and promptly current state is changed into the TAR2 state; When the address that determines the address state transmission was other situations, state machine was transferred to initial state, and promptly current state is changed into initial state;
When current state was the TAR2 state, the enable signal of reading of second buffer zone put 0, and the bidirectional data line of lpc bus is changed to 1111, and state machine is transferred to the END state, and promptly current state is changed into the END state;
When current state is the END state, the enable signal of reading of second buffer zone is put 0, the data line of lpc bus is put high-impedance state, and state machine is transferred to initial state afterwards, and promptly current state changes to initial state;
When other situations, the current state of state machine remains initial state.
In force, first buffer zone, second buffer zone, CLKV module are mainly with utilizing Xilinx developing instrument ISE9.2 to generate IP CORE, wherein first buffer zone and second buffer zone are the FIFO of degree of depth 16K, utilize FPGA clock internal manager DCM to realize the CLKV module.First buffer zone is mainly realized the buffering of lpc bus write data, USB module read data.Lpc bus transmits data to first buffer zone by data input pin, the USB module is by data output end reading of data in first buffer zone, the enable signal of writing of first buffer zone links to each other with the lpc bus control end with clock signal, the enable signal of reading of first buffer zone links to each other with USB module controls end with clock signal, when first buffer zone is full, send FULL to indicate lpc bus, when first buffer empty, send EMPTY to indicate the USB module, when first buffer zone has 510 data empty again, send the PROG_EMPTY signal to the USB module.Second buffer zone is mainly realized the buffering of lpc bus read data, USB module write data.The USB module transmits data to second buffer zone by data input pin, lpc bus is by data output end reading of data in second buffer zone, the enable signal of reading of second buffer zone links to each other with the lpc bus control end with clock signal, the enable signal of writing of second buffer zone links to each other with the USB control end with clock signal, when second buffer zone is full, send FULL to indicate the USB module, when second buffer empty, send EMPTY to indicate lpc bus.
As shown in Figure 7, the USB module uses Cypress 68013A to change the controller of local bus as USB, and its is inner integrated enhancement mode 51 kernels can be done a lot of configurations to the related register in the usb communication, equally also can be used as standard 51 and call.Far Left is the USB transceiver, on transceiver the right is SIE (Serial Interface Engine), it also is in the communication of USB, the main unit of being responsible for, its inner integrated USB packing, give out a contract for a project, and packet receiving, the hardware circuit that unpacks, and stayed a large amount of registers, can allow 51 kernels dispose.SIE the right, and coupled be the configurable FIFO of 4KB, data enter FIFO from SIE, under the control of GPIF module or 51 kernels, outwards transmit in the mode of 8bit/16bit, just arrive Local bus, enter FPGA then.In the USB host-host protocol, our demand is: data volume want big and data transmission reliable, adopt the bulk transmission mode, it is to support wrong retransmission mechanism, in the configuration of FIFO, we have adopted 2 FIFO, a turnover, each 2Kbyte.
Be illustrated in figure 8 as the interface connection diagram of FPGA and USB module, and the physical interface definition, as shown in table 2 below:
Signal name |
Bit wide |
Direction |
Describe |
RDYO |
1 |
IN |
The empty zone bit that FPGA sends, sky is read in expression |
RDY1 |
1 |
IN |
The full zone bit that FPGA sends, expression is write full |
CTLO |
1 |
OUT |
The WEN# enable signal, FIFO's writes among the control FPGA |
CTL1 |
1 |
OUT |
The REN# enable signal, FIFO's reads among the control FPGA |
CTL2 |
1 |
OUT |
The OE# enable signal is chosen FIFO among the FPGA |
USB_CLK |
1 |
OUT |
USB is the synchronous clock of interface, 48MHz to FPGA |
Data |
|
8 |
INOUT |
Bi-directional data |
Table 2
The present invention describes by several specific embodiments, it will be appreciated by those skilled in the art that, without departing from the present invention, can also carry out various conversion and be equal to alternative the present invention.In addition, at particular condition or concrete condition, can make various modifications to the present invention, and not depart from the scope of the present invention.Therefore, the present invention is not limited to disclosed specific embodiment, and should comprise the whole embodiments that fall in the claim scope of the present invention.