c2b040193a777c09bdc595c95492b57a2521db87
Stefan Schuermans added file headers

Stefan Schuermans authored 12 years ago

1) -- MIPS I system
2) -- Copyright 2011-2012 Stefan Schuermans <stefan@schuermans.info>
3) -- Copyleft GNU public license V2 or later
4) --          http://www.gnu.org/copyleft/gpl.html
5) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

6) LIBRARY IEEE;
7) USE IEEE.STD_LOGIC_1164.ALL;
8) USE IEEE.NUMERIC_STD.ALL;
9) 
10) ENTITY e_io_eth_txframe IS
11)     PORT (
12)         rst:              IN  std_logic;
13)         clk:              IN  std_logic;
14)         o_if_data:        OUT std_logic_vector(7 DOWNTO 0);
15)         o_if_data_en:     OUT std_logic;
16)         i_if_data_ack:    IN  std_logic;
17)         i_frame_en:       IN  std_logic;
18)         i_frame_data:     IN  std_logic_vector(31 DOWNTO 0);
19)         i_frame_data_en:  IN  std_logic;
20)         o_frame_data_ack: OUT std_logic;
21)         o_frame_done:     OUT std_logic
22)     );
23) END ENTITY e_io_eth_txframe;
24) 
25) ARCHITECTURE a_io_eth_txframe OF e_io_eth_txframe IS
26) 
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

27)     TYPE t_state IS (st_idle, st_sync, st_start, st_data,
28)                      st_pad, st_crc, st_gap);
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

29) 
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

30)     SUBTYPE t_data_cnt IS natural RANGE 0 TO 3;
31)     SUBTYPE t_byte_cnt IS natural RANGE 0 TO 255;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

32) 
33)     SIGNAL r_state:     t_state                       := st_idle;
34)     SIGNAL n_state:     t_state;
35)     SIGNAL r_data_cnt:  t_data_cnt                    := 0;
36)     SIGNAL n_data_cnt:  t_data_cnt;
37)     SIGNAL r_data:      std_logic_vector(31 DOWNTO 0) := (OTHERS => '0');
38)     SIGNAL n_data:      std_logic_vector(31 DOWNTO 0);
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

39)     SIGNAL r_byte_cnt:  t_byte_cnt                    := 0;
40)     SIGNAL n_byte_cnt:  t_byte_cnt;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

41)     SIGNAL r_crc_start: std_logic                     := '0';
42)     SIGNAL n_crc_start: std_logic;
43) 
44)     SIGNAL s_crc_en:    std_logic;
45)     SIGNAL s_crc_start: std_logic;
46)     SIGNAL s_crc_data:  std_logic_vector( 7 DOWNTO 0);
47)     SIGNAL s_crc_crc:   std_logic_vector(31 DOWNTO 0);
48) 
49)     COMPONENT e_block_crc32 IS
50)         PORT (
51)             rst:     IN  std_logic;
52)             clk:     IN  std_logic;
53)             i_en:    IN  std_logic;
54)             i_start: IN  std_logic;
55)             i_data:  IN  std_logic_vector( 7 DOWNTO 0);
56)             o_crc:   OUT std_logic_vector(31 DOWNTO 0)
57)         );
58)     END COMPONENT e_block_crc32;
59) 
60) BEGIN
61) 
62)     crc32: e_block_crc32
63)         PORT MAP (
64)             rst     => rst,
65)             clk     => clk,
66)             i_en    => s_crc_en,
67)             i_start => s_crc_start,
68)             i_data  => s_crc_data,
69)             o_crc   => s_crc_crc
70)         );
71) 
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

72)     p_next: PROCESS(r_state, r_data_cnt, r_data, r_byte_cnt, r_crc_start,
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

73)                     i_if_data_ack,
74)                     i_frame_en, i_frame_data, i_frame_data_en,
75)                     s_crc_crc)
Stefan Schuermans fix CRC generation during e...

Stefan Schuermans authored 12 years ago

76)         VARIABLE v_data: std_logic_vector(31 DOWNTO 0);
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

77)     BEGIN
78)         n_state          <= r_state;
79)         n_data_cnt       <= r_data_cnt;
80)         n_data           <= r_data;
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

81)         n_byte_cnt       <= r_byte_cnt;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

82)         n_crc_start      <= '0';
83)         o_if_data        <= X"00";
84)         o_if_data_en     <= '0';
85)         o_frame_data_ack <= '0';
Stefan Schuermans fixed uninitialized / not r...

Stefan Schuermans authored 12 years ago

86)         o_frame_done     <= '0';
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

87)         s_crc_en         <= '0';
88)         s_crc_start      <= '0';
89)         s_crc_data       <= (OTHERS => '0');
90)         CASE r_state IS
91)             WHEN st_idle =>
92)                 IF i_frame_en = '1' THEN
93)                     n_state    <= st_sync;
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

94)                     n_byte_cnt <= 0;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

95)                 END IF;
96)             WHEN st_sync =>
97)                 IF i_if_data_ack = '1' THEN
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

98)                     IF r_byte_cnt = 6 THEN
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

99)                         n_state <= st_start;
100)                     ELSE
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

101)                         n_byte_cnt <= r_byte_cnt + 1;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

102)                     END IF;
103)                 END IF;
104)                 o_if_data    <= X"55";
105)                 o_if_data_en <= '1';
106)             WHEN st_start =>
107)                 IF i_if_data_ack = '1' THEN
108)                     IF i_frame_data_en = '1' THEN
109)                         n_state          <= st_data;
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

110)                         n_data_cnt       <= 0;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

111)                         n_data           <= i_frame_data;
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

112)                         n_byte_cnt       <= 0;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

113)                         n_crc_start      <= '1';
114)                         o_frame_data_ack <= '1';
115)                     ELSE
116)                         n_state    <= st_gap;
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

117)                         n_byte_cnt <= 0;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

118)                     END IF;
119)                 END IF;
120)                 o_if_data    <= X"D5";
121)                 o_if_data_en <= '1';
122)             WHEN st_data =>
123)                 IF i_if_data_ack = '1' THEN
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

124)                     IF r_data_cnt = 3 THEN
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

125)                         IF i_frame_data_en = '1' THEN
126)                             n_state          <= st_data;
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

127)                             n_data_cnt       <= 0;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

128)                             n_data           <= i_frame_data;
129)                             o_frame_data_ack <= '1';
130)                         ELSE
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

131)                             IF r_byte_cnt = 59 THEN
132)                                 n_state    <= st_crc;
133)                                 n_data_cnt <= 0;
134)                             ELSE
135)                                 n_state    <= st_pad;
136)                             END IF;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

137)                         END IF;
138)                     ELSE
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

139)                         n_data_cnt          <= r_data_cnt + 1;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

140)                         n_data(23 DOWNTO 0) <= r_data(31 DOWNTO 8);
141)                     END IF;
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

142)                     IF r_byte_cnt /= 59 THEN
143)                         n_byte_cnt <= r_byte_cnt + 1;
144)                     END IF;
Stefan Schuermans fix CRC generation during e...

Stefan Schuermans authored 12 years ago

145)                     s_crc_en    <= '1';
146)                     s_crc_start <= r_crc_start;
147)                     s_crc_data  <= r_data(7 DOWNTO 0);
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

148)                 END IF;
149)                 o_if_data    <= r_data(7 DOWNTO 0);
150)                 o_if_data_en <= '1';
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

151)             WHEN st_pad =>
152)                 IF i_if_data_ack = '1' THEN
153)                     IF r_byte_cnt = 59 THEN
154)                         n_state    <= st_crc;
155)                         n_data_cnt <= 0;
156)                     ELSE
157)                         n_byte_cnt <= r_byte_cnt + 1;
158)                     END IF;
159)                     s_crc_en   <= '1';
160)                     s_crc_data <= (OTHERS => '0');
161)                 END IF;
162)                 o_if_data    <= (OTHERS => '0');
163)                 o_if_data_en <= '1';
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

164)             WHEN st_crc =>
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

165)                 IF r_data_cnt = 0 THEN
Stefan Schuermans fix CRC generation during e...

Stefan Schuermans authored 12 years ago

166)                     v_data := s_crc_crc; -- get CRC value on first CRC byte
167)                 ELSE
168)                     v_data := r_data;
169)                 END IF;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

170)                 IF i_if_data_ack = '1' THEN
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

171)                     IF r_data_cnt = 3 THEN
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

172)                         n_state    <= st_gap;
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

173)                         n_byte_cnt <= 0;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

174)                     ELSE
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

175)                         n_data_cnt          <= r_data_cnt + 1;
Stefan Schuermans fix CRC generation during e...

Stefan Schuermans authored 12 years ago

176)                         n_data(23 DOWNTO 0) <= v_data(31 DOWNTO 8);
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

177)                     END IF;
178)                 END IF;
Stefan Schuermans fix CRC generation during e...

Stefan Schuermans authored 12 years ago

179)                 o_if_data    <= v_data(7 DOWNTO 0);
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

180)                 o_if_data_en <= '1';
181)             WHEN st_gap =>
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

182)                  -- 12 octets, *2 because of clk, plus async FIFO len
183)                 IF r_byte_cnt = 12 * 8 * 2 + 16 THEN
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

184)                     n_state      <= st_idle;
185)                     o_frame_done <= '1';
186)                 ELSE
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

187)                     n_byte_cnt <= r_byte_cnt + 1;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

188)                 END IF;
189)             WHEN OTHERS => NULL;
190)         END CASE;
191)     END PROCESS p_next;
192) 
193)     p_sync: PROCESS(rst, clk)
194)     BEGIN
195)         IF rst = '1' THEN
196)             r_state     <= st_idle;
197)             r_data_cnt  <= 0;
198)             r_data      <= (OTHERS => '0');
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

199)             r_byte_cnt  <= 0;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

200)             r_crc_start <= '0';
201)         ELSIF rising_edge(clk) THEN
202)             r_state     <= n_state;
203)             r_data_cnt  <= n_data_cnt;
204)             r_data      <= n_data;
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

205)             r_byte_cnt  <= n_byte_cnt;