Skip to content

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
# Component
id: eth_driver
instantiable:
  prefix: eth
config_file:
  - path: "config/ethernet_{{instance}}_init.h"
---
# Project
component:
  - id: eth_driver
    instance: [eth0]

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 for certain file formats that are known to be plaintext. File formats not listed below are treated as binary content and do not undergo transformation.

C and C++ Headers

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 allow the template configuration header to be valid C or C++ code. This enables use of the template configuration header for testing.

This content transformation is only applied to configuration files with the .h, .hh, .hpp or .hxx extension.

XML Files

The string {{instance}} is replaced with the instance name verbatim. This content transformation is only applied to configuration files with the .xml extension.

Back to top