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 begin of ethernet RX implem...

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 IS
11)     PORT (
12)         rst:          IN  std_logic;
13)         clk:          IN  std_logic;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

14)         i_addr:       IN  std_logic_vector( 3 DOWNTO 0);
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

15)         o_rd_data:    OUT std_logic_vector(31 DOWNTO 0);
Stefan Schuermans add read_enable signal to d...

Stefan Schuermans authored 12 years ago

16)         i_rd_en:      IN  std_logic_vector( 3 DOWNTO 0);
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

17)         i_wr_data:    IN  std_logic_vector(31 DOWNTO 0);
18)         i_wr_en:      IN  std_logic_vector( 3 DOWNTO 0);
Stefan Schuermans implemented multi-master fe...

Stefan Schuermans authored 12 years ago

19)         o_bm_req:     OUT std_logic;
20)         i_bm_grant:   IN  std_logic;
21)         o_bm_addr:    OUT std_logic_vector(31 DOWNTO 0);
22)         i_bm_rd_data: IN  std_logic_vector(31 DOWNTO 0);
23)         o_bm_rd_en:   OUT std_logic_vector( 3 DOWNTO 0);
24)         o_bm_wr_data: OUT std_logic_vector(31 DOWNTO 0);
25)         o_bm_wr_en:   OUT std_logic_vector( 3 DOWNTO 0);
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

26)         pin_o_nrst:   OUT std_logic;
27)         pin_i_rx_clk: IN  std_logic;
28)         pin_i_rxd:    IN  std_logic_vector(4 DOWNTO 0);
29)         pin_i_rx_dv:  IN  std_logic;
30)         pin_i_crs:    IN  std_logic;
31)         pin_i_col:    IN  std_logic;
32)         pin_i_tx_clk: IN  std_logic;
33)         pin_o_txd:    OUT std_logic_vector(3 DOWNTO 0);
34)         pin_o_tx_en:  OUT std_logic
35)     );
36) END ENTITY e_io_eth;
37) 
38) ARCHITECTURE a_io_eth OF e_io_eth IS
39) 
Stefan Schuermans implemented ethernet RX fra...

Stefan Schuermans authored 12 years ago

40)     SIGNAL s_rxif_data:    std_logic_vector(7 DOWNTO 0);
41)     SIGNAL s_rxif_data_en: std_logic;
42)     SIGNAL s_rxif_done:    std_logic;
43)     SIGNAL s_rxif_err:     std_logic;
44) 
45)     SIGNAL s_rxframe_data:    std_logic_vector(31 DOWNTO 0);
46)     SIGNAL s_rxframe_data_en: std_logic;
47)     SIGNAL s_rxframe_done:    std_logic;
48)     SIGNAL s_rxframe_err:     std_logic;
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

49) 
Stefan Schuermans implemented ethernet TX int...

Stefan Schuermans authored 12 years ago

50)     SIGNAL s_rx_new: std_logic;
51) 
52)     SIGNAL s_txif_data:     std_logic_vector(7 DOWNTO 0);
53)     SIGNAL s_txif_data_en:  std_logic;
54)     SIGNAL s_txif_data_ack: std_logic;
55) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

56)     SIGNAL s_txframe_en:   std_logic;
57)     SIGNAL s_txframe_done: std_logic;
58) 
59)     SIGNAL s_txbuf_wr_rdy:  std_logic;
60)     SIGNAL s_txbuf_wr_data: std_logic_vector(31 DOWNTO 0);
61)     SIGNAL s_txbuf_wr_en:   std_logic;
62)     SIGNAL s_txbuf_rd_rdy:  std_logic;
63)     SIGNAL s_txbuf_rd_data: std_logic_vector(31 DOWNTO 0);
64)     SIGNAL s_txbuf_rd_en:   std_logic;
65) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

66)     -- RX buffer registers
67)     --   start: current buffer begin
68)     --   cur: address of next data write
69)     --   size: size of data received
70)     --   end: address just behind buffer
71)     --   data is written to buffer like this: <size><data 0>...<data size-1>
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

72)     --     size is written last
73)     --     next packet begins directly afterwards
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

74)     --   all addresses/sizes are word-aligned
75)     SIGNAL r_rx_start: std_logic_vector(31 DOWNTO 0) := X"00000000";
76)     SIGNAL n_rx_start: std_logic_vector(31 DOWNTO 0);
77)     SIGNAL r_rx_cur:   std_logic_vector(31 DOWNTO 0) := X"00000004";
78)     SIGNAL n_rx_cur:   std_logic_vector(31 DOWNTO 0);
79)     SIGNAL r_rx_size:  std_logic_vector(31 DOWNTO 0) := X"00000000";
80)     SIGNAL n_rx_size:  std_logic_vector(31 DOWNTO 0);
81)     SIGNAL r_rx_end:   std_logic_vector(31 DOWNTO 0) := X"00000000";
82)     SIGNAL n_rx_end:   std_logic_vector(31 DOWNTO 0);
83) 
84)     -- RX new buffer registers
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

85)     --   new_start: begin of new buffer
86)     --   new_end: address just behind new buffer
87)     --   new_en: if a new buffer is available
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

88)     --   all addresses are word-aligned
89)     SIGNAL r_rx_new_start: std_logic_vector(31 DOWNTO 0) := X"00000000";
90)     SIGNAL n_rx_new_start: std_logic_vector(31 DOWNTO 0);
91)     SIGNAL r_rx_new_end:   std_logic_vector(31 DOWNTO 0) := X"00000000";
92)     SIGNAL n_rx_new_end:   std_logic_vector(31 DOWNTO 0);
93)     SIGNAL r_rx_new_en:    std_logic                     := '0';
94)     SIGNAL n_rx_new_en:    std_logic;
95) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

96)     -- TX buffer registers
Stefan Schuermans handle eth TX packets of od...

Stefan Schuermans authored 12 years ago

97)     --   start: begin of buffer (word-aligned)
98)     --   end: address just behind buffer (NOT word-aligned)
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

99)     --   en: write 1 to start transmission, returns to zero if complete
100)     SIGNAL r_tx_start: std_logic_vector(31 DOWNTO 0) := X"00000000";
101)     SIGNAL n_tx_start: std_logic_vector(31 DOWNTO 0);
102)     SIGNAL r_tx_end:   std_logic_vector(31 DOWNTO 0) := X"00000000";
103)     SIGNAL n_tx_end:   std_logic_vector(31 DOWNTO 0);
104)     SIGNAL r_tx_en:    std_logic                     := '0';
105)     SIGNAL n_tx_en:    std_logic;
106) 
Stefan Schuermans made MAC configurable in et...

Stefan Schuermans authored 12 years ago

107)     -- MAC address register
108)     SIGNAL r_mac: std_logic_vector(47 DOWNTO 0) := X"FFFFFFFFFFFF";
109)     SIGNAL n_mac: std_logic_vector(47 DOWNTO 0);
110) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

111)     -- TX busmaster read state machine
Stefan Schuermans handle eth TX packets of od...

Stefan Schuermans authored 12 years ago

112)     --   pos: next address to read (NOT word-aligned)
113)     --   rem: number of bytes remaining (NOT multiple of words size)
114)     SIGNAL r_tx_pos: std_logic_vector(31 DOWNTO 0) := X"00000000";
115)     SIGNAL n_tx_pos: std_logic_vector(31 DOWNTO 0);
116)     SIGNAL r_tx_rem: signed          (31 DOWNTO 0) := X"00000000";
117)     SIGNAL n_tx_rem: signed          (31 DOWNTO 0);
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

118) 
119)     -- busmaster write buffer
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

120)     SIGNAL s_wrbuf_wr_rdy:  std_logic;
121)     SIGNAL s_wrbuf_wr_data: std_logic_vector(63 DOWNTO 0);
122)     SIGNAL s_wrbuf_wr_en:   std_logic;
123)     SIGNAL s_wrbuf_rd_rdy:  std_logic;
124)     SIGNAL s_wrbuf_rd_data: std_logic_vector(63 DOWNTO 0);
125)     SIGNAL s_wrbuf_rd_en:   std_logic;
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

126) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

127)     -- busmaster read flag
128)     SIGNAL r_bm_rd: std_logic := '0';
129)     SIGNAL n_bm_rd: std_logic;
130) 
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

131)     COMPONENT e_io_eth_rst IS
132)         PORT (
133)             rst:        IN  std_logic;
134)             clk:        IN  std_logic;
135)             pin_o_nrst: OUT std_logic
136)         );
137)     END COMPONENT e_io_eth_rst;
138) 
139)     COMPONENT e_io_eth_rxif IS
140)         PORT (
141)             rst:          IN  std_logic;
142)             clk:          IN  std_logic;
143)             o_data:       OUT std_logic_vector(7 DOWNTO 0);
144)             o_data_en:    OUT std_logic;
145)             o_done:       OUT std_logic;
146)             o_err:        OUT std_logic;
147)             pin_i_rx_clk: IN  std_logic;
148)             pin_i_rxd:    IN  std_logic_vector(4 DOWNTO 0);
149)             pin_i_rx_dv:  IN  std_logic;
150)             pin_i_crs:    IN  std_logic;
151)             pin_i_col:    IN  std_logic
152)         );
153)     END COMPONENT e_io_eth_rxif;
154) 
Stefan Schuermans implemented ethernet RX fra...

Stefan Schuermans authored 12 years ago

155)     COMPONENT e_io_eth_rxframe IS
156)         PORT (
157)             rst:       IN  std_logic;
158)             clk:       IN  std_logic;
159)             i_data:    IN  std_logic_vector( 7 DOWNTO 0);
160)             i_data_en: IN  std_logic;
161)             i_done:    IN  std_logic;
162)             i_err:     IN  std_logic;
163)             i_mac:     IN  std_logic_vector(47 DOWNTO 0);
164)             o_data:    OUT std_logic_vector(31 DOWNTO 0);
165)             o_data_en: OUT std_logic;
166)             o_done:    OUT std_logic;
167)             o_err:     OUT std_logic
168)         );
169)     END COMPONENT e_io_eth_rxframe;
170) 
Stefan Schuermans implemented ethernet TX int...

Stefan Schuermans authored 12 years ago

171)     COMPONENT e_io_eth_txif IS
172)         PORT (
173)             rst:          IN  std_logic;
174)             clk:          IN  std_logic;
175)             i_data:       IN  std_logic_vector(7 DOWNTO 0);
176)             i_data_en:    IN  std_logic;
177)             o_data_ack:   OUT std_logic;
178)             pin_i_tx_clk: IN  std_logic;
179)             pin_o_txd:    OUT std_logic_vector(3 DOWNTO 0);
180)             pin_o_tx_en:  OUT std_logic
181)         );
182)     END COMPONENT e_io_eth_txif;
183) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

184)     COMPONENT e_io_eth_txframe IS
185)         PORT (
186)             rst:              IN  std_logic;
187)             clk:              IN  std_logic;
188)             o_if_data:        OUT std_logic_vector(7 DOWNTO 0);
189)             o_if_data_en:     OUT std_logic;
190)             i_if_data_ack:    IN  std_logic;
191)             i_frame_en:       IN  std_logic;
192)             i_frame_data:     IN  std_logic_vector(31 DOWNTO 0);
193)             i_frame_data_en:  IN  std_logic;
194)             o_frame_data_ack: OUT std_logic;
195)             o_frame_done:     OUT std_logic
196)         );
197)     END COMPONENT e_io_eth_txframe;
198) 
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

199)     COMPONENT e_block_fifo IS
200)         GENERIC (
201)             addr_width: natural;
202)             data_width: natural
203)         );
204)         PORT (
205)             rst:       IN  std_logic;
206)             clk:       IN  std_logic;
207)             o_wr_rdy:  OUT std_logic;
208)             i_wr_data: IN  std_logic_vector(data_width - 1 DOWNTO 0);
209)             i_wr_en:   IN  std_logic;
210)             o_rd_rdy:  OUT std_logic;
211)             o_rd_data: OUT std_logic_vector(data_width - 1 DOWNTO 0);
212)             i_rd_en:   IN  std_logic
213)         );
214)     END COMPONENT e_block_fifo;
215) 
216) BEGIN
217) 
218)     reset: e_io_eth_rst
219)         PORT MAP (
220)             rst        => rst,
221)             clk        => clk,
222)             pin_o_nrst => pin_o_nrst
223)         );
224) 
225)     rxif: e_io_eth_rxif
226)         PORT MAP (
227)             rst          => rst,
228)             clk          => clk,
Stefan Schuermans implemented ethernet RX fra...

Stefan Schuermans authored 12 years ago

229)             o_data       => s_rxif_data,
230)             o_data_en    => s_rxif_data_en,
231)             o_done       => s_rxif_done,
232)             o_err        => s_rxif_err,
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

233)             pin_i_rx_clk => pin_i_rx_clk,
234)             pin_i_rxd    => pin_i_rxd,
235)             pin_i_rx_dv  => pin_i_rx_dv,
236)             pin_i_crs    => pin_i_crs,
237)             pin_i_col    => pin_i_col
238)         );
239) 
Stefan Schuermans implemented ethernet RX fra...

Stefan Schuermans authored 12 years ago

240)     rxframe: e_io_eth_rxframe
241)         PORT MAP (
242)             rst       => rst,
243)             clk       => clk,
244)             i_data    => s_rxif_data,
245)             i_data_en => s_rxif_data_en,
246)             i_done    => s_rxif_done,
247)             i_err     => s_rxif_err,
Stefan Schuermans made MAC configurable in et...

Stefan Schuermans authored 12 years ago

248)             i_mac     => r_mac,
Stefan Schuermans implemented ethernet RX fra...

Stefan Schuermans authored 12 years ago

249)             o_data    => s_rxframe_data,
250)             o_data_en => s_rxframe_data_en,
251)             o_done    => s_rxframe_done,
252)             o_err     => s_rxframe_err
253)         );
254) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

255)     p_rx_next: PROCESS(r_rx_start, r_rx_cur, r_rx_size, r_rx_end,
256)                        r_rx_new_start, r_rx_new_end, r_rx_new_en,
257)                        s_rxframe_data, s_rxframe_data_en,
258)                        s_rxframe_done, s_rxframe_err,
259)                        s_wrbuf_wr_rdy)
260)         VARIABLE v_abort:  boolean; -- abort current packet reception
261)         VARIABLE v_ignore: boolean; -- ignore rest of packet
262)         VARIABLE v_store:  boolean; -- store packet data
263)         VARIABLE v_finish: boolean; -- finish reception of packet
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

264)     BEGIN
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

265)         n_rx_start      <= r_rx_start;
266)         n_rx_cur        <= r_rx_cur;
267)         n_rx_size       <= r_rx_size;
268)         n_rx_end        <= r_rx_end;
269)         s_wrbuf_wr_data <= (OTHERS => '0');
270)         s_wrbuf_wr_en   <= '0';
271)         s_rx_new        <= '0';
272) 
273)         -- determine which action to perform
274)         v_abort  := false;
275)         v_ignore := false;
276)         v_store  := false;
277)         v_finish := false;
278)         -- incoming data
279)         IF s_rxframe_data_en = '1' THEN
280)             IF r_rx_start = r_rx_end THEN
281)                 v_ignore := true; -- buffer not available -> ignore rest of packet
282)             ELSIF r_rx_cur = r_rx_end THEN
283)                 v_ignore := true; -- buffer full -> ignore rest of packet
284)             ELSIF s_wrbuf_wr_rdy = '0' THEN
285)                 v_ignore := true; -- bus master write buffer full -> ignore rest of packet
286)             ELSE
287)                 v_store := true; -- store data
288)             END IF;
289)         -- packet complete
Stefan Schuermans implemented ethernet RX fra...

Stefan Schuermans authored 12 years ago

290)         ELSIF s_rxframe_done = '1' THEN
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

291)             IF r_rx_start = r_rx_end THEN
292)                 v_abort := true; -- buffer not available -> abort
293)             ELSIF r_rx_cur = r_rx_end THEN
294)                 v_abort := true; -- buffer full -> abort
295)             ELSIF s_wrbuf_wr_rdy = '0' THEN
296)                 v_abort := true; -- bus master write buffer full -> abort
297)             ELSIF r_rx_size = X"00000000" THEN
298)                 v_abort := true; -- empty packet -> abort
299)             ELSE
300)                 v_finish := true; -- finish packet recpetion
301)             END IF;
302)         -- error
303)         ELSIF s_rxframe_err = '1' THEN
304)             v_abort := true; -- abort
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

305)         END IF;
306) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

307)         -- perform action selected above
308)         -- abort current packet
309)         IF v_abort THEN
310)             n_rx_cur  <= std_logic_vector(unsigned(r_rx_start) + X"00000004");
311)             n_rx_size <= X"00000000";
312)         -- ignore rest of packet
313)         --   count size to ensure it is not zero
314)         ELSIF v_ignore THEN
315)             n_rx_cur  <= r_rx_end;
316)             n_rx_size <= std_logic_vector(unsigned(r_rx_size) + X"00000004");
317)         -- store data to current address and advance in buffer
318)         ELSIF v_store THEN
319)             s_wrbuf_wr_data <= r_rx_cur & s_rxframe_data;
320)             s_wrbuf_wr_en   <= '1';
321)             n_rx_cur  <= std_logic_vector(unsigned(r_rx_cur) + X"00000004");
322)             n_rx_size <= std_logic_vector(unsigned(r_rx_size) + X"00000004");
323)         -- store size to start and restart after packet
324)         ELSIF v_finish THEN
325)             s_wrbuf_wr_data <= r_rx_start & r_rx_size;
326)             s_wrbuf_wr_en   <= '1';
327)             n_rx_start <= r_rx_cur;
328)             n_rx_cur   <= std_logic_vector(unsigned(r_rx_cur) + X"00000004");
329)             n_rx_size  <= X"00000000";
330)         END IF;
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

331) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

332)         -- use new buffer
333)         --   if no action, no data yet and new_en set
334)         IF NOT v_abort AND NOT v_ignore AND NOT v_store AND NOT v_finish AND
335)            r_rx_size = X"00000000" AND r_rx_new_en = '1' THEN
336)             -- terminate old buffer by writing size 0 (if old buffer was available)
337)             IF r_rx_start /= r_rx_end THEN
338)                 s_wrbuf_wr_data <= r_rx_start & X"00000000";
339)                 s_wrbuf_wr_en   <= '1';
340)             END IF;
341)             -- take over new_start and new_end
342)             n_rx_start <= r_rx_new_start;
343)             n_rx_cur   <= std_logic_vector(unsigned(r_rx_new_start) + X"00000004");
344)             n_rx_size  <= X"00000000";
345)             n_rx_end   <= r_rx_new_end;
346)             -- signal overtake of new buffer to process p_write
347)             s_rx_new   <= '1';
348)         END IF;
349)     END PROCESS p_rx_next;
Stefan Schuermans fix reading (1 cycle latenc...

Stefan Schuermans authored 12 years ago

350) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

351)     txif: e_io_eth_txif
352)         PORT MAP (
353)             rst          => rst,
354)             clk          => clk,
355)             i_data       => s_txif_data,
356)             i_data_en    => s_txif_data_en,
357)             o_data_ack   => s_txif_data_ack,
358)             pin_i_tx_clk => pin_i_tx_clk,
359)             pin_o_txd    => pin_o_txd,
360)             pin_o_tx_en  => pin_o_tx_en
361)         );
362) 
363)     txframe: e_io_eth_txframe
364)         PORT MAP (
365)             rst              => rst,
366)             clk              => clk,
367)             o_if_data        => s_txif_data,
368)             o_if_data_en     => s_txif_data_en,
369)             i_if_data_ack    => s_txif_data_ack,
370)             i_frame_en       => s_txframe_en,
371)             i_frame_data     => s_txbuf_rd_data,
372)             i_frame_data_en  => s_txbuf_rd_rdy,
373)             o_frame_data_ack => s_txbuf_rd_en,
374)             o_frame_done     => s_txframe_done
375)         );
376) 
377)     txbuf: e_block_fifo
378)         GENERIC MAP (
379)             addr_width => 2,
380)             data_width => 32
381)         )
382)         PORT MAP (
383)             rst       => rst,
384)             clk       => clk,
385)             o_wr_rdy  => s_txbuf_wr_rdy,
386)             i_wr_data => s_txbuf_wr_data,
387)             i_wr_en   => s_txbuf_wr_en,
388)             o_rd_rdy  => s_txbuf_rd_rdy,
389)             o_rd_data => s_txbuf_rd_data,
390)             i_rd_en   => s_txbuf_rd_en
391)         );
392) 
393)     p_reg_sync: PROCESS(rst, clk)
Stefan Schuermans fix reading (1 cycle latenc...

Stefan Schuermans authored 12 years ago

394)     BEGIN
395)         IF rst = '1' THEN
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

396)             r_rx_start     <= X"00000000";
397)             r_rx_cur       <= X"00000004";
398)             r_rx_size      <= X"00000000";
399)             r_rx_end       <= X"00000000";
400)             r_rx_new_start <= X"00000000";
401)             r_rx_new_end   <= X"00000000";
402)             r_rx_new_en    <= '0';
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

403)             r_tx_start     <= X"00000000";
404)             r_tx_end       <= X"00000000";
405)             r_tx_en        <= '0';
Stefan Schuermans made MAC configurable in et...

Stefan Schuermans authored 12 years ago

406)             r_mac          <= X"FFFFFFFFFFFF";
Stefan Schuermans fix reading (1 cycle latenc...

Stefan Schuermans authored 12 years ago

407)         ELSIF rising_edge(clk) THEN
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

408)             r_rx_start     <= n_rx_start;
409)             r_rx_cur       <= n_rx_cur;
410)             r_rx_size      <= n_rx_size;
411)             r_rx_end       <= n_rx_end;
412)             r_rx_new_start <= n_rx_new_start;
413)             r_rx_new_end   <= n_rx_new_end;
414)             r_rx_new_en    <= n_rx_new_en;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

415)             r_tx_start     <= n_tx_start;
416)             r_tx_end       <= n_tx_end;
417)             r_tx_en        <= n_tx_en;
Stefan Schuermans made MAC configurable in et...

Stefan Schuermans authored 12 years ago

418)             r_mac          <= n_mac;
Stefan Schuermans fix reading (1 cycle latenc...

Stefan Schuermans authored 12 years ago

419)         END IF;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

420)     END PROCESS p_reg_sync;
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

421) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

422)     -- register interface write
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

423)     p_write: PROCESS(r_rx_new_start, r_rx_new_end, r_rx_new_en, s_rx_new,
Stefan Schuermans made MAC configurable in et...

Stefan Schuermans authored 12 years ago

424)                      r_tx_start, r_tx_end, r_tx_en, s_txframe_done, r_mac,
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

425)                      i_addr, i_wr_data, i_wr_en)
426)     BEGIN
427)         n_rx_new_start <= r_rx_new_start;
428)         n_rx_new_end   <= r_rx_new_end;
429)         n_rx_new_en    <= r_rx_new_en;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

430)         n_tx_start     <= r_tx_start;
431)         n_tx_end       <= r_tx_end;
432)         n_tx_en        <= r_tx_en;
Stefan Schuermans made MAC configurable in et...

Stefan Schuermans authored 12 years ago

433)         n_mac          <= r_mac;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

434)         s_txframe_en   <= '0';
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

435)         IF s_rx_new = '1' THEN
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

436)             n_rx_new_en <= '0'; -- new buffer has been overtaken, reset rx_new_en
437)         END IF;
438)         IF s_txframe_done = '1' THEN
439)             n_tx_en <= '0'; -- TX operation completed, reset tx_en
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

440)         END IF;
Stefan Schuermans made MAC configurable in et...

Stefan Schuermans authored 12 years ago

441)         CASE i_addr IS
442)             WHEN "0100" =>
443)                 IF i_wr_en = "1111" THEN
444)                     n_rx_new_start <= i_wr_data;
445)                 END IF;
446)             WHEN "0101" =>
447)                 IF i_wr_en = "1111" THEN
448)                     n_rx_new_end <= i_wr_data;
449)                 END IF;
450)             WHEN "0110" =>
451)                 IF i_wr_en(0) = '1' AND i_wr_data(0) = '1' THEN
452)                     n_rx_new_en <= '1';
453)                 END IF;
454)             WHEN "1000" =>
455)                 IF i_wr_en = "1111" AND r_tx_en = '0' THEN
456)                     n_tx_start <= i_wr_data;
457)                 END IF;
458)             WHEN "1001" =>
459)                 IF i_wr_en = "1111" AND r_tx_en = '0' THEN
460)                     n_tx_end <= i_wr_data;
461)                 END IF;
462)             WHEN "1010" =>
463)                 IF i_wr_en(0) = '1' AND i_wr_data(0) = '1' THEN
464)                     IF r_tx_en = '0' THEN
465)                         s_txframe_en <= '1';
466)                     END IF;
467)                     n_tx_en <= '1';
468)                 END IF;
469)             WHEN "1100" =>
470)                 IF i_wr_en(0) = '1' THEN
471)                     n_mac(7 DOWNTO 0) <= i_wr_data(7 DOWNTO 0);
472)                 END IF;
473)                 IF i_wr_en(1) = '1' THEN
474)                     n_mac(15 DOWNTO 8) <= i_wr_data(15 DOWNTO 8);
475)                 END IF;
476)                 IF i_wr_en(2) = '1' THEN
477)                     n_mac(23 DOWNTO 16) <= i_wr_data(23 DOWNTO 16);
478)                 END IF;
479)                 IF i_wr_en(3) = '1' THEN
480)                     n_mac(31 DOWNTO 24) <= i_wr_data(31 DOWNTO 24);
481)                 END IF;
482)             WHEN "1101" =>
483)                 IF i_wr_en(0) = '1' THEN
484)                     n_mac(39 DOWNTO 32) <= i_wr_data(7 DOWNTO 0);
485)                 END IF;
486)                 IF i_wr_en(1) = '1' THEN
487)                     n_mac(47 DOWNTO 40) <= i_wr_data(15 DOWNTO 8);
488)                 END IF;
489)             WHEN OTHERS => NULL;
490)         END CASE;
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

491)     END PROCESS p_write;
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

492) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

493)     -- register interface read
494)     p_read: PROCESS(rst, clk)
Stefan Schuermans implemented multi-master fe...

Stefan Schuermans authored 12 years ago

495)     BEGIN
496)         IF rst = '1' THEN
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

497)             o_rd_data <= (OTHERS => '0');
Stefan Schuermans implemented multi-master fe...

Stefan Schuermans authored 12 years ago

498)         ELSIF rising_edge(clk) THEN
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

499)             o_rd_data <= (OTHERS => '0');
500)             CASE i_addr IS
Stefan Schuermans made MAC configurable in et...

Stefan Schuermans authored 12 years ago

501)                 WHEN "0000" => o_rd_data              <= r_rx_start;
502)                 WHEN "0001" => o_rd_data              <= r_rx_cur;
503)                 WHEN "0010" => o_rd_data              <= r_rx_size;
504)                 WHEN "0011" => o_rd_data              <= r_rx_end;
505)                 WHEN "0100" => o_rd_data              <= r_rx_new_start;
506)                 WHEN "0101" => o_rd_data              <= r_rx_new_end;
507)                 WHEN "0110" => o_rd_data(0)           <= r_rx_new_en;
508)                 WHEN "1000" => o_rd_data              <= r_tx_start;
509)                 WHEN "1001" => o_rd_data              <= r_tx_end;
510)                 WHEN "1010" => o_rd_data(0)           <= r_tx_en;
511)                 WHEN "1100" => o_rd_data              <= r_mac(31 DOWNTO 0);
512)                 WHEN "1101" => o_rd_data(15 DOWNTO 0) <= r_mac(47 DOWNTO 32);
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

513)                 WHEN OTHERS => NULL;
514)             END CASE;
Stefan Schuermans implemented multi-master fe...

Stefan Schuermans authored 12 years ago

515)         END IF;
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

516)     END PROCESS p_read;
517) 
518)     -- bus master write buffer
519)     --   as the core has lower bus priority than ethernet,
520)     --   the core will never access memory or ethernet registers
521)     --   when data is in this buffer
522)     wrbuf: e_block_fifo
523)         GENERIC MAP (
524)             addr_width => 2,
525)             data_width => 64
526)         )
527)         PORT MAP (
528)             rst       => rst,
529)             clk       => clk,
530)             o_wr_rdy  => s_wrbuf_wr_rdy,
531)             i_wr_data => s_wrbuf_wr_data,
532)             i_wr_en   => s_wrbuf_wr_en,
533)             o_rd_rdy  => s_wrbuf_rd_rdy,
534)             o_rd_data => s_wrbuf_rd_data,
535)             i_rd_en   => s_wrbuf_rd_en
536)         );
537) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

538)     -- TX busmaster read state machine
Stefan Schuermans handle eth TX packets of od...

Stefan Schuermans authored 12 years ago

539)     p_tx_rd_next: PROCESS(r_tx_pos, r_tx_rem, r_tx_start, r_tx_end,
540)                           s_txframe_en, s_txbuf_wr_en)
Stefan Schuermans improve ethernet busmaster...

Stefan Schuermans authored 12 years ago

541)        VARIABLE v_rem: signed(31 DOWNTO 0);
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

542)     BEGIN
543)         n_tx_pos <= r_tx_pos;
Stefan Schuermans handle eth TX packets of od...

Stefan Schuermans authored 12 years ago

544)         n_tx_rem <= r_tx_rem;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

545)         IF s_txframe_en = '1' THEN
546)             n_tx_pos <= r_tx_start;
Stefan Schuermans handle eth TX packets of od...

Stefan Schuermans authored 12 years ago

547)             n_tx_rem <= signed(r_tx_end) - signed(r_tx_start);
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

548)         ELSIF s_txbuf_wr_en = '1' THEN
549)             n_tx_pos <= std_logic_vector(unsigned(r_tx_pos) + X"00000004");
Stefan Schuermans improve ethernet busmaster...

Stefan Schuermans authored 12 years ago

550)             v_rem := r_tx_rem - X"00000004";
551)             IF v_rem < X"00000000" THEN
552)                 v_rem := X"00000000";
553)             END IF;
554)             n_tx_rem <= v_rem;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

555)         END IF;
556)     END PROCESS p_tx_rd_next;
557) 
558)     p_tx_rd_sync: PROCESS(clk, rst)
559)     BEGIN
560)         IF rst = '1' THEN
561)             r_tx_pos <= X"00000000";
Stefan Schuermans handle eth TX packets of od...

Stefan Schuermans authored 12 years ago

562)             r_tx_rem <= X"00000000";
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

563)         ELSIF rising_edge(clk) THEN
564)             r_tx_pos <= n_tx_pos;
Stefan Schuermans handle eth TX packets of od...

Stefan Schuermans authored 12 years ago

565)             r_tx_rem <= n_tx_rem;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

566)         END IF;
567)     END PROCESS p_tx_rd_sync;
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

568) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

569)     -- busmaster read completed    
Stefan Schuermans handle eth TX packets of od...

Stefan Schuermans authored 12 years ago

570)     p_bm_rd: PROCESS(r_bm_rd, r_tx_rem, i_bm_rd_data)
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

571)     BEGIN
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

572)         s_txbuf_wr_data <= X"00000000";
573)         s_txbuf_wr_en   <= '0';
574)         -- read was just completed
575)         IF r_bm_rd = '1' THEN
Stefan Schuermans handle eth TX packets of od...

Stefan Schuermans authored 12 years ago

576)             CASE r_tx_rem IS
577)                 WHEN X"00000000" => NULL;
578)                 WHEN X"00000001" => s_txbuf_wr_data( 7 DOWNTO 0)
579)                                     <= i_bm_rd_data( 7 DOWNTO 0);
580)                 WHEN X"00000002" => s_txbuf_wr_data(15 DOWNTO 0)
581)                                     <= i_bm_rd_data(15 DOWNTO 0);
582)                 WHEN X"00000003" => s_txbuf_wr_data(23 DOWNTO 0)
583)                                     <= i_bm_rd_data(23 DOWNTO 0);
584)                 WHEN OTHERS      => s_txbuf_wr_data
585)                                     <= i_bm_rd_data;
586)             END CASE;
587)             s_txbuf_wr_en <= '1';
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

588)         END IF;
589)     END PROCESS p_bm_rd;
590) 
591)     -- bus master write (and request side of read)
592)     p_bm_wr: PROCESS(r_bm_rd,
Stefan Schuermans handle eth TX packets of od...

Stefan Schuermans authored 12 years ago

593)                      r_tx_en, r_tx_pos, r_tx_rem, s_txbuf_wr_rdy,
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

594)                      s_wrbuf_rd_rdy, s_wrbuf_rd_data, i_bm_grant)
595)         VARIABLE v_read:  boolean;
596)         VARIABLE v_write: boolean;
597)     BEGIN
598)         n_bm_rd       <= '0';
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

599)         s_wrbuf_rd_en <= '0';
600)         o_bm_req      <= '0';
601)         o_bm_addr     <= (OTHERS => '0');
602)         o_bm_rd_en    <= (OTHERS => '0');
603)         o_bm_wr_data  <= (OTHERS => '0');
604)         o_bm_wr_en    <= (OTHERS => '0');
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

605)         -- check for requests
606)         --   read: no read just completed, TX running, not reached end,
607)         --         space in buffer
608)         --   write: write request in write buffer
609)         v_read  := r_bm_rd = '0' AND r_tx_en = '1' AND
Stefan Schuermans improve ethernet busmaster...

Stefan Schuermans authored 12 years ago

610)                    r_tx_rem /= X"00000000" AND s_txbuf_wr_rdy = '1';
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

611)         v_write := s_wrbuf_rd_rdy = '1';
612)         -- read access
613)         IF v_read THEN
614)             n_bm_rd    <= i_bm_grant;
615)             o_bm_req   <= '1';
616)             o_bm_addr  <= r_tx_pos;
617)             o_bm_rd_en <= "1111";
618)         -- write access (arbitrate with read)
619)         ELSIF v_write THEN
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

620)             s_wrbuf_rd_en <= i_bm_grant;
621)             o_bm_req      <= '1';
622)             o_bm_addr     <= s_wrbuf_rd_data(63 DOWNTO 32);
623)             o_bm_wr_data  <= s_wrbuf_rd_data(31 DOWNTO  0);
624)             o_bm_wr_en    <= "1111";
625)         END IF;        
626)     END PROCESS p_bm_wr;
Stefan Schuermans implemented multi-master fe...

Stefan Schuermans authored 12 years ago

627) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

628)     p_bm_sync: PROCESS(clk, rst)
629)     BEGIN
630)         IF rst = '1' THEN
631)             r_bm_rd <= '0';
632)         ELSIF rising_edge(clk) THEN
633)             r_bm_rd <= n_bm_rd;
634)         END IF;
635)     END PROCESS p_bm_sync;
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

636)