14cef84dbd46fa0958be3a641af7a6049b681045
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) 
103)     -- TX busmaster read state machine
104)     SIGNAL r_tx_pos:  std_logic_vector(31 DOWNTO 0) := X"00000000";
105)     SIGNAL n_tx_pos:  std_logic_vector(31 DOWNTO 0);
106) 
107)     -- busmaster write buffer
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

108)     SIGNAL s_wrbuf_wr_rdy:  std_logic;
109)     SIGNAL s_wrbuf_wr_data: std_logic_vector(63 DOWNTO 0);
110)     SIGNAL s_wrbuf_wr_en:   std_logic;
111)     SIGNAL s_wrbuf_rd_rdy:  std_logic;
112)     SIGNAL s_wrbuf_rd_data: std_logic_vector(63 DOWNTO 0);
113)     SIGNAL s_wrbuf_rd_en:   std_logic;
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

114) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

115)     -- busmaster read flag
116)     SIGNAL r_bm_rd: std_logic := '0';
117)     SIGNAL n_bm_rd: std_logic;
118) 
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

217)             o_data       => s_rxif_data,
218)             o_data_en    => s_rxif_data_en,
219)             o_done       => s_rxif_done,
220)             o_err        => s_rxif_err,
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

221)             pin_i_rx_clk => pin_i_rx_clk,
222)             pin_i_rxd    => pin_i_rxd,
223)             pin_i_rx_dv  => pin_i_rx_dv,
224)             pin_i_crs    => pin_i_crs,
225)             pin_i_col    => pin_i_col
226)         );
227) 
Stefan Schuermans implemented ethernet RX fra...

Stefan Schuermans authored 12 years ago

228)     rxframe: e_io_eth_rxframe
229)         PORT MAP (
230)             rst       => rst,
231)             clk       => clk,
232)             i_data    => s_rxif_data,
233)             i_data_en => s_rxif_data_en,
234)             i_done    => s_rxif_done,
235)             i_err     => s_rxif_err,
236)             i_mac     => X"070605040302",
237)             o_data    => s_rxframe_data,
238)             o_data_en => s_rxframe_data_en,
239)             o_done    => s_rxframe_done,
240)             o_err     => s_rxframe_err
241)         );
242) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

293)         END IF;
294) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

319) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

338) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

382)     BEGIN
383)         IF rst = '1' THEN
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

384)             r_rx_start     <= X"00000000";
385)             r_rx_cur       <= X"00000004";
386)             r_rx_size      <= X"00000000";
387)             r_rx_end       <= X"00000000";
388)             r_rx_new_start <= X"00000000";
389)             r_rx_new_end   <= X"00000000";
390)             r_rx_new_en    <= '0';
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

391)             r_tx_start     <= X"00000000";
392)             r_tx_end       <= X"00000000";
393)             r_tx_en        <= '0';
Stefan Schuermans fix reading (1 cycle latenc...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

395)             r_rx_start     <= n_rx_start;
396)             r_rx_cur       <= n_rx_cur;
397)             r_rx_size      <= n_rx_size;
398)             r_rx_end       <= n_rx_end;
399)             r_rx_new_start <= n_rx_new_start;
400)             r_rx_new_end   <= n_rx_new_end;
401)             r_rx_new_en    <= n_rx_new_en;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

402)             r_tx_start     <= n_tx_start;
403)             r_tx_end       <= n_tx_end;
404)             r_tx_en        <= n_tx_en;
Stefan Schuermans fix reading (1 cycle latenc...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

407) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

409)     p_write: PROCESS(r_rx_new_start, r_rx_new_end, r_rx_new_en, s_rx_new,
410)                      r_tx_start, r_tx_end, r_tx_en, s_txframe_done,
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

411)                      i_addr, i_wr_data, i_wr_en)
412)     BEGIN
413)         n_rx_new_start <= r_rx_new_start;
414)         n_rx_new_end   <= r_rx_new_end;
415)         n_rx_new_en    <= r_rx_new_en;
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

416)         n_tx_start     <= r_tx_start;
417)         n_tx_end       <= r_tx_end;
418)         n_tx_en        <= r_tx_en;
419)         s_txframe_en   <= '0';
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

425)         END IF;
426)         IF i_wr_en = "1111" THEN
427)             CASE i_addr IS
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

428)                 WHEN "0100" => n_rx_new_start <= i_wr_data;
429)                 WHEN "0101" => n_rx_new_end   <= i_wr_data;
430)                 WHEN "0110" => IF i_wr_data(0) = '1' THEN
431)                                    n_rx_new_en <= '1';
432)                                END IF;
433)                 WHEN "1000" => IF r_tx_en = '0' THEN
434)                                    n_tx_start <= i_wr_data;
435)                                END IF;
436)                 WHEN "1001" => IF r_tx_en = '0' THEN
437)                                    n_tx_end <= i_wr_data;
438)                                END IF;
439)                 WHEN "1010" => IF i_wr_data(0) = '1' THEN
440)                                    IF r_tx_en = '0' THEN
441)                                        s_txframe_en <= '1';
442)                                    END IF;
443)                                    n_tx_en <= '1';
444)                                END IF;
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

445)                 WHEN OTHERS => NULL;
446)             END CASE;
447)         END IF;
448)     END PROCESS p_write;
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

449) 
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

452)     BEGIN
453)         IF rst = '1' THEN
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

456)             o_rd_data <= (OTHERS => '0');
457)             CASE i_addr IS
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

458)                 WHEN "0000" => o_rd_data    <= r_rx_start;
459)                 WHEN "0001" => o_rd_data    <= r_rx_cur;
460)                 WHEN "0010" => o_rd_data    <= r_rx_size;
461)                 WHEN "0011" => o_rd_data    <= r_rx_end;
462)                 WHEN "0100" => o_rd_data    <= r_rx_new_start;
463)                 WHEN "0101" => o_rd_data    <= r_rx_new_end;
464)                 WHEN "0110" => o_rd_data(0) <= r_rx_new_en;
465)                 WHEN "1000" => o_rd_data    <= r_tx_start;
466)                 WHEN "1001" => o_rd_data    <= r_tx_end;
467)                 WHEN "1010" => o_rd_data(0) <= r_tx_en;
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

471)     END PROCESS p_read;
472) 
473)     -- bus master write buffer
474)     --   as the core has lower bus priority than ethernet,
475)     --   the core will never access memory or ethernet registers
476)     --   when data is in this buffer
477)     wrbuf: e_block_fifo
478)         GENERIC MAP (
479)             addr_width => 2,
480)             data_width => 64
481)         )
482)         PORT MAP (
483)             rst       => rst,
484)             clk       => clk,
485)             o_wr_rdy  => s_wrbuf_wr_rdy,
486)             i_wr_data => s_wrbuf_wr_data,
487)             i_wr_en   => s_wrbuf_wr_en,
488)             o_rd_rdy  => s_wrbuf_rd_rdy,
489)             o_rd_data => s_wrbuf_rd_data,
490)             i_rd_en   => s_wrbuf_rd_en
491)         );
492) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

493)     -- TX busmaster read state machine
494)     p_tx_rd_next: PROCESS(r_tx_pos, r_tx_start, s_txframe_en, s_txbuf_wr_en)
495)     BEGIN
496)         n_tx_pos <= r_tx_pos;
497)         IF s_txframe_en = '1' THEN
498)             n_tx_pos <= r_tx_start;
499)         ELSIF s_txbuf_wr_en = '1' THEN
500)             n_tx_pos <= std_logic_vector(unsigned(r_tx_pos) + X"00000004");
501)         END IF;
502)     END PROCESS p_tx_rd_next;
503) 
504)     p_tx_rd_sync: PROCESS(clk, rst)
505)     BEGIN
506)         IF rst = '1' THEN
507)             r_tx_pos <= X"00000000";
508)         ELSIF rising_edge(clk) THEN
509)             r_tx_pos <= n_tx_pos;
510)         END IF;
511)     END PROCESS p_tx_rd_sync;
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

512) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

516)         s_txbuf_wr_data <= X"00000000";
517)         s_txbuf_wr_en   <= '0';
518)         -- read was just completed
519)         IF r_bm_rd = '1' THEN
520)             s_txbuf_wr_data <= i_bm_rd_data;
521)             s_txbuf_wr_en   <= '1';
522)         END IF;
523)     END PROCESS p_bm_rd;
524) 
525)     -- bus master write (and request side of read)
526)     p_bm_wr: PROCESS(r_bm_rd,
527)                      r_tx_en, r_tx_pos, r_tx_end, s_txbuf_wr_rdy,
528)                      s_wrbuf_rd_rdy, s_wrbuf_rd_data, i_bm_grant)
529)         VARIABLE v_read:  boolean;
530)         VARIABLE v_write: boolean;
531)     BEGIN
532)         n_bm_rd       <= '0';
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

533)         s_wrbuf_rd_en <= '0';
534)         o_bm_req      <= '0';
535)         o_bm_addr     <= (OTHERS => '0');
536)         o_bm_rd_en    <= (OTHERS => '0');
537)         o_bm_wr_data  <= (OTHERS => '0');
538)         o_bm_wr_en    <= (OTHERS => '0');
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

539)         -- check for requests
540)         --   read: no read just completed, TX running, not reached end,
541)         --         space in buffer
542)         --   write: write request in write buffer
543)         v_read  := r_bm_rd = '0' AND r_tx_en = '1' AND
544)                    r_tx_pos /= r_tx_end AND s_txbuf_wr_rdy = '1';
545)         v_write := s_wrbuf_rd_rdy = '1';
546)         -- read access
547)         IF v_read THEN
548)             n_bm_rd    <= i_bm_grant;
549)             o_bm_req   <= '1';
550)             o_bm_addr  <= r_tx_pos;
551)             o_bm_rd_en <= "1111";
552)         -- write access (arbitrate with read)
553)         ELSIF v_write THEN
Stefan Schuermans implemented ethernet RX bus...

Stefan Schuermans authored 12 years ago

554)             s_wrbuf_rd_en <= i_bm_grant;
555)             o_bm_req      <= '1';
556)             o_bm_addr     <= s_wrbuf_rd_data(63 DOWNTO 32);
557)             o_bm_wr_data  <= s_wrbuf_rd_data(31 DOWNTO  0);
558)             o_bm_wr_en    <= "1111";
559)         END IF;        
560)     END PROCESS p_bm_wr;
Stefan Schuermans implemented multi-master fe...

Stefan Schuermans authored 12 years ago

561) 
Stefan Schuermans implemented ethernet TX fra...

Stefan Schuermans authored 12 years ago

562)     p_bm_sync: PROCESS(clk, rst)
563)     BEGIN
564)         IF rst = '1' THEN
565)             r_bm_rd <= '0';
566)         ELSIF rising_edge(clk) THEN
567)             r_bm_rd <= n_bm_rd;
568)         END IF;
569)     END PROCESS p_bm_sync;
Stefan Schuermans begin of ethernet RX implem...

Stefan Schuermans authored 12 years ago

570)