160b4d93b00d57104ce5ae5f9f7773242c26c262
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
Stefan Schuermans handle eth TX packets of od...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

121) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

224)             o_data       => s_rxif_data,
225)             o_data_en    => s_rxif_data_en,
226)             o_done       => s_rxif_done,
227)             o_err        => s_rxif_err,
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

228)             pin_i_rx_clk => pin_i_rx_clk,
229)             pin_i_rxd    => pin_i_rxd,
230)             pin_i_rx_dv  => pin_i_rx_dv,
231)             pin_i_crs    => pin_i_crs,
232)             pin_i_col    => pin_i_col
233)         );
234) 
Stefan Schuermans implemented ethernet RX fra...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

326) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

345) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

416) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

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

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

487) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

563) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

622) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

631)