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

Subversion Repositories wb4pb

[/] [wb4pb/] [trunk/] [rtl/] [wbs_gpio.v] - Blame information for rev 31

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ste.fis
////////////////////////////////////////////////////////////////////////////////
2
// This sourcecode is released under BSD license.
3
// Please see http://www.opensource.org/licenses/bsd-license.php for details!
4
////////////////////////////////////////////////////////////////////////////////
5
//
6
// Copyright (c) 2010, Stefan Fischer <Ste.Fis@OpenCores.org>
7
// All rights reserved.
8
//
9
// Redistribution and use in source and binary forms, with or without 
10
// modification, are permitted provided that the following conditions are met:
11
//
12
//  * Redistributions of source code must retain the above copyright notice, 
13
//    this list of conditions and the following disclaimer.
14
//  * Redistributions in binary form must reproduce the above copyright notice,
15
//    this list of conditions and the following disclaimer in the documentation
16 31 ste.fis
//    and/or other materials provided with the distribution.
17 2 ste.fis
//
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
19
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
20
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
21
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 
22
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
23
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
24
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
25
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
26
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
27
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
28
// POSSIBILITY OF SUCH DAMAGE.
29
//
30
////////////////////////////////////////////////////////////////////////////////
31
// filename: wbs_gpio.v
32
// description: synthesizable wishbone slave general purpose i/o module
33
// todo4user: add more i/o ports as needed
34
// version: 0.0.0
35
// changelog: - 0.0.0, initial release
36
//            - ...
37
////////////////////////////////////////////////////////////////////////////////
38
 
39
 
40
module wbs_gpio (
41
  rst,
42
  clk,
43
 
44
  wbs_cyc_i,
45
  wbs_stb_i,
46
  wbs_we_i,
47
  wbs_adr_i,
48
  wbs_dat_m2s_i,
49
  wbs_dat_s2m_o,
50
  wbs_ack_o,
51
 
52
  gpio_in_i,
53
  gpio_out_o,
54
  gpio_oe_o
55
);
56
 
57
  input rst;
58
  wire  rst;
59
  input clk;
60
  wire  clk;
61
 
62
  input wbs_cyc_i;
63
  wire  wbs_cyc_i;
64
  input wbs_stb_i;
65
  wire  wbs_stb_i;
66
  input wbs_we_i;
67
  wire  wbs_we_i;
68
  input[7:0] wbs_adr_i;
69
  wire [7:0] wbs_adr_i;
70
  input[7:0] wbs_dat_m2s_i;
71
  wire [7:0] wbs_dat_m2s_i;
72
  output[7:0] wbs_dat_s2m_o;
73
  reg   [7:0] wbs_dat_s2m_o;
74
  output wbs_ack_o;
75
  reg    wbs_ack_o;
76
 
77
  input[7:0] gpio_in_i;
78
  wire [7:0] gpio_in_i;
79
  output[7:0] gpio_out_o;
80
  reg   [7:0] gpio_out_o;
81
  output[7:0] gpio_oe_o;
82
  reg   [7:0] gpio_oe_o;
83
 
84
  wire wb_reg_we;
85
 
86
  reg[7:0] gpio_in;
87
 
88
  parameter IS_INPUT = 1'b0;
89
  parameter IS_OUTPUT = ! IS_INPUT;
90
 
91
  parameter ADDR_MSB = 0;
92
  parameter[7:0] GPIO_IO_ADDR = 8'h00;
93
  parameter[7:0] GPIO_OE_ADDR = 8'h01;
94
 
95
  // internal register write enable signal
96
  assign wb_reg_we = wbs_cyc_i && wbs_stb_i && wbs_we_i;
97
 
98
  always@(posedge clk) begin
99
 
100
    gpio_in <= gpio_in_i;
101
 
102
    wbs_dat_s2m_o <= 8'h00;
103
    // registered wishbone slave handshake
104
    wbs_ack_o <= wbs_cyc_i && wbs_stb_i && (! wbs_ack_o);
105
 
106
    case(wbs_adr_i[ADDR_MSB:0])
107
      // i/o register access
108
      GPIO_IO_ADDR[ADDR_MSB:0]: begin
109
        if (wb_reg_we)
110
          gpio_out_o <= wbs_dat_m2s_i;
111
        wbs_dat_s2m_o <= gpio_in;
112
      end
113
      // output enable register access
114
      GPIO_OE_ADDR[ADDR_MSB:0]: begin
115
        if (wb_reg_we)
116
          gpio_oe_o <= wbs_dat_m2s_i;
117
        wbs_dat_s2m_o <= gpio_oe_o;
118
      end
119
      default: ;
120
    endcase
121
 
122
    if (rst) begin
123
      wbs_ack_o <= 1'b0;
124
      gpio_oe_o <= {8{IS_INPUT}};
125
    end
126
 
127
  end
128
 
129
endmodule

powered by: WebSVN 2.1.0

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