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

Subversion Repositories t400

[/] [t400/] [trunk/] [rtl/] [vhdl/] [t400_sio.vhd] - Blame information for rev 8

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 8 arniml
-- $Id: t400_sio.vhd,v 1.2 2006-05-06 13:34:58 arniml Exp $
6 2 arniml
--
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 8 arniml
  signal phi1_en_q  : std_logic;
108 2 arniml
 
109
  signal so_s,
110
         sk_s       : std_logic;
111
 
112
  signal vdd_s      : std_logic;
113
 
114
begin
115
 
116
  vdd_s <= '1';
117
 
118
  -----------------------------------------------------------------------------
119
  -- Process seq
120
  --
121
  -- Purpose:
122
  --   Implements the sequential elements.
123
  --
124
  seq: process (ck_i, por_i)
125
  begin
126
    if    por_i then
127
      sio_q     <= (others => '0');
128
      skl_q     <= '1';
129 8 arniml
      phi1_en_q <= '1';
130 2 arniml
      si_q      <= '1';
131
      si_flt_q  <= SI_LOW_0;
132
      si_0_ok_q <= false;
133
      si_1_ok_q <= false;
134
 
135
    elsif ck_i'event and ck_i = '1' then
136
      if res_i then
137
        -- synchronous reset upon external reset event
138 8 arniml
        skl_q     <= '1';
139
        phi1_en_q <= '1';
140 2 arniml
      else
141
        if in_en_i then
142
          -- sample asynchronous SI input
143
          si_q      <= si_i;
144
        end if;
145
 
146
        if out_en_i then
147
          -- SI filter FSM
148
          si_flt_q  <= si_flt_s;
149
          -- SI low/high markers
150
          si_0_ok_q <= si_0_ok_s;
151
          si_1_ok_q <= si_1_ok_s;
152
        end if;
153
 
154
        -- SIO shift register / counter
155
        if    op_i = SIO_LOAD and ck_en_i then
156
          -- parallel update has priority
157
          sio_q <= unsigned(a_i);
158
          skl_q <= c_i;
159
 
160
        else
161
          sio_q <= new_sio_s;
162
        end if;
163
 
164 8 arniml
        if ck_en_i then
165
          -- delay enable of PHI1 by one clock cycle
166
          -- this prevents glitches on sk_o when enabling/disabling
167
          -- sk_o as a clock output
168
          phi1_en_q <= skl_q;
169
        end if;
170
 
171 2 arniml
      end if;
172
    end if;
173
  end process seq;
174
  --
175
  -----------------------------------------------------------------------------
176
 
177
 
178
  -----------------------------------------------------------------------------
179
  -- Process new_sio
180
  --
181
  -- Purpose:
182
  --   Calculates the new value of SIO.
183
  --   Splitting this from the sequential process is required to deliver
184
  --   the transient new value of SIO to sio_o upon reading SIO.
185
  --
186
  new_sio: process (out_en_i,
187
                    en0_i,
188
                    sio_q,
189
                    dec_sio_s)
190
  begin
191
    -- default value
192
    new_sio_s <= sio_q;
193
 
194
    if out_en_i then
195
      if en0_i = '0' then
196
        -- shift register mode
197
        new_sio_s(3 downto 1) <= sio_q(2 downto 0);
198
        new_sio_s(0)          <= si_q;
199
 
200
      else
201
        -- counter mode
202
        if dec_sio_s then
203
          new_sio_s <= sio_q - 1;
204
        end if;
205
 
206
      end if;
207
    end if;
208
  end process new_sio;
209
  --
210
  -----------------------------------------------------------------------------
211
 
212
 
213
  -----------------------------------------------------------------------------
214
  -- Process si_sample
215
  --
216
  -- Purpose:
217
  --   Implements the low pass filter on SI for low and high levels.
218
  --
219
  si_sample: process (si_q,
220
                      si_flt_q,
221
                      si_0_ok_q, si_1_ok_q)
222
  begin
223
    -- default assignments
224
    si_flt_s  <= si_flt_q;
225
    si_0_ok_s <= si_0_ok_q;
226
    si_1_ok_s <= si_1_ok_q;
227
    dec_sio_s <= false;
228
 
229
    case si_flt_q is
230
      when SI_LOW_0 =>
231
        if si_q = '0' then
232
          si_flt_s  <= SI_LOW_1;
233
        else
234
          si_flt_s  <= SI_HIGH_0;
235
        end if;
236
 
237
      when SI_LOW_1 =>
238
        if si_q = '0' then
239
          si_0_ok_s <= true;            -- enough '0' on SI
240
 
241
          if not si_0_ok_q and si_1_ok_q then
242
            -- decrement counter if durations of high and low phases
243
            -- were long enough
244
            dec_sio_s <= true;
245
          end if;
246
        else
247
          si_flt_s  <= SI_HIGH_0;
248
          si_1_ok_s <= false;           -- restart measuring
249
        end if;
250
 
251
      when SI_HIGH_0 =>
252
        si_1_ok_s <= false;             -- restart marker
253
        if si_q = '1' then
254
          si_flt_s <= SI_HIGH_1;
255
        else
256
          si_flt_s <= SI_LOW_0;
257
        end if;
258
 
259
      when SI_HIGH_1 =>
260
        if si_q = '1' then
261
          si_1_ok_s   <= true;          -- enough '1' on SI
262
        else
263
          si_flt_s    <= SI_LOW_0;
264
          si_0_ok_s   <= false;         -- restart measuring
265
        end if;
266
 
267
      when others =>
268
        null;
269
    end case;
270
  end process si_sample;
271
  --
272
  -----------------------------------------------------------------------------
273
 
274
 
275
  -----------------------------------------------------------------------------
276
  -- Output mapping
277
  -----------------------------------------------------------------------------
278
  sio_o   <= std_logic_vector(new_sio_s);
279
  so_s    <= en3_i and (en0_i or sio_q(3));
280 8 arniml
  sk_s    <= phi1_en_q and (en0_i or phi1_i);
281 2 arniml
  so_o    <= io_out_f(dat => so_s, opt => opt_so_output_type_g);
282
  so_en_o <= io_en_f (en  => vdd_s,
283
                      dat => so_s, opt => opt_so_output_type_g);
284
  sk_o    <= io_out_f(dat => sk_s, opt => opt_sk_output_type_g);
285
  sk_en_o <= io_en_f (en  => vdd_s,
286
                      dat => sk_s, opt => opt_sk_output_type_g);
287
 
288
end rtl;
289
 
290
 
291
-------------------------------------------------------------------------------
292
-- File History:
293
--
294
-- $Log: not supported by cvs2svn $
295 8 arniml
-- Revision 1.1.1.1  2006/05/06 01:56:45  arniml
296
-- import from local CVS repository, LOC_CVS_0_1
297
--
298 2 arniml
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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