~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/plugins/scriptedwizard/resources/matlab_csf/files/sfuntmpl.c

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * sfuntmpl_basic.c: Basic 'C' template for a level 2 S-function.
 
3
 */
 
4
 
 
5
 
 
6
/*
 
7
 * You must specify the S_FUNCTION_NAME as the name of your S-function
 
8
 * (i.e. replace sfuntmpl_basic with the name of your S-function).
 
9
 */
 
10
 
 
11
#define S_FUNCTION_NAME  sfuntmpl
 
12
#define S_FUNCTION_LEVEL 2
 
13
 
 
14
/*
 
15
 * Need to include simstruc.h for the definition of the SimStruct and
 
16
 * its associated macro definitions.
 
17
 */
 
18
#include "simstruc.h"
 
19
 
 
20
 
 
21
 
 
22
/* Error handling
 
23
 * --------------
 
24
 *
 
25
 * You should use the following technique to report errors encountered within
 
26
 * an S-function:
 
27
 *
 
28
 *       ssSetErrorStatus(S,"Error encountered due to ...");
 
29
 *       return;
 
30
 *
 
31
 * Note that the 2nd argument to ssSetErrorStatus must be persistent memory.
 
32
 * It cannot be a local variable. For example the following will cause
 
33
 * unpredictable errors:
 
34
 *
 
35
 *      mdlOutputs()
 
36
 *      {
 
37
 *         char msg[256];         {ILLEGAL: to fix use "static char msg[256];"}
 
38
 *         sprintf(msg,"Error due to %s", string);
 
39
 *         ssSetErrorStatus(S,msg);
 
40
 *         return;
 
41
 *      }
 
42
 *
 
43
 * See matlabroot/simulink/src/sfuntmpl_doc.c for more details.
 
44
 */
 
45
 
 
46
/*====================*
 
47
 * S-function methods *
 
48
 *====================*/
 
49
 
 
50
/* Function: mdlInitializeSizes ===============================================
 
51
 * Abstract:
 
52
 *    The sizes information is used by Simulink to determine the S-function
 
53
 *    block's characteristics (number of inputs, outputs, states, etc.).
 
54
 */
 
55
static void mdlInitializeSizes(SimStruct *S)
 
56
{
 
57
    /* See sfuntmpl_doc.c for more details on the macros below */
 
58
 
 
59
    ssSetNumSFcnParams(S, 0);  /* Number of expected parameters */
 
60
    if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
 
61
        /* Return if number of expected != number of actual parameters */
 
62
        return;
 
63
    }
 
64
 
 
65
    ssSetNumContStates(S, 0);
 
66
    ssSetNumDiscStates(S, 0);
 
67
 
 
68
    if (!ssSetNumInputPorts(S, 1)) return;
 
69
    ssSetInputPortWidth(S, 0, 1);
 
70
    ssSetInputPortRequiredContiguous(S, 0, true); /*direct input signal access*/
 
71
    /*
 
72
     * Set direct feedthrough flag (1=yes, 0=no).
 
73
     * A port has direct feedthrough if the input is used in either
 
74
     * the mdlOutputs or mdlGetTimeOfNextVarHit functions.
 
75
     * See matlabroot/simulink/src/sfuntmpl_directfeed.txt.
 
76
     */
 
77
    ssSetInputPortDirectFeedThrough(S, 0, 1);
 
78
 
 
79
    if (!ssSetNumOutputPorts(S, 1)) return;
 
80
    ssSetOutputPortWidth(S, 0, 1);
 
81
 
 
82
    ssSetNumSampleTimes(S, 1);
 
83
    ssSetNumRWork(S, 0);
 
84
    ssSetNumIWork(S, 0);
 
85
    ssSetNumPWork(S, 0);
 
86
    ssSetNumModes(S, 0);
 
87
    ssSetNumNonsampledZCs(S, 0);
 
88
 
 
89
    ssSetOptions(S, 0);
 
90
}
 
91
 
 
92
 
 
93
 
 
94
/* Function: mdlInitializeSampleTimes =========================================
 
95
 * Abstract:
 
96
 *    This function is used to specify the sample time(s) for your
 
97
 *    S-function. You must register the same number of sample times as
 
98
 *    specified in ssSetNumSampleTimes.
 
99
 */
 
100
static void mdlInitializeSampleTimes(SimStruct *S)
 
101
{
 
102
    ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);
 
103
    ssSetOffsetTime(S, 0, 0.0);
 
104
 
 
105
}
 
106
 
 
107
 
 
108
 
 
109
#define MDL_INITIALIZE_CONDITIONS   /* Change to #undef to remove function */
 
110
#if defined(MDL_INITIALIZE_CONDITIONS)
 
111
  /* Function: mdlInitializeConditions ========================================
 
112
   * Abstract:
 
113
   *    In this function, you should initialize the continuous and discrete
 
114
   *    states for your S-function block.  The initial states are placed
 
115
   *    in the state vector, ssGetContStates(S) or ssGetRealDiscStates(S).
 
116
   *    You can also perform any other initialization activities that your
 
117
   *    S-function may require. Note, this routine will be called at the
 
118
   *    start of simulation and if it is present in an enabled subsystem
 
119
   *    configured to reset states, it will be call when the enabled subsystem
 
120
   *    restarts execution to reset the states.
 
121
   */
 
122
  static void mdlInitializeConditions(SimStruct *S)
 
123
  {
 
124
  }
 
125
#endif /* MDL_INITIALIZE_CONDITIONS */
 
126
 
 
127
 
 
128
 
 
129
#define MDL_START  /* Change to #undef to remove function */
 
130
#if defined(MDL_START)
 
131
  /* Function: mdlStart =======================================================
 
132
   * Abstract:
 
133
   *    This function is called once at start of model execution. If you
 
134
   *    have states that should be initialized once, this is the place
 
135
   *    to do it.
 
136
   */
 
137
  static void mdlStart(SimStruct *S)
 
138
  {
 
139
  }
 
140
#endif /*  MDL_START */
 
141
 
 
142
 
 
143
 
 
144
/* Function: mdlOutputs =======================================================
 
145
 * Abstract:
 
146
 *    In this function, you compute the outputs of your S-function
 
147
 *    block. Generally outputs are placed in the output vector, ssGetY(S).
 
148
 */
 
149
static void mdlOutputs(SimStruct *S, int_T tid)
 
150
{
 
151
    const real_T *u = (const real_T*) ssGetInputPortSignal(S,0);
 
152
    real_T       *y = ssGetOutputPortSignal(S,0);
 
153
    y[0] = 2.0 * u[0];
 
154
}
 
155
 
 
156
 
 
157
 
 
158
#define MDL_UPDATE  /* Change to #undef to remove function */
 
159
#if defined(MDL_UPDATE)
 
160
  /* Function: mdlUpdate ======================================================
 
161
   * Abstract:
 
162
   *    This function is called once for every major integration time step.
 
163
   *    Discrete states are typically updated here, but this function is useful
 
164
   *    for performing any tasks that should only take place once per
 
165
   *    integration step.
 
166
   */
 
167
  static void mdlUpdate(SimStruct *S, int_T tid)
 
168
  {
 
169
  }
 
170
#endif /* MDL_UPDATE */
 
171
 
 
172
 
 
173
 
 
174
#define MDL_DERIVATIVES  /* Change to #undef to remove function */
 
175
#if defined(MDL_DERIVATIVES)
 
176
  /* Function: mdlDerivatives =================================================
 
177
   * Abstract:
 
178
   *    In this function, you compute the S-function block's derivatives.
 
179
   *    The derivatives are placed in the derivative vector, ssGetdX(S).
 
180
   */
 
181
  static void mdlDerivatives(SimStruct *S)
 
182
  {
 
183
  }
 
184
#endif /* MDL_DERIVATIVES */
 
185
 
 
186
 
 
187
 
 
188
/* Function: mdlTerminate =====================================================
 
189
 * Abstract:
 
190
 *    In this function, you should perform any actions that are necessary
 
191
 *    at the termination of a simulation.  For example, if memory was
 
192
 *    allocated in mdlStart, this is the place to free it.
 
193
 */
 
194
static void mdlTerminate(SimStruct *S)
 
195
{
 
196
}
 
197
 
 
198
 
 
199
/*======================================================*
 
200
 * See sfuntmpl_doc.c for the optional S-function methods *
 
201
 *======================================================*/
 
202
 
 
203
/*=============================*
 
204
 * Required S-function trailer *
 
205
 *=============================*/
 
206
 
 
207
#ifdef  MATLAB_MEX_FILE    /* Is this file being compiled as a MEX-file? */
 
208
  #include "simulink.c"    /* MEX-file interface mechanism */
 
209
#else
 
210
  #include "cg_sfun.h"     /* Code generation registration function */
 
211
#endif