From a47f1f18da1d24009202df987b931eeac6449ab2 Mon Sep 17 00:00:00 2001 From: Zilog80 Date: Tue, 12 Aug 2025 23:26:28 +0200 Subject: [PATCH] more general rs_init_RS(); cf. test/cn/cf06 --- demod/mod/bch_ecc_mod.c | 35 +++++++++++++++++++++++++++++++++-- demod/mod/bch_ecc_mod.h | 5 +++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/demod/mod/bch_ecc_mod.c b/demod/mod/bch_ecc_mod.c index 812fc9e..9e598ee 100644 --- a/demod/mod/bch_ecc_mod.c +++ b/demod/mod/bch_ecc_mod.c @@ -708,7 +708,38 @@ static void prn_table(void) { INCSTAT -int rs_init_RS255(RS_t *RS) { +int rs_init_RS(RS_t *RS) { + GF_t *gf = &RS->GF; + int i, check_gen; + ui8_t Xalp[MAX_DEG+1]; + + check_gen = GF_genTab(gf); + + for (i = 0; i <= MAX_DEG; i++) RS->g[i] = 0; + for (i = 0; i <= MAX_DEG; i++) Xalp[i] = 0; + + // beta=alpha^p primitive root of g(X) + // beta^ip=alpha + for (i = 1; i < gf->ord-1; i++) { + if ( (RS->p * i) % (gf->ord-1) == 1 ) { + RS->ip = i; + break; + } + } + + // g(X)=(X-(alpha^p)^b)...(X-(alpha^p)^(b+2t-1)) + RS->g[0] = 0x01; + Xalp[1] = 0x01; // X + for (i = 0; i < 2*RS->t; i++) { + Xalp[0] = gf->exp_a[(RS->p*(RS->b+i)) % (gf->ord-1)]; // Xalp[0..1]: X - (alpha^p)^(b+i) + poly_mul(gf, RS->g, Xalp, RS->g); + } + + return check_gen; +} + +INCSTAT +int rs_init_RS255(RS_t *RS) { // RS(255, 231) GF_t *gf = &RS->GF; int i, check_gen; ui8_t Xalp[MAX_DEG+1]; @@ -732,7 +763,7 @@ int rs_init_RS255(RS_t *RS) { } INCSTAT -int rs_init_RS255ccsds(RS_t *RS) { +int rs_init_RS255ccsds(RS_t *RS) { // RS(255, 223) GF_t *gf = &RS->GF; int i, check_gen; ui8_t Xalp[MAX_DEG+1]; diff --git a/demod/mod/bch_ecc_mod.h b/demod/mod/bch_ecc_mod.h index 13d33eb..ae3e47c 100644 --- a/demod/mod/bch_ecc_mod.h +++ b/demod/mod/bch_ecc_mod.h @@ -92,8 +92,9 @@ static RS_t RS16ccsds = { 15, 2, 4, 11, 6, 1, 1, {0}, {0} }; #ifndef INCLUDESTATIC -int rs_init_RS255(RS_t *RS); -int rs_init_RS255ccsds(RS_t *RS); +int rs_init_RS(RS_t *RS); +int rs_init_RS255(RS_t *RS); // RS(255, 231) +int rs_init_RS255ccsds(RS_t *RS); // RS(255, 223) int rs_init_RS15ccsds(RS_t *RS); int rs_init_BCH64(RS_t *RS);