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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [rtl/] [ex/] [fwb_counter.v] - Blame information for rev 209

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 209 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    fwb_counter.v
4
//
5
// Project:     Zip CPU -- a small, lightweight, RISC CPU soft core
6
//
7
// Purpose:
8
//
9
// Creator:     Dan Gisselquist, Ph.D.
10
//              Gisselquist Technology, LLC
11
//
12
////////////////////////////////////////////////////////////////////////////////
13
//
14
// Copyright (C) 2017-2019, Gisselquist Technology, LLC
15
//
16
// This program is free software (firmware): you can redistribute it and/or
17
// modify it under the terms of  the GNU General Public License as published
18
// by the Free Software Foundation, either version 3 of the License, or (at
19
// your option) any later version.
20
//
21
// This program is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License along
27
// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
28
// target there if the PDF file isn't present.)  If not, see
29
// <http://www.gnu.org/licenses/> for a copy.
30
//
31
// License:     GPL, v3, as defined and found on www.gnu.org,
32
//              http://www.gnu.org/licenses/gpl.html
33
//
34
//
35
////////////////////////////////////////////////////////////////////////////////
36
//
37
//
38
`default_nettype none
39
//
40
module  fwb_counter(i_clk, i_reset,
41
                // The Wishbone bus
42
                i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data, i_wb_sel,
43
                        i_wb_ack, i_wb_stall, i_wb_idata, i_wb_err,
44
                // Some convenience output parameters
45
                f_nreqs, f_nacks, f_outstanding);
46
        parameter               AW=32, DW=32;
47
        parameter               F_MAX_STALL = 0,
48
                                F_MAX_ACK_DELAY = 0;
49
        parameter               F_LGDEPTH = 4;
50
        parameter [(F_LGDEPTH-1):0] F_MAX_REQUESTS = 0;
51
        //
52
        // If true, allow the bus to be kept open when there are no outstanding
53
        // requests.  This is useful for any master that might execute a
54
        // read modify write cycle, such as an atomic add.
55
        parameter [0:0]           F_OPT_RMW_BUS_OPTION = 1;
56
        //
57
        // 
58
        // If true, allow the bus to issue multiple discontinuous requests.
59
        // Unlike F_OPT_RMW_BUS_OPTION, these requests may be issued while other
60
        // requests are outstanding
61
        parameter       [0:0]     F_OPT_DISCONTINUOUS = 0;
62
        //
63
        //
64
        // If true, insist that there be a minimum of a single clock delay
65
        // between request and response.  This defaults to off since the
66
        // wishbone specification specifically doesn't require this.  However,
67
        // some interfaces do, so we allow it as an option here.
68
        parameter       [0:0]     F_OPT_MINCLOCK_DELAY = 0;
69
        //
70
        //
71
        localparam [(F_LGDEPTH-1):0] MAX_OUTSTANDING = {(F_LGDEPTH){1'b1}};
72
        localparam      MAX_DELAY = (F_MAX_STALL > F_MAX_ACK_DELAY)
73
                                ? F_MAX_STALL : F_MAX_ACK_DELAY;
74
        localparam      DLYBITS= (MAX_DELAY < 4) ? 2
75
                                : ((MAX_DELAY <    16) ? 4
76
                                : ((MAX_DELAY <    64) ? 6
77
                                : ((MAX_DELAY <   256) ? 8
78
                                : ((MAX_DELAY <  1024) ? 10
79
                                : ((MAX_DELAY <  4096) ? 12
80
                                : ((MAX_DELAY < 16384) ? 14
81
                                : ((MAX_DELAY < 65536) ? 16
82
                                : 32)))))));
83
        //
84
        input   wire                    i_clk, i_reset;
85
        // Input/master bus
86
        input   wire                    i_wb_cyc, i_wb_stb, i_wb_we;
87
        input   wire    [(AW-1):0]       i_wb_addr;
88
        input   wire    [(DW-1):0]       i_wb_data;
89
        input   wire    [(DW/8-1):0]     i_wb_sel;
90
        //
91
        input   wire                    i_wb_ack;
92
        input   wire                    i_wb_stall;
93
        input   wire    [(DW-1):0]       i_wb_idata;
94
        input   wire                    i_wb_err;
95
        //
96
        output  reg     [(F_LGDEPTH-1):0]        f_nreqs, f_nacks;
97
        output  wire    [(F_LGDEPTH-1):0]        f_outstanding;
98
 
99
        //
100
        // Let's just make sure our parameters are set up right
101
        //
102
        always @(*)
103
                assert(F_MAX_REQUESTS < {(F_LGDEPTH){1'b1}});
104
 
105
        //
106
        //
107
        // Bus requests
108
        //
109
        //
110
 
111
        //
112
        // Count the number of requests that have been received
113
        //
114
        initial f_nreqs = 0;
115
        always @(posedge i_clk)
116
        if ((i_reset)||(!i_wb_cyc))
117
                f_nreqs <= 0;
118
        else if ((i_wb_stb)&&(!i_wb_stall))
119
                f_nreqs <= f_nreqs + 1'b1;
120
 
121
 
122
        //
123
        // Count the number of acknowledgements that have been returned
124
        //
125
        initial f_nacks = 0;
126
        always @(posedge i_clk)
127
        if (i_reset)
128
                f_nacks <= 0;
129
        else if (!i_wb_cyc)
130
                f_nacks <= 0;
131
        else if ((i_wb_ack)||(i_wb_err))
132
                f_nacks <= f_nacks + 1'b1;
133
 
134
        //
135
        // The number of outstanding requests is the difference between
136
        // the number of requests and the number of acknowledgements
137
        //
138
        assign  f_outstanding = (i_wb_cyc) ? (f_nreqs - f_nacks):0;
139
 
140
endmodule

powered by: WebSVN 2.1.0

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