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

Subversion Repositories bit_gpio

[/] [bit_gpio/] [trunk/] [sopc/] [hdl/] [gpio.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 hippo5329
//                              -*- Mode: Verilog -*-
2
// Filename        : gpio.v
3
// Description     : a bitwise gpio
4
// Author          : Thomas Chou
5
 
6
// this is a bitwise gpio to be used with i2c,spi,sdio,1 wire etc.
7
// it is unlike Altera's pio, each access is bit by bit.
8
// it is designed to work with generic gpio interface of Linux
9
// so that it will run faster and use less LEs
10
// you may turn on FAST_OUTPUT_REGISTER for the port pins to reduce LEs usage further
11
// interrupt is not supported
12
// port pin[i] can be addressed with base+(i*4)
13
// writedata[1] : output enable
14
// writedata[0] : output data
15
// readdata[0] : input data from pin
16
// paramters
17
// GPIO_WIDTH for total number of io pins (bidir + input_only), 
18
// GPIO_BIDIR for number of bidir pins.
19
// GPIO_ADDR the address width
20
// WIDTH <= 2^ADDR
21
 
22
module gpio (
23
             /*AUTOARG*/
24
   // Outputs
25
   readdata,
26
   // Inouts
27
   bidir_port,
28
   // Inputs
29
   input_port, address, clk, reset_n, write_n, writedata
30
   );
31
 
32
   parameter BIDIR_WIDTH = 8;
33
   parameter INPUT_WIDTH = 4;
34
   parameter ADDR_WIDTH = 3;
35
 
36
   inout [  BIDIR_WIDTH - 1: 0] bidir_port;
37
   input [  INPUT_WIDTH - 1: 0 ] input_port;
38
   output [  1: 0]       readdata;
39
   input [  ADDR_WIDTH - 1: 0]   address;
40
   input                clk;
41
   input                reset_n;
42
   input                write_n;
43
   input [  1: 0]        writedata;
44
 
45
   wire [ (BIDIR_WIDTH + INPUT_WIDTH) - 1: 0]      data_in;
46
   reg [  BIDIR_WIDTH - 1: 0]    bidir_port;
47
   reg [  1: 0]  readdata;
48
   reg [  BIDIR_WIDTH - 1: 0]    data_mode;
49
   reg [  BIDIR_WIDTH - 1: 0]    data_outz;
50
   reg [  BIDIR_WIDTH - 1: 0]    data_mode_v;
51
   reg [  BIDIR_WIDTH - 1: 0]    data_outz_v;
52
   integer N;
53
 
54
   assign  data_in = { input_port,bidir_port };
55
 
56
   always @(data_mode or data_outz)
57
     for (N = 0; N <= (BIDIR_WIDTH - 1) ; N = N+1)
58
       bidir_port[N] = data_mode[N]? ~data_outz[N] : 1'bz;
59
 
60
   always @(/*AS*/address or data_in)
61
     readdata = { 1'b0, data_in[address] };
62
 
63
   always @(/*AS*/BIDIR_WIDTH or address or data_outz or write_n
64
            or writedata)
65
     for (N = 0; N <= (BIDIR_WIDTH - 1) ; N = N+1)
66
       data_outz_v[N] = (~write_n & (address == N)) ? ~writedata[0] : data_outz[N];
67
 
68
   always @(/*AS*/BIDIR_WIDTH or address or data_mode or write_n
69
            or writedata)
70
     for (N = 0; N <= (BIDIR_WIDTH - 1) ; N = N+1)
71
       data_mode_v[N] = (~write_n & (address == N)) ? writedata[1] : data_mode[N];
72
 
73
   always @(posedge clk or negedge reset_n)
74
     begin
75
        if (reset_n == 0)
76
          begin
77
             data_outz <= 0;
78
             data_mode <=0;
79
          end
80
        else
81
          begin
82
             data_outz <= data_outz_v;
83
             data_mode <= data_mode_v;
84
          end
85
     end // always @ (posedge clk or negedge reset_n)
86
 
87
endmodule
88
 

powered by: WebSVN 2.1.0

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