Skip to content

ysheng1/bch-codec

Repository files navigation

BCH(274, 256) 全并行编解码器

特性

特性 规格
码型 BCH(274, 256),缩短码
信息位 256 bit
校验位 18 bit
纠错能力 t = 2 位
编码延迟 1 周期
解码延迟 4 周期
吞吐率 256 bits/cycle
GF 域 GF(2^9),本原多项式 x^9 + x^4 + 1

快速开始

1. 生成预计算表

python3 bch_complete.py
# 生成: bch_generated_tables_complete.sv

2. 运行 Python 测试

python3 bch_complete.py
# 输出: 所有编解码测试通过

3. 仿真 SystemVerilog

# 使用 Icarus Verilog
iverilog -g2012 -D SIMULATION -o bch_sim.vvp bch_codec_complete.sv
vvp bch_sim.vvp

项目结构

BCH/
├── bch_complete.py                  # Python 实现 + 表生成
├── bch_codec_complete.sv            # SystemVerilog 实现
├── bch_generated_tables_complete.sv # 生成的查找表
├── verify_tables.py                 # 验证脚本
├── bch_architecture.md              # 架构设计文档
├── IMPLEMENTATION_GUIDE.md          # 实现指南
├── RESULTS_SUMMARY.md               # 验证结果
└── README.md                        # 本文件

架构

编码器 (单周期)

256-bit Message
      │
      ▼
┌─────────────────┐
│  Transition     │  256×18 转移向量矩阵
│  Matrix         │  分层 XOR 树
└─────────────────┘
      │
      ▼
18-bit Parity + 256-bit Message = 274-bit Codeword

解码器 (4级流水线)

周期 阶段 操作
1 伴随式计算 S1 = r(α), S3 = r(α³)
2 关键方程求解 σ(x) = 1 + σ₁x + σ₂x²
3 Chien 搜索 求 σ(x) = 0 的根
4 纠错输出 c = r ⊕ error_loc

关键优化技术

  1. 全并行伴随式计算 - 274 输入 XOR 树
  2. 关键方程直接公式 - Peterson 算法 (t=2)
  3. Chien 搜索矩阵化 - 预计算 274 个位置的常量乘法
  4. 分层 XOR 树 - 减少关键路径延迟

验证结果

Python 测试

  • ✅ 无错情况
  • ✅ 1位错误 (所有位置)
  • ✅ 2位错误 (随机组合)
  • ✅ 随机消息测试

生成多项式

g(x) = 0x495c9
     = x^18 + x^15 + x^12 + x^11 + x^10 + x^8 + x^6 + x^3 + 1

使用示例

// 实例化编解码器
bch_codec u_codec (
    .clk             (clk),
    .rst_n           (rst_n),
    // 编码器
    .enc_valid_in    (enc_valid),
    .enc_message     (message_256b),
    .enc_valid_out   (enc_valid_out),
    .enc_codeword    (codeword_274b),
    // 解码器
    .dec_valid_in    (dec_valid),
    .dec_received    (received_274b),
    .dec_valid_out   (dec_valid_out),
    .dec_message     (decoded_message),
    .dec_error_count (error_count),
    .dec_uncorrectable(uncorrectable)
);

参考

  1. Lin & Costello, "Error Control Coding", 2nd Ed.
  2. Peterson & Weldon, "Error-Correcting Codes"

版本: 1.0.0 日期: 2024-03-03

About

BCH(274,256) Fully Parallel Error Correction Codec

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors