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

Subversion Repositories bluespec_md6

[/] [bluespec_md6/] [trunk/] [lib/] [bsv/] [Register/] [src/] [ControlReg.bsv] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 kfleming
import Vector::*;
2
import ActionSeq::*;
3
import FIFOF::*;
4
import FIFO::*;
5
import GetPut::*;
6
import ClientServer::*;
7
import Register::*;
8
 
9
interface ControlReg#(type addr_t, type data_t);
10
   method addr_t getAddr();
11
   method Action write(data_t x1);
12
   method ActionValue#(data_t) read();
13
endinterface
14
 
15
// function makeControlRegFromRAM(TBDRegisterMap regNum, HSTDEC_OCP_RAM_module_addr_t inc,
16
//    FIFO#(HSTDEC_OCP_RAM_module_addr_t));
17
//    begin
18
//       ControlReg#(HSTDEC_OCP_RAM_addr_t, HSTDEC_OCP_RAM_data_t) cr =
19
//       interface ControlReg
20
//       method HSTDEC_OCP_RAM_addr_t getAddr();
21
//       return zeroExtend(pack(regNum));
22
//       endmethod
23
//       method Action write(HSTDEC_OCP_RAM_data_t data);
24
//       begin
25
//          tbdRegs.hstRamAddr <= tbdRegs.hstRamAddr + inc;
26
//          (determineMemory(curTBD,tbdRegs)).writeReq.put(tuple2(truncate(tbdRegs.hstRamAddr),data));
27
//       end
28
//       endmethod
29
//       method ActionValue#(HSTDEC_OCP_RAM_data_t) read();
30
//       begin
31
//          let mem = (determineMemory(curTBD,tbdRegs));
32
//          debugModule(hstdecDebug, $display("HSTDEC Pushing read request"));
33
//          mem.readReq.put(truncate(tbdRegs.hstRamAddr));
34
//          state <= Read;
35
//          read_inc_fifo.enq(inc);
36
//          return ?;
37
//       end
38
//       endmethod
39
//       endinterface;
40
//       return cr;
41
//    end
42
 
43
//    rule complete_read;
44
//       let inc = read_inc_fifo.first; read_inc_fifo.deq;
45
//       let mem = (determineMemory(curTBD,tbdRegs));
46
//       tbdRegs.hstRamAddr <= tbdRegs.hstRamAddr + signExtend(inc);
47
//       let data <- mem.readResp().get();
48
//       resp_fifo.enq(data);
49
//    endrule
50
// endfunction
51
 
52
 
53
 
54
// function ControlReg#(addrT, dataT) mkControlReg(addrT addr,
55
//                                              function regDataT get(),
56
//                                                 function Action put(regDataT))
57
//    provisos (Bits#(regDataT, regDataSz),
58
//           Bits#(dataT, dataSz),
59
//           Add#(regDataSz,aaa,dataSz));
60
//    ControlReg#(addrT, dataT) cr =
61
//    interface ControlReg;
62
//    method addrT getAddr();
63
//       return addr;
64
//    endmethod
65
//    method Action write(dataT data);
66
//       let foo <- put(unpack(truncate(pack(data))));
67
//    endmethod
68
//    method ActionValue#(dataT) read();
69
//       let data <- get();
70
//       return unpack(zeroExtend(pack(data)));
71
//    endmethod
72
//    endinterface;
73
//    return cr;
74
// endfunction
75
 
76
 
77
 
78
function ControlReg#(addrT, dataT) mkControlRegFromReg(addrT addr,
79
                                                       Reg#(dataT) r)
80
   provisos (//Bits#(regDataT, regDataSz),
81
             Bits#(dataT, dataSz)
82
             //Add#(regDataSz,aaa,dataSz)
83
             );
84
   ControlReg#(addrT, dataT) cr =
85
   interface ControlReg;
86
   method addrT getAddr();
87
      return addr;
88
   endmethod
89
   method Action write(dataT data);
90
      r._write(data);
91
   endmethod
92
   method ActionValue#(dataT) read();
93
      let data = r._read();
94
      return data;
95
   endmethod
96
   endinterface;
97
   return cr;
98
endfunction
99
 
100
function ControlReg#(addrT, dataT) mkControlRegFromGet(addrT addr,
101
                                                       Get#(dataT) get)
102
   provisos (Bits#(dataT, dataSz));
103
   ControlReg#(addrT, dataT) cr =
104
   interface ControlReg;
105
   method addrT getAddr();
106
      return addr;
107
   endmethod
108
   method Action write(dataT data);
109
      // no write method
110
   endmethod
111
   method ActionValue#(dataT) read();
112
      let data <- get.get();
113
      return data;
114
   endmethod
115
   endinterface;
116
   return cr;
117
endfunction
118
 
119
function ControlReg#(addrT, dataT) mkControlRegFromGetPut(addrT addr,
120
                                                          Get#(dataT) get,
121
                                                          Put#(dataT) put)
122
   provisos (Bits#(dataT, dataSz));
123
   ControlReg#(addrT, dataT) cr =
124
   interface ControlReg;
125
   method addrT getAddr();
126
      return addr;
127
   endmethod
128
   method Action write(dataT data);
129
      put.put(data);
130
   endmethod
131
   method ActionValue#(dataT) read();
132
      let data <- get.get();
133
      return data;
134
   endmethod
135
   endinterface;
136
   return cr;
137
endfunction
138
 
139
function ControlReg#(addrT, dataT) mkControlRegFromServer(addrT addr,
140
                                                          Server#(dataT, dataT) server)
141
   provisos (Bits#(dataT, dataSz));
142
   ControlReg#(addrT, dataT) cr =
143
   interface ControlReg;
144
   method addrT getAddr();
145
      return addr;
146
   endmethod
147
   method Action write(dataT data);
148
      server.request.put(data);
149
   endmethod
150
   method ActionValue#(dataT) read();
151
      let data <- server.response.get();
152
      return data;
153
   endmethod
154
   endinterface;
155
   return cr;
156
endfunction
157
 
158
function Vector#(n, ControlReg#(addrT, dataT))
159
         addControlReg(Vector#(n, ControlReg#(addrT, dataT)) crvec,
160
                              regNumT regNum,
161
                              ControlReg#(addrT, dataT) cr)
162
      provisos (Bits#(regNumT, regNumSz),
163
                Bits#(addrT, addrSz),
164
                Bits#(dataT, ramDataSz),
165
                Add#(regNumSz,aaa,addrSz));
166
   crvec[zeroExtend(pack(regNum))] = cr;
167
   return crvec;
168
endfunction
169
 
170
function Vector#(n, ControlReg#(addrT, dataT))
171
         addControlRegFromReg(Vector#(n, ControlReg#(addrT, dataT)) crvec,
172
                              regNumT regNum,
173
                              Reg#(dataT) r)
174
      provisos (Bits#(regNumT, regNumSz),
175
                Bits#(addrT, addrSz),
176
                Bits#(dataT, ramDataSz),
177
                Add#(regNumSz,aaa,addrSz)
178
                );
179
   ControlReg#(addrT, dataT) cr =
180
      mkControlRegFromReg(unpack(zeroExtend(pack(regNum))), r);
181
   crvec[zeroExtend(pack(regNum))] = cr;
182
   return crvec;
183
endfunction
184
 
185
function Vector#(n, ControlReg#(addrT, dataT))
186
         addControlRegFromGet(Vector#(n, ControlReg#(addrT, dataT)) crvec,
187
                              regNumT regNum,
188
                              Get#(dataT) g)
189
      provisos (Bits#(dataT, ramDataSz),
190
                Bits#(regNumT, regNumSz),
191
                Bits#(addrT, addrSz),
192
                Add#(regNumSz,aaa,addrSz));
193
   ControlReg#(addrT, dataT) cr =
194
      mkControlRegFromGet(unpack(zeroExtend(pack(regNum))), g);
195
   crvec[zeroExtend(pack(regNum))] = cr;
196
   return crvec;
197
endfunction
198
 
199
function Vector#(n, ControlReg#(addrT, dataT))
200
         addControlRegFromGetPut(Vector#(n, ControlReg#(addrT, dataT)) crvec,
201
                                 regNumT regNum,
202
                                 Get#(dataT) g,
203
                                 Put#(dataT) p)
204
      provisos (Bits#(dataT, ramDataSz),
205
                Bits#(regNumT, regNumSz),
206
                Bits#(addrT, addrSz),
207
                Add#(regNumSz,aaa,addrSz));
208
   ControlReg#(addrT, dataT) cr =
209
      mkControlRegFromGetPut(unpack(zeroExtend(pack(regNum))), g, p);
210
   crvec[pack(regNum)] = cr;
211
   return crvec;
212
endfunction
213
 
214
function ControlReg#(addrT, dataT) widenControlReg(ControlReg#(nAddrT, nDataT) ncr)
215
   provisos (Bits#(addrT, addrSz),
216
             Bits#(dataT, dataSz),
217
             Bits#(nAddrT, nAddrSz),
218
             Bits#(nDataT, nDataSz),
219
             Add#(nDataSz,ddd,dataSz),
220
             Add#(nAddrSz,aaa,addrSz));
221
   ControlReg#(addrT, dataT) cr =
222
   interface ControlReg;
223
   method addrT getAddr();
224
      return unpack(zeroExtend(pack(ncr.getAddr())));
225
   endmethod
226
   method Action write(dataT data);
227
      ncr.write(unpack(truncate(pack(data))));
228
   endmethod
229
   method ActionValue#(dataT) read();
230
      let data <- ncr.read();
231
      return unpack(zeroExtend(pack(data)));
232
   endmethod
233
   endinterface;
234
   return cr;
235
endfunction
236
 
237
 

powered by: WebSVN 2.1.0

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