/* Include files */

#include "blascompat32.h"
#include "Master_sfun.h"
#include "c5_Master.h"
#define CHARTINSTANCE_CHARTNUMBER      (chartInstance.chartNumber)
#define CHARTINSTANCE_INSTANCENUMBER   (chartInstance.instanceNumber)
#include "Master_sfun_debug_macros.h"

/* Type Definitions */

/* Named Constants */
#define c5_IN_NO_ACTIVE_CHILD          (0)

/* Variable Declarations */

/* Variable Definitions */
static SFc5_MasterInstanceStruct chartInstance;

/* Function Declarations */
static void initialize_c5_Master(void);
static void initialize_params_c5_Master(void);
static void enable_c5_Master(void);
static void disable_c5_Master(void);
static void c5_update_debugger_state_c5_Master(void);
static const mxArray *get_sim_state_c5_Master(void);
static void set_sim_state_c5_Master(const mxArray *c5_st);
static void finalize_c5_Master(void);
static void sf_c5_Master(void);
static void init_script_number_translation(uint32_T c5_machineNumber, uint32_T
  c5_chartNumber);
static const mxArray *c5_sf_marshall(void *c5_chartInstance, void *c5_u);
static const mxArray *c5_b_sf_marshall(void *c5_chartInstance, void *c5_u);
static const mxArray *c5_c_sf_marshall(void *c5_chartInstance, void *c5_u);
static uint8_T c5_emlrt_marshallIn(const mxArray *c5_Tx, char *c5_name);
static uint8_T c5_b_emlrt_marshallIn(const mxArray *c5_flag, char *c5_name);
static uint8_T c5_c_emlrt_marshallIn(const mxArray *c5_b_is_active_c5_Master,
  char *c5_name);
static void init_io_bus_offset(void);
static void init_dsm_address_info(void);

/* Function Definitions */
static void initialize_c5_Master(void)
{
  _sfTime_ = (real_T)ssGetT(chartInstance.S);
  chartInstance.c5_is_active_c5_Master = 0U;
}

static void initialize_params_c5_Master(void)
{
}

static void enable_c5_Master(void)
{
  _sfTime_ = (real_T)ssGetT(chartInstance.S);
}

static void disable_c5_Master(void)
{
  _sfTime_ = (real_T)ssGetT(chartInstance.S);
}

static void c5_update_debugger_state_c5_Master(void)
{
}

static const mxArray *get_sim_state_c5_Master(void)
{
  const mxArray *c5_st = NULL;
  const mxArray *c5_y = NULL;
  uint8_T c5_u;
  const mxArray *c5_b_y = NULL;
  uint8_T c5_b_u;
  const mxArray *c5_c_y = NULL;
  uint8_T c5_c_u;
  const mxArray *c5_d_y = NULL;
  uint8_T *c5_Tx;
  uint8_T *c5_flag;
  c5_flag = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 2);
  c5_Tx = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 1);
  c5_st = NULL;
  c5_y = NULL;
  sf_mex_assign(&c5_y, sf_mex_createcellarray(3));
  c5_u = *c5_Tx;
  c5_b_y = NULL;
  sf_mex_assign(&c5_b_y, sf_mex_create("y", &c5_u, 3, 0U, 0U, 0U, 0));
  sf_mex_setcell(c5_y, 0, c5_b_y);
  c5_b_u = *c5_flag;
  c5_c_y = NULL;
  sf_mex_assign(&c5_c_y, sf_mex_create("y", &c5_b_u, 3, 0U, 0U, 0U, 0));
  sf_mex_setcell(c5_y, 1, c5_c_y);
  c5_c_u = chartInstance.c5_is_active_c5_Master;
  c5_d_y = NULL;
  sf_mex_assign(&c5_d_y, sf_mex_create("y", &c5_c_u, 3, 0U, 0U, 0U, 0));
  sf_mex_setcell(c5_y, 2, c5_d_y);
  sf_mex_assign(&c5_st, c5_y);
  return c5_st;
}

static void set_sim_state_c5_Master(const mxArray *c5_st)
{
  const mxArray *c5_u;
  uint8_T *c5_Tx;
  uint8_T *c5_flag;
  c5_flag = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 2);
  c5_Tx = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 1);
  chartInstance.c5_doneDoubleBufferReInit = true;
  c5_u = sf_mex_dup(c5_st);
  *c5_Tx = c5_emlrt_marshallIn(sf_mex_dup(sf_mex_getcell(c5_u, 0)), "Tx");
  *c5_flag = c5_b_emlrt_marshallIn(sf_mex_dup(sf_mex_getcell(c5_u, 1)), "flag");
  chartInstance.c5_is_active_c5_Master = c5_c_emlrt_marshallIn(sf_mex_dup
    (sf_mex_getcell(c5_u, 2)), "is_active_c5_Master");
  sf_mex_destroy(&c5_u);
  c5_update_debugger_state_c5_Master();
  sf_mex_destroy(&c5_st);
}

static void finalize_c5_Master(void)
{
}

static void sf_c5_Master(void)
{
  uint8_T c5_previousEvent;
  boolean_T c5_D;
  uint8_T c5_Rx1;
  boolean_T c5_op;
  real_T c5_nargout = 2.0;
  real_T c5_nargin = 3.0;
  uint8_T c5_flag;
  uint8_T c5_Tx;
  boolean_T *c5_b_D;
  uint8_T *c5_b_Tx;
  uint8_T *c5_b_flag;
  uint8_T *c5_b_Rx1;
  boolean_T *c5_b_op;
  c5_b_flag = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 2);
  c5_b_D = (boolean_T *)ssGetInputPortSignal(chartInstance.S, 0);
  c5_b_op = (boolean_T *)ssGetInputPortSignal(chartInstance.S, 2);
  c5_b_Tx = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 1);
  c5_b_Rx1 = (uint8_T *)ssGetInputPortSignal(chartInstance.S, 1);
  _sfTime_ = (real_T)ssGetT(chartInstance.S);
  _SFD_CC_CALL(CHART_ENTER_SFUNCTION_TAG,4);
  _SFD_DATA_RANGE_CHECK((real_T)*c5_b_D, 0U);
  _SFD_DATA_RANGE_CHECK((real_T)*c5_b_Tx, 1U);
  _SFD_DATA_RANGE_CHECK((real_T)*c5_b_flag, 2U);
  _SFD_DATA_RANGE_CHECK((real_T)*c5_b_Rx1, 3U);
  _SFD_DATA_RANGE_CHECK((real_T)*c5_b_op, 4U);
  c5_previousEvent = _sfEvent_;
  _sfEvent_ = CALL_EVENT;
  _SFD_CC_CALL(CHART_ENTER_DURING_FUNCTION_TAG,4);
  c5_D = *c5_b_D;
  c5_Rx1 = *c5_b_Rx1;
  c5_op = *c5_b_op;
  sf_debug_symbol_scope_push(7U, 0U);
  sf_debug_symbol_scope_add("nargout", &c5_nargout, c5_c_sf_marshall);
  sf_debug_symbol_scope_add("nargin", &c5_nargin, c5_c_sf_marshall);
  sf_debug_symbol_scope_add("flag", &c5_flag, c5_b_sf_marshall);
  sf_debug_symbol_scope_add("Tx", &c5_Tx, c5_b_sf_marshall);
  sf_debug_symbol_scope_add("op", &c5_op, c5_sf_marshall);
  sf_debug_symbol_scope_add("Rx1", &c5_Rx1, c5_b_sf_marshall);
  sf_debug_symbol_scope_add("D", &c5_D, c5_sf_marshall);
  CV_EML_FCN(0, 0);
  _SFD_EML_CALL(0,4);
  if (CV_EML_COND(0, 0, (real_T)c5_D == 1.0)) {
    if (CV_EML_COND(0, 1, (real_T)c5_op == 1.0)) {
      CV_EML_MCDC(0, 0, true);
      CV_EML_IF(0, 0, true);
      _SFD_EML_CALL(0,5);
      c5_Tx = c5_Rx1;
      _SFD_EML_CALL(0,6);
      c5_flag = 1U;
      goto label_1;
    }
  }

  CV_EML_MCDC(0, 0, false);
  CV_EML_IF(0, 0, false);
  _SFD_EML_CALL(0,8);
  c5_flag = 0U;
  _SFD_EML_CALL(0,9);
  c5_Tx = 0U;
 label_1:
  ;
  _SFD_EML_CALL(0,-9);
  sf_debug_symbol_scope_pop();
  *c5_b_Tx = c5_Tx;
  *c5_b_flag = c5_flag;
  _SFD_CC_CALL(EXIT_OUT_OF_FUNCTION_TAG,4);
  _sfEvent_ = c5_previousEvent;
  sf_debug_check_for_state_inconsistency(_MasterMachineNumber_,
    chartInstance.chartNumber, chartInstance.instanceNumber);
}

static void init_script_number_translation(uint32_T c5_machineNumber, uint32_T
  c5_chartNumber)
{
}

static const mxArray *c5_sf_marshall(void *c5_chartInstance, void *c5_u)
{
  const mxArray *c5_y = NULL;
  boolean_T c5_b_u;
  const mxArray *c5_b_y = NULL;
  c5_y = NULL;
  c5_b_u = *((boolean_T *)c5_u);
  c5_b_y = NULL;
  sf_mex_assign(&c5_b_y, sf_mex_create("y", &c5_b_u, 11, 0U, 0U, 0U, 0));
  sf_mex_assign(&c5_y, c5_b_y);
  return c5_y;
}

static const mxArray *c5_b_sf_marshall(void *c5_chartInstance, void *c5_u)
{
  const mxArray *c5_y = NULL;
  uint8_T c5_b_u;
  const mxArray *c5_b_y = NULL;
  c5_y = NULL;
  c5_b_u = *((uint8_T *)c5_u);
  c5_b_y = NULL;
  sf_mex_assign(&c5_b_y, sf_mex_create("y", &c5_b_u, 3, 0U, 0U, 0U, 0));
  sf_mex_assign(&c5_y, c5_b_y);
  return c5_y;
}

static const mxArray *c5_c_sf_marshall(void *c5_chartInstance, void *c5_u)
{
  const mxArray *c5_y = NULL;
  real_T c5_b_u;
  const mxArray *c5_b_y = NULL;
  c5_y = NULL;
  c5_b_u = *((real_T *)c5_u);
  c5_b_y = NULL;
  sf_mex_assign(&c5_b_y, sf_mex_create("y", &c5_b_u, 0, 0U, 0U, 0U, 0));
  sf_mex_assign(&c5_y, c5_b_y);
  return c5_y;
}

const mxArray *sf_c5_Master_get_eml_resolved_functions_info(void)
{
  const mxArray *c5_nameCaptureInfo = NULL;
  c5_ResolvedFunctionInfo c5_info[2];
  c5_ResolvedFunctionInfo (*c5_b_info)[2];
  const mxArray *c5_m0 = NULL;
  int32_T c5_i0;
  c5_ResolvedFunctionInfo *c5_r0;
  c5_nameCaptureInfo = NULL;
  c5_b_info = (c5_ResolvedFunctionInfo (*)[2])c5_info;
  (*c5_b_info)[0].context = "";
  (*c5_b_info)[0].name = "eq";
  (*c5_b_info)[0].dominantType = "double";
  (*c5_b_info)[0].resolved = "[B]eq";
  (*c5_b_info)[0].fileLength = 0U;
  (*c5_b_info)[0].fileTime1 = 0U;
  (*c5_b_info)[0].fileTime2 = 0U;
  (*c5_b_info)[1].context = "";
  (*c5_b_info)[1].name = "uint8";
  (*c5_b_info)[1].dominantType = "double";
  (*c5_b_info)[1].resolved = "[B]uint8";
  (*c5_b_info)[1].fileLength = 0U;
  (*c5_b_info)[1].fileTime1 = 0U;
  (*c5_b_info)[1].fileTime2 = 0U;
  sf_mex_assign(&c5_m0, sf_mex_createstruct("nameCaptureInfo", 1, 2));
  for (c5_i0 = 0; c5_i0 < 2; c5_i0 = c5_i0 + 1) {
    c5_r0 = &c5_info[c5_i0];
    sf_mex_addfield(c5_m0, sf_mex_create("nameCaptureInfo", c5_r0->context, 15,
      0U, 0U, 0U, 2, 1, strlen(c5_r0->context)), "context",
                    "nameCaptureInfo", c5_i0);
    sf_mex_addfield(c5_m0, sf_mex_create("nameCaptureInfo", c5_r0->name, 15, 0U,
      0U, 0U, 2, 1, strlen(c5_r0->name)), "name",
                    "nameCaptureInfo", c5_i0);
    sf_mex_addfield(c5_m0, sf_mex_create("nameCaptureInfo", c5_r0->dominantType,
      15, 0U, 0U, 0U, 2, 1, strlen(c5_r0->dominantType)),
                    "dominantType", "nameCaptureInfo", c5_i0);
    sf_mex_addfield(c5_m0, sf_mex_create("nameCaptureInfo", c5_r0->resolved, 15,
      0U, 0U, 0U, 2, 1, strlen(c5_r0->resolved)), "resolved"
                    , "nameCaptureInfo", c5_i0);
    sf_mex_addfield(c5_m0, sf_mex_create("nameCaptureInfo", &c5_r0->fileLength,
      7, 0U, 0U, 0U, 0), "fileLength", "nameCaptureInfo",
                    c5_i0);
    sf_mex_addfield(c5_m0, sf_mex_create("nameCaptureInfo", &c5_r0->fileTime1, 7,
      0U, 0U, 0U, 0), "fileTime1", "nameCaptureInfo", c5_i0);
    sf_mex_addfield(c5_m0, sf_mex_create("nameCaptureInfo", &c5_r0->fileTime2, 7,
      0U, 0U, 0U, 0), "fileTime2", "nameCaptureInfo", c5_i0);
  }

  sf_mex_assign(&c5_nameCaptureInfo, c5_m0);
  return c5_nameCaptureInfo;
}

static uint8_T c5_emlrt_marshallIn(const mxArray *c5_Tx, char *c5_name)
{
  uint8_T c5_y;
  uint8_T c5_u0;
  sf_mex_import(c5_name, sf_mex_dup(c5_Tx), &c5_u0, 1, 3, 0U, 0, 0U, 0);
  c5_y = c5_u0;
  sf_mex_destroy(&c5_Tx);
  return c5_y;
}

static uint8_T c5_b_emlrt_marshallIn(const mxArray *c5_flag, char *c5_name)
{
  uint8_T c5_y;
  uint8_T c5_u1;
  sf_mex_import(c5_name, sf_mex_dup(c5_flag), &c5_u1, 1, 3, 0U, 0, 0U, 0);
  c5_y = c5_u1;
  sf_mex_destroy(&c5_flag);
  return c5_y;
}

static uint8_T c5_c_emlrt_marshallIn(const mxArray *c5_b_is_active_c5_Master,
  char *c5_name)
{
  uint8_T c5_y;
  uint8_T c5_u2;
  sf_mex_import(c5_name, sf_mex_dup(c5_b_is_active_c5_Master), &c5_u2, 1, 3, 0U,
                0, 0U, 0);
  c5_y = c5_u2;
  sf_mex_destroy(&c5_b_is_active_c5_Master);
  return c5_y;
}

static void init_io_bus_offset(void)
{
}

static void init_dsm_address_info(void)
{
}

/* SFunction Glue Code */
void sf_c5_Master_get_check_sum(mxArray *plhs[])
{
  ((real_T *)mxGetPr((plhs[0])))[0] = (real_T)(2908107194U);
  ((real_T *)mxGetPr((plhs[0])))[1] = (real_T)(3388472471U);
  ((real_T *)mxGetPr((plhs[0])))[2] = (real_T)(3415583782U);
  ((real_T *)mxGetPr((plhs[0])))[3] = (real_T)(3944458785U);
}

mxArray *sf_c5_Master_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,4,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateDoubleMatrix(4,1,mxREAL);
    double *pr = mxGetPr(mxChecksum);
    pr[0] = (double)(1703356473U);
    pr[1] = (double)(3038335155U);
    pr[2] = (double)(1817249806U);
    pr[3] = (double)(82931302U);
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,3,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(1));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(3));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(1));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,2,"type",mxType);
    }

    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,2,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(3));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(3));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  return(mxAutoinheritanceInfo);
}

static mxArray *sf_get_sim_state_info_c5_Master(void)
{
  const char *infoFields[] = { "chartChecksum", "varInfo" };

  mxArray *mxInfo = mxCreateStructMatrix(1, 1, 2, infoFields);
  char *infoEncStr[] = {
    "100 S1x3'type','srcId','name','auxInfo'{{M[1],M[7],T\"Tx\",},{M[1],M[5],T\"flag\",},{M[8],M[0],T\"is_active_c5_Master\",}}"
  };

  mxArray *mxVarInfo = sf_mex_decode_encoded_mx_struct_array(infoEncStr, 3, 10);
  mxArray *mxChecksum = mxCreateDoubleMatrix(1, 4, mxREAL);
  sf_c5_Master_get_check_sum(&mxChecksum);
  mxSetField(mxInfo, 0, infoFields[0], mxChecksum);
  mxSetField(mxInfo, 0, infoFields[1], mxVarInfo);
  return mxInfo;
}

static void chart_debug_initialization(SimStruct *S, unsigned int
  fullDebuggerInitialization)
{
  if (!sim_mode_is_rtw_gen(S)) {
    if (ssIsFirstInitCond(S) && fullDebuggerInitialization==1) {
      /* do this only if simulation is starting */
      {
        unsigned int chartAlreadyPresent;
        chartAlreadyPresent = sf_debug_initialize_chart(_MasterMachineNumber_,
          5,
          1,
          1,
          5,
          0,
          0,
          0,
          0,
          0,
          &(chartInstance.chartNumber),
          &(chartInstance.instanceNumber),
          ssGetPath(S),
          (void *)S);
        if (chartAlreadyPresent==0) {
          /* this is the first instance */
          init_script_number_translation(_MasterMachineNumber_,
            chartInstance.chartNumber);
          sf_debug_set_chart_disable_implicit_casting(_MasterMachineNumber_,
            chartInstance.chartNumber,1);
          sf_debug_set_chart_event_thresholds(_MasterMachineNumber_,
            chartInstance.chartNumber,
            0,
            0,
            0);
          _SFD_SET_DATA_PROPS(0,1,1,0,SF_UINT8,0,NULL,0,0,0,0.0,1.0,0,"D",0,
                              c5_sf_marshall);
          _SFD_SET_DATA_PROPS(1,2,0,1,SF_UINT8,0,NULL,0,0,0,0.0,1.0,0,"Tx",0,
                              NULL);
          _SFD_SET_DATA_PROPS(2,2,0,1,SF_UINT8,0,NULL,0,0,0,0.0,1.0,0,"flag",0,
                              NULL);
          _SFD_SET_DATA_PROPS(3,1,1,0,SF_UINT8,0,NULL,0,0,0,0.0,1.0,0,"Rx1",0,
                              c5_b_sf_marshall);
          _SFD_SET_DATA_PROPS(4,1,1,0,SF_UINT8,0,NULL,0,0,0,0.0,1.0,0,"op",0,
                              NULL);
          _SFD_STATE_INFO(0,0,2);
          _SFD_CH_SUBSTATE_COUNT(0);
          _SFD_CH_SUBSTATE_DECOMP(0);
        }

        _SFD_CV_INIT_CHART(0,0,0,0);

        {
          _SFD_CV_INIT_STATE(0,0,0,0,0,0,NULL,NULL);
        }

        _SFD_CV_INIT_TRANS(0,0,NULL,NULL,0,NULL);

        /* Initialization of EML Model Coverage */
        _SFD_CV_INIT_EML(0,1,1,0,0,0,2,1);
        _SFD_CV_INIT_EML_FCN(0,0,"eML_blk_kernel",0,-1,146);
        _SFD_CV_INIT_EML_IF(0,0,45,61,93,144);

        {
          static int condStart[] = { 48, 56 };

          static int condEnd[] = { 52, 61 };

          static int pfixExpr[] = { 0, 1, -3 };

          _SFD_CV_INIT_EML_MCDC(0,0,48,61,2,0,&(condStart[0]),&(condEnd[0]),3,
                                &(pfixExpr[0]));
        }

        _SFD_TRANS_COV_WTS(0,0,0,1,0);
        if (chartAlreadyPresent==0) {
          _SFD_TRANS_COV_MAPS(0,
                              0,NULL,NULL,
                              0,NULL,NULL,
                              1,NULL,NULL,
                              0,NULL,NULL);
        }

        {
          boolean_T *c5_D;
          uint8_T *c5_Tx;
          uint8_T *c5_flag;
          uint8_T *c5_Rx1;
          boolean_T *c5_op;
          c5_flag = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 2);
          c5_D = (boolean_T *)ssGetInputPortSignal(chartInstance.S, 0);
          c5_op = (boolean_T *)ssGetInputPortSignal(chartInstance.S, 2);
          c5_Tx = (uint8_T *)ssGetOutputPortSignal(chartInstance.S, 1);
          c5_Rx1 = (uint8_T *)ssGetInputPortSignal(chartInstance.S, 1);
          _SFD_SET_DATA_VALUE_PTR(0U, c5_D);
          _SFD_SET_DATA_VALUE_PTR(1U, c5_Tx);
          _SFD_SET_DATA_VALUE_PTR(2U, c5_flag);
          _SFD_SET_DATA_VALUE_PTR(3U, c5_Rx1);
          _SFD_SET_DATA_VALUE_PTR(4U, c5_op);
        }
      }
    } else {
      sf_debug_reset_current_state_configuration(_MasterMachineNumber_,
        chartInstance.chartNumber,chartInstance.instanceNumber);
    }
  }
}

static void sf_opaque_initialize_c5_Master(void *chartInstanceVar)
{
  chart_debug_initialization(chartInstance.S,0);
  initialize_params_c5_Master();
  initialize_c5_Master();
}

static void sf_opaque_enable_c5_Master(void *chartInstanceVar)
{
  enable_c5_Master();
}

static void sf_opaque_disable_c5_Master(void *chartInstanceVar)
{
  disable_c5_Master();
}

static void sf_opaque_gateway_c5_Master(void *chartInstanceVar)
{
  sf_c5_Master();
}

static mxArray* sf_opaque_get_sim_state_c5_Master(void *chartInstanceVar)
{
  mxArray *st = (mxArray *) get_sim_state_c5_Master();
  return st;
}

static void sf_opaque_set_sim_state_c5_Master(void *chartInstanceVar, const
  mxArray *st)
{
  set_sim_state_c5_Master(sf_mex_dup(st));
}

static void sf_opaque_terminate_c5_Master(void *chartInstanceVar)
{
  if (sim_mode_is_rtw_gen(chartInstance.S) || sim_mode_is_external
      (chartInstance.S)) {
    sf_clear_rtw_identifier(chartInstance.S);
  }

  finalize_c5_Master();
}

extern unsigned int sf_machine_global_initializer_called(void);
static void mdlProcessParameters_c5_Master(SimStruct *S)
{
  int i;
  for (i=0;i<ssGetNumRunTimeParams(S);i++) {
    if (ssGetSFcnParamTunable(S,i)) {
      ssUpdateDlgParamAsRunTimeParam(S,i);
    }
  }

  if (sf_machine_global_initializer_called()) {
    initialize_params_c5_Master();
  }
}

static void mdlSetWorkWidths_c5_Master(SimStruct *S)
{
  if (sim_mode_is_rtw_gen(S) || sim_mode_is_external(S)) {
    int_T chartIsInlinable =
      (int_T)sf_is_chart_inlinable("Master","Master",5);
    ssSetStateflowIsInlinable(S,chartIsInlinable);
    ssSetRTWCG(S,sf_rtw_info_uint_prop("Master","Master",5,"RTWCG"));
    ssSetEnableFcnIsTrivial(S,1);
    ssSetDisableFcnIsTrivial(S,1);
    ssSetNotMultipleInlinable(S,sf_rtw_info_uint_prop("Master","Master",5,
      "gatewayCannotBeInlinedMultipleTimes"));
    if (chartIsInlinable) {
      ssSetInputPortOptimOpts(S, 0, SS_REUSABLE_AND_LOCAL);
      ssSetInputPortOptimOpts(S, 1, SS_REUSABLE_AND_LOCAL);
      ssSetInputPortOptimOpts(S, 2, SS_REUSABLE_AND_LOCAL);
      sf_mark_chart_expressionable_inputs(S,"Master","Master",5,3);
      sf_mark_chart_reusable_outputs(S,"Master","Master",5,2);
    }

    sf_set_rtw_dwork_info(S,"Master","Master",5);
    ssSetHasSubFunctions(S,!(chartIsInlinable));
    ssSetOptions(S,ssGetOptions(S)|SS_OPTION_WORKS_WITH_CODE_REUSE);
  }

  ssSetChecksum0(S,(3459349524U));
  ssSetChecksum1(S,(3599566402U));
  ssSetChecksum2(S,(2696648170U));
  ssSetChecksum3(S,(1962177175U));
  ssSetmdlDerivatives(S, NULL);
  ssSetExplicitFCSSCtrl(S,1);
}

static void mdlRTW_c5_Master(SimStruct *S)
{
  if (sim_mode_is_rtw_gen(S)) {
    sf_write_symbol_mapping(S, "Master", "Master",5);
    ssWriteRTWStrParam(S, "StateflowChartType", "Embedded MATLAB");
  }
}

static void mdlStart_c5_Master(SimStruct *S)
{
  chartInstance.chartInfo.chartInstance = NULL;
  chartInstance.chartInfo.isEMLChart = 1;
  chartInstance.chartInfo.chartInitialized = 0;
  chartInstance.chartInfo.sFunctionGateway = sf_opaque_gateway_c5_Master;
  chartInstance.chartInfo.initializeChart = sf_opaque_initialize_c5_Master;
  chartInstance.chartInfo.terminateChart = sf_opaque_terminate_c5_Master;
  chartInstance.chartInfo.enableChart = sf_opaque_enable_c5_Master;
  chartInstance.chartInfo.disableChart = sf_opaque_disable_c5_Master;
  chartInstance.chartInfo.getSimState = sf_opaque_get_sim_state_c5_Master;
  chartInstance.chartInfo.setSimState = sf_opaque_set_sim_state_c5_Master;
  chartInstance.chartInfo.getSimStateInfo = sf_get_sim_state_info_c5_Master;
  chartInstance.chartInfo.zeroCrossings = NULL;
  chartInstance.chartInfo.outputs = NULL;
  chartInstance.chartInfo.derivatives = NULL;
  chartInstance.chartInfo.mdlRTW = mdlRTW_c5_Master;
  chartInstance.chartInfo.mdlStart = mdlStart_c5_Master;
  chartInstance.chartInfo.mdlSetWorkWidths = mdlSetWorkWidths_c5_Master;
  chartInstance.chartInfo.extModeExec = NULL;
  chartInstance.chartInfo.restoreLastMajorStepConfiguration = NULL;
  chartInstance.chartInfo.restoreBeforeLastMajorStepConfiguration = NULL;
  chartInstance.chartInfo.storeCurrentConfiguration = NULL;
  chartInstance.S = S;
  ssSetUserData(S,(void *)(&(chartInstance.chartInfo)));/* register the chart instance with simstruct */
  if (!sim_mode_is_rtw_gen(S)) {
    init_dsm_address_info();
  }

  chart_debug_initialization(S,1);
}

void c5_Master_method_dispatcher(SimStruct *S, int_T method, void *data)
{
  switch (method) {
   case SS_CALL_MDL_START:
    mdlStart_c5_Master(S);
    break;

   case SS_CALL_MDL_SET_WORK_WIDTHS:
    mdlSetWorkWidths_c5_Master(S);
    break;

   case SS_CALL_MDL_PROCESS_PARAMETERS:
    mdlProcessParameters_c5_Master(S);
    break;

   default:
    /* Unhandled method */
    sf_mex_error_message("Stateflow Internal Error:\n"
                         "Error calling c5_Master_method_dispatcher.\n"
                         "Can't handle method %d.\n", method);
    break;
  }
}
