2 * Copyright (C) 2015 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <sys/types.h>
30 #define FEC_RSN (FEC_RSM - FEC_ROOTS)
31 #define FEC_PARAMS(roots) \
32 8, 0x11d, 0, 1, (roots), 0
36 uint8_t data[FEC_RSM];
37 uint8_t dupl[FEC_RSM];
38 uint8_t corr[FEC_RSM];
39 int i, rc, neras, errors;
40 int erasures[FEC_RSM];
43 memset(data, 0x00, sizeof(data));
44 memset(corr, 0x00, sizeof(corr));
46 rs = init_rs_char(FEC_PARAMS(FEC_ROOTS));
49 perror("init_rs_char");
53 encode_rs_char(rs, data, &corr[FEC_RSN]);
55 for (neras = 1; neras <= FEC_ROOTS; ++neras) {
56 printf("%d errors\n", neras);
58 for (i = 0; i < neras; ++i) {
63 memcpy(dupl, corr, sizeof(corr));
65 rc = decode_rs_char(rs, corr, NULL, 0);
67 printf("\tno erasures: %d\n", rc);
70 for (i = 0; i < FEC_RSN; ++i) {
71 if (corr[i] != 0x00) {
72 printf("\t\terror at %d (%02x)\n", i, corr[i]);
76 printf("\t\t%d errors in output\n", errors);
78 rc = decode_rs_char(rs, dupl, erasures, neras);
80 printf("\terasures: %d\n", rc);
83 for (i = 0; i < FEC_RSN; ++i) {
84 if (dupl[i] != 0x00) {
85 printf("\t\terror at %d (%02x)\n", i, dupl[i]);
89 printf("\t\t%d errors in output\n", errors);