Search code examples
vhdl

VHDL component and outputs based on generic


I have a system consisting out of several components that has to be attached to a bus. However to keep the system bus independent, I gave the system a generic bus port that I run through a bus specific module that translates between my system and a specific bus. Thus it is easy to connect the entire system to different buses by switching the translating module.

However I don't want to go through the hassle of connecting the system with the translation module every time. Thus I wonder if it is possible to instantiate a module from a generic parameter, and use its types for the outputs of the architecture.

The whole becomes clearer with a little illustration, my translator modules have the following "signature".

entity translate<BusName>
port(toSystem: out toSystem_t,
  fromSystem: in fromSystem_t,
  toBus: out to<BusName>_t,
  fromBus: in from<BusName>_t
end entity;

I now want to build an entity containing the system and a translator, based on a generic, somewhat like so:

entity entireSystem is
  generic(busType := translate<BusName>)
  port(toBus: out to<BusName>_t,
       fromBus: in from<BusName>_t)
end entity

architecture genArc of entireSystem is
   signal toTrans: fromSystem;
   signal fromTrans: toSystem;
begin
   system: system(toTrans,fromTrans)
   translator: translate<BusName>(
       fromTrans,
       toTrans,
       toBus,
       fromBus
   )
end architecture;

My problems are: Can I use a generic parameter to directly instantiate a component, or do I have to go the if generic=xxx generate path? Can I derive the type of ports from a generic parameter. It would be best if I can use one generic parameter to determine the ports and the entity, so that one can not pick wrong types for an entity by accidents. It would be fine to derive the types from the generic parameter with a function.


Solution

  • I don't think so, no.

    If you want to instantiate different things based on a generic, you have to use if..generate.

    The only influence that generics can have on the types of ports is that of changing the width. You can't switch between (say) an integer and a boolean based on a generic.