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

class UdpContext extends Bundle {
val sourceMacAddress = UInt(48.W)
val destinationMacAddress = UInt(48.W)
val sourceAddress = UInt(32.W)
val destinationAddress = UInt(32.W)
val sourcePort = UInt(16.W)
val destinationPort = UInt(16.W)
val dataLength = UInt(16.W)
}

object UdpContext {
def apply(ethernet: EthernetHeader, ipv4: Ipv4Header, udp: UdpHeader): UdpContext = {
val context = Wire(new UdpContext)
context.sourceMacAddress := ethernet.source
context.destinationMacAddress := ethernet.destination
context.sourceAddress := ipv4.source
context.destinationAddress := ipv4.destination
context.sourcePort := udp.sourcePort
context.destinationPort := udp.destinationPort
context.dataLength := udp.dataLength
context
}
def default(): UdpContext = {
val context = Wire(new UdpContext)
context.sourceMacAddress := 0.U
context.destinationMacAddress := 0.U
context.sourceAddress := 0.U
context.destinationAddress := 0.U
context.sourcePort := 0.U
context.destinationPort := 0.U
context.dataLength := 0.U
context
}
}