SURF  1.0
RawEthFramer.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : RawEthFramer.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2016-05-23
5 -- Last update: 2016-05-26
6 -------------------------------------------------------------------------------
7 -- Description: Top-level Raw L2 Ethernet Framer
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_unsigned.all;
21 use ieee.std_logic_arith.all;
22 
23 use work.StdRtlPkg.all;
24 use work.AxiStreamPkg.all;
25 
26 --! @see entity
27  --! @ingroup ethernet_RawEthFramer
28 entity RawEthFramer is
29  generic (
30  TPD_G : time := 1 ns;
31  ETH_TYPE_G : slv(15 downto 0) := x"0010"); -- 0x1000 (big-Endian configuration)
32  port (
33  -- Local Configurations
34  localMac : in slv(47 downto 0); -- big-Endian configuration
35  remoteMac : in slv(47 downto 0); -- big-Endian configuration
36  tDest : out slv(7 downto 0);
37  -- Interface to Ethernet Media Access Controller (MAC)
42  -- Interface to Application engine(s)
47  -- Clock and Reset
48  clk : in sl;
49  rst : in sl);
50 end RawEthFramer;
51 
52 architecture rtl of RawEthFramer is
53 
54  type StateType is (
55  IDLE_S,
56  RX_S,
57  TX_S);
58 
59  type RegType is record
60  rxAck : sl;
61  txAck : sl;
62  rxMac : slv(47 downto 0);
63  txMac : slv(47 downto 0);
64  rdEn : sl;
65  tDest : slv(7 downto 0);
66  state : StateType;
67  end record RegType;
68  constant REG_INIT_C : RegType := (
69  rxAck => '0',
70  txAck => '0',
71  rxMac => (others => '0'),
72  txMac => (others => '0'),
73  rdEn => '0',
74  tDest => (others => '0'),
75  state => IDLE_S);
76 
77  signal r : RegType := REG_INIT_C;
78  signal rin : RegType;
79 
80  signal rxReq : sl;
81  signal txReq : sl;
82  signal rxDest : slv(7 downto 0);
83  signal txDest : slv(7 downto 0);
84  signal rxAck : sl;
85  signal txAck : sl;
86  signal rxMac : slv(47 downto 0);
87  signal txMac : slv(47 downto 0);
88 
89  -- attribute dont_touch : string;
90  -- attribute dont_touch of r : signal is "TRUE";
91 
92 begin
93 
94  U_Tx : entity work.RawEthFramerTx
95  generic map (
96  TPD_G => TPD_G,
98  port map (
99  -- Local Configurations
100  localMac => localMac,
101  remoteMac => txMac,
102  tDest => txDest,
103  req => txReq,
104  ack => txAck,
105  -- Interface to Ethernet Media Access Controller (MAC)
108  -- Interface to Application engine(s)
111  -- Clock and Reset
112  clk => clk,
113  rst => rst);
114 
115  U_Rx : entity work.RawEthFramerRx
116  generic map (
117  TPD_G => TPD_G,
119  port map (
120  -- Local Configurations
121  localMac => localMac,
122  remoteMac => rxMac,
123  tDest => rxDest,
124  req => rxReq,
125  ack => rxAck,
126  -- Interface to Ethernet Media Access Controller (MAC)
129  -- Interface to Application engine(s)
132  -- Clock and Reset
133  clk => clk,
134  rst => rst);
135 
136  comb : process (r, remoteMac, rst, rxDest, rxReq, txDest, txReq) is
137  variable v : RegType;
138  begin
139  -- Latch the current value
140  v := r;
141 
142  -- Reset the flags
143  v.rxAck := '0';
144  v.txAck := '0';
145 
146  -- shift Register
147  v.rdEn := '0';
148 
149  -- State Machine
150  case r.state is
151  ----------------------------------------------------------------------
152  when IDLE_S =>
153  -- Check for RX request
154  if (r.rxAck = '0') and (rxReq = '1') then
155  -- Set the flag
156  v.rdEn := '1';
157  -- Set the data bus
158  v.tDest := rxDest;
159  -- Next state
160  v.state := RX_S;
161  elsif (r.txAck = '0') and (txReq = '1') then
162  -- Set the flag
163  v.rdEn := '1';
164  -- Set the data bus
165  v.tDest := txDest;
166  -- Next state
167  v.state := TX_S;
168  end if;
169  ----------------------------------------------------------------------
170  when RX_S =>
171  -- Check if data is ready
172  if r.rdEn = '0' then
173  -- Set the flag
174  v.rxAck := '1';
175  -- Set the data bus
176  v.rxMac := remoteMac;
177  -- Next state
178  v.state := IDLE_S;
179  end if;
180  ----------------------------------------------------------------------
181  when TX_S =>
182  -- Check if data is ready
183  if r.rdEn = '0' then
184  -- Set the flag
185  v.txAck := '1';
186  -- Set the data bus
187  v.txMac := remoteMac;
188  -- Next state
189  v.state := IDLE_S;
190  end if;
191  ----------------------------------------------------------------------
192  end case;
193 
194  -- Reset
195  if (rst = '1') then
196  v := REG_INIT_C;
197  end if;
198 
199  -- Register the variable for next clock cycle
200  rin <= v;
201 
202  -- Outputs
203  tDest <= v.tDest;
204  rxAck <= v.rxAck;
205  txAck <= v.txAck;
206  rxMac <= v.rxMac;
207  txMac <= v.txMac;
208 
209  end process comb;
210 
211  seq : process (clk) is
212  begin
213  if rising_edge(clk) then
214  r <= rin after TPD_G;
215  end if;
216  end process seq;
217 
218 end rtl;
std_logic sl
Definition: StdRtlPkg.vhd:28
in ibAppSlaveAxiStreamSlaveType
in ibAppSlaveAxiStreamSlaveType
out ibMacMasterAxiStreamMasterType
out ibAppMasterAxiStreamMasterType
ETH_TYPE_Gslv( 15 downto 0) := x"0010"
TPD_Gtime := 1 ns
in remoteMacslv( 47 downto 0)
out obAppSlaveAxiStreamSlaveType
out tDestslv( 7 downto 0)
TPD_Gtime := 1 ns
in obAppMasterAxiStreamMasterType
TPD_Gtime := 1 ns
in remoteMacslv( 47 downto 0)
out ibMacMasterAxiStreamMasterType
in ibMacSlaveAxiStreamSlaveType
in obMacMasterAxiStreamMasterType
out tDestslv( 7 downto 0)
in localMacslv( 47 downto 0)
out obMacSlaveAxiStreamSlaveType
ETH_TYPE_Gslv( 15 downto 0) := x"0010"
in obMacMasterAxiStreamMasterType
out obAppSlaveAxiStreamSlaveType
out ibAppMasterAxiStreamMasterType
out obMacSlaveAxiStreamSlaveType
in remoteMacslv( 47 downto 0)
in localMacslv( 47 downto 0)
_library_ ieeeieee
in ibMacSlaveAxiStreamSlaveType
in obAppMasterAxiStreamMasterType
ETH_TYPE_Gslv( 15 downto 0) := x"0010"
in localMacslv( 47 downto 0)
out tDestslv( 7 downto 0)
std_logic_vector slv
Definition: StdRtlPkg.vhd:29