Instantiable Components¶
By default, only a single copy of a component may be present in a project. However, certain use cases like driver initialization benefit from the ability to add multiple named instances of the same component to the project. Such components typically do not add source files to the project, but may contribute configuration headers and template contributions. For the driver initialization example, a typical usecase is that each instance registers itself using a template contribution, such that the core initialization code can be generated using a centralized template file to include calls to the initialization function of each instance.
A component is considered instantiable if the instantiable
key is set. A default prefix
has to be given, which is used as the default instance name in GUIs that allow users to add components. For instance, if the prefix is eth
, the GUI will propose instance names eth0
, eth1
etc.
Files added to the project by an instantiable component need to have instance-specific names to avoid collisions. The component references the file using {{instance}}
as a placeholder. In the SDK, the file replaces the placeholder with the prefix
. When copied to the project, the full instance name replaces the placeholder.
Example:
1 2 3 4 5 6 7 8 9 10 11 |
|
will copy the file config/ethernet_eth_init.h
from the SDK to ethernet_eth0_init.h
in the project config/
directory.
The {{instance}}
placeholder can also be used in define
and template_contribution
.
Configuration Files¶
When copying a configuration header file from an instantiable component to the project, the contents are also transformed. The string INSTANCE
is replaced with the uppercase transformation of the instance name. This allows for instance-specific configuration. The replacement string is different from the one used in the .slcc file in order to keep the template configuration header C code valid to ease testing.
This content transformation is only applied to configuration files with the .h
, .hh
, .hpp
or .hxx
extension, to avoid clobbering data in configuration headers that are not C/C++.