chisel2-deprecated icon indicating copy to clipboard operation
chisel2-deprecated copied to clipboard

emulator supporting optional peripherals

Open jackbackrack opened this issue 11 years ago • 1 comments

For Patmos, we use a customized emulator, such that we can a) initialize memories as needed and b) to emulate peripherals (e.g., external memory or the UART). The Chisel code instantiates I/O devices and the memory controller according to an XML configuration file.

The problem now is that simulating a peripheral only makes sense if it is actually present. If a module is absent, compilation fails, because signals that are accessed in the emulator code are missing. Editing the emulator every time the configuration changes would be a bad idea. A nicer way would be to have defines in the code generated by Chisel and use #ifdefs to optionally include the relevant code. I can do that with the following dirty hack:

val defineName = getClass().getName().replace('.', '_') Params.register(this, "", ValueParam("1;\n#define "+defineName+" //"));

It works, but code injection is probably not the most elegant way to get something done ;-)

Do you think that you could add a feature to Chisel achieve the same thing in a cleaner way? Alternatively, do you have suggestions on how to support optional modules efficiently?

jackbackrack avatar Feb 07 '14 18:02 jackbackrack

We have solved the problem for Patmos now with the help of an auxiliary header file. The code looks like this:

if (Driver.backend.isInstanceOf[CppBackend]) {
    val emuConfig = Driver.createOutputFile("emulator_config.h")
    for (d <- Devs) { emuConfig.write("#define IO_"+d.name.toUpperCase+"\n") }
    emuConfig.close();
}

That's a clean enough solution for my taste, so maybe the feature request can be closed.

jeuneS2 avatar Dec 08 '15 16:12 jeuneS2