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

Subversion Repositories gamepads

[/] [gamepads/] [trunk/] [snespad/] [rtl/] [vhdl/] [snespad_ctrl.vhd] - Blame information for rev 3

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

Line No. Rev Author Line
1 3 arniml
-------------------------------------------------------------------------------
2
--
3
-- SNESpad controller core
4
--
5
-- $Id: snespad_ctrl.vhd,v 1.1 2004-10-05 17:01:27 arniml Exp $
6
--
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 snespad_ctrl is
53
 
54
  generic (
55
    reset_level_g    :     natural := 0;
56
    clocks_per_6us_g :     natural := 6
57
  );
58
  port (
59
    -- System Interface -------------------------------------------------------
60
    clk_i            : in  std_logic;
61
    reset_i          : in  std_logic;
62
    clk_en_o         : out boolean;
63
    -- Control Interface ------------------------------------------------------
64
    shift_buttons_o  : out boolean;
65
    save_buttons_o   : out boolean;
66
    -- Pad Interface ----------------------------------------------------------
67
    pad_clk_o        : out std_logic;
68
    pad_latch_o      : out std_logic
69
  );
70
 
71
end snespad_ctrl;
72
 
73
 
74
use work.snespad_pack.all;
75
 
76
architecture rtl of snespad_ctrl is
77
 
78
  subtype  clocks_per_6us_t is natural range 0 to clocks_per_6us_g;
79
 
80
  type state_t is (IDLE,
81
                   IDLE2,
82
                   LATCH,
83
                   CLOCK,
84
                   READ_PAD);
85
 
86
  signal pad_latch_q,
87
         pad_latch_s  : std_logic;
88
 
89
  signal pad_clk_q,
90
         pad_clk_s  : std_logic;
91
 
92
  signal num_buttons_read_q : num_buttons_read_t;
93
  signal clocks_per_6us_q : clocks_per_6us_t;
94
 
95
  signal state_q,
96
         state_s  : state_t;
97
 
98
  signal clk_en_s        : boolean;
99
  signal shift_buttons_s : boolean;
100
 
101
begin
102
 
103
  -- pragma translate_off
104
  -----------------------------------------------------------------------------
105
  -- Check generics
106
  -----------------------------------------------------------------------------
107
  assert (reset_level_g = 0) or (reset_level_g = 1)
108
    report "reset_level_g must be either 0 or 1!"
109
    severity failure;
110
 
111
  assert clocks_per_6us_g > 1
112
    report "clocks_per_6us_g must be at least 2!"
113
    severity failure;
114
  -- pragma translate_on
115
 
116
 
117
  seq: process (reset_i, clk_i)
118
    variable clocks_per_6us_overflow_v : boolean;
119
  begin
120
    if reset_i = reset_level_g then
121
      pad_latch_q <= '1';
122
      pad_clk_q   <= '1';
123
 
124
      num_buttons_read_q <= num_buttons_c-1;
125
 
126
      clocks_per_6us_q  <= 0;
127
 
128
      state_q     <= IDLE;
129
 
130
    elsif clk_i'event and clk_i = '1' then
131
      if clk_en_s then
132
        clocks_per_6us_q <= 0;
133
      else
134
        clocks_per_6us_q <= clocks_per_6us_q + 1;
135
      end if;
136
 
137
      if clk_en_s and shift_buttons_s then
138
        if num_buttons_read_q = 0 then
139
          num_buttons_read_q <= num_buttons_c-1;
140
        else
141
          num_buttons_read_q <= num_buttons_read_q - 1;
142
        end if;
143
      end if;
144
 
145
      if clk_en_s then
146
        state_q <= state_s;
147
      end if;
148
 
149
      pad_clk_q   <= pad_clk_s;
150
 
151
      pad_latch_q <= pad_latch_s;
152
 
153
    end if;
154
  end process;
155
 
156
  clk_en_s <=  clocks_per_6us_q = clocks_per_6us_g-1;
157
 
158
 
159
  fsm: process (state_q,
160
                num_buttons_read_q)
161
  begin
162
    -- default assignments
163
    pad_clk_s       <= '1';
164
    pad_latch_s     <= '1';
165
    shift_buttons_s <= false;
166
    save_buttons_o  <= false;
167
    state_s         <= IDLE;
168
 
169
    case state_q is
170
      when IDLE =>
171
        save_buttons_o <= true;
172
        state_s        <= IDLE2;
173
 
174
      when IDLE2 =>
175
        state_s <= LATCH;
176
 
177
      when LATCH =>
178
        pad_latch_s <= '0';
179
        state_s     <= READ_PAD;
180
 
181
      when READ_PAD =>
182
        pad_latch_s <= '0';
183
        -- set clock low
184
        -- pad data will be read at end of 6us cycle
185
        pad_clk_s   <= '0';
186
 
187
        shift_buttons_s <= true;
188
 
189
        if num_buttons_read_q = 0 then
190
          -- return to IDLE after last button bit has been read
191
          state_s <= IDLE;
192
        else
193
          state_s <= LATCH;
194
        end if;
195
 
196
      when others =>
197
        null;
198
 
199
    end case;
200
 
201
  end process fsm;
202
 
203
 
204
  -----------------------------------------------------------------------------
205
  -- Output Mapping
206
  -----------------------------------------------------------------------------
207
  clk_en_o        <= clk_en_s;
208
  shift_buttons_o <= shift_buttons_s;
209
  pad_clk_o       <= pad_clk_q;
210
  pad_latch_o     <= pad_latch_q;
211
 
212
end rtl;
213
 
214
 
215
-------------------------------------------------------------------------------
216
-- File History:
217
--
218
-- $Log: not supported by cvs2svn $
219
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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