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

Subversion Repositories reedsolomon

[/] [reedsolomon/] [trunk/] [bluespec-source/] [ErrorCorrector.bsv] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
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 GFArith::*;
29
import GFTypes::*;
30
import Vector::*;
31
import GetPut::*;
32
import FIFO::*;
33
 
34
// ---------------------------------------------------------
35
// Reed-Solomon error corrector interface
36
// ---------------------------------------------------------
37
interface IErrorCorrector;
38
   method Action              r_in (Byte datum);
39
   method Action              e_in (Byte datum);
40
   method Action              k_in (Byte k_new);
41
   method Action              no_error_flag_in (Bool no_error);
42
 
43
   method ActionValue#(Byte)  d_out ();
44
endinterface
45
 
46
// ---------------------------------------------------------
47
// Reed-Solomon error corrector module
48
// ---------------------------------------------------------
49
(* synthesize *)
50
module mkErrorCorrector (IErrorCorrector);
51
 
52
   FIFO#(Byte)      r              <- mkSizedFIFO(2);
53
   FIFO#(Byte)      e              <- mkSizedFIFO(2);
54
   FIFO#(Byte)      d              <- mkSizedFIFO(2);
55
   FIFO#(Byte)      k              <- mkSizedFIFO(1);
56
   FIFO#(Bool)      no_error_flag  <- mkSizedFIFO(1);
57
   Reg#(Byte)       e_cnt          <- mkReg(0);
58
   Reg#(Byte)       block_number   <- mkReg(0);
59
 
60
   rule d_no_error (e_cnt < k.first() && no_error_flag.first());
61
      $display ("  [error corrector %d] No Error processing", block_number);
62
      r.deq();
63
      d.enq(r.first());
64
      if (e_cnt == k.first()-1)
65
         begin
66
            block_number <= block_number + 1;
67
            k.deq();
68
            no_error_flag.deq();
69
            e_cnt <= 0;
70
         end
71
      else
72
         e_cnt <= e_cnt + 1;
73
   endrule
74
 
75
   rule d_corrected (e_cnt < k.first() && !no_error_flag.first());
76
      $display ("  [error corrector %d]  Correction processing", block_number);
77
      r.deq();
78
      e.deq();
79
      d.enq(r.first() ^ e.first());
80
      if (e_cnt == k.first()-1)
81
         begin
82
            block_number <= block_number + 1;
83
            k.deq();
84
            no_error_flag.deq();
85
            e_cnt <= 0;
86
         end
87
      else
88
         e_cnt <= e_cnt + 1;
89
   endrule
90
 
91
   // ------------------------------------------------
92
   method Action r_in (Byte datum);
93
      $display ("  [error corrector %d]  r_in : %d)", block_number, datum);
94
      r.enq(datum);
95
   endmethod
96
 
97
   // ------------------------------------------------
98
   method Action e_in (Byte datum);
99
      e.enq(datum);
100
      $display ("  [error corrector %d]  Valid e_in : %d)", block_number, datum);
101
   endmethod
102
 
103
   // ------------------------------------------------
104
   method Action k_in (Byte k_new);
105
      $display ("  [error corrector %d]  k_in : %d", block_number, k_new);
106
 
107
      k.enq(k_new);
108
   endmethod
109
 
110
   // ------------------------------------------------
111
   method Action no_error_flag_in (Bool no_error);
112
      $display ("  [error corrector %d]  no_error : %d", block_number, no_error);
113
 
114
      no_error_flag.enq(no_error);
115
   endmethod
116
 
117
   // ------------------------------------------------
118
   method ActionValue#(Byte) d_out ();
119
      $display ("  [error corrector %d]  d_out (%d)", block_number, d.first());
120
 
121
      d.deq();
122
      return d.first();
123
   endmethod
124
 
125
endmodule
126
 
127
 
128
 

powered by: WebSVN 2.1.0

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