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

Subversion Repositories usb_fpga_2_14

[/] [usb_fpga_2_14/] [trunk/] [default/] [fpga-fx2/] [ezusb_gpio.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
/*%
2
   Common communication interface of default firmwares
3
   Copyright (C) 2009-2017 ZTEX GmbH.
4
   http://www.ztex.de
5
 
6
   Copyright and related rights are licensed under the Solderpad Hardware
7
   License, Version 0.51 (the "License"); you may not use this file except
8
   in compliance with the License. You may obtain a copy of the License at
9
 
10
       http://solderpad.org/licenses/SHL-0.51.
11
 
12
   Unless required by applicable law or agreed to in writing, software, hardware
13
   and materials distributed under this License is distributed on an "AS IS"
14
   BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15
   implied. See the License for the specific language governing permissions
16
   and limitations under the License.
17
%*/
18
/*
19
   Implements the 4 bi-directional GPIO's of the default interface.
20
 
21
   Outputs on both ends are or-ed.
22
 
23
   Remember (because it's not implemented here) default interface always
24
   contains a reset signal.
25
*/
26
 
27
 
28
// all directions are seen from FPGA
29
module ezusb_gpio (
30
        // control signals
31
        input clk,                      // system clock, minimum frequency is 24 MHz
32
        // hardware pins
33
        input gpio_clk,                 // data clock; data sent on both edges
34
        input gpio_dir,                 // 1: output, 0->1 transition latches input data and starts writing
35
        inout gpio_dat,
36
        // interface
37
        output reg [3:0] in,
38
        input [3:0] out                  // wired or: GPIO's not used for output should be 0
39
    );
40
 
41
    reg [2:0] gpio_clk_buf, gpio_dir_buf;
42
    reg [3:0] in_buf, out_reg, in_reg;
43
    reg [7:0] in_tmp;
44
    reg do_out;
45
 
46
    wire clk_edge = ( (gpio_clk_buf[0]!=gpio_clk_buf[1]) && (gpio_clk_buf[1]==gpio_clk_buf[2]) );
47
    wire dir_edge = ( (gpio_dir_buf[0]!=gpio_dir_buf[1]) && (gpio_dir_buf[1]==gpio_dir_buf[2]) );
48
 
49
    assign gpio_dat = gpio_dir ? out_reg[3] : 1'bz;
50
 
51
    always @ (posedge clk)
52
    begin
53
        gpio_clk_buf <= { gpio_clk_buf[1:0], gpio_clk };
54
        gpio_dir_buf <= { gpio_dir_buf[1:0], gpio_dir };
55
 
56
        do_out <= (do_out && gpio_dir_buf[0] && !clk_edge ) || (dir_edge && gpio_dir_buf[0]);
57
 
58
        if ( dir_edge && gpio_dir_buf[0] ) in_buf <= in_reg;
59
        if ( do_out ) out_reg <= out | in_reg;
60
 
61
        if ( clk_edge )
62
        begin
63
            if ( gpio_dir_buf[0] ) out_reg <= {out_reg[2:0], 1'b0};
64
            else in_reg <= { gpio_dat, in_reg[3:1] };
65
        end;
66
 
67
        in <= in_buf | out;
68
    end
69
endmodule

powered by: WebSVN 2.1.0

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