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

Subversion Repositories srdydrdy_lib

[/] [srdydrdy_lib/] [trunk/] [rtl/] [verilog/] [utility/] [sd_scoreboard_fsm.v] - Blame information for rev 19

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

Line No. Rev Author Line
1 18 ghutchis
//----------------------------------------------------------------------
2
//  Scoreboard FSM
3
//
4
// Keeps track of data regarding N items.  Allows multiple entities
5
// to track data about a particular item.  Supports masked writes,
6
// allowing only part of a record to be updated by a particular
7
// transaction.
8
//
9
// If masks are enabled, 
10
//
11
// Naming convention: c = consumer, p = producer, i = internal interface
12
//----------------------------------------------------------------------
13
//  Author: Guy Hutchison
14
//
15
// This block is uncopyrighted and released into the public domain.
16
//----------------------------------------------------------------------
17
 
18
// Clocking statement for synchronous blocks.  Default is for
19
// posedge clocking and positive async reset
20
`ifndef SDLIB_CLOCKING
21
 `define SDLIB_CLOCKING posedge clk or posedge reset
22
`endif
23
 
24
// delay unit for nonblocking assigns, default is to #1
25
`ifndef SDLIB_DELAY
26
 `define SDLIB_DELAY #1
27
`endif
28
 
29
module sd_scoreboard_fsm
30
  #(parameter width=8,
31
    parameter items=64,
32
    parameter use_txid=0,
33
    parameter use_mask=0,
34
    parameter txid_sz=2,
35
    parameter asz=$clog2(items))
36
  (input      clk,
37
   input      reset,
38
 
39
   input      ip_srdy,
40
   output reg     ip_drdy,
41
   input      ip_req_type, // 0=read, 1=write
42
   input [txid_sz-1:0] ip_txid,
43
   input [width-1:0] ip_mask,
44
   input [width-1:0] ip_data,
45
   input [asz-1:0]   ip_itemid,
46
 
47
   output reg     ic_srdy,
48
   input      ic_drdy,
49
   output reg [txid_sz-1:0] ic_txid,
50
   output reg [width-1:0]   ic_data,
51
 
52
   input [width-1:0]    d_out,
53
   output reg               wr_en,
54
   output reg               rd_en,
55
   output reg [width-1:0]   d_in,
56
   output reg [asz-1:0]     addr
57
   );
58
 
59
  localparam s_idle = 0, s_read = 1, s_rdmod = 2;
60
 
61
  reg [2:0]                 state, nxt_state;
62
  reg [txid_sz-1:0]         txid, nxt_txid;
63
 
64
  always @*
65
    begin
66
      ip_drdy = 0;
67
      ic_srdy = 0;
68
      ic_data = 0;
69
      wr_en = 0;
70
      rd_en = 0;
71
      d_in = 0;
72
      addr = ip_itemid;
73
      nxt_state = state;
74
      nxt_txid  = txid;
75
      if (use_txid)
76
        ic_txid = txid;
77
      else
78
        ic_txid = 0;
79
 
80
      nxt_state[s_read] = 0;
81
 
82
      if (state[s_idle])
83
        begin
84 19 ghutchis
          if (state[s_read] & !ic_drdy)
85
            begin
86
              // output is busy, stall
87
            end
88
          else if (ip_srdy & (ip_req_type==1))
89 18 ghutchis
            begin
90
              if ((use_mask==0) | (ip_mask=={width{1'b1}}))
91
                begin
92
                  ip_drdy = 1;
93
                  wr_en   = 1;
94
                  d_in    = ip_data;
95
                end
96
              else
97
                begin
98
                  rd_en = 1;
99
                  nxt_state[s_rdmod] = 1;
100
                  nxt_state[s_idle]  = 0;
101
                end
102
            end
103 19 ghutchis
          else if (ip_srdy & (ip_req_type==0))
104 18 ghutchis
            begin
105
              rd_en = 1;
106
              nxt_state[s_read] = 1;
107
              nxt_txid  = ip_txid;
108
              ip_drdy   = 1;
109
            end
110
        end // case: s_idle
111
 
112
      if (state[s_read])
113
        begin
114
          ic_srdy = 1;
115
          ic_data = d_out;
116
          if (!ic_drdy)
117
            begin
118
              nxt_state[s_read] = 1;
119
              //nxt_state[s_idle] = 1;
120
            end
121
        end // case: state[s_read]
122
 
123
      if (state[s_rdmod])
124
        begin
125
          ip_drdy = 1;
126
          d_in = (d_out & ~ip_mask) | (ip_data & ip_mask);
127
          wr_en   = 1;
128
 
129
          nxt_state[s_rdmod] = 0;
130
          nxt_state[s_idle]  = 1;
131
        end
132
    end // always @ *
133
 
134
 
135
  always @(`SDLIB_CLOCKING)
136
    begin
137
      if (reset)
138
        begin
139
          state <= `SDLIB_DELAY 1;
140
        end
141
      else
142
        begin
143
          state <= `SDLIB_DELAY nxt_state;
144
        end
145
    end // always @ (`SDLIB_CLOCKING)
146
 
147
  generate
148
    if (use_txid != 0)
149
      begin : gen_txid_hold
150
        always @(`SDLIB_CLOCKING)
151
          begin
152
            if (reset)
153
              begin
154
                txid  <= `SDLIB_DELAY 0;
155
              end
156
            else
157
              begin
158
                txid  <= `SDLIB_DELAY nxt_txid;
159
              end
160
          end // always @ (`SDLIB_CLOCKING)
161
      end // block: gen_txid_hold
162
  endgenerate
163
 
164
endmodule // sd_scoreboard_fsm

powered by: WebSVN 2.1.0

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