| 1 | Up to [[TrackerReadoutModule]] |
| 2 | |
| 3 | Data from the TDC is encoded using |
| 4 | [http://en.wikipedia.org/wiki/8b/10b_encoding 8b10b] |
| 5 | |
| 6 | Need to double-check the following, but here are our current assumptions: |
| 7 | <pre> |
| 8 | Each 32-bit word is sent as four bytes, in network byte order. This would be: |
| 9 | |
| 10 | {{{ |
| 11 | 1. bits 31:24 |
| 12 | 2. bits 23:16 |
| 13 | 3. bits 15:8 |
| 14 | 4. bits 7:0 |
| 15 | |
| 16 | }}} |
| 17 | Each byte is encoded 8b/10b using the "IBM" 8b10b encoding |
| 18 | http://en.wikipedia.org/wiki/8B10B#Encoding_tables |
| 19 | where the 8-bit code (ABCDEFGH) maps to bits (01234567) |
| 20 | and the 10-bit code (abcdei fghj) maps to bits (0123456789). |
| 21 | In the 10-bit code the bits are shifted out LSB-first so abcdeifghj come out |
| 22 | in that order with a being sent first. |
| 23 | |
| 24 | What 8b10b code is sent while the link is idle? It says "0''s" in your |
| 25 | document, but does that mean D.0.0? |
| 26 | </pre> |
| 27 | |
| 28 | Decoding involves a 3-step process: |
| 29 | |
| 30 | == Data recovery == |
| 31 | |
| 32 | This is the process of recovering a reliable stream of serial data from a data link for which |
| 33 | no separate clock is available. See for example |
| 34 | [http://ohm.bu.edu/~hazen/Papers/blind_oversampling_CDR.pdf this paper] |
| 35 | |
| 36 | Below is a prototype VHDL entity for a data recovery block. The <b>oversamp</b> parameter sets |
| 37 | the ratio of the <b>clk</b> rate to the bit rate. The <b>d</b> input is the bit stream from |
| 38 | the TDC. The <b>q</b> output is the recovered data stream, with <b>dav</b>=1 indicating |
| 39 | a valid bit. Generally, <b>dav</b> will be high one clock every 5th for an oversampling |
| 40 | factor of 5. The <b>err</b> output may indicate a failure to identify a valid bit stream. |
| 41 | |
| 42 | {{{ |
| 43 | entity data_rec is |
| 44 | generic ( |
| 45 | oversamp : integer := 5); -- oversampling factor |
| 46 | port ( |
| 47 | clk : in std_logic; -- oversampling clock |
| 48 | rst_n : in std_logic; -- active low async reset |
| 49 | d : in std_logic; -- bitstream |
| 50 | q : out std_logic; -- data output |
| 51 | dav : out std_logic; -- data valid |
| 52 | err : out std_logic); -- error output |
| 53 | end data_rec; |
| 54 | |
| 55 | }}} |
| 56 | == Byte synchronization == |
| 57 | |
| 58 | Byte synchronization is the process of assembling the bit stream from the data recovery |
| 59 | block into 10-bit symbols. The synchronizer watches for a specific unique pattern which |
| 60 | does not otherwise occur in the bit stream to acquire synchronization, then simply |
| 61 | shifts 10 bits at a time into a register and provides them as output to the decoder. |
| 62 | |
| 63 | The TDC sends the 8b10b code K.28.1 ("0011111001" or "1100000110") at the start of each transmission. |
| 64 | This code contains the unique bit sequence "0011111" or "1100000" which does not otherwise occur in |
| 65 | the bit stream. |
| 66 | |
| 67 | Below is a prototype VHDL entity for a synchronizer. |
| 68 | |
| 69 | |
| 70 | {{{ |
| 71 | entity synchro is |
| 72 | port ( |
| 73 | clk : in std_logic; -- oversampling clock |
| 74 | rst_n : in std_logic; -- active low async reset |
| 75 | d : in std_logic; -- serial bits in |
| 76 | dav_in : in std_logic; -- input data valid |
| 77 | comma : out std_logic; -- comma sequence detected |
| 78 | in_sync : out std_logic; -- synchronized |
| 79 | err : out std_logic; -- error in bit stream |
| 80 | dav_out : out std_logic; -- data valid out |
| 81 | q : out std_logic_vector(9 downto 0)); -- symbol out |
| 82 | end synchro; |
| 83 | |
| 84 | }}} |
| 85 | |
| 86 | == 8b10b decoding == |
| 87 | |
| 88 | This is the process of converting the 10-bit symbols from the bit stream |
| 89 | back to 8-bit bytes. A simple decoder may be downloaded |
| 90 | from [http://opencores.org/project,8b10b_encdec opencores] |
| 91 | prototype VHDL entity for the decoder: |
| 92 | |
| 93 | {{{ |
| 94 | entity dec_8b10b is |
| 95 | port ( |
| 96 | clk : in std_logic; -- oversampling clock |
| 97 | rst_n : in std_logic; -- asynchronous reset active low |
| 98 | d_in : in std_logic_vector(9 downto 0); -- data symbol in |
| 99 | dav_in : in std_logic; -- input data valid |
| 100 | d_out : out std_logic_vector(7 downto 0); -- decoded data out |
| 101 | k : out std_logic); -- control character |
| 102 | end dec_8b10b; |
| 103 | |
| 104 | }}} |
| 105 | |