summaryrefslogtreecommitdiff
path: root/rtl/dma_axi32/dma_axi32_core0_ctrl.v
blob: 46c9a0ace62be58a5933c37c1942dfde4007e404 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/////////////////////////////////////////////////////////////////////
////                                                             ////
////  Author: Eyal Hochberg                                      ////
////          eyal@provartec.com                                 ////
////                                                             ////
////  Downloaded from: http://www.opencores.org                  ////
/////////////////////////////////////////////////////////////////////
////                                                             ////
//// Copyright (C) 2010 Provartec LTD                            ////
//// www.provartec.com                                           ////
//// info@provartec.com                                          ////
////                                                             ////
//// This source file may be used and distributed without        ////
//// restriction provided that this copyright statement is not   ////
//// removed from the file and that any derivative work contains ////
//// the original copyright notice and the associated disclaimer.////
////                                                             ////
//// This source file is free software; you can redistribute it  ////
//// and/or modify it under the terms of the GNU Lesser General  ////
//// Public License as published by the Free Software Foundation.////
////                                                             ////
//// This source is distributed in the hope that it will be      ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied  ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR     ////
//// PURPOSE.  See the GNU Lesser General Public License for more////
//// details. http://www.gnu.org/licenses/lgpl.html              ////
////                                                             ////
/////////////////////////////////////////////////////////////////////
//---------------------------------------------------------
//-- File generated by RobustVerilog parser
//-- Version: 1.0
//-- Invoked Fri Mar 25 23:34:51 2011
//--
//-- Source file: dma_core_ctrl.v
//---------------------------------------------------------



module dma_axi32_core0_ctrl(clk,reset,ch_go,cmd_full,cmd_pending,joint_req,ch_num,ch_num_resp,go_next_line,periph_clr_valid,periph_clr,periph_clr_last,periph_delay,clr_stall,tokens,ch_ready,ch_last,burst_start,finish,busy,hold);


   input                    clk;
   input             reset;

   input             ch_go;

   input             cmd_full;
   input             cmd_pending;
   input             joint_req;
      
   input [2:0]             ch_num;
   input [2:0]             ch_num_resp;   
   input             go_next_line;
   input             periph_clr_valid;
   input             periph_clr;
   input             periph_clr_last;
   input [`DELAY_BITS-1:0]  periph_delay;

   input             clr_stall;
   input [`TOKEN_BITS-1:0]  tokens;
   
   input             ch_ready;
   input             ch_last;
   output             burst_start;
   output             finish;             
   output             busy;
   input             hold;
   

   reg                 burst_start;
   reg                 finish;
   wire             tokens_remain;
   reg                 tokens_remain_reg;
   reg [`TOKEN_BITS-1:0]    tokens_counter;
   wire             stall;
   reg                 joint_ctrl_reg;
   wire             joint_ctrl;
   
   reg [`DELAY_BITS-1:0]    delay_counter;
   
   wire             periph_clr_ch;
   wire             periph_clr_last_ch;   
   wire             go_next_line_d;
   
  
   
   reg [2:0]             ps;
   reg [2:0]             ns;


   
   parameter                IDLE        = 3'd0;
   parameter             CMD         = 3'd1;
   parameter             WAIT_CLR    = 3'd2;
   parameter             WAIT_DELAY  = 3'd3;
   parameter             STALL       = 3'd4;
   

   assign             busy = ps != IDLE;

   assign             periph_clr_ch      = periph_clr_valid & periph_clr & (ch_num == ch_num_resp);
   assign             periph_clr_last_ch = periph_clr_valid & periph_clr_last & (ch_num == ch_num_resp);

   assign             go_next_line_d = 1'b0;


   always @(posedge clk or posedge reset)
     if (reset)
       joint_ctrl_reg <= #1 1'b0;
     else if (finish)
       joint_ctrl_reg <= #1 1'b0;
     else if (ch_go)
       joint_ctrl_reg <= #1 joint_req;

   assign             joint_ctrl = joint_ctrl_reg;
   
   
   
   assign             tokens_remain = (|tokens_counter) | ch_last;
   
   always @(posedge clk or posedge reset)
     if (reset)
       tokens_counter <= #1 {`TOKEN_BITS{1'b0}};
     else if (ch_go)
       tokens_counter <= #1 tokens;
     else if (burst_start & (|tokens_counter))
       tokens_counter <= #1 tokens_counter - 1'b1;
   
   always @(posedge clk or posedge reset)
     if (reset)
       delay_counter <= #1 {`DELAY_BITS{1'b0}};
     else if (periph_clr_ch)
       delay_counter <= #1 periph_delay;
     else if (|delay_counter)
       delay_counter <= #1 delay_counter - 1'b1;

   
   assign             stall  = cmd_pending | cmd_full | go_next_line_d;
  
   
   always @(/*AUTOSENSE*/ch_go or ch_last or ch_ready or clr_stall
        or delay_counter or go_next_line_d or hold or joint_ctrl
        or joint_req or periph_clr_ch or periph_clr_last_ch
        or periph_clr_valid or periph_delay or ps or stall
        or tokens_remain)
     begin
    ns          = IDLE;
    burst_start = 1'b0;
    finish  = 1'b0;
    
    case (ps)
      IDLE :
        begin
           if (ch_go)
         begin
            if (!ch_ready)
              begin
             ns = IDLE;
             finish = 1'b1;
              end
            else if (stall)
              ns = STALL;
            else
              ns = CMD;
         end
           else
         ns = IDLE;
        end
      
      CMD :
        begin
           if (joint_req ^ joint_ctrl) //change in joint_req
         begin
            ns = IDLE;
            finish = 1'b1;
         end
           else if ((clr_stall | hold) & tokens_remain)
         ns = CMD;
           else if (ch_ready & tokens_remain)
         begin
                    if (stall)
                      ns = STALL;
                    else
                      begin
                         burst_start = 1'b1;
                         ns = WAIT_CLR;
                      end  
         end
           else if (ch_last & (~ch_ready))
         ns = CMD;
           else
         begin
            ns = IDLE;
            finish = 1'b1;
         end
        end 
      
      WAIT_CLR :
        begin
           if ((|periph_delay) & periph_clr_valid) //don't wait for clr if not valid (block clr)
         begin
            if (periph_clr_last_ch) //release if load cmd
              begin
             ns = IDLE;
             finish = 1'b1;
              end
            else if (periph_clr_ch)
              ns = WAIT_DELAY;
            else
              ns = WAIT_CLR;
         end
           //memory - allow command depth
           else if (!tokens_remain)
         begin
            ns = IDLE;
            finish = 1'b1;
         end
           else
         ns = WAIT_DELAY;
        end
      
      WAIT_DELAY :
        begin
           if (go_next_line_d) //delay in case of cmd split (cross page)
         ns = WAIT_DELAY;
           else if (delay_counter == 'd0)
         ns = STALL;
           else
         ns = WAIT_DELAY;
        end

      STALL :
        begin
           if (ch_ready & tokens_remain)
         begin
            if (stall)
              ns = STALL;
            else
              ns = CMD;
         end
           else if (ch_last & (~ch_ready))
         ns = CMD;
           else
         begin
            ns = IDLE;
            finish = 1'b1;
         end 
        end

      default :
        begin
           ns = IDLE;
        end
      
    endcase
     end
   
   always @(posedge clk or posedge reset)
     if (reset)
       ps <= #1 IDLE;
     else
       ps <= #1 ns;
   

endmodule