2018年3月23日 星期五

Systemverilog 筆記 - Interface

interface應該要是獨立的一個file,不要寫在module

modport 只是用來定義方向,不用標註型態跟大小

只有function可以合成,task,initial block,always block, assersion 都不能合成, task可以用void  function來取代, 如果有用到這些可以用synthesis translate_off, tanslate_on 或是`ifdef來控制

interface裡面也可以包含其他的interface

interfaceport 不能空接,不然會有elaboration error 

盡量使用短名,因為會經常被reference

interfacemodule有三點不同: interface裡面不能有階層設計,interface可以整個被當成一個port來連接在module上面,interface可以有modport

type-specific interface ports (module <module_name> (<interface_name> <port_name >), 不要用generic(module <module name> (interface <port_name>))

interface instance來指定modport (<interface_instance_name>.<modport_name >)
如果interface裡面沒有被指定modport,則所有的nets都會被預設為雙向的inout,simulation,變數都會被架設為ref(不可合成)

interface裡面的function 必須要寫automatic , modport 可以用import函數名稱, 來使用函數, 也可以在import時將整個函式的參數標示出來,以方便查詢, import 函式不用在寫一次automatic

如果兩個模組之間溝通訊號超過兩個,就可以考慮使用interface,如果信號不段重複,如網路轉接,則必須使用virtual interface

Interface 裡面的非同步訊號最好用logic,但是如果有多個drive,則需用wire

Interface 裡面必須要有clocking來產生同步的訊號,避免race condition ,但是clocking只能用在testbench,不能合成

一個interface可以包括多個clocking block,但是每個clocking block只能有一個clock domain,通常用@(posedge clk), @( clk)表示DDR double data rate,定義clcoking block以後,之後可以直接用@arbif.cb,好處是如果要修改clock,可以直接修改clocking block即可,不用再修改testbench

可以用@或是wait來同步testbench裡面的訊號

如果modportclocking一起在interface裡面,這樣如果要使用訊號,需要經過interface prefixclocking.所以看上面的例子arbif.cb.request是合法的

如果想要延遲兩個clock cycle 可以用 repeat (2) @arbif.cb 或是##2

clocking裡面也可以用#來做延遲,可以寫default  input #10ns output 15ns


沒有留言:

張貼留言