|
Usb2Stream.DLL |
||||
| Index | ||||
| Basics about the parallel interfaces | ||||
| The FX2 has 2 different kinds of parallel interfaces which can me selected:
GPIF interfaceThe default GPIF waveform is selected and initialized by calling the function "SetDefaultGpifParams" before starting a stream. The default waveform works synchronous to a selectable 30 or 48 MHz internal clock. A divider value defines then the transfer speed of the bus. The minimal divider value is 2, the maximum is 255. The CTL0 line of the FX2 generates a synchronous clock signal: For streams from the PC to the FX2 the data will be latched on each rising edge of the CTL0 signal. For streams from FX2 to the PC the data bus is sampled on each rising edge of the CTL0 signal. The following diagram shows the Timing diagram of the default GPIF waveform.
User defined waveforms can also be used. The waveforms can be designed using the Cypress GPIF designer which can me downloaded from the Cypress website. It is important the the GPIF waveforms make use of long transfer mode i.e. the Transaction counter TC needs to be checked and the state machine may only pass over to the idle state if the transaction counter is expired. Slave FIFO interfaceStatus lines: CTL0 = /FE = low active fifo empty flag CTL1 = /FF = low active fifo full Flag Depending on the needed data transfer direction 2 IO pins need to be connected to the correct Level:
The slave fifo interface can be initialized by calling the "SetSlaveFifoParams" before starting a stream. Basically 2 kind of fifo interfaces can be selected:
| ||||
| information | ||||
| This Dll realizes the GPIF and Slave fifo interface of the FX2 Cypress controller. To exchange data with the user application a callback function has to be realized and set with the function SetCallBack. This Callback function will be called every time a new data packet was received or needs to be send depending on the selected streaming direction. All Dll functions return a boolean parameter which contains true if the function was executed successfully or false if an error occured.
|
||||
| Dll functions | ||||
| Basic functions | ||||
| ^ | SetCallBack | |||
|
function SetCallBack(CallBack : TUsbDataCallbackProc) : Boolean; stdcall; Set a callback function. Calling this function before starting streaming action is mandatory. The callback function needs to have the following signature: procedure Callbackname(pData : pointer; DatLen : DWord; PcToDevice : Boolean); stdcall; The callback function receives 3 parameters when beeing called:
|
||||
| ^ | SetDefaultGpifParams | |||
|
function SetDefaultGpifParams(MHz48 : Boolean; Divider : Byte; BitWidth : Byte) : Boolean; stdcall; This function specifies the Bitwidth (8 or 16) and
sample frequency. |
||||
| ^ |
StartStream |
|||
function
StartStream(PcToDevice : Boolean) : Boolean; stdcall;
|
||||
| ^ |
StopStream |
|||
Stops an active streaming process. This function might also be called
when streaming is not active |
||||
| ^ |
SetLicense |
|||
Activates the license. If the license is not set a nag-screen will be shown in irregular intervals.
|
||||
| ^ |
isHighSpeed |
|||
Returns TRUE if device is present and connected to a High speed 480 Mbps USB 2.0 Port. Otherwise it returns false. |
||||
| ^ | Status functions | |||
| ^ |
StreamActive |
|||
function StreamActive :
Boolean; stdcall;This function returns true if the streaming
process is currently active |
||||
| ^ |
LostPacketCount |
|||
function LostPacketCount :
DWord; stdcall;
LostPacketCount might be called after stopping a streaming process to
check if any USB data packets were lost. This function should return 0,
otherwise something went wrong. |
||||
| ^ |
StreamDevPresent |
|||
function StreamDevPresent :
Boolean; stdcall;
With StreamDevPresent you can check if the streaming device is connected and the driver installed correctly.
|
||||
| Advanced functions | ||||
| ^ |
SetGpifParams |
|||
function
SetGpifParams(pWaveData, pInitData : Pointer; IfConfig : Byte; BitWidth :
Byte) : Boolean; stdcall;
|
||||
| ^ | SetGpifParamsFromFile | |||
|
function SetGpifParamsFromFile(Filename :
PChar; BitWidth : Byte) : Boolean; stdcall; Set the GPIF interface parameters from a gpif.c file. Just pass the filename+path and select the Bitwidth (8 or 16) to set the gpif interface parameters. |
||||
| ^ | SetSlaveFifoParams | |||
|
function SetSlaveFifoParams(SyncFifo : Boolean; IfClkMode : Byte; BitWidth : Byte) : Boolean; stdcall; The Dll also realizes the Slave fifo interface from the FX2. To enable the Slave fifo mode just call this function before starting the stream. The parameters are:
To use the slave fifo interface some external connections are needed:
|
||||
| IO functions | ||||
| ^ |
SetPortDir |
|||
function
SetPortDir(PortNum, PortDir : Byte) : Boolean; stdcall;
Set the direction of PortA (PortNum=0), PortB (PortNum=1) or PortD (PortNum=2). If A Bit is 1 the correspondent Port-Pin is an output, otherwise it is an input. It is not needed to set the direction of the databus as it is done internally. |
||||
| ^ |
SetPortState |
|||
function
SetPortState(PortNum, PortState : Byte) : Boolean; stdcall;
Set the status of a complete Port (PortA=0, PortB=1, PortD=2) to "PortState".
|
||||
| ^ |
GetPortState |
|||
function
GetPortState(PortNum: Byte; Var PortState : Byte) : Boolean; stdcall;
Read the status from the selected Port to PortState.
|
||||
| ^ |
I2cTransfer |
|||
function
I2cTransfer(SlaveAddr : Byte; WriteLen, ReadLen : DWord; pWriteData,
pReadData : pByte) : Boolean; stdcall;Executes an I2c Read or Write transfer. This function writes the Data specified by pWriteData and WriteLen to the i2c device with address "SlaveAddr" and reads the amount of data specified by ReadLen to pReadData after the write transfer.
|
||||
| ^ |
SpiTransfer |
|||
function SpiTransfer(LsbFirst : Boolean; SPIMode : Byte;
Speed : Byte; PWrite, PRead : pByte; Len : Word) : Boolean; stdcall;
Executes a Spi transfer This function writes the Data specified by pWrite to the device. As an spi transfer is always bidirectional the read data will be written to the buffer passed to pRead. pRead can also be set to nul if you are not interested in the received data. The SPI bus function implement a SPI master and consists of 4 I/O lines: PortA.7 = /SS (Slave select - Output) PortA.6 = SCK (Clockline - Output)PortA.5 = MOSI (Master Out Slave In - Output) PortA.4 = MISO (Master In Slave Out - Output) Data is transfered bit-wise synchronous to SCK over the data lines MOSI and MISO. /SS gets low before a data byte will be transfered and high after a byte has been transfered. If LsbFirst is true (1), the first bit transfered is the LSB (Bit 0), if it is false (0), the MSB (Bit 7) will be transfered first.Speed selects the bitrate of the bus: 0 = 50 kHz SPIMode defines the idle state of the clockline and the edges data is transfered: Bit 0 = 0: The Idle state of SCK is 0. The leading
edge is a 0 to 1 transition, trailing edge a 1 to 0 transition Bit 1 = 0: Data is sampled at leading edge of SCK and
Setup on the trailing edge pWrite is an pointer to the data-block what needs to be send. pRead is a pointer to the buffer where the read data can be stored. If you’re not interested in the received data you can set pRead to null. pRead might point to the same address location as pWrite Len specifies the count of byte to be transfered.
|
||||
| ^ | ||||