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 18

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
          if (ip_srdy & (ip_req_type==1))
85
            begin
86
              if ((use_mask==0) | (ip_mask=={width{1'b1}}))
87
                begin
88
                  ip_drdy = 1;
89
                  wr_en   = 1;
90
                  d_in    = ip_data;
91
                end
92
              else
93
                begin
94
                  rd_en = 1;
95
                  nxt_state[s_rdmod] = 1;
96
                  nxt_state[s_idle]  = 0;
97
                end
98
            end
99
          else if (ip_srdy & (ip_req_type==0) & (!state[s_read] | ic_drdy))
100
            begin
101
              rd_en = 1;
102
              nxt_state[s_read] = 1;
103
              nxt_txid  = ip_txid;
104
              ip_drdy   = 1;
105
            end
106
        end // case: s_idle
107
 
108
      if (state[s_read])
109
        begin
110
          ic_srdy = 1;
111
          ic_data = d_out;
112
          if (!ic_drdy)
113
            begin
114
              nxt_state[s_read] = 1;
115
              //nxt_state[s_idle] = 1;
116
            end
117
        end // case: state[s_read]
118
 
119
      if (state[s_rdmod])
120
        begin
121
          ip_drdy = 1;
122
          d_in = (d_out & ~ip_mask) | (ip_data & ip_mask);
123
          wr_en   = 1;
124
 
125
          nxt_state[s_rdmod] = 0;
126
          nxt_state[s_idle]  = 1;
127
        end
128
    end // always @ *
129
 
130
 
131
  always @(`SDLIB_CLOCKING)
132
    begin
133
      if (reset)
134
        begin
135
          state <= `SDLIB_DELAY 1;
136
        end
137
      else
138
        begin
139
          state <= `SDLIB_DELAY nxt_state;
140
        end
141
    end // always @ (`SDLIB_CLOCKING)
142
 
143
  generate
144
    if (use_txid != 0)
145
      begin : gen_txid_hold
146
        always @(`SDLIB_CLOCKING)
147
          begin
148
            if (reset)
149
              begin
150
                txid  <= `SDLIB_DELAY 0;
151
              end
152
            else
153
              begin
154
                txid  <= `SDLIB_DELAY nxt_txid;
155
              end
156
          end // always @ (`SDLIB_CLOCKING)
157
      end // block: gen_txid_hold
158
  endgenerate
159
 
160
endmodule // sd_scoreboard_fsm

powered by: WebSVN 2.1.0

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