lx9_FT245_0.vhd


1
library ieee;
2
use ieee.std_logic_1164.all;
3
use IEEE.numeric_std.all;
4
-- synthesis translate_off
5
LIBRARY XilinxCoreLib;
6
-- synthesis translate_on
7
library unisim;
8
use unisim.vcomponents.all;
9
10
entity lx9_FT245 is port(
11
  CLK: in std_logic;
12
  D: inout std_logic_vector(7 downto 0);
13
  RXF: in std_logic; --when high do not read
14
  TXE: in std_logic; --when high do not write
15
  RD: out std_logic;
16
  WR: out std_logic;
17
  SIWU: out std_logic;
18
  CLKOUT: in std_logic;
19
  OE: out std_logic;
20
  PWRSAV: out std_logic;
21
  ACBUS8: out std_logic;
22
  ACBUS9: out std_logic;
23
  RST: out std_logic;
24
  PIN: out std_logic_vector(26 downto 3);
25
  LED: out std_logic_vector(1 downto 0);
26
  BTN: in std_logic);
27
end lx9_FT245;
28
29
architecture behav of lx9_FT245 is
30
31
component FIFO_ft232h is
32
Port (
33
  clk : in std_logic;
34
  rd: in std_logic;
35
  wr: in std_logic;
36
  data_in : in std_logic_vector(175 downto 0);
37
  data_out : out std_logic_vector(175 downto 0);
38
  full: out std_logic;
39
  empty: out std_logic);
40
end component;
41
42
signal blinkcounter_50: unsigned(25 downto 0):=(others => '0');
43
signal blinkcounter_60: unsigned(25 downto 0):=(others => '0');
44
signal bytecounter: unsigned(7 downto 0):=(others => '0');
45
46
signal counter_1ms: integer range 0 to 49:=0;
47
signal send_counter: integer range 0 to 21:=21;
48
signal fifo_in, fifo_out, send_data: std_logic_vector(175 downto 0):=(others => '0');
49
signal bytes_send: std_logic_vector(175 downto 0):=(others => '0');--:=x"000102030405060708090A0B0C0D0E0F1011121314";
50
signal fifo_empty,fifo_full,fifo_wr,fifo_rd_60,fifo_rd: std_logic:='0';
51
signal state: integer range 0 to 4:=0;
52
53
begin
54
55
f0: FIFO_ft232h Port map(
56
  clk => CLK,
57
  rd => fifo_rd,
58
  wr => fifo_wr,
59
  data_in => fifo_in,
60
  data_out => fifo_out,
61
  full => fifo_full,
62
  empty => fifo_empty);
63
64
RD <= '1';
65
SIWU <= '1';
66
OE <= '1';
67
PWRSAV <= 'Z';
68
ACBUS8 <= 'Z';
69
ACBUS9 <= 'Z';
70
RST <= '1';
71
72
PIN(3) <= CLKOUT;
73
PIN(4) <= TXE;
74
PIN(5) <= '0';
75
PIN(6) <= fifo_full;
76
PIN(7) <= '0';
77
PIN(26 downto 9) <= (others => '0');
78
79
LED(0) <= blinkcounter_50(25);
80
LED(1) <= blinkcounter_60(25);
81
82
fifo_in <= bytes_send;
83
84
process 
85
variable sr_rd_50 : std_logic_vector (1 downto 0) := "00";
86
begin
87
  wait until rising_edge(CLK);
88
  blinkcounter_50 <= blinkcounter_50 +1;
89
  counter_1ms <= counter_1ms+1;
90
  
91
  if counter_1ms = 49 then
92
    counter_1ms <= 0;
93
  end if;
94
  
95
  --- data ---
96
  if counter_1ms < 22 then
97
    bytecounter <= bytecounter +1;
98
    bytes_send <= bytes_send(167 downto 0) & std_logic_vector(bytecounter);
99
  end if;
100
  
101
  --- write ---
102
  fifo_wr <= '0';
103
  if counter_1ms = 32 then
104
    fifo_wr <= '1';
105
  end if;
106
  
107
  --- read ---
108
    sr_rd_50 := sr_rd_50(0) & fifo_rd_60;
109
    fifo_rd <= not sr_rd_50(1) and sr_rd_50(0);
110
end process;
111
112
113
process begin
114
  wait until rising_edge(CLKOUT);
115
  blinkcounter_60 <= blinkcounter_60 +1;
116
  
117
  fifo_rd_60 <= '0';
118
  if state = 0 then
119
    if fifo_empty = '0' then
120
      fifo_rd_60 <= '1';
121
      send_data <= fifo_out;
122
      state <= 1;
123
    end if;
124
  elsif state = 1 then
125
    fifo_rd_60 <= '1';
126
    send_data <= fifo_out;
127
    state <= 2;
128
  elsif state = 2 then
129
    fifo_rd_60 <= '0';
130
    send_data <= fifo_out;
131
    state <= 3;
132
  elsif state = 3 then
133
    fifo_rd_60 <= '0';
134
    send_data <= fifo_out;
135
    if TXE = '0' then
136
      send_counter <= 21;
137
      state <= 4;
138
      WR <= '0';
139
      PIN(8) <= '0';
140
    end if;
141
  elsif state = 4 then
142
    if send_counter = 0 then
143
      WR <= '1';
144
      PIN(8) <= '1';
145
    end if;
146
    if TXE = '0' and send_counter > 0 then
147
      send_counter <= send_counter-1;
148
    end if;
149
    if send_counter = 0 then
150
      WR <= '1';
151
      PIN(8) <= '1';
152
      state <= 0;
153
    end if;
154
  end if;
155
end process;
156
157
D <= send_data(send_counter*8 +7 downto send_counter*8) when state = 4 else "00000000";
158
159
end behav;