SURF  1.0
EthMacRxImportGmii.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : EthMacRxImportGmii.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2015-02-04
5 -- Last update: 2016-09-14
6 -------------------------------------------------------------------------------
7 -- Description: 1GbE Import MAC core with GMII interface
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 ieee.std_logic_arith.all;
21 use ieee.std_logic_unsigned.all;
22 
23 use work.StdRtlPkg.all;
24 use work.AxiStreamPkg.all;
25 use work.EthMacPkg.all;
26 
27 --! @see entity
28  --! @ingroup ethernet_EthMacCore
30  generic (
31  TPD_G : time := 1 ns);
32  port (
33  -- Clock and Reset
34  ethClk : in sl;
35  ethRst : in sl;
36  -- AXIS Interface
38  -- GMII PHY Interface
39  gmiiRxDv : in sl;
40  gmiiRxEr : in sl;
41  gmiiRxd : in slv(7 downto 0);
42  -- Configuration and status
43  phyReady : in sl;
44  rxCountEn : out sl;
45  rxCrcError : out sl);
46 end EthMacRxImportGmii;
47 
48 architecture rtl of EthMacRxImportGmii is
49 
50  constant SFD_C : slv(7 downto 0) := x"D5";
51  constant AXI_CONFIG_C : AxiStreamConfigType := (
53  TDATA_BYTES_C => 1, -- 8-bit AXI stream interface
59 
60  type StateType is(
61  WAIT_SFD_S,
62  WAIT_DATA_S,
63  GET_DATA_S,
64  DELAY0_S,
65  DELAY1_S,
66  CRC_S);
67 
68  type RegType is record
69  rxCountEn : sl;
70  rxCrcError : sl;
71  crcReset : sl;
72  delRxDv : sl;
73  delRxDvSr : slv(7 downto 0);
74  crcDataValid : sl;
75  sof : sl;
76  state : StateType;
77  macData : slv(63 downto 0);
78  macMaster : AxiStreamMasterType;
79  end record;
80 
81  constant REG_INIT_C : RegType := (
82  rxCountEn => '0',
83  rxCrcError => '0',
84  crcReset => '0',
85  delRxDv => '0',
86  delRxDvSr => (others => '0'),
87  crcDataValid => '0',
88  sof => '0',
89  state => WAIT_SFD_S,
90  macData => (others => '0'),
91  macMaster => AXI_STREAM_MASTER_INIT_C);
92 
93  signal r : RegType := REG_INIT_C;
94  signal rin : RegType;
95 
96  signal crcOut : slv(31 downto 0);
97  signal crcIn : slv(31 downto 0);
98  signal macMaster : AxiStreamMasterType;
99 
100 -- attribute dont_touch : string;
101 -- attribute dont_touch of r : signal is "TRUE";
102 -- attribute dont_touch of crcIn : signal is "TRUE";
103 -- attribute dont_touch of crcOut : signal is "TRUE";
104 -- attribute dont_touch of macMaster : signal is "TRUE";
105 
106 begin
107 
108  DATA_MUX : entity work.AxiStreamFifoV2
109  generic map (
110  -- General Configurations
111  TPD_G => TPD_G,
112  PIPE_STAGES_G => 0,
113  SLAVE_READY_EN_G => true,
114  VALID_THOLD_G => 1,
115  -- FIFO configurations
116  BRAM_EN_G => false,
117  USE_BUILT_IN_G => false,
118  GEN_SYNC_FIFO_G => true,
119  CASCADE_SIZE_G => 1,
120  FIFO_ADDR_WIDTH_G => 4,
121  -- AXI Stream Port Configurations
122  SLAVE_AXI_CONFIG_G => AXI_CONFIG_C, -- 8-bit AXI stream interface
123  MASTER_AXI_CONFIG_G => EMAC_AXIS_CONFIG_C) -- 128-bit AXI stream interface
124  port map (
125  -- Slave Port
126  sAxisClk => ethClk,
127  sAxisRst => ethRst,
128  sAxisMaster => macMaster, -- 8-bit AXI stream interface
129  sAxisSlave => open,
130  -- Master Port
131  mAxisClk => ethClk,
132  mAxisRst => ethRst,
133  mAxisMaster => macIbMaster, -- 128-bit AXI stream interface
135 
136  comb : process (crcIn, crcOut, ethRst, gmiiRxDv, gmiiRxEr, gmiiRxd, phyReady, r) is
137  variable v : RegType;
138  begin
139  -- Latch the current value
140  v := r;
141 
142  -- Reset the flags
143  v.rxCountEn := '0';
144  v.rxCrcError := '0';
145  v.crcDataValid := '0';
146  v.delRxDv := '0';
147  v.macMaster.tValid := '0';
148  v.macMaster.tLast := '0';
149  v.macMaster.tUser := (others => '0');
150  v.macMaster.tKeep := (others => '1');
151 
152  -- Delay data to avoid sending the CRC
153  v.macData(63 downto 0) := r.macData(55 downto 0) & gmiiRxd;
154 
155  -- Delay the GMII valid for start up sequencing
156  v.delRxDvSr := r.delRxDvSr(6 downto 0) & r.delRxDv;
157 
158  -- Check for CRC reset
159  v.crcReset := r.delRxDvSr(2) or ethRst or (not phyReady);
160 
161  -- State Machine
162  case r.state is
163  ----------------------------------------------------------------------
164  when WAIT_SFD_S =>
165  v.sof := '1';
166  if ((gmiiRxd = SFD_C) and (gmiiRxDv = '1') and (gmiiRxEr = '0') and (phyReady = '1')) then
167  v.delRxDv := '1';
168  v.state := WAIT_DATA_S;
169  end if;
170  ----------------------------------------------------------------------
171  when WAIT_DATA_S =>
172  if (gmiiRxDv = '0') or (gmiiRxEr = '1') or (phyReady = '0') then
173  v.state := WAIT_SFD_S;
174  elsif (r.delRxDvSr(3) = '1') then
175  v.state := GET_DATA_S;
176  end if;
177  ----------------------------------------------------------------------
178  when GET_DATA_S =>
179  if ((gmiiRxEr = '1') and (gmiiRxDv = '1')) or (phyReady = '0') then -- Error
180  v.macMaster.tvalid := '1';
181  v.macMaster.tlast := '1';
182  axiStreamSetUserBit(AXI_CONFIG_C, v.macMaster, EMAC_EOFE_BIT_C, '1', 0);
183  v.state := WAIT_SFD_S;
184  else
185  v.crcDataValid := '1';
186  v.macMaster.tvalid := gmiiRxDv;
187  v.macMaster.tdata(7 downto 0) := r.macData(39 downto 32);
188  if (gmiiRxDv = '0') then
189  v.state := DELAY0_S;
190  end if;
191  if (r.sof = '1') then
192  axiStreamSetUserBit(AXI_CONFIG_C, v.macMaster, EMAC_SOF_BIT_C, '1', 0);
193  v.sof := '0';
194  end if;
195  end if;
196  ----------------------------------------------------------------------
197  when DELAY0_S =>
198  v.state := DELAY1_S;
199  ----------------------------------------------------------------------
200  when DELAY1_S =>
201  v.state := CRC_S;
202  ----------------------------------------------------------------------
203  when CRC_S =>
204  v.macMaster.tvalid := '1';
205  v.macMaster.tlast := '1';
206  if (crcIn /= crcOut) then
207  v.rxCrcError := '1';
208  axiStreamSetUserBit(AXI_CONFIG_C, v.macMaster, EMAC_EOFE_BIT_C, '1', 0);
209  else
210  v.rxCountEn := '1';
211  end if;
212  v.state := WAIT_SFD_S;
213  ----------------------------------------------------------------------
214  end case;
215 
216  -- Reset
217  if (ethRst = '1') then
218  v := REG_INIT_C;
219  end if;
220 
221  -- Register the variable for next clock cycle
222  rin <= v;
223 
224  -- Outputs
225  macMaster <= r.macMaster;
226  rxCountEn <= r.rxCountEn;
227  rxCrcError <= r.rxCrcError;
228 
229  end process comb;
230 
231  seq : process (ethClk) is
232  begin
233  if rising_edge(ethClk) then
234  r <= rin after TPD_G;
235  end if;
236  end process seq;
237 
238  -- CRC Input
239  crcIn(31 downto 0) <= r.macData(55 downto 24);
240 
241  -- CRC
242  U_Crc32 : entity work.Crc32Parallel
243  generic map (
244  BYTE_WIDTH_G => 1)
245  port map (
246  crcOut => crcOut,
247  crcClk => ethClk,
248  crcDataValid => r.crcDataValid,
249  crcDataWidth => "000",
250  crcIn => r.macData(47 downto 40),
251  crcReset => r.crcReset);
252 
253 end rtl;
FIFO_ADDR_WIDTH_Ginteger range 4 to 48:= 9
natural range 0 to 8 TDEST_BITS_C
PIPE_STAGES_Gnatural range 0 to 16:= 1
std_logic sl
Definition: StdRtlPkg.vhd:28
out crcOutslv( 31 downto 0)
AxiStreamMasterType :=(tValid => '0',tData =>( others => '0'),tStrb =>( others => '1'),tKeep =>( others => '1'),tLast => '0',tDest =>( others => '0'),tId =>( others => '0'),tUser =>( others => '0')) AXI_STREAM_MASTER_INIT_C
SLAVE_AXI_CONFIG_GAxiStreamConfigType := AXI_STREAM_CONFIG_INIT_C
in crcDataWidthslv( 2 downto 0)
slv( 15 downto 0) tKeep
SLAVE_READY_EN_Gboolean := true
natural range 1 to 16 TDATA_BYTES_C
GEN_SYNC_FIFO_Gboolean := false
TkeepModeType TKEEP_MODE_C
natural range 0 to 8 TID_BITS_C
BRAM_EN_Gboolean := true
integer := 0 EMAC_EOFE_BIT_C
Definition: EthMacPkg.vhd:52
integer := 1 EMAC_SOF_BIT_C
Definition: EthMacPkg.vhd:49
boolean TSTRB_EN_C
TUserModeType TUSER_MODE_C
slv( 127 downto 0) tUser
in gmiiRxdslv( 7 downto 0)
TPD_Gtime := 1 ns
natural range 0 to 8 TUSER_BITS_C
out sAxisSlaveAxiStreamSlaveType
out macIbMasterAxiStreamMasterType
in sAxisMasterAxiStreamMasterType
out mAxisMasterAxiStreamMasterType
in crcInslv(( BYTE_WIDTH_G* 8- 1) downto 0)
AxiStreamSlaveType :=(tReady => '1') AXI_STREAM_SLAVE_FORCE_C
_library_ ieeeieee
in mAxisSlaveAxiStreamSlaveType
CASCADE_SIZE_Ginteger range 1 to ( 2** 24):= 1
USE_BUILT_IN_Gboolean := false
VALID_THOLD_Ginteger range 0 to ( 2** 24):= 1
MASTER_AXI_CONFIG_GAxiStreamConfigType := AXI_STREAM_CONFIG_INIT_C
AxiStreamConfigType :=(TSTRB_EN_C => false,TDATA_BYTES_C => 16,TDEST_BITS_C => 8,TID_BITS_C => 0,TKEEP_MODE_C => TKEEP_COMP_C,TUSER_BITS_C => 4,TUSER_MODE_C => TUSER_FIRST_LAST_C) EMAC_AXIS_CONFIG_C
Definition: EthMacPkg.vhd:58
std_logic_vector slv
Definition: StdRtlPkg.vhd:29
BYTE_WIDTH_Ginteger := 4