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

Subversion Repositories aemb

[/] [aemb/] [trunk/] [lib/] [vpio/] [vpio_gpio.v] - Blame information for rev 202

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

Line No. Rev Author Line
1 195 sybreon
/* $Id: fasm_sparam.v,v 1.2 2008/06/05 20:55:15 sybreon Exp $
2
**
3
** VIRTUAL PERIPHERAL INPUT/OUTPUT LIBRARY
4
** Copyright (C) 2004-2009 Shawn Tan <shawn.tan@aeste.net>
5
** All rights reserved.
6
**
7
** LITE is free software: you can redistribute it and/or modify it
8
** under the terms of the GNU Lesser General Public License as
9
** published by the Free Software Foundation, either version 3 of the
10
** License, or (at your option) any later version.
11
**
12
** LITE is distributed in the hope that it will be useful, but WITHOUT
13
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
** or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
15
** Public License for more details.
16
**
17
** You should have received a copy of the GNU Lesser General Public
18
** License along with FASM. If not, see <http:**www.gnu.org/licenses/>.
19
*/
20
/*
21
 * GENERAL PURPOSE I/O
22
 */
23
 
24
module vpio_gpio (/*AUTOARG*/
25
   // Outputs
26
   wb_dat_o, wb_ack_o,
27
   // Inouts
28
   gpio_io,
29
   // Inputs
30
   wb_dat_i, wb_adr_i, wb_stb_i, wb_sel_i, wb_wre_i, wb_clk_i,
31
   wb_rst_i
32
   );
33
   parameter IO = 8;
34
 
35
   // WISHBONE SLAVE
36
   output [IO-1:0] wb_dat_o;
37
   output          wb_ack_o;
38
 
39
   input [IO-1:0]  wb_dat_i;
40
   input           wb_adr_i;
41
   input           wb_stb_i,
42
                   wb_sel_i,
43
                   wb_wre_i,
44
                   wb_clk_i,
45
                   wb_rst_i;
46
 
47
   // GPIO I/F
48
   inout [IO-1:0]  gpio_io;
49
 
50
   /*AUTOREG*/
51
   // Beginning of automatic regs (for this module's undeclared outputs)
52
   reg                  wb_ack_o;
53
   reg [IO-1:0]          wb_dat_o;
54
   // End of automatics
55
 
56
   reg [IO-1:0]  rTRIS, // Direction - 1:output, 0:input
57
                        rPORT;
58
 
59
   wire                 wb_stb = wb_stb_i & wb_sel_i;
60
   wire                 wb_wre = wb_stb_i & wb_sel_i & wb_wre_i;
61
 
62
   // WISHBONE SIDE
63
   always @(posedge wb_clk_i)
64
     if (wb_rst_i) begin
65
        /*AUTORESET*/
66
        // Beginning of autoreset for uninitialized flops
67
        rPORT <= {(1+(IO-1)){1'b0}};
68
        rTRIS <= {(1+(IO-1)){1'b0}};
69
        // End of automatics
70
     end else if (wb_wre) begin
71
        if (wb_adr_i) rPORT <= #1 wb_dat_i;
72
        if (!wb_adr_i) rTRIS <= #1 wb_dat_i;
73
     end
74
 
75
   always @(posedge wb_clk_i)
76
     if (wb_rst_i) begin
77
        /*AUTORESET*/
78
        // Beginning of autoreset for uninitialized flops
79
        wb_ack_o <= 1'h0;
80
        wb_dat_o <= {(1+(IO-1)){1'b0}};
81
        // End of automatics
82
     end else begin
83
        wb_ack_o <= #1 !wb_ack_o & wb_stb;
84
 
85
        case (wb_adr_i) // WAR
86
          1'b0: wb_dat_o <= #1 rTRIS;
87
          1'b1: wb_dat_o <= #1 rPORT;
88
        endcase // case (wb_adr_i)
89
     end // else: !if(wb_rst_i)
90
 
91
   // GPIO SIDE
92
   integer         i;
93
   reg [IO-1:0]    rGPIO;   // async latch
94
   assign gpio_io = rGPIO;
95
 
96
   always @(/*AUTOSENSE*/rPORT or rTRIS)
97
     for (i=0;i<IO;i=i+1)
98
       rGPIO[i] <= (rTRIS[i]) ? rPORT[i] : 1'bZ;
99
 
100
endmodule // vpio_gpio

powered by: WebSVN 2.1.0

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