source: firmware/FAD/FACT_FAD_lib/hdl/FAD_rs485_interface.vhd@ 19183

Last change on this file since 19183 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: 3.8 KB
Line 
1--
2-- VHDL Architecture FACT_FAD_lib.rs485_interface.beha
3--
4-- Created:
5-- by - Benjamin Krumm.UNKNOWN (EEPC8)
6-- at - 13:24:23 08.06.2010
7--
8-- using Mentor Graphics HDL Designer(TM) 2009.1 (Build 12)
9--
10--
11-- modified for FTU design by Q. Weitzel, 30 July 2010
12--
13
14LIBRARY ieee;
15USE ieee.std_logic_1164.all;
16USE ieee.std_logic_arith.all;
17
18--library fad_rs485_definitions;
19--USE fad_rs485_definitions.fad_rs485_constants.all;
20library fact_fad_lib;
21use fact_fad_lib.fad_rs485_constants.all;
22
23
24ENTITY FAD_rs485_interface IS
25 GENERIC(
26 CLOCK_FREQUENCY : integer := FAD_RS485_INPUT_CLK_F;
27 BAUD_RATE : integer := RS485_BAUD_RATE
28 );
29 PORT(
30 clk : IN std_logic;
31 -- RS485
32 rx_d : IN std_logic;
33 rx_en : OUT std_logic;
34 tx_d : OUT std_logic;
35 tx_en : OUT std_logic;
36 -- FPGA
37 rx_data : OUT std_logic_vector (7 DOWNTO 0);
38 --rx_busy : OUT std_logic := '0';
39 rx_valid : OUT std_logic := '0';
40 tx_data : IN std_logic_vector (7 DOWNTO 0);
41 tx_busy : OUT std_logic := '0';
42 tx_start : IN std_logic
43 );
44
45END FAD_rs485_interface;
46
47ARCHITECTURE beha OF FAD_rs485_interface IS
48
49 signal flow_ctrl : std_logic := '0'; -- '0' -> RX enable, '1' -> TX enable
50
51 --transmit
52 signal tx_start_f : std_logic := '0';
53 signal tx_sr : std_logic_vector(10 downto 0) := (others => '1'); -- start bit, 8 data bits, 2 stop bits
54 signal tx_bitcnt : integer range 0 to 11 := 11;
55 signal tx_cnt : integer range 0 to ((CLOCK_FREQUENCY / BAUD_RATE) - 1);
56
57 --receive
58 signal rx_dsr : std_logic_vector(3 downto 0) := (others => '1');
59 signal rx_sr : std_logic_vector(7 downto 0) := (others => '0');
60 signal rx_bitcnt : integer range 0 to 11 := 11;
61 signal rx_cnt : integer range 0 to ((CLOCK_FREQUENCY / BAUD_RATE) - 1);
62
63BEGIN
64
65 -- Senden
66 tx_data_proc: process(clk)
67 begin
68 if rising_edge(clk) then
69 tx_start_f <= tx_start;
70 if (tx_start = '1' or tx_bitcnt < 11) then
71 flow_ctrl <= '1';
72 else
73 flow_ctrl <= '0';
74 end if;
75 if (tx_start = '1' and tx_start_f = '0') then -- steigende Flanke, los gehts
76 tx_cnt <= 0; -- Zaehler initialisieren
77 tx_bitcnt <= 0;
78 tx_sr <= "11" & tx_data & '0'; -- 2 x Stopbit, 8 Datenbits, Startbit, rechts gehts los
79 else
80 if (tx_cnt < (CLOCK_FREQUENCY/BAUD_RATE) - 1) then
81 tx_cnt <= tx_cnt + 1;
82 else -- naechstes Bit ausgeben
83 if (tx_bitcnt < 11) then
84 tx_cnt <= 0;
85 tx_bitcnt <= tx_bitcnt + 1;
86 tx_sr <= '1' & tx_sr(tx_sr'left downto 1);
87 end if;
88 end if;
89 end if;
90 end if;
91 end process;
92
93 tx_en <= flow_ctrl;
94 tx_d <= tx_sr(0); -- LSB first
95 tx_busy <= '1' when (tx_start = '1' or tx_bitcnt < 11) else '0';
96
97 -- Empfangen
98 rx_data_proc: process(clk)
99 begin
100 if rising_edge(clk) then
101 rx_dsr <= rx_dsr(rx_dsr'left - 1 downto 0) & rx_d;
102 if (rx_bitcnt < 11) then -- Empfang laeuft
103 if (rx_cnt < (CLOCK_FREQUENCY/BAUD_RATE) - 1) then
104 rx_cnt <= rx_cnt + 1;
105 else
106 rx_cnt <= 0;
107 rx_bitcnt <= rx_bitcnt + 1;
108 if (rx_bitcnt < 9) then
109 rx_sr <= rx_dsr(rx_dsr'left - 1) & rx_sr(rx_sr'left downto 1); -- rechts schieben, weil LSB first
110 else
111 rx_valid <= '1';
112 end if;
113 end if;
114 else
115 if (rx_dsr(3 downto 2) = "10") then -- warten auf Start bit
116 rx_valid <= '0';
117 rx_cnt <= ((CLOCK_FREQUENCY / BAUD_RATE) - 1) / 2;
118 rx_bitcnt <= 0;
119 end if;
120 end if;
121 end if;
122 end process;
123
124 rx_en <= flow_ctrl;
125 rx_data <= rx_sr;
126 --rx_busy <= '1' when (rx_bitcnt < 11) else '0';
127
128END ARCHITECTURE beha;
Note: See TracBrowser for help on using the repository browser.