1 |
2 |
abhiag |
//----------------------------------------------------------------------//
|
2 |
|
|
// The MIT License
|
3 |
|
|
//
|
4 |
|
|
// Copyright (c) 2010 Abhinav Agarwal, Alfred Man Cheuk Ng
|
5 |
|
|
// Contact: abhiag@gmail.com
|
6 |
|
|
//
|
7 |
|
|
// Permission is hereby granted, free of charge, to any person
|
8 |
|
|
// obtaining a copy of this software and associated documentation
|
9 |
|
|
// files (the "Software"), to deal in the Software without
|
10 |
|
|
// restriction, including without limitation the rights to use,
|
11 |
|
|
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12 |
|
|
// copies of the Software, and to permit persons to whom the
|
13 |
|
|
// Software is furnished to do so, subject to the following conditions:
|
14 |
|
|
//
|
15 |
|
|
// The above copyright notice and this permission notice shall be
|
16 |
|
|
// included in all copies or substantial portions of the Software.
|
17 |
|
|
//
|
18 |
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
|
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
|
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
|
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
|
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
|
|
// OTHER DEALINGS IN THE SOFTWARE.
|
26 |
|
|
//----------------------------------------------------------------------//
|
27 |
|
|
|
28 |
|
|
import FIFO::*;
|
29 |
|
|
import GetPut::*;
|
30 |
|
|
import GFTypes::*;
|
31 |
|
|
import mkReedSolomon::*;
|
32 |
|
|
|
33 |
|
|
import Transfer::*;
|
34 |
|
|
|
35 |
|
|
typedef enum{ ReadN, ReadT, ReadD } FPGAState deriving (Eq, Bits);
|
36 |
|
|
|
37 |
|
|
// ---------------------------------------------------------
|
38 |
|
|
// FPGA Reed-Solomon Wrapper module
|
39 |
|
|
// ---------------------------------------------------------
|
40 |
|
|
(* synthesize *)
|
41 |
|
|
module mkfuncunit (ProcSide);
|
42 |
|
|
|
43 |
|
|
Transfer transfer <- mkTransfer();
|
44 |
|
|
IReedSolomon decoder <- mkReedSolomon();
|
45 |
|
|
Reg#(FPGAState) state <- mkReg(ReadN);
|
46 |
|
|
Reg#(Byte) n <- mkReg(0);
|
47 |
|
|
|
48 |
|
|
rule readN(state == ReadN);
|
49 |
|
|
let inData <- transfer.funcSideGet.get();
|
50 |
|
|
n <= truncate(inData);
|
51 |
|
|
state <= ReadT;
|
52 |
|
|
|
53 |
|
|
$display(" [mkFPGAReedSolomon] readN n : %d", inData);
|
54 |
|
|
endrule
|
55 |
|
|
|
56 |
|
|
rule readT(state == ReadT);
|
57 |
|
|
let inData <- transfer.funcSideGet.get();
|
58 |
|
|
let t = truncate(inData);
|
59 |
|
|
let k = n - 2 * t;
|
60 |
|
|
|
61 |
|
|
decoder.rs_t_in.put(t);
|
62 |
|
|
decoder.rs_k_in.put(k);
|
63 |
|
|
state <= ReadD;
|
64 |
|
|
|
65 |
|
|
$display(" [mkFPGAReedSolomon] readT t : %d", inData);
|
66 |
|
|
endrule
|
67 |
|
|
|
68 |
|
|
rule readD(state == ReadD);
|
69 |
|
|
let inData <- transfer.funcSideGet.get();
|
70 |
|
|
decoder.rs_input.put(truncate(inData));
|
71 |
|
|
n <= n - 1;
|
72 |
|
|
if (n == 1) // last element, start to ReadN again
|
73 |
|
|
state <= ReadN;
|
74 |
|
|
|
75 |
|
|
$display(" [mkFPGAReedSolomon] readD i : %d, data in : %d", n, inData);
|
76 |
|
|
endrule
|
77 |
|
|
|
78 |
|
|
rule discardFlag(True);
|
79 |
|
|
let rs_flag <- decoder.rs_flag.get();
|
80 |
|
|
|
81 |
|
|
$display(" [mkFPGAReedSolomon] discardFlag flag : %d", rs_flag);
|
82 |
|
|
endrule
|
83 |
|
|
|
84 |
|
|
rule enqOut(True);
|
85 |
|
|
let datum <- decoder.rs_output.get();
|
86 |
|
|
transfer.funcSidePut.put(zeroExtend(datum));
|
87 |
|
|
|
88 |
|
|
$display(" [mkFPGAReedSolomon] enqOut data out : %d", datum);
|
89 |
|
|
endrule
|
90 |
|
|
|
91 |
|
|
return transfer.procSide();
|
92 |
|
|
|
93 |
|
|
endmodule
|