This is an old revision of the document!


ECB USB FIFO

Introduction

The ECB-USB-FIFO board provides a high-speed interface for an EuroCard Bus machine to talk to a modern PC over USB. The board is based around the widely supported FTDI FT232H chip operating in “245-style asynchronous FIFO” mode. To avoid the need to solder surface-mount parts the Adafruit FT232H Breakout board is used.

On the PC the interface is presented as a standard USB serial interface (a “Virtual COM port” on Windows, /dev/ttyUSB* on Linux) and can be used by any application normally used with standard serial ports. Note that although it presents as a serial port, the baud rate and other serial settings configured on the Virtual COM Port are ignored, it just provides an 8-bit clean path at whatever rate you can pump data in or out of it.

The FT232H has a separate FIFO (first-in-first-out queue) for the receive and transmit directions. Each FIFO is 1KB in size. In the receive direction (PC to ECB) the operating system decides when to transmit data and can send up to 512 bytes in a single USB transfer. In the transmit direction (ECB to PC) the FT232H will accumulate data until 512 bytes has been received, or some period of time (believed to be around 17ms) has passed since the last byte was queued, or when a “send immediate” signal is given.

The board supports generating interrupts on either (or both) of two conditions: data waiting in receive FIFO, or space available in transmit FIFO. The interrupt can be routed to ECB lines NMI, INT, IR0–IR7. Enabling and masking of interrupts is under software control.

In addition to the 8-bit data path through the FIFO, there are two GPIO data lines (one input and one output) connected from the FT232H to the Status Register. These are not currently used but they were “free” to add to the design. To make use of them I believe you would need to use the FTDI MPSSE commands.

ECB I/O Registers

The ECB-USB-FIFO board decodes four adjacent I/O registers. The user can choose the top 6 bits (A2–A7) of the I/O address so it can be located anywhere in the I/O address space. The recommended base address is 0x0C (so the card occupies addresses 0x0C–0x0F).

The register use is as follows:

I/O addressRegister use
BASE+0 (0x0C)Read: Remove one byte of data from the receive FIFO
Write: Insert one byte of data into the transmit FIFO
BASE+1 (0x0D)Read: Read the Status Register
Write: Write to the Status Register (note that not all bits are writable)
BASE+2 (0x0E)Read: No effect (junk value is returned)
Write: Send Immediate – any data queued in the transmit FIFO is sent over the USB at the earliest opportunity. Without this the data will be queued until a timeout (~17ms) expires. Note that the value written to the register is ignored, any value written to the register will trigger the Send Immediate signal.
BASE+3 (0x0F)Read: No effect (junk value is returned)
Write: No effect

The Status Register bits have the following meanings:

Bit (Value)Meaning
0 (0x01)TX_FULL: read-only
0 if the transmit FIFO has space available,
1 if the transmit FIFO is full.
Any writes to the FIFO will be ignored while the transmit FIFO is full.
1 (0x02)INT_ENABLE: read/write
0 if interrupts are disabled,
1 if interrupts are enabled.
2 (0x04)INT_TX: read/write
0 if interrupts will not be generated to report transmit FIFO state,
1 if an interrupt will be generated when the transmit FIFO has space available (providing INT_ENABLE is also set).
3 (0x08)INT_RX: read/write
0 if interrupts will not be generated to report receive FIFO state,
1 if an interrupt will be generated when the receive FIFO has space available (providing INT_ENABLE is also set).
4 (0x10)GPIO_IN: read/write
Single bit GPIO, output from ECB, input to FT232H
5 (0x20)GPIO_OUT: read-only
Single bit GPIO, output from FT232H, input to ECB
6 (0x40)IRQ: read-only
0 if no interrupt would be requested providing INT_ENABLE is also set,
1 if an interrupt would be requested providing INT_ENABLE is also set.
7 (0x80)RX_EMPTY: read-only
0 if the receive FIFO contains queued data,
1 if the receive FIFO is empty.
Any reads from the FIFO while it is empty will return junk values.

The INT_TX and INT_RX bits in the Status Register control the conditions under which an interrupt will be requested. The IRQ bit always reflects if either condition is met regardless of the value of INT_ENABLE. The bus interrupt line will be asserted only when the INT_ENABLE bit is also set. In other words, the bus interrupt line is asserted only when INT_TX and/or INT_RX are set, one or both of the relevant conditions is met, and INT_ENABLE is also set. So, for example, software which wants to receive an interrupt when data arrives in the receive FIFO over USB should set both INT_RX and INT_ENABLE. If the interrupt line is shared with multiple devices the interrupt service routine can then check the IRQ bit to determine if the USB-FIFO card is requesting the interrupt before calling the USB-FIFO interrupt handler code.

When the USB cable is disconnected, TX_FULL =1 and RX_EMPTY =1 indicating (correctly!) that data cannot be transferred in either direction.

When the ECB machine is reset, the INT_ENABLE, INT_TX, INT_RX and GPIO_IN bits are all reset to 0. The USB connection is not reset (ie the virtual serial device will remain connected).

ECB Card Jumpers

J1: Reset input selector. Jumper 1-2 for legacy (DIN pin C31), or jumper 2-3 for Kontron (DIN pin C26). Kontron style (2-3) is recommended.

J2: I/O address selection. The top 6 bits of the I/O address can be set here. Presence of a jumper indicates a 0 bit, absence of a jumper indicates a 1 bit. Recommended configuration is to fit jumpers on A4, A5, A6, A7 to select I/O addresses 000011xx, ie 0x0C–0x0F.

J3: Interrupt line selection. Install at most one jumper to select the bus line to which the interrupt request signal will be routed. Recommended configuration is “IRQ” on Z80/Z180 machines, and “IR1” on 68K machines. If interrupts are not required the jumper may be omitted.

Schematic

Bill of Materials

ComponentDescriptionExample Part
C147uF electrolytic capacitor, 0.2” lead spacingPanasonic ECA-2AHG470 (Farnell order code 9694617)
C2–C110.1uF multilayer ceramic capacitor, 0.2” lead spacingMulticomp MCRR50104X7RK0050 (Farnell order code 1216440)
C12No component (see Notes on Construction)-
RR122K bussed resistor network: 8 resistors, 9 pinsBOURNS 4609X-101-223LF (Farnell order code 9356924)
R1, R22.2K ohm 0.25W (or 0.125W) resistorMulticomp MF25 2K2 (Farnell order code 9341536)
R3Wire jumper (see Notes on Construction)Use excess lead cut off from a resistor
J11×3 0.1“ headerTE Connectivity part 5-826629-0: 1×50 contact breakaway header strip (Farnell order code 3418388)
J22×6 0.1” headerTE Connectivity part 5-826632-0: 2×50 contact breakaway header strip (Farnell order code 3418560)
J32×10 0.1“ headerTE Connectivity part 5-826632-0: 2×50 contact breakaway header strip (Farnell order code 3418560)
U1, U3, U974LS244TI SN74LS244N (Farnell order code 1739688)
U274LS245TI SN74LS245N (Farnell order code 1106085)
U474LS688TI SN74LS688N (Farnell order code 1470949)
U574LS38TI SN74LS38N (Farnell order code 1470758)
U674LS139ATI SN74LS139AN (Farnell order code 9592296)
U7, U1174LS32TI SN74LS32N (Farnell order code 1740030)
U874LS175TI SN74LS175N (Farnell order code 1607731)
U10Adafruit FT232H Breakout (product 2264)Mouser order code 485-2264, Digikey order code 1528-1449-ND
U12DIN 41612 Connector, Type C Plug, 96 pinTE Connectivity 5650913-5 (Farnell order code 1557020)
(qty 5)20 pin DIP IC socketMulticomp SPC15501 (Farnell order code 2678574)
(qty 2)16 pin DIP IC socketTE Connectivity 1-2199298-4 (Farnell order code 2445622)
(qty 3)14 pin DIP IC socketTE Connectivity 1-2199298-3 (Farnell order code 2445621)

Notes on Construction

Important note on R3, C12: Footprints are provided for these components but they should not normally be required. No component should be fitted at C12. A wire jumper should be fitted at R3.

The FT232H /WRITE signal is active on the falling edge of the signal, instead of the standard rising edge. To ensure the data signals are steady for long enough to meet its setup time requirements, the write signal is delayed by routing it through a few gates in U3 and U7. R3 and C12 can form an LC circuit used to extend this delay if required. Alternatively the delay can be shortened by omitting the wire jumper at R3 and connecting U3 pin 17 to U3 pins 5, 7 or 13. Testing indicates that the standard delay should suit all current Retrobrew Computers systems and so the LC circuit components should not be required.

The Adafruit FT232H breakout board can be permanently mounted using either 0.1” breakaway header strips soldered to both boards, or it can be made removable using SIL pin strips and sockets (eg Harwin D01-9922046 and D01-9973246) which allows it to be re-used for other projects.

The FT232H breakout board contains a serial EEPROM which must be programmed to configure the FT232H to use the correct operating mode (“245 Asynchronous FIFO”). This can be done over USB from a PC. The EEPROM needs to be programmed one time only.

For Windows you need to use the FT_PROG utility which can be freely downloaded from the FTDI web site. I've made a template that you can load into the FT_PROG program. The program is a bit counter-intuitive so here are some brief instructions: Connect the USB device, run FT_PROG, load the provided XML template. Tell FT_PROG to scan for devices, then right-click on the FT232H USB device (not the template) and tell it to apply the loaded template. This sets the desired configuration for the device. Click the “Program Devices” button in the toolbar, then click the “Program” button. This writes the configuration to the EEPROM.

For Linux I have written a short C program which uses libftdi1 to program the EEPROM. The tarball contains both the source code and a binary with libftdi1 statically linked in. Ensure the FT232H board is the only connected FTDI device (just in case it tries to overwrite the EEPROM in other devices!) and then run “sudo ./program-eeprom -w” to program the device. Running “sudo ./program-eeprom” (without the “-w” option) will report the current EEPROM contents.

For MacOS I had success running FT_PROG in a virtual Windows machine (using Parallels Desktop) using the USB passthrough feature.

It is recommended to use 74LS series parts on this board, at the time of writing it has not been tested with substitutions from other 74 series logic families. In particular U1, U2 and U3 benefit from having hysteresis (Schmitt triggers) on the inputs, which the 74LS244 and 74LS245 parts have.

Photographs

ecb-usb-fifo-assembled.jpg

Example Code

Note that this code has been optimised on a Z180. On Z80 it may be faster to replace the JR instructions with JP (untested).

FIFO_BASE       = 0x0C
FIFO_DATA       = (FIFO_BASE+0)
FIFO_STATUS     = (FIFO_BASE+1)
FIFO_SEND_IMM   = (FIFO_BASE+2)

; Receive a block of length DE bytes from the FIFO to memory starting at address HL
fifo_receive:
        ; Enter with:
        ;   HL = pointer to data buffer
        ;   DE = number of bytes to transmit
        ld b, e                 ; setup loop counter
        dec de
        inc d
        ld c, #FIFO_DATA        ; load port address
waitrx:
        in a, (FIFO_STATUS)
        rla                     ; RX_EMPTY bit into carry flag
        jr c, waitrx            ; loop until data ready
        ini                     ; read from port C, write to HL, HL++, B--
        jr nz, waitrx           ; INI sets Z flag to indicate new value of B
        dec d
        jr nz, waitrx
        ret

; Transmit a block of length DE bytes to the FIFO from memory starting at address HL
fifo_transmit:
        ; Enter with:
        ;   HL = pointer to data buffer
        ;   DE = number of bytes to transmit
        ld b, e                 ; setup loop counter
        dec de
        inc d
        ld c, #FIFO_DATA        ; load port address
waittx:
        in a, (FIFO_STATUS)
        rra                     ; TX_FULL bit into carry flag
        jr c, waittx            ; loop while tx fifo full
        outi                    ; read from HL, write to port C, HL++, B--
        jr nz, waittx           ; OUTI sets Z flag to indicate new value of B
        dec d
        jr nz, waittx
        ret

; Request transfer of transmitted data ASAP (without this it is delayed up to 17ms)
fifo_flush:
        out (FIFO_SEND_IMM), a  ; we can write any value to the register
        ret

Untested idea: For writes up to 512 bytes in length, I believe you could signal a Send Immediate, then poll for the RX_EMPTY bit, and then proceed to load up to 512 bytes into the transmit FIFO without checking the RX_EMPTY bit again (using the OTIR instruction, or an unrolled loop of OUTIs). I believe the 1KB FIFO in the FT232H is divided into two 512-byte buffers and one is loaded with data while the other is transferred over USB, so once any space in the buffer becomes available you can be confident there is at least 512 bytes of space available. Again, this is untested, but could allow for very fast transmission.


boards/ecb/usb-fifo/start.1489998492.txt.gz · Last modified: 2017/03/20 04:28 by will
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0