SpinalHDL中Bundle與SystemVerilog中的packed struct很像,在某些場(chǎng)景下,與普通數(shù)據(jù)類型之間的連接賦值可以通過(guò)asBits,assignFromBits來(lái)實(shí)現(xiàn)。
》Bundle—>Bits 在SpinalHDL中,無(wú)論是哪種數(shù)據(jù)類型都是可以轉(zhuǎn)換成Bits類型,我們擴(kuò)展Bundle類型定義的復(fù)雜數(shù)據(jù)類型也不例外,可以通過(guò)asBits函數(shù)將自定義的數(shù)據(jù)類型轉(zhuǎn)換成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) } }我們完全可以通過(guò)調(diào)用asBits函數(shù)將其轉(zhuǎn)換成Bits類型:
val portInst=port() valdata=portInst.asBits生成的Verilog代碼將對(duì)應(yīng):
assign data = {portInst_last,{portInst_data1,portInst_data0}};這里與SystemVerilog中的packed struct略不相同的是,在SystemVerilog中packed struct中先定義的元素排在最高位,而在SpinalHDL Bundle中先定義的元素在轉(zhuǎn)換成Bits時(shí)則是排在最低位,這與asBits函數(shù)的實(shí)現(xiàn)有關(guān):
》Bits—>Bundle
Bits—>Bundle的轉(zhuǎn)換可以通過(guò)assignFromBits來(lái)實(shí)現(xiàn)。在SpinalHDL中針對(duì)Bundle類型,提供了三種不同的實(shí)現(xiàn):
assignFromBits(bits:Bits)—將bits整個(gè)賦值給Bundle,當(dāng)bits位寬大于Bundle定義的位寬時(shí),高位將抹去。
assignFromBits(bits:Bits,hi:Int,lo:Int)—將bits整個(gè)賦值給Bundle對(duì)應(yīng)Bits的(hi down to lo),多余的位將抹去
assignFromBits(bits:Bits,offset:Int,bitCount:BitCount)—等價(jià)于assignFromBits(bits,offset:Int+bitCount.value,offset)
在和已有的一些Verilog/SystemVerilog接口進(jìn)行對(duì)接時(shí)這些API還是很有作用的,可以方便的實(shí)現(xiàn)接口轉(zhuǎn)換以實(shí)現(xiàn)功能。
像下面的用法是等價(jià)的:
val dataIn=Bits(17 bits) val portInst=port() portInst.assignFromBits(dataIn) 等價(jià)于: 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 等價(jià)于 portInst.data0:=portData(7 downto 0) portInst.data1:=portData(15 downto 8) portInst.last:=portLast
下面的這個(gè)例子展示了如果通過(guò)這些方法調(diào)用SpinalHDL中的StreamArbiter來(lái)實(shí)現(xiàn)兩個(gè)port端口FragmentLock RR調(diào)度:
-
數(shù)據(jù)
+關(guān)注
關(guān)注
8文章
7292瀏覽量
93408 -
函數(shù)
+關(guān)注
關(guān)注
3文章
4400瀏覽量
66382 -
BITS
+關(guān)注
關(guān)注
0文章
4瀏覽量
8280
發(fā)布評(píng)論請(qǐng)先 登錄
labview數(shù)據(jù)類型與PLC 數(shù)據(jù)類型之間的轉(zhuǎn)換(來(lái)自于寫入浮點(diǎn)數(shù)到匯川 PLC中的數(shù)據(jù)轉(zhuǎn)換關(guān)鍵的修改)
JAVA語(yǔ)言的數(shù)據(jù)類型轉(zhuǎn)換
變量和數(shù)據(jù)類型PPT教程
labview音頻數(shù)據(jù)的類型與生成噪音的數(shù)據(jù)類型不一致。
關(guān)于數(shù)據(jù)類型轉(zhuǎn)換的問(wèn)題
怎么轉(zhuǎn)換連接數(shù)據(jù)類型?
請(qǐng)問(wèn)使用強(qiáng)制數(shù)據(jù)類型轉(zhuǎn)換函數(shù)的時(shí)候,數(shù)據(jù)類型type端該如何設(shè)置,才能使數(shù)據(jù)成功轉(zhuǎn)換類型?
如何利用一個(gè)函數(shù)將24位的數(shù)據(jù)類型轉(zhuǎn)換成32位的呢
SpinalHDL中Bundle與普通數(shù)據(jù)類型之間的連接賦值轉(zhuǎn)換
怎么把int類型的數(shù)據(jù)轉(zhuǎn)換成字符串?
C++之類型轉(zhuǎn)換函數(shù)詳解
SpinalHDL中Bundle數(shù)據(jù)類型的轉(zhuǎn)換
什么是數(shù)據(jù)類型轉(zhuǎn)換

GaussDB數(shù)據(jù)類型轉(zhuǎn)換介紹

評(píng)論