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

Subversion Repositories t400

[/] [t400/] [tags/] [rel_0_1_beta/] [rtl/] [vhdl/] [t400_sio.vhd] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 arniml
-------------------------------------------------------------------------------
2
--
3
-- The serial input/output unit.
4
--
5
-- $Id: t400_sio.vhd,v 1.1.1.1 2006-05-06 01:56:45 arniml Exp $
6
--
7
-- Copyright (c) 2006 Arnim Laeuger (arniml@opencores.org)
8
--
9
-- All rights reserved
10
--
11
-- Redistribution and use in source and synthezised forms, with or without
12
-- modification, are permitted provided that the following conditions are met:
13
--
14
-- Redistributions of source code must retain the above copyright notice,
15
-- this list of conditions and the following disclaimer.
16
--
17
-- Redistributions in synthesized form must reproduce the above copyright
18
-- notice, this list of conditions and the following disclaimer in the
19
-- documentation and/or other materials provided with the distribution.
20
--
21
-- Neither the name of the author nor the names of other contributors may
22
-- be used to endorse or promote products derived from this software without
23
-- specific prior written permission.
24
--
25
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
29
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35
-- POSSIBILITY OF SUCH DAMAGE.
36
--
37
-- Please report bugs to the author, but before you do so, please
38
-- make sure that this is not a derivative work and that
39
-- you have the latest version of this file.
40
--
41
-- The latest version of this file can be found at:
42
--      http://www.opencores.org/cvsweb.shtml/t400/
43
--
44
-------------------------------------------------------------------------------
45
 
46
library ieee;
47
use ieee.std_logic_1164.all;
48
 
49
use work.t400_pack.all;
50
use work.t400_opt_pack.all;
51
 
52
entity t400_sio is
53
 
54
  generic (
55
    opt_so_output_type_g : integer := t400_opt_out_type_std_c;
56
    opt_sk_output_type_g : integer := t400_opt_out_type_std_c
57
  );
58
  port (
59
    -- System Interface -------------------------------------------------------
60
    ck_i       : in  std_logic;
61
    ck_en_i    : in  boolean;
62
    por_i      : in  boolean;
63
    res_i      : in  boolean;
64
    phi1_i     : in  std_logic;
65
    out_en_i   : in  boolean;
66
    in_en_i    : in  boolean;
67
    -- Control Interface ------------------------------------------------------
68
    op_i       : in  sio_op_t;
69
    en0_i      : in  std_logic;
70
    en3_i      : in  std_logic;
71
    -- SIO Interface ----------------------------------------------------------
72
    a_i        : in  dw_t;
73
    c_i        : in  std_logic;
74
    sio_o      : out dw_t;
75
    -- Pad Interface ----------------------------------------------------------
76
    si_i       : in  std_logic;
77
    so_o       : out std_logic;
78
    so_en_o    : out std_logic;
79
    sk_o       : out std_logic;
80
    sk_en_o    : out std_logic
81
  );
82
 
83
end t400_sio;
84
 
85
 
86
library ieee;
87
use ieee.numeric_std.all;
88
 
89
use work.t400_io_pack.all;
90
 
91
architecture rtl of t400_sio is
92
 
93
  signal si_q       : std_logic;
94
  type   si_flt_t   is (SI_LOW_0, SI_LOW_1,
95
                        SI_HIGH_0, SI_HIGH_1);
96
  signal si_flt_s,
97
         si_flt_q   : si_flt_t;
98
  signal si_0_ok_s,
99
         si_1_ok_s  : boolean;
100
  signal si_0_ok_q,
101
         si_1_ok_q  : boolean;
102
  signal dec_sio_s  : boolean;
103
 
104
  signal new_sio_s,
105
         sio_q      : unsigned(dw_range_t);
106
  signal skl_q      : std_logic;
107
 
108
  signal so_s,
109
         sk_s       : std_logic;
110
 
111
  signal vdd_s      : std_logic;
112
 
113
begin
114
 
115
  vdd_s <= '1';
116
 
117
  -----------------------------------------------------------------------------
118
  -- Process seq
119
  --
120
  -- Purpose:
121
  --   Implements the sequential elements.
122
  --
123
  seq: process (ck_i, por_i)
124
  begin
125
    if    por_i then
126
      sio_q     <= (others => '0');
127
      skl_q     <= '1';
128
      si_q      <= '1';
129
      si_flt_q  <= SI_LOW_0;
130
      si_0_ok_q <= false;
131
      si_1_ok_q <= false;
132
 
133
    elsif ck_i'event and ck_i = '1' then
134
      if res_i then
135
        -- synchronous reset upon external reset event
136
        skl_q <= '1';
137
      else
138
        if in_en_i then
139
          -- sample asynchronous SI input
140
          si_q      <= si_i;
141
        end if;
142
 
143
        if out_en_i then
144
          -- SI filter FSM
145
          si_flt_q  <= si_flt_s;
146
          -- SI low/high markers
147
          si_0_ok_q <= si_0_ok_s;
148
          si_1_ok_q <= si_1_ok_s;
149
        end if;
150
 
151
        -- SIO shift register / counter
152
        if    op_i = SIO_LOAD and ck_en_i then
153
          -- parallel update has priority
154
          sio_q <= unsigned(a_i);
155
          skl_q <= c_i;
156
 
157
        else
158
          sio_q <= new_sio_s;
159
        end if;
160
 
161
      end if;
162
    end if;
163
  end process seq;
164
  --
165
  -----------------------------------------------------------------------------
166
 
167
 
168
  -----------------------------------------------------------------------------
169
  -- Process new_sio
170
  --
171
  -- Purpose:
172
  --   Calculates the new value of SIO.
173
  --   Splitting this from the sequential process is required to deliver
174
  --   the transient new value of SIO to sio_o upon reading SIO.
175
  --
176
  new_sio: process (out_en_i,
177
                    en0_i,
178
                    sio_q,
179
                    dec_sio_s)
180
  begin
181
    -- default value
182
    new_sio_s <= sio_q;
183
 
184
    if out_en_i then
185
      if en0_i = '0' then
186
        -- shift register mode
187
        new_sio_s(3 downto 1) <= sio_q(2 downto 0);
188
        new_sio_s(0)          <= si_q;
189
 
190
      else
191
        -- counter mode
192
        if dec_sio_s then
193
          new_sio_s <= sio_q - 1;
194
        end if;
195
 
196
      end if;
197
    end if;
198
  end process new_sio;
199
  --
200
  -----------------------------------------------------------------------------
201
 
202
 
203
  -----------------------------------------------------------------------------
204
  -- Process si_sample
205
  --
206
  -- Purpose:
207
  --   Implements the low pass filter on SI for low and high levels.
208
  --
209
  si_sample: process (si_q,
210
                      si_flt_q,
211
                      si_0_ok_q, si_1_ok_q)
212
  begin
213
    -- default assignments
214
    si_flt_s  <= si_flt_q;
215
    si_0_ok_s <= si_0_ok_q;
216
    si_1_ok_s <= si_1_ok_q;
217
    dec_sio_s <= false;
218
 
219
    case si_flt_q is
220
      when SI_LOW_0 =>
221
        if si_q = '0' then
222
          si_flt_s  <= SI_LOW_1;
223
        else
224
          si_flt_s  <= SI_HIGH_0;
225
        end if;
226
 
227
      when SI_LOW_1 =>
228
        if si_q = '0' then
229
          si_0_ok_s <= true;            -- enough '0' on SI
230
 
231
          if not si_0_ok_q and si_1_ok_q then
232
            -- decrement counter if durations of high and low phases
233
            -- were long enough
234
            dec_sio_s <= true;
235
          end if;
236
        else
237
          si_flt_s  <= SI_HIGH_0;
238
          si_1_ok_s <= false;           -- restart measuring
239
        end if;
240
 
241
      when SI_HIGH_0 =>
242
        si_1_ok_s <= false;             -- restart marker
243
        if si_q = '1' then
244
          si_flt_s <= SI_HIGH_1;
245
        else
246
          si_flt_s <= SI_LOW_0;
247
        end if;
248
 
249
      when SI_HIGH_1 =>
250
        if si_q = '1' then
251
          si_1_ok_s   <= true;          -- enough '1' on SI
252
        else
253
          si_flt_s    <= SI_LOW_0;
254
          si_0_ok_s   <= false;         -- restart measuring
255
        end if;
256
 
257
      when others =>
258
        null;
259
    end case;
260
  end process si_sample;
261
  --
262
  -----------------------------------------------------------------------------
263
 
264
 
265
  -----------------------------------------------------------------------------
266
  -- Output mapping
267
  -----------------------------------------------------------------------------
268
  sio_o   <= std_logic_vector(new_sio_s);
269
  so_s    <= en3_i and (en0_i or sio_q(3));
270
  sk_s    <= skl_q and (en0_i or phi1_i);
271
  so_o    <= io_out_f(dat => so_s, opt => opt_so_output_type_g);
272
  so_en_o <= io_en_f (en  => vdd_s,
273
                      dat => so_s, opt => opt_so_output_type_g);
274
  sk_o    <= io_out_f(dat => sk_s, opt => opt_sk_output_type_g);
275
  sk_en_o <= io_en_f (en  => vdd_s,
276
                      dat => sk_s, opt => opt_sk_output_type_g);
277
 
278
end rtl;
279
 
280
 
281
-------------------------------------------------------------------------------
282
-- File History:
283
--
284
-- $Log: not supported by cvs2svn $
285
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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