File: SYS_STATS_Functional.c

    1   /*
    2    * Code generation for system model 'SYS_STATS_Functional'
    3    *
    4    * Model                      : SYS_STATS_Functional
    5    * Model version              : 1.1404
    6    * Simulink Coder version : 8.4 (R2013a) 13-Feb-2013
    7    * C source code generated on : Thu Sep 12 09:50:15 2013
    8    *
    9    * Note that the functions contained in this file are part of a Simulink
   10    * model, and are not self-contained algorithms.
   11    */
   12   
   13   #include "SYS_STATS_Functional.h"
   14   #include "SYS_STATS_Functional_private.h"
   15   
   16   /* Initial conditions for referenced model: 'SYS_STATS_Functional' */
   17   void SYS_STATS_Functional_Init(DW_SYS_STATS_Functional_f_T *localDW)
   18   {
   19     /* InitializeConditions for UnitDelay: '<S5>/Unit Delay' */
   20     localDW->UnitDelay_DSTATE = 0U;
   21   }
   22   
   23   /* Outputs for referenced model: 'SYS_STATS_Functional' */
   24   void SYS_STATS_Functional(const Infusion_Manager_Outputs *rtu_IM_IN, const
   25     Top_Level_Mode_Outputs *rtu_TLM_MODE_IN, const Device_Sensor_Inputs
   26     *rtu_SENSOR_IN, const Device_Configuration_Inputs *rtu_CONST_IN, const
   27     Config_Outputs *rtu_CONFIG_IN, System_Status_Outputs *rty_SYS_STAT_OUT,
   28     B_SYS_STATS_Functional_c_T *localB, DW_SYS_STATS_Functional_f_T *localDW)
   29   {
   30     uint8_T rtb_Reservoir_Volume_e;
   31     uint8_T tmp;
   32   
   33     /* Switch: '<S4>/Reservoir_Volume' incorporates:
   34      *  Constant: '<S4>/Constant'
   35      *  Product: '<S4>/Divide'
   36      *  Sum: '<S4>/Subtract'
   37      *  Switch: '<S4>/Reservoir_Empty'
   38      */
   39     if (rtu_TLM_MODE_IN->System_On) {
   40       rtb_Reservoir_Volume_e = (uint8_T)(rtu_CONFIG_IN->Reservoir_Volume -
   41         rtu_SENSOR_IN->Flow_Rate);
   42   
   43       /* Switch: '<S4>/if then ' incorporates:
   44        *  Product: '<S4>/Divide'
   45        *  RelationalOperator: '<S4>/Relational Operator'
   46        *  Sum: '<S4>/Subtract'
   47        */
   48       rty_SYS_STAT_OUT->Reservoir_Empty = (rtb_Reservoir_Volume_e <
   49         rtu_CONST_IN->Empty_Reservoir);
   50     } else {
   51       rtb_Reservoir_Volume_e = 0U;
   52   
   53       /* Switch: '<S4>/if then ' incorporates:
   54        *  Constant: '<S4>/Constant'
   55        *  Constant: '<S4>/Constant16'
   56        */
   57       rty_SYS_STAT_OUT->Reservoir_Empty = FALSE;
   58     }
   59   
   60     /* End of Switch: '<S4>/Reservoir_Volume' */
   61   
   62     /* Switch: '<S5>/if then 4 ' incorporates:
   63      *  Constant: '<S5>/Constant8'
   64      *  Logic: '<S5>/Logical Operator3'
   65      *  UnitDelay: '<S5>/Unit Delay'
   66      */
   67     if (!rtu_IM_IN->New_Infusion) {
   68       tmp = localDW->UnitDelay_DSTATE;
   69     } else {
   70       tmp = 0U;
   71     }
   72   
   73     /* End of Switch: '<S5>/if then 4 ' */
   74   
   75     /* Sum: '<S5>/Subtract1' incorporates:
   76      *  Product: '<S5>/Divide1'
   77      */
   78     localB->Subtract1 = (uint8_T)((uint32_T)tmp + rtu_SENSOR_IN->Flow_Rate);
   79   
   80     /* Switch: '<S3>/Total_Volume_Infused2' incorporates:
   81      *  Constant: '<S3>/Constant20'
   82      *  Constant: '<S3>/Constant21'
   83      *  Switch: '<S2>/In_Therapy'
   84      */
   85     if (rtu_TLM_MODE_IN->System_On) {
   86       rty_SYS_STAT_OUT->Log_Message_ID = 8U;
   87   
   88       /* Switch: '<S2>/if then6' incorporates:
   89        *  Constant: '<S2>/Constant5'
   90        *  Constant: '<S3>/Constant21'
   91        *  RelationalOperator: '<S2>/Relational Operator1'
   92        */
   93       rty_SYS_STAT_OUT->In_Therapy = (rtu_IM_IN->Current_System_Mode > 1);
   94     } else {
   95       rty_SYS_STAT_OUT->Log_Message_ID = 0U;
   96   
   97       /* Switch: '<S2>/if then6' incorporates:
   98        *  Constant: '<S2>/Constant17'
   99        *  Constant: '<S3>/Constant20'
  100        */
  101       rty_SYS_STAT_OUT->In_Therapy = FALSE;
  102     }
  103   
  104     /* End of Switch: '<S3>/Total_Volume_Infused2' */
  105   
  106     /* BusCreator: '<Root>/BusConversion_InsertedFor_SYS_STAT_OUT_at_inport_0' */
  107     rty_SYS_STAT_OUT->Reservoir_Volume = rtb_Reservoir_Volume_e;
  108   
  109     /* Switch: '<S5>/Total_Volume_Infused' */
  110     if (rtu_TLM_MODE_IN->System_On) {
  111       /* BusCreator: '<Root>/BusConversion_InsertedFor_SYS_STAT_OUT_at_inport_0' */
  112       rty_SYS_STAT_OUT->Volume_Infused = localB->Subtract1;
  113     } else {
  114       /* BusCreator: '<Root>/BusConversion_InsertedFor_SYS_STAT_OUT_at_inport_0' incorporates:
  115        *  Constant: '<S5>/Constant9'
  116        */
  117       rty_SYS_STAT_OUT->Volume_Infused = 0U;
  118     }
  119   
  120     /* End of Switch: '<S5>/Total_Volume_Infused' */
  121   }
  122   
  123   /* Update for referenced model: 'SYS_STATS_Functional' */
  124   void SYS_STATS_Functional_Update(B_SYS_STATS_Functional_c_T *localB,
  125     DW_SYS_STATS_Functional_f_T *localDW)
  126   {
  127     /* Update for UnitDelay: '<S5>/Unit Delay' */
  128     localDW->UnitDelay_DSTATE = localB->Subtract1;
  129   }
  130   
  131   /* Model initialize function */
  132   void SYS_STATS_Functional_initialize(const char_T **rt_errorStatus,
  133     RT_MODEL_SYS_STATS_Functional_T *const SYS_STATS_Functional_M,
  134     B_SYS_STATS_Functional_c_T *localB, DW_SYS_STATS_Functional_f_T *localDW)
  135   {
  136     /* Registration code */
  137   
  138     /* initialize error status */
  139     rtmSetErrorStatusPointer(SYS_STATS_Functional_M, rt_errorStatus);
  140   
  141     /* block I/O */
  142     (void) memset(((void *) localB), 0,
  143                   sizeof(B_SYS_STATS_Functional_c_T));
  144   
  145     /* states (dwork) */
  146     (void) memset((void *)localDW, 0,
  147                   sizeof(DW_SYS_STATS_Functional_f_T));
  148   }
  149