SpinalHDL中Bundle與SystemVerilog中的packed struct很像,在某些場景下,與普通數(shù)據(jù)類型之間的連接賦值可以通過asBits,assignFromBits來實現(xiàn)。
》Bundle—>Bits 在SpinalHDL中,無論是哪種數(shù)據(jù)類型都是可以轉換成Bits類型,我們擴展Bundle類型定義的復雜數(shù)據(jù)類型也不例外,可以通過asBits函數(shù)將自定義的數(shù)據(jù)類型轉換成Bits數(shù)據(jù)類型。以下面所定義的數(shù)據(jù)類型為例:
case class port() extends Bundle with IMasterSlave { val data0=UInt(8 bits) val data1=Bits(8 bits) val last=Bool() override def asMaster(): Unit = { out(data0,data1,last) } }我們完全可以通過調用asBits函數(shù)將其轉換成Bits類型:
val portInst=port() valdata=portInst.asBits生成的Verilog代碼將對應:
assign data = {portInst_last,{portInst_data1,portInst_data0}};這里與SystemVerilog中的packed struct略不相同的是,在SystemVerilog中packed struct中先定義的元素排在最高位,而在SpinalHDL Bundle中先定義的元素在轉換成Bits時則是排在最低位,這與asBits函數(shù)的實現(xiàn)有關:
》Bits—>Bundle
Bits—>Bundle的轉換可以通過assignFromBits來實現(xiàn)。在SpinalHDL中針對Bundle類型,提供了三種不同的實現(xiàn):
assignFromBits(bits:Bits)—將bits整個賦值給Bundle,當bits位寬大于Bundle定義的位寬時,高位將抹去。
assignFromBits(bits:Bits,hi:Int,lo:Int)—將bits整個賦值給Bundle對應Bits的(hi down to lo),多余的位將抹去
assignFromBits(bits:Bits,offset:Int,bitCount:BitCount)—等價于assignFromBits(bits,offset:Int+bitCount.value,offset)
在和已有的一些Verilog/SystemVerilog接口進行對接時這些API還是很有作用的,可以方便的實現(xiàn)接口轉換以實現(xiàn)功能。
像下面的用法是等價的:
val dataIn=Bits(17 bits) val portInst=port() portInst.assignFromBits(dataIn) 等價于: portInst.data0:=dataIn(7downto 0) portInst.data1:=dataIn(15 downto 8) portInst.last:=dataIn(16)
valportData=Bits(16bits) valportLast=Bits(16bits) val portInst=port() portInst.assignFromBits(portData,15,0) portInst.last:=portLast 等價于 portInst.data0:=portData(7 downto 0) portInst.data1:=portData(15 downto 8) portInst.last:=portLast
下面的這個例子展示了如果通過這些方法調用SpinalHDL中的StreamArbiter來實現(xiàn)兩個port端口FragmentLock RR調度:
-
數(shù)據(jù)
+關注
關注
8文章
7166瀏覽量
89679 -
函數(shù)
+關注
關注
3文章
4346瀏覽量
63006 -
BITS
+關注
關注
0文章
4瀏覽量
8110
發(fā)布評論請先 登錄
相關推薦
JAVA語言的數(shù)據(jù)類型轉換
變量和數(shù)據(jù)類型PPT教程
labview音頻數(shù)據(jù)的類型與生成噪音的數(shù)據(jù)類型不一致。
關于數(shù)據(jù)類型轉換的問題
請問使用強制數(shù)據(jù)類型轉換函數(shù)的時候,數(shù)據(jù)類型type端該如何設置,才能使數(shù)據(jù)成功轉換類型?
如何利用一個函數(shù)將24位的數(shù)據(jù)類型轉換成32位的呢
SpinalHDL中Bundle與普通數(shù)據(jù)類型之間的連接賦值轉換
怎么把int類型的數(shù)據(jù)轉換成字符串?
C++之類型轉換函數(shù)詳解
SpinalHDL中Bundle數(shù)據(jù)類型的轉換
什么是數(shù)據(jù)類型轉換
GaussDB數(shù)據(jù)類型轉換介紹
![GaussDB<b class='flag-5'>數(shù)據(jù)類型</b><b class='flag-5'>轉換</b>介紹](https://file1.elecfans.com//web2/M00/89/37/wKgZomR9nNGAHTg_AADCo48eNrg051.png)
評論