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

Subversion Repositories t400

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 arniml
-------------------------------------------------------------------------------
2
--
3
-- The serial input/output unit.
4
--
5 179 arniml
-- $Id: t400_sio.vhd 179 2009-04-01 19:48:38Z arniml $
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 12 arniml
                    si_q,
190 2 arniml
                    dec_sio_s)
191
  begin
192
    -- default value
193
    new_sio_s <= sio_q;
194
 
195
    if out_en_i then
196
      if en0_i = '0' then
197
        -- shift register mode
198
        new_sio_s(3 downto 1) <= sio_q(2 downto 0);
199
        new_sio_s(0)          <= si_q;
200
 
201
      else
202
        -- counter mode
203
        if dec_sio_s then
204
          new_sio_s <= sio_q - 1;
205
        end if;
206
 
207
      end if;
208
    end if;
209
  end process new_sio;
210
  --
211
  -----------------------------------------------------------------------------
212
 
213
 
214
  -----------------------------------------------------------------------------
215
  -- Process si_sample
216
  --
217
  -- Purpose:
218
  --   Implements the low pass filter on SI for low and high levels.
219
  --
220
  si_sample: process (si_q,
221
                      si_flt_q,
222
                      si_0_ok_q, si_1_ok_q)
223
  begin
224
    -- default assignments
225
    si_flt_s  <= si_flt_q;
226
    si_0_ok_s <= si_0_ok_q;
227
    si_1_ok_s <= si_1_ok_q;
228
    dec_sio_s <= false;
229
 
230
    case si_flt_q is
231
      when SI_LOW_0 =>
232
        if si_q = '0' then
233
          si_flt_s  <= SI_LOW_1;
234
        else
235
          si_flt_s  <= SI_HIGH_0;
236
        end if;
237
 
238
      when SI_LOW_1 =>
239
        if si_q = '0' then
240
          si_0_ok_s <= true;            -- enough '0' on SI
241
 
242
          if not si_0_ok_q and si_1_ok_q then
243
            -- decrement counter if durations of high and low phases
244
            -- were long enough
245
            dec_sio_s <= true;
246
          end if;
247
        else
248
          si_flt_s  <= SI_HIGH_0;
249
          si_1_ok_s <= false;           -- restart measuring
250
        end if;
251
 
252
      when SI_HIGH_0 =>
253
        si_1_ok_s <= false;             -- restart marker
254
        if si_q = '1' then
255
          si_flt_s <= SI_HIGH_1;
256
        else
257
          si_flt_s <= SI_LOW_0;
258
        end if;
259
 
260
      when SI_HIGH_1 =>
261
        if si_q = '1' then
262
          si_1_ok_s   <= true;          -- enough '1' on SI
263
        else
264
          si_flt_s    <= SI_LOW_0;
265
          si_0_ok_s   <= false;         -- restart measuring
266
        end if;
267
 
268
      when others =>
269
        null;
270
    end case;
271
  end process si_sample;
272
  --
273
  -----------------------------------------------------------------------------
274
 
275
 
276
  -----------------------------------------------------------------------------
277
  -- Output mapping
278
  -----------------------------------------------------------------------------
279
  sio_o   <= std_logic_vector(new_sio_s);
280
  so_s    <= en3_i and (en0_i or sio_q(3));
281 8 arniml
  sk_s    <= phi1_en_q and (en0_i or phi1_i);
282 2 arniml
  so_o    <= io_out_f(dat => so_s, opt => opt_so_output_type_g);
283
  so_en_o <= io_en_f (en  => vdd_s,
284
                      dat => so_s, opt => opt_so_output_type_g);
285
  sk_o    <= io_out_f(dat => sk_s, opt => opt_sk_output_type_g);
286
  sk_en_o <= io_en_f (en  => vdd_s,
287
                      dat => sk_s, opt => opt_sk_output_type_g);
288
 
289
end rtl;

powered by: WebSVN 2.1.0

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