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

📄 simstruc.h

📁 simulink应用实例
💻 H
📖 第 1 页 / 共 5 页
字号:
#  error defined(MathWorks_h)
# endif
# if defined(FIPXT_SHARED_MODULE)
#  error defined(FIPXT_SHARED_MODULE)
# endif
#endif

#if (defined(NRT) && SS_MULTITASKING)
# error NRT does not support MULTITASKING
#endif

#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.
 *===========================================================================*
 *===========================================================================*
 *===========================================================================*/


/*===============================*
 * Defines for S-function blocks *
 *===============================*/

/*
 * DYNAMICALLY_SIZED - Specify for sizes entries that inherit their values
 * from the block that drives them.
 *
 * DYNAMICALLY_TYPED - Specify for input/output port data types that can
 * accept a variety of data types.
 *
 * SIMSTRUCT_VERSION - An integer which is the sizeof the SimStruct times
 * 10000 plus the version times 100. When updating version numbers within the
 * Matlab image, increment both level 1 and level 2 S-functions. Level 1
 * version cannot be in range 220 to 229.  This was the level 2 version in
 * Simulink 2.20 (R10)
 *
 * DYNAMIC_DIMENSION - Specify for input/output port dimension entries that
 * the port inherits its dimension from the block that drives it.
 */

#define ALWAYS_NEEDED          (0)
#define CONDITIONALLY_NEEDED   (1)
#define NEVER_NEEDED           (2)

#define DYNAMICALLY_SIZED            (-1)
#define DYNAMICALLY_TYPED            (-1)
#define SIMSTRUCT_VERSION_LEVEL1     (sizeof(SimStruct)*10000 + 214)
#define SIMSTRUCT_VERSION_LEVEL2     (sizeof(SimStruct)*10000 + 229)

#if SS_SL_INTERNAL || SS_SFCN_FOR_SIM
    #ifdef __cplusplus
    extern "C" {
    #endif
    extern const DimsInfo_T *DYNAMIC_DIMENSION;
    #ifdef __cplusplus
    }
    #endif
#else
#define DYNAMIC_DIMENSION NULL
#endif

#ifndef NUM_MAT_DIMS
#define NUM_MAT_DIMS                 (2)
#endif

#if SS_SL_INTERNAL
#if defined(RSIM_WITH_SL_SOLVER)
# define DISABLED_VARIABLE_NEXT_TIME  rtMinusInf
#else
# define DISABLED_VARIABLE_NEXT_TIME (utGetMinusInf())
#endif
#endif

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

/*
 * Task ID's ordering
 *      Continuous task
 *      Continuous but fixed in minor step task
 *      Discrete task 1
 *         ...
 *      Discrete task N
 *      Variable sample time task(s), offset is instance number.
 *
 * If continuous task is present then it's task ID is 0, otherwise the
 * first discrete task ID will be 0 if it is present, etc.
 * All blocks with varying sample times have same sample task period of -2,
 * and the offset is the instance number.
 *
 * The triggered blocks are not in the sample time table and have a task ID
 * of -1.
 */

#define TRIGGERED_TID           (-1)
#define CONSTANT_TID            (-2)
#define MODEL_EVENT_TID         (-3)


/*
 * ssSetNumSampleTimes(S,PORT_BASED_SAMPLE_TIMES) - Indicates that the sample
 * times are assigned on a per port basis.
 */
#if !SS_SFCN_LEVEL_1
# define PORT_BASED_SAMPLE_TIMES -1
#endif

/*
 * Frame enum
 */
typedef enum {
    FRAME_INHERITED = -1,
    FRAME_NO,
    FRAME_YES
} Frame_T;

typedef enum {
    BD_ERR_VALUE_NONE,
    BD_ERR_VALUE_WARNING,
    BD_ERR_VALUE_ERROR
} BDErrorValue;

/*===============================================*
 * General defines used only by the macros below *
 *===============================================*/


/*
 * Conversion routines for frame data storage
 */
#define NEG1_2BITS '\x03'
#define CONV_BITS2INT(val) \
          ( (((val) & 2U) != 0) ? FRAME_INHERITED : ((int)(val)) )
#define CONV_INT2BITS(val) \
          ( ((val) == FRAME_INHERITED) ? (NEG1_2BITS) : ((val) & 1U) )

/*=================================================================*
 * Defines used by Simulink.c when calling the S-function routines *
 *=================================================================*/
#if SS_SL_INTERNAL || SS_SFCN_FOR_SIM
# define SS_CALL_MDL_INITIALIZE_SAMPLE_TIMES        101
# define SS_CALL_MDL_INITIALIZE_CONDITIONS          102
# define SS_CALL_MDL_GET_TIME_OF_NEXT_VAR_HIT       103
# define SS_CALL_MDL_OUTPUTS                        104
# define SS_CALL_MDL_UPDATE                         105
# define SS_CALL_MDL_DERIVATIVES                    106
# define SS_CALL_MDL_TERMINATE                      107
# define SS_CALL_MDL_ZERO_CROSSINGS                 108
# define SS_CALL_MDL_GET_INPUT_PORT_WIDTH           109
# define SS_CALL_MDL_GET_OUTPUT_PORT_WIDTH          110
# define SS_CALL_MDL_SET_WORK_WIDTHS                111
# define SS_CALL_MDL_CHECK_PARAMETERS               112
# define SS_CALL_MDL_SET_INPUT_PORT_DATA_TYPE       113
# define SS_CALL_MDL_SET_OUTPUT_PORT_DATA_TYPE      114
# define SS_CALL_MDL_SET_INPUT_PORT_WIDTH           115
# define SS_CALL_MDL_SET_OUTPUT_PORT_WIDTH          116
# define SS_CALL_MDL_START                          117
# define SS_CALL_MDL_PROCESS_PARAMETERS             118
# define SS_CALL_MDL_RTW                            119
# define SS_CALL_MDL_SET_INPUT_PORT_COMPLEX_SIGNAL  120
# define SS_CALL_MDL_SET_OUTPUT_PORT_COMPLEX_SIGNAL 121
# define SS_CALL_MDL_SET_INPUT_PORT_SAMPLE_TIME     122
# define SS_CALL_MDL_SET_OUTPUT_PORT_SAMPLE_TIME    123
# define SS_CALL_RTW_GENERATED_ENABLE               124
# define SS_CALL_RTW_GENERATED_DISABLE              125
# define SS_CALL_MDL_SET_INPUT_PORT_DIMENSION_INFO  126
# define SS_CALL_MDL_SET_OUTPUT_PORT_DIMENSION_INFO 127
# define SS_CALL_MDL_SET_INPUT_PORT_FRAME_DATA      128
# define SS_CALL_MDL_PROJECTION                     129
# define SS_CALL_MDL_JACOBIAN                       130
# define SS_CALL_MDL_SET_DEFAULT_PORT_DIMENSION_INFO  131
# define SS_CALL_MDL_SET_DEFAULT_PORT_DATA_TYPES      132
# define SS_CALL_MDL_SET_DEFAULT_PORT_COMPLEX_SIGNALS 133
#endif

/*=================================================================*
 * Defines for use by External Mode during simulation              *
 *=================================================================*/
#ifndef ExtModeLogBlockMeth_def
#define ExtModeLogBlockMeth_def
typedef enum {
    /*
     * Called when the user request the trigger to be armed (i.e., after
     * the 'arm trigger' button is pressed and the trigger arm message
     * has successfully been handed off to ext_comm).
     */
    EXTLOGTASK_TRIG_ARM,

    /*
     * Called when the first point of a one-shot arrives.
     */
    EXTLOGTASK_INIT_EVENT,

    /*
     * Definitions:
     *  one-shot:    one buffer of data collected when the trigger fires.
     *  normal-mode: a series of one-shots
     *
     * When in normal mode, each buffer in the series, except for the last
     * buffer is consider to be an 'intermediate' buffer.  When the final
     * point of an intermediate buffer has arrived on the host, the
     * EXTLOGTASK_TERM_INTERMEDIATE_ONESHOT method is called.  When the
     * final point of the last buffer of the series arrives, the
     * EXTLOGTASK_TERM_SESSION is called.
     *
     * Note that when not in normal mode, the
     * EXTLOGTASK_TERM_INTERMEDIATE_ONESHOT method is never called.
     *
     * Also see EXTLOGTASK_TERM_SESSION.
     */
    EXTLOGTASK_TERM_INTERMEDIATE_ONESHOT,

    /*
     * Called when:
     *  o In normal mode and the last point of the last buffer in a one-shot
     *    series has arrived (i.e., this is the end of the current log session).
     *
     *  o When in one-shot mode and the final point arrives (again this is the
     *    end of the logging session since the one and only buffer has been
     *    acquired).
     *

⌨️ 快捷键说明

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