sfcn_bridge.h 7.84 KB
Newer Older
Maxime Perrotin's avatar
Maxime Perrotin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/*
 * Copyright 1994-2008 The MathWorks, Inc.
 *
 * File: sfcn_bridge.h     $Revision: 1.2.4.10 $
 *
 * Abstract:
 *   This file helps support a bridge between non-inlined S-functions
 *   and the rtModel. When we did not have the notion of an rtModel,
 *   non-inlined S-functions obtained model data by directly accessing
 *   the model's SimStruct. With the introduction of the rtModel, 
 *   this direct access is no longer possible. Therefore, we need to 
 *   redefine some of the macros inside simstruc.h to instead access
 *   fields of the rtModel. 
 */

#ifndef __SFCN_BRIDGE_H__
#define __SFCN_BRIDGE_H__

typedef struct {
    const char_T  **errorStatusPtr;
    
    int           *numRootSampTimesPtr;
    
    time_T        **tPtrPtr;
    time_T        *tStartPtr;
    time_T        *tFinalPtr;
    time_T        *tOfLastOutputPtr;
    time_T        *stepSizePtr;
    boolean_T     *stopRequestedPtr;
    boolean_T     *derivCacheNeedsResetPtr;
    boolean_T     *zcCacheNeedsResetPtr;
    boolean_T     *blkStateChangePtr;

    int_T         **sampleHitsPtr;
    int_T         **perTaskSampleHitsPtr;

    SS_SimMode    *simModePtr;
    
    RTWSolverInfo **siPtr;
} RTWSfcnInfo;

/* Get a type-cast sfcn info from the SimStruct */
#define _RTSS(S) ((RTWSfcnInfo *) ssGetRTWSfcnInfo(S))

/* Set/Get fields of the sfcn info */
#define rtssSetErrorStatusPtr(sfi,p) (sfi)->errorStatusPtr = (p)

#define rtssSetNumRootSampTimesPtr(sfi,p) (sfi)->numRootSampTimesPtr = (p)

#define rtssSetTPtrPtr(sfi,p)        (sfi)->tPtrPtr = (p)
#define rtssSetTStartPtr(sfi,p)      (sfi)->tStartPtr = (p)
#define rtssSetTFinalPtr(sfi,p)      (sfi)->tFinalPtr = (p)
#define rtssSetTimeOfLastOutputPtr(sfi,p) (sfi)->tOfLastOutputPtr = (p)
#define rtssSetStepSizePtr(sfi,p)    (sfi)->stepSizePtr = (p)
#define rtssSetStopRequestedPtr(sfi,p) (sfi)->stopRequestedPtr = (p)
#define rtssSetDerivCacheNeedsResetPtr(sfi,p) \
     (sfi)->derivCacheNeedsResetPtr = (p)
#define rtssSetZCCacheNeedsResetPtr(sfi,p) \
     (sfi)->zcCacheNeedsResetPtr = (p)
#define rtssSetBlkStateChangePtr(sfi,p) \
     (sfi)->blkStateChangePtr = (p)
#define rtssSetSampleHitsPtr(sfi,p) (sfi)->sampleHitsPtr = (p)
#define rtssSetPerTaskSampleHitsPtr(sfi,p) (sfi)->perTaskSampleHitsPtr = (p)

#define rtssSetSimModePtr(sfi,p)      (sfi)->simModePtr = (p)

#define rtssSetSolverInfoPtr(sfi,p)  (sfi)->siPtr = (p)

/* Error status defines */
#undef ssSetErrorStatus
#define ssSetErrorStatus(S,e) *(_RTSS(S)->errorStatusPtr) = (e)

#undef ssGetErrorStatus
#define ssGetErrorStatus(S)   *(_RTSS(S)->errorStatusPtr)

#undef ssGetNumRootSampleTimes
#define ssGetNumRootSampleTimes(S) *(_RTSS(S)->numRootSampTimesPtr)

/* Timing defines */
#undef ssGetTPtr
#define ssGetTPtr(S) *(_RTSS(S)->tPtrPtr)

#undef ssGetT
#define ssGetT(S) *(_RTSS(S)->tPtrPtr)[0]

#undef ssGetTStart
#define ssGetTStart(S) *(_RTSS(S)->tStartPtr)

#undef ssGetTFinal
#define ssGetTFinal(S) *(_RTSS(S)->tFinalPtr)

#undef ssGetTimeOfLastOutput
#define ssGetTimeOfLastOutput(S) *(_RTSS(S)->tOfLastOutputPtr)

#undef ssGetStepSize
#define ssGetStepSize(S) *(_RTSS(S)->stepSizePtr)

#undef ssSetStopRequested
#define ssSetStopRequested(S,v) *(_RTSS(S)->stopRequestedPtr) = (v)

#undef ssGetStopRequested
#define ssGetStopRequested(S) *(_RTSS(S)->stopRequestedPtr)

#undef ssSetDerivCacheNeedsReset
#define ssSetDerivCacheNeedsReset(S,v) \
     *(_RTSS(S)->derivCacheNeedsResetPtr) = (v)

#undef ssGetDerivCacheNeedsReset
#define ssGetDerivCacheNeedsReset(S) \
     *(_RTSS(S)->derivCacheNeedsResetPtr)

#undef ssSetZCCacheNeedsReset
#define ssSetZCCacheNeedsReset(S,v) \
     *(_RTSS(S)->zcCacheNeedsResetPtr) = (v)

#undef ssGetZCCacheNeedsReset
#define ssGetZCCacheNeedsReset(S) \
     *(_RTSS(S)->zcCacheNeedsResetPtr)

#undef ssSetBlkStateChange
#define ssSetBlkStateChange(S) *(_RTSS(S)->blkStateChangePtr) = true

#undef ssGetBlkStateChange
#define ssGetBlkStateChange(S) *(_RTSS(S)->blkStateChangePtr)

#undef ssGetSampleHitPtr
#define ssGetSampleHitPtr(S) *(_RTSS(S)->sampleHitsPtr)

#undef ssGetPerTaskSampleHitsPtr
#define ssGetPerTaskSampleHitsPtr(S) *(_RTSS(S)->perTaskSampleHitsPtr)
           
#undef ssGetSimMode
#define ssGetSimMode(S) *(_RTSS(S)->simModePtr)

/* Solver-related defines */
#undef ssGetSolverName
#define ssGetSolverName(S) \
   rtsiGetSolverName(*(_RTSS(S)->siPtr))

#undef ssIsVariableStepSolver
#define ssIsVariableStepSolver(S) \
   rtsiIsVariableStepSolver(*(_RTSS(S)->siPtr))

#undef ssSetSolverNeedsReset
#define ssSetSolverNeedsReset(S) \
   rtsiSetSolverNeedsReset(*(_RTSS(S)->siPtr), true)

#undef ssGetSolverNeedsReset
#define ssGetSolverNeedsReset(S) \
   rtsiGetSolverNeedsReset(*(_RTSS(S)->siPtr))

#undef ssGetSolverMode
#define ssGetSolverMode(S) \
   rtsiGetSolverMode(*(_RTSS(S)->siPtr))

#undef ssGetSolverMode
#define ssGetSolverMode(S) \
   rtsiGetSolverMode(*(_RTSS(S)->siPtr))

#undef ssGetSolverStopTime
#define ssGetSolverStopTime(S) \
   rtsiGetSolverStopTime(*(_RTSS(S)->siPtr))

#undef ssGetMinStepSize
#define ssGetMinStepSize(S) \
   rtsiGetMinStepSize(*(_RTSS(S)->siPtr))

#undef ssGetMaxStepSize
#define ssGetMaxStepSize(S) \
   rtsiGetMaxStepSize(*(_RTSS(S)->siPtr))

#undef ssGetSolverMaxConsecutiveMinStep
#define ssGetSolverMaxConsecutiveMinStep(S) \
   rtsiGetSolverMaxConsecutiveMinStep(*(_RTSS(S)->siPtr))

#undef ssGetFixedStepSize
#define ssGetFixedStepSize(S) \
   rtsiGetFixedStepSize(*(_RTSS(S)->siPtr))

#undef ssGetMaxNumMinSteps
#define ssGetMaxNumMinSteps(S) \
   rtsiGetMaxNumMinSteps(*(_RTSS(S)->siPtr))

#undef ssGetSolverRefineFactor
#define ssGetSolverRefineFactor(S) \
   rtsiGetSolverRefineFactor(*(_RTSS(S)->siPtr))

#undef ssGetSolverRelTol
#define ssGetSolverRelTol(S) \
   rtsiGetSolverRelTol(*(_RTSS(S)->siPtr))

#undef ssGetSolverAbsTol
#define ssGetSolverAbsTol(S) \
   rtsiGetSolverAbsTol(*(_RTSS(S)->siPtr))

#undef ssGetSolverMaxOrder
#define ssGetSolverMaxOrder(S) \
   rtsiGetSolverMaxOrder(*(_RTSS(S)->siPtr))

#undef ssGetSolverConsecutiveZCsStepRelTol
#define ssGetSolverConsecutiveZCsStepRelTol(S) \
   rtsiGetSolverConsecutiveZCsStepRelTol(*(_RTSS(S)->siPtr))

#undef ssGetSolverZcThreshold
#define ssGetSolverZcThreshold(S) \
   rtsiGetSolverZcThreshold(*(_RTSS(S)->siPtr))

#undef ssGetSolverZeroCrossAlgorithm
#define ssGetSolverZeroCrossAlgorithm(S) \
   rtsiGetSolverZeroCrossAlgorithm(*(_RTSS(S)->siPtr))


#undef ssGetSolverMaxConsecutiveZCs
#define ssGetSolverMaxConsecutiveZCs(S) \
   rtsiGetSolverMaxConsecutiveZCs(*(_RTSS(S)->siPtr))

#undef ssGetSolverExtrapolationOrder
#define ssGetSolverExtrapolationOrder(S) \
   rtsiGetSolverExtrapolationOrder(*(_RTSS(S)->siPtr))

#undef ssGetSolverNumberNewtonIterations
#define ssGetSolverNumberNewtonIterations(S) \
   rtsiGetSolverNumberNewtonIterations(*(_RTSS(S)->siPtr))

#undef ssGetSimTimeStep
#define ssGetSimTimeStep(S) \
   rtsiGetSimTimeStep(*(_RTSS(S)->siPtr))

#undef ssIsMinorTimeStep
#if NCSTATES > 0
#define ssIsMinorTimeStep(S) \
   (ssGetSimTimeStep(S) == MINOR_TIME_STEP)
#else
#define ssIsMinorTimeStep(S) (0)
#endif

#undef ssIsMajorTimeStep
#if NCSTATES > 0
#define ssIsMajorTimeStep(S) \
     (ssGetSimTimeStep(S) == MAJOR_TIME_STEP)
#else
#define ssIsMajorTimeStep(S) (1)
#endif

#undef ssGetTaskTime
#define ssGetTaskTime(S,sti) \
          (ssGetTPtr(S))[ssGetSampleTimeTaskID(S,sti)]

#undef ssIsSampleHit

#if SS_MULTITASKING

#if TID01EQ 
#define ssIsSampleHit(S,sti,tid) \
   ((ssGetSampleTimeTaskID(S,sti) == 1 ? \
     0:ssGetSampleTimeTaskID(S,sti)) == (tid))
#else 
#define ssIsSampleHit(S,sti,tid) \
  (ssGetSampleTimeTaskID(S,sti) == (tid)) 
#endif 

#else

#define ssIsSampleHit(S,sti,tid) \
     (ssIsMajorTimeStep(S) && (tid != CONSTANT_TID) &&\
            ((ssGetSampleHitPtr(S))[ssGetSampleTimeTaskID(S,sti)]))

#endif 

#undef  ssIsFirstInitCond
#define ssIsFirstInitCond(S) (ssGetT(S)==ssGetTStart(S))

#undef ssSetFirstInitCondCalled
#define ssSetFirstInitCondCalled(S) 

#undef ssClearFirstInitCondCalled
#define ssClearFirstInitCondCalled(S)

#endif /* __SFCN_BRIDGE_H__ */

/* [EOF] sfcn_bridge.h */