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

Subversion Repositories reedsolomon

[/] [reedsolomon/] [trunk/] [bluespec-source/] [ErrorMagnitude.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 FIFO::*;
29
import GFArith::*;
30
import GFTypes::*;
31
import Vector::*;
32
 
33
// ---------------------------------------------------------
34
// Reed-Solomon Error Magnitude computer interface
35
// ---------------------------------------------------------
36
interface IErrorMagnitude;
37
   method Action              k_in(Byte k_new);
38
   method Action              no_error_flag_in(Bool no_error_new);
39
   method Action              loc_in(Maybe#(Byte) loc_new);
40
   method Action              alpha_inv_in(Maybe#(Byte) alpha_inv_new);
41
   method Action              lambda_in(Syndrome#(T) lambda_new);
42
   method Action              omega_in(Syndrome#(T) omega_new);
43
 
44
   method ActionValue#(Byte)  error_out();
45
endinterface
46
 
47
// ---------------------------------------------------------
48
// Reed-Solomon Error Magnitude computer module
49
// ---------------------------------------------------------
50
(* synthesize *)
51
module mkErrorMagnitude (IErrorMagnitude);
52
 
53
   // input queues
54
   FIFO#(Byte)             k_q             <- mkSizedFIFO(1);
55
   FIFO#(Bool)             no_error_flag_q <- mkSizedFIFO(1);
56
   FIFO#(Syndrome#(T))     lambda_q        <- mkSizedFIFO(1);
57
   FIFO#(Syndrome#(T))     omega_q         <- mkSizedFIFO(1);
58
   FIFO#(Maybe#(Byte))     loc_q           <- mkSizedFIFO(valueOf(TwoT));
59
   FIFO#(Maybe#(Byte))     alpha_inv_q     <- mkSizedFIFO(valueOf(T));
60
 
61
   // output queues
62
   FIFO#(Byte)             err_q           <- mkSizedFIFO(2);
63
 
64
   // internal quques
65
   FIFO#(Byte)             int_err_q       <- mkSizedFIFO(valueOf(T));
66
 
67
   // booking state
68
   Reg#(Byte)              omega_val       <- mkReg(0);
69
   Reg#(Byte)              lambda_d_val    <- mkReg(0);
70
 
71
   Reg#(Byte)              i               <- mkReg(0);
72
   Reg#(Byte)              count           <- mkReg(0);
73
   Reg#(Byte)              block_number    <- mkReg(1);
74
 
75
   // variables
76
   Byte t = fromInteger(valueOf(T));
77
   let k = k_q.first();
78
   let no_error_flag = no_error_flag_q.first();
79
   let loc = fromMaybe(255,loc_q.first()); // next location has no error?
80
   let alpha_inv = fromMaybe(?,alpha_inv_q.first());
81
   let lambda = lambda_q.first();
82
   let omega  = omega_q.first();
83
 
84
   // -----------------------------------------------
85
   rule eval_lambda_omega (count < t && isValid(alpha_inv_q.first()));
86
      // Derivative of Lambda is done by dropping even terms and shifting odd terms by one
87
      // So count is incremented by 2
88
      // valid_t - 2 is the index used as the final term since valid_t - 1 term gets dropped
89
      Byte idx = (t - 1) - count;
90
      Byte lambda_add_val = ((count & 8'd1) == 8'd1) ? lambda[idx] : 0;
91
      lambda_d_val <= gf_add(gf_mult(lambda_d_val, alpha_inv),lambda_add_val);
92
      omega_val <= gf_mult(omega_val, alpha_inv) ^ omega[idx];
93
      count <= count + 1;
94
 
95
      $display ("  [errMag %d]  Evaluating Lambda_der count : %d, lambda_d_val[prev] : %d, lambda_add_val : %d, idx : %d",
96
                block_number, count, lambda_d_val, lambda_add_val, idx);
97
      $display ("  [errMag %d]  Evaluating Omega count : %d, omega_val[prev] : %d",
98
                block_number, count, omega_val);
99
   endrule
100
 
101
   // ------------------------------------------------
102
   rule enq_error (count == t);
103
      $display ("  [errMag %d]  Finish Evaluating Lambda Omega", block_number);
104
 
105
      let err_val = gf_mult(omega_val, gf_inv(lambda_d_val));
106
      int_err_q.enq(err_val);
107
      count <= 0;
108
      lambda_d_val <= 0;
109
      omega_val <= 0;
110
      alpha_inv_q.deq();
111
   endrule
112
 
113
   rule deq_invalid_alpha_inv (alpha_inv_q.first() matches Invalid);
114
      $display ("  [errMag %d]  Deq Invalid Alpha Inv", block_number);
115
 
116
      alpha_inv_q.deq();
117
      lambda_q.deq();
118
      omega_q.deq();
119
   endrule
120
 
121
   // ------------------------------------------------
122
   rule process_error_no_error (i < k && !no_error_flag);
123
 
124
      Byte err_val;
125
      if (i == loc)
126
         begin
127
            $display ("  [errMag %d]  Processing location %d which is in error ", block_number, i);
128
 
129
            err_val = int_err_q.first();
130
            int_err_q.deq();
131
            loc_q.deq();
132
         end
133
      else
134
         begin
135
            $display ("  [errMag %d]  process location %d which has no error ", block_number, i);
136
 
137
            err_val = 0;
138
         end
139
      err_q.enq(err_val);
140
      i <= i + 1;
141
   endrule
142
 
143
   // ------------------------------------------------
144
   rule bypass(i < k && no_error_flag);
145
      $display ("  [errMag %d]  process location %d bypass which has no error ", block_number, i);
146
 
147
      i <= k;
148
   endrule
149
 
150
   // ------------------------------------------------
151
   rule start_next_errMag (i == k);
152
      $display ("Start Next ErrMag");
153
 
154
      k_q.deq();
155
      no_error_flag_q.deq();
156
      i <= 0;
157
      block_number <= block_number + 1;
158
      if (!no_error_flag)
159
         begin
160
            loc_q.deq(); // this one should be the Invalid denomiator
161
         end
162
   endrule
163
 
164
   // ------------------------------------------------
165
   method Action k_in(Byte k_new);
166
      $display ("  [errMag %d]  k_in : %d", block_number, k_new);
167
 
168
      k_q.enq(k_new);
169
   endmethod
170
 
171
   // ------------------------------------------------
172
   method Action no_error_flag_in(Bool no_error_new);
173
      $display ("  [errMag %d]  no_error_flag_in : %d", block_number, no_error_new);
174
 
175
      no_error_flag_q.enq(no_error_new);
176
   endmethod
177
 
178
   // ------------------------------------------------
179
   method Action loc_in(Maybe#(Byte) loc_new);
180
      $display ("  [errMag %d]  loc_in : %d", block_number, loc_new);
181
 
182
      loc_q.enq(loc_new);
183
   endmethod
184
 
185
   // ------------------------------------------------
186
   method Action alpha_inv_in(Maybe#(Byte) alpha_inv_new);
187
      $display ("  [errMag %d]  alpha_inv_in : %d", block_number, alpha_inv_new);
188
 
189
      alpha_inv_q.enq(alpha_inv_new);
190
   endmethod
191
 
192
   // ------------------------------------------------
193
   method Action lambda_in(Syndrome#(T) lambda_new);
194
      $display ("  [errMag %d]  lambda_in : %d", block_number, lambda_new);
195
 
196
      lambda_q.enq(lambda_new);
197
   endmethod
198
 
199
   // ------------------------------------------------
200
   method Action omega_in(Syndrome#(T) omega_new);
201
      $display ("  [errMag %d]  w_in : %d", block_number, omega_new);
202
 
203
      omega_q.enq(omega_new);
204
   endmethod
205
 
206
   // ------------------------------------------------
207
   method ActionValue#(Byte) error_out();
208
      $display ("  [errMag %d]  err_out: %d", block_number, err_q.first());
209
      err_q.deq();
210
 
211
      return err_q.first();
212
   endmethod
213
 
214
endmodule
215
 
216
 
217
 
218
 
219
 
220
 

powered by: WebSVN 2.1.0

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