OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [orpsocv2/] [boards/] [actel/] [ordb1a3pe1500/] [rtl/] [verilog/] [gpio/] [gpio.v] - Blame information for rev 502

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

Line No. Rev Author Line
1 408 julius
/*
2
 *
3
 * Simple 8-bit wide GPIO module
4
 *
5
 * Can be made wider as needed, but must be done manually.
6
 *
7
 * First lot of bytes are the GPIO I/O regs
8
 * Second lot are the direction registers
9
 *
10
 * Set direction bit to '1' to output corresponding data bit.
11
 *
12
 * Register mapping:
13
 *
14
 * For 8 GPIOs we would have
15
 * adr 0: gpio data 7:0
16
 * adr 1: gpio dir 7:0
17
 *
18
 *
19
 * So for 24 GPIOs we would have
20
 * adr 0: gpio data 7:0
21
 * adr 1: gpio data 15:8
22
 * adr 2: gpio data 24:16
23
 * adr 3: gpio dir 7:0
24
 * adr 4: gpio dir 15:8
25
 * adr 5: gpio dir 24:16
26
 *
27
 * Obviously any width where width%8!=0 you must skip the remainder of the byte
28
 * before starting the dir registers.
29
 *
30
 * Backend pinout file needs to be updated for any GPIO width changes.
31
 *
32
 */
33
 
34
module gpio(
35
            wb_clk,
36
            wb_rst,
37
 
38
            wb_adr_i,
39
            wb_dat_i,
40
            wb_we_i,
41
            wb_cyc_i,
42
            wb_stb_i,
43
            wb_cti_i,
44
            wb_bte_i,
45
 
46
            wb_ack_o,
47
            wb_dat_o,
48
            wb_err_o,
49
            wb_rty_o,
50
 
51
            gpio_io);
52
 
53
 
54
   parameter gpio_io_width = 8;
55
 
56
   parameter gpio_dir_reset_val = 0;
57
   parameter gpio_o_reset_val = 0;
58
 
59
 
60
   parameter wb_dat_width = 8;
61
   parameter wb_adr_width = 3; // 8 bytes addressable
62
 
63
   input wb_clk;
64
   input wb_rst;
65
 
66
   input [wb_adr_width-1:0] wb_adr_i;
67
   input [wb_dat_width-1:0] wb_dat_i;
68
   input                    wb_we_i;
69
   input                    wb_cyc_i;
70
   input                    wb_stb_i;
71
   input [2:0]               wb_cti_i;
72
   input [1:0]               wb_bte_i;
73
   output reg [wb_dat_width-1:0] wb_dat_o; // constantly sampling gpio in bus
74
   output reg                wb_ack_o;
75
   output                    wb_err_o;
76
   output                    wb_rty_o;
77
 
78
   inout [gpio_io_width-1:0] gpio_io;
79
 
80
   // Internal registers
81
   reg [gpio_io_width-1:0]   gpio_dir;
82
 
83
   reg [gpio_io_width-1:0]   gpio_o;
84
 
85
   wire [gpio_io_width-1:0]  gpio_i;
86
 
87
   // Tristate logic for IO
88
   genvar                    i;
89
   generate
90
      for (i=0;i<gpio_io_width;i=i+1)  begin: gpio_tris
91
         assign gpio_io[i] = (gpio_dir[i]) ? gpio_o[i] : 1'bz;
92
         assign gpio_i[i] = (gpio_dir[i]) ? gpio_o[i] : gpio_io[i];
93
      end
94
   endgenerate
95
 
96
 
97
   // GPIO dir register
98
   always @(posedge wb_clk)
99
     if (wb_rst)
100
       gpio_dir <= 0; // All set to in at reset
101
     else if (wb_stb_i & wb_we_i)
102
       begin
103
          if (wb_adr_i == ((gpio_io_width/8)))
104
            gpio_dir[7:0] <= wb_dat_i;
105
/*
106
          if (wb_adr_i == ((gpio_io_width/8)+1))
107
            gpio_dir[15:8] <= wb_dat_i;
108
          if (wb_adr_i == ((gpio_io_width/8)+2))
109
            //gpio_dir[23:16] <= wb_dat_i;
110
            gpio_dir[21:16] <= wb_dat_i[5:0];
111
 */
112
          /* Add appropriate address detection here for wider GPIO */
113
 
114
       end
115
 
116
 
117
   // GPIO data out register
118
   always @(posedge wb_clk)
119
     if (wb_rst)
120
       gpio_o <= 0; // All set to in at reset
121
     else if (wb_stb_i & wb_we_i)
122
       begin
123
          if (wb_adr_i == 0)
124
            gpio_o[7:0] <= wb_dat_i;
125
/*
126
          if (wb_adr_i == 1)
127
            gpio_o[15:8] <= wb_dat_i;
128
          if (wb_adr_i == 2)
129
            gpio_o[23:16] <= wb_dat_i;
130
 */
131
          /* Add appropriate address detection here for wider GPIO */
132
       end
133
 
134
 
135
   // Register the gpio in signal
136
   always @(posedge wb_clk)
137
     begin
138
        // Data regs
139
        if (wb_adr_i == 0)
140
          wb_dat_o[7:0] <= gpio_i[7:0];
141
/*
142
        if (wb_adr_i == 1)
143
          wb_dat_o[7:0] <= gpio_i[15:8];
144
        if (wb_adr_i == 2)
145
          wb_dat_o[7:0] <= gpio_i[23:16];
146
*/
147
        /* Add appropriate address detection here for wider GPIO */
148
        // Direction regs
149
        if (wb_adr_i == 1)
150
          wb_dat_o[7:0] <= gpio_dir[7:0];
151
/*
152
        if (wb_adr_i == 4)
153
          wb_dat_o[7:0] <= gpio_dir[15:8];
154
        if (wb_adr_i == 5)
155
          wb_dat_o[7:0] <= gpio_dir[23:16];
156
*/
157
        /* Add appropriate address detection here for wider GPIO */
158
 
159
     end
160
 
161
 
162
   // Ack generation
163
   always @(posedge wb_clk)
164
     if (wb_rst)
165
       wb_ack_o <= 0;
166
     else if (wb_ack_o)
167
       wb_ack_o <= 0;
168
     else if (wb_stb_i & !wb_ack_o)
169
       wb_ack_o <= 1;
170
 
171
   assign wb_err_o = 0;
172
   assign wb_rty_o = 0;
173
 
174
 
175
endmodule // gpio

powered by: WebSVN 2.1.0

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