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 230

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 230 diegovalve
wire [`MCU_VPMASK_LEN-1:0] wWE_SelectMask;
175
assign wWE_SelectMask = wCurrentRequest[`MCU_COPYMEMBLOCKCMD_VPMASK_RNG];
176 213 diegovalve
 
177
SELECT_1_TO_N # ( $clog2(`MAX_CORES), `MAX_CORES ) WESEL
178
 (
179 230 diegovalve
 .Sel(wWE_SelectMask[$clog2(`MAX_CORES)-1:0]),
180 213 diegovalve
 .En( ~oFifoEmpty),
181
 .O(  WE_O )
182
 );
183
 
184
 
185
reg [4:0]  rCurrentState, rNextState;
186
//Next states logic and Reset sequence
187
always @(posedge Clock )
188
  begin
189
 
190
    if (Reset )
191
                rCurrentState <= `MCU_STATE_AFTER_RESET;
192
    else
193
                rCurrentState <= rNextState;
194
 
195
end
196
 
197
 
198
 
199
always @ ( * )
200
begin
201
        case (rCurrentState)
202
        //--------------------------------------
203
        `MCU_STATE_AFTER_RESET:
204
        begin
205
                rPopFifo          = 1'b0;
206
                rIncrementAddress = 1'b0;
207
                TAG_O             = `TAG_NULL;
208
                MST_O             = 1'b0;
209
                CYC_O             = 1'b0;
210
                rResetCycCount    = 1'b1;
211
                rMEM_ReadRequest  = 1'b0;
212
                rResetStbCount    = 1'b0;
213
 
214
                rNextState = `MCU_WAIT_FOR_REQUEST;
215
        end
216
        //--------------------------------------
217
        /*
218
        Wait until a request becomes available
219
        */
220
        `MCU_WAIT_FOR_REQUEST:
221
        begin
222
           rPopFifo         = 1'b0;
223
           rIncrementAddress = 1'b0;
224
           TAG_O             = `TAG_NULL;
225
           MST_O             = 1'b0;
226
           CYC_O             = 1'b0;
227
           rResetCycCount    = 1'b1;
228
                rMEM_ReadRequest  = 1'b0;
229
                rResetStbCount    = 1'b1;
230
 
231
        if (~oFifoEmpty && wRequestType == `MCU_COPYMEMBLOCKCMD_DSTTYPE_VPCODEMEM)
232
                rNextState = `MCU_TRANSFER_BLOCK_TO_VPCODEMEM;
233
        else if (~oFifoEmpty && wRequestType == `MCU_COPYMEMBLOCKCMD_DSTTYPE_VPDATAMEM)
234
                rNextState = `MCU_TRANSFER_BLOCK_TO_VPDATAMEM;
235
        else
236
                rNextState = `MCU_WAIT_FOR_REQUEST;
237
 
238
        end
239
        //--------------------------------------
240
        //Code MEM is 64 bits
241
        `MCU_TRANSFER_BLOCK_TO_VPCODEMEM:
242
        begin
243
                rPopFifo          = 1'b0;
244
                rIncrementAddress = 1'b0;
245
                TAG_O             = `TAG_INSTRUCTION_ADDRESS_TYPE;
246
                MST_O             = 1'b1;
247
                CYC_O             = 1'b1;
248
                rResetCycCount    = 1'b0;
249
                rMEM_ReadRequest  = ~w64BisTransmitted;
250
                rResetStbCount    = 1'b0;
251
 
252
                if (w64BisTransmitted)
253
                        rNextState = `MCU_INC_TRANSFER_BLOCK_ADDR;
254
                else
255
                        rNextState = `MCU_TRANSFER_BLOCK_TO_VPCODEMEM;
256
        end
257
        //--------------------------------------
258
        `MCU_TRANSFER_BLOCK_TO_VPDATAMEM:
259
        begin
260
                rPopFifo          = 1'b0;
261
                rIncrementAddress = 1'b0;
262
                TAG_O             = `TAG_INSTRUCTION_ADDRESS_TYPE;
263
                MST_O             = 1'b1;
264
                CYC_O             = 1'b1;
265
                rResetCycCount    = 1'b0;
266
                rMEM_ReadRequest  = ~w96BisTransmitted;
267
                rResetStbCount    = 1'b0;
268
 
269
                if (w96BisTransmitted)
270
                        rNextState = `MCU_INC_TRANSFER_BLOCK_ADDR;
271
                else
272
                        rNextState = `MCU_TRANSFER_BLOCK_TO_VPDATAMEM;
273
 
274
        end
275
        //--------------------------------------
276
        `MCU_INC_TRANSFER_BLOCK_ADDR:
277
        begin
278
                rPopFifo          = wLastBlock;
279
                rIncrementAddress = ~wLastBlock;
280
                TAG_O             = `TAG_NULL;
281
                MST_O             = 1'b1;
282
                CYC_O             = 1'b0;
283
                rResetCycCount    = 1'b0;
284
                rMEM_ReadRequest  = 1'b0;
285
                rResetStbCount    = 1'b1;
286
 
287
                if (wLastBlock)
288
                        rNextState = `MCU_WAIT_FOR_REQUEST;
289
                else if (wRequestType == `MCU_COPYMEMBLOCKCMD_DSTTYPE_VPCODEMEM)
290
                        rNextState = `MCU_TRANSFER_BLOCK_TO_VPCODEMEM;
291
                else if (wRequestType == `MCU_COPYMEMBLOCKCMD_DSTTYPE_VPDATAMEM)
292
                        rNextState = `MCU_TRANSFER_BLOCK_TO_VPDATAMEM;
293
                else
294
                        rNextState = `MCU_WAIT_FOR_REQUEST; //Should never reach this!
295
        end
296
        //--------------------------------------
297
        default:
298
        begin
299
           rPopFifo          = 1'b0;
300
           rIncrementAddress = 1'b0;
301
                TAG_O             = `TAG_NULL;
302
                MST_O             = 1'b0;
303
                CYC_O             = 1'b0;
304
                rResetCycCount    = 1'b1;
305
                rMEM_ReadRequest  = 1'b0;
306
                rResetStbCount    = 1'b0;
307
 
308
           rNextState = `MCU_STATE_AFTER_RESET;
309
        end
310
        //--------------------------------------
311
        endcase
312
end
313
 
314
 
315
endmodule

powered by: WebSVN 2.1.0

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