/*
 * CANTest.c
 *
 * Academic License - for use in teaching, academic research, and meeting
 * course requirements at degree granting institutions only.  Not for
 * government, commercial, or other organizational use.
 *
 * Code generation for model "CANTest".
 *
 * Model version              : 1.360
 * Simulink Coder version : 8.14 (R2018a) 06-Feb-2018
 * C source code generated on : Tue Jul 11 11:56:08 2023
 *
 * Target selection: slrt.tlc
 * Note: GRT includes extra infrastructure and instrumentation for prototyping
 * Embedded hardware selection: Generic->32-bit x86 compatible
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "rt_logging_mmi.h"
#include "CANTest_capi.h"
#include "CANTest.h"
#include "CANTest_private.h"

/* Block signals (default storage) */
B_CANTest_T CANTest_B;

/* Block states (default storage) */
DW_CANTest_T CANTest_DW;

/* Real-time model */
RT_MODEL_CANTest_T CANTest_M_;
RT_MODEL_CANTest_T *const CANTest_M = &CANTest_M_;

/* Model output function */
static void CANTest_output(void)
{
  int32_T s1_iter;

  /* Gain: '<S4>/ContM' incorporates:
   *  Constant: '<S4>/ContMode'
   */
  CANTest_B.ContMode = CANTest_P.ContM_Gain * CANTest_P.ContMode_Value;

  /* Constant: '<S5>/Constant' */
  CANTest_B.Ready = CANTest_P.Constant_Value;

  /* Constant: '<S5>/Constant1' */
  CANTest_B.Gear = CANTest_P.Constant1_Value;

  /* Constant: '<S5>/Constant2' */
  CANTest_B.BMS = CANTest_P.Constant2_Value;

  /* Constant: '<S5>/Constant3' */
  CANTest_B.PosTQLim = CANTest_P.Constant3_Value;

  /* Constant: '<S5>/Constant4' */
  CANTest_B.NegTQLim = CANTest_P.Constant4_Value;

  /* UnitDelay: '<S6>/d1' */
  CANTest_B.d1 = CANTest_DW.d1_DSTATE;

  /* Sum: '<S6>/Sum3' incorporates:
   *  Constant: '<S4>/TQCom'
   */
  CANTest_B.Sum3 = CANTest_P.TQCom_Value + CANTest_B.d1;

  /* Gain: '<S6>/gain' */
  CANTest_B.gain = CANTest_P.Ts * CANTest_B.Sum3;

  /* Gain: '<S6>/gain2' incorporates:
   *  Constant: '<S4>/Constant1'
   */
  CANTest_B.gain2 = CANTest_P.gain2_Gain * CANTest_P.Constant1_Value_j;

  /* Product: '<S6>/Product2' incorporates:
   *  Constant: '<S6>/Constant1'
   */
  CANTest_B.Product2 = CANTest_P.Constant1_Value_a / CANTest_B.gain2;

  /* Gain: '<S6>/gain1' */
  CANTest_B.gain1 = CANTest_P.gain1_Gain * CANTest_B.Product2;

  /* Sum: '<S6>/Sum1' incorporates:
   *  Constant: '<S6>/Constant'
   */
  CANTest_B.Sum1 = CANTest_B.gain1 - CANTest_P.Ts;

  /* UnitDelay: '<S6>/d' */
  CANTest_B.d = CANTest_DW.d_DSTATE;

  /* Product: '<S6>/Product11' */
  CANTest_B.Product11 = CANTest_B.Sum1 * CANTest_B.d;

  /* Sum: '<S6>/Sum2' */
  CANTest_B.Sum2 = CANTest_B.gain + CANTest_B.Product11;

  /* Sum: '<S6>/Sum4' incorporates:
   *  Constant: '<S6>/Constant'
   */
  CANTest_B.Sum4 = CANTest_B.gain1 + CANTest_P.Ts;

  /* Product: '<S6>/Product1' */
  CANTest_B.Product1 = CANTest_B.Sum2 / CANTest_B.Sum4;

  /* S-Function (scanpack): '<S5>/CAN Pack' */
  /* S-Function (scanpack): '<S5>/CAN Pack' */
  CANTest_B.CANPack.ID = 592U;
  CANTest_B.CANPack.Length = 8U;
  CANTest_B.CANPack.Extended = 0U;
  CANTest_B.CANPack.Remote = 0;
  CANTest_B.CANPack.Data[0] = 0;
  CANTest_B.CANPack.Data[1] = 0;
  CANTest_B.CANPack.Data[2] = 0;
  CANTest_B.CANPack.Data[3] = 0;
  CANTest_B.CANPack.Data[4] = 0;
  CANTest_B.CANPack.Data[5] = 0;
  CANTest_B.CANPack.Data[6] = 0;
  CANTest_B.CANPack.Data[7] = 0;

  {
    /* --------------- START Packing signal 0 ------------------
     *  startBit                = 0
     *  length                  = 1
     *  desiredSignalByteLayout = LITTLEENDIAN
     *  dataType                = UNSIGNED
     *  factor                  = 1.0
     *  offset                  = 0.0
     *  minimum                 = 0.0
     *  maximum                 = 0.0
     * -----------------------------------------------------------------------*/
    {
      {
        real64_T outValue = 0;

        {
          real64_T result = CANTest_B.ContMode;

          /* no scaling required */
          outValue = result;
        }

        {
          {
            uint8_T packedValue;
            if (outValue > (real64_T)(1)) {
              packedValue = (uint8_T) 1;
            } else if (outValue < (real64_T)(0)) {
              packedValue = (uint8_T) 0;
            } else {
              packedValue = (uint8_T) (outValue);
            }

            {
              {
                CANTest_B.CANPack.Data[0] = CANTest_B.CANPack.Data[0] | (uint8_T)
                  ((uint8_T)((uint8_T)(packedValue & (uint8_T)(((uint8_T)(1)) <<
                      0)) >> 0)<<0);
              }
            }
          }
        }
      }
    }

    /* --------------- START Packing signal 1 ------------------
     *  startBit                = 1
     *  length                  = 1
     *  desiredSignalByteLayout = LITTLEENDIAN
     *  dataType                = UNSIGNED
     *  factor                  = 1.0
     *  offset                  = 0.0
     *  minimum                 = 0.0
     *  maximum                 = 0.0
     * -----------------------------------------------------------------------*/
    {
      {
        real64_T outValue = 0;

        {
          real64_T result = CANTest_B.Ready;

          /* no scaling required */
          outValue = result;
        }

        {
          {
            uint8_T packedValue;
            if (outValue > (real64_T)(1)) {
              packedValue = (uint8_T) 1;
            } else if (outValue < (real64_T)(0)) {
              packedValue = (uint8_T) 0;
            } else {
              packedValue = (uint8_T) (outValue);
            }

            {
              {
                CANTest_B.CANPack.Data[0] = CANTest_B.CANPack.Data[0] | (uint8_T)
                  ((uint8_T)((uint8_T)(packedValue & (uint8_T)(((uint8_T)(1)) <<
                      0)) >> 0)<<1);
              }
            }
          }
        }
      }
    }

    /* --------------- START Packing signal 2 ------------------
     *  startBit                = 2
     *  length                  = 1
     *  desiredSignalByteLayout = LITTLEENDIAN
     *  dataType                = UNSIGNED
     *  factor                  = 1.0
     *  offset                  = 0.0
     *  minimum                 = 0.0
     *  maximum                 = 0.0
     * -----------------------------------------------------------------------*/
    {
      {
        real64_T outValue = 0;

        {
          real64_T result = CANTest_B.Ready;

          /* no scaling required */
          outValue = result;
        }

        {
          {
            uint8_T packedValue;
            if (outValue > (real64_T)(1)) {
              packedValue = (uint8_T) 1;
            } else if (outValue < (real64_T)(0)) {
              packedValue = (uint8_T) 0;
            } else {
              packedValue = (uint8_T) (outValue);
            }

            {
              {
                CANTest_B.CANPack.Data[0] = CANTest_B.CANPack.Data[0] | (uint8_T)
                  ((uint8_T)((uint8_T)(packedValue & (uint8_T)(((uint8_T)(1)) <<
                      0)) >> 0)<<2);
              }
            }
          }
        }
      }
    }

    /* --------------- START Packing signal 3 ------------------
     *  startBit                = 3
     *  length                  = 1
     *  desiredSignalByteLayout = LITTLEENDIAN
     *  dataType                = UNSIGNED
     *  factor                  = 1.0
     *  offset                  = 0.0
     *  minimum                 = 0.0
     *  maximum                 = 0.0
     * -----------------------------------------------------------------------*/
    {
      {
        real64_T outValue = 0;

        {
          real64_T result = CANTest_B.Ready;

          /* no scaling required */
          outValue = result;
        }

        {
          {
            uint8_T packedValue;
            if (outValue > (real64_T)(1)) {
              packedValue = (uint8_T) 1;
            } else if (outValue < (real64_T)(0)) {
              packedValue = (uint8_T) 0;
            } else {
              packedValue = (uint8_T) (outValue);
            }

            {
              {
                CANTest_B.CANPack.Data[0] = CANTest_B.CANPack.Data[0] | (uint8_T)
                  ((uint8_T)((uint8_T)(packedValue & (uint8_T)(((uint8_T)(1)) <<
                      0)) >> 0)<<3);
              }
            }
          }
        }
      }
    }

    /* --------------- START Packing signal 4 ------------------
     *  startBit                = 4
     *  length                  = 4
     *  desiredSignalByteLayout = LITTLEENDIAN
     *  dataType                = UNSIGNED
     *  factor                  = 1.0
     *  offset                  = 0.0
     *  minimum                 = 0.0
     *  maximum                 = 0.0
     * -----------------------------------------------------------------------*/
    {
      {
        real64_T outValue = 0;

        {
          real64_T result = CANTest_B.Gear;

          /* no scaling required */
          outValue = result;
        }

        {
          {
            uint8_T packedValue;
            if (outValue > (real64_T)(15)) {
              packedValue = (uint8_T) 15;
            } else if (outValue < (real64_T)(0)) {
              packedValue = (uint8_T) 0;
            } else {
              packedValue = (uint8_T) (outValue);
            }

            {
              {
                CANTest_B.CANPack.Data[0] = CANTest_B.CANPack.Data[0] | (uint8_T)
                  ((uint8_T)((uint8_T)(packedValue & (uint8_T)(((uint8_T)(1)) <<
                      0)) >> 0)<<4);
              }

              {
                CANTest_B.CANPack.Data[0] = CANTest_B.CANPack.Data[0] | (uint8_T)
                  ((uint8_T)((uint8_T)(packedValue & (uint8_T)(((uint8_T)(1)) <<
                      1)) >> 1)<<5);
              }

              {
                CANTest_B.CANPack.Data[0] = CANTest_B.CANPack.Data[0] | (uint8_T)
                  ((uint8_T)((uint8_T)(packedValue & (uint8_T)(((uint8_T)(1)) <<
                      2)) >> 2)<<6);
              }

              {
                CANTest_B.CANPack.Data[0] = CANTest_B.CANPack.Data[0] | (uint8_T)
                  ((uint8_T)((uint8_T)(packedValue & (uint8_T)(((uint8_T)(1)) <<
                      3)) >> 3)<<7);
              }
            }
          }
        }
      }
    }

    /* --------------- START Packing signal 5 ------------------
     *  startBit                = 8
     *  length                  = 2
     *  desiredSignalByteLayout = LITTLEENDIAN
     *  dataType                = UNSIGNED
     *  factor                  = 1.0
     *  offset                  = 0.0
     *  minimum                 = 0.0
     *  maximum                 = 0.0
     * -----------------------------------------------------------------------*/
    {
      {
        real64_T outValue = 0;

        {
          real64_T result = CANTest_B.Ready;

          /* no scaling required */
          outValue = result;
        }

        {
          {
            uint8_T packedValue;
            if (outValue > (real64_T)(3)) {
              packedValue = (uint8_T) 3;
            } else if (outValue < (real64_T)(0)) {
              packedValue = (uint8_T) 0;
            } else {
              packedValue = (uint8_T) (outValue);
            }

            {
              {
                CANTest_B.CANPack.Data[1] = CANTest_B.CANPack.Data[1] | (uint8_T)
                  ((uint8_T)((uint8_T)(packedValue & (uint8_T)(((uint8_T)(1)) <<
                      0)) >> 0)<<0);
              }

              {
                CANTest_B.CANPack.Data[1] = CANTest_B.CANPack.Data[1] | (uint8_T)
                  ((uint8_T)((uint8_T)(packedValue & (uint8_T)(((uint8_T)(1)) <<
                      1)) >> 1)<<1);
              }
            }
          }
        }
      }
    }

    /* --------------- START Packing signal 6 ------------------
     *  startBit                = 10
     *  length                  = 3
     *  desiredSignalByteLayout = LITTLEENDIAN
     *  dataType                = UNSIGNED
     *  factor                  = 1.0
     *  offset                  = 0.0
     *  minimum                 = 0.0
     *  maximum                 = 0.0
     * -----------------------------------------------------------------------*/
    {
      {
        real64_T outValue = 0;

        {
          real64_T result = CANTest_B.BMS;

          /* no scaling required */
          outValue = result;
        }

        {
          {
            uint8_T packedValue;
            if (outValue > (real64_T)(7)) {
              packedValue = (uint8_T) 7;
            } else if (outValue < (real64_T)(0)) {
              packedValue = (uint8_T) 0;
            } else {
              packedValue = (uint8_T) (outValue);
            }

            {
              {
                CANTest_B.CANPack.Data[1] = CANTest_B.CANPack.Data[1] | (uint8_T)
                  ((uint8_T)((uint8_T)(packedValue & (uint8_T)(((uint8_T)(1)) <<
                      0)) >> 0)<<2);
              }

              {
                CANTest_B.CANPack.Data[1] = CANTest_B.CANPack.Data[1] | (uint8_T)
                  ((uint8_T)((uint8_T)(packedValue & (uint8_T)(((uint8_T)(1)) <<
                      1)) >> 1)<<3);
              }

              {
                CANTest_B.CANPack.Data[1] = CANTest_B.CANPack.Data[1] | (uint8_T)
                  ((uint8_T)((uint8_T)(packedValue & (uint8_T)(((uint8_T)(1)) <<
                      2)) >> 2)<<4);
              }
            }
          }
        }
      }
    }

    /* --------------- START Packing signal 7 ------------------
     *  startBit                = 13
     *  length                  = 2
     *  desiredSignalByteLayout = LITTLEENDIAN
     *  dataType                = UNSIGNED
     *  factor                  = 1.0
     *  offset                  = 0.0
     *  minimum                 = 0.0
     *  maximum                 = 0.0
     * -----------------------------------------------------------------------*/
    {
      {
        real64_T outValue = 0;

        {
          real64_T result = CANTest_B.Ready;

          /* no scaling required */
          outValue = result;
        }

        {
          {
            uint8_T packedValue;
            if (outValue > (real64_T)(3)) {
              packedValue = (uint8_T) 3;
            } else if (outValue < (real64_T)(0)) {
              packedValue = (uint8_T) 0;
            } else {
              packedValue = (uint8_T) (outValue);
            }

            {
              {
                CANTest_B.CANPack.Data[1] = CANTest_B.CANPack.Data[1] | (uint8_T)
                  ((uint8_T)((uint8_T)(packedValue & (uint8_T)(((uint8_T)(1)) <<
                      0)) >> 0)<<5);
              }

              {
                CANTest_B.CANPack.Data[1] = CANTest_B.CANPack.Data[1] | (uint8_T)
                  ((uint8_T)((uint8_T)(packedValue & (uint8_T)(((uint8_T)(1)) <<
                      1)) >> 1)<<6);
              }
            }
          }
        }
      }
    }

    /* --------------- START Packing signal 8 ------------------
     *  startBit                = 16
     *  length                  = 16
     *  desiredSignalByteLayout = LITTLEENDIAN
     *  dataType                = UNSIGNED
     *  factor                  = 0.1
     *  offset                  = -200.0
     *  minimum                 = 0.0
     *  maximum                 = 0.0
     * -----------------------------------------------------------------------*/
    {
      {
        real64_T outValue = 0;

        {
          real64_T result = CANTest_B.PosTQLim;

          /* full scaling operation */
          result = (result - -200.0) * (1 / 0.1);
          outValue = result;
        }

        {
          {
            uint16_T packedValue;
            if (outValue > (real64_T)(65535)) {
              packedValue = (uint16_T) 65535;
            } else if (outValue < (real64_T)(0)) {
              packedValue = (uint16_T) 0;
            } else {
              packedValue = (uint16_T) (outValue);
            }

            {
              {
                CANTest_B.CANPack.Data[2] = CANTest_B.CANPack.Data[2] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 0)) >> 0)<<0);
              }

              {
                CANTest_B.CANPack.Data[2] = CANTest_B.CANPack.Data[2] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 1)) >> 1)<<1);
              }

              {
                CANTest_B.CANPack.Data[2] = CANTest_B.CANPack.Data[2] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 2)) >> 2)<<2);
              }

              {
                CANTest_B.CANPack.Data[2] = CANTest_B.CANPack.Data[2] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 3)) >> 3)<<3);
              }

              {
                CANTest_B.CANPack.Data[2] = CANTest_B.CANPack.Data[2] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 4)) >> 4)<<4);
              }

              {
                CANTest_B.CANPack.Data[2] = CANTest_B.CANPack.Data[2] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 5)) >> 5)<<5);
              }

              {
                CANTest_B.CANPack.Data[2] = CANTest_B.CANPack.Data[2] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 6)) >> 6)<<6);
              }

              {
                CANTest_B.CANPack.Data[2] = CANTest_B.CANPack.Data[2] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 7)) >> 7)<<7);
              }

              {
                CANTest_B.CANPack.Data[3] = CANTest_B.CANPack.Data[3] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 8)) >> 8)<<0);
              }

              {
                CANTest_B.CANPack.Data[3] = CANTest_B.CANPack.Data[3] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 9)) >> 9)<<1);
              }

              {
                CANTest_B.CANPack.Data[3] = CANTest_B.CANPack.Data[3] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 10)) >> 10)<<2);
              }

              {
                CANTest_B.CANPack.Data[3] = CANTest_B.CANPack.Data[3] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 11)) >> 11)<<3);
              }

              {
                CANTest_B.CANPack.Data[3] = CANTest_B.CANPack.Data[3] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 12)) >> 12)<<4);
              }

              {
                CANTest_B.CANPack.Data[3] = CANTest_B.CANPack.Data[3] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 13)) >> 13)<<5);
              }

              {
                CANTest_B.CANPack.Data[3] = CANTest_B.CANPack.Data[3] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 14)) >> 14)<<6);
              }

              {
                CANTest_B.CANPack.Data[3] = CANTest_B.CANPack.Data[3] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 15)) >> 15)<<7);
              }
            }
          }
        }
      }
    }

    /* --------------- START Packing signal 9 ------------------
     *  startBit                = 32
     *  length                  = 16
     *  desiredSignalByteLayout = LITTLEENDIAN
     *  dataType                = UNSIGNED
     *  factor                  = 0.1
     *  offset                  = -200.0
     *  minimum                 = 0.0
     *  maximum                 = 0.0
     * -----------------------------------------------------------------------*/
    {
      {
        real64_T outValue = 0;

        {
          real64_T result = CANTest_B.NegTQLim;

          /* full scaling operation */
          result = (result - -200.0) * (1 / 0.1);
          outValue = result;
        }

        {
          {
            uint16_T packedValue;
            if (outValue > (real64_T)(65535)) {
              packedValue = (uint16_T) 65535;
            } else if (outValue < (real64_T)(0)) {
              packedValue = (uint16_T) 0;
            } else {
              packedValue = (uint16_T) (outValue);
            }

            {
              {
                CANTest_B.CANPack.Data[4] = CANTest_B.CANPack.Data[4] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 0)) >> 0)<<0);
              }

              {
                CANTest_B.CANPack.Data[4] = CANTest_B.CANPack.Data[4] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 1)) >> 1)<<1);
              }

              {
                CANTest_B.CANPack.Data[4] = CANTest_B.CANPack.Data[4] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 2)) >> 2)<<2);
              }

              {
                CANTest_B.CANPack.Data[4] = CANTest_B.CANPack.Data[4] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 3)) >> 3)<<3);
              }

              {
                CANTest_B.CANPack.Data[4] = CANTest_B.CANPack.Data[4] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 4)) >> 4)<<4);
              }

              {
                CANTest_B.CANPack.Data[4] = CANTest_B.CANPack.Data[4] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 5)) >> 5)<<5);
              }

              {
                CANTest_B.CANPack.Data[4] = CANTest_B.CANPack.Data[4] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 6)) >> 6)<<6);
              }

              {
                CANTest_B.CANPack.Data[4] = CANTest_B.CANPack.Data[4] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 7)) >> 7)<<7);
              }

              {
                CANTest_B.CANPack.Data[5] = CANTest_B.CANPack.Data[5] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 8)) >> 8)<<0);
              }

              {
                CANTest_B.CANPack.Data[5] = CANTest_B.CANPack.Data[5] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 9)) >> 9)<<1);
              }

              {
                CANTest_B.CANPack.Data[5] = CANTest_B.CANPack.Data[5] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 10)) >> 10)<<2);
              }

              {
                CANTest_B.CANPack.Data[5] = CANTest_B.CANPack.Data[5] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 11)) >> 11)<<3);
              }

              {
                CANTest_B.CANPack.Data[5] = CANTest_B.CANPack.Data[5] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 12)) >> 12)<<4);
              }

              {
                CANTest_B.CANPack.Data[5] = CANTest_B.CANPack.Data[5] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 13)) >> 13)<<5);
              }

              {
                CANTest_B.CANPack.Data[5] = CANTest_B.CANPack.Data[5] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 14)) >> 14)<<6);
              }

              {
                CANTest_B.CANPack.Data[5] = CANTest_B.CANPack.Data[5] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 15)) >> 15)<<7);
              }
            }
          }
        }
      }
    }

    /* --------------- START Packing signal 10 ------------------
     *  startBit                = 48
     *  length                  = 16
     *  desiredSignalByteLayout = LITTLEENDIAN
     *  dataType                = UNSIGNED
     *  factor                  = 0.1
     *  offset                  = -200.0
     *  minimum                 = 0.0
     *  maximum                 = 0.0
     * -----------------------------------------------------------------------*/
    {
      {
        real64_T outValue = 0;

        {
          real64_T result = CANTest_B.Product1;

          /* full scaling operation */
          result = (result - -200.0) * (1 / 0.1);
          outValue = result;
        }

        {
          {
            uint16_T packedValue;
            if (outValue > (real64_T)(65535)) {
              packedValue = (uint16_T) 65535;
            } else if (outValue < (real64_T)(0)) {
              packedValue = (uint16_T) 0;
            } else {
              packedValue = (uint16_T) (outValue);
            }

            {
              {
                CANTest_B.CANPack.Data[6] = CANTest_B.CANPack.Data[6] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 0)) >> 0)<<0);
              }

              {
                CANTest_B.CANPack.Data[6] = CANTest_B.CANPack.Data[6] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 1)) >> 1)<<1);
              }

              {
                CANTest_B.CANPack.Data[6] = CANTest_B.CANPack.Data[6] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 2)) >> 2)<<2);
              }

              {
                CANTest_B.CANPack.Data[6] = CANTest_B.CANPack.Data[6] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 3)) >> 3)<<3);
              }

              {
                CANTest_B.CANPack.Data[6] = CANTest_B.CANPack.Data[6] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 4)) >> 4)<<4);
              }

              {
                CANTest_B.CANPack.Data[6] = CANTest_B.CANPack.Data[6] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 5)) >> 5)<<5);
              }

              {
                CANTest_B.CANPack.Data[6] = CANTest_B.CANPack.Data[6] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 6)) >> 6)<<6);
              }

              {
                CANTest_B.CANPack.Data[6] = CANTest_B.CANPack.Data[6] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 7)) >> 7)<<7);
              }

              {
                CANTest_B.CANPack.Data[7] = CANTest_B.CANPack.Data[7] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 8)) >> 8)<<0);
              }

              {
                CANTest_B.CANPack.Data[7] = CANTest_B.CANPack.Data[7] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 9)) >> 9)<<1);
              }

              {
                CANTest_B.CANPack.Data[7] = CANTest_B.CANPack.Data[7] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 10)) >> 10)<<2);
              }

              {
                CANTest_B.CANPack.Data[7] = CANTest_B.CANPack.Data[7] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 11)) >> 11)<<3);
              }

              {
                CANTest_B.CANPack.Data[7] = CANTest_B.CANPack.Data[7] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 12)) >> 12)<<4);
              }

              {
                CANTest_B.CANPack.Data[7] = CANTest_B.CANPack.Data[7] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 13)) >> 13)<<5);
              }

              {
                CANTest_B.CANPack.Data[7] = CANTest_B.CANPack.Data[7] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 14)) >> 14)<<6);
              }

              {
                CANTest_B.CANPack.Data[7] = CANTest_B.CANPack.Data[7] | (uint8_T)
                  ((uint8_T)((uint16_T)(packedValue & (uint16_T)(((uint16_T)(1))
                      << 15)) >> 15)<<7);
              }
            }
          }
        }
      }
    }
  }

  /* S-Function (sg_IO61X_write_s): '<S5>/CAN Write1' */

  /* Level2 S-Function Block: '<S5>/CAN Write1' (sg_IO61X_write_s) */
  {
    SimStruct *rts = CANTest_M->childSfunctions[2];
    sfcnOutputs(rts,0);
  }

  /* Outputs for Iterator SubSystem: '<Root>/DAQ_In' incorporates:
   *  WhileIterator: '<S1>/While Iterator'
   */
  s1_iter = 1;
  do {
    /* Level2 S-Function Block: '<S1>/CAN Setup' (sg_IO613_setup_s) */
    {
      SimStruct *rts = CANTest_M->childSfunctions[0];
      sfcnOutputs(rts,0);
    }

    /* Level2 S-Function Block: '<S1>/CAN Read1' (sg_IO61X_read_s) */
    {
      SimStruct *rts = CANTest_M->childSfunctions[1];
      sfcnOutputs(rts,0);
    }

    {
      /* S-Function (scanunpack): '<S1>/CAN Unpack2' */
      if ((8 == CANTest_B.CANRead1_o2.Length) && (CANTest_B.CANRead1_o2.ID !=
           INVALID_CAN_ID) ) {
        if ((768U == CANTest_B.CANRead1_o2.ID) && (0U ==
             CANTest_B.CANRead1_o2.Extended) ) {
          {
            /* --------------- START Unpacking signal 0 ------------------
             *  startBit                = 32
             *  length                  = 16
             *  desiredSignalByteLayout = LITTLEENDIAN
             *  dataType                = UNSIGNED
             *  factor                  = 1.0
             *  offset                  = -32768.0
             * -----------------------------------------------------------------------*/
            {
              {
                real64_T outValue = 0;

                {
                  {
                    uint16_T unpackedValue = 0;

                    {
                      uint16_T tempValue = (uint16_T) (0);

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[4]) & (uint16_T)
                           ( (uint16_T) (1)<< 0)) >> 0)<<0);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[4]) & (uint16_T)
                           ( (uint16_T) (1)<< 1)) >> 1)<<1);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[4]) & (uint16_T)
                           ( (uint16_T) (1)<< 2)) >> 2)<<2);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[4]) & (uint16_T)
                           ( (uint16_T) (1)<< 3)) >> 3)<<3);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[4]) & (uint16_T)
                           ( (uint16_T) (1)<< 4)) >> 4)<<4);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[4]) & (uint16_T)
                           ( (uint16_T) (1)<< 5)) >> 5)<<5);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[4]) & (uint16_T)
                           ( (uint16_T) (1)<< 6)) >> 6)<<6);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[4]) & (uint16_T)
                           ( (uint16_T) (1)<< 7)) >> 7)<<7);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[5]) & (uint16_T)
                           ( (uint16_T) (1)<< 0)) >> 0)<<8);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[5]) & (uint16_T)
                           ( (uint16_T) (1)<< 1)) >> 1)<<9);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[5]) & (uint16_T)
                           ( (uint16_T) (1)<< 2)) >> 2)<<10);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[5]) & (uint16_T)
                           ( (uint16_T) (1)<< 3)) >> 3)<<11);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[5]) & (uint16_T)
                           ( (uint16_T) (1)<< 4)) >> 4)<<12);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[5]) & (uint16_T)
                           ( (uint16_T) (1)<< 5)) >> 5)<<13);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[5]) & (uint16_T)
                           ( (uint16_T) (1)<< 6)) >> 6)<<14);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[5]) & (uint16_T)
                           ( (uint16_T) (1)<< 7)) >> 7)<<15);
                      }

                      unpackedValue = tempValue;
                    }

                    outValue = (real64_T) (unpackedValue);
                  }
                }

                {
                  real64_T result = (real64_T) outValue;
                  result = result + -32768.0;
                  CANTest_B.RPM = result;
                }
              }
            }

            /* --------------- START Unpacking signal 1 ------------------
             *  startBit                = 48
             *  length                  = 16
             *  desiredSignalByteLayout = LITTLEENDIAN
             *  dataType                = UNSIGNED
             *  factor                  = 0.1
             *  offset                  = -200.0
             * -----------------------------------------------------------------------*/
            {
              {
                real64_T outValue = 0;

                {
                  {
                    uint16_T unpackedValue = 0;

                    {
                      uint16_T tempValue = (uint16_T) (0);

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[6]) & (uint16_T)
                           ( (uint16_T) (1)<< 0)) >> 0)<<0);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[6]) & (uint16_T)
                           ( (uint16_T) (1)<< 1)) >> 1)<<1);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[6]) & (uint16_T)
                           ( (uint16_T) (1)<< 2)) >> 2)<<2);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[6]) & (uint16_T)
                           ( (uint16_T) (1)<< 3)) >> 3)<<3);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[6]) & (uint16_T)
                           ( (uint16_T) (1)<< 4)) >> 4)<<4);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[6]) & (uint16_T)
                           ( (uint16_T) (1)<< 5)) >> 5)<<5);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[6]) & (uint16_T)
                           ( (uint16_T) (1)<< 6)) >> 6)<<6);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[6]) & (uint16_T)
                           ( (uint16_T) (1)<< 7)) >> 7)<<7);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[7]) & (uint16_T)
                           ( (uint16_T) (1)<< 0)) >> 0)<<8);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[7]) & (uint16_T)
                           ( (uint16_T) (1)<< 1)) >> 1)<<9);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[7]) & (uint16_T)
                           ( (uint16_T) (1)<< 2)) >> 2)<<10);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[7]) & (uint16_T)
                           ( (uint16_T) (1)<< 3)) >> 3)<<11);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[7]) & (uint16_T)
                           ( (uint16_T) (1)<< 4)) >> 4)<<12);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[7]) & (uint16_T)
                           ( (uint16_T) (1)<< 5)) >> 5)<<13);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[7]) & (uint16_T)
                           ( (uint16_T) (1)<< 6)) >> 6)<<14);
                      }

                      {
                        tempValue = tempValue | (uint16_T)((uint16_T)((uint16_T)
                          ((CANTest_B.CANRead1_o2.Data[7]) & (uint16_T)
                           ( (uint16_T) (1)<< 7)) >> 7)<<15);
                      }

                      unpackedValue = tempValue;
                    }

                    outValue = (real64_T) (unpackedValue);
                  }
                }

                {
                  real64_T result = (real64_T) outValue;
                  result = (result * 0.1) + -200.0;
                  CANTest_B.TQ = result;
                }
              }
            }
          }
        }
      }
    }

    s1_iter++;
  } while (CANTest_B.CANRead1_o1 && (s1_iter <= 501));

  /* End of Outputs for SubSystem: '<Root>/DAQ_In' */
}

/* Model update function */
static void CANTest_update(void)
{
  /* Update for UnitDelay: '<S6>/d1' incorporates:
   *  Constant: '<S4>/TQCom'
   */
  CANTest_DW.d1_DSTATE = CANTest_P.TQCom_Value;

  /* Update for UnitDelay: '<S6>/d' */
  CANTest_DW.d_DSTATE = CANTest_B.Product1;

  /* Update absolute time for base rate */
  /* The "clockTick0" counts the number of times the code of this task has
   * been executed. The absolute time is the multiplication of "clockTick0"
   * and "Timing.stepSize0". Size of "clockTick0" ensures timer will not
   * overflow during the application lifespan selected.
   * Timer of this task consists of two 32 bit unsigned integers.
   * The two integers represent the low bits Timing.clockTick0 and the high bits
   * Timing.clockTickH0. When the low bit overflows to 0, the high bits increment.
   */
  if (!(++CANTest_M->Timing.clockTick0)) {
    ++CANTest_M->Timing.clockTickH0;
  }

  CANTest_M->Timing.t[0] = CANTest_M->Timing.clockTick0 *
    CANTest_M->Timing.stepSize0 + CANTest_M->Timing.clockTickH0 *
    CANTest_M->Timing.stepSize0 * 4294967296.0;
}

/* Model initialize function */
static void CANTest_initialize(void)
{
  /* Start for Constant: '<S5>/Constant' */
  CANTest_B.Ready = CANTest_P.Constant_Value;

  /* Start for Constant: '<S5>/Constant1' */
  CANTest_B.Gear = CANTest_P.Constant1_Value;

  /* Start for Constant: '<S5>/Constant2' */
  CANTest_B.BMS = CANTest_P.Constant2_Value;

  /* Start for Constant: '<S5>/Constant3' */
  CANTest_B.PosTQLim = CANTest_P.Constant3_Value;

  /* Start for Constant: '<S5>/Constant4' */
  CANTest_B.NegTQLim = CANTest_P.Constant4_Value;

  /* Start for S-Function (sg_IO61X_write_s): '<S5>/CAN Write1' */
  /* Level2 S-Function Block: '<S5>/CAN Write1' (sg_IO61X_write_s) */
  {
    SimStruct *rts = CANTest_M->childSfunctions[2];
    sfcnStart(rts);
    if (ssGetErrorStatus(rts) != (NULL))
      return;
  }

  /* Start for Iterator SubSystem: '<Root>/DAQ_In' */

  /* Start for S-Function (sg_IO613_setup_s): '<S1>/CAN Setup' */
  /* Level2 S-Function Block: '<S1>/CAN Setup' (sg_IO613_setup_s) */
  {
    SimStruct *rts = CANTest_M->childSfunctions[0];
    sfcnStart(rts);
    if (ssGetErrorStatus(rts) != (NULL))
      return;
  }

  /* Start for S-Function (sg_IO61X_read_s): '<S1>/CAN Read1' */
  /* Level2 S-Function Block: '<S1>/CAN Read1' (sg_IO61X_read_s) */
  {
    SimStruct *rts = CANTest_M->childSfunctions[1];
    sfcnStart(rts);
    if (ssGetErrorStatus(rts) != (NULL))
      return;
  }

  /* Start for S-Function (scanunpack): '<S1>/CAN Unpack2' */

  /*-----------S-Function Block: <S1>/CAN Unpack2 -----------------*/

  /* End of Start for SubSystem: '<Root>/DAQ_In' */

  /* InitializeConditions for UnitDelay: '<S6>/d1' */
  CANTest_DW.d1_DSTATE = CANTest_P.d1_InitialCondition;

  /* InitializeConditions for UnitDelay: '<S6>/d' */
  CANTest_DW.d_DSTATE = CANTest_P.d_InitialCondition;
}

/* Model terminate function */
static void CANTest_terminate(void)
{
  /* Terminate for S-Function (sg_IO61X_write_s): '<S5>/CAN Write1' */
  /* Level2 S-Function Block: '<S5>/CAN Write1' (sg_IO61X_write_s) */
  {
    SimStruct *rts = CANTest_M->childSfunctions[2];
    sfcnTerminate(rts);
  }

  /* Terminate for Iterator SubSystem: '<Root>/DAQ_In' */

  /* Terminate for S-Function (sg_IO613_setup_s): '<S1>/CAN Setup' */
  /* Level2 S-Function Block: '<S1>/CAN Setup' (sg_IO613_setup_s) */
  {
    SimStruct *rts = CANTest_M->childSfunctions[0];
    sfcnTerminate(rts);
  }

  /* Terminate for S-Function (sg_IO61X_read_s): '<S1>/CAN Read1' */
  /* Level2 S-Function Block: '<S1>/CAN Read1' (sg_IO61X_read_s) */
  {
    SimStruct *rts = CANTest_M->childSfunctions[1];
    sfcnTerminate(rts);
  }

  /* End of Terminate for SubSystem: '<Root>/DAQ_In' */
}

/*========================================================================*
 * Start of Classic call interface                                        *
 *========================================================================*/
void MdlOutputs(int_T tid)
{
  CANTest_output();
  UNUSED_PARAMETER(tid);
}

void MdlUpdate(int_T tid)
{
  CANTest_update();
  UNUSED_PARAMETER(tid);
}

void MdlInitializeSizes(void)
{
}

void MdlInitializeSampleTimes(void)
{
}

void MdlInitialize(void)
{
}

void MdlStart(void)
{
  CANTest_initialize();
}

void MdlTerminate(void)
{
  CANTest_terminate();
}

/* Registration function */
RT_MODEL_CANTest_T *CANTest(void)
{
  /* Registration code */

  /* initialize non-finites */
  rt_InitInfAndNaN(sizeof(real_T));

  /* initialize real-time model */
  (void) memset((void *)CANTest_M, 0,
                sizeof(RT_MODEL_CANTest_T));
  rtsiSetSolverName(&CANTest_M->solverInfo,"FixedStepDiscrete");
  CANTest_M->solverInfoPtr = (&CANTest_M->solverInfo);

  /* Initialize timing info */
  {
    int_T *mdlTsMap = CANTest_M->Timing.sampleTimeTaskIDArray;
    mdlTsMap[0] = 0;
    CANTest_M->Timing.sampleTimeTaskIDPtr = (&mdlTsMap[0]);
    CANTest_M->Timing.sampleTimes = (&CANTest_M->Timing.sampleTimesArray[0]);
    CANTest_M->Timing.offsetTimes = (&CANTest_M->Timing.offsetTimesArray[0]);

    /* task periods */
    CANTest_M->Timing.sampleTimes[0] = (0.002);

    /* task offsets */
    CANTest_M->Timing.offsetTimes[0] = (0.0);
  }

  rtmSetTPtr(CANTest_M, &CANTest_M->Timing.tArray[0]);

  {
    int_T *mdlSampleHits = CANTest_M->Timing.sampleHitArray;
    mdlSampleHits[0] = 1;
    CANTest_M->Timing.sampleHits = (&mdlSampleHits[0]);
  }

  rtmSetTFinal(CANTest_M, -1);
  CANTest_M->Timing.stepSize0 = 0.002;

  /* Setup for data logging */
  {
    static RTWLogInfo rt_DataLoggingInfo;
    rt_DataLoggingInfo.loggingInterval = NULL;
    CANTest_M->rtwLogInfo = &rt_DataLoggingInfo;
  }

  /* Setup for data logging */
  {
    /*
     * Set pointers to the data and signal info each state
     */
    {
      static int_T rt_LoggedStateWidths[] = {
        1,
        1
      };

      static int_T rt_LoggedStateNumDimensions[] = {
        1,
        1
      };

      static int_T rt_LoggedStateDimensions[] = {
        1,
        1
      };

      static boolean_T rt_LoggedStateIsVarDims[] = {
        0,
        0
      };

      static BuiltInDTypeId rt_LoggedStateDataTypeIds[] = {
        SS_DOUBLE,
        SS_DOUBLE
      };

      static int_T rt_LoggedStateComplexSignals[] = {
        0,
        0
      };

      static RTWPreprocessingFcnPtr rt_LoggingStatePreprocessingFcnPtrs[] = {
        (NULL),
        (NULL)
      };

      static const char_T *rt_LoggedStateLabels[] = {
        "DSTATE",
        "DSTATE"
      };

      static const char_T *rt_LoggedStateBlockNames[] = {
        "CANTest/Mon_Cont/LPFM/d1",
        "CANTest/Mon_Cont/LPFM/d"
      };

      static const char_T *rt_LoggedStateNames[] = {
        "",
        ""
      };

      static boolean_T rt_LoggedStateCrossMdlRef[] = {
        0,
        0
      };

      static RTWLogDataTypeConvert rt_RTWLogDataTypeConvert[] = {
        { 0, SS_DOUBLE, SS_DOUBLE, 0, 0, 0, 1.0, 0, 0.0 },

        { 0, SS_DOUBLE, SS_DOUBLE, 0, 0, 0, 1.0, 0, 0.0 }
      };

      static RTWLogSignalInfo rt_LoggedStateSignalInfo = {
        2,
        rt_LoggedStateWidths,
        rt_LoggedStateNumDimensions,
        rt_LoggedStateDimensions,
        rt_LoggedStateIsVarDims,
        (NULL),
        (NULL),
        rt_LoggedStateDataTypeIds,
        rt_LoggedStateComplexSignals,
        (NULL),
        rt_LoggingStatePreprocessingFcnPtrs,

        { rt_LoggedStateLabels },
        (NULL),
        (NULL),
        (NULL),

        { rt_LoggedStateBlockNames },

        { rt_LoggedStateNames },
        rt_LoggedStateCrossMdlRef,
        rt_RTWLogDataTypeConvert
      };

      static void * rt_LoggedStateSignalPtrs[2];
      rtliSetLogXSignalPtrs(CANTest_M->rtwLogInfo, (LogSignalPtrsType)
                            rt_LoggedStateSignalPtrs);
      rtliSetLogXSignalInfo(CANTest_M->rtwLogInfo, &rt_LoggedStateSignalInfo);
      rt_LoggedStateSignalPtrs[0] = (void*)&CANTest_DW.d1_DSTATE;
      rt_LoggedStateSignalPtrs[1] = (void*)&CANTest_DW.d_DSTATE;
    }

    rtliSetLogT(CANTest_M->rtwLogInfo, "tout");
    rtliSetLogX(CANTest_M->rtwLogInfo, "xout");
    rtliSetLogXFinal(CANTest_M->rtwLogInfo, "");
    rtliSetLogVarNameModifier(CANTest_M->rtwLogInfo, "rt_");
    rtliSetLogFormat(CANTest_M->rtwLogInfo, 2);
    rtliSetLogMaxRows(CANTest_M->rtwLogInfo, 0);
    rtliSetLogDecimation(CANTest_M->rtwLogInfo, 1);
    rtliSetLogY(CANTest_M->rtwLogInfo, "");
    rtliSetLogYSignalInfo(CANTest_M->rtwLogInfo, (NULL));
    rtliSetLogYSignalPtrs(CANTest_M->rtwLogInfo, (NULL));
  }

  CANTest_M->solverInfoPtr = (&CANTest_M->solverInfo);
  CANTest_M->Timing.stepSize = (0.002);
  rtsiSetFixedStepSize(&CANTest_M->solverInfo, 0.002);
  rtsiSetSolverMode(&CANTest_M->solverInfo, SOLVER_MODE_SINGLETASKING);

  /* block I/O */
  CANTest_M->blockIO = ((void *) &CANTest_B);
  (void) memset(((void *) &CANTest_B), 0,
                sizeof(B_CANTest_T));

  {
    CANTest_B.CANPack = CAN_DATATYPE_GROUND;
    CANTest_B.CANRead1_o2 = CAN_DATATYPE_GROUND;
    CANTest_B.ContMode = 0.0;
    CANTest_B.Ready = 0.0;
    CANTest_B.Gear = 0.0;
    CANTest_B.BMS = 0.0;
    CANTest_B.PosTQLim = 0.0;
    CANTest_B.NegTQLim = 0.0;
    CANTest_B.d1 = 0.0;
    CANTest_B.Sum3 = 0.0;
    CANTest_B.gain = 0.0;
    CANTest_B.gain2 = 0.0;
    CANTest_B.Product2 = 0.0;
    CANTest_B.gain1 = 0.0;
    CANTest_B.Sum1 = 0.0;
    CANTest_B.d = 0.0;
    CANTest_B.Product11 = 0.0;
    CANTest_B.Sum2 = 0.0;
    CANTest_B.Sum4 = 0.0;
    CANTest_B.Product1 = 0.0;
    CANTest_B.RPM = 0.0;
    CANTest_B.TQ = 0.0;
  }

  /* parameters */
  CANTest_M->defaultParam = ((real_T *)&CANTest_P);

  /* states (dwork) */
  CANTest_M->dwork = ((void *) &CANTest_DW);
  (void) memset((void *)&CANTest_DW, 0,
                sizeof(DW_CANTest_T));
  CANTest_DW.d1_DSTATE = 0.0;
  CANTest_DW.d_DSTATE = 0.0;

  /* Initialize DataMapInfo substructure containing ModelMap for C API */
  CANTest_InitializeDataMapInfo();

  /* child S-Function registration */
  {
    RTWSfcnInfo *sfcnInfo = &CANTest_M->NonInlinedSFcns.sfcnInfo;
    CANTest_M->sfcnInfo = (sfcnInfo);
    rtssSetErrorStatusPtr(sfcnInfo, (&rtmGetErrorStatus(CANTest_M)));
    rtssSetNumRootSampTimesPtr(sfcnInfo, &CANTest_M->Sizes.numSampTimes);
    CANTest_M->NonInlinedSFcns.taskTimePtrs[0] = &(rtmGetTPtr(CANTest_M)[0]);
    rtssSetTPtrPtr(sfcnInfo,CANTest_M->NonInlinedSFcns.taskTimePtrs);
    rtssSetTStartPtr(sfcnInfo, &rtmGetTStart(CANTest_M));
    rtssSetTFinalPtr(sfcnInfo, &rtmGetTFinal(CANTest_M));
    rtssSetTimeOfLastOutputPtr(sfcnInfo, &rtmGetTimeOfLastOutput(CANTest_M));
    rtssSetStepSizePtr(sfcnInfo, &CANTest_M->Timing.stepSize);
    rtssSetStopRequestedPtr(sfcnInfo, &rtmGetStopRequested(CANTest_M));
    rtssSetDerivCacheNeedsResetPtr(sfcnInfo, &CANTest_M->derivCacheNeedsReset);
    rtssSetZCCacheNeedsResetPtr(sfcnInfo, &CANTest_M->zCCacheNeedsReset);
    rtssSetContTimeOutputInconsistentWithStateAtMajorStepPtr(sfcnInfo,
      &CANTest_M->CTOutputIncnstWithState);
    rtssSetSampleHitsPtr(sfcnInfo, &CANTest_M->Timing.sampleHits);
    rtssSetPerTaskSampleHitsPtr(sfcnInfo, &CANTest_M->Timing.perTaskSampleHits);
    rtssSetSimModePtr(sfcnInfo, &CANTest_M->simMode);
    rtssSetSolverInfoPtr(sfcnInfo, &CANTest_M->solverInfoPtr);
  }

  CANTest_M->Sizes.numSFcns = (3);

  /* register each child */
  {
    (void) memset((void *)&CANTest_M->NonInlinedSFcns.childSFunctions[0], 0,
                  3*sizeof(SimStruct));
    CANTest_M->childSfunctions = (&CANTest_M->
      NonInlinedSFcns.childSFunctionPtrs[0]);
    CANTest_M->childSfunctions[0] = (&CANTest_M->
      NonInlinedSFcns.childSFunctions[0]);
    CANTest_M->childSfunctions[1] = (&CANTest_M->
      NonInlinedSFcns.childSFunctions[1]);
    CANTest_M->childSfunctions[2] = (&CANTest_M->
      NonInlinedSFcns.childSFunctions[2]);

    /* Level2 S-Function Block: CANTest/<S1>/CAN Setup (sg_IO613_setup_s) */
    {
      SimStruct *rts = CANTest_M->childSfunctions[0];

      /* timing info */
      time_T *sfcnPeriod = CANTest_M->NonInlinedSFcns.Sfcn0.sfcnPeriod;
      time_T *sfcnOffset = CANTest_M->NonInlinedSFcns.Sfcn0.sfcnOffset;
      int_T *sfcnTsMap = CANTest_M->NonInlinedSFcns.Sfcn0.sfcnTsMap;
      (void) memset((void*)sfcnPeriod, 0,
                    sizeof(time_T)*1);
      (void) memset((void*)sfcnOffset, 0,
                    sizeof(time_T)*1);
      ssSetSampleTimePtr(rts, &sfcnPeriod[0]);
      ssSetOffsetTimePtr(rts, &sfcnOffset[0]);
      ssSetSampleTimeTaskIDPtr(rts, sfcnTsMap);

      {
        ssSetBlkInfo2Ptr(rts, &CANTest_M->NonInlinedSFcns.blkInfo2[0]);
      }

      _ssSetBlkInfo2PortInfo2Ptr(rts,
        &CANTest_M->NonInlinedSFcns.inputOutputPortInfo2[0]);

      /* Set up the mdlInfo pointer */
      ssSetRTWSfcnInfo(rts, CANTest_M->sfcnInfo);

      /* Allocate memory of model methods 2 */
      {
        ssSetModelMethods2(rts, &CANTest_M->NonInlinedSFcns.methods2[0]);
      }

      /* Allocate memory of model methods 3 */
      {
        ssSetModelMethods3(rts, &CANTest_M->NonInlinedSFcns.methods3[0]);
      }

      /* Allocate memory of model methods 4 */
      {
        ssSetModelMethods4(rts, &CANTest_M->NonInlinedSFcns.methods4[0]);
      }

      /* Allocate memory for states auxilliary information */
      {
        ssSetStatesInfo2(rts, &CANTest_M->NonInlinedSFcns.statesInfo2[0]);
        ssSetPeriodicStatesInfo(rts,
          &CANTest_M->NonInlinedSFcns.periodicStatesInfo[0]);
      }

      /* path info */
      ssSetModelName(rts, "CAN Setup");
      ssSetPath(rts, "CANTest/DAQ_In/CAN Setup");
      ssSetRTModel(rts,CANTest_M);
      ssSetParentSS(rts, (NULL));
      ssSetRootSS(rts, rts);
      ssSetVersion(rts, SIMSTRUCT_VERSION_LEVEL2);

      /* parameters */
      {
        mxArray **sfcnParams = (mxArray **)
          &CANTest_M->NonInlinedSFcns.Sfcn0.params;
        ssSetSFcnParamsCount(rts, 24);
        ssSetSFcnParamsPtr(rts, &sfcnParams[0]);
        ssSetSFcnParam(rts, 0, (mxArray*)CANTest_P.CANSetup_P1_Size);
        ssSetSFcnParam(rts, 1, (mxArray*)CANTest_P.CANSetup_P2_Size);
        ssSetSFcnParam(rts, 2, (mxArray*)CANTest_P.CANSetup_P3_Size);
        ssSetSFcnParam(rts, 3, (mxArray*)CANTest_P.CANSetup_P4_Size);
        ssSetSFcnParam(rts, 4, (mxArray*)CANTest_P.CANSetup_P5_Size);
        ssSetSFcnParam(rts, 5, (mxArray*)CANTest_P.CANSetup_P6_Size);
        ssSetSFcnParam(rts, 6, (mxArray*)CANTest_P.CANSetup_P7_Size);
        ssSetSFcnParam(rts, 7, (mxArray*)CANTest_P.CANSetup_P8_Size);
        ssSetSFcnParam(rts, 8, (mxArray*)CANTest_P.CANSetup_P9_Size);
        ssSetSFcnParam(rts, 9, (mxArray*)CANTest_P.CANSetup_P10_Size);
        ssSetSFcnParam(rts, 10, (mxArray*)CANTest_P.CANSetup_P11_Size);
        ssSetSFcnParam(rts, 11, (mxArray*)CANTest_P.CANSetup_P12_Size);
        ssSetSFcnParam(rts, 12, (mxArray*)CANTest_P.CANSetup_P13_Size);
        ssSetSFcnParam(rts, 13, (mxArray*)CANTest_P.CANSetup_P14_Size);
        ssSetSFcnParam(rts, 14, (mxArray*)CANTest_P.CANSetup_P15_Size);
        ssSetSFcnParam(rts, 15, (mxArray*)CANTest_P.CANSetup_P16_Size);
        ssSetSFcnParam(rts, 16, (mxArray*)CANTest_P.CANSetup_P17_Size);
        ssSetSFcnParam(rts, 17, (mxArray*)CANTest_P.CANSetup_P18_Size);
        ssSetSFcnParam(rts, 18, (mxArray*)CANTest_P.CANSetup_P19_Size);
        ssSetSFcnParam(rts, 19, (mxArray*)CANTest_P.CANSetup_P20_Size);
        ssSetSFcnParam(rts, 20, (mxArray*)CANTest_P.CANSetup_P21_Size);
        ssSetSFcnParam(rts, 21, (mxArray*)CANTest_P.CANSetup_P22_Size);
        ssSetSFcnParam(rts, 22, (mxArray*)CANTest_P.CANSetup_P23_Size);
        ssSetSFcnParam(rts, 23, (mxArray*)CANTest_P.CANSetup_P24_Size);
      }

      /* work vectors */
      ssSetIWork(rts, (int_T *) &CANTest_DW.CANSetup_IWORK);

      {
        struct _ssDWorkRecord *dWorkRecord = (struct _ssDWorkRecord *)
          &CANTest_M->NonInlinedSFcns.Sfcn0.dWork;
        struct _ssDWorkAuxRecord *dWorkAuxRecord = (struct _ssDWorkAuxRecord *)
          &CANTest_M->NonInlinedSFcns.Sfcn0.dWorkAux;
        ssSetSFcnDWork(rts, dWorkRecord);
        ssSetSFcnDWorkAux(rts, dWorkAuxRecord);
        _ssSetNumDWork(rts, 1);

        /* IWORK */
        ssSetDWorkWidth(rts, 0, 1);
        ssSetDWorkDataType(rts, 0,SS_INTEGER);
        ssSetDWorkComplexSignal(rts, 0, 0);
        ssSetDWork(rts, 0, &CANTest_DW.CANSetup_IWORK);
      }

      /* registration */
      sg_IO613_setup_s(rts);
      sfcnInitializeSizes(rts);
      sfcnInitializeSampleTimes(rts);

      /* adjust sample time */
      ssSetSampleTime(rts, 0, 0.002);
      ssSetOffsetTime(rts, 0, 0.0);
      sfcnTsMap[0] = 0;

      /* set compiled values of dynamic vector attributes */
      ssSetNumNonsampledZCs(rts, 0);

      /* Update connectivity flags for each port */
      /* Update the BufferDstPort flags for each input port */
    }

    /* Level2 S-Function Block: CANTest/<S1>/CAN Read1 (sg_IO61X_read_s) */
    {
      SimStruct *rts = CANTest_M->childSfunctions[1];

      /* timing info */
      time_T *sfcnPeriod = CANTest_M->NonInlinedSFcns.Sfcn1.sfcnPeriod;
      time_T *sfcnOffset = CANTest_M->NonInlinedSFcns.Sfcn1.sfcnOffset;
      int_T *sfcnTsMap = CANTest_M->NonInlinedSFcns.Sfcn1.sfcnTsMap;
      (void) memset((void*)sfcnPeriod, 0,
                    sizeof(time_T)*1);
      (void) memset((void*)sfcnOffset, 0,
                    sizeof(time_T)*1);
      ssSetSampleTimePtr(rts, &sfcnPeriod[0]);
      ssSetOffsetTimePtr(rts, &sfcnOffset[0]);
      ssSetSampleTimeTaskIDPtr(rts, sfcnTsMap);

      {
        ssSetBlkInfo2Ptr(rts, &CANTest_M->NonInlinedSFcns.blkInfo2[1]);
      }

      _ssSetBlkInfo2PortInfo2Ptr(rts,
        &CANTest_M->NonInlinedSFcns.inputOutputPortInfo2[1]);

      /* Set up the mdlInfo pointer */
      ssSetRTWSfcnInfo(rts, CANTest_M->sfcnInfo);

      /* Allocate memory of model methods 2 */
      {
        ssSetModelMethods2(rts, &CANTest_M->NonInlinedSFcns.methods2[1]);
      }

      /* Allocate memory of model methods 3 */
      {
        ssSetModelMethods3(rts, &CANTest_M->NonInlinedSFcns.methods3[1]);
      }

      /* Allocate memory of model methods 4 */
      {
        ssSetModelMethods4(rts, &CANTest_M->NonInlinedSFcns.methods4[1]);
      }

      /* Allocate memory for states auxilliary information */
      {
        ssSetStatesInfo2(rts, &CANTest_M->NonInlinedSFcns.statesInfo2[1]);
        ssSetPeriodicStatesInfo(rts,
          &CANTest_M->NonInlinedSFcns.periodicStatesInfo[1]);
      }

      /* outputs */
      {
        ssSetPortInfoForOutputs(rts,
          &CANTest_M->NonInlinedSFcns.Sfcn1.outputPortInfo[0]);
        _ssSetNumOutputPorts(rts, 2);
        _ssSetPortInfo2ForOutputUnits(rts,
          &CANTest_M->NonInlinedSFcns.Sfcn1.outputPortUnits[0]);
        ssSetOutputPortUnit(rts, 0, 0);
        ssSetOutputPortUnit(rts, 1, 0);
        _ssSetPortInfo2ForOutputCoSimAttribute(rts,
          &CANTest_M->NonInlinedSFcns.Sfcn1.outputPortCoSimAttribute[0]);
        ssSetOutputPortIsContinuousQuantity(rts, 0, 0);
        ssSetOutputPortIsContinuousQuantity(rts, 1, 0);

        /* port 0 */
        {
          _ssSetOutputPortNumDimensions(rts, 0, 1);
          ssSetOutputPortWidth(rts, 0, 1);
          ssSetOutputPortSignal(rts, 0, ((boolean_T *) &CANTest_B.CANRead1_o1));
        }

        /* port 1 */
        {
          _ssSetOutputPortNumDimensions(rts, 1, 1);
          ssSetOutputPortWidth(rts, 1, 1);
          ssSetOutputPortSignal(rts, 1, ((CAN_DATATYPE *) &CANTest_B.CANRead1_o2));
        }
      }

      /* path info */
      ssSetModelName(rts, "CAN Read1");
      ssSetPath(rts, "CANTest/DAQ_In/CAN Read1");
      ssSetRTModel(rts,CANTest_M);
      ssSetParentSS(rts, (NULL));
      ssSetRootSS(rts, rts);
      ssSetVersion(rts, SIMSTRUCT_VERSION_LEVEL2);

      /* parameters */
      {
        mxArray **sfcnParams = (mxArray **)
          &CANTest_M->NonInlinedSFcns.Sfcn1.params;
        ssSetSFcnParamsCount(rts, 6);
        ssSetSFcnParamsPtr(rts, &sfcnParams[0]);
        ssSetSFcnParam(rts, 0, (mxArray*)CANTest_P.CANRead1_P1_Size);
        ssSetSFcnParam(rts, 1, (mxArray*)CANTest_P.CANRead1_P2_Size);
        ssSetSFcnParam(rts, 2, (mxArray*)CANTest_P.CANRead1_P3_Size);
        ssSetSFcnParam(rts, 3, (mxArray*)CANTest_P.CANRead1_P4_Size);
        ssSetSFcnParam(rts, 4, (mxArray*)CANTest_P.CANRead1_P5_Size);
        ssSetSFcnParam(rts, 5, (mxArray*)CANTest_P.CANRead1_P6_Size);
      }

      /* work vectors */
      ssSetIWork(rts, (int_T *) &CANTest_DW.CANRead1_IWORK);

      {
        struct _ssDWorkRecord *dWorkRecord = (struct _ssDWorkRecord *)
          &CANTest_M->NonInlinedSFcns.Sfcn1.dWork;
        struct _ssDWorkAuxRecord *dWorkAuxRecord = (struct _ssDWorkAuxRecord *)
          &CANTest_M->NonInlinedSFcns.Sfcn1.dWorkAux;
        ssSetSFcnDWork(rts, dWorkRecord);
        ssSetSFcnDWorkAux(rts, dWorkAuxRecord);
        _ssSetNumDWork(rts, 1);

        /* IWORK */
        ssSetDWorkWidth(rts, 0, 1);
        ssSetDWorkDataType(rts, 0,SS_INTEGER);
        ssSetDWorkComplexSignal(rts, 0, 0);
        ssSetDWork(rts, 0, &CANTest_DW.CANRead1_IWORK);
      }

      /* registration */
      sg_IO61X_read_s(rts);
      sfcnInitializeSizes(rts);
      sfcnInitializeSampleTimes(rts);

      /* adjust sample time */
      ssSetSampleTime(rts, 0, 0.002);
      ssSetOffsetTime(rts, 0, 0.0);
      sfcnTsMap[0] = 0;

      /* set compiled values of dynamic vector attributes */
      ssSetNumNonsampledZCs(rts, 0);

      /* Update connectivity flags for each port */
      _ssSetOutputPortConnected(rts, 0, 1);
      _ssSetOutputPortConnected(rts, 1, 1);
      _ssSetOutputPortBeingMerged(rts, 0, 0);
      _ssSetOutputPortBeingMerged(rts, 1, 0);

      /* Update the BufferDstPort flags for each input port */
    }

    /* Level2 S-Function Block: CANTest/<S5>/CAN Write1 (sg_IO61X_write_s) */
    {
      SimStruct *rts = CANTest_M->childSfunctions[2];

      /* timing info */
      time_T *sfcnPeriod = CANTest_M->NonInlinedSFcns.Sfcn2.sfcnPeriod;
      time_T *sfcnOffset = CANTest_M->NonInlinedSFcns.Sfcn2.sfcnOffset;
      int_T *sfcnTsMap = CANTest_M->NonInlinedSFcns.Sfcn2.sfcnTsMap;
      (void) memset((void*)sfcnPeriod, 0,
                    sizeof(time_T)*1);
      (void) memset((void*)sfcnOffset, 0,
                    sizeof(time_T)*1);
      ssSetSampleTimePtr(rts, &sfcnPeriod[0]);
      ssSetOffsetTimePtr(rts, &sfcnOffset[0]);
      ssSetSampleTimeTaskIDPtr(rts, sfcnTsMap);

      {
        ssSetBlkInfo2Ptr(rts, &CANTest_M->NonInlinedSFcns.blkInfo2[2]);
      }

      _ssSetBlkInfo2PortInfo2Ptr(rts,
        &CANTest_M->NonInlinedSFcns.inputOutputPortInfo2[2]);

      /* Set up the mdlInfo pointer */
      ssSetRTWSfcnInfo(rts, CANTest_M->sfcnInfo);

      /* Allocate memory of model methods 2 */
      {
        ssSetModelMethods2(rts, &CANTest_M->NonInlinedSFcns.methods2[2]);
      }

      /* Allocate memory of model methods 3 */
      {
        ssSetModelMethods3(rts, &CANTest_M->NonInlinedSFcns.methods3[2]);
      }

      /* Allocate memory of model methods 4 */
      {
        ssSetModelMethods4(rts, &CANTest_M->NonInlinedSFcns.methods4[2]);
      }

      /* Allocate memory for states auxilliary information */
      {
        ssSetStatesInfo2(rts, &CANTest_M->NonInlinedSFcns.statesInfo2[2]);
        ssSetPeriodicStatesInfo(rts,
          &CANTest_M->NonInlinedSFcns.periodicStatesInfo[2]);
      }

      /* inputs */
      {
        _ssSetNumInputPorts(rts, 1);
        ssSetPortInfoForInputs(rts,
          &CANTest_M->NonInlinedSFcns.Sfcn2.inputPortInfo[0]);
        _ssSetPortInfo2ForInputUnits(rts,
          &CANTest_M->NonInlinedSFcns.Sfcn2.inputPortUnits[0]);
        ssSetInputPortUnit(rts, 0, 0);
        _ssSetPortInfo2ForInputCoSimAttribute(rts,
          &CANTest_M->NonInlinedSFcns.Sfcn2.inputPortCoSimAttribute[0]);
        ssSetInputPortIsContinuousQuantity(rts, 0, 0);

        /* port 0 */
        {
          ssSetInputPortRequiredContiguous(rts, 0, 1);
          ssSetInputPortSignal(rts, 0, &CANTest_B.CANPack);
          _ssSetInputPortNumDimensions(rts, 0, 1);
          ssSetInputPortWidth(rts, 0, 1);
        }
      }

      /* path info */
      ssSetModelName(rts, "CAN Write1");
      ssSetPath(rts, "CANTest/DAQ_Out/CANBoard/CAN Write1");
      ssSetRTModel(rts,CANTest_M);
      ssSetParentSS(rts, (NULL));
      ssSetRootSS(rts, rts);
      ssSetVersion(rts, SIMSTRUCT_VERSION_LEVEL2);

      /* parameters */
      {
        mxArray **sfcnParams = (mxArray **)
          &CANTest_M->NonInlinedSFcns.Sfcn2.params;
        ssSetSFcnParamsCount(rts, 7);
        ssSetSFcnParamsPtr(rts, &sfcnParams[0]);
        ssSetSFcnParam(rts, 0, (mxArray*)CANTest_P.CANWrite1_P1_Size);
        ssSetSFcnParam(rts, 1, (mxArray*)CANTest_P.CANWrite1_P2_Size);
        ssSetSFcnParam(rts, 2, (mxArray*)CANTest_P.CANWrite1_P3_Size);
        ssSetSFcnParam(rts, 3, (mxArray*)CANTest_P.CANWrite1_P4_Size);
        ssSetSFcnParam(rts, 4, (mxArray*)CANTest_P.CANWrite1_P5_Size);
        ssSetSFcnParam(rts, 5, (mxArray*)CANTest_P.CANWrite1_P6_Size);
        ssSetSFcnParam(rts, 6, (mxArray*)CANTest_P.CANWrite1_P7_Size);
      }

      /* work vectors */
      ssSetIWork(rts, (int_T *) &CANTest_DW.CANWrite1_IWORK);
      ssSetPWork(rts, (void **) &CANTest_DW.CANWrite1_PWORK);

      {
        struct _ssDWorkRecord *dWorkRecord = (struct _ssDWorkRecord *)
          &CANTest_M->NonInlinedSFcns.Sfcn2.dWork;
        struct _ssDWorkAuxRecord *dWorkAuxRecord = (struct _ssDWorkAuxRecord *)
          &CANTest_M->NonInlinedSFcns.Sfcn2.dWorkAux;
        ssSetSFcnDWork(rts, dWorkRecord);
        ssSetSFcnDWorkAux(rts, dWorkAuxRecord);
        _ssSetNumDWork(rts, 2);

        /* IWORK */
        ssSetDWorkWidth(rts, 0, 1);
        ssSetDWorkDataType(rts, 0,SS_INTEGER);
        ssSetDWorkComplexSignal(rts, 0, 0);
        ssSetDWork(rts, 0, &CANTest_DW.CANWrite1_IWORK);

        /* PWORK */
        ssSetDWorkWidth(rts, 1, 1);
        ssSetDWorkDataType(rts, 1,SS_POINTER);
        ssSetDWorkComplexSignal(rts, 1, 0);
        ssSetDWork(rts, 1, &CANTest_DW.CANWrite1_PWORK);
      }

      /* registration */
      sg_IO61X_write_s(rts);
      sfcnInitializeSizes(rts);
      sfcnInitializeSampleTimes(rts);

      /* adjust sample time */
      ssSetSampleTime(rts, 0, 0.002);
      ssSetOffsetTime(rts, 0, 0.0);
      sfcnTsMap[0] = 0;

      /* set compiled values of dynamic vector attributes */
      ssSetNumNonsampledZCs(rts, 0);

      /* Update connectivity flags for each port */
      _ssSetInputPortConnected(rts, 0, 1);

      /* Update the BufferDstPort flags for each input port */
      ssSetInputPortBufferDstPort(rts, 0, -1);
    }
  }

  /* Initialize Sizes */
  CANTest_M->Sizes.numContStates = (0);/* Number of continuous states */
  CANTest_M->Sizes.numY = (0);         /* Number of model outputs */
  CANTest_M->Sizes.numU = (0);         /* Number of model inputs */
  CANTest_M->Sizes.sysDirFeedThru = (0);/* The model is not direct feedthrough */
  CANTest_M->Sizes.numSampTimes = (1); /* Number of sample times */
  CANTest_M->Sizes.numBlocks = (39);   /* Number of blocks */
  CANTest_M->Sizes.numBlockIO = (23);  /* Number of block outputs */
  CANTest_M->Sizes.numBlockPrms = (163);/* Sum of parameter "widths" */
  return CANTest_M;
}

/*========================================================================*
 * End of Classic call interface                                          *
 *========================================================================*/
