码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 【yosys】基础的综合操作(更新中)


    目录

    • 0. 须知:随时查看netlist的命令
        • (1). 使用xdot,以图像形式查看
        • (2). 以RTLIL格式(yosys自己设的一种文本表示格式)查看
    • 1. Load RTL to Parser
        • (1). 读入并解析Verilog代码
        • (2). 检查层次结构,设置顶层module
    • 2. 使用`proc`命令处理process
    • 3. 使用`fsm`命令处理有限自动状态机
    • 4. 使用`opt`命令进行优化

    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(过程结构) 包括initial 和 always

    • 电路在上电后是浮动电平,无法实现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中的if 和 else 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命令进行优化

  • 相关阅读:
    vscode不显示横滚动条处理
    【EI检索会议】第四届智能电网与能源工程国际研讨会(SGEE 2023)
    堆的使用(堆排序和Top-K问题)
    【QT进阶】Qt http编程之http相关类的简单介绍
    冰冰学习笔记:进程概念
    第十五届蓝桥杯物联网试题(省赛)
    H3C路由器 basic NAT典型组网配置
    2023最新SSM计算机毕业设计选题大全(附源码+LW)之java小区宠物信息管理系统0v9l2
    Abbkine 细胞侵袭分析试剂盒,简单方便,快速检测
    理解 YOLOV1 第二篇 预测阶段 非极大值抑制(NMS)
  • 原文地址:https://blog.csdn.net/qq_44850725/article/details/126175561
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号