Gowin Vol.3 第2部第9章 リスト9

class ArpFrame extends Bundle {
val hardwareType = UInt(16.W) // hrd
val protocolType = UInt(16.W) // pro
val hlen = UInt(8.W)
val plen = UInt(8.W)
val operation = UInt(16.W) // op
val sha = UInt(48.W)
val spa = UInt(32.W)
val tha = UInt(48.W)
val tpa = UInt(32.W)

def toUInt(): UInt = {
Cat(Seq(
FlipBytes(hardwareType),
FlipBytes(protocolType),
FlipBytes(hlen),
FlipBytes(plen),
FlipBytes(operation),
FlipBytes(sha),
FlipBytes(spa),
FlipBytes(tha),
FlipBytes(tpa),
).reverse)
}
def toBytes(): Vec[UInt] = {
Bytes(this.toUInt())
}
}
object ArpFrame {
def apply(value: UInt): ArpFrame = {
val header = Wire(new ArpFrame)
header.hardwareType := NetworkBytes(value, 0, 1)
header.protocolType := NetworkBytes(value, 2, 3)
header.hlen := NetworkBytes(value, 4, 4)
header.plen := NetworkBytes(value, 5, 5)
header.operation := NetworkBytes(value, 6, 7)
header.sha := NetworkBytes(value, 8, 13)
header.spa := NetworkBytes(value, 14, 17)
header.tha := NetworkBytes(value, 18, 23)
header.tpa := NetworkBytes(value, 24, 27)
header
}
}