902aa402b3830b9c9aa26758390b6eb93b42a0f5
Stefan Schuermans added file headers

Stefan Schuermans authored 12 years ago

1) -- MIPS I system
Stefan Schuermans replace email address in he...

Stefan Schuermans authored 12 years ago

2) -- Copyright 2011-2012 Stefan Schuermans <stefan@blinkenarea.org>
Stefan Schuermans added file headers

Stefan Schuermans authored 12 years ago

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;
Stefan Schuermans records for ethernet pins

Stefan Schuermans authored 12 years ago

9) USE work.io_eth_pins.all;
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

10) 
11) ENTITY e_io_eth IS
12)     PORT (
13)         rst:          IN  std_logic;
14)         clk:          IN  std_logic;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

20)         o_bm_req:     OUT std_logic;
21)         i_bm_grant:   IN  std_logic;
22)         o_bm_addr:    OUT std_logic_vector(31 DOWNTO 0);
23)         i_bm_rd_data: IN  std_logic_vector(31 DOWNTO 0);
24)         o_bm_rd_en:   OUT std_logic_vector( 3 DOWNTO 0);
25)         o_bm_wr_data: OUT std_logic_vector(31 DOWNTO 0);
26)         o_bm_wr_en:   OUT std_logic_vector( 3 DOWNTO 0);
Stefan Schuermans records for ethernet pins

Stefan Schuermans authored 12 years ago

27)         pin_o:        OUT t_io_eth_o_pins;
28)         pin_i:        IN  t_io_eth_i_pins
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

29)     );
30) END ENTITY e_io_eth;
31) 
32) ARCHITECTURE a_io_eth OF e_io_eth IS
33) 
Stefan Schuermans implemented ethernet RX fra...

Stefan Schuermans authored 12 years ago

34)     SIGNAL s_rxif_data:    std_logic_vector(7 DOWNTO 0);
35)     SIGNAL s_rxif_data_en: std_logic;
36)     SIGNAL s_rxif_done:    std_logic;
37)     SIGNAL s_rxif_err:     std_logic;
38) 
39)     SIGNAL s_rxframe_data:    std_logic_vector(31 DOWNTO 0);
40)     SIGNAL s_rxframe_data_en: std_logic;
41)     SIGNAL s_rxframe_done:    std_logic;
42)     SIGNAL s_rxframe_err:     std_logic;
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

43) 
Stefan Schuermans implemented ethernet TX int...

Stefan Schuermans authored 12 years ago

44)     SIGNAL s_rx_new: std_logic;
45) 
46)     SIGNAL s_txif_data:     std_logic_vector(7 DOWNTO 0);
47)     SIGNAL s_txif_data_en:  std_logic;
48)     SIGNAL s_txif_data_ack: std_logic;
49) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

50)     SIGNAL s_txframe_en:   std_logic;
51)     SIGNAL s_txframe_done: std_logic;
52) 
53)     SIGNAL s_txbuf_wr_rdy:  std_logic;
54)     SIGNAL s_txbuf_wr_data: std_logic_vector(31 DOWNTO 0);
55)     SIGNAL s_txbuf_wr_en:   std_logic;
56)     SIGNAL s_txbuf_rd_rdy:  std_logic;
57)     SIGNAL s_txbuf_rd_data: std_logic_vector(31 DOWNTO 0);
58)     SIGNAL s_txbuf_rd_en:   std_logic;
59) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

60)     -- RX buffer registers
61)     --   start: current buffer begin
62)     --   cur: address of next data write
63)     --   size: size of data received
64)     --   end: address just behind buffer
65)     --   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

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

Stefan Schuermans authored 12 years ago

68)     --   all addresses/sizes are word-aligned
69)     SIGNAL r_rx_start: std_logic_vector(31 DOWNTO 0) := X"00000000";
70)     SIGNAL n_rx_start: std_logic_vector(31 DOWNTO 0);
71)     SIGNAL r_rx_cur:   std_logic_vector(31 DOWNTO 0) := X"00000004";
72)     SIGNAL n_rx_cur:   std_logic_vector(31 DOWNTO 0);
73)     SIGNAL r_rx_size:  std_logic_vector(31 DOWNTO 0) := X"00000000";
74)     SIGNAL n_rx_size:  std_logic_vector(31 DOWNTO 0);
75)     SIGNAL r_rx_end:   std_logic_vector(31 DOWNTO 0) := X"00000000";
76)     SIGNAL n_rx_end:   std_logic_vector(31 DOWNTO 0);
77) 
78)     -- RX new buffer registers
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

82)     --   all addresses are word-aligned
83)     SIGNAL r_rx_new_start: std_logic_vector(31 DOWNTO 0) := X"00000000";
84)     SIGNAL n_rx_new_start: std_logic_vector(31 DOWNTO 0);
85)     SIGNAL r_rx_new_end:   std_logic_vector(31 DOWNTO 0) := X"00000000";
86)     SIGNAL n_rx_new_end:   std_logic_vector(31 DOWNTO 0);
87)     SIGNAL r_rx_new_en:    std_logic                     := '0';
88)     SIGNAL n_rx_new_en:    std_logic;
89) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

93)     --   en: write 1 to start transmission, returns to zero if complete
94)     SIGNAL r_tx_start: std_logic_vector(31 DOWNTO 0) := X"00000000";
95)     SIGNAL n_tx_start: std_logic_vector(31 DOWNTO 0);
96)     SIGNAL r_tx_end:   std_logic_vector(31 DOWNTO 0) := X"00000000";
97)     SIGNAL n_tx_end:   std_logic_vector(31 DOWNTO 0);
98)     SIGNAL r_tx_en:    std_logic                     := '0';
99)     SIGNAL n_tx_en:    std_logic;
100) 
Stefan Schuermans made MAC configurable in et...

Stefan Schuermans authored 12 years ago

101)     -- MAC address register
102)     SIGNAL r_mac: std_logic_vector(47 DOWNTO 0) := X"FFFFFFFFFFFF";
103)     SIGNAL n_mac: std_logic_vector(47 DOWNTO 0);
104) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

106)     --   pos: next address to read (NOT word-aligned)
107)     --   rem: number of bytes remaining (NOT multiple of words size)
108)     SIGNAL r_tx_pos: std_logic_vector(31 DOWNTO 0) := X"00000000";
109)     SIGNAL n_tx_pos: std_logic_vector(31 DOWNTO 0);
110)     SIGNAL r_tx_rem: signed          (31 DOWNTO 0) := X"00000000";
111)     SIGNAL n_tx_rem: signed          (31 DOWNTO 0);
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

112) 
113)     -- busmaster write buffer
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

114)     SIGNAL s_wrbuf_wr_rdy:  std_logic;
115)     SIGNAL s_wrbuf_wr_data: std_logic_vector(63 DOWNTO 0);
116)     SIGNAL s_wrbuf_wr_en:   std_logic;
117)     SIGNAL s_wrbuf_rd_rdy:  std_logic;
118)     SIGNAL s_wrbuf_rd_data: std_logic_vector(63 DOWNTO 0);
119)     SIGNAL s_wrbuf_rd_en:   std_logic;
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

120) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

121)     -- busmaster read flag
122)     SIGNAL r_bm_rd: std_logic := '0';
123)     SIGNAL n_bm_rd: std_logic;
124) 
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

149)     COMPONENT e_io_eth_rxframe IS
150)         PORT (
151)             rst:       IN  std_logic;
152)             clk:       IN  std_logic;
153)             i_data:    IN  std_logic_vector( 7 DOWNTO 0);
154)             i_data_en: IN  std_logic;
155)             i_done:    IN  std_logic;
156)             i_err:     IN  std_logic;
157)             i_mac:     IN  std_logic_vector(47 DOWNTO 0);
158)             o_data:    OUT std_logic_vector(31 DOWNTO 0);
159)             o_data_en: OUT std_logic;
160)             o_done:    OUT std_logic;
161)             o_err:     OUT std_logic
162)         );
163)     END COMPONENT e_io_eth_rxframe;
164) 
Stefan Schuermans implemented ethernet TX int...

Stefan Schuermans authored 12 years ago

165)     COMPONENT e_io_eth_txif IS
166)         PORT (
167)             rst:          IN  std_logic;
168)             clk:          IN  std_logic;
169)             i_data:       IN  std_logic_vector(7 DOWNTO 0);
170)             i_data_en:    IN  std_logic;
171)             o_data_ack:   OUT std_logic;
172)             pin_i_tx_clk: IN  std_logic;
173)             pin_o_txd:    OUT std_logic_vector(3 DOWNTO 0);
174)             pin_o_tx_en:  OUT std_logic
175)         );
176)     END COMPONENT e_io_eth_txif;
177) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

178)     COMPONENT e_io_eth_txframe IS
179)         PORT (
180)             rst:              IN  std_logic;
181)             clk:              IN  std_logic;
182)             o_if_data:        OUT std_logic_vector(7 DOWNTO 0);
183)             o_if_data_en:     OUT std_logic;
184)             i_if_data_ack:    IN  std_logic;
185)             i_frame_en:       IN  std_logic;
186)             i_frame_data:     IN  std_logic_vector(31 DOWNTO 0);
187)             i_frame_data_en:  IN  std_logic;
188)             o_frame_data_ack: OUT std_logic;
189)             o_frame_done:     OUT std_logic
190)         );
191)     END COMPONENT e_io_eth_txframe;
192) 
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

193)     COMPONENT e_block_fifo IS
194)         GENERIC (
195)             addr_width: natural;
196)             data_width: natural
197)         );
198)         PORT (
199)             rst:       IN  std_logic;
200)             clk:       IN  std_logic;
201)             o_wr_rdy:  OUT std_logic;
202)             i_wr_data: IN  std_logic_vector(data_width - 1 DOWNTO 0);
203)             i_wr_en:   IN  std_logic;
204)             o_rd_rdy:  OUT std_logic;
205)             o_rd_data: OUT std_logic_vector(data_width - 1 DOWNTO 0);
206)             i_rd_en:   IN  std_logic
207)         );
208)     END COMPONENT e_block_fifo;
209) 
210) BEGIN
211) 
212)     reset: e_io_eth_rst
213)         PORT MAP (
214)             rst        => rst,
215)             clk        => clk,
Stefan Schuermans records for ethernet pins

Stefan Schuermans authored 12 years ago

216)             pin_o_nrst => pin_o.nrst
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

217)         );
218) 
219)     rxif: e_io_eth_rxif
220)         PORT MAP (
221)             rst          => rst,
222)             clk          => clk,
Stefan Schuermans implemented ethernet RX fra...

Stefan Schuermans authored 12 years ago

223)             o_data       => s_rxif_data,
224)             o_data_en    => s_rxif_data_en,
225)             o_done       => s_rxif_done,
226)             o_err        => s_rxif_err,
Stefan Schuermans records for ethernet pins

Stefan Schuermans authored 12 years ago

227)             pin_i_rx_clk => pin_i.rx_clk,
228)             pin_i_rxd    => pin_i.rxd,
229)             pin_i_rx_dv  => pin_i.rx_dv,
230)             pin_i_crs    => pin_i.crs,
231)             pin_i_col    => pin_i.col
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

232)         );
233) 
Stefan Schuermans implemented ethernet RX fra...

Stefan Schuermans authored 12 years ago

234)     rxframe: e_io_eth_rxframe
235)         PORT MAP (
236)             rst       => rst,
237)             clk       => clk,
238)             i_data    => s_rxif_data,
239)             i_data_en => s_rxif_data_en,
240)             i_done    => s_rxif_done,
241)             i_err     => s_rxif_err,
Stefan Schuermans made MAC configurable in et...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

243)             o_data    => s_rxframe_data,
244)             o_data_en => s_rxframe_data_en,
245)             o_done    => s_rxframe_done,
246)             o_err     => s_rxframe_err
247)         );
248) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

249)     p_rx_next: PROCESS(r_rx_start, r_rx_cur, r_rx_size, r_rx_end,
250)                        r_rx_new_start, r_rx_new_end, r_rx_new_en,
251)                        s_rxframe_data, s_rxframe_data_en,
252)                        s_rxframe_done, s_rxframe_err,
253)                        s_wrbuf_wr_rdy)
254)         VARIABLE v_abort:  boolean; -- abort current packet reception
255)         VARIABLE v_ignore: boolean; -- ignore rest of packet
256)         VARIABLE v_store:  boolean; -- store packet data
257)         VARIABLE v_finish: boolean; -- finish reception of packet
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

299)         END IF;
300) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

325) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

344) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

345)     txif: e_io_eth_txif
346)         PORT MAP (
347)             rst          => rst,
348)             clk          => clk,
349)             i_data       => s_txif_data,
350)             i_data_en    => s_txif_data_en,
351)             o_data_ack   => s_txif_data_ack,
Stefan Schuermans records for ethernet pins

Stefan Schuermans authored 12 years ago

352)             pin_i_tx_clk => pin_i.tx_clk,
353)             pin_o_txd    => pin_o.txd,
354)             pin_o_tx_en  => pin_o.tx_en
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

388)     BEGIN
389)         IF rst = '1' THEN
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

390)             r_rx_start     <= X"00000000";
391)             r_rx_cur       <= X"00000004";
392)             r_rx_size      <= X"00000000";
393)             r_rx_end       <= X"00000000";
394)             r_rx_new_start <= X"00000000";
395)             r_rx_new_end   <= X"00000000";
396)             r_rx_new_en    <= '0';
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

397)             r_tx_start     <= X"00000000";
398)             r_tx_end       <= X"00000000";
399)             r_tx_en        <= '0';
Stefan Schuermans made MAC configurable in et...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

402)             r_rx_start     <= n_rx_start;
403)             r_rx_cur       <= n_rx_cur;
404)             r_rx_size      <= n_rx_size;
405)             r_rx_end       <= n_rx_end;
406)             r_rx_new_start <= n_rx_new_start;
407)             r_rx_new_end   <= n_rx_new_end;
408)             r_rx_new_en    <= n_rx_new_en;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

409)             r_tx_start     <= n_tx_start;
410)             r_tx_end       <= n_tx_end;
411)             r_tx_en        <= n_tx_en;
Stefan Schuermans made MAC configurable in et...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

415) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

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

419)                      i_addr, i_wr_data, i_wr_en)
420)     BEGIN
421)         n_rx_new_start <= r_rx_new_start;
422)         n_rx_new_end   <= r_rx_new_end;
423)         n_rx_new_en    <= r_rx_new_en;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

424)         n_tx_start     <= r_tx_start;
425)         n_tx_end       <= r_tx_end;
426)         n_tx_en        <= r_tx_en;
Stefan Schuermans made MAC configurable in et...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

486) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

489)     BEGIN
490)         IF rst = '1' THEN
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

495)                 WHEN "0000" => o_rd_data              <= r_rx_start;
496)                 WHEN "0001" => o_rd_data              <= r_rx_cur;
497)                 WHEN "0010" => o_rd_data              <= r_rx_size;
498)                 WHEN "0011" => o_rd_data              <= r_rx_end;
499)                 WHEN "0100" => o_rd_data              <= r_rx_new_start;
500)                 WHEN "0101" => o_rd_data              <= r_rx_new_end;
501)                 WHEN "0110" => o_rd_data(0)           <= r_rx_new_en;
502)                 WHEN "1000" => o_rd_data              <= r_tx_start;
503)                 WHEN "1001" => o_rd_data              <= r_tx_end;
504)                 WHEN "1010" => o_rd_data(0)           <= r_tx_en;
505)                 WHEN "1100" => o_rd_data              <= r_mac(31 DOWNTO 0);
506)                 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

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

544)             v_rem := r_tx_rem - X"00000004";
545)             IF v_rem < X"00000000" THEN
546)                 v_rem := X"00000000";
547)             END IF;
548)             n_tx_rem <= v_rem;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

549)         END IF;
550)     END PROCESS p_tx_rd_next;
551) 
552)     p_tx_rd_sync: PROCESS(clk, rst)
553)     BEGIN
554)         IF rst = '1' THEN
555)             r_tx_pos <= X"00000000";
Stefan Schuermans handle eth TX packets of od...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

560)         END IF;
561)     END PROCESS p_tx_rd_sync;
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

562) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

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

Stefan Schuermans authored 12 years ago

566)         s_txbuf_wr_data <= X"00000000";
567)         s_txbuf_wr_en   <= '0';
568)         -- read was just completed
569)         IF r_bm_rd = '1' THEN
Stefan Schuermans handle eth TX packets of od...

Stefan Schuermans authored 12 years ago

570)             CASE r_tx_rem IS
571)                 WHEN X"00000000" => NULL;
572)                 WHEN X"00000001" => s_txbuf_wr_data( 7 DOWNTO 0)
573)                                     <= i_bm_rd_data( 7 DOWNTO 0);
574)                 WHEN X"00000002" => s_txbuf_wr_data(15 DOWNTO 0)
575)                                     <= i_bm_rd_data(15 DOWNTO 0);
576)                 WHEN X"00000003" => s_txbuf_wr_data(23 DOWNTO 0)
577)                                     <= i_bm_rd_data(23 DOWNTO 0);
578)                 WHEN OTHERS      => s_txbuf_wr_data
579)                                     <= i_bm_rd_data;
580)             END CASE;
581)             s_txbuf_wr_en <= '1';
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

582)         END IF;
583)     END PROCESS p_bm_rd;
584) 
585)     -- bus master write (and request side of read)
586)     p_bm_wr: PROCESS(r_bm_rd,
Stefan Schuermans handle eth TX packets of od...

Stefan Schuermans authored 12 years ago

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

588)                      s_wrbuf_rd_rdy, s_wrbuf_rd_data, i_bm_grant)
589)         VARIABLE v_read:  boolean;
590)         VARIABLE v_write: boolean;
591)     BEGIN
592)         n_bm_rd       <= '0';
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

593)         s_wrbuf_rd_en <= '0';
594)         o_bm_req      <= '0';
595)         o_bm_addr     <= (OTHERS => '0');
596)         o_bm_rd_en    <= (OTHERS => '0');
597)         o_bm_wr_data  <= (OTHERS => '0');
598)         o_bm_wr_en    <= (OTHERS => '0');
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

599)         -- check for requests
600)         --   read: no read just completed, TX running, not reached end,
601)         --         space in buffer
602)         --   write: write request in write buffer
603)         v_read  := r_bm_rd = '0' AND r_tx_en = '1' AND
Stefan Schuermans improve ethernet busmaster...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

605)         v_write := s_wrbuf_rd_rdy = '1';
606)         -- read access
607)         IF v_read THEN
608)             n_bm_rd    <= i_bm_grant;
609)             o_bm_req   <= '1';
610)             o_bm_addr  <= r_tx_pos;
611)             o_bm_rd_en <= "1111";
612)         -- write access (arbitrate with read)
613)         ELSIF v_write THEN
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

614)             s_wrbuf_rd_en <= i_bm_grant;
615)             o_bm_req      <= '1';
616)             o_bm_addr     <= s_wrbuf_rd_data(63 DOWNTO 32);
617)             o_bm_wr_data  <= s_wrbuf_rd_data(31 DOWNTO  0);
618)             o_bm_wr_en    <= "1111";
619)         END IF;        
620)     END PROCESS p_bm_wr;
Stefan Schuermans implemented multi-master fe...

Stefan Schuermans authored 12 years ago

621) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

622)     p_bm_sync: PROCESS(clk, rst)
623)     BEGIN
624)         IF rst = '1' THEN
625)             r_bm_rd <= '0';
626)         ELSIF rising_edge(clk) THEN
627)             r_bm_rd <= n_bm_rd;
628)         END IF;
629)     END PROCESS p_bm_sync;
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

630)