1 /* Copyright (C) 2013 Czech Technical University in Prague
4 * - Carlos Jenkins <carlos@jenkins.co.cr>
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
29 * Common trailer for all RPP S-Functions.
30 * This file is included at the tail of each S-Function file. It includes refactored and
31 * commonly repeated structures that pollute S-Functions implementations. It includes basic
32 * includes, required definitions, macro definitions, common functions implementations and
33 * documentation on optional functions and commented prototypes for optional model calls/hooks.
40 #ifndef S_FUNCTION_NAME
41 #error 'Please include this file inside an S-Function implementation.'
45 /* Function: mdlInitializeSizes ================================================
47 * The sizes information is used by Simulink to determine the S-function
48 * block's characteristics (number of inputs, outputs, states, etc.).
50 #ifdef UNUSED_MDLINITIALIZESIZES
51 static void mdlInitializeSizes(SimStruct *S)
58 /* Function: mdlInitializeSampleTimes ==========================================
60 * This function is used to specify the sample time(s) for your
61 * S-function. You must register the same number of sample times as
62 * specified in ssSetNumSampleTimes.
64 #ifdef UNUSED_MDLINITIALIZESAMPLETIMES
65 static void mdlInitializeSampleTimes(SimStruct *S)
72 #ifdef COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
73 static void mdlInitializeSampleTimes(SimStruct *S)
75 ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME);
76 ssSetOffsetTime(S, 0, 0.0);
77 #if defined(ssSetModelReferenceSampleTimeDefaultInheritance)
78 ssSetModelReferenceSampleTimeDefaultInheritance(S);
84 /* Function: mdlOutputs ========================================================
86 * In this function, you compute the outputs of your S-function
87 * block. Generally outputs are placed in the output vector(s),
88 * ssGetOutputPortSignal.
90 #ifdef UNUSED_MDLOUTPUTS
91 static void mdlOutputs(SimStruct *S, int_T tid)
94 UNUSED_PARAMETER(tid);
99 /* Function: mdlTerminate ======================================================
101 * In this function, you should perform any actions that are necessary
102 * at the termination of a simulation.
104 #ifdef UNUSED_MDLTERMINATE
105 static void mdlTerminate(SimStruct *S)
112 /* Function: mdlCheckParameters ================================================
114 * mdlCheckParameters verifies new parameter settings whenever parameter
115 * change or are re-evaluated during a simulation. When a simulation is
116 * running, changes to S-function parameters can occur at any time during
117 * the simulation loop.
119 * Note: this an optional function for S-Function, in contrast to the ones
120 * above. This is here just because header.c declares
121 * checkParametersMismatch() that uses this function in order to
122 * refactor that commonly used block of code.
124 #ifdef UNUSED_MDLCHECKPARAMETERS
125 static void mdlCheckParameters(SimStruct *S)
133 * Required S-function trailer
135 #ifdef MATLAB_MEX_FILE
136 # include "simulink.c"
138 # include "cg_sfun.h"