dSPACE FAQ 271 FAQ 271 Alternatives for the User-Code and User-Make file Keywords User-Code file; USR.C File; <model>_usr.c; User-Code; Real-Time Workshop® Custom Code library; Simulink® Coder Custom Code library; custcode; user makefile; USR.MK File; <model>_usr.mk; Configuration Parameters page “Real-Time Workshop > Custom Code” Question Are there any known alternatives for replacing the user-code file functions (<model>_usr.c) and user-makefile (<model>_usr.mk) directives? Is it possible to specify settings of the User-Code file (<model>_usr.c) and User-Make file inside the model? Solution User-Code File The template user-code file contains the following C functions, which are automatically called by RealTime Interface (RTI). As an alternative to the user-code file, you can use blocks from the Real-Time Workshop/Simulink Coder Custom Code library (type ‘custcode’ to open the block library) or the Configuration Parameter’s custom code page (beneath Real-Time Workshop (with Real-Time Workshop) or Code generation (with Simulink Coder)). Unlike the user-code file, the Real-Time Workshop/Simulink Coder Custom Code blocks or the custom code settings of the Configuration Parameters are part of the model configuration and are not stored in a separate file. This makes model sharing easier: #include directives for header files Copy the pre-processor directives from the beginning of the user-code file to the Top of Model Source edit field of the Model Source Custom Code block from the Real-Time Workshop/Simulink Coder Custom Code library or copy the pre-processor directives from the beginning of the User-Code file to the Source file edit box when the option Source file for Include custom c-code in generated: of the Configuration Parameter’s page Custom Code has been set before. usr_initialize() Copy the function body of usr_initialize() to the Exit Code edit field of the System Start Function Custom Code block from the Real-Time Workshop/Simulink Coder Custom Code library. or copy the function body of usr_initialize() to the Initialize function edit box when the option Initialize function for Include custom c-code in generated: of the Configuration Parameter’s page Custom Code has been set before. usr_sample_input() There is no alternative available to generate code to the location where usr_sample_input() is called by RTI. usr_input() There is no adequate alternative to generate code to the location where usr_input() is called by RTI. But it is nearly the same to copy the function body of usr_input() to the Declaration Code edit field of the System Outputs Function Custom Code block from the Real-Time Workshop/Simulink Coder Custom Code library. usr_output() Copy the function body of usr_output() to the Exit Code edit field of the System Outputs Function Custom Code block from the Real-Time Workshop/Simulink Coder Custom Code library. Alternatives for the User-Code and User-Make file FAQ Version: 2 / 2017-07-13 Page 1 dSPACE FAQ 271 usr_terminate() Copy the function body of usr_terminate() to the Exit Code (or Execution Code) edit field of the System Terminate Function Custom Code block from the Real-Time Workshop/Simulink Coder Custom Code library or copy the function body of usr_terminate() to the Terminate function’ edit box when the option Terminate function for Include custom c-code in generated: of the Configuration Parameter’s page Custom Code has been set before. usr_background() Copy the function body of usr_background() to the Exit Code (or Execution Code) edit field of the System Outputs Function Custom Code block from the Real-Time Workshop/Simulink Coder Custom Code library and place it in a Function-Call subsystem triggered by the Background block of the RTI TaskLib library with all checkbox activated. The communication between the Real-Time Workshop/Simulink Coder Custom Code library blocks and the Simulink model is based on Data Store blocks in the same manner as documented for the User-Code (User C code) Related dSPACE HelpDesk documents Implementing User-Code in the RTI and RTI-MP Implementation Guide User-Code File (USR.C File) in the RTI and RTI-MP Implementation Guide User-Makefile The template user makefile contains the following directives and lets you modify the standard build process by defining additional paths, files and dependencies. As an alternative to the user makefile you can use Configuration Parameter’s custom code page (beneath Real-Time Workshop (with RealTime Workshop) or Code generation (with Simulink Coder)). It does not offer all the features of the RTI user makefile, but the most frequently used ones. Unlike the user makefile, the custom code settings are part of the model configuration and are not stored in a separate file. This makes model sharing easier. SFCN_DIR Copy the directory list of SFCN_DIR to the Include directories: edit box when the option Include directories for Include list of additional: of the Configuration Parameters page Real-Time Workshop > Custom Code has been set before. USER_SRCS Copy the file list of USER_SRCS to the Source file: edit box when the option Source files for Include list of additional: of the Configuration Parameters page Real-Time Workshop > Custom Code has been set before. USER_ASM_SRCS There is no alternative available in the Configuration Parameters dialog to replace this specific user makefile directive. USER_SRCS_DIR Copy the directory list of USER_SRCS_DIR to the Include directories: edit box when the option Include directories for Include list of additional: of the Configuration Parameters page Real-Time Workshop > Custom Code has been set before. USER_INCLUDES_PATH Copy the directory list of SFCN_DIR to the Include directories: edit box when the option Include directories for Include list of additional: of the Configuration Parameters page Real-Time Workshop > Custom Code has been set before. USER_OBJS There is no alternative available in the Configuration Parameters dialog to replace this specific user makefile directive. Alternatives for the User-Code and User-Make file FAQ Version: 2 / 2017-07-13 Page 2 dSPACE FAQ 271 USER_LIBS Copy the file list of USER_LIBS to the Source file: edit box when the option Source files for Include list of additional: of the Configuration Parameters page Real-Time Workshop > Custom Code has been chosen. <Dependencies> There is no alternative available in the Configuration Parameters dialog to replace this specific user makefile directive. As a further alternative to specify extra search paths, user libraries, user object files etc. it is possible to define a so called rtwmakecfg.m file which sets pertaining information for all models using a specific S-Function (FAQ 011). Related dSPACE HelpDesk documents Tips and Tricks for Custom C Code in the RTI and RTI-MP Implementation Guide User Makefile (USR.MK File) in the RTI and RTI-MP Implementation Guide Alternatives for the User-Code and User-Make file FAQ Version: 2 / 2017-07-13 Page 3 dSPACE FAQ 271 Related FAQs FAQ 011: Alternatives for the User-Code and User-Make file FAQ 013: Using Libraries with C-Coded S-Functions FAQ 212: Using Additional Source Files in S_Functions FAQ Overview http://www.dspace.com/go/faq Support To request support, please use the form at http://www.dspace.com/go/supportrequest Updates and Patches Software updates and patches are available at http://www.dspace.com/go/patches. dSPACE strongly recommends to use the most recent patches for your dSPACE installation. Important Notice This document contains proprietary information that is protected by copyright. All rights are reserved. The document may be printed for personal or internal use provided all the proprietary markings are retained on all printed copies. In all other cases, the document must not be copied, photocopied, reproduced, translated, or reduced to any electronic medium or machine-readable form, in whole or in part, without the prior written consent of dSPACE GmbH. © 2017 by: dSPACE GmbH Rathenaustraße 26 33102 Paderborn Germany This publication and the contents hereof are subject to change without notice. A list of registered dSPACE trademarks is available at: http://www.dspace.com/go/Trademarks Alternatives for the User-Code and User-Make file FAQ Version: 2 / 2017-07-13 Page 4
© Copyright 2026 Paperzz