Generate Source Files with Custom User Code Blocks
Starting with DaVinci Configurator Classic 6, user code blocks are no longer managed during source file generation. Instead, the User Code Blocks are now separated from the generated source files and can be provided as a separate input to the generation process. This approach allows you to provide user code blocks as a separate input, rather than relying on previously generated data.
User Code Blocks
User Code Blocks are special sections in the generated source files that are marked for user modifications. These blocks are preserved during subsequent code generations, allowing users to add custom code without losing their changes.
This example shows a user code block with filled-in data. User Code Blocks are generated by the DaVinci Configurator Classic and the content can be modified by the user after generation.
The DaVinci User Code Tool restores the modified user code after the DaVinci Configurator Classic has overwritten the files during the generation process.
/**********************************************************************************************************************
* DO NOT CHANGE THIS COMMENT! <USERBLOCK EcuM_GlobalConfigDefines> DO NOT CHANGE THIS COMMENT!
*********************************************************************************************************************/
/* If ECUM_USE_GENERATED_GLOBAL_CONFIG is STD_ON, the generated EcuM_GlobalConfigRoot will be used.
* Turn to STD_OFF if custom implementation shall be used. Therefore use the corresponding user blocks */
#define ECUM_USE_GENERATED_GLOBAL_CONFIG STD_ON
/**********************************************************************************************************************
* DO NOT CHANGE THIS COMMENT! </USERBLOCK> DO NOT CHANGE THIS COMMENT!
*********************************************************************************************************************/
Automatic User Code Restore After Generation
The DaVinci Configurator Classic can automatically restore the User Code Blocks after the generation and project generate-swct command.
To enable this, configure the folder containing your *.ucb user code backup files in the project settings under general → folders → userCodeBlocks:
"folders": {
"userCodeBlocks": "Config/UserCodeBlocks"
}
When this folder is configured, the user code is restored automatically:
-
After generation via GUI and CLI, the user code is restored into the
GenDataand (if configured)GenDataVttfolders. -
After
project generate-swct, the user code is restored into theTemplatesfolder.
The userCodeBlocks folder awaits a GenData folder, a GenDataVtt folder, and a Templates folder to be present in the same directory for a distinct restore of the user code blocks into the generated files.
If the userCodeBlocks folder is not configured, no automatic restore is performed and you must restore the user code manually as described in the following sections.
Extract User Code Blocks From Generated Files
If you want to extract user code blocks from existing generated files you can use the DaVinci User Code Tool with the store command.
$ dvuct.exe store -r=<PathToGenData> -u=<PathToUserCodeFiles>
This command extracts all user code blocks from the generated files located in <PathToGenData> and saves them into separate *.ucb files in the <PathToUserCodeFiles> directory.
To restore user code blocks automatically after generation, store the blocks from the source files in GenData, GenDataVtt, and Templates in a folder with the same name inside the userCodeBlocks folder configured in your project settings.
|
If the source folders are located in the same directory, you can also specify the common parent directory as |
Adding User Code Using the Tool CLI Manually
To fill the generated data with User Code Blocks, follow these steps:
-
Run the generation process with DaVinci Configurator Classic.
For BSW generation:
$ dvcfg-b.exe project generate --bsw-package=<PathToYourBswPackage> --project=<PathToYourProjectFile>For SWC Template and Contract Phase Header generation:
$ dvcfg-b.exe project generate-swct --bsw-package=<PathToYourBswPackage> --project=<PathToYourProjectFile> -
Start the DaVinci User Code Tool to restore the User Code Blocks into the generated files.
If you have configured the
userCodeBlocksfolder in your project settings, DaVinci Configurator Classic performs this restore step automatically after generation. You only need to run this command manually whenuserCodeBlocksis not configured.$ dvuct.exe restore -r=<PathToGenData> -u=<PathToUserCodeFiles> -
Check the generated files to ensure the User Code Blocks have been correctly inserted.