1 |
2 |
ndave |
// The MIT License
|
2 |
|
|
//
|
3 |
|
|
// Copyright (c) 2006 Nirav Dave (ndave@csail.mit.edu)
|
4 |
|
|
//
|
5 |
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
|
|
// of this software and associated documentation files (the "Software"), to deal
|
7 |
|
|
// in the Software without restriction, including without limitation the rights
|
8 |
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
|
|
// copies of the Software, and to permit persons to whom the Software is
|
10 |
|
|
// furnished to do so, subject to the following conditions:
|
11 |
|
|
//
|
12 |
|
|
// The above copyright notice and this permission notice shall be included in
|
13 |
|
|
// all copies or substantial portions of the Software.
|
14 |
|
|
//
|
15 |
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21 |
|
|
// THE SOFTWARE.
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
// *************************************************************************
|
27 |
|
|
// ConvEncoder.bsv
|
28 |
|
|
// *************************************************************************
|
29 |
|
|
import DataTypes::*;
|
30 |
|
|
import Interfaces::*;
|
31 |
|
|
|
32 |
|
|
import LibraryFunctions::*;
|
33 |
|
|
import FIFO::*;
|
34 |
|
|
|
35 |
|
|
(* synthesize *)
|
36 |
|
|
module mkConvEncoder_24_48(ConvEncoder#(24, 48));
|
37 |
|
|
let _c <- mkConvEncoder();
|
38 |
|
|
return(_c);
|
39 |
|
|
endmodule
|
40 |
|
|
|
41 |
|
|
// n has to be 24 here
|
42 |
|
|
module mkConvEncoder(ConvEncoder#(n, nn))
|
43 |
|
|
provisos
|
44 |
|
|
(Add#(n,n,nn),Add#(6,n,n6));
|
45 |
|
|
|
46 |
|
|
//-----------------------------------------
|
47 |
|
|
// State
|
48 |
|
|
//-----------------------------------------
|
49 |
|
|
|
50 |
|
|
// input queues
|
51 |
|
|
FIFO#(Header#(n)) headerQ <- mkLFIFO();
|
52 |
|
|
FIFO#(RateData#(n)) dataQ <- mkLFIFO();
|
53 |
|
|
|
54 |
|
|
// internal state
|
55 |
|
|
FIFO#(RateData#(n)) orderedQ <- mkLFIFO();
|
56 |
|
|
Reg#(Bool) getHeader <- mkReg(True);
|
57 |
|
|
Reg#(Bit#(5)) timeOut <- mkReg(24);
|
58 |
|
|
Reg#(Bit#(6)) histVal <- mkReg(0);
|
59 |
|
|
|
60 |
|
|
// output queue
|
61 |
|
|
FIFO#(RateData#(nn)) outputQ <- mkLFIFO();
|
62 |
|
|
|
63 |
|
|
//-----------------------------------------
|
64 |
|
|
// Rules
|
65 |
|
|
//-----------------------------------------
|
66 |
|
|
|
67 |
|
|
rule sort(True);
|
68 |
|
|
|
69 |
|
|
// look at heads of header and data input queues
|
70 |
|
|
Header#(n) header = headerQ.first();
|
71 |
|
|
RateData#(n) data = dataQ.first();
|
72 |
|
|
|
73 |
|
|
// if we've not started a header and the data rate is nonzero, enq a header
|
74 |
|
|
if(getHeader && data.rate != RNone)
|
75 |
|
|
begin
|
76 |
|
|
orderedQ.enq(RateData{
|
77 |
|
|
rate: R1,
|
78 |
|
|
data: header
|
79 |
|
|
});
|
80 |
|
|
headerQ.deq();
|
81 |
|
|
let ntimeOut = (timeOut - fromInteger(valueOf(n)));
|
82 |
|
|
|
83 |
|
|
timeOut <= (ntimeOut > 0) ? ntimeOut : 24; // reset
|
84 |
|
|
|
85 |
|
|
if (!(ntimeOut > 0))
|
86 |
|
|
getHeader <= False;
|
87 |
|
|
end
|
88 |
|
|
else // otherwise, enq a data
|
89 |
|
|
begin
|
90 |
|
|
if (data.rate != RNone) // newpacket
|
91 |
|
|
getHeader <= True;
|
92 |
|
|
|
93 |
|
|
dataQ.deq();
|
94 |
|
|
orderedQ.enq(data);
|
95 |
|
|
end
|
96 |
|
|
endrule
|
97 |
|
|
|
98 |
|
|
rule compute(True);
|
99 |
|
|
|
100 |
|
|
// get input out of input queues
|
101 |
|
|
Bit#(n) input_data = reverseBits((orderedQ.first).data);
|
102 |
|
|
Rate input_rate = (orderedQ.first).rate;
|
103 |
|
|
orderedQ.deq();
|
104 |
|
|
|
105 |
|
|
// if this is a new message, reset history
|
106 |
|
|
|
107 |
|
|
Bit#(n6) history;
|
108 |
|
|
|
109 |
|
|
if(input_rate == RNone) // new entry
|
110 |
|
|
history = {input_data, histVal};
|
111 |
|
|
else
|
112 |
|
|
history = {input_data, 6'b0};
|
113 |
|
|
|
114 |
|
|
// local variables
|
115 |
|
|
Bit#(nn) rev_output_data = 0;
|
116 |
|
|
Bit#(1) shared = 0;
|
117 |
|
|
Bit#(6) newHistVal = histVal;
|
118 |
|
|
|
119 |
|
|
// convolutionally encode data
|
120 |
|
|
for(Integer i = 0; i < valueOf(n); i = i + 1)
|
121 |
|
|
begin
|
122 |
|
|
shared = input_data[i] ^ history[i + 4] ^ history[i + 3] ^ history[i + 0];
|
123 |
|
|
rev_output_data[(2*i) + 0] = shared ^ history[i + 1];
|
124 |
|
|
rev_output_data[(2*i) + 1] = shared ^ history[i + 5];
|
125 |
|
|
newHistVal = {input_data[i], newHistVal[5:1]}; // only last update will be saved
|
126 |
|
|
end
|
127 |
|
|
|
128 |
|
|
// enqueue result
|
129 |
|
|
RateData#(nn) retval = RateData{
|
130 |
|
|
rate: input_rate,
|
131 |
|
|
data: reverseBits(rev_output_data)
|
132 |
|
|
};
|
133 |
|
|
outputQ.enq(retval);
|
134 |
|
|
|
135 |
|
|
// setup for next cycle
|
136 |
|
|
histVal <= newHistVal;
|
137 |
|
|
endrule
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
//-----------------------------------------
|
141 |
|
|
// Methods
|
142 |
|
|
//-----------------------------------------
|
143 |
|
|
|
144 |
|
|
// input from controller queue method
|
145 |
|
|
method Action encode_fromController(Header#(n) header);
|
146 |
|
|
headerQ.enq(header);
|
147 |
|
|
endmethod
|
148 |
|
|
|
149 |
|
|
// input from scrambler queue method
|
150 |
|
|
method Action encode_fromScrambler(RateData#(n) data);
|
151 |
|
|
dataQ.enq(data);
|
152 |
|
|
endmethod
|
153 |
|
|
|
154 |
|
|
// output to interleaver queue method
|
155 |
|
|
method ActionValue#(RateData#(nn)) getOutput();
|
156 |
|
|
outputQ.deq();
|
157 |
|
|
return(outputQ.first());
|
158 |
|
|
endmethod
|
159 |
|
|
|
160 |
|
|
endmodule
|
161 |
|
|
|