Difference between revisions of "Programming the Ethernet controller"

From UConn PAN
Jump to navigation Jump to search
Line 74: Line 74:
  
 
[[FPGA_Idler|Idler (Idle Process Module)]]
 
[[FPGA_Idler|Idler (Idle Process Module)]]
 +
 +
[[FPGA_Reader|Packet Reader]] (Packet type inspection)
  
 
[[FPGA_Transmitter|Packet Transmitter]]
 
[[FPGA_Transmitter|Packet Transmitter]]
Line 89: Line 91:
  
  
== (011) Read Packet ==
 
 
Block 011 is the only block with switching between following states.  Its first task is to load the MAC data of the packet.  If filtering inside of the FPGA is required, this block is responsible for it.  The only MAC filtering likely to be needed is a check to see if the destination MAC address matches the MAC address of the CP2200/1, but the CP2200/1 should filter this itself (verify in the data sheet).  If the packet is bad, this block tells the CP2200/1 to skip the packet and returns to block 010.  The MAC filter would be the first substate.
 
 
After MAC filtering comes the second substate (or the only substate if MAC filtering is found to be unnecessary).  This reads the first byte of the packet's data and uses it as a switch to determine the transition to the next state:
 
{| align="center" cellpadding="4" border="0" cellspacing="0" style="text-align:center"
 
! ASCII
 
|   
 
! Next State
 
|-
 
| R ||      || 000
 
|-
 
| Q ||      || 100
 
|-
 
| P ||      || 110
 
|-
 
| other ||      || 010
 
|}
 
Anything other than the three defined packets is considered a bad packet and is discarded in the CP2200/1 before transitioning back to state 010.  An "R" packet obtains the reset mask from the second byte then discards the packet before transitioning to state 000.  State 000 assumes that the reset mask is held, so this output needs to be latched in place until the next time this block activates.  A query has no switches or masks on it, so a "Q" packet will be discarded from the CP2200/1 before continuing on.  A "P" packet has a large amount of data attached to it, so that is the only packet not discarded before continuing to the next state.  This allows later states to access the packet data, but also puts on those later states the responsibility for discarding the packet once finished with it.
 
 
inputs
 
* ''Clk'': clock
 
* ''/Rst'': asynchronous, active-low reset
 
* ''State'': 3-bit state value
 
* - transceiver control lines -
 
 
internal signals
 
* ''S_En'': state enable, ''S_En'' <= not (''St(2)'' or ''St(1)'' or ''St(0)'')
 
* ''Go'': when ''S_En'' goes high ''Go'' pulses for one cycle
 
 
blocks
 
* '''MAC Filter'''
 
** This block checks that the MAC address in the packet destination field is the same as the MAC address of the board.  If not the packet is discarded, if so then the MAC data (destination and source MAC address, packet length) are discarded and processing continues.
 
** inputs
 
*** ''Clk'': clock
 
*** ''/Rst'': asynchronous, active-low reset
 
*** ''Go'': pulse to begin
 
*** - transceiver control lines -
 
** outputs
 
*** ''Discard'': pulse to State Advance to discard packet and return to 010
 
*** ''Continue'': pulse to Switch to continue processing
 
*** - transceiver control lines -
 
* '''Switch'''
 
** This block reads the first data byte of the packet and uses it as a switch to direct the state machine to the appropriate next step.
 
** inputs
 
*** ''Clk'': clock
 
*** ''/Rst'': asynchronous, active-low reset
 
*** ''Go'': pulse to begin
 
*** - transceiver control lines -
 
** outputs
 
*** ''Discard'': pulse to State Advance to discard packet and return to 010
 
*** ''Reset_000'': pulse to State Advance to discard packet and go to 000
 
*** ''Query'': pulse to State Advance to discard packet and go to 100
 
*** ''Program'': pulse to State Advance to keep packet and go to 110
 
*** - transceiver control lines -
 
* '''State Advance'''
 
** This block has several ''Go'' lines and based on which is pulsed the next state is set up by loading a new state value into the state register.  It also discards packets other than "P".
 
** inputs
 
*** ''Clk'': clock
 
*** ''/Rst'': asynchronous, active-low reset
 
*** ''Discard'': pulse to discard packet and return to 010
 
*** ''Reset_000'': pulse to discard packet and go to 000
 
*** ''Query'': pulse to discard packet and go to 100
 
*** ''Program'': pulse to keep packet and go to 110
 
*** - transceiver control lines -
 
** outputs
 
*** ''Done'': pulse to signal completion; connects to state register enable
 
*** ''New_St'': new state to load to state register; goes to 000, 010, 100, or 110 when ''Done'' is high depending on switching
 
*** - transceiver control lines -
 
  
 
== (100) Poll Status ==
 
== (100) Poll Status ==

Revision as of 18:59, 16 May 2008

The modules involved in communication with the Ethernet Controller chip serve as the core of the FPGA. The different tasks that need to be performed by these modules include

  • executing the complex board reset and address lookup sequence
  • polling for new packets and switching execution accordingly
  • collecting sensor information upon a status report request
  • programming the DAC upon a program packet receipt
  • building return packets

In our design, the modules involved with packet handling and interfacing with sensor chip controllers are organized by state. A state register specifies the current stage of the process and only the corresponding module is allowed to act during that stage. Aside from defining a process sequence, the state serves as a complex "enable" signal for the modules, ensuring that only one module is driving the communication bus used to query the Ethernet Controller chip.


Interface

See also: Ethernet packets
Multiplexed Intel Bus and internal I/O timing scheme enforced by FPGA clocks

The compact approach to wire and poll the Ethernet Controller chop is via the Multiplexed Intel bus format. Aside from some use of the interrupt and reset pins, all communication is done via this bus. (The control architecture of the chip uses 8-bit registers selected with 8-bit addresses.) A communication over this bus begins with an pulse on the "ALE" pin, by the fall of which a valid address is expected on the 8-bit inout "AD" bus. After this /RD (/WR) signal falls, executing the read (write) process, and then rises accompanied with valid input from (to) the chip. The adjacent figure illustrates this process along with the approach to timing the conversation taken in this design. Please refer to Section 16.2 in the manual for details on the timing tolerances on this bus.

As shown in the figure, the 20 MHz clock is very convenient for metering this conversation. The communication delay for the FPGA (most of which runs essentially on 5 MHz) turns out to be only two clock cycles.

The eight states

There are eight major states to the module.

State list

(000) Reset Cycle
The reset cycle resets the selected chips. There are flags for resetting all 4 chips: DAC, ADC, temperature sensor, Ethernet controller. This is the entry state from a power-on. From this state, proceed unconditionally to 001.
(001) Transmit "I"
This state transmits an "I" packet to acknowledge that a reset occurred but the board is now prepared to accept new packets and function normally. From this state, proceed unconditionally to 010. "S"-Packet (from state 101) would do just as well, returning zeroed registers, location address etc for computer's address LUT.
(010) Idle
This is the idle state where the state machine awaits a new packet's arrival. If the Receive FIFO is empty, it loops back on itself and continues checking the FIFO. If the FIFO is not empty, proceed to 011.
(011) Read Packet
This state accesses the first packet. If packets need to be filtered by the FPGA, this state will filter and return to 010 on a bad packet. The MAC data is discarded, as it is unimportant to the FPGA, and the first data byte is read. This byte is used as a switch: an ASCII "R" loops to 000. A "Q" proceeds to 100. A "P" proceeds to 110. Any other value is a bad packet and the state machine returns to 010.
(100) Poll Status
This state polls the status chips (the ADC and the temperature sensor) so that recent data is ready for transmission.
(101) Transmit "S"
This state packages and transmits an "S" packet over the Ethernet to report back the status of the board in response to a "Q" packet.
(110) Program DAC
This state programs the DAC with new values according to the mask and data in the "P" packet.
(111) Transmit "D"
This state packages and transmits a "D" packet over the Ethernet to report back the DAC voltages in response to a "P" packet.

State interconnect

These states will form the outline of the functional block diagram. Within each state will be a smaller process or set of processes, possibly broken into substates. This implementation calls for a central state register. Each block reads the state value in the register and enables itself upon seeing its own value. After completion of its function, a block will write a new value to the state register to enable the next block. With several modules writing to the register, usual precautions must be taken to avoid more than one drivers forcing a line simultaneously. All modules must be designed to go to high impedance on their output lines when they are not active.

State variable

Based on the assignments of state values to the various states, certain interpretations of the state's bits arise. They may or may not prove useful in coding the system. They are given here in the case that they do become useful.

  • S2:1:
    • S2 = 0: "Core cycle" that executes regularly and forms the spine of the state diagram.
      • S2:1 = 00: "Initialization cycle" that prepares the state diagram for normal functioning.
      • S2:1 = 01: "Standard cycle" that the state machine returns to most frequently to process appropriate switching to branches.
    • S2 = 1: "Branch cycles" that execute selectively based on received packets.
  • S0:
    • S0 = 0: "Setup state" to prepare internal workings for a communication.
    • S0 = 1: "Transfer state" to communicate with the external PC.


Controller

Foreword on Timing

With a controller this complex, the timing of signals must be inspected even more scrupulously than usual. In particular, simultaneous transitions of data and "Done" lines must be avoided. When possible, a one-cycle-delayed "Done" signal is used to ensure that the data lines have been stabilized. (All delays are implemented via the c_delay module which postpones the signal by one cycle via two sequential flip-flops, each shifting by half-cycle). When this is inconvenient (e.g. when writing to registers) the target component must not be enabled on rising edges on "Go" or the clock. The registers, for instance, have been designed to read values on the falling edge of the clock - middle of the "Go" pulse, safely after the data line transitions.


Transceiver

Reset Modules

Idler (Idle Process Module)

Packet Reader (Packet type inspection)

Packet Transmitter



Registers

Miscellaneous Reusable Components




(100) Poll Status

This block will have at least two functional blocks: one to poll the temperature sensor and one to poll the ADC. Its job is to update all status values from the status chips in preparation for transmission. Additionally, it converts all values to 16-bit two's-complement before storing locally. Once all status values have been updated it transitions to state 101.

Currently we assume that data values will be stored in the FPGA. If data values will be stored on CP2200/1 Flash memory or other storage device, the interfaces and blocks will have to be adjusted appropriately.

inputs

  • Clk: clock
  • /Rst: asynchronous, active-low reset
  • State: 3-bit state value

internal signals

  • S_En: state enable, S_En <= not (St(2) or St(1) or St(0))
  • Go: when S_En goes high Go pulses for one cycle

blocks

  • ADC Poll
    • Updates values stored in the FPGA from the ADC. Obtains data from ADC, converts to 16-bit two's-complement, and stores.
    • inputs
      • Clk: clock
      • /Rst: asynchronous, active-low reset
      • Go: go pulse to begin
    • outputs
      • - All ADC control lines -
      • A_Done: goes high when reset/initialization process is complete, falls on Go pulse
      • En: enable line for writing to the internal registers
      • Sel: 3-bit select bus to specify which ADC channel data is available
      • Data: 16-bit data bus to carry data to FPGA internal registers
  • Temp Poll
    • Updates value stored in the FPGA from the temperature sensor. Obtains data from temperature sensor, converts to 16-bit two's-complement, and stores.
    • inputs
      • Clk: clock
      • /Rst: asynchronous, active-low reset
      • Go: go pulse to begin
    • outputs
      • - All temperature sensor control lines -
      • En: enable line for writing to the internal register
      • Data: 16-bit data bus to carry data to FPGA internal registers
  • Coordinator
    • Coordinates the completion of each polling cycle and notifies other blocks that the polling process is complete.
    • inputs
      • Clk: clock
      • /Rst: asynchronous, active-low reset
      • A_Done: high when ADC is done polling
    • outputs
      • Done: when A_Done goes high, Done pulses for one cycle; connects to state register as an enable
      Note that the temperature sensor does not signal completion. That is because the temperature sensor need only update one value, while the ADC must update eight values. Thus it is known ahead of time that the temperature sensor will already be done by the time the ADC is done.
      • New_St: new state to be written to the state register; goes to 101 while Done is high

(101) Transmit "S"

This block compiles the status values into a single packet by loading them into the CP2200/1 in a defined order and format, including padding/converting any values that need it. Once the packet has been sent, the block transitions to state 010.

inputs

  • Clk: clock
  • /Rst: asynchronous, active-low reset
  • State: 3-bit state value

internal signals

  • S_En: state enable, S_En <= not (St(2) or St(1) or St(0))
  • Go: when S_En goes high Go pulses for one cycle

blocks

  • Temp Loader
    • This block reads the temperature value from the internal registers and loads it to the transmit buffer.
    • inputs
      • Clk: clock
      • /Rst: asynchronous, active-low reset
      • Go: pulse to begin; feeds from Go internal signal of block 101
      • D_in: 16-bit data bus from internal registers
      • TxRx_Done: Done signal from transceiver
    • ouputs
      • TxRx_Go: Go signal on transceiver
      • TxRx_R/W: R/W signal on transceiver
      • TxRx_A: A_in bus on transceiver
      • TxRx_D: D_in bus on transceiver
      • Done: pulse to signal completion
  • ADC Loader
    • This block reads the ADC values from the internal registers and loads them to the transmit buffer in order: channel zero to channel seven.
    • inputs
      • Clk: clock
      • /Rst: asynchronous, active-low reset
      • Go: pulse to begin; feeds from Done signal of Temp Loader
      • D_in: 16-bit data bus from internal registers
      • TxRx_Done: Done signal from transceiver
    • ouputs
      • Sel: 3-bit select bus for internal registers
      • TxRx_Go: Go signal on transceiver
      • TxRx_R/W: R/W signal on transceiver
      • TxRx_A: A_in bus on transceiver
      • TxRx_D: D_in bus on transceiver
      • Done: pulse to signal completion
  • Padder
    • This block pads the packet to the minimum 46 bytes. Only 19 bytes have been loaded by this point (1 byte "S", 2 byte temperature, 8 x 2 byte ADC), so 27 bytes of padding (zero) must be loaded.
    • inputs
      • Clk: clock
      • /Rst: asynchronous, active-low reset
      • Go: pulse to begin; feeds from Done signal of ADC Loader
      • TxRx_Done: Done signal from transceiver
    • outputs
      • TxRx_Go: Go signal on transceiver
      • TxRx_R/W: R/W signal on transceiver
      • TxRx_A: A_in bus on transceiver
      • TxRx_D: D_in bus on transceiver
      • Done: pulse to signal completion
  • Sender
    • This block tells the CP2200/1 to send the completed packet.
    • inputs
      • Clk: clock
      • /Rst: asynchronous, active-low reset
      • Go: pulse to begin; feeds from Done signal of Padder
      • TxRx_Done: Done signal from transceiver
    • outputs
      • TxRx_Go: Go signal on transceiver
      • TxRx_R/W: R/W signal on transceiver
      • TxRx_A: A_in bus on transceiver
      • TxRx_D: D_in bus on transceiver
      • Done: pulse to signal completion

(110) Program DAC

This block will have a substate to obtain the programming mask. It then loops 32 (or 24 or 16) times on a second substate that obtains the next programming value and, if the corresponding mask bit is high, programs that channel of the DAC. A mux may be needed to select the appropriate bit from the programming mask. It also updates the locally stored DAC channel values (which may be stored on the FPGA, the CP2200/1 Flash, or other) in preparation for a "D" response packet. Then it transitions to state 111.

inputs

  • Clk: clock
  • /Rst: asynchronous, active-low reset
  • State: 3-bit state value

internal signals

  • S_En: state enable, S_En <= not (St(2) or St(1) or St(0))
  • Go: when S_En goes high Go pulses for one cycle

blocks

  • Mask Fetcher
    • This block reads the programming mask, contained in the second data byte (first remaining byte) through the 5th/4th/3rd byte (4th/3rd/2nd remaining byte), and saves it into a 32/24/16-bit register.
    • inputs
      • Clk: clock
      • /Rst: asynchronous, active-low reset
      • Go: pulse to begin, comes from Go internal signal of block 110
      • TxRx_D: 8-bit data bus from transceiver
      • TxRx_Done: Done signal from transceiver
    • outputs
      • TxRx_Go: Go input on transceiver
      • TxRx_R/W: R/W input on transceiver; tied to read (one)
      • TxRx_A: A_in bus on transceiver
      • Mask: 32/24/16-bit readout of programming mask
      • Done: pulse to signal that mask has been obtained
  • Programmer
    • Programs the DAC. Loops 32/24/16 times, obtaining the next byte from the CP2200/1 buffer, checking the mask, programming the DAC if the mask is 1 or skipping if the mask is 0. Also writes the value to the internal DAC value storage registers (or Flash memory or other).
    • inputs
      • Clk: clock
      • /Rst: asynchronous, active-low reset
      • Go: pulse to begin; feeds from Done signal of Mask Fetcher
      • TxRx_D: D_out bus on transceiver
      • TxRx_Done: Done signal on transceiver
    • outputs
      • - DAC control lines -
      • TxRx_Go: Go signal on transceiver
      • TxRx_R/W: R/W signal on transceiver
      • TxRx_A: A_in bus on transceiver
      • Sel: 5/5/4-bit select bus to internal registers
      • Data: 32/24/16-bit data bus to internal registers
      • Done: pulse to signal completion
  • Discarder
    • This block orders the CP2200/1 to discard the packet, now that the FPGA is done with all the data contained within the packet.
    • inputs
      • Clk: clock
      • /Rst: asynchronous, active-low reset
      • Go: pulse to begin; feeds from Done signal of Programmer
      • TxRx_Done: Done signal on transceiver
    • outputs
      • TxRx_Go: Go signal on transceiver
      • TxRx_R/W: R/W signal on transceiver
      • TxRx_A: A_in bus on transceiver
      • Done: pulse to signal completion
      • New_St: next state to load into the state register; goes to 111 when Done is high

(111) Transmit "D"

This block loads a "D" to the transmit buffer then loops 32 (or 24 or 16) times to load the locally stored DAC channel values to the transmit buffer. Once the full packet has been loaded, it sends the packet, then transitions to state 010.

inputs

  • Clk: clock
  • /Rst: asynchronous, active-low reset
  • State: 3-bit state value

internal signals

  • S_En: state enable, S_En <= not (St(2) or St(1) or St(0))
  • Go: when S_En goes high Go pulses for one cycle

blocks

  • Loader
    • Loads the DAC values into a packet in the transmission buffer of the CP2200/1. Loops through all values and loads them in order (channel zero to channel thirty-one).
    • inputs
      • Clk: clock
      • /Rst: asynchronous, active-low reset
      • Go: pulse to begin loading a packet
      • TxRx_Done: Done signal on transceiver
      • Data: 14-bit data bus from internal registers
    • outputs
      • TxRx_Go: Go signal on transceiver
      • TxRx_RW: R/W signal on transceiver
      • TxRx_A: A_in bus on transceiver
      • TxRx_D: D_in bus on transceiver
      • Done: pulse to signal completion
  • Sender
    • Tells CP2200/1 to send the packet
    • inputs
      • Clk: clock
      • /Rst: asynchronous, active-low reset
      • Go: pulse to begin, connected to Done signal from Loader
      • TxRx_Done: Done signal from transceiver
    • outputs
      • TxRx_Go: Go signal on transceiver
      • TxRx_RW: R/W signal on transceiver
      • TxRx_A: A_in bus on transceiver
      • TxRx_D: D_in bus on transceiver
      • Done: pulse to signal completion
      • New_St: 3-bit bus of new state to write to state register; goes to 010 when Done is high

Emulator

Since the modules described here represent the core of the FPGA, their combined simulation calls for inclusion of all other fringe modules. Essentially the whole FPGA will have to be tested to ensure this scheme for the core is acting properly. The challenge is in the complexity of the stimulus for such simulation: whole packets will need to be sent in and possibly inter-packet Ethernet Controller Chip states tested.

A stripped down emulator for the Ethernet Controller has been written. It is a essentially a set of registers with a Multiplexed Intel bus communication layer and packet file read/write layers. These registers, however, are not passive memory banks but include "events" that are triggered by particular register states. For instance writing to registers designated to make up a receive buffer pointer actually delivers the requested byte from the buffer to the appropriate control register to be available for a subsequent request. A simple interrupt system (stimulated externally by the simulation layer) has also been included.