⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simulink_rtdefs.h

📁 simlink应用实例
💻 H
📖 第 1 页 / 共 2 页
字号:

#if (SS_SIM && SS_MULTITASKING)
# error MATLAB/Simulink does not support MULTITASKING
#endif

/*===========================================================================*
 * END SECTION
 * CHECK PROPER USAGE
 *
 * Issue errors if incompatible modes have been selected
 *===========================================================================*/


/*===========================================================================*
 * BEGIN SECTION
 * DETERMINE GROUP DEFINES
 *
 * Group defines are derived from the "KEY DEFINES" listed and determined
 * in previous sections.
 *===========================================================================*/

#if ( SS_SFCN_LEVEL_1 || SS_SFCN_NORMAL || SS_GENERATED_S_FUNCTION )
# define SS_SFCN     (1)
#else
# define SS_SFCN     (0)
#endif


#define SS_SFCN_FOR_SIM (0)
#define SS_SFCN_FOR_RTW (0)
#if SS_SFCN
# if SS_SIM
  /*
   * Used for s-functions (user written or s-fcn target) that are being
   * compiled for use with simulink.dll (i.e., for a regular sim).  Includes:
   *      o build for use with normal simulation (via mex command)
   *
   *  but does not include:
   *
   *      o build for use with rtw (grt)
   */
#  undef  SS_SFCN_FOR_SIM
#  define SS_SFCN_FOR_SIM (1)
# else
#  undef  SS_SFCN_FOR_RTW
#  define SS_SFCN_FOR_RTW (1)
# endif
#endif

/*===========================================================================*
 * END SECTION
 * DETERMINE GROUP DEFINES
 *
 * Group defines are derived from the "KEY DEFINES" listed and determined
 * in previous sections.
 *===========================================================================*/

/*
 * Include headers for MATLAB API function prototypes (e.g. mxGetPr)
 */
#if SS_SL_INTERNAL
# if defined(RSIM_WITH_SL_SOLVER)
   /*
    * Run-time interface for Real-Time Workshop RSIM Full target.
    */
#  include "rt_matrx.h"
# else
   /*
    * Using within Simulink itself
    */
#  include <stdlib.h>
#  include <stdarg.h>
#  include "matrix.h"
# endif

#elif SS_SFCN_FOR_SIM
  /*
   * Used in simulation by sfunction
   */
# include <stdlib.h>
# include <stdarg.h>
# include "mex.h"
# if !defined(S_FUNCTION_NAME)
#   define _S_FUNCTION_NAME_NOT_DEFINED_BEFORE_SIMSTRUCT
# endif
#elif SS_SFCN_FOR_RTW
  /*
   * Used in RTW by sfunction
   */
# include "rt_matrx.h" /* S-function is being used with Real-Time Workshop */
#elif SS_RTW_INTERNAL
  /*
   * Run-time interface for Real-Time Workshop
   */
# if !defined(TYPEDEF_MX_ARRAY)
#  define TYPEDEF_MX_ARRAY
   typedef real_T mxArray;
# endif
#else
  /*
   * Error
   */
# error Unhandled case
#endif


/*===========================================================================*
 *===========================================================================*
 *===========================================================================*
 * WARNING: For maintainability:
 *
 * Conditional Compilation below this point should only depend on
 *    KEY DEFINES
 * or
 *    GROUP DEFINES
 * that where determined in the sections above.
 *
 * In particular, #if and #elif should only depend on the KEY DEFINES and/or
 * GROUP DEFINES.
 *
 * All the KEY DEFINES and GROUP DEFINES always have definitions.  Therefore,
 * the preprocessor directives defined(), #ifdef, and #ifndef are not needed
 * below, and their use indicates a likely maintainability problem.  The
 * only exception is the use of #ifndef in the standard technique for guarding
 * against multiple inclusion and multiple definition.
 *===========================================================================*
 *===========================================================================*
 *===========================================================================*/


/*
 * INHERITED_SAMPLE_TIME      - Specify for blocks that inherit their sample
 *                              time from the block that feeds their input.
 *
 * CONTINUOUS_SAMPLE_TIME     - A continuous sample time indicates that the
 *                              block executes every simulation step.
 *
 * VARIABLE_SAMPLE_TIME       - Specifies that this sample time is discrete
 *                              with a varying period.
 *
 * FIXED_IN_MINOR_STEP_OFFSET - This can be specified for the offset of either
 *                              the inherited or continuous sample time
 *                              indicating that the output does not change
 *                              in minor steps.
 */

#define INHERITED_SAMPLE_TIME      ((real_T)-1.0)
#define CONTINUOUS_SAMPLE_TIME     ((real_T)0.0)
#define VARIABLE_SAMPLE_TIME       ((real_T)-2.0)
#define MODEL_EVENT_SAMPLE_TIME    ((real_T)-3.0)
#define FIXED_IN_MINOR_STEP_OFFSET ((real_T)1.0)

#if SS_SL_INTERNAL
#define DISABLED_VARIABLE_NEXT_TIME (utGetMinusInf())
#endif

#define ssSampleAndOffsetAreTriggered(st,ot) \
((st == INHERITED_SAMPLE_TIME) && (ot == INHERITED_SAMPLE_TIME))

/*
 * _rtSolverNeedsReset
 */
#define _rtGetSolverNeedsReset(sflag) \
          (sflag)
#define _rtSetSolverNeedsReset(sflag) \
          (sflag) = ((int_T)1)

/*
 * _rtBlkStateChange
 */
#define _rtGetBlkStateChange(sflag) \
          (sflag)
#define _rtSetBlkStateChange(sflag) \
          (sflag) = 1U

/*
 * _rtGetT
 * _rtSetT
 */
#define _rtGetT(tPtr) (tPtr)[0]
#define _rtSetT(tPtr,val) (tPtr)[0] = (val)

/*
 * _rtIsMajorTimeStep
 * _rtIsMinorTimeStep
 */
#define _rtIsMajorTimeStep(tstep) ((tstep) == MAJOR_TIME_STEP)
#define _rtIsMinorTimeStep(tstep) ((tstep) == MINOR_TIME_STEP)

/*
 * _rtIsFirstInitCond
 */
#define _rtIsFirstInitCond(tPtr, tStart) \
     (_rtGetT(tPtr) == tStart)

/*
 * _rtGetSampleTimeTaskID
 */
#if TID_EQUALS_SAMPLE_TIME_INDEX
#  define _rtGetSampleTimeTaskID(stiPtr,sti) (sti)
#else
#  define _rtGetSampleTimeTaskID(stiPtr,sti) (stiPtr)[sti]
#endif

/*
 * _rtGetTaskTime
 */
#define _rtGetTaskTime(tPtr, tidPtr, tid) \
         (tPtr)[_rtGetSampleTimeTaskID(tidPtr,tid)]
#define _rtSetTaskTime(tPtr, tidPtr, tid, val) (tPtr)[tid] = (val)

/*
 * _rtSetSampleHitInTask
 */
#if SS_MULTITASKING || SS_SL_INTERNAL || SS_SFCN_FOR_SIM
# if !SS_SFCN
#  define _rtSetSampleHitInTask(shp, ns, t_j, t_i, hit) \
      (shp)[(t_j) + ((t_i) * (ns))] = (hit)
# else
#  define _rtSetSampleHitInTask(shp, ns, t_j, t_i, hit) \
           _rtSetSampleHitInTask_cannot_be_used_in_SFunctions
# endif
#endif

/*
 * _rtIsContinuousTask
 */
#if SS_SL_INTERNAL || SS_SFCN_FOR_SIM
 /*
  * During simulation, tid passed to S-functions is always 0 even in
  * multitasking mode
  */
# define _rtIsContinuousTask(shp,tid) shp[0]
#elif SS_MULTITASKING && SS_TID01EQ_EQUAL_ONE
# define _rtIsContinuousTask(shp,tid) \
           ((tid) <= 1)
#else
# define _rtIsContinuousTask(shp,tid) \
           ((tid) == 0)
#endif

/*
 * _rtIsSampleHit
 */
#if SS_MULTITASKING

# define _rtIsSampleHit(shp,stip,sts,sti,tid) \
      (_rtGetSampleTimeTaskID(stip,sti) == (tid))

#else

# define _rtIsSampleHit(shp,stip,sts,sti,tid) \
   (_rtIsMajorTimeStep(sts) && (shp[_rtGetSampleTimeTaskID(stip,sti)]))

#endif


/*
 * _rtIsSampleHitInTask
 */
#if SS_MULTITASKING || SS_SL_INTERNAL || SS_SFCN_FOR_SIM
# define _rtIsSampleHitInTask(ptshp, stip, nst, my_sti, tid) \
    ptshp[_rtGetSampleTimeTaskID(stip,my_sti) + \
          ((tid) * (nst))]
#else
# define _rtIsSampleHitInTask(ptshp, stip, nst, my_sti, tid) \
         rtIsSampleHitInTask_cannot_be_used_in_singletasking_mode
#endif

/*
 * _rtIsSpecialSampleHit
 */
#if SS_MULTITASKING || SS_SL_INTERNAL || SS_SFCN_FOR_SIM
/*
 * The ssIsSpecialSampleHit(S, my_sti, promoted_sti, tid) macro will be
 * "true" if the block is executing in a major time step in context of a
 * promoted sample time (promoted_sti) and we have a sample hit in the
 * original task (my_sti) which translates to:
 *    1) tid == tid_for(promoted_sti). It is required that this macro be
 *       invoked with in a ssIsSampleHit(S,promoted_sti,tid) to guarantee this
 *       case.
 *    2) Must be major time step.
 *    3) my_sti (the block's sti) has a sample hit at the current point in
 *       time.
 * Valid usage in an S-function would be:
 *	if (ssIsSampleHit(S, promoted_sti)) {
 *        if (ssIsSpecialSampleHit(S, my_sti, promoted_sti, tid)) {
 *        }
 *      }
 * providing prompted_sti is not the continuous task. If promoted_sti is
 * the continuous task, then the following must be used:
 *	if (ssIsContinuousTask(S, promoted_sti)) {
 *        if (ssIsSpecialSampleHit(S, my_sti, promoted_sti, tid)) {
 *        }
 *      }
 */
#  define _rtIsSpecialSampleHit(shp, ptshp, stip, nst, sts, sti, prom_sti, tid) \
   (_rtIsMajorTimeStep(sts) && \
     _rtIsSampleHitInTask(ptshp, stip, nst, sti, tid))
#else
#  define _rtIsSpecialSampleHit(shp, ptshp, stip, nst, sts, sti, prom_sti, tid) \
     _rtIsSampleHit(shp, stip, sts, sti, tid)
#endif

#endif /* __SIMULINK_RTDEFS_H__ */

/* [EOF] simulink_rtdefs.h */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -