SURF  1.0
Encoder8b10b.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : Encoder8b10b.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2016-10-12
5 -- Last update: 2017-05-01
6 -------------------------------------------------------------------------------
7 -- Description: 8B10B Encoder Module
8 -------------------------------------------------------------------------------
9 -- This file is part of 'SLAC Firmware Standard Library'.
10 -- It is subject to the license terms in the LICENSE.txt file found in the
11 -- top-level directory of this distribution and at:
12 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
13 -- No part of 'SLAC Firmware Standard Library', including this file,
14 -- may be copied, modified, propagated, or distributed except according to
15 -- the terms contained in the LICENSE.txt file.
16 -------------------------------------------------------------------------------
17 
18 library ieee;
19 use ieee.std_logic_1164.all;
20 use work.StdRtlPkg.all;
21 use work.Code8b10bPkg.all;
22 
23 --! @see entity
24  --! @ingroup base_general
25 entity Encoder8b10b is
26 
27  generic (
28  TPD_G : time := 1 ns;
29  NUM_BYTES_G : positive := 2;
30  RST_POLARITY_G : sl := '0';
31  RST_ASYNC_G : boolean := true;
32  FLOW_CTRL_EN_G : boolean := false);
33  port (
34  clk : in sl;
35  clkEn : in sl := '1'; -- Optional Clock Enable
36  rst : in sl := not RST_POLARITY_G; -- Optional Reset
37  validIn : in sl := '1';
38  readyIn : out sl;
39  dataIn : in slv(NUM_BYTES_G*8-1 downto 0);
40  dataKIn : in slv(NUM_BYTES_G-1 downto 0);
41  validOut : out sl;
42  readyOut : in sl := '1';
43  dataOut : out slv(NUM_BYTES_G*10-1 downto 0));
44 
45 end entity Encoder8b10b;
46 
47 architecture rtl of Encoder8b10b is
48 
49  type RegType is record
50  validOut : sl;
51  readyIn : sl;
52  runDisp : sl;
53  dataOut : slv(NUM_BYTES_G*10-1 downto 0);
54  end record RegType;
55 
56  constant REG_INIT_C : RegType := (
57  validOut => toSl(not FLOW_CTRL_EN_G),
58  readyIn => '0',
59  runDisp => '0',
60  dataOut => (others => '0'));
61 
62  signal r : RegType := REG_INIT_C;
63  signal rin : RegType;
64 
65 begin
66 
67  comb : process (dataIn, dataKIn, r, readyOut, rst) is
68  variable v : RegType;
69  variable dispChainVar : sl;
70  begin
71  v := r;
72 
73  v.readyIn := readyOut;
74  if (readyOut = '1' and FLOW_CTRL_EN_G) then
75  v.validOut := '0';
76  end if;
77 
78  if (v.validOut = '0' or FLOW_CTRL_EN_G = false) then
79  v.validOut := '1';
80 
81  dispChainVar := r.runDisp;
82  for i in 0 to NUM_BYTES_G-1 loop
83  encode8b10b(dataIn => dataIn(i*8+7 downto i*8),
84  dataKIn => dataKIn(i),
85  dispIn => dispChainVar,
86  dataOut => v.dataOut(i*10+9 downto i*10),
87  dispOut => dispChainVar);
88  end loop;
89  v.runDisp := dispChainVar;
90  end if;
91 
92  -- Synchronous reset
93  if (RST_ASYNC_G = false and rst = RST_POLARITY_G) then
94  v := REG_INIT_C;
95  end if;
96 
97  rin <= v;
98  dataOut <= r.dataOut;
99  readyIn <= v.readyIn;
100  validOut <= r.validOut;
101  end process comb;
102 
103  seq : process (clk, rst) is
104  begin
105  if (rst = RST_POLARITY_G) then
106  r <= REG_INIT_C after TPD_G;
107  elsif (rising_edge(clk)) then
108  if clkEn = '1' then
109  r <= rin after TPD_G;
110  end if;
111  end if;
112  end process seq;
113 
114 end architecture rtl;
NUM_BYTES_Gpositive := 2
RST_POLARITY_Gsl := '0'
in dataInslv( NUM_BYTES_G* 8- 1 downto 0)
out readyInsl
std_logic sl
Definition: StdRtlPkg.vhd:28
TPD_Gtime := 1 ns
in clkEnsl := '1'
FLOW_CTRL_EN_Gboolean := false
in readyOutsl := '1'
_library_ ieeeieee
out dataOutslv( NUM_BYTES_G* 10- 1 downto 0)
out validOutsl
RST_ASYNC_Gboolean := true
in rstsl :=not RST_POLARITY_G
in validInsl := '1'
std_logic_vector slv
Definition: StdRtlPkg.vhd:29
in dataKInslv( NUM_BYTES_G- 1 downto 0)