2011年10月15日 星期六

Digital Circuit Functional Verification(十五)

斷言ASSERTIONS


Simulation Assertions 
簡單來說就是利用簡單的語義描述來驗證signals protocol
而這個驗證語法是基於一個或多個clock來確認signals之間的關係

断言被分为两大类:一类是由设计者定义,另一类由验证工程师定义。
● 由设计者定义的设计断言(Implementation Assertion)
    通常寫成embedded Mode,而嵌入到RTL中,因為Assertion 不會被合成
● 由验证工程师定义的规范断言(Specification Assertion)
   通常會使用blockbox方式來驗證design,常放在design的外部

由於assertion只能指出錯誤,但不能指出少驗了那些項目
因此必須搭配code coverage相關的方法來使用


Formal Assertion Proving
Formal tools called model checker or assertion provers can mathe-
matically  prove that,  given an  RTL design  and  some  assumptions
about the relationships of the input signals, an assertion will always
hold  true.  If a counter  example  is  found,  the  formal  tool  will  pro-
vide  details  on  the  sequence  of events  that leads  to  the  assertion
violation. It is then up to you to decide if this sequence of events is
possible, given additional knowledge about the environment of the
design.

 形式验证领域将这些输入断言称为约束(constraint),这里作者使用术语“假设”(assumption)将其与随机发生
的约束区分开来,后者是一种随机的概念。

這個驗證觀念在2008之後似乎不再有人再提了,

現在的觀念應該是
Formal verification就用formal tools(LEC, formality)之類來作靜態驗證
Assertion就用SVA, PSL, OVL之類來作動態驗證

另一種原因可能是OVM/UVM的出現,而random input及constraints在其中的使用

2011年10月14日 星期五

Digital Circuit Functional Verification(十四)

FUNCTIONAL  COVERAGE

Functional coverage is another tool to help ensure that a bad design
is not hiding behind passing testbenches
. 它是一個新的驗證方法。
Functional  coverage  records  relevant  metrics  (e.g.,  packet  length,
instruction opcode, buffer occupancy level)  to ensure that the veri-
fication process has exercised the design through all of the interest-
ing  values.  Whereas  code  coverage  measures  how  much  of  the
implementation  has  been  exercised,  functional  coverage  measures
how much of the original design specification has been exercised.

Functional coverage是補Code Coverage的不足,並協助去驗證錯誤的遺漏點

Functional coverage有以下幾種分類
Item Coverage  
Item  coverage  is  the  recording  of individual  scalar  values.
它是最基本的functional coverage

Cross  Coverage
cross  coverage  measures  the  presence  or  occurrence  of combina-
tions of values.
意義上接近item coverage,但是為數個item coverage的組合
例如針對Addr(100->1ff)之間,data(為20->2F)的coverage

Transition Coverage 
針對signals之間關係變化的偵測,有Assertion的意思在
因此使用上assertion的item也可以是Transition Coverage的item

 
以下是文件上的說法
1. 是否产生了所有的重要值序列
2. 与item coverage相似
3. 与FSM PATH Coverage相似
4. 转移覆盖能反映设计意图

2011年10月13日 星期四

Digital Circuit Functional Verification(十三)

代码覆盖CODE COVERAGE

概念源于软件工程,用来判断测试是否充分,代码是否有
没测试到的。

1. Code must first be instrumented
2.Trace Information is collected at runtime
3. Statement and block coverage are the same thing
4. block boundaries may not be that obvious

代码覆盖最常用的是语句覆盖,过程覆盖和表达覆盖

语句覆盖(模块覆盖 block coverage)
模块是由一系列语句构成的,只要执行其中一条语句,整
个模块就会随之执行。

Sample. Block vs. statement execution
if (dtack == l'b1 ) begin: acked
as       <= 1'b0;
data     <= l6'hZZZZ;
bus_rq <= l'b0;
state    <= IDLE;
end

The block named acked is executed entirely
whenever the expression in the if statement
evaluates to TRUE.

语句覆盖 (Statement Coverage)
语句覆盖用来计算在测试的过程中共有多少
行代码得到了执行,它提供一个图形用户接口来
显示所有的源代码,以及有那些语句没有执行。

Example of statement coverage.
√ if (Parity == ODD||parity == EVEN) begin
□ tx <= compute_Parity(data, parity);
□ # ( tx_time );
□ end
√ tx<=l'b0;
√ #(tx_time);
√ if(stop_bits==2) begin
√ tx<=1'b0;
√ #(tx_time);
√ end
紫色為未執行區

无法执行的代码是无效的,删除无效代码可减少无序性,增加源程序可维护性。



过程覆盖(Path Coverage)
There is more than one way to execute a sequence of statements.
Path coverage measures all possible ways you can execute a
sequence of statements.




表达覆盖 Expression Coverage
两个相互独立的条件可以使第一条if语句引起then语句的执行。
表达覆盖就是统计执行一段代码的方法数。尽管语句覆盖已达
100%,表达覆盖却只有50%。


FSM  Coverage 
針對FSM中所有可能的轉移路徑來看
0. Power reset =1
1. Reset -> A/C =2
2. A/B/C/D -> A/B/C/D = 7
3. A/B/C/D -> Reset =4
共有14種狀態的路徑




  What Does 100 Percent Coverage Mean?
 •  代码覆盖表示的是测试过程对源代码的覆盖程度,但
它并不能辨别测试过程是否正确。
•  对代码覆盖的结果进行描述时应该有所保留。这些结
果可以用来鉴别没有被测试的特殊情况,或用来检测
在执行的过程中出现的特征。
•  代码覆盖可以体现测试工作的全面性,可以了解测试
范围有多广,但这并不是唯一的指标。
•  代码覆盖率较低表明测试工作尚未完成,但代码覆盖
率较高并不就表明测试工作已经完成。

2011年10月12日 星期三

Digital Circuit Functional Verification(十二)

波形顯示器 (WAVEFORM VIEWERS)

用來看simulation waveform的軟體,一般模擬器都會附上基本的waveform viewer
並且與simulator一起提供debug的功能

最有名的商用的waveform viewer是nWave
是台灣思源科技所開發
並與其debussy/verdi一起提供強大的debug功能

為一要注意的是
Do not use a waveform viewer to determine if a
design passes or fails.

2011年10月11日 星期二

Digital Circuit Functional Verification(十一)

第三方模型 (THIRD-PARTY MODELS)

—Board-level designs should also be simulated.
板级的设计通常都包括从第三方买来的部件,有时
这些部件是可编程的,如存储器,PLD,和FPGA。必
须对设计进行测试,以保证ASIC之间,和第三方部件之
间能够兼容。
—You can buy models for standard parts
—It is cheaper to buy models than write them yourself
—Your model is not as reliable as the one you buy.


1 硬件模块 (Hardware Modelers)
—What if you cannot find a model to buy?
You may be faced with procuring a model for a device that is
so new or so complex, that no provider has had time to develop
a reliable model for it.
—You can "plug" a chip into a simulator.
A hardware modeler is a small box that connects to your
network. A real physical chip that needs to be simulated is
plugged in it.

Hardware modelers  are  also  very  useful  when  simulating  a  model
of  the  part  at  the  required  level  of  abstraction.
  A  full-functional
model  of  a  modern  processor  that  can  fetch,  decode  and  execute
instructions  could  not  realistically  execute  more  than   1000  to  5000
instructions  within  an  acceptable  time  period.  The  real  physical
device  can  perform  the  same  task  in  a  few  milliseconds.  Using  a
hardware  modeler  can  greatly  speed  up  board-  and  system-level
simulation.


2011年10月10日 星期一

Digital Circuit Functional Verification(十)

模拟 (SIMULATORS)
A. 在实现前模拟,可以及时的发现错误,改正错误
B. 模拟是现实近似。为了降低难度,模拟中很多特征都
简化了,甚至被忽略。(Analog較常發生)
C. 模拟实际能实现的是对设计的说明进行,而且还必须
以严格的语法来说明。
D. 不能确定模拟和实际的差别。不能证明模拟完全无
错,其功能的正确性和模型的精确性始终值得怀疑。

1 激励与响应 (Simulation requires stimulus)
•  模拟要求提供一个测试平台
•  目标是如何建立测试平台。
•  测试平台提供设计所需的输入,模拟器依据设计会作出响应。
•  设计者本人根据模拟器的输出结果来判断设计的正确性。
•  在一定条件下给了模拟器一个激发信号后,检查其输出,判断
其响应是否符合要求。

2 事件驱动模拟 (Event-Driven Simulation )
—Simulators are never fast enough.
—Outputs change only when an input changes.
只有输入变化时才进行模拟。因此模拟程序是由输
入的变化驱动的,称事件驱动。

• 输入变化,即使输出不变化,也进行模拟
• 满足事件触发条件

3 基于时钟周期的模拟 (Cycle-Based   Simulation)
— Cycle-based simulators collapse combinatorial logic into
equations.
• When the circuit description is compiled, all combinatorial
functions are collapsed into a single expression that can be used
to determine all flip-flop input values based on the current state of
the fan-in flip-flops.
• During simulation, whenever the clock input rises, the value of all
flip-flops is updated using the input value returned by the pre-
compiled combinatorial input functions.

—Cycle-based simulations have no timing information.
• This great improvement in simulation performance comes at a
cost: all timing and delay information is lost. 不考虑定时与延迟信息
• Cycle-based simulators assume that the entire design meets the
set-up and hold requirements of all the flip-flops. 设计满足触发器
建立和保时的时间要求
• When using a cycle-based simulator, timing is usually verified
using a static timing analyzer. 基于时钟周期的模拟,使用静态时序
分析器分析时序

— Cycle-based simulators can only handle synchronous
circuits. (仅能用于同步电路)
•  Cycle-based simulators further assume that the active clock edge
is the only significant event in changing the state of the design. 有
效的时钟边沿触发状态改变
•  All other inputs are assumed to be perfectly synchronous with the
active clock edge. 所有输入被有效的时钟边沿同步
•  Therefore, cycle-based simulators can only simulate perfectly
synchronous designs. 仅能用于同步设计
•  Anything containing asynchronous inputs, latches, or multiple-
clock domains cannot be simulated accurately. 


4 共同模拟Co-Simulators
设计中的同步部份用的是时钟驱动,而其它部份用的是事件驱
动。两种模拟结合起来共同完成模拟功能。
 Multiple simulators can handle separate portions of a design

—All simulators operate in locked-step.
• During co-simulation, all simulators involved progress along the time
axis in lock-step.
• All are at simulation time T1 at the same time and reach the next
time T2 at the same time.
• This implies that the speed of a co-simulation environment is limited
by the slowest simulator.
—Performance  is  decreased  by  the  communication  and
synchronization overhead.
—Translating  values  and  events  from  one  simulator  to
another can create ambiguities.

Co-simulation should no be confused with single-kernel
simulation

IP核互连策略的歷史

參考網頁http://www.dzsc.com/data/html/2007-4-30/34764.html

我之所以稱它為歷史,是因為目前基本上都被ARM的AMBA所吃掉
其它規格所佔的百分比太小,以至於基本的IP都會支援ARM BUS

PCI BUS主要在PC系統
ARM BUS主宰Mobile系統

文中轉貼

主要的IP核互连规范
目前有较大影响的IP核互连规范有IBM的CoreConnect 总线、ARM的AMBA(Advanced MicroController Bus Architecture)、Silicore Corp的Wishbone、开放核心协议国际联合(OCP-IP)的OCP (Open Core Protocol)与虚拟插座接口连盟VSIA (Virtual Socket Interface Alliance)的VCI(Virtual Component Interface)、Altera的Avalon 总线, 以及PlamchIP的CoreFrame 、MIPS的EC(tm) Interface, Altera的Atlantic(tm) Interface、IDT的IPBus(tm) (IDT Peripheral Bus) 、Sonics的SiliconBackplane(tm) uNetwork等等,新的互连方案如基于PCI的方案也在积极发展中



另可參考http://tw.myblog.yahoo.com/renaissance-flyingsquirrel/article?mid=33&prev=34&next=29&page=1

IP再用方法手冊Reuse Methodology Manual (RMM)是個不錯的參考文件
 




2011年10月9日 星期日

Digital Circuit Functional Verification(九)

检错工具 ( LlNTING TOOLS )

•  检错(lint)一词源于一个专门用来检测C语言程序错误的UNIX设
备。当Dennis Ritchie最开始发明C语言的时候,它并不象现在的
ANSI-C和C++这么安全可靠,也比不上Pascal和ADA。检错程序
允许编程者尽可能快的发现常规错误,而不是在测试的过程中发
现了致命错误以后才知道。

—Linting tools find common programmer mistakes.
• 检错程序能够找到错误,使编程者能在执行程序或发生重大错误
之前改正它们。运行时检错将需要一个运行时的调试程序,并且
要花好几分钟,而检错程序则只需要几秒钟,后者效率更高。

检错程序的优点:
不需要激发,也不要说明期望的输出结果。它们的检错完全是静
态进行的,本身就自带了期望的输出结果。

在IC設計上, 我們一般使用Linting tools 來找出設計上對映到合成器上的錯誤,
就是在未使用合成器時,就可以很簡單的找出設計上的不可合成點。
以減少後面作合成後再回來修正設計的時間。

检错程序的局限性
•    检错程序并不能找出源代码中的所有错误,它只是通过分析源代
码的结构来判断何处出错,而算法错误和数据流错误则发现不
了。
•    检错程序在检错时有时表现得很固执。为了避免犯II型错误—即肯
定为错,常常犯检查出并不存在的错误,结果导致I型错误—否定
为错。

解决方法
•  细心过滤错误信息 :分析输出结果,把那些事实上不存在的错
误排除掉,就不必为查找根本没有的错误而浪费时间。更重要
的是,它可以避免一个真正的错误随着众多的假错误被忽略。
•  正确的命名习惯有助于判断一个警告是否值得注意
•  对于检查潜在的真实错误来说,逐行检查仍具有不可替代的作
用。
•  编写源代码时就应该检错。判断一个错误的真假的最好时间是
在刚写完代码的时候。
•  保证代码的可读性和可维护性
此處包含了coding Style的必要性與實用性。在許多的小型設計公司,
扔會忽略了此處的重要性,以至於發生了許多奇怪的錯誤現象。 

代码检查 (Code Reviews)  • 代码检查是由人工完成的
• 作用:在测试和模拟之前找出功能错误和编码格式错误。
• 为了找出自动检错工具发现不了的错误,源代码将由多人过目。
• 可通过代码检查来评估一个源文件的可维护性以及其代码的正确
性,还能发现编码格式方面的问题。
• 能完全读懂代码,很容易找到功能错误及疏忽遗漏之处。
此處由Designer互相檢查,或由manager來實行