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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [beta_2.0/] [rtl/] [Module_MemoryController.v] - Blame information for rev 229

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

Line No. Rev Author Line
1 213 diegovalve
`timescale 1ns / 1ps
2
`include "aDefinitions.v"
3
/**********************************************************************************
4
Theia, Ray Cast Programable graphic Processing Unit.
5
Copyright (C) 2010  Diego Valverde (diego.valverde.g@gmail.com)
6
 
7
This program is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License
9
as published by the Free Software Foundation; either version 2
10
of the License, or (at your option) any later version.
11
 
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
 
21
***********************************************************************************/
22
//--------------------------------------------------------
23
 
24
`define MCU_STATE_AFTER_RESET           0
25
`define MCU_WAIT_FOR_REQUEST            1
26
`define MCU_TRANSFER_BLOCK_TO_VPCODEMEM 2
27
`define MCU_TRANSFER_BLOCK_TO_VPDATAMEM 3
28
`define MCU_INC_TRANSFER_BLOCK_ADDR     4
29
 
30
module MemoryController # (parameter CORE_COUNT=`MAX_CORES )
31
(
32
 
33
                input wire                                          Clock,
34
                input wire                                          Reset,
35
                input wire [`MCU_REQUEST_SIZE-1:0]                  iRequest,
36
 
37
                output wire                                         oMEM_ReadRequest,
38
                output wire [`WB_WIDTH-1:0]                         oMEM_ReadAddress,
39 229 diegovalve
                input wire [`WB_WIDTH-1:0]                          iMEM_ReadData,               //Data read from Main memory
40
                output wire                                         oPendingRequests,   //Connected to FIFO
41 213 diegovalve
                output wire                                         oFifoFull,
42
                output wire                                         oFifoEmpty,
43
                input wire                                          iMEM_DataAvailable,
44
                //Wishbone signals
45
                output wire [`WB_WIDTH-1:0]                         DAT_O,
46
                output wire [`WB_WIDTH-1:0]                         ADR_O,
47
                output wire                                         STB_O,
48
                output wire [CORE_COUNT-1:0]                        WE_O,
49
                output reg [1:0]                                    TAG_O,
50
                output reg                                          CYC_O,
51
                output reg                                          MST_O,
52
                input wire                                          ACK_I
53
 
54
);
55
 
56
 
57
reg                               rPopFifo;
58
wire [`MCU_REQUEST_SIZE-1:0]      wCurrentRequest;
59
wire                              wMEM_DataAvailable;
60
reg                               rIncrementAddress;
61
wire [10:0]                       wCycCount;
62
reg                               rResetCycCount;
63
reg                               rMEM_ReadRequest;
64
wire                              w64BisTransmitted,w96BisTransmitted;
65
wire                              wRequestDetected;
66
wire[2:0]                         wStbCount;
67
reg                               rResetStbCount;
68
wire                              wLastBlock;
69
wire                              wRequestType;
70
wire                              wStall;                               //If ACK is not received afte STB_O wait for ACK
71
 
72
assign DAT_O             = iMEM_ReadData;
73
assign wRequestDetected  = (iRequest[`MCU_COPYMEMBLOCKCMD_VPMASK_RNG] != 0) ? 1'b1 : 1'b0;
74
assign oMEM_ReadRequest  = rMEM_ReadRequest & ~iMEM_DataAvailable ;
75
 
76
 
77
//assign STB_O             = wMEM_DataAvailable;
78
 
79
 
80
wire wSTB_O;
81
UPCOUNTER_POSEDGE # (1) STB_O_UP
82
(
83
.Clock(      Clock                                            ),
84
.Reset(      Reset | wRequestDetected                         ),
85
.Initial(    1'b0                                             ),
86
.Enable(     wMEM_DataAvailable | ACK_I                       ),
87
.Q(          wSTB_O                                           )
88
);
89
 
90
assign STB_O =  (wSTB_O );//| wMEM_DataAvailable);// & ~ACK_I;
91
 
92
assign w64BisTransmitted = (wStbCount == 3'd2) ? 1'b1 : 1'b0;
93
assign w96BisTransmitted = (wStbCount == 3'd3) ? 1'b1 : 1'b0;
94
assign wLastBlock        = (wCycCount == wCurrentRequest[`MCU_COPYMEMBLOCKCMD_BLKLEN_RNG]) ? 1'b1 : 1'b0;
95
assign wRequestType      = wCurrentRequest[`MCU_COPYMEMBLOCK_TAG_BIT];
96
 
97
 
98
 
99
UPCOUNTER_POSEDGE # (`WB_WIDTH) OUT_MEM_ADR_UP
100
(
101
.Clock(      Clock                                            ),
102
.Reset(      Reset | wRequestDetected                         ),
103
.Initial(    iRequest[`MCU_COPYMEMBLOCKCMD_SRCOFF_RNG]        ),
104
.Enable(     ACK_I                                            ),
105
.Q(          oMEM_ReadAddress                                 )
106
);
107
 
108
 
109
//Incomming requests are stored in the FIFO
110
sync_fifo  # (`MCU_REQUEST_SIZE,`MCU_FIFO_DEPTH ) IN_FIFO
111
(
112
 .clk(    Clock              ),
113
 .reset(  Reset              ),
114
 .din(    iRequest           ),
115
 .wr_en(  wRequestDetected   ),
116
 .rd_en(  rPopFifo           ),
117
 .dout(   wCurrentRequest    ),
118
 .empty(  oFifoEmpty         ),
119
 .full(   oFifoFull          )
120
 
121
);
122
 
123
 
124
 
125
PULSE P1
126
(
127
.Clock( Clock               ),
128
.Reset( Reset               ),
129
.Enable( 1'b1               ),
130
.D(      iMEM_DataAvailable ),
131
.Q(      wMEM_DataAvailable )
132
);
133
 
134
 
135
 
136
UPCOUNTER_POSEDGE # (11) UP_CYC
137
(
138
.Clock(      Clock                                      ),
139
.Reset(      Reset | rResetCycCount                     ),
140
.Initial(     11'b1                                      ),
141
.Enable(     rIncrementAddress                          ),
142
.Q(          wCycCount                                  )
143
);
144
 
145
wire wStbPulse;
146
PULSE P2
147
(
148
.Clock( Clock               ),
149
.Reset( Reset               ),
150
.Enable( 1'b1               ),
151
.D(      STB_O              ),
152
.Q(      wStbPulse          )
153
);
154
 
155
 
156
UPCOUNTER_POSEDGE # (3) UP_STB
157
(
158
.Clock(      Clock                                      ),
159
.Reset(      Reset | rResetStbCount                     ),
160
.Initial(    3'b0                                       ),
161
.Enable(     wStbPulse                                  ),
162
.Q(          wStbCount                                  )
163
);
164
 
165
UPCOUNTER_POSEDGE # (`WB_WIDTH) UP_VPADDR
166
(
167
.Clock(      Clock                                             ),
168
.Reset(      Reset |  wRequestDetected                         ),
169
.Initial(    {12'b0,iRequest[`MCU_COPYMEMBLOCKCMD_DSTOFF_RNG]} ),
170
.Enable(     rIncrementAddress                                 ),
171
.Q(          ADR_O                                             )
172
);
173
 
174
 
175
 
176
SELECT_1_TO_N # ( $clog2(`MAX_CORES), `MAX_CORES ) WESEL
177
 (
178
 .Sel(wCurrentRequest[`MCU_COPYMEMBLOCKCMD_VPMASK_RNG]),
179
 .En( ~oFifoEmpty),
180
 .O(  WE_O )
181
 );
182
 
183
 
184
reg [4:0]  rCurrentState, rNextState;
185
//Next states logic and Reset sequence
186
always @(posedge Clock )
187
  begin
188
 
189
    if (Reset )
190
                rCurrentState <= `MCU_STATE_AFTER_RESET;
191
    else
192
                rCurrentState <= rNextState;
193
 
194
end
195
 
196
 
197
 
198
always @ ( * )
199
begin
200
        case (rCurrentState)
201
        //--------------------------------------
202
        `MCU_STATE_AFTER_RESET:
203
        begin
204
                rPopFifo          = 1'b0;
205
                rIncrementAddress = 1'b0;
206
                TAG_O             = `TAG_NULL;
207
                MST_O             = 1'b0;
208
                CYC_O             = 1'b0;
209
                rResetCycCount    = 1'b1;
210
                rMEM_ReadRequest  = 1'b0;
211
                rResetStbCount    = 1'b0;
212
 
213
                rNextState = `MCU_WAIT_FOR_REQUEST;
214
        end
215
        //--------------------------------------
216
        /*
217
        Wait until a request becomes available
218
        */
219
        `MCU_WAIT_FOR_REQUEST:
220
        begin
221
           rPopFifo         = 1'b0;
222
           rIncrementAddress = 1'b0;
223
           TAG_O             = `TAG_NULL;
224
           MST_O             = 1'b0;
225
           CYC_O             = 1'b0;
226
           rResetCycCount    = 1'b1;
227
                rMEM_ReadRequest  = 1'b0;
228
                rResetStbCount    = 1'b1;
229
 
230
        if (~oFifoEmpty && wRequestType == `MCU_COPYMEMBLOCKCMD_DSTTYPE_VPCODEMEM)
231
                rNextState = `MCU_TRANSFER_BLOCK_TO_VPCODEMEM;
232
        else if (~oFifoEmpty && wRequestType == `MCU_COPYMEMBLOCKCMD_DSTTYPE_VPDATAMEM)
233
                rNextState = `MCU_TRANSFER_BLOCK_TO_VPDATAMEM;
234
        else
235
                rNextState = `MCU_WAIT_FOR_REQUEST;
236
 
237
        end
238
        //--------------------------------------
239
        //Code MEM is 64 bits
240
        `MCU_TRANSFER_BLOCK_TO_VPCODEMEM:
241
        begin
242
                rPopFifo          = 1'b0;
243
                rIncrementAddress = 1'b0;
244
                TAG_O             = `TAG_INSTRUCTION_ADDRESS_TYPE;
245
                MST_O             = 1'b1;
246
                CYC_O             = 1'b1;
247
                rResetCycCount    = 1'b0;
248
                rMEM_ReadRequest  = ~w64BisTransmitted;
249
                rResetStbCount    = 1'b0;
250
 
251
                if (w64BisTransmitted)
252
                        rNextState = `MCU_INC_TRANSFER_BLOCK_ADDR;
253
                else
254
                        rNextState = `MCU_TRANSFER_BLOCK_TO_VPCODEMEM;
255
        end
256
        //--------------------------------------
257
        `MCU_TRANSFER_BLOCK_TO_VPDATAMEM:
258
        begin
259
                rPopFifo          = 1'b0;
260
                rIncrementAddress = 1'b0;
261
                TAG_O             = `TAG_INSTRUCTION_ADDRESS_TYPE;
262
                MST_O             = 1'b1;
263
                CYC_O             = 1'b1;
264
                rResetCycCount    = 1'b0;
265
                rMEM_ReadRequest  = ~w96BisTransmitted;
266
                rResetStbCount    = 1'b0;
267
 
268
                if (w96BisTransmitted)
269
                        rNextState = `MCU_INC_TRANSFER_BLOCK_ADDR;
270
                else
271
                        rNextState = `MCU_TRANSFER_BLOCK_TO_VPDATAMEM;
272
 
273
        end
274
        //--------------------------------------
275
        `MCU_INC_TRANSFER_BLOCK_ADDR:
276
        begin
277
                rPopFifo          = wLastBlock;
278
                rIncrementAddress = ~wLastBlock;
279
                TAG_O             = `TAG_NULL;
280
                MST_O             = 1'b1;
281
                CYC_O             = 1'b0;
282
                rResetCycCount    = 1'b0;
283
                rMEM_ReadRequest  = 1'b0;
284
                rResetStbCount    = 1'b1;
285
 
286
                if (wLastBlock)
287
                        rNextState = `MCU_WAIT_FOR_REQUEST;
288
                else if (wRequestType == `MCU_COPYMEMBLOCKCMD_DSTTYPE_VPCODEMEM)
289
                        rNextState = `MCU_TRANSFER_BLOCK_TO_VPCODEMEM;
290
                else if (wRequestType == `MCU_COPYMEMBLOCKCMD_DSTTYPE_VPDATAMEM)
291
                        rNextState = `MCU_TRANSFER_BLOCK_TO_VPDATAMEM;
292
                else
293
                        rNextState = `MCU_WAIT_FOR_REQUEST; //Should never reach this!
294
        end
295
        //--------------------------------------
296
        default:
297
        begin
298
           rPopFifo          = 1'b0;
299
           rIncrementAddress = 1'b0;
300
                TAG_O             = `TAG_NULL;
301
                MST_O             = 1'b0;
302
                CYC_O             = 1'b0;
303
                rResetCycCount    = 1'b1;
304
                rMEM_ReadRequest  = 1'b0;
305
                rResetStbCount    = 1'b0;
306
 
307
           rNextState = `MCU_STATE_AFTER_RESET;
308
        end
309
        //--------------------------------------
310
        endcase
311
end
312
 
313
 
314
endmodule

powered by: WebSVN 2.1.0

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