蓝色天空.知识 · 实践 · 创造
我的收藏
Verilog 教程目录 36章
Verilog / LEARN BY DOING

1.4 Verilog 设计方法

阐述 Verilog 自上而下(Top-Down)的层次化设计思想,并逐阶段解析从需求分析、RTL 建模、前仿真、逻辑综合、布局布线、后仿真到 FPGA 下载与 ASIC 流片的完整流程。

学完这一章,你能够

  • 阐述 Verilog 自上而下(Top-Down)的层次化设计思想,并逐阶段解析从需求分析、RTL 建模、前仿真、逻辑综合、布局布线、后仿真到 FPGA 下载与 ASIC 流片的完整流程。

自上而下(Top-Down)的设计方法

复杂的数字集成电路系统通常采用自上而下(Top-Down)的层次化设计方法:首先明确顶层模块的总体功能与外部接口,再将其逐级拆解为若干职责清晰的子模块,持续细化直至可以直接用基本逻辑块或标准单元实现的底层叶模块。这种分而治之的架构便于将大型系统按工作量合理并行分配给多名工程师协同开发,显著缩短研发周期并降低联调风险。

Verilog 数字电路完整设计流程

标准 Verilog 硬件开发流程通常包含八个紧密衔接的阶段。首先是需求分析:团队需深入拆解用户功能要求并制定系统总体规划与技术指标(例如设计电子显示屏时,需权衡供电、工作频率、体积、成本、功耗以及采用 ASIC 还是 FPGA/CPLD 平台)。其次是功能划分:在明确需求后确定整体架构、模块切分方案以及各子模块间的数据接口与内部/外部时序协议,为并行编码打下基础。

第三阶段是文本描述(RTL 编码):开发者可使用通用代码编辑器或专用 HDL 开发环境对电路进行寄存器传输级(RTL)建模并保存为 `.v` 源文件。第四阶段是功能仿真(前仿真):对 RTL 代码进行编译并施加测试激励,专门验证电路逻辑功能是否正确;此阶段不计入物理门延迟与走线时延,专注于尽早排除逻辑缺陷。

第五阶段是逻辑综合(Synthesis):综合工具依据目标工艺的标准单元库与面积/时序约束,将高层次 Verilog 描述翻译并优化为由基本门电路构成的门级网表,在逻辑正确性、芯片面积、功耗与可测试性间取得平衡;需牢记并非全部 Verilog 语法都可综合(如 `#delay` 时延语句仅用于仿真)。第六阶段是布局布线(Place & Route):结合门级网表、约束文件与厂商单元库完成物理单元摆放与金属互连布线,生成接近真实物理结构的标准单元电路。

第七阶段是时序仿真(后仿真):将布局布线后提取的精确单元延迟与互连延迟反标到网表中,使用仿真软件检验建立/保持时间及真实时序表现;若器件特性或布线延迟引发时序违例,则需回溯修改 RTL 或约束并重复综合与布局布线迭代,直至完全收敛。第八阶段是 FPGA/CPLD 下载或 ASIC 流片生产:对可编程器件可直接生成比特流下载至开发板实测;若面向 ASIC 量产,通常也会先在 FPGA 原型板上充分验证逻辑功能后再投入芯片制造。

离线校验 Top-Down 层次树、8 阶段设计流、可综合子集与前后仿真时序差异

含完整源码 · 160 行
展开查看收起
python
"""Offline Verilog semantic verification lab for Chapter 03 (design-method)."""
import json

VERSION = "CPython 3.12.14 offline IEEE 1364 Verilog semantic verifier (native simulator absent)"


def case_top_down_hierarchy_decomposition():
    tree = {
        "display_top": ["timing_ctrl", "frame_buffer", "pixel_pipeline"],
        "timing_ctrl": ["clk_div", "sync_gen"],
        "frame_buffer": ["sram_ctrl"],
        "pixel_pipeline": ["color_lut", "gamma_corr"],
        "clk_div": [],
        "sync_gen": [],
        "sram_ctrl": [],
        "color_lut": [],
        "gamma_corr": [],
    }
    leaves = sorted(k for k, children in tree.items() if not children)
    visited = set()

    def walk(node):
        if node in visited:
            return False
        visited.add(node)
        return all(walk(ch) for ch in tree[node])

    acyclic = walk("display_top")
    expected = {
        "acyclic_dag": True,
        "total_modules": 9,
        "leaf_count": 5,
        "leaves": ["clk_div", "color_lut", "gamma_corr", "sram_ctrl", "sync_gen"],
    }
    actual = {
        "acyclic_dag": acyclic and len(visited) == len(tree),
        "total_modules": len(tree),
        "leaf_count": len(leaves),
        "leaves": leaves,
    }
    return {
        "name": "top_down_hierarchy_decomposition",
        "summary": "验证自上而下(Top-Down)模块层次分解的无环树结构与底层功能块划分",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_rtl_to_silicon_flow_stages():
    stages = [
        "requirements_analysis",
        "functional_partition",
        "rtl_verilog_coding",
        "functional_pre_simulation",
        "logic_synthesis",
        "place_and_route",
        "timing_post_simulation",
        "fpga_download_or_asic_tapeout",
    ]
    timing_fail_target = "rtl_verilog_coding"
    expected = {
        "stage_count": 8,
        "pre_sim_before_synthesis": True,
        "post_sim_after_pnr": True,
        "timing_violation_reentry": "rtl_verilog_coding",
    }
    actual = {
        "stage_count": len(stages),
        "pre_sim_before_synthesis": stages.index("functional_pre_simulation") < stages.index("logic_synthesis"),
        "post_sim_after_pnr": stages.index("timing_post_simulation") > stages.index("place_and_route"),
        "timing_violation_reentry": timing_fail_target,
    }
    return {
        "name": "rtl_to_silicon_flow_stages",
        "summary": "校验需求分析、功能划分、RTL 编写、前仿真、综合、布局布线、后仿真到下载/流片 8 阶段顺序",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_synthesizable_vs_nonsynthesizable_subset():
    constructs = {
        "assign_comb": True,
        "always_posedge_ff": True,
        "always_star_comb": True,
        "case_mux": True,
        "delay_hash_10": False,
        "initial_test_stimulus": False,
        "system_finish": False,
        "force_release_debug": False,
    }
    synth = sorted(k for k, v in constructs.items() if v)
    nonsynth = sorted(k for k, v in constructs.items() if not v)
    expected = {
        "synthesizable_count": 4,
        "nonsynthesizable_count": 4,
        "delay_is_synthesizable": False,
    }
    actual = {
        "synthesizable_count": len(synth),
        "nonsynthesizable_count": len(nonsynth),
        "delay_is_synthesizable": constructs["delay_hash_10"],
    }
    return {
        "name": "synthesizable_vs_nonsynthesizable_subset",
        "summary": "区分可综合 RTL 语句子集与不可综合的时延/仿真激励语句",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_pre_sim_vs_post_sim_timing_model():
    # Pre-sim: zero delay -> always passes functional check
    # Post-sim: T_clk must satisfy T_cq + T_comb + T_route + T_setup <= T_clk
    t_cq_ns = 1.2
    t_comb_ns = 4.5
    t_route_ns = 2.8
    t_setup_ns = 0.7
    required_period_ns = round(t_cq_ns + t_comb_ns + t_route_ns + t_setup_ns, 2)

    pre_sim_ok_at_8ns = True  # zero-delay functional sim ignores physical timing
    post_sim_ok_at_8ns = 8.0 >= required_period_ns
    post_sim_ok_at_10ns = 10.0 >= required_period_ns
    expected = {
        "required_period_ns": 9.2,
        "pre_sim_8ns_pass": True,
        "post_sim_8ns_pass": False,
        "post_sim_10ns_pass": True,
    }
    actual = {
        "required_period_ns": required_period_ns,
        "pre_sim_8ns_pass": pre_sim_ok_at_8ns,
        "post_sim_8ns_pass": post_sim_ok_at_8ns,
        "post_sim_10ns_pass": post_sim_ok_at_10ns,
    }
    return {
        "name": "pre_sim_vs_post_sim_timing_model",
        "summary": "对比零延迟功能前仿真与含单元/布线时延的时序后仿真在 8ns 与 10ns 时钟周期下的建立时间判定",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def main():
    cases = [
        case_top_down_hierarchy_decomposition(),
        case_rtl_to_silicon_flow_stages(),
        case_synthesizable_vs_nonsynthesizable_subset(),
        case_pre_sim_vs_post_sim_timing_model(),
    ]
    print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
在 CPython 3.12.14 离线脚本中验证无环 Top-Down 模块分解树、8 阶段顺序与后仿真回溯环路、可综合语句判定以及 8ns/10ns 时钟周期下前仿真通过而后仿真检出建立时间违例的模型。

查看独立实例 ↗ 在独立页面查看源码、运行环境与工程包

本地运行

解压后按 README 说明在对应本地环境运行脚本。

下载本章实验包 (mbskycom202612a2591.zip) ↓ 查看运行说明 ↗

本章附件与实例包

下载课程关联工程包:Verilog

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2591.zip

下载课程关联工程包:Verilog

课程关联工程包(登记关联36章) · 含当前章节或实例 · mbskycom202612a2580.zip

常见错误与边界检查

  • 实际端口、文档资源与应用配置都应和测试条件一致。

技术规范与官方资料

练习与参考解答

查看参考解答

前仿真不计入实际逻辑单元延迟与物理连线延迟,仅验证纯逻辑功能;布局布线后会引入真实的门级传输时延和互连线时延,若关键路径总时延超过时钟周期减去建立时间,就会发生时序违例,需要返回修改 RTL(如插入流水线)或优化约束。

SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习