【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

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

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

yosys> show
  • 需要先安装xdot sudo install xdot
  • 可以添加option来设置保存格式、路径、文件名等,比如show -format dot -prefix /home/wq/Documents/yosys/wq/after_proc

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

yosys> dump

TextRtlil Document 描述了语法


1. Load RTL to Parser

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

yosys> read_verilog counter.v

使用flex&bison自动生成词法和语法分析器,对RTL进行解析,使用HDL Frontend生成AST(Abstract Syntax Tree 抽象语法树),再使用AST Frontend产生RTLIL
在这里插入图片描述

yosys> show

在这里插入图片描述

yosys> dump

dump 输出的内容很多,这里只截取了后半部分:
在这里插入图片描述
使用gdb debug可以查看代码执行顺序:(Linux + gdb + vscode)
在这里插入图片描述

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

yosys> hierarchy -check -top counter

2. 使用proc命令处理process

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

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

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

yosys> proc_clean
yosys> proc_rmdead
yosys> proc_init
yosys> proc_arst
yosys> proc_mux
yosys> proc_dlatch
yosys> proc_dff
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

extract and optimize finite state machines

4. 使用opt命令进行优化

  • 6
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值