OpenCores
URL https://opencores.org/ocsvn/bluespec-80211atransmitter/bluespec-80211atransmitter/trunk

Subversion Repositories bluespec-80211atransmitter

[/] [bluespec-80211atransmitter/] [trunk/] [Interleaver.bsv] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
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
//  Scrambler.bsv
28
// *************************************************************************
29
import DataTypes::*;
30
import Interfaces::*;
31
 
32
import LibraryFunctions::*;
33
import FIFO::*;
34
import RWire::*;
35
import Vector::*;
36
 
37
interface Interleaver#(type n, type m );
38
   //inputs
39
  method Action fromEncoder(RateData#(n) txSVec);
40
 
41
   //outputs
42
  method ActionValue#(RateData#(m))       toMapper();
43
endinterface
44
 
45
(* synthesize *)
46
module mkInterleaver(Interleaver#(48, 48));
47
 
48
  Reg#(Bit#(2))                     outCnt <- mkReg(0);
49
  FIFO#(Tuple2#(Rate, Bit#(192)))     buff <- mkFIFO();
50
 
51
  match {.buff_rate, .buff_data} = buff.first();
52
 
53
  Reg#(Rate)                     cur_rate <- mkReg(RNone);
54
  Reg#(Bit#(2))                     inCnt <- mkReg(0);
55
  Reg#(Bit#(192))                    mapR <- mkReg(0);
56
 
57
  method Action fromEncoder(RateData#(48) i);
58
    //calc new value
59
    Rate this_rate = (i.rate == RNone) ? cur_rate : i.rate;
60
    Bit#(48)    in = i.data;
61
 
62
    cur_rate <=  this_rate;
63
 
64
    function Bit#(48) f1(Bit#(48) x);
65
       Vector#(16, Bit#(1)) va = bitBreak(x[47:32]),
66
                            vb = bitBreak(x[31:16]),
67
                            vc = bitBreak(x[15: 0]);
68
       function merge(a,b,c) = {a,b,c};
69
 
70
       let data_out = bitMerge(zipWith3(merge,va,vb,vc));
71
 
72
       return data_out;
73
    endfunction
74
 
75
    function Bit#(96) f2(Bit#(48) x, Bit#(48) y);
76
       Vector#(16, Bit#(3)) va = bitBreak(y),
77
                            vb = bitBreak(f1(x));
78
 
79
       function merge(a,b) = {a,b};
80
 
81
       let data_out = bitMerge(zipWith(merge,va,vb));
82
 
83
       return {data_out,0};
84
    endfunction
85
 
86
    function Bit#(192) switchBits(Bit#(192) x);
87
       Vector#(8 , Bit#(24)) va = bitBreak(x);
88
 
89
       function Bit#(24) swap(Bit#(24) b) = {b[23:10],b[8],b[9],b[7:4],b[2],b[3],b[1:0]};
90
 
91
       let out = bitMerge(map(swap,va));
92
 
93
       return out;
94
    endfunction
95
 
96
    Bit#(192) new_mapR =
97
       case (inCnt)
98
 
99
         1 : return {f2(in,mapR[47:0]),?};
100
         2 : return {mapR[191:96],?,f1(in)};
101
         3 : return switchBits({mapR[191:96],f2(in, mapR[47:0])});
102
       endcase;
103
 
104
    Bit#(2) new_inCnt = pack(tuple2(cur_rate == R4, cur_rate != R1)) & (inCnt + 1);
105
    inCnt <= new_inCnt;
106
 
107
    if (new_inCnt == 2'b00) // we're done
108
      buff.enq(tuple2(cur_rate,new_mapR));
109
    else //store
110
      mapR <= new_mapR;
111
 
112
  endmethod
113
 
114
  method ActionValue#(RateData#(48)) toMapper();
115
     Bit#(48) res = case (outCnt)
116
                       2'b00: return buff_data[191:144];
117
                       2'b01: return buff_data[143:96];
118
                       2'b10: return buff_data[95:48];
119
                       2'b11: return buff_data[47:0];
120
                    endcase;
121
     Bit#(2) new_outCnt = pack(tuple2(buff_rate == R4, buff_rate != R1)) & (outCnt + 1);
122
     outCnt <= new_outCnt;
123
 
124
     if(new_outCnt == 2'b00)
125
       buff.deq();
126
 
127
     return RateData{
128
               rate: buff_rate,
129
               data: res
130
              };
131
  endmethod
132
 
133
 
134
endmodule

powered by: WebSVN 2.1.0

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