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

Subversion Repositories sv_dir_tb

[/] [sv_dir_tb/] [trunk/] [examples/] [internal/] [sv/] [gpio_mod.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sckoarn
 
2
module gpio_mod (
3
  clk,   // input clock
4
  rst_n,
5
  addr,  // address
6
  datai,  // data in
7
  datao,  // data out
8
  w_n,   // Write  not
9
  sel,   // select input
10
  io_o,  // gpio  out
11
  io_i   // gpio  in
12
);
13
 
14
 
15
input         rst_n;
16
input         clk;
17
input         sel;
18
input  [31:0] addr;
19
input  [31:0] datai;
20
output [31:0] datao;
21
input         w_n;
22
input  [31:0] io_i;
23
output [31:0] io_o;
24
 
25
reg [31:0] io_mode; //  1 = output
26
reg [31:0] tdatao;
27
reg [31:0] tio_o;
28
 
29
assign datao = tdatao;
30
assign io_o  = tio_o & io_mode;
31
 
32
always @(posedge clk) begin
33
  if(rst_n == 0) begin
34
    tio_o   <= 32'h00000000;
35
    io_mode <= 32'h00000000;
36
 
37
  end else if (w_n == 1 && sel == 1'b1) begin
38
    if (addr[3:0] > 4'h0) begin
39
      tdatao <= io_i & ~io_mode;
40
    end else begin
41
      tdatao <= io_mode;
42
    end
43
  end else if (w_n == 0 && sel == 1'b1) begin
44
    if (addr[3:0] > 4'h0) begin
45
      tio_o <= datai;
46
    end else begin
47
      io_mode <= datai;
48
    end
49
  end else if (sel == 1'b0) begin
50
    tdatao <= 32'hzzzzzzzz;
51
  end
52
end
53
 
54
 
55
endmodule

powered by: WebSVN 2.1.0

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