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

Subversion Repositories gamepads

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

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

Line No. Rev Author Line
1 14 arniml
-------------------------------------------------------------------------------
2
--
3
-- GCpad controller core
4
--
5 15 arniml
-- $Id: gcpad_sampler.vhd,v 1.2 2004-10-08 21:35:08 arniml Exp $
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
    clk_i              : in  std_logic;
60
    reset_i            : in  std_logic;
61
    wrap_sample_i      : in  boolean;
62
    sync_sample_i      : in  boolean;
63
    sample_underflow_o : out boolean;
64
    pad_data_i         : in  std_logic;
65
    pad_data_o         : out std_logic;
66
    sample_o           : out std_logic
67
  );
68
 
69
end gcpad_sampler;
70
 
71
 
72
use work.gcpad_pack.all;
73
 
74
architecture rtl of gcpad_sampler is
75
 
76
  signal pad_data_sync_q : std_logic_vector(1 downto 0);
77
  signal pad_data_s      : std_logic;
78
 
79
  constant cnt_sample_high_c  : natural := clocks_per_1us_g * 4 - 1;
80
  subtype  cnt_sample_t       is natural range 0 to cnt_sample_high_c;
81
  signal   cnt_zeros_q        : cnt_sample_t;
82
  signal   cnt_ones_q         : cnt_sample_t;
83
  signal   sample_underflow_q : boolean;
84
 
85
  signal   more_ones_q    : boolean;
86
 
87
begin
88
 
89
  seq: process (reset_i, clk_i)
90
    variable dec_timeout_v : boolean;
91
  begin
92
    if reset_i = reset_level_g then
93
      cnt_zeros_q          <= cnt_sample_high_c;
94
      cnt_ones_q           <= cnt_sample_high_c;
95
      more_ones_q          <= false;
96
      sample_underflow_q   <= false;
97
 
98
      pad_data_sync_q      <= (others => '1');
99
 
100
    elsif clk_i'event and clk_i = '1' then
101
      -- synchronizer for pad data
102
      pad_data_sync_q(0) <= pad_data_i;
103
      pad_data_sync_q(1) <= pad_data_sync_q(0);
104
 
105
      -- sample counter
106
      dec_timeout_v := false;
107
      if sync_sample_i then
108
        -- explicit preload
109
        cnt_zeros_q     <= cnt_sample_high_c;
110
        cnt_ones_q      <= cnt_sample_high_c;
111
      else
112
        if cnt_zeros_q = 0 then
113
          if wrap_sample_i then
114
            cnt_zeros_q <= cnt_sample_high_c;
115
          end if;
116
          dec_timeout_v := true;
117
        elsif pad_data_s = '0' then
118
          cnt_zeros_q   <= cnt_zeros_q - 1;
119
        end if;
120
 
121
        if cnt_ones_q = 0 then
122
          if wrap_sample_i then
123
            cnt_ones_q  <= cnt_sample_high_c;
124
          end if;
125
          dec_timeout_v := true;
126
        elsif pad_data_s /= '0' then
127
          cnt_ones_q    <= cnt_ones_q - 1;
128
        end if;
129
      end if;
130
 
131
      if cnt_ones_q < cnt_zeros_q then
132
        more_ones_q <= true;
133
      else
134
        more_ones_q <= false;
135
      end if;
136
 
137
      -- detect sample underflow
138
      sample_underflow_q <= dec_timeout_v;
139
 
140
    end if;
141
 
142
  end process seq;
143
 
144
  pad_data_s <= pad_data_sync_q(1);
145
 
146
 
147
  -----------------------------------------------------------------------------
148
  -- Output mapping
149
  -----------------------------------------------------------------------------
150
  pad_data_o         <= pad_data_s;
151
  sample_o           <=   '1'
152
                        when more_ones_q else
153
                          '0';
154
  sample_underflow_o <= sample_underflow_q;
155
 
156
end rtl;
157 15 arniml
 
158
 
159
-------------------------------------------------------------------------------
160
-- File History:
161
--
162
-- $Log: not supported by cvs2svn $
163
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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