編 者 按
SpinalHDL中Bundle與SystemVerilog中的packed struct很像,在某些場(chǎng)景下,與普通數(shù)據(jù)類型之間的連接賦值可以通過asBits,assignFromBits來(lái)實(shí)現(xiàn)。
》Bundle—>Bits 在SpinalHDL中,無(wú)論是哪種數(shù)據(jù)類型都是可以轉(zhuǎn)換成Bits類型,我們擴(kuò)展Bundle類型定義的復(fù)雜數(shù)據(jù)類型也不例外,可以通過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) } }我們完全可以通過調(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)換可以通過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è)例子展示了如果通過這些方法調(diào)用SpinalHDL中的StreamArbiter來(lái)實(shí)現(xiàn)兩個(gè)port端口FragmentLock RR調(diào)度:
-
Verilog
+關(guān)注
關(guān)注
28文章
1352瀏覽量
110441 -
bundled
+關(guān)注
關(guān)注
0文章
4瀏覽量
9120 -
數(shù)據(jù)類型
+關(guān)注
關(guān)注
0文章
236瀏覽量
13667
原文標(biāo)題:Bundle的轉(zhuǎn)換
文章出處:【微信號(hào):Spinal FPGA,微信公眾號(hào):Spinal FPGA】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
GaussDB 數(shù)據(jù)類型介紹
![GaussDB <b class='flag-5'>數(shù)據(jù)類型</b>介紹](https://file1.elecfans.com//web2/M00/89/36/wKgaomR9n2OAH_SBAADpw3AtE6c828.png)
JAVA語(yǔ)言的數(shù)據(jù)類型轉(zhuǎn)換
關(guān)于數(shù)據(jù)類型轉(zhuǎn)換的問題
怎么轉(zhuǎn)換連接數(shù)據(jù)類型?
在SpinalHDL中定義各種各樣的復(fù)合數(shù)據(jù)類型
SpinalHDL的UInt與SInt數(shù)據(jù)類型能夠進(jìn)行有符號(hào)/無(wú)符號(hào)數(shù)操作
SpinalHDL中Bundle與普通數(shù)據(jù)類型之間的連接賦值轉(zhuǎn)換
51單片機(jī)中的數(shù)據(jù)類型解析
![51單片機(jī)<b class='flag-5'>中</b>的<b class='flag-5'>數(shù)據(jù)類型</b>解析](https://file1.elecfans.com//web2/M00/A6/E6/wKgZomUMQSSAJVOnAAAamzHN2CY563.jpg)
vhdl數(shù)據(jù)類型
asBits函數(shù)如何轉(zhuǎn)換成Bits數(shù)據(jù)類型
什么是數(shù)據(jù)類型轉(zhuǎn)換
什么是數(shù)據(jù)類型轉(zhuǎn)換
![什么是<b class='flag-5'>數(shù)據(jù)類型</b><b class='flag-5'>轉(zhuǎn)換</b>](https://file.elecfans.com/web2/M00/94/9D/pYYBAGP8VbeAMbslAAAOd7Vzhyk300.jpg)
GaussDB數(shù)據(jù)類型轉(zhuǎn)換介紹
![GaussDB<b class='flag-5'>數(shù)據(jù)類型</b><b class='flag-5'>轉(zhuǎn)換</b>介紹](https://file1.elecfans.com//web2/M00/89/37/wKgZomR9nNGAHTg_AADCo48eNrg051.png)
評(píng)論