OpenCores
URL https://opencores.org/ocsvn/etherlab/etherlab/trunk

Subversion Repositories etherlab

[/] [etherlab/] [trunk/] [vhdl/] [mac_rcv.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 idiolatrie
--------------------------------------------------------------------------------
2
-- ETHERLAB - FPGA To C# To LABVIEW Bridge                                    --
3
--------------------------------------------------------------------------------
4
-- REFERENCES                                                                 --
5
--  [1] http://tools.ietf.org/html/rfc2460                                    --
6
--  [2] https://en.wikipedia.org/wiki/Ethernet_frame                          --
7
--  [5] http://outputlogic.com/my-stuff/circuit-cellar-january-2010-crc.pdf   --
8
--  [6] OPB Ethernet Lite Media Access Controller (v1.01b)                    --
9
--  [7] LAN83C185 - 10/100 Ethernet PHY                                       --
10
--  [8] Xilinx UG230                                                          --
11
--------------------------------------------------------------------------------
12
-- Copyright (C)2012  Mathias Hörtnagl <mathias.hoertnagl@gmail.com>          --
13
--                                                                            --
14
-- This program is free software: you can redistribute it and/or modify       --
15
-- it under the terms of the GNU General Public License as published by       --
16
-- the Free Software Foundation, either version 3 of the License, or          --
17
-- (at your option) any later version.                                        --
18
--                                                                            --
19
-- This program is distributed in the hope that it will be useful,            --
20
-- but WITHOUT ANY WARRANTY; without even the implied warranty of             --
21
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              --
22
-- GNU General Public License for more details.                               --
23
--                                                                            --
24
-- You should have received a copy of the GNU General Public License          --
25
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.      --
26
--------------------------------------------------------------------------------
27
library ieee;
28
use ieee.std_logic_1164.all;
29
use ieee.numeric_std.all;
30
 
31
library work;
32
use work.common.all;
33
 
34
entity mac_rcv is
35
   port(
36
      E_RX_CLK : in  std_logic;                      -- Receiver Clock.
37
      E_RX_DV  : in  std_logic;                      -- Received Data Valid.
38
      E_RXD    : in  std_logic_vector(3 downto 0);   -- Received Nibble.
39
      el_chnl  : out std_logic_vector(7 downto 0);   -- EtherLab channels.
40
      el_data  : out data_t;                         -- EtherLab channel data.
41
      el_dv    : out std_logic;                      -- EtherLab data valid.
42
      el_ack   : in  std_logic                       -- Packet reception ACK.
43
   );
44
end mac_rcv;
45
 
46
architecture rtl of mac_rcv is
47
 
48
   type state_t is (
49
      Preamble, StartOfFrame,             -- 7 Bytes 0x55, 1 Byte 0x5d.
50
      MACS,                               -- 12 Byte MAC addresses.
51
      EtherTypeCheck,                     -- Next Protocol EtherLab?
52
      Version,                            -- EtherLab - Version.
53
      Channel,                            -- EtherLab - Channel.
54
      DataU, DataL,                       -- EtherLab - Channel data.
55
      Notify                              -- Inform other hardware components.
56
   );
57
 
58
   type rcv_t is record
59
      s    : state_t;
60
      chnl : std_logic_vector(7 downto 0);   -- EtherLab channel field.
61
      d    : data_t;                         -- Channel data.
62
      c    : natural range 0 to 23;
63
      a    : natural range 0 to 7;
64
   end record;
65
 
66
   signal r, rin : rcv_t
67
      := rcv_t'(Preamble, x"00", (others => (others => '0')), 0, 0);
68
begin
69
 
70
   rcv_nsl : process(r, E_RX_DV, E_RXD, el_ack)
71
   begin
72
 
73
      rin   <= r;
74
      el_dv <= '0';
75
 
76
      if E_RX_DV = '1' then
77
         case r.s is
78
 
79
            --------------------------------------------------------------------
80
            -- Ethernet II - Preamble and Start Of Frame.                     --
81
            --------------------------------------------------------------------
82
            when Preamble =>
83
               if E_RXD = x"5" then
84
                  if r.c = 14 then
85
                     rin.c <= 0;
86
                     rin.s <= StartOfFrame;
87
                  else
88
                     rin.c <= r.c + 1;
89
                  end if;
90
               else
91
                  rin.c <= 0;
92
               end if;
93
 
94
            when StartOfFrame =>
95
               if E_RXD = x"d" then
96
                  rin.s <= MACS;
97
               else
98
                  rin.s <= Preamble;
99
               end if;
100
 
101
            --------------------------------------------------------------------
102
            -- Ethernet II - 12 Byte MAC addresses.                           --
103
            --------------------------------------------------------------------
104
            when MACS =>
105
               if r.c = 23 then
106
                  rin.c <= 0;
107
                  rin.s <= EtherTypeCheck;
108
               else
109
                  rin.c <= r.c + 1;
110
               end if;
111
 
112
            --------------------------------------------------------------------
113
            -- Ethernet II - Next Layer EtherLab?                             --
114
            --------------------------------------------------------------------
115
            when EtherTypeCheck =>
116
               if E_RXD = x"0" then
117
                  if r.c = 3 then
118
                     rin.c <= 0;
119
                     rin.s <= Version;
120
                  else
121
                     rin.c <= r.c + 1;
122
                  end if;
123
               else
124
                  rin.c <= 0;
125
                  rin.s <= Preamble;
126
               end if;
127
 
128
            --------------------------------------------------------------------
129
            -- EtherLab - Version                                             --
130
            --------------------------------------------------------------------
131
            when Version =>
132
               if r.c = 1 then
133
                  rin.c <= 0;
134
                  rin.s <= Channel;
135
               else
136
                  rin.c <= r.c + 1;
137
               end if;
138
 
139
            --------------------------------------------------------------------
140
            -- EtherLab - Channel Flags.                                       --
141
            --------------------------------------------------------------------
142
            when Channel =>
143
               rin.chnl(7 downto 0) <= E_RXD & r.chnl(7 downto 4);
144
               if r.c = 1 then
145
                  rin.c <= 0;
146
                  rin.a <= 0;
147
                  rin.s <= DataU;
148
               else
149
                  rin.c <= r.c + 1;
150
               end if;
151
 
152
            --------------------------------------------------------------------
153
            -- EtherLab - Data. 8 channels á 16 bit.                          --
154
            --------------------------------------------------------------------
155
            when DataU =>
156
               rin.d(r.a)(15 downto 8) <= E_RXD & r.d(r.a)(15 downto 12);
157
               if r.c = 1 then
158
                  rin.c <= 0;
159
                  rin.s <= DataL;
160
               else
161
                  rin.c <= r.c + 1;
162
               end if;
163
 
164
            when DataL =>
165
               rin.d(r.a)(7 downto 0) <= E_RXD & r.d(r.a)(7 downto 4);
166
               if r.c = 1 then
167
                  rin.c <= 0;
168
                  if r.a = 7 then
169
                     rin.a <= 0;
170
                     rin.s <= Notify;
171
                  else
172
                     rin.a <= r.a + 1;
173
                     rin.s <= DataU;
174
                  end if;
175
               else
176
                  rin.c <= r.c + 1;
177
               end if;
178
 
179
            --------------------------------------------------------------------
180
            -- Notification                                                   --
181
            --------------------------------------------------------------------
182
            when Notify =>
183
               el_dv <= '1';
184
               rin.s <= Preamble;
185
 
186
         end case;
187
      end if;
188
   end process;
189
 
190
   snd_reg : process(E_RX_CLK)
191
   begin
192
      if rising_edge(E_RX_CLK) then
193
         r <= rin;
194
      end if;
195
   end process;
196
 
197
   el_chnl <= r.chnl;
198
   el_data <= r.d;
199
end rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.