OpenCores
URL https://opencores.org/ocsvn/usb_dongle_fpga/usb_dongle_fpga/trunk

Subversion Repositories usb_dongle_fpga

[/] [usb_dongle_fpga/] [trunk/] [src/] [lpc_proto/] [lpc_byte.vhd] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 nuubik
------------------------------------------------------------------
2
-- Universal dongle board source code
3
-- 
4
-- Copyright (C) 2006 Artec Design <jyrit@artecdesign.ee>
5
-- 
6
-- This source code is free hardware; you can redistribute it and/or
7
-- modify it under the terms of the GNU Lesser General Public
8
-- License as published by the Free Software Foundation; either
9
-- version 2.1 of the License, or (at your option) any later version.
10
-- 
11
-- This source code is distributed in the hope that it will be useful,
12
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
-- Lesser General Public License for more details.
15
-- 
16
-- You should have received a copy of the GNU Lesser General Public
17
-- License along with this library; if not, write to the Free Software
18
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
-- 
20
-- 
21
-- The complete text of the GNU Lesser General Public License can be found in 
22
-- the file 'lesser.txt'.
23
 
24
 
25
library ieee;
26
use ieee.std_logic_1164.all;
27
use IEEE.std_logic_unsigned.all;
28
use IEEE.std_logic_arith.all;
29
 
30
 
31
entity lpc_iow is
32
  port (
33
     --system signals
34
    lreset_n   : in  std_logic;
35
    lclk       : in  std_logic;
36
        --LPC bus from host
37
    lad_i      : in  std_logic_vector(3 downto 0);
38
    lad_o      : out std_logic_vector(3 downto 0);
39
    lad_oe     : out std_logic;
40
    lframe_n   : in  std_logic;
41
        --memory interface
42
    lpc_addr   : out std_logic_vector(23 downto 0); --shared address
43
    lpc_wr     : out std_logic;         --shared write not read
44
    lpc_data_i : in  std_logic_vector(7 downto 0);
45
    lpc_data_o : out std_logic_vector(7 downto 0);
46
    lpc_val    : out std_logic;
47
    lpc_ack    : in  std_logic
48
    );
49
end lpc_iow;
50
 
51
architecture rtl of lpc_iow is
52
type state is (RESETs,STARTs,ADDRs,TARs,SYNCs,DATAs,LOCAL_TARs);  -- simple LCP states
53
signal CS : state;
54
signal r_lad   : std_logic_vector(3 downto 0);
55
signal r_addr  : std_logic_vector(31 downto 0);  --should consider saving max
56
                                                --adress 23 bits on flash
57
signal r_data  : std_logic_vector(7 downto 0);
58
signal r_cnt   : std_logic_vector(2 downto 0);
59
signal ext_sum : std_logic_vector(2 downto 0);
60
signal mem_nio : std_logic;             -- memory not io cycle
61
signal data_valid : std_logic;
62
begin  -- rtl
63
 
64
 
65
--Pass the whole LPC address to the system
66
lpc_addr <= r_addr(23 downto 0);
67
lpc_data_o<= r_data;
68
 
69
 
70
--this result is used in LPC process 
71
ext_sum <= r_cnt + 1;
72
 
73
-- purpose: LPC IO write handler
74
-- type   : sequential
75
-- inputs : lclk, lreset_n
76
-- outputs: 
77
LPC: process (lclk, lreset_n)
78
begin  -- process LPC
79
  if lreset_n = '0' then                -- asynchronous reset (active low)
80
    CS<= RESETs;
81
    lad_oe<='0';
82
    data_valid <='1';
83
    lad_o <="0000";
84
    lpc_val <='0';
85
         r_addr <= (others=>'0');
86
   elsif lclk'event and lclk = '1' then  -- rising clock edge
87
    case CS is
88
      when RESETs => ----------------------------------------------------------
89
        lpc_wr <='0';
90
        lpc_val <='0';
91
        if lframe_n='0' then
92
          CS <= STARTs;
93
          r_lad <= lad_i;
94
        else
95
          CS <= RESETs;
96
        end if;
97
      when STARTs => ----------------------------------------------------------
98
        if lframe_n = '0' then
99
          r_lad <= lad_i;
100
          CS <= STARTs;
101
        elsif r_lad="0000" then
102
          --must identify CYCTYPE
103
          if lad_i(3 downto 1)="001" then --IO WRITE WILL HAPPEN
104
            --next 4 states must be address states
105
            CS<=ADDRs;
106
            mem_nio <= '0';
107
            r_cnt <= "000";
108
          elsif lad_i(3 downto 1)="010" then
109
            CS<=ADDRs;
110
            mem_nio <= '1';
111
            r_cnt <= "000";
112
          else
113
            CS<= RESETs;
114
          end if;
115
        end if;
116
      when ADDRs => -----------------------------------------------------------
117
       case mem_nio is
118
         when '0' =>                   --IO write cycle
119
          if r_cnt ="011" then
120
             if r_addr(11 downto 0)=x"008" and lad_i(3 downto 2)="00" then
121
              r_addr<= r_addr(27 downto 0)&lad_i;
122
              r_cnt <= "000";
123
              CS<=DATAs;
124
            elsif r_addr(11 downto 0)=x"008" and lad_i(3 downto 0)=x"8" then  --for debug switch
125
              r_addr<= r_addr(27 downto 0)&lad_i;
126
              r_cnt <= "000";
127
              CS<=DATAs;
128
            else
129
              --not for this device
130
               CS<=RESETs;
131
            end if;
132
          else
133
            r_addr<= r_addr(27 downto 0)&lad_i;
134
            r_cnt<=ext_sum;
135
            CS<=ADDRs;
136
          end if;
137
        when '1' =>                    --Memory read cycle
138
          if r_cnt ="111" then
139
              r_addr<= r_addr(27 downto 0)&lad_i;
140
              r_cnt <= "000";
141
              lpc_wr <='0';             --memory read mus accure
142
              lpc_val <='1';
143
              data_valid <='0';
144
              CS<=TARs;
145
          else
146
            r_addr<= r_addr(27 downto 0)&lad_i;
147
            r_cnt<=ext_sum;
148
            CS<=ADDRs;
149
          end if;
150
         when others => null;
151
        end case;
152
      when DATAs => -----------------------------------------------------------
153
       case mem_nio is
154
        when '0' =>                   --IO write cycle              
155
          if r_cnt ="001" then
156
            r_data <= r_data(3 downto 0)&lad_i;
157
            r_cnt <= "000";
158
            lpc_wr <='1';             --IO write must accure
159
            lpc_val <='1';
160
            CS <= TARs;
161
          else
162
            r_data <= r_data(3 downto 0)&lad_i;
163
            r_cnt<=ext_sum;
164
            CS <= DATAs;
165
          end if;
166
        when '1' =>                    --Memory read cycle
167
          if r_cnt ="001" then
168
            lad_o <= r_data(7 downto 4);
169
            r_cnt <= "000";
170
            CS <= LOCAL_TARs;
171
          else
172
            lad_o <= r_data(3 downto 0);
173
            r_cnt<=ext_sum;
174
            CS <= DATAs;
175
          end if;
176
        when others => null;
177
       end case;
178
      when TARs => ------------------------------------------------------------
179
          if mem_nio = '1' and lpc_ack='1' and r_cnt ="001" then
180
            r_data <= lpc_data_i;
181
            lpc_val <='0';
182
            data_valid <='1';
183
                        CS<= SYNCs;
184
                        r_cnt <= "000";
185
                  elsif lpc_ack='1' and r_cnt ="001" then
186
                  lad_o<="0000";              --added to avoid trouble
187
                        lpc_val <='0';
188
                        CS<= SYNCs;
189
                        r_cnt <= "000";
190
          end if;
191
 
192
          if r_cnt ="001" then
193
                          if lpc_ack='0' then
194
                                lad_o<="0110";              --added to avoid trouble                            
195
                          end if;
196
            lad_oe<='1';
197
          elsif lad_i="1111" then
198
            r_cnt<=ext_sum;
199
            lad_oe<='1';
200
            lad_o<="1111";              --drive to F on the bus
201
            CS <= TARs;
202
          else
203
            CS <= RESETs; --some error in protocol master must drive lad to "1111" on 1st TAR
204
          end if;
205
      when SYNCs => -----------------------------------------------------------
206
       case mem_nio is
207
        when '0' =>                   --IO write cycle   
208
          -- just passing r_lad on bus again
209
          lad_o <= "1111";
210
          CS <= LOCAL_TARs;
211
        when '1' =>                    --Memory read cycle
212
          if data_valid ='1' then
213
            lad_o <="0000";
214
            CS <= DATAs;
215
          else
216
            if lpc_ack='1' then
217
              r_data <= lpc_data_i;
218
              data_valid <= '1';
219
              lad_o<="0000";           --SYNC ok now                            
220
              lpc_val <='0';
221
              CS <= DATAs;
222
            end if;
223
          end if;
224
         when others => null;
225
        end case;
226
      when LOCAL_TARs => ------------------------------------------------------
227
       case mem_nio is
228
        when '0' =>                   --IO write cycle   
229
            lpc_wr <='0';
230
            lad_oe <='0';
231
            CS <= RESETs;
232
        when '1' =>                    --Memory read cycle
233
          if r_cnt ="000" then
234
            lad_o <= "1111";
235
            r_cnt <= ext_sum;
236
          else
237
            lad_oe <= '0';
238
            r_cnt <="000";
239
            CS <= RESETs;
240
          end if;
241
        when others => null;
242
       end case;
243
    end case; -----------------------------------------------------------------
244
  end if;
245
end process LPC;
246
 
247
end rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.