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

Subversion Repositories gamepads

[/] [gamepads/] [trunk/] [gcpad/] [rtl/] [vhdl/] [gcpad_sampler.vhd] - Blame information for rev 41

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 arniml
-------------------------------------------------------------------------------
2
--
3
-- GCpad controller core
4
--
5 41 arniml
-- $Id: gcpad_sampler.vhd 41 2009-04-01 19:58:04Z arniml $
6 14 arniml
--
7
-- Copyright (c) 2004, 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/gamepads/
43
--
44
-- The project homepage is located at:
45
--      http://www.opencores.org/projects.cgi/web/gamepads/overview
46
--
47
-------------------------------------------------------------------------------
48
 
49
library ieee;
50
use ieee.std_logic_1164.all;
51
 
52
entity gcpad_sampler is
53
 
54
  generic (
55
    reset_level_g      :     integer := 0;
56
    clocks_per_1us_g   :     integer := 2
57
  );
58
  port (
59 16 arniml
    -- System Interface -------------------------------------------------------
60 14 arniml
    clk_i              : in  std_logic;
61
    reset_i            : in  std_logic;
62 16 arniml
    -- Control Interface ------------------------------------------------------
63 14 arniml
    wrap_sample_i      : in  boolean;
64
    sync_sample_i      : in  boolean;
65
    sample_underflow_o : out boolean;
66 16 arniml
    -- Pad Interface ----------------------------------------------------------
67 14 arniml
    pad_data_i         : in  std_logic;
68
    pad_data_o         : out std_logic;
69
    sample_o           : out std_logic
70
  );
71
 
72
end gcpad_sampler;
73
 
74
 
75
use work.gcpad_pack.all;
76
 
77
architecture rtl of gcpad_sampler is
78
 
79
  signal pad_data_sync_q : std_logic_vector(1 downto 0);
80
  signal pad_data_s      : std_logic;
81
 
82
  constant cnt_sample_high_c  : natural := clocks_per_1us_g * 4 - 1;
83
  subtype  cnt_sample_t       is natural range 0 to cnt_sample_high_c;
84
  signal   cnt_zeros_q        : cnt_sample_t;
85
  signal   cnt_ones_q         : cnt_sample_t;
86
  signal   sample_underflow_q : boolean;
87
 
88
  signal   more_ones_q    : boolean;
89
 
90
begin
91
 
92
  seq: process (reset_i, clk_i)
93
    variable dec_timeout_v : boolean;
94
  begin
95
    if reset_i = reset_level_g then
96
      cnt_zeros_q          <= cnt_sample_high_c;
97
      cnt_ones_q           <= cnt_sample_high_c;
98
      more_ones_q          <= false;
99
      sample_underflow_q   <= false;
100
 
101
      pad_data_sync_q      <= (others => '1');
102
 
103
    elsif clk_i'event and clk_i = '1' then
104
      -- synchronizer for pad data
105
      pad_data_sync_q(0) <= pad_data_i;
106
      pad_data_sync_q(1) <= pad_data_sync_q(0);
107
 
108
      -- sample counter
109
      dec_timeout_v := false;
110
      if sync_sample_i then
111
        -- explicit preload
112
        cnt_zeros_q     <= cnt_sample_high_c;
113
        cnt_ones_q      <= cnt_sample_high_c;
114
      else
115
        if cnt_zeros_q = 0 then
116
          if wrap_sample_i then
117
            cnt_zeros_q <= cnt_sample_high_c;
118
          end if;
119
          dec_timeout_v := true;
120
        elsif pad_data_s = '0' then
121
          cnt_zeros_q   <= cnt_zeros_q - 1;
122
        end if;
123
 
124
        if cnt_ones_q = 0 then
125
          if wrap_sample_i then
126
            cnt_ones_q  <= cnt_sample_high_c;
127
          end if;
128
          dec_timeout_v := true;
129
        elsif pad_data_s /= '0' then
130
          cnt_ones_q    <= cnt_ones_q - 1;
131
        end if;
132
      end if;
133
 
134
      if cnt_ones_q < cnt_zeros_q then
135
        more_ones_q <= true;
136
      else
137
        more_ones_q <= false;
138
      end if;
139
 
140
      -- detect sample underflow
141
      sample_underflow_q <= dec_timeout_v;
142
 
143
    end if;
144
 
145
  end process seq;
146
 
147
  pad_data_s <= pad_data_sync_q(1);
148
 
149
 
150
  -----------------------------------------------------------------------------
151
  -- Output mapping
152
  -----------------------------------------------------------------------------
153
  pad_data_o         <= pad_data_s;
154
  sample_o           <=   '1'
155
                        when more_ones_q else
156
                          '0';
157
  sample_underflow_o <= sample_underflow_q;
158
 
159
end rtl;

powered by: WebSVN 2.1.0

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