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

Subversion Repositories bluespec_md6

[/] [bluespec_md6/] [trunk/] [MD6Control/] [fpga/] [MD6ControlEngineTest.bsv] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 kfleming
//----------------------------------------------------------------------//
2
// The MIT License
3
//
4
// Copyright (c) 2008 Kermin Fleming, kfleming@mit.edu
5
//
6
// Permission is hereby granted, free of charge, to any person
7
// obtaining a copy of this software and associated documentation
8
// files (the "Software"), to deal in the Software without
9
// restriction, including without limitation the rights to use,
10
// copy, modify, merge, publish, distribute, sublicense, and/or sell
11
// copies of the Software, and to permit persons to whom the
12
// Software is furnished to do so, subject to the following conditions:
13
//
14
// The above copyright notice and this permission notice shall be
15
// included in all copies or substantial portions of the Software.
16
//
17
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
// OTHER DEALINGS IN THE SOFTWARE.
25
//----------------------------------------------------------------------//
26 2 kfleming
/*
27
Copyright (c) 2008 MIT
28
 
29
Permission is hereby granted, free of charge, to any person
30
obtaining a copy of this software and associated documentation
31
files (the "Software"), to deal in the Software without
32
restriction, including without limitation the rights to use,
33
copy, modify, merge, publish, distribute, sublicense, and/or sell
34
copies of the Software, and to permit persons to whom the
35
Software is furnished to do so, subject to the following
36
conditions:
37
 
38
The above copyright notice and this permission notice shall be
39
included in all copies or substantial portions of the Software.
40
 
41
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
42
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
43
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
44
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
45
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
46
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
47
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
48
OTHER DEALINGS IN THE SOFTWARE.
49
 
50
Author: Kermin Fleming
51
*/
52
 
53
/****
54
 *
55
 * This module serves as the top level for the MD6 control engine.
56
 *
57
 ****/
58
 
59
// Bluespec Lib
60
import FIFO::*;
61
import GetPut::*;
62
import Vector::*;
63
import Connectable::*;
64
import StmtFSM::*;
65
import RegFile::*;
66
 
67
// CSG Lib
68
import PLBMasterWires::*;
69
import BRAMInitiatorWires::*;
70
import PLBMaster::*;
71
import BRAMFeeder::*;
72
import PLBMaster::*;
73
import PLBMasterDefaultParameters::*;
74
import PLBMasterEmulator::*;
75
import RegisterMapper::*;
76
import Register::*;
77
 
78
// Local includes
79
import MD6Control::*;
80
import MD6Parameters::*;
81
import MD6Types::*;
82
 
83
 
84
typedef Bit#(16) ControlReg;
85
 
86
 
87
 
88
typedef 16 TotalMD6ControlRegs;
89
 
90
 
91
// This might ought to be baked out into some sort of BSP
92
function  MapperRequest#(regsSize, ControlReg) mapPPCMessageToMapperRequest(PPCMessage msg)
93
  provisos (Add#(xxx, TLog#(regsSize), 15));
94
  MapperRequest#(regsSize, ControlReg) mapperRequest;
95
  mapperRequest.command = unpack(msg[31]);
96
  mapperRequest.location = truncate(msg[30:16]);
97
  mapperRequest.payload = msg[15:0];
98
  return mapperRequest;
99
endfunction
100
 
101
function PPCMessage mapMapperRequestToPPCMessage(ControlReg data);
102
  return 32'hc0000000 | zeroExtend(data);
103
endfunction
104
 
105
 
106
module mkMD6ControlEngineTest ();
107
  RegFile#(Bit#(26),BusWord) memory <- mkRegFileFullLoad("md6Input.hex");
108
  PLBMasterEmulator#(TExp#(26)) plbmaster <- mkPLBMasterEmulator(memory);
109
 
110
 
111
  MD6Control#(1,48) control <- mkMD6Control;
112
 
113
 
114
 
115
 
116
  Reg#(Bit#(32)) memPtr <- mkReg(0);
117
 
118
  RegFile#(Bit#(1), Bit#(32))  rfileSize <- mkRegFileFullLoad("inputSize.hex");
119
  RegFile#(Bit#(TLog#(MD6_c)), BusWord) rfileRes <- mkRegFileFullLoad("md6Result.hex");
120
  Reg#(Bit#(TAdd#(TLog#(MD6_c),1))) resPtr <- mkReg(0);
121
 
122
 
123
 
124
 
125
  /* create action-based registers */
126
  /* Maybe push this down? */
127
  function Action wrapStart(Bool bool);
128
    action
129
    $display("wrapStart");
130
    if(!control.running())
131
      begin
132
        $display("calling start decode");
133
        control.startDecode();
134
      end
135
    endaction
136
  endfunction
137
 
138
  Reg#(Bool) startReg = mkRegFromActions(control.running,wrapStart);
139
 
140
  // Probably build a list and map and concat would be best?
141
 
142
 
143
  let regBank = append(append(append(append(append(append(append(
144
                              explodeRegister(control.keyRegister), //32
145
                              explodeRegister(control.sourceAddress)),//2
146
                              explodeRegister(control.destinationAddress)),//2
147
                              explodeRegister(control.bufferAddress)), //2
148
                              explodeRegister(control.bitSize)),//4
149
                              explodeRegister(control.bigEndian)), // 1
150
                              explodeRegister(startReg)), //1
151
                              explodeRegister(control.digestLength)); //1
152
  RegisterMapper#(PPCMessage,
153
                  PPCMessage
154
                 ) regMapper <- mkRegisterMapper(mapPPCMessageToMapperRequest,
155
                                                 mapMapperRequestToPPCMessage,
156
                                                 regBank);
157
 
158
 
159
  // Hook up the system
160
  mkConnection(plbmaster.plbmaster.wordInput.put,control.wordOutput);
161
  mkConnection(control.wordInput,plbmaster.plbmaster.wordOutput.get);
162
  mkConnection(plbmaster.plbmaster.plbMasterCommandInput.put,control.outputCommand);
163
  // mkConnection(regMapper.registerRequest, feeder.ppcMessageOutput.get);
164
  // mkConnection(feeder.ppcMessageInput.put, regMapper.registerResponse);
165
/*
166
  mapperRequest.command = unpack(msg[31]);
167
  mapperRequest.location = truncate(msg[30:16]);
168
  mapperRequest.payload = msg[15:0];
169
  */
170
  Bit#(32) inputSize = (((rfileSize.sub(0))/fromInteger(8*valueof(MD6_b))) + 1)*fromInteger(valueof(MD6_b));
171
 
172
/******
173
 * The reg map
174
 * 0-31   key
175
 * 32-33  source ptr
176
 * 34-35  destination ptr
177
 * 36-37  buffer ptr
178
 * 38-41  bitSize
179
 * 42     endianess
180
 * 43     start/status
181
 * 44     digestLength
182
 ******/
183
 
184
 
185
 
186
  Reg#(Bit#(7)) i <- mkReg(0);
187
  Reg#(Bool) done <- mkReg(False);
188
  Bit#(64) sizeValue = zeroExtend(rfileSize.sub(0));
189
 
190
  Stmt s = seq
191
             for( i <= 0; i < 32; i <= i + 1)
192
               seq
193
                 regMapper.registerRequest({1'b1,zeroExtend(i),16'h0});
194
               endseq
195
             regMapper.registerRequest({1'b1,15'd32,0});
196
             regMapper.registerRequest({1'b1,15'd33,0});
197
             regMapper.registerRequest({1'b1,15'd34,(2*inputSize)[15:0]});
198
             regMapper.registerRequest({1'b1,15'd35,(2*inputSize)[31:16]});
199
             regMapper.registerRequest({1'b1,15'd36,(4*inputSize)[15:0]});
200
             regMapper.registerRequest({1'b1,15'd37,(4*inputSize)[31:16]});
201
             $display("InputSize: %h", sizeValue);
202
             regMapper.registerRequest({1'b1,15'd38,(sizeValue)[15:0]});
203
             regMapper.registerRequest({1'b1,15'd39,(sizeValue)[31:16]});
204
             regMapper.registerRequest({1'b1,15'd40,(sizeValue)[47:32]});
205
             regMapper.registerRequest({1'b1,15'd41,(sizeValue)[63:48]});
206
             regMapper.registerRequest({1'b1,15'd42,16'h1});
207
             regMapper.registerRequest({1'b1,15'd44,512});
208
             regMapper.registerRequest({1'b1,15'd43,16'h0});
209
             delay(100);
210
             regMapper.registerRequest({1'b0,15'd43,16'h0});
211
             while(!done)
212
               seq
213
                 regMapper.registerRequest({1'b0,15'd43,16'h0});
214
                 delay(100);
215
                 action
216
                   let value <- regMapper.registerResponse();
217
                   $display("Doness: %d",value);
218
                   done <= (value[15:0] == 0);
219
                 endaction
220
               endseq
221
             delay(100);
222
             for(resPtr <= 0;
223
                 resPtr < fromInteger(valueof(MD6_c));
224
                 resPtr <= resPtr+1)
225
             seq
226
               if(rfileRes.sub(truncate(resPtr)) != memory.sub(truncate(zeroExtend(resPtr) +  inputSize)))
227
                 seq
228
                   $display("Offset: %d rfile: %d",zeroExtend(resPtr), rfileSize.sub(0));
229
                   $display("FAILED at %d, %h != %h", inputSize+zeroExtend(resPtr),rfileRes.sub(truncate(resPtr)),memory.sub(truncate(zeroExtend(resPtr) +  inputSize)));
230
                   $finish;
231
                 endseq
232
               else
233
                 seq
234
                   $display("Match at %d", zeroExtend(resPtr) + inputSize);
235
                 endseq
236
             endseq
237
             $display("PASS");
238
             $finish;
239
           endseq;
240
 
241
  FSM fsm <- mkFSM(s);
242
 
243
 
244
  rule startFSM;
245
    fsm.start;
246
  endrule
247
 
248
 
249
endmodule

powered by: WebSVN 2.1.0

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