SystemVerilog的跨时钟域设计验证技术
- 格式:pdf
- 大小:1.74 MB
- 文档页数:56
systemverilog断言例子(一)SystemVerilog断言什么是SystemVerilog断言SystemVerilog断言是一种在硬件设计中使用的验证技术,用于检查设计行为和性质的正确性。
断言可以描述设计中的时序序列、性质规则或者约束条件,并在设计运行时进行验证。
SystemVerilog断言的语法SystemVerilog断言采用assert关键字来定义。
断言语句由一个条件表达式和一个可选的信息字符串组成,语法如下:assert condition;assert condition else failure_message;断言实例例子1:检查FIFO写入操作的空闲状态assert (wr_en == 0) |-> (is_empty == 1);上述例子中,断言检查了当写使能信号wr_en为0时,FIFO的空状态is_empty应为1。
如果断言条件不满足,则产生错误。
例子2:验证FIFO读取操作的一致性assert (rd_en == 0) |-> (rd_data === rd_data[$rose (wr_en)]);这个例子中,断言检查了当读使能信号rd_en为0时,已读取的数据rd_data应与最近的写入数据wr_data相等。
使用$rose函数来检测写入使能信号的上升沿。
例子3:检查FIFO写入和读取的顺序assert (wr_en & rd_en) |-> (wr_index <= rd_index);此例中,断言验证了在写入使能信号和读取使能信号同时为1时,写入的索引地址wr_index应小于等于读取的索引地址rd_index。
例子4:检查FIFO的深度不超过上限int depth = 16;assert (wr_en & !rd_en) |-> (wr_index - rd_index < dept h);这个例子中,断言验证了在写使能信号为1且读使能信号为0时,写入的索引地址与读取的索引地址之差应小于FIFO的深度上限。
系统Verilog是一种硬件描述语言(HDL),用于描述数字电路。
它包含了Verilog的所有特性,并添加了一些新的特性。
这些新的特性包括在设计中引入了数据类型的定义,更好地支持设计的抽象,以及更自然地支持设计的层次式描述。
在本文中,我们将深入了解System Verilog标准。
1. 介绍System Verilog标准System Verilog是IEEE标准1800,最初是由Accellera组织进行开发的。
它于2005年发行,是Verilog HDL的扩展,它添加了许多新的特性,使得它更适合于硬件验证和设计。
2. System Verilog的特性System Verilog添加了许多新的特性,以提高Verilog HDL的功能。
其中一些主要特性包括:a. 对象导向编程:System Verilog引入了面向对象的编程范式,使得设计和验证更加抽象和灵活。
b. 增强了数据类型和操作:System Verilog引入了更多的数据类型和操作,更好地支持设计和验证的需求。
c. 增加了随机性:System Verilog引入了随机性,使得验证更加全面和高效。
3. System Verilog在硬件验证中的应用System Verilog的特性使得它在硬件验证中应用广泛。
它提供了丰富的验证方法和工具,包括:a. 事务级建模(TLM):System Verilog提供了TLM的支持,使得验证更加抽象和高效。
b. Constrained随机验证:System Verilog引入了constrained random的验证方法,使得验证更加全面和高效。
c. Coverage驱动验证:System Verilog提供了coverage驱动的验证方法,使得验证更加全面和高效。
4. System Verilog在硬件设计中的应用除了在硬件验证中应用广泛外,System Verilog在硬件设计中也有着广泛的应用。
systemverilog验证学习笔记=阻塞串行<=非阻塞并行1)时序逻辑----使用非阻塞赋值2)锁存器----使用非阻塞赋值3)用alway块生成的组合逻辑----用阻塞赋值4)在同一个alway 块中既有时序逻辑又有组合逻辑---用非阻塞赋值5)在同一个alway块中不要既用阻塞赋值又用非阻塞赋值6)不要在一个以上的alway块中对同一个变量赋值7)用$trobe显示用非阻塞赋值指定的变量值8)不要用#0过程性赋值Modport将信号分组并指明方向Interfacearb_if(inputbitclk);Logic[1:0]a,b;Logicrt;Modporttet(outputa,rt,Inputb,clk);EndinterfaceModulearb(arb_if.tetarbif);…………Endmodule数组定位Inttq[$],d[]=’{9,1,8,3,4,4};Tq=d.find_inde某(某)with(item>3);//{0,2,4,5}得到的是脚标Tq=d.findwith(item>3);//{9,8,4,4}数组求和Intcount,total;Count=d.umwith(item>7);//2:{9,8}返回结果为元素与7比较表达式返回1为真或者零这里面返回,{1,0,1,0,0,0}求和得2Total=d.umwith((item>7)某item);//{1,0,1,0,0,0}和对应元素相乘求和得17=9加8数组排序d.revere();//逆序d.ort();//从小到大d.rotr();//从大到小d.huffle();时钟块指定同步信号相对于时钟的时序Interfacearb_if(inputbitclk);Logic[1:0]a,b;Logicrt;Modporttet(outputrt,Clockingcb);Endinterface断言A1:aert(bu.cb.a==2’b01)Ele$error(“grantnotaerted”);四种有输出消息的函数可在断言内部使用$info$waring$error$fatal 要验证这样一个属性:“当信号a在某一个时钟周期为高电平时,那么在接下来的2~4个时钟周期内,信号b应该为高电平”。
vivado跨时钟域约束在FPGA设计中,时钟域的划分和约束是非常重要的一部分。
时钟域的划分可以保证设计的正确性和性能的稳定性,而跨时钟域约束则是确保跨时钟域的数据传输和处理的正确性。
本文将介绍在Vivado中如何进行跨时钟域约束,以及一些常见的问题和解决方法。
在Vivado中,时钟域的划分是通过使用时钟约束和时钟分组来实现的。
时钟约束用于定义时钟的周期和延迟等参数,而时钟分组则用于将设计中的寄存器和逻辑单元划分到不同的时钟域中。
通过合理的划分和约束,可以确保设计在不同时钟域之间的数据传输和处理是可靠的。
在进行跨时钟域约束时,首先需要确定需要进行约束的时钟域。
一般来说,一个设计中会存在多个时钟域,每个时钟域都有自己的时钟信号和时钟周期。
在Vivado中,可以通过时钟分组的方式将不同时钟域中的寄存器和逻辑单元进行划分。
划分时钟域的目的是为了在跨时钟域传输数据时,保证数据在时钟边沿的稳定性和正确性。
一般情况下,跨时钟域的数据传输可以通过使用寄存器来实现。
在Vivado中,可以使用时钟同步模块(CLOCK_SYNC)来实现跨时钟域的数据传输。
时钟同步模块是一种可以在不同时钟域之间传输数据的特殊模块,它可以保证数据在时钟边沿的稳定性和正确性。
在进行跨时钟域约束时,需要使用时钟组(CLOCK_GROUP)来定义不同的时钟域。
时钟组可以将设计中的寄存器和逻辑单元划分到不同的时钟域中,并通过时钟同步模块实现数据的传输和处理。
通过使用时钟组,可以保证跨时钟域的数据传输和处理是可靠的,并且可以避免时钟域间的冲突和不一致。
在Vivado中,可以通过使用时钟组约束语句(CLOCK_GROUP)来定义时钟组。
时钟组约束语句可以指定不同时钟域的时钟信号和时钟周期,并将设计中的寄存器和逻辑单元划分到相应的时钟组中。
通过使用时钟组约束语句,可以确保跨时钟域的数据传输和处理是可靠的,并且可以避免时钟域间的冲突和不一致。
除了使用时钟组约束语句,还可以使用时钟组属性(CLOCK_GROUP_PROPERTY)来定义时钟组的属性。
uvm system verilog总结### UVM System Verilog 总结#### 导语UVM(Universal Verification Methodology)与System Verilog的结合,为芯片设计验证领域带来了革新。
这种方法论不仅提高了验证效率,还增强了验证的可重用性和覆盖率。
本文将全面总结UVM与System Verilog的相关概念、特点以及应用。
---#### 一、UVM与System Verilog概述**1.1 UVM简介**UVM是建立在System Verilog基础上的一个标准化验证方法论,旨在提供一种通用的、模块化的验证平台。
它通过将验证环境分层,实现了环境的可重用性和易于维护性。
**1.2 System Verilog简介**System Verilog是一种硬件描述和验证语言,结合了Verilog和VHDL的优点,并增加了面向对象编程的特性。
它在芯片设计和验证中广泛应用。
---#### 二、UVM的核心特点**2.1 面向对象**UVM采用面向对象的设计思想,将验证环境分为不同的类和层次,便于管理和重用。
**2.2 模块化**UVM的模块化设计使得验证环境可以根据不同的测试需求灵活组合和配置。
**2.3 自动化**UVM支持自动化测试,包括自动生成测试序列、自动检查和报告错误等。
---#### 三、System Verilog在UVM中的应用**3.1 非阻塞赋值**System Verilog的非阻塞赋值在UVM中用于描述硬件行为。
**3.2 面向对象编程**System Verilog的面向对象编程特性使得UVM可以定义基类和派生类,实现代码的复用。
**3.3 功能覆盖**利用System Verilog的功能覆盖(Functional Coverage)特性,UVM 可以全面检查设计功能的覆盖率。
---#### 四、UVM与System Verilog的结合优势**4.1 提高验证效率**UVM与System Verilog的结合使得验证人员可以快速搭建验证环境,提高验证效率。
systemverilog函数SystemVerilog是一种硬件描述语言,用于描述硬件设计和验证。
它包含了一系列的语法和语义,使得开发人员能够对电子系统进行描述、模拟和验证。
在SystemVerilog中,我们可以使用函数来创建可重用的代码块,以便在设计和验证过程中使用。
本文将介绍SystemVerilog函数的概念和使用方法。
一、SystemVerilog函数的概述SystemVerilog函数是一段可执行的代码,可以接受输入参数并返回一个值。
它在设计和验证过程中起到了模块化和重用代码的作用。
函数可以用于实现常用的算法、逻辑函数、数据转换等。
与任务不同,函数是同步的,会阻塞进程直到返回结果。
函数可以在模块内部定义,也可以在模块之外定义。
二、SystemVerilog函数的语法函数的语法在SystemVerilog中如下所示:function 函数返回值类型函数名(输入参数列表);函数体;endfunction其中,函数返回值类型指定了函数的返回值类型,函数名指定了函数的名称,输入参数列表指定了函数的输入参数,函数体是实现函数功能的代码。
下面是一个例子:function int add(int a, int b);return a + b;endfunction本例中,函数add接受两个整型参数a和b,并返回它们的和。
三、SystemVerilog函数的特性1.函数可以是递归的,即一个函数可以调用自身。
这在实现一些递归算法时非常有用。
2.函数可以有输入参数,也可以没有输入参数。
输入参数可以通过值传递或引用传递。
3.函数可以有返回值,也可以没有返回值。
如果没有返回值,则函数被称为过程。
4.函数可以有本地变量和输入参数,但不能有任何输出参数。
输出结果通过函数的返回值传递。
5.函数可以在模块之外定义,以便在多个模块中共享和重用。
四、SystemVerilog函数的使用示例下面是一个使用函数的示例,实现了一个二进制加法器:module binary_adder(input [3:0] a, input [3:0] b, output logic [3:0] sum);//二进制加法函数function logic [3:0] binary_add(input [3:0] a, input [3:0] b);logic [3:0] carry = 0;logic [3:0] sum = 0;for(int i=0; i<4; i++) beginsum[i] = a[i] ^ b[i] ^ carry;carry = (a[i] & b[i]) , (a[i] & carry) , (b[i] & carry);endbinary_add = sum;endfunction//使用函数计算二进制加法assign sum = binary_add(a, b);endmodule本例中,我们定义了一个模块binary_adder,包含了一个输入端口a和b,一个输出端口sum。
system verilog 时序电路和组合电路udp SystemVerilog是一种硬件描述语言,它广泛应用于设计和验证复杂的数字电路。
在SystemVerilog中,我们可以使用时序电路和组合电路来描述数字电路的行为和功能。
本文将逐步解释SystemVerilog中时序电路和组合电路的概念和用法。
1. SystemVerilog简介SystemVerilog是一种硬件描述语言,它扩展了Verilog HDL,并添加了一些新的功能。
它既可以用于描述数字电路的结构和行为,也可以用于验证设计的正确性。
SystemVerilog通过组合电路和时序电路的描述,能够模拟和分析电路的行为,进行功能验证和时序验证。
2. 组合电路组合电路是一种无记忆的电路,其输出只依赖于输入的当前值。
在SystemVerilog中,我们使用逻辑门和赋值语句来描述组合电路的行为。
例如,下面是一个使用逻辑门描述的2输入AND门:systemverilogmodule and_gate(input logic a, b, output logic y);assign y = a & b;endmodule在上面的例子中,我们定义了一个具有两个输入和一个输出的模块。
通过使用AND运算符,我们将输入a和b进行逻辑与操作,并将结果赋值给输出y。
这样,无论输入值如何变化,输出y始终是输入a和b的逻辑与结果。
3. 时序电路时序电路是一种有记忆能力的电路,其输出不仅依赖于输入的当前值,还依赖于过去的输入值。
在SystemVerilog中,我们使用时钟、寄存器和时序块来描述时序电路的行为。
下面是一个简单的时序电路的例子:systemverilogmodule counter(input logic clk, input logic reset, output logic [3:0] out); always_ff @(posedge clk or posedge reset)if(reset)out <= 4'b0000;elseout <= out + 1;endmodule在上面的例子中,我们定义了一个计数器模块,它有一个时钟输入clk、一个复位输入reset和一个4位输出out。
vivado跨时钟域约束Vivado是一款由Xilinx公司开发的集成电路设计工具,用于设计和实现FPGA(现场可编程门阵列)和SoC(片上系统)等数字电路。
在FPGA设计中,时钟域划分和时钟约束是非常重要的步骤,特别是在跨时钟域的设计中。
跨时钟域设计是指在一个FPGA设计中存在多个时钟域,不同的时钟域之间存在时序约束和时钟域间的数据传输。
由于不同时钟域之间的时钟频率和相位存在差异,因此需要进行跨时钟域约束来确保数据的正确传输和时序的满足。
在Vivado中,可以使用set_clock_groups命令来定义时钟组,以及使用set_false_path和set_multicycle_path等命令来设置跨时钟域约束。
我们需要将不同的时钟信号分组,形成时钟组。
在时钟组中,所有时钟信号都需要满足相同的时钟约束。
我们可以使用set_clock_groups命令来定义时钟组,如下所示:set_clock_groups -asynchronous -group {clk1 clk2 clk3}上述命令表示将clk1、clk2和clk3形成一个时钟组,并且时钟之间是异步的。
这意味着在时钟组中的时钟之间不需要保持任何特定的时序关系。
除了时钟组的设置,还需要设置跨时钟域的路径约束。
在跨时钟域的设计中,数据的传输需要经过时钟域边界,因此需要设置路径约束来确保数据的正确传输。
在Vivado中,可以使用set_false_path命令来设置不需要进行时序分析的路径,如下所示:set_false_path -from [get_clocks clk1] -to [get_clocks clk2]上述命令表示将clk1到clk2之间的路径设置为false path,不进行时序分析。
这样可以避免时序分析器对这条路径进行时序优化,从而减少时序分析的复杂性。
除了set_false_path命令,还可以使用set_multicycle_path命令来设置跨时钟域的多周期路径。
跨时钟域处理方法fifo跨时钟域处理方法FIFO是用于在不同时钟域之间传输数据的一种常见技术。
在数字系统设计中,由于不同的模块可能使用不同的时钟信号,因此需要一种方法来处理这些不同时钟域之间的数据传输。
FIFO(First-In-First-Out)是一种常见的数据缓冲器,用于在不同时钟域之间进行数据传输和同步。
首先,让我们来看看FIFO是如何工作的。
FIFO包含一个读指针和一个写指针,它可以在不同时钟域之间缓存数据。
当数据被写入FIFO时,它被存储在FIFO的存储单元中,并且可以在另一个时钟域中被读取。
这样,FIFO提供了一种机制,可以在不同时钟域之间进行数据传输,同时保持数据的顺序。
在实际应用中,跨时钟域处理方法FIFO可以通过一些技术来实现。
例如,可以使用双口RAM来实现FIFO,其中一个端口用于写入数据,另一个端口用于读取数据。
此外,可以使用专门设计的同步电路来确保在不同时钟域之间进行数据传输时的正确同步。
另一种常见的方法是使用双缓冲区FIFO,其中一个缓冲区用于接收数据,另一个缓冲区用于发送数据。
这种方法可以确保在不同时钟域之间进行数据传输时的可靠性和稳定性。
除了硬件实现,还可以使用一些设计技巧来处理跨时钟域的数据传输。
例如,可以使用手动握手协议来确保在不同时钟域之间进行数据传输时的正确性,或者可以使用一些同步技术来确保数据在不同时钟域之间的正确传输。
总之,跨时钟域处理方法FIFO是一种常见的用于在不同时钟域之间进行数据传输的技术。
它可以通过硬件实现或者一些设计技巧来确保数据在不同时钟域之间的正确传输和同步。
在数字系统设计中,了解并掌握这种技术对于确保系统的可靠性和稳定性非常重要。
SNUG-2008 Boston, MA Voted Best Paper 1st PlaceWorld Class Verilog & SystemVerilog TrainingClock Domain Crossing (CDC) Design & Verification Techniques Using SystemVerilogClifford E. CummingsSunburst Design, Inc. cliffc@ABSTRACT Important design considerations require that multi-clock designs be carefully constructed at Clock Domain Crossing (CDC) boundaries. This paper details some of the latest strategies and best known methods to address passing of one and multiple signals across a CDC boundary. Included in the paper are techniques related to CDC verification and an interesting 2-deep FIFO design for passing multiple control signals between clock domains. Although the design methods described in the paper can be generally implemented using any HDL, the examples are shown using efficient SystemVerilog techniques.Table of Contents1.0 2.0 2.1 3.0 3.1 3.2 3.3 3.4 3.5 3.6 4.0 4.1 4.1.1 4.2 4.3 4.4 4.5 5.0 5.1 5.2 5.3 5.3.1 5.4 5.4.1 5.5 5.5.1 5.6 5.6.1 5.6.2 5.6.3 5.7 5.7.1 5.7.2 5.7.3 5.7.4 5.7.5 5.7.6 5.8 5.8.1 5.8.2 6.0 6.1 Introduction........................................................................................................................... 6 Metastability.......................................................................................................................... 6 Why is metastability a problem?........................................................................................... 7 Synchronizers........................................................................................................................ 8 Two synchronization scenarios ............................................................................................. 8 Two flip-flop synchronizer ................................................................................................... 8 MTBF - mean time before failure ......................................................................................... 9 Three flip-flop synchronizer ............................................................................................... 10 Synchronizing signals from the sending clock domain....................................................... 10 Synchronizing signals into the receiving clock domain...................................................... 11 Synchronizing fast signals into slow clock domains .......................................................... 13 Requirement for reliable signal passing between clock domains ....................................... 13 The "three edge" requirement .......................................................................................... 13 Problem - passing a fast CDC pulse ................................................................................... 14 Problem - sampling a long CDC pulse - but not long enough!........................................... 15 Open-loop solution - sampling signals with synchronizers ................................................ 16 Closed loop solution - sampling signals with synchronizers .............................................. 17 Passing multiple signals between clock domains ............................................................... 18 Multi-bit CDC strategies..................................................................................................... 18 Multi-bit signal consolidation ............................................................................................. 18 Problem - Two simultaneously required control signals..................................................... 19 Solution - Consolidation.................................................................................................. 20 Problem - Two phase-shifted sequencing control signals................................................... 21 Solution - consolidation and an extra flip-flop................................................................ 22 Problem - Multiple CDC signals......................................................................................... 23 Solutions for passing multiple CDC signals.................................................................... 23 Multi-Cycle Path (MCP) formulation ................................................................................. 24 MCP formulation using a synchronized enable pulse ..................................................... 25 Closed-loop - MCP formulation with feedback .............................................................. 27 Closed-loop - MCP formulation with acknowledge feedback ........................................ 28 Synchronizing counters....................................................................................................... 29 Binary counters ................................................................................................................ 29 Gray codes ....................................................................................................................... 30 Gray-to-binary conversion ............................................................................................... 30 Binary-to-gray conversion ............................................................................................... 31 Gray code counter style #1 .............................................................................................. 32 Gray code counter style #2 .............................................................................................. 33 Additional multi-bit CDC techniques ................................................................................. 34 Multi-bit CDC signal passing using asynchronous FIFOS.............................................. 34 Multi-bit CDC signal passing using 1-deep / 2-register FIFO synchronizer ................... 35 Naming conventions & design partitioning ........................................................................ 36 Clock & signal naming conventions ................................................................................... 362 Clock Domain Crossing (CDC) Design & Verification Techniques Using SystemVerilogSNUG Boston 2008 Rev 1.06.1.1 6.2 6.3 6.3.1 6.4 7.0 7.1 7.2 7.2.1 7.2.2 7.2.3 7.2.4 7.3 7.3.1 7.3.2 7.3.3 7.4 7.5 7.6 7.7 8.0 8.1 8.2 8.3 8.4 9.0 10.0 11.0 12.0 12.1 12.2 12.3Multi-clock / multi-source modules with no naming convention................................... 37 Timing verification for each clock domain......................................................................... 37 Clock oriented design partitioning...................................................................................... 37 Timing analysis of clock-partitioned modules................................................................. 39 Partitioning with MCP formulations................................................................................... 40 Multi-clock gate-level simulation issues ............................................................................ 41 Synchronizer gate-level CDC simulation issue .................................................................. 41 Strategies to remove X-propagation from gate-level simulations....................................... 41 Simulator command to turn off timing checks ................................................................ 42 Change flip-flop setup and hold times to 0...................................................................... 42 Copy and modify new flip-flop models ........................................................................... 42 Synopsys set_annotated_check command ....................................................................... 42 Additional strategies to remove X-propagation .................................................................. 43 Use multiple SDF files .................................................................................................... 43 Vendor synchronizer cell with supporting SDF generation tools.................................... 43 Vendors with built-in synchronizer support .................................................................... 44 Multiple SDF files for gate-level CDC simulations ........................................................... 44 Force synchronizer notifier inputs to a fixed value............................................................. 44 ASIC & FPGA library cell synchronizers........................................................................... 45 Simulation model with random delay insertion .................................................................. 46 Summary & conclusions ..................................................................................................... 47 Recommended 1-bit CDC techniques................................................................................. 47 Recommended multi-bit CDC techniques .......................................................................... 48 Recommended naming conventions and design partitioning ............................................. 48 Recommended solutions to multi-clock gate-level CDC simulations ................................ 48 Acknowledgements............................................................................................................. 48 References........................................................................................................................... 48 Author & Contact Information............................................................................................ 49 Appendix............................................................................................................................. 50 Common sync2 model - used by MCP formulation and FIFO synchronizer...................... 50 MCP formulation with ready-acknowledge source code .................................................... 50 Multi-bit 1-deep / 2-register FIFO synchronizer source code............................................. 55SNUG Boston 2008 Rev 1.03Clock Domain Crossing (CDC) Design & Verification Techniques Using SystemVerilogTable of FiguresFigure 1 - Asynchronous clocks and synchronization failure ......................................................... 6 Figure 2 - Metastable bdat1 output propagating invalid data throughout the design................... 7 Figure 3 - Two flip-flop synchronizer............................................................................................. 9 Figure 4 - Primary contributing factors to short MTBF values..................................................... 10 Figure 5 - Three flip-flop synchronizer used in higher speed designs .......................................... 10 Figure 6 - Unregistered signals sent across a CDC boundary....................................................... 11 Figure 7 - Registered signals sent across a CDC boundary .......................................................... 12 Figure 8 - Short CDC signal pulse missed during synchronization .............................................. 14 Figure 9 - Marginal CDC pulse that violates the destination setup and hold times...................... 15 Figure 10 - Lengthened pulse to guarantee that the control signal will be sampled ..................... 16 Figure 11 - Signal with feedback to acknowledge receipt ............................................................ 17 Figure 12 - Problem - Passing multiple control signals between clock domains.......................... 19 Figure 13 - Solution - Consolidating control signals before passing between clock domains ..... 20 Figure 14 - Problem - Passing sequential control signals between clock domains....................... 21 Figure 15 - Solution - Logic to generate proper sequencing signals in the new clock domains ... 22 Figure 16 - Problem - Encoded control signals passed between clock domains .......................... 23 Figure 17 - Logic to pass a synchronized enable pulse between clock domains .......................... 24 Figure 18 - Synchronized pulse generation logic.......................................................................... 25 Figure 19 - Synchronized enable pulse generation logic and equivalent symbol ......................... 26 Figure 20 - Multi-Cycle Path (MCP ) formulation toggle-pulse generation................................. 26 Figure 21 - Multi-Cycle Path (MCP ) formulation toggle-pulse generation with acknowledge... 27 Figure 22 - Multi-Cycle Path (MCP ) formulation toggle-pulse generation with ready-ack ........ 28 Figure 23 - Binary count values sampled in mid-transition .......................................................... 29 Figure 24 - 4-bit gray-to-binary conversion equations.................................................................. 30 Figure 25 - 4-bit gray-to-binary conversion equations - 2nd method ........................................... 31 Figure 26 - 4-bit binary-to-gray conversion equations.................................................................. 31 Figure 27 - Gray code counter style #1 - only one gray code register........................................... 32 Figure 28 - Gray code counter style #2 - binary register and gray code register........................... 33 Figure 29 - 1-deep / 2-register FIFO synchronizer block diagram................................................ 35 Figure 30 - Design partitioned on clock boundaries ..................................................................... 38 Figure 31 - Partitioned design with MCP formulation ................................................................. 40 Figure 32 - Synchronizer gate-level CDC simulation waveforms ................................................ 41 Figure 33 - Sample ASIC & FPGA synchronizer cell for synthesis and simulation .................... 46SNUG Boston 2008 Rev 1.04Clock Domain Crossing (CDC) Design & Verification Techniques Using SystemVerilogTable of ExamplesExample 1 - Non-working but conceptually correct gray-to-binary SystemVerilog model ......... 30 Example 2 - Parameterized and correct gray-to-binary SystemVerilog model............................. 31 Example 3 - Parameterized binary-to-gray SystemVerilog model................................................ 32 Example 5 - Parameterized gray-code counter SystemVerilog model.......................................... 33 Example 6 - Parameterized gray-code counter with binary counter ............................................. 34 Example 7 - SystemVerilog model for ASIC & FPGA synchronizer cell.................................... 47 Example 8 - sync2.sv code............................................................................................................ 50 Example 9 - plsgen.sv code .......................................................................................................... 50 Example 10 - asend_fsm.sv code.................................................................................................. 51 Example 11 - back_fsm.sv code ................................................................................................... 51 Example 12 - bmcp_recv.sv code ................................................................................................. 52 Example 13 - mcp_blk.sv code..................................................................................................... 53 Example 14 - acmp_send.sv code................................................................................................. 54 Example 15 - wctl.sv code ............................................................................................................ 55 Example 16 - cdc_syncfifo.sv code .............................................................................................. 55 Example 17 - Dual Port Ram code - dp_ram2.sv ......................................................................... 56 Example 18 - rctl.sv code.............................................................................................................. 56SNUG Boston 2008 Rev 1.05Clock Domain Crossing (CDC) Design & Verification Techniques Using SystemVerilog1.0 IntroductionIn 2001, I presented my first paper on multi-asynchronous clock design. At that time, I had not found any good sources to describe the design and synthesis techniques required to do proper multi-clock design. The 2001 paper was a collection of techniques that I had gathered over years from actual ASIC and FPGA design experiences. At the conclusion of the 2001 conference presentation, dozens of engineers and colleagues came forward and shared with me enough additional interesting ideas and techniques to write a sequel on the topic. Over the past eight years, I have included instruction on multi-clock design techniques in my Advanced and Expert Verilog and SystemVerilog training courses, and over that same period of time, more colleagues and students have shared with me additional interesting multi-clock design techniques. Since the release of the first multi-clock paper in 2001, the industry has largely identified these types of design methodologies as Clock Domain Crossing (CDC) techniques. I will use this common nomenclature in this paper. This paper includes the best techniques described in the 2001 paper along with an updated collection of interesting and efficient multi-clock design techniques that have been shared with me over the past decade. The actual conference presentation slides will be mostly a collection of the new techniques incorporated since the original 2001 presentation, retaining only enough of the original slides to introduce the fundamental CDC design concepts and issues.2.0 MetastabilityMetastbility refers to signals that do not assume stable 0 or 1 states for some duration of time at some point during normal operation of a design. In a multi-clock design, metastability cannot be avoided but the detrimental effects of metastability can be neutralized.Figure 1 - Asynchronous clocks and synchronization failure SNUG Boston 2008 Rev 1.0 6 Clock Domain Crossing (CDC) Design & Verification Techniques Using SystemVerilogQuoting from Dally and Poulton's book[9] concerning metastability: "When sampling a changing data signal with a clock ... the order of the events determines the outcome. The smaller the time difference between the events, the longer it takes to determine which came first. When two events occur very close together, the decision process can take longer than the time allotted, and a synchronization failure occurs." Figure 1 shows a synchronization failure that occurs when a signal generated in one clock domain is sampled too close to the rising edge of a clock signal from a second clock domain. Synchronization failure is caused by an output going metastable and not converging to a legal stable state by the time the output must be sampled again. 2.1 Why is metastability a problem? So why is metastability a problem? Figure 2 shows that a metastable output that traverses additional logic in the receiving clock domain can cause illegal signal values to be propagated throughout the rest of the design. Since the CDC signal can fluctuate for some period of time, the input logic in the receiving clock domain might recognize the logic level of the fluctuating signal to be different values and hence propagate erroneous signals into the receiving clock domain.Figure 2 - Metastable bdat1 output propagating invalid data throughout the designEvery flip-flop that is used in any design has a specified setup and hold time, or the time in which the data input is not legally permitted to change before and after a rising clock edge. This timeSNUG Boston 2008 Rev 1.0 7 Clock Domain Crossing (CDC) Design & Verification Techniques Using SystemVerilogwindow is specified as a design parameter precisely to keep a data signal from changing too close to another synchronizing signal that could cause the output to go metastable.3.0 SynchronizersWhen passing signals between clock domains, an important question to ask is, do I need to sample every value of a signal that is passed from one clock domain to another? 3.1 Two synchronization scenarios There are two scenarios that are possible when passing signals across CDC boundaries, and it is important to determine which scenario applies to your design: (1) It is permitted to miss samples that are passed between clock domains. (2) Every signal passed between clock domains must be sampled. First scenario: sometimes it is not necessary to sample every value, but it is important that the sampled values are accurate. One example is the set of gray code counters used in a standard asynchronous FIFO design. In a properly designed asynchronous FIFO model, synchronized gray code counters do not need to capture every legal value from the opposite clock domain, but it is critical that sampled values be accurate to recognize when full and empty conditions have occurred. Second scenario: a CDC signal must be properly recognized or recognized and acknowledged before a change is permitted on the CDC signal. In both of these scenarios, the CDC signals will require some form of synchronization into the receiving clock domain. 3.2 Two flip-flop synchronizer Quoting again from Dally and Poulton[9] concerning synchronizers: "A synchronizer is a device that samples an asynchronous signal and outputs a version of the signal that has transitions synchronized to a local or sample clock." The simplest and most common synchronizer used by digital designers is a two-flip-flop synchronizer as shown in Figure 3. The first flip-flop samples the asynchronous input signal into the new clock domain and waits for a full clock cycle to permit any metastability on the stage-1 output signal to decay, then the stage1 signal is sampled by the same clock into a second stage flip-flop, with the intended goal that the stage-2 signal is now a stable and valid signal synchronized and ready for distribution within the new clock domain.SNUG Boston 2008 Rev 1.08Clock Domain Crossing (CDC) Design & Verification Techniques Using SystemVerilogFigure 3 - Two flip-flop synchronizerIt is theoretically possible for the stage-1 signal to still be sufficiently metastable by the time the signal is clocked into the second stage to cause the stage-2 output signal to also go metastable. The calculation of the probability of the time between synchronization failures (MTBF) is a function of multiple variables including the clock frequencies used to generate the input signal and to clock the synchronizing flip-flops. One description of the MTBF calculation can be found in Dally and Poulton[9]. For most synchronization applications, the two flip-flop synchronizer is sufficient to remove all likely metastability. 3.3 MTBF - mean time before failure For most applications, it is important to run a calculation of the Mean Time Before Failure (MTBF) for any signal crossing a CDC boundary. Failure in this sense means a signal that is passed to a synchronizing flip-flop, goes metastable on the first stage synchronizer flip-flop, and continues to be metastable one cycle later when it is sampled into the second stage synchronizer flip-flop. Since the signal did not settle to a known value after one clock cycle, the signal could still be metastable when sampled and passed to the receiving clock domain, causing potential failures to the corresponding logic. When calculating MTBF numbers, larger numbers are preferred over smaller numbers. Larger MTBF numbers indicate longer periods of time between potential failures, while smaller MTBFSNUG Boston 2008 Rev 1.09Clock Domain Crossing (CDC) Design & Verification Techniques Using SystemVerilognumbers indicate that metastability could happen frequently, similarly causing failures within the design. Dally and Poulton[9] give a good equation with very thorough analysis of the calculation that can be performed to calculate the MTBF of a synchronizer circuit. Without repeating the equation and analysis, it should be pointed out that two of the most important factors that directly impact the MTBF of a synchronizer circuit are, the sample clock frequency (how fast are signals being sampled into the receiving clock domain) and the data change frequency (how fast is the data changing that crosses the CDC boundary).Figure 4 - Primary contributing factors to short MTBF valuesFrom the above partial equation, it can be seen that failures occur more frequently (shorter MTBF) in higher speed designs, or when the sampled data changes more frequently. 3.4 Three flip-flop synchronizer For some very high speed designs, the MTBF of a two-flop synchronizer is too short and a third flop is added to increase the MTBF to a satisfactory duration of time. Of course, satisfactory is determined by the architect of the design.Figure 5 - Three flip-flop synchronizer used in higher speed designs3.5 Synchronizing signals from the sending clock domain Frequently asked question regarding CDC design: Is it a good idea to register signals from the sending clock domain before passing the signals to the receiving clock domain? Implied in the question is the assumption that CDC signals will be synchronized into the receiving clock domain; therefore, they do not require synchronization in the sending clock domain. This rationalization is incorrect and registering signals in the sending clock domain should generally be required.SNUG Boston 2008 Rev 1.010Clock Domain Crossing (CDC) Design & Verification Techniques Using SystemVerilogConsider an example where the signals in the sending clock domain are not registered before being passed into the receiving clock domain, as shown in Figure 6.Figure 6 - Unregistered signals sent across a CDC boundaryIn this example, the combinational output from the sending clock domain could experience combinational settling at the CDC boundary. This combinational settling effectively increases the data-change frequency potentially creating small bursts of oscillating data and thereby increasing the number of edges that could be sampled while changing, with a corresponding increase in the potential for sampling changing data and generating metastable signals. 3.6 Synchronizing signals into the receiving clock domain Signals in the sending clock domain should be synchronized before being passed to a CDC boundary. The synchronization of signals from the sending clock domain reduces the number of edges that can be sampled in the receiving clock domain, effectively reducing the data-change frequency in the MTBF equation and hence increasing the time between calculated failures (see section 3.3 for a description of the impact of data change frequencies on MTBF).SNUG Boston 2008 Rev 1.011Clock Domain Crossing (CDC) Design & Verification Techniques Using SystemVerilogFigure 7 - Registered signals sent across a CDC boundaryIn Figure 7, the aclk logic settles and sets up on the adat flip-flop before being passed into the bclk domain. The adat flip-flop filters out the combinational settling on the flip-flop input (a) and passes a clean signal to the bclk logic.SNUG Boston 2008 Rev 1.012Clock Domain Crossing (CDC) Design & Verification Techniques Using SystemVerilog4.0 Synchronizing fast signals into slow clock domainsAs discussed in section 3.1, if a CDC signal cannot be skipped when passed between clock domains, it is important to consider signal widths or synchronization techniques when they are passed between clock domains. One issue associated with synchronizers is the possibility that a signal from a sending clock domain might change values twice before it can be sampled, or might be too close to the sampling edges of a slower clock domain. This possibility must be considered any time signals are sent from one clock domain to another and a determination must be made whether missed signals are or are not a problem for the design in question. When missed samples are not allowed, there are two general approaches to the problem: (1) An open-loop solution to ensure that signals are captured without acknowledgment. (2) A closed-loop solution that requires acknowledgement of receipt of the signal that crosses a CDC boundary. Both solutions are discussed in this section. 4.1 Requirement for reliable signal passing between clock domains Synchronizing slower control signals into a faster clock domain is generally not a problem if the faster clock domain is 1.5X the frequency (or more) of the slower clock domain, since the faster clock signal will sample the slower CDC signal one or more times. Recognizing that sampling slower signals into faster clock domains causes fewer potential problems than sampling faster signals into slower clock domains, a designer might to take advantage of this fact by using simple two flip-flop synchronizers to pass single CDC signals between clock domains. 4.1.1 The "three edge" requirementMark Litterick[4] noted that when passing one CDC signal between clock domains through a two-flip-flop synchronizer, the CDC signal must be wider than 1-1/2 times the cycle width of the receiving domain clock period. Littereick described this requirement as "input data values must be stable for three destination clock edges." For exceptionally long source and destination clock frequencies, this requirement could probably be safely relaxed to 1-1/4 times the cycle time of the receiving clock domain or less, but the "three edge" guideline is the safest initial design condition, and is easier to prove through the use of SystemVerilog assertions than to dynamically measure a fractional width of a CDC signal during simulation. The "three edge" requirement actually applies to both open-loop and closed-loop solutions, but implementations of the closed-loop solution automatically ensure that at least three edges are detected for all CDC signals.SNUG Boston 2008 Rev 1.013Clock Domain Crossing (CDC) Design & Verification Techniques Using SystemVerilog。