Debian Codegraph @

hdl/fpga/ip/nuand/synthesis/rx_packet_generator.vhd

raw
1 -- Copyright (c) 2020 Nuand LLC
2 --
3 -- Permission is hereby granted, free of charge, to any person obtaining a copy
4 -- of this software and associated documentation files (the "Software"), to deal
5 -- in the Software without restriction, including without limitation the rights
6 -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 -- copies of the Software, and to permit persons to whom the Software is
8 -- furnished to do so, subject to the following conditions:
9 --
10 -- The above copyright notice and this permission notice shall be included in
11 -- all copies or substantial portions of the Software.
12 --
13 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 -- THE SOFTWARE.
20
21 library ieee;
22 use ieee.std_logic_1164.all;
23 use ieee.numeric_std.all;
24 use ieee.math_real.all;
25 use ieee.math_complex.all;
26
27 library work;
28 use work.fifo_readwrite_p.all;
29
30
31 entity rx_packet_generator is
32 generic (
33 PACKET_LEN : integer := 500;
34 MAX_LEN : integer := 1000;
35 INCR : integer := 50;
36 GAP : integer := 10
37 );
38
39 port (
40 rx_reset : in std_logic;
41 rx_clock : in std_logic;
42 rx_enable : in std_logic;
43 rx_packet_enable : in std_logic;
44
45 rx_packet_ready : in std_logic;
46
47 rx_packet_control : out packet_control_t
48 );
49 end entity;
50
51 architecture arch of rx_packet_generator is
52 type state_t is (
53 IDLE,
54 HOLDOFF,
55 WAITED,
56 WRITE
57 );
58
59 type fsm_t is record
60 state : state_t;
61 hold_count : integer range -1 to GAP + 2;
62 write_count : integer range -1 to PACKET_LEN;
63 pkt_id : integer range 0 to 65536;
64 pkt : packet_control_t;
65 end record;
66
67 constant FSM_RESET_VALUE : fsm_t := (
68 state => IDLE,
69 hold_count => 0,
70 write_count => 0,
71 pkt_id => 0,
72 pkt => PACKET_CONTROL_DEFAULT
73 );
74
75 signal current : fsm_t := FSM_RESET_VALUE;
76 signal future : fsm_t := FSM_RESET_VALUE;
77
78 begin
79
80 fsm_proc : process (rx_clock, rx_reset)
81 begin
82 if( rx_reset = '1' ) then
83 current <= FSM_RESET_VALUE;
84 elsif( rising_edge( rx_clock ) ) then
85 current <= future;
86 end if;
87 end process;
88
89 rx_packet_control <= current.pkt;
90
91 fsm_comb : process(all)
92 begin
93
94 future <= current;
95 future.pkt <= PACKET_CONTROL_DEFAULT;
96
97 case current.state is
98 when IDLE =>
99
100 future.hold_count <= 0;
101 future.write_count <= 0;
102 if( rx_enable = '1' and rx_packet_enable = '1' ) then
103 future.state <= HOLDOFF;
104 end if;
105
106 when HOLDOFF =>
107 future.write_count <= PACKET_LEN;
108 future.hold_count <= current.hold_count + 1;
109 if(current.hold_count = GAP) then
110 future.state <= WAITED;
111 end if;
112
113 when WAITED =>
114 if( rx_packet_ready = '1' ) then
115 future.state <= WRITE;
116 end if;
117
118 when WRITE =>
119
120 future.pkt.data_valid <= '1';
121 future.pkt.data <= std_logic_vector(to_unsigned(current.pkt_id, 16)) & std_logic_vector(to_unsigned(current.write_count, 16));
122
123 if(current.write_count = PACKET_LEN) then
124 future.pkt.pkt_sop <= '1';
125 future.pkt.data_valid <= '1';
126 elsif(current.write_count = 1) then
127 future.pkt.pkt_eop <= '1';
128 future.state <= IDLE;
129 if( current.pkt_id > 65000) then
130 future.pkt_id <= 0;
131 else
132 future.pkt_id <= current.pkt_id + 1;
133 end if;
134 end if;
135
136 future.write_count <= current.write_count - 1;
137
138 when others =>
139
140 future <= FSM_RESET_VALUE;
141 end case;
142
143 end process;
144 end architecture;