2a4b80d0fbe03ad69747e148b5fd93b0ed7f3f0c
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

27) 
28)     SIGNAL r_state:     t_state                       := st_idle;
29)     SIGNAL n_state:     t_state;
30)     SIGNAL r_data_cnt:  t_data_cnt                    := 0;
31)     SIGNAL n_data_cnt:  t_data_cnt;
32)     SIGNAL r_data:      std_logic_vector(31 DOWNTO 0) := (OTHERS => '0');
33)     SIGNAL n_data:      std_logic_vector(31 DOWNTO 0);
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

67)     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

68)                     i_if_data_ack,
69)                     i_frame_en, i_frame_data, i_frame_data_en,
70)                     s_crc_crc)
Stefan Schuermans fix CRC generation during e...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

72)     BEGIN
73)         n_state          <= r_state;
74)         n_data_cnt       <= r_data_cnt;
75)         n_data           <= r_data;
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

77)         n_crc_start      <= '0';
78)         o_if_data        <= X"00";
79)         o_if_data_en     <= '0';
80)         o_frame_data_ack <= '0';
Stefan Schuermans fixed uninitialized / not r...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

82)         s_crc_en         <= '0';
83)         s_crc_start      <= '0';
84)         s_crc_data       <= (OTHERS => '0');
85)         CASE r_state IS
86)             WHEN st_idle =>
87)                 IF i_frame_en = '1' THEN
88)                     n_state    <= st_sync;
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

90)                 END IF;
91)             WHEN st_sync =>
92)                 IF i_if_data_ack = '1' THEN
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

94)                         n_state <= st_start;
95)                     ELSE
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

97)                     END IF;
98)                 END IF;
99)                 o_if_data    <= X"55";
100)                 o_if_data_en <= '1';
101)             WHEN st_start =>
102)                 IF i_if_data_ack = '1' THEN
103)                     IF i_frame_data_en = '1' THEN
104)                         n_state          <= st_data;
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

108)                         n_crc_start      <= '1';
109)                         o_frame_data_ack <= '1';
110)                     ELSE
111)                         n_state    <= st_gap;
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)                     END IF;
114)                 END IF;
115)                 o_if_data    <= X"D5";
116)                 o_if_data_en <= '1';
117)             WHEN st_data =>
118)                 IF i_if_data_ack = '1' THEN
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

123)                             n_data           <= i_frame_data;
124)                             o_frame_data_ack <= '1';
125)                         ELSE
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

126)                             IF r_byte_cnt = 59 THEN
127)                                 n_state    <= st_crc;
128)                                 n_data_cnt <= 0;
129)                             ELSE
130)                                 n_state    <= st_pad;
131)                             END IF;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

132)                         END IF;
133)                     ELSE
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

137)                     IF r_byte_cnt /= 59 THEN
138)                         n_byte_cnt <= r_byte_cnt + 1;
139)                     END IF;
Stefan Schuermans fix CRC generation during e...

Stefan Schuermans authored 12 years ago

140)                     s_crc_en    <= '1';
141)                     s_crc_start <= r_crc_start;
142)                     s_crc_data  <= r_data(7 DOWNTO 0);
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

143)                 END IF;
144)                 o_if_data    <= r_data(7 DOWNTO 0);
145)                 o_if_data_en <= '1';
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

161)                     v_data := s_crc_crc; -- get CRC value on first CRC byte
162)                 ELSE
163)                     v_data := r_data;
164)                 END IF;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

172)                     END IF;
173)                 END IF;
Stefan Schuermans fix CRC generation during e...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

179)                     n_state      <= st_idle;
180)                     o_frame_done <= '1';
181)                 ELSE
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

195)             r_crc_start <= '0';
196)         ELSIF rising_edge(clk) THEN
197)             r_state     <= n_state;
198)             r_data_cnt  <= n_data_cnt;
199)             r_data      <= n_data;
Stefan Schuermans handle padding to minimum e...

Stefan Schuermans authored 12 years ago

200)             r_byte_cnt  <= n_byte_cnt;