📄 doc_ecc.lst
字号:
C51 COMPILER V7.20 DOC_ECC 02/25/2005 14:20:20 PAGE 1
C51 COMPILER V7.20, COMPILATION OF MODULE DOC_ECC
OBJECT MODULE PLACED IN DOC_ECC.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE DOC_ECC.C LARGE ROM(COMPACT)
line level source
1 /*---------------------------------------------------------------------*/
2 /* DiskOnchip 2000 & Millenium - Boot Developers Kit */
3 /*---------------------------------------------------------------------*/
4 /*
5 * $Log: V:/Flite/archives/BDK/doc_ecc.c_V $
6 *
7 * Rev 1.2 22 Dec 1999 13:26:52 dimitrys
8 * Fix Error only in Data Area (first 512 bytes)
9 *
10 * Rev 1.1 22 Dec 1999 13:24:20 dimitrys
11 * Added Copyright warning and #ifdef EDC_MODE
12 */
13 /*---------------------------------------------------------------------*/
14 /* Copyright 1999, M-Systems Flash Disk Pioneers. */
15 /* ALL RIGHTS RESERVED */
16 /* */
17 /* Permission is hereby granted to licensees of M-Systems */
18 /* products to use or abstract this computer program for the */
19 /* sole purpose of implementing a product based on M-Systems */
20 /* products. No other rights to reproduce, use or disseminate */
21 /* this computer program, whether in part or in whole, are granted. */
22 /* M-systems makes no representation or warranties with respect */
23 /* to the performance of this computer program, and specifically */
24 /* disclaims any responsibility for any damages, special or */
25 /* consequential, connected with the use of this program. */
26 /*---------------------------------------------------------------------*/
27
28 #include "doc_api.h"
29 #include "doc_def.h"
30 #include "doc_ecc.h"
31
32 #ifdef EDC_MODE
33
34 #define T 2 /* Number of recoverable errors */
35 #define SYND_LEN (T*2) /* length of syndrom vector */
36 #define K512 (((512+1)*8+6)/10) /* number of inf symbols for record
37 of 512 bytes (K512=411) */
38 #define N512 (K512 + SYND_LEN) /* code word length for record of 512 bytes */
39 #define INIT_DEG 510
40 #define MOD 1023
41
42 static short gfi(short val);
43 static short gfmul( short f, short s );
44 static short gfdiv( short f, short s );
45 static short flog(short val);
46 static short alog(short val);
47
48 /*------------------------------------------------------------------------------*/
49 /* Function Name: RTLeightToTen */
50 /* Purpose......: convert an array of five 8-bit values into an array of */
51 /* four 10-bit values, from right to left. */
52 /* Returns......: Nothing */
53 /*------------------------------------------------------------------------------*/
54 static void RTLeightToTen(char *reg8, unsigned short reg10[])
55 {
C51 COMPILER V7.20 DOC_ECC 02/25/2005 14:20:20 PAGE 2
56 1 reg10[0] = (reg8[0] & 0xFF) | ((reg8[1] & 0x03) << 8);
57 1 reg10[1] = ((reg8[1] & 0xFC) >> 2) | ((reg8[2] & 0x0F) << 6);
58 1 reg10[2] = ((reg8[2] & 0xF0) >> 4) | ((reg8[3] & 0x3F) << 4);
59 1 reg10[3] = ((reg8[3] & 0xC0) >> 6) | ((reg8[4] & 0xFF) << 2);
60 1 }
61
62 /*----------------------------------------------------------------------------*/
63 static void unpack( short word1, short length, short vector[] )
64 /* */
65 /* Function unpacks word into vector */
66 /* */
67 /* Parameters: */
68 /* word - word to be unpacked */
69 /* vector - array to be filled */
70 /* length - number of bits in word */
71
72 {
73 1 short i, *ptr;
74 1
75 1 ptr = vector + length - 1;
76 1 for( i = 0; i < length; i++ )
77 1 {
78 2 *ptr-- = word1 & 1;
79 2 word1 >>= 1;
80 2 }
81 1 }
82
83 /*----------------------------------------------------------------------------*/
84 static short pack( short *vector, short length )
85 /* */
86 /* Function packs vector into word */
87 /* */
88 /* Parameters: */
89 /* vector - array to be packed */
90 /* length - number of bits in word */
91
92 {
93 1 short tmp, i;
94 1
95 1 vector += length - 1;
96 1 tmp = 0;
97 1 i = 1;
98 1 while( length-- > 0 )
99 1 {
100 2 if( *vector-- )
101 2 tmp |= i;
102 2 i <<= 1;
103 2 }
104 1 return( tmp );
105 1 }
106
107 /*----------------------------------------------------------------------------*/
108 static short gfi( short val) /* GF inverse */
109 {
110 1 return alog((short)(MOD-flog(val)));
111 1 }
112
113 /*----------------------------------------------------------------------------*/
114 static short gfmul( short f, short s ) /* GF multiplication */
115 {
116 1 short i;
117 1 if( f==0 || s==0 )
C51 COMPILER V7.20 DOC_ECC 02/25/2005 14:20:20 PAGE 3
118 1 return 0;
119 1 else
120 1 {
121 2 i = flog(f) + flog(s);
122 2 if( i > MOD ) i -= MOD;
123 2 return( alog(i) );
124 2 }
125 1 }
126
127 /*----------------------------------------------------------------------------*/
128 static short gfdiv( short f, short s ) /* GF division */
129 {
130 1 return gfmul(f,gfi(s));
131 1 }
132
133 /*----------------------------------------------------------------------------*/
134 static void residue_to_syndrom( short reg[], short realsynd[] )
135 {
136 1 short i,l,alpha,x,s,x4;
137 1 short deg,deg4;
138 1
139 1
140 1 for(i=0,deg=INIT_DEG;i<SYND_LEN;i++,deg++)
141 1 {
142 2 s = reg[0];
143 2 alpha = x = alog(deg);
144 2 deg4 = deg+deg;
145 2 if( deg4 >= MOD ) deg4 -= MOD;
146 2 deg4 += deg4;
147 2 if( deg4 >= MOD ) deg4 -= MOD;
148 2 x4 = alog(deg4);
149 2
150 2 for(l=1;l<SYND_LEN;l++)
151 2 {
152 3 s ^= gfmul( reg[l], x );
153 3 x = gfmul( alpha, x );
154 3 }
155 2
156 2 realsynd[i] = gfdiv( s, x4 );
157 2 }
158 1 }
159
160 /*----------------------------------------------------------------------------*/
161 static short alog(short i)
162 {
163 1 short j=0, val=1;
164 1
165 1 for( ; j < i ; j++ )
166 1 {
167 2 val <<= 1 ;
168 2
169 2 if ( val > 0x3FF )
170 2 {
171 3 if ( val & 8 ) val -= (0x400+7);
172 3 else val -= (0x400-9);
173 3 }
174 2 }
175 1
176 1 return val ;
177 1 }
178
179 static short flog(short val)
C51 COMPILER V7.20 DOC_ECC 02/25/2005 14:20:20 PAGE 4
180 {
181 1 short j, val1;
182 1
183 1 if (val == 0)
184 1 return (short)0xFFFF;
185 1
186 1 j=0;
187 1 val1=1;
188 1
189 1 for( ; j <= MOD ; j++ )
190 1 {
191 2 if (val1 == val)
192 2 return j;
193 2
194 2 val1 <<= 1 ;
195 2
196 2 if ( val1 > 0x3FF )
197 2 {
198 3 if ( val1 & 8 ) val1 -= (0x400+7);
199 3 else val1 -= (0x400-9);
200 3 }
201 2
202 2 }
203 1
204 1 return 0;
205 1 }
206
207 /*----------------------------------------------------------------------------*/
208 static short convert_to_byte_patterns( short *locators, short *values,
209 short noferr, short *blocs, short *bvals )
210 {
211 1 static short mask[] = { 0x0, 0x1, 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff };
212 1
213 1 short i,j,n, n0, n1, tmp;
214 1 short n_bit, n_byte, k_bit, nb;
215 1
216 1 for( i = 0, nb = 0; i< noferr; i++)
217 1 {
218 2 n = locators[i];
219 2 tmp = values[i];
220 2 n_bit = n *10 - 6 ;
221 2 n_byte = n_bit >> 3;
222 2 k_bit = n_bit - (n_byte<<3);
223 2 n_byte++;
224 2 if( k_bit == 7 )
225 2 {
226 3 /* 3 corrupted bytes */
227 3 blocs[nb] = n_byte+1;
228 3 bvals[nb++] = tmp & 1 ? 0x80 : 0;
229 3
230 3 tmp >>= 1;
231 3 blocs[nb] = n_byte;
232 3 bvals[nb++] = tmp & 0xff;
233 3
234 3 tmp >>= 8;
235 3 bvals[nb++] = tmp & 0xff;
236 3 }
237 2 else
238 2 {
239 3 n0 = 8 - k_bit;
240 3 n1 = 10 - n0;
241 3
C51 COMPILER V7.20 DOC_ECC 02/25/2005 14:20:20 PAGE 5
242 3 blocs[nb] = n_byte;
243 3 bvals[nb++] = (tmp & mask[n1]) << (8 - n1);
244 3
245 3 tmp >>= n1;
246 3 blocs[nb] = n_byte - 1;
247 3 bvals[nb++] = (tmp & mask[n0]);
248 3 }
249 2 }
250 1
251 1 for( i = 0, j = -1; i < nb; i++ )
252 1 {
253 2 if( bvals[i] == 0 ) continue;
254 2 if( (blocs[i] == blocs[j]) && ( j>= 0 ) )
255 2 {
256 3 bvals[j] |= bvals[i];
257 3 }
258 2 else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -