InterleaverTest.bsv
上传用户:aoptech
上传日期:2014-09-22
资源大小:784k
文件大小:3k
源码类别:

3G开发

开发平台:

Others

  1. //----------------------------------------------------------------------//
  2. // The MIT License 
  3. // 
  4. // Copyright (c) 2007 Alfred Man Cheuk Ng, mcn02@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. import Controls::*;
  27. import DataTypes::*;
  28. import FPComplex::*;
  29. import GetPut::*;
  30. import Interfaces::*;
  31. import Vector::*;
  32. import Interleaver::*;
  33. function t idFunc (t in);
  34.    return in;
  35. endfunction
  36. function Integer interleaverGetIndex(Modulation m, Integer k);
  37.     Integer s = 1;  
  38.     Integer ncbps = 192;
  39.     case (m)
  40.       BPSK:  
  41. begin
  42.    ncbps = 192;
  43.    s = 1;
  44. end
  45.       QPSK:  
  46. begin
  47.    ncbps = 384;
  48.    s = 1;
  49. end
  50.       QAM_16:
  51. begin
  52.    ncbps = 768;
  53.    s = 2;
  54. end
  55.       QAM_64:
  56. begin
  57.    ncbps = 1152;
  58.    s = 3;
  59. end
  60.     endcase // case(m)
  61.     Integer i = (ncbps/12) * (k%12) + k/12;
  62.     Integer f = (i/s);
  63.     Integer j = s*f + (i + ncbps - (12*i/ncbps))%s;
  64.     return (k >= ncbps) ? k : j;
  65. endfunction   
  66. (* synthesize *)
  67. module mkInterleaverTest(Empty);
  68.    
  69.    // state elements
  70.    Interleaver#(Modulation,24,24,192) interleaver;
  71.    interleaver <- mkInterleaver(idFunc, interleaverGetIndex);
  72.    Reg#(Bit#(4))  ctrl  <- mkReg(1);
  73.    Reg#(Bit#(24)) data  <- mkRegU;
  74.    Reg#(Bit#(8))  cntr  <- mkReg(0);
  75.    Reg#(Bit#(32)) cycle <- mkReg(0);
  76.    
  77.    rule putNewCtrl(cntr==0);
  78.       let newCtrl = (ctrl == 8) ? 1 : ctrl << 1;
  79.       let newCntr = case (unpack(newCtrl))
  80.        BPSK:   7;
  81.        QPSK:   15;
  82.        QAM_16: 31;
  83.        QAM_64: 47;
  84.     endcase;
  85.       let mesg = Mesg { control: unpack(newCtrl),
  86.             data: data};
  87.       interleaver.in.put(mesg);
  88.       ctrl <= newCtrl;
  89.       cntr <= newCntr;
  90.       data <= data + 1;
  91.       $display("input: ctrl = %d, data:%h",newCtrl,data);
  92.    endrule
  93.    
  94.    rule putInput(cntr > 0);
  95.       let mesg = Mesg { control: unpack(ctrl),
  96.             data: data};
  97.       interleaver.in.put(mesg);
  98.       cntr <= cntr - 1;
  99.       data <= data + 1;
  100.       $display("input: ctrl = %d, data:%h",ctrl,data);
  101.    endrule
  102.    rule getOutput(True);
  103.       let mesg <- interleaver.out.get;
  104.       $display("output: ctrl = %d, data: %h",mesg.control,mesg.data);
  105.    endrule
  106.    
  107.    rule tick(True);
  108.       cycle <= cycle + 1;
  109.       if (cycle == 100000)
  110.  $finish;
  111.       $display("Cycle: %d",cycle);
  112.    endrule
  113.   
  114. endmodule