Hi,
I am making a command class extending Bundle, which contains "op" (operation).
In a code using this class, I want to compare "op" with defined MACROs like:
class bWrDMA_comm extends Bundle {
val addr = UInt(width=40)
val bytes = UInt(width=16)
val op = UInt(width=4)
}
// This is in C, but shows what I want to do.
#define NOP UInt("h_0", width=4)
#define WRITE UInt("h_1", width=4)
#define CLEAR UInt("h_2", width=4)
...
var cmd = new bWrDMA_comm
when (cmd.op === NOP) {
...
} .elsewhen (cmd.op === WRITE) {
...
} .elsewhen (cmd.op === CLEAR) {
...
} .otherwise {
...
}
However, I don't know what should I write in Chisel/scala.
First, I try to use "def" like:
class bWrDMA_comm extends Bundle {
val addr = UInt(width=40)
val bytes = UInt(width=16)
val op = UInt(width=4)
def NOP() = UInt("h_0", width=4)
def WRITE() = UInt("h_1", width=4)
def CLEAR() = UInt("h_2", width=4)
}
But this code failed in exeption error in executing an emulation.
Could you tell me the best way for this?
======== ERROR MESSAGES ========
[info] Running StdModules.mRemoteMM.main mWrDMA --genHarness --compile --test --backend c
[error] (run-main-0) Chisel.ChiselException: Node.getWidth() for node /*? in class StdModules.mRemoteMM.mWrDMA*/ Chisel.UInt(OUTPUT, width=None, connect to 0 inputs: ()) returns unknown width
Chisel.ChiselException: Node.getWidth() for node /*? in class StdModules.mRemoteMM.mWrDMA*/ Chisel.UInt(OUTPUT, width=None, connect to 0 inputs: ()) returns unknown width
at StdModules.ioAvlST_src.<init>(StdQsysIO.scala:27)
[trace] Stack trace suppressed: run 'last compile:run' for the full output.
java.lang.RuntimeException: Nonzero exit code: 1
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run 'last compile:run' for the full output.
[error] (compile:run) Nonzero exit code: 1
[error] Total time: 6 s, completed 2014/10/29 2:39:59
Thanks in advance.
Kentaro