source: firmware/FAD/FACT_FAD_lib/hdl/FAD_rs485_receiver.vhd@ 11757

Last change on this file since 11757 was 11755, checked in by neise, 13 years ago
reinit of this svn repos .... it was all too messy deleted the old folders and restarted with FACT_FAD_lib only. (well and the testbenches)
File size: 4.8 KB
Line 
1--
2-- VHDL Architecture FACT_FAD_lib.rs485_receiver.beha
3--
4-- Created:
5-- by - Benjamin Krumm.UNKNOWN (EEPC8)
6-- at - 12:16:57 11.06.2010
7--
8-- using Mentor Graphics HDL Designer(TM) 2009.2 (Build 10)
9--
10--
11-- modified for FTU design by Q. Weitzel, 13 September 2010
12-- timeout added, Q. Weitzel, 26 October 2010
13--
14-- modified for FAD design by D.Neise, 12. April 2011
15-- modified library include statements mainly.
16--
17
18LIBRARY ieee;
19USE ieee.std_logic_1164.all;
20USE ieee.std_logic_arith.all;
21
22--library fad_rs485_definitions;
23--USE fad_rs485_definitions.fad_rs485_constants.all;
24library fact_fad_lib;
25use fact_fad_lib.fad_rs485_constants.all;
26
27ENTITY FAD_rs485_receiver IS
28 generic(
29 -- defined in fad_rs485_definitions.fad_rs485_constants
30 RX_BYTES : integer := RS485_MESSAGE_LEN_BYTES; -- no. of bytes to receive
31 RX_WIDTH : integer := RS485_MESSAGE_LEN_BYTES * 8 -- no. of bits to receive
32 );
33 port(
34 rec_clk : in std_logic;
35
36 -- Interface to MAX3485:
37 rx_d : IN std_logic;
38 rx_en : OUT std_logic;
39 tx_d : OUT std_logic;
40 tx_en : OUT std_logic;
41
42
43 rec_start : in std_logic;
44 rec_timeout_occured : out std_logic := '0';
45 rec_dout : out std_logic_vector(RX_WIDTH - 1 downto 0) := (others => '0');
46 rec_valid : out std_logic := '0'
47 );
48END ENTITY FAD_rs485_receiver;
49
50ARCHITECTURE beha OF FAD_rs485_receiver IS
51
52 signal rxcnt : integer range 0 to RX_BYTES := 0;
53 signal rxsr : std_logic_vector(3 downto 0) := (others => '0');
54 signal timeout_cnt : integer range 0 to RS485_TIMEOUT + 1 := 0;
55 signal rec_den : std_logic := '0';
56 signal rec_din : std_logic_vector(7 downto 0) := (others => '0');
57 signal start_sr : std_logic_vector(1 downto 0) := (others => '0');
58 signal started : std_logic := '0'; -- 0-not running; 1-running
59
60 component FAD_rs485_interface
61 port(
62 clk : IN std_logic;
63 -- RS485
64 rx_d : IN std_logic;
65 rx_en : OUT std_logic;
66 tx_d : OUT std_logic;
67 tx_en : OUT std_logic;
68 -- FPGA
69 rx_data : OUT std_logic_vector (7 DOWNTO 0);
70 --rx_busy : OUT std_logic := '0';
71 rx_valid : OUT std_logic := '0';
72 tx_data : IN std_logic_vector (7 DOWNTO 0);
73 tx_busy : OUT std_logic := '0';
74 tx_start : IN std_logic );
75 end component;
76
77
78BEGIN
79
80 Inst_FAD_rs485_interface : FAD_rs485_interface
81 port map(
82 clk => rec_clk,
83 -- RS485
84 rx_d => rx_d,
85 rx_en => rx_en,
86 tx_d => tx_d,
87 tx_en => tx_en,
88 -- FPGA
89 rx_data => rec_din,
90
91 rx_valid => rec_den,
92 tx_data => "00000000",
93 tx_busy => open,
94 tx_start => '0'
95 );
96
97-- process(rec_clk)
98 -- begin
99 -- if rising_edge(rec_clk) then
100 -- start_sr <= start_sr(0) & rec_start;
101 -- rxsr <= rxsr(2 downto 0) & rec_den;
102
103
104 -- if (start_sr = "01") then
105 -- started <= '1';
106 -- end if;
107
108 -- if ((rxcnt > 0) or (started = '1')) then
109 -- timeout_cnt <= timeout_cnt + 1;
110 -- else
111 -- timeout_cnt <= 0;
112 -- end if;
113
114 -- if (timeout_cnt = RS485_TIMEOUT) then
115 -- rxcnt <= 0;
116 -- started <= '0';
117 -- rec_timeout_occured <= '1';
118 -- rec_valid <= '1';
119 -- else
120 -- if (rxsr(3 downto 2) = "01") then -- identify rising edge
121 -- if (rxcnt = 0) then
122 -- rec_dout <= (others => '0');
123 -- end if;
124 -- rec_dout((rxcnt*rec_din'length + rec_din'length - 1) downto (rxcnt*rec_din'length)) <= rec_din;
125 -- rxcnt <= rxcnt + 1;
126 -- if (rxcnt < RX_BYTES - 1) then
127 -- rec_valid <= '0';
128 -- rec_timeout_occured <= '0';
129 -- else
130 -- rxcnt <= 0;
131 -- rec_valid <= '1';
132 -- end if;
133 -- end if;
134 -- end if;
135
136 -- end if; --if rising_edge(rec_clk)
137 -- end process ;
138
139
140
141
142 process (rec_clk)
143 begin
144 if rising_edge(rec_clk) then
145 start_sr <= start_sr(0) & rec_start;
146 rxsr <= rxsr(2 downto 0) & rec_den;
147
148
149 if ((timeout_cnt = RS485_TIMEOUT) or (rxcnt = RX_BYTES)) then
150 rxcnt <= 0;
151 started <= '0';
152 rec_valid <= '1';
153 timeout_cnt <= 0;
154 rec_timeout_occured <= '0';
155 if (timeout_cnt = RS485_TIMEOUT) then
156 rec_timeout_occured <= '1';
157 end if;
158 else
159 -- since neither the timeout counter is overrun,
160 -- it should be increased if 'started'
161 if (started = '1') then
162 timeout_cnt <= timeout_cnt + 1;
163 end if;
164
165 -- nor the message, was completely received.
166 -- maybe we have to receive a bit now -->
167 if (rxsr(3 downto 2) = "01") then -- identify rising edge of rec_den
168 started <= '1';
169 rec_dout((rxcnt*rec_din'length + rec_din'length - 1) downto (rxcnt*rec_din'length)) <= rec_din;
170 rxcnt <= rxcnt + 1;
171 if (rxcnt < RX_BYTES - 1) then
172 rec_valid <= '0';
173 rec_timeout_occured <= '0';
174 end if;
175 end if;
176
177 end if;
178
179 if (start_sr = "01") then
180 started <= '1';
181 rec_valid <= '0';
182 rec_dout <= (others => '0');
183 end if;
184
185
186 end if; --rising edge
187 end process;
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207END ARCHITECTURE beha;
Note: See TracBrowser for help on using the repository browser.