ucb-bar / chisel2-deprecated

chisel.eecs.berkeley.edu
388 stars 90 forks source link

emulator supporting optional peripherals #120

Open jackbackrack opened 10 years ago

jackbackrack commented 10 years ago

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?

jeuneS2 commented 8 years ago

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.