SURF  1.0
EthMacTxExportGmii.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : EthMacTxExportGmii.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2015-02-04
5 -- Last update: 2016-09-14
6 -------------------------------------------------------------------------------
7 -- Description: 1GbE Export 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
39  -- GMII PHY Interface
40  gmiiTxEn : out sl;
41  gmiiTxEr : out sl;
42  gmiiTxd : out slv(7 downto 0);
43  phyReady : in sl;
44  -- Configuration
45  macAddress : in slv(47 downto 0);
46  -- Status
47  txCountEn : out sl;
48  txUnderRun : out sl;
50 end EthMacTxExportGmii;
51 
52 architecture rtl of EthMacTxExportGmii is
53 
54  constant AXI_CONFIG_C : AxiStreamConfigType := (
56  TDATA_BYTES_C => 1, -- 8-bit AXI stream interface
62 
63  type StateType is(
64  IDLE_S,
65  TX_PREAMBLE_S,
66  TX_DATA_S,
67  PAD_S,
68  TX_CRC_S,
69  TX_CRC0_S,
70  TX_CRC1_S,
71  TX_CRC2_S,
72  TX_CRC3_S,
73  DUMP_S,
74  INTERGAP_S);
75 
76  type RegType is record
77  gmiiTxEn : sl;
78  gmiiTxEr : sl;
79  gmiiTxd : slv(7 downto 0);
80  txCount : slv(7 downto 0);
81  txData_d : slv(7 downto 0);
82  txCountEn : sl;
83  txUnderRun : sl;
85  crcReset : sl;
86  crcDataValid : sl;
87  crcIn : slv(7 downto 0);
88  state : StateType;
89  macSlave : AxiStreamSlaveType;
90  end record;
91 
92  constant REG_INIT_C : RegType := (
93  gmiiTxEn => '0',
94  gmiiTxEr => '0',
95  gmiiTxd => (others => '0'),
96  txCount => (others => '0'),
97  txData_d => (others => '0'),
98  txCountEn => '0',
99  txUnderRun => '0',
100  txLinkNotReady => '0',
101  crcReset => '0',
102  crcDataValid => '0',
103  crcIn => (others => '0'),
104  state => IDLE_S,
105  macSlave => AXI_STREAM_SLAVE_INIT_C);
106 
107  signal r : RegType := REG_INIT_C;
108  signal rin : RegType;
109 
110  signal macMaster : AxiStreamMasterType;
111  signal macSlave : AxiStreamSlaveType;
112  signal crcOut : slv(31 downto 0);
113  signal crcDataValid : sl;
114  signal crcIn : slv(7 downto 0);
115 
116  -- attribute dont_touch : string;
117  -- attribute dont_touch of r : signal is "TRUE";
118  -- attribute dont_touch of macMaster : signal is "TRUE";
119  -- attribute dont_touch of macSlave : signal is "TRUE";
120  -- attribute dont_touch of crcOut : signal is "TRUE";
121  -- attribute dont_touch of crcDataValid : signal is "TRUE";
122  -- attribute dont_touch of crcIn : signal is "TRUE";
123 
124 begin
125 
126  DATA_MUX : entity work.AxiStreamFifoV2
127  generic map (
128  -- General Configurations
129  TPD_G => TPD_G,
130  INT_PIPE_STAGES_G => 0,
131  PIPE_STAGES_G => 1,
132  SLAVE_READY_EN_G => true,
133  VALID_THOLD_G => 1,
134  -- FIFO configurations
135  BRAM_EN_G => false,
136  USE_BUILT_IN_G => false,
137  GEN_SYNC_FIFO_G => true,
138  CASCADE_SIZE_G => 1,
139  FIFO_ADDR_WIDTH_G => 4,
140  -- AXI Stream Port Configurations
141  SLAVE_AXI_CONFIG_G => EMAC_AXIS_CONFIG_C, -- 128-bit AXI stream interface
142  MASTER_AXI_CONFIG_G => AXI_CONFIG_C) -- 8-bit AXI stream interface
143  port map (
144  -- Slave Port
145  sAxisClk => ethClk,
146  sAxisRst => ethRst,
147  sAxisMaster => macObMaster, -- 128-bit AXI stream interface
149  -- Master Port
150  mAxisClk => ethClk,
151  mAxisRst => ethRst,
152  mAxisMaster => macMaster, -- 8-bit AXI stream interface
153  mAxisSlave => macSlave);
154 
155  comb : process (crcOut, ethRst, macMaster, phyReady, r) is
156  variable v : RegType;
157  begin
158  -- Latch the current value
159  v := r;
160 
161  -- Reset the flags
162  v.macSlave := AXI_STREAM_SLAVE_INIT_C;
163  v.crcDataValid := '0';
164  v.txUnderRun := '0';
165  v.txLinkNotReady := '0';
166 
167  -- State Machine
168  case r.state is
169  ----------------------------------------------------------------------
170  when IDLE_S =>
171  v.crcReset := '1';
172  v.TxCount := x"00";
173  v.txData_d := x"07";
174  v.gmiiTxd := x"07";
175  v.gmiiTxEn := '0';
176  v.gmiiTxEr := '0';
177  -- Wait for start flag
178  if ((macMaster.tValid = '1') and (ethRst = '0')) then
179  -- Phy is ready
180  if phyReady = '1' then
181  v.state := TX_PREAMBLE_S;
182  -- Phy is not ready dump data
183  else
184  v.state := DUMP_S;
185  v.txLinkNotReady := '1';
186  end if;
187  end if;
188  ----------------------------------------------------------------------
189  when TX_PREAMBLE_S =>
190  v.gmiiTxEn := '1';
191  if (r.TxCount = x"07") then
192  v.CrcReset := '0';
193  v.txData_d := x"D5";
194  v.gmiiTxd := r.txData_d;
195  v.TxCount := x"00";
196  v.state := TX_DATA_S;
197  else
198  v.TxCount := r.TxCount +1;
199  v.txData_d := x"55";
200  v.gmiiTxd := r.txData_d;
201  v.state := TX_PREAMBLE_S;
202  end if;
203  ----------------------------------------------------------------------
204  when TX_DATA_S =>
205  v.macSlave.tReady := '1';
206  v.crcDataValid := '1';
207  v.crcIn := macMaster.tdata(7 downto 0);
208  v.txData_d := macMaster.tdata(7 downto 0);
209  v.gmiiTxd := r.txData_d;
210  if (r.TxCount < x"3C") then -- Minimum frame of 64 includes 4byte FCS
211  v.TxCount := r.TxCount + 1;
212  end if;
213  if (macMaster.tValid = '1') then
214  if (macMaster.tlast = '1') then
215  if (v.TxCount = x"3C") then
216  v.state := TX_CRC_S;
217  else
218  v.state := PAD_S;
219  end if;
220  end if;
221  else
222  v.gmiiTxEr := '1';
223  v.txUnderRun := '1';
224  v.state := DUMP_S;
225  end if;
226  ----------------------------------------------------------------------
227  when PAD_S =>
228  v.crcDataValid := '1';
229  v.crcIn := x"00";
230  v.txData_d := x"00";
231  v.gmiiTxd := r.txData_d;
232  if (r.TxCount < x"3C") then
233  v.TxCount := v.TxCount + 1;
234  else
235  v.state := TX_CRC_S;
236  end if;
237  ----------------------------------------------------------------------
238  when TX_CRC_S =>
239  v.gmiiTxd := r.txData_d;
240  v.state := TX_CRC0_S;
241  ----------------------------------------------------------------------
242  when TX_CRC0_S =>
243  v.gmiitxd := crcOut(31 downto 24);
244  v.state := TX_CRC1_S;
245  ----------------------------------------------------------------------
246  when TX_CRC1_S =>
247  v.gmiitxd := crcOut(23 downto 16);
248  v.state := TX_CRC2_S;
249  ----------------------------------------------------------------------
250  when TX_CRC2_S =>
251  v.gmiitxd := crcOut(15 downto 8);
252  v.state := TX_CRC3_S;
253  ----------------------------------------------------------------------
254  when TX_CRC3_S =>
255  v.gmiitxd := crcOut(7 downto 0);
256  v.TxCount := x"00";
257  v.state := INTERGAP_S;
258  ----------------------------------------------------------------------
259  when DUMP_S =>
260  v.gmiiTxEn := '0';
261  v.macSlave.tReady := '1';
262  v.TxCount := x"00";
263  if ((macMaster.tValid = '1') and (macMaster.tlast = '1')) then
264  v.state := INTERGAP_S;
265  end if;
266  ----------------------------------------------------------------------
267  when INTERGAP_S =>
268  v.gmiiTxEn := '0';
269  v.TxCount := r.TxCount +1;
270  if r.TxCount = x"0A" then -- 12 Octels - IDLE state
271  v.TxCount := x"00";
272  v.state := IDLE_S;
273  end if;
274  ----------------------------------------------------------------------
275  end case;
276 
277  -- Reset
278  if (ethRst = '1') then
279  v := REG_INIT_C;
280  end if;
281 
282  -- Register the variable for next clock cycle
283  rin <= v;
284 
285  -- Outputs
286  macSlave <= v.macSlave; -- Flow control with non-registered signal
287  txCountEn <= r.txCountEn;
288  txUnderRun <= r.txUnderRun;
290  gmiiTxEn <= r.gmiiTxEn;
291  gmiiTxEr <= r.gmiiTxEr;
292  gmiiTxd <= r.gmiiTxd;
293  crcDataValid <= v.crcDataValid;
294  crcIn <= v.crcIn;
295 
296  end process comb;
297 
298  seq : process (ethClk) is
299  begin
300  if rising_edge(ethClk) then
301  r <= rin after TPD_G;
302  end if;
303  end process seq;
304 
305  -- CRC
306  U_Crc32 : entity work.Crc32Parallel
307  generic map (
308  BYTE_WIDTH_G => 1)
309  port map (
310  crcOut => crcOut,
311  crcClk => ethClk,
312  crcDataValid => crcDataValid,
313  crcDataWidth => "000",
314  crcIn => crcIn,
315  crcReset => r.crcReset);
316 
317 end rtl;
FIFO_ADDR_WIDTH_Ginteger range 4 to 48:= 9
out gmiiTxdslv( 7 downto 0)
natural range 0 to 8 TDEST_BITS_C
in macObMasterAxiStreamMasterType
out macObSlaveAxiStreamSlaveType
PIPE_STAGES_Gnatural range 0 to 16:= 1
std_logic sl
Definition: StdRtlPkg.vhd:28
out crcOutslv( 31 downto 0)
SLAVE_AXI_CONFIG_GAxiStreamConfigType := AXI_STREAM_CONFIG_INIT_C
in crcDataWidthslv( 2 downto 0)
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
INT_PIPE_STAGES_Gnatural range 0 to 16:= 0
AxiStreamSlaveType :=(tReady => '0') AXI_STREAM_SLAVE_INIT_C
BRAM_EN_Gboolean := true
_library_ ieeeieee
boolean TSTRB_EN_C
in macAddressslv( 47 downto 0)
TUserModeType TUSER_MODE_C
TPD_Gtime := 1 ns
natural range 0 to 8 TUSER_BITS_C
out sAxisSlaveAxiStreamSlaveType
in sAxisMasterAxiStreamMasterType
out mAxisMasterAxiStreamMasterType
in crcInslv(( BYTE_WIDTH_G* 8- 1) downto 0)
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