2ef1d95cf5b52936b651e95a370f0485bb60d998
Stefan Schuermans begin of ethernet RX implem...

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

14)         o_bm_req:     OUT std_logic;
15)         i_bm_grant:   IN  std_logic;
16)         o_bm_addr:    OUT std_logic_vector(31 DOWNTO 0);
17)         i_bm_rd_data: IN  std_logic_vector(31 DOWNTO 0);
18)         o_bm_rd_en:   OUT std_logic_vector( 3 DOWNTO 0);
19)         o_bm_wr_data: OUT std_logic_vector(31 DOWNTO 0);
20)         o_bm_wr_en:   OUT std_logic_vector( 3 DOWNTO 0);
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

44) 
Stefan Schuermans implemented ethernet TX int...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

91)     -- TX buffer registers
92)     --   start: begin of buffer
93)     --   end: address just behind buffer
94)     --   en: write 1 to start transmission, returns to zero if complete
95)     --   all addresses are word-aligned
96)     SIGNAL r_tx_start: std_logic_vector(31 DOWNTO 0) := X"00000000";
97)     SIGNAL n_tx_start: std_logic_vector(31 DOWNTO 0);
98)     SIGNAL r_tx_end:   std_logic_vector(31 DOWNTO 0) := X"00000000";
99)     SIGNAL n_tx_end:   std_logic_vector(31 DOWNTO 0);
100)     SIGNAL r_tx_en:    std_logic                     := '0';
101)     SIGNAL n_tx_en:    std_logic;
102) 
Stefan Schuermans made MAC configurable in et...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

107)     -- TX busmaster read state machine
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) 
111)     -- busmaster write buffer
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

118) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

221)             o_data       => s_rxif_data,
222)             o_data_en    => s_rxif_data_en,
223)             o_done       => s_rxif_done,
224)             o_err        => s_rxif_err,
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

225)             pin_i_rx_clk => pin_i_rx_clk,
226)             pin_i_rxd    => pin_i_rxd,
227)             pin_i_rx_dv  => pin_i_rx_dv,
228)             pin_i_crs    => pin_i_crs,
229)             pin_i_col    => pin_i_col
230)         );
231) 
Stefan Schuermans implemented ethernet RX fra...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

297)         END IF;
298) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

323) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

342) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

386)     BEGIN
387)         IF rst = '1' THEN
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

413) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

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

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

484) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

487)     BEGIN
488)         IF rst = '1' THEN
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

530)     -- TX busmaster read state machine
531)     p_tx_rd_next: PROCESS(r_tx_pos, r_tx_start, s_txframe_en, s_txbuf_wr_en)
532)     BEGIN
533)         n_tx_pos <= r_tx_pos;
534)         IF s_txframe_en = '1' THEN
535)             n_tx_pos <= r_tx_start;
536)         ELSIF s_txbuf_wr_en = '1' THEN
537)             n_tx_pos <= std_logic_vector(unsigned(r_tx_pos) + X"00000004");
538)         END IF;
539)     END PROCESS p_tx_rd_next;
540) 
541)     p_tx_rd_sync: PROCESS(clk, rst)
542)     BEGIN
543)         IF rst = '1' THEN
544)             r_tx_pos <= X"00000000";
545)         ELSIF rising_edge(clk) THEN
546)             r_tx_pos <= n_tx_pos;
547)         END IF;
548)     END PROCESS p_tx_rd_sync;
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

549) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

550)     -- busmaster read completed    
551)     p_bm_rd: PROCESS(r_bm_rd, i_bm_rd_data)
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

553)         s_txbuf_wr_data <= X"00000000";
554)         s_txbuf_wr_en   <= '0';
555)         -- read was just completed
556)         IF r_bm_rd = '1' THEN
557)             s_txbuf_wr_data <= i_bm_rd_data;
558)             s_txbuf_wr_en   <= '1';
559)         END IF;
560)     END PROCESS p_bm_rd;
561) 
562)     -- bus master write (and request side of read)
563)     p_bm_wr: PROCESS(r_bm_rd,
564)                      r_tx_en, r_tx_pos, r_tx_end, s_txbuf_wr_rdy,
565)                      s_wrbuf_rd_rdy, s_wrbuf_rd_data, i_bm_grant)
566)         VARIABLE v_read:  boolean;
567)         VARIABLE v_write: boolean;
568)     BEGIN
569)         n_bm_rd       <= '0';
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

570)         s_wrbuf_rd_en <= '0';
571)         o_bm_req      <= '0';
572)         o_bm_addr     <= (OTHERS => '0');
573)         o_bm_rd_en    <= (OTHERS => '0');
574)         o_bm_wr_data  <= (OTHERS => '0');
575)         o_bm_wr_en    <= (OTHERS => '0');
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

576)         -- check for requests
577)         --   read: no read just completed, TX running, not reached end,
578)         --         space in buffer
579)         --   write: write request in write buffer
580)         v_read  := r_bm_rd = '0' AND r_tx_en = '1' AND
581)                    r_tx_pos /= r_tx_end AND s_txbuf_wr_rdy = '1';
582)         v_write := s_wrbuf_rd_rdy = '1';
583)         -- read access
584)         IF v_read THEN
585)             n_bm_rd    <= i_bm_grant;
586)             o_bm_req   <= '1';
587)             o_bm_addr  <= r_tx_pos;
588)             o_bm_rd_en <= "1111";
589)         -- write access (arbitrate with read)
590)         ELSIF v_write THEN
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

591)             s_wrbuf_rd_en <= i_bm_grant;
592)             o_bm_req      <= '1';
593)             o_bm_addr     <= s_wrbuf_rd_data(63 DOWNTO 32);
594)             o_bm_wr_data  <= s_wrbuf_rd_data(31 DOWNTO  0);
595)             o_bm_wr_en    <= "1111";
596)         END IF;        
597)     END PROCESS p_bm_wr;
Stefan Schuermans implemented multi-master fe...

Stefan Schuermans authored 12 years ago

598) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

599)     p_bm_sync: PROCESS(clk, rst)
600)     BEGIN
601)         IF rst = '1' THEN
602)             r_bm_rd <= '0';
603)         ELSIF rising_edge(clk) THEN
604)             r_bm_rd <= n_bm_rd;
605)         END IF;
606)     END PROCESS p_bm_sync;
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

607)