• 【yosys】基础的综合操作(更新中)



    https://github.com/YosysHQ/yosys/tree/dca8fb54aa625f1600e2ccb16f9763c6abfa798f
    https://yosyshq.net/yosys/

    Yosys 输入: RTL code ,输出:Netlist

    module counter (clk, rst, en, count);  // counter.v 作为例子
    
       input clk, rst, en;
       output reg [1:0] count;
    
       always @(posedge clk)
          if (rst)
             count <= 2'd0;
          else if (en)
             count <= count + 2'd1;
    
    endmodule
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    0. 须知:随时查看netlist的命令

    (1). 使用xdot,以图像形式查看

    yosys> show
    
    • 1

    需要先安装xdot sudo install xdot

    (2). 以RTLIL格式(yosys自己设的一种文本表示格式)查看

    yosys> dump
    
    • 1

    TextRtlil Document 描述了语法,主要是对Verilog代码进行词法分析,我还没细看,应该是使用lex&yacc自动生成


    1. Load RTL to Parser

    (1). 读入并解析Verilog代码

    yosys> read_verilog counter.v
    
    • 1

    read_verilog 使用Parser对RTL进行解析,生成AST(Abstract Syntax Tree 抽象语法树?但这明显是个图,不懂),并产生RTLIL
    在这里插入图片描述

    yosys> show
    
    • 1

    在这里插入图片描述

    yosys> dump
    
    • 1

    dump 输出的内容很多,这里只截取了后半部分:
    在这里插入图片描述

    (2). 检查层次结构,设置顶层module

    yosys> hierarchy -check -top counter
    
    • 1

    2. 使用proc命令处理process

    verilog中的process(过程结构) 包括initialalways

    • 电路在上电后是浮动电平,无法实现initial,所以initial不可综合,只能在仿真时使用
    • 实际上板中,使用 reset 来处理浮动电平
    yosys> proc
    
    • 1

    这是一个指令集合,等价于如下一系列指令:

    yosys> proc_clean
    yosys> proc_rmdead
    yosys> proc_init
    yosys> proc_arst
    yosys> proc_mux
    yosys> proc_dlatch
    yosys> proc_dff
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    CommandFunctionfor counter.v
    proc_cleanremove empty parts of processes没有空的process,所以没效果
    proc_rmdeadeliminate dead trees in decision trees / if-else switch会构成决策树,清除永远不会到达或者空的分支没有永远不会到达的分支,所以没效果
    proc_initconvert initial block to init attributes没效果,不懂
    proc_arstdetect asynchronous resets / 检测异步复位没有异步复位,所以没效果
    proc_muxconvert decision trees to multiplexers / 用选择器来实现决策树效果如下图所示
    proc_dlatchextract latches from processes and converts them to d-type latches / 将锁存器转换成D锁存器没有锁存器?所以没效果,一般都用触发器
    proc_dffextract flip-flops from processes and converts them to d-type flip-flop cells / 将always block中的D触发器提取出来效果如下图所示

    在这里插入图片描述
    在这里插入图片描述

    • always中的ifelse if 是有先后关系的,这里使用两个mux串行来实现
    • 其中A和B是mux的输入数据,S是选择信号,Y是输出数据。

    在这里插入图片描述
    在这里插入图片描述

    • 把always里的时序逻辑分离出来

    提示信息说的很清楚,这个命令做了哪些事;如果没起效果,就只输出一行Executing ...

    3. 使用fsm命令处理有限自动状态机

    由于HDL的并行性,如果我们想分周期完成一个任务,可以设置多个使能信号来链接不同的模块(一个模块执行结束,输出下一个模块的使能信号),但比较麻烦。
    如果使用FSM,一个模块就可以完成。

    module test(input clk, rst, ctrl, output [3:0] Out); 
        reg [1:0] curState;  // current state
        reg [1:0] nextState; // next state
    
        always @(posedge clk) begin // 时序逻辑,一般使用非阻塞赋值
            if(rst) curState <= 0;
            else curState <= nextState;
        end
    
        always @(curState or ctrl) begin // 组合逻辑,一般使用阻塞赋值
            case (curState) 
                0: begin 
                        Out = 1;
                        nextState = ctrl ? 1 : 2;
                     end 
                1: begin 
                        Out = 2; 
                        if (ctrl) begin
                            Out = 3; 
                            nextState = 2;  
                        end
                     end 
                2: begin 
                        Out = 4; 
                        if (ctrl) begin
                            Out = 5; 
                            nextState = 3;
                        end 
                    end 
                3: begin
                        if (!ctrl) 
                            nextState = 2'b00; 
                     end
                default: ;
            endcase 
          end 
      endmodule
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37

    extract and optimize finite state machines

    4. 使用opt命令进行优化

  • 相关阅读:
    STM32H7使用FileX库BUG,SD卡挂载失败
    C++:set和map的使用
    组件间通信
    前端开发环境安装(vue)
    python-time时间库
    书店漫游记录
    盒子阴影和网页布局
    【elasticsearch】记录ES查询数据结果为空的问题(单个字搜索可以,词语搜索为空)
    Jackson注释的使用
    [C#]使用C#部署yolov8的目标检测tensorrt模型
  • 原文地址:https://blog.csdn.net/qq_44850725/article/details/126175561