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

Subversion Repositories wb4pb

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

Go to most recent revision | 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
//    and/or other materials provided with the distribution. 
17
//  * Neither the name of the author nor the names of his contributors may be 
18
//    used to endorse or promote products derived from this software without 
19
//    specific prior written permission.
20
//
21
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
22
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
23
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
24
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 
25
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
26
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
27
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
28
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
29
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
30
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
31
// POSSIBILITY OF SUCH DAMAGE.
32
//
33
////////////////////////////////////////////////////////////////////////////////
34
// filename: wbs_gpio.v
35
// description: synthesizable wishbone slave general purpose i/o module
36
// todo4user: add more i/o ports as needed
37
// version: 0.0.0
38
// changelog: - 0.0.0, initial release
39
//            - ...
40
////////////////////////////////////////////////////////////////////////////////
41
 
42
 
43
module wbs_gpio (
44
  rst,
45
  clk,
46
 
47
  wbs_cyc_i,
48
  wbs_stb_i,
49
  wbs_we_i,
50
  wbs_adr_i,
51
  wbs_dat_m2s_i,
52
  wbs_dat_s2m_o,
53
  wbs_ack_o,
54
 
55
  gpio_in_i,
56
  gpio_out_o,
57
  gpio_oe_o
58
);
59
 
60
  input rst;
61
  wire  rst;
62
  input clk;
63
  wire  clk;
64
 
65
  input wbs_cyc_i;
66
  wire  wbs_cyc_i;
67
  input wbs_stb_i;
68
  wire  wbs_stb_i;
69
  input wbs_we_i;
70
  wire  wbs_we_i;
71
  input[7:0] wbs_adr_i;
72
  wire [7:0] wbs_adr_i;
73
  input[7:0] wbs_dat_m2s_i;
74
  wire [7:0] wbs_dat_m2s_i;
75
  output[7:0] wbs_dat_s2m_o;
76
  reg   [7:0] wbs_dat_s2m_o;
77
  output wbs_ack_o;
78
  reg    wbs_ack_o;
79
 
80
  input[7:0] gpio_in_i;
81
  wire [7:0] gpio_in_i;
82
  output[7:0] gpio_out_o;
83
  reg   [7:0] gpio_out_o;
84
  output[7:0] gpio_oe_o;
85
  reg   [7:0] gpio_oe_o;
86
 
87
  wire wb_reg_we;
88
 
89
  reg[7:0] gpio_in;
90
 
91
  parameter IS_INPUT = 1'b0;
92
  parameter IS_OUTPUT = ! IS_INPUT;
93
 
94
  parameter ADDR_MSB = 0;
95
  parameter[7:0] GPIO_IO_ADDR = 8'h00;
96
  parameter[7:0] GPIO_OE_ADDR = 8'h01;
97
 
98
  // internal register write enable signal
99
  assign wb_reg_we = wbs_cyc_i && wbs_stb_i && wbs_we_i;
100
 
101
  always@(posedge clk) begin
102
 
103
    gpio_in <= gpio_in_i;
104
 
105
    wbs_dat_s2m_o <= 8'h00;
106
    // registered wishbone slave handshake
107
    wbs_ack_o <= wbs_cyc_i && wbs_stb_i && (! wbs_ack_o);
108
 
109
    case(wbs_adr_i[ADDR_MSB:0])
110
      // i/o register access
111
      GPIO_IO_ADDR[ADDR_MSB:0]: begin
112
        if (wb_reg_we)
113
          gpio_out_o <= wbs_dat_m2s_i;
114
        wbs_dat_s2m_o <= gpio_in;
115
      end
116
      // output enable register access
117
      GPIO_OE_ADDR[ADDR_MSB:0]: begin
118
        if (wb_reg_we)
119
          gpio_oe_o <= wbs_dat_m2s_i;
120
        wbs_dat_s2m_o <= gpio_oe_o;
121
      end
122
      default: ;
123
    endcase
124
 
125
    if (rst) begin
126
      wbs_ack_o <= 1'b0;
127
      gpio_oe_o <= {8{IS_INPUT}};
128
    end
129
 
130
  end
131
 
132
endmodule

powered by: WebSVN 2.1.0

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