File: INFUSION_MGR_Functional.c

    1   /*
    2    * Code generation for system model 'INFUSION_MGR_Functional'
    3    *
    4    * Model                      : INFUSION_MGR_Functional
    5    * Model version              : 1.1141
    6    * Simulink Coder version : 8.4 (R2013a) 13-Feb-2013
    7    * C source code generated on : Thu Sep 12 09:49:58 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 "INFUSION_MGR_Functional.h"
   14   #include "INFUSION_MGR_Functional_private.h"
   15   
   16   /* Named constants for Chart: '<Root>/Infusion Manager Sub-System' */
   17   #define INFUSION_MGR_Functional_IN_ACTIVE ((uint8_T)1U)
   18   #define INFUSION_MGR_Functional_IN_Basal ((uint8_T)1U)
   19   #define INFUSION_MGR_Functional_IN_IDLE ((uint8_T)1U)
   20   #define INFUSION_MGR_Functional_IN_Infusion_Manager ((uint8_T)1U)
   21   #define INFUSION_MGR_Functional_IN_Intermittent_Bolus ((uint8_T)2U)
   22   #define INFUSION_MGR_Functional_IN_LOCKOUT ((uint8_T)1U)
   23   #define INFUSION_MGR_Functional_IN_Manual_Paused_KVO ((uint8_T)1U)
   24   #define INFUSION_MGR_Functional_IN_NOT_ON ((uint8_T)2U)
   25   #define INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD ((uint8_T)0U)
   26   #define INFUSION_MGR_Functional_IN_OFF ((uint8_T)1U)
   27   #define INFUSION_MGR_Functional_IN_OFF_b ((uint8_T)2U)
   28   #define INFUSION_MGR_Functional_IN_ON  ((uint8_T)2U)
   29   #define INFUSION_MGR_Functional_IN_ON_b ((uint8_T)3U)
   30   #define INFUSION_MGR_Functional_IN_PAUSED ((uint8_T)2U)
   31   #define INFUSION_MGR_Functional_IN_Patient_Bolus ((uint8_T)3U)
   32   #define INFUSION_MGR_Functional_IN_Paused_KVO ((uint8_T)2U)
   33   #define INFUSION_MGR_Functional_IN_Paused_NoKVO ((uint8_T)3U)
   34   #define INFUSION_MGR_Functional_IN_THERAPY ((uint8_T)2U)
   35   
   36   /* Forward declaration for local functions */
   37   static real_T INFUSION_MGR_Functional_Step_Scaling_Factor(uint8_T inputVal);
   38   static void INFUSION_MGR_Functional_writeLog(real_T logEvent,
   39     B_INFUSION_MGR_Functional_c_T *localB);
   40   static void INFUSION_MGR_Functional_resetForNewInfusion
   41     (B_INFUSION_MGR_Functional_c_T *localB, DW_INFUSION_MGR_Functional_f_T
   42      *localDW);
   43   static void INFUSION_MGR_Functional_exit_internal_ACTIVE
   44     (DW_INFUSION_MGR_Functional_f_T *localDW);
   45   static void INFUSION_MGR_Functional_exit_internal_PAUSED
   46     (B_INFUSION_MGR_Functional_c_T *localB, DW_INFUSION_MGR_Functional_f_T
   47      *localDW);
   48   static void INFUSION_MGR_Functional_TherapyExitOperations
   49     (B_INFUSION_MGR_Functional_c_T *localB);
   50   static real_T INFUSION_MGR_Functional_sbolus_trigger
   51     (B_INFUSION_MGR_Functional_c_T *localB, DW_INFUSION_MGR_Functional_f_T
   52      *localDW);
   53   static void INFUSION_MGR_Functional_enter_internal_ACTIVE
   54     (B_INFUSION_MGR_Functional_c_T *localB, DW_INFUSION_MGR_Functional_f_T
   55      *localDW);
   56   static void INFUSION_MGR_Functional_enter_internal_PAUSED
   57     (B_INFUSION_MGR_Functional_c_T *localB, DW_INFUSION_MGR_Functional_f_T
   58      *localDW);
   59   static void INFUSION_MGR_Functional_resetAllInfusionDetails
   60     (B_INFUSION_MGR_Functional_c_T *localB, DW_INFUSION_MGR_Functional_f_T
   61      *localDW);
   62   static void INFUSION_MGR_Functional_THERAPY(B_INFUSION_MGR_Functional_c_T
   63     *localB, DW_INFUSION_MGR_Functional_f_T *localDW);
   64   
   65   /* Function for Chart: '<Root>/Infusion Manager Sub-System' */
   66   static real_T INFUSION_MGR_Functional_Step_Scaling_Factor(uint8_T inputVal)
   67   {
   68     /* Graphical Function 'Step_Scaling_Factor': '<S1>:4016' */
   69     /* Transition: '<S1>:4013' */
   70     return inputVal;
   71   }
   72   
   73   /* Function for Chart: '<Root>/Infusion Manager Sub-System' */
   74   static void INFUSION_MGR_Functional_writeLog(real_T logEvent,
   75     B_INFUSION_MGR_Functional_c_T *localB)
   76   {
   77     /* Graphical Function 'writeLog': '<S1>:3724' */
   78     /* Transition: '<S1>:3726' */
   79     localB->IM_OUT_Log_Message_ID = (uint8_T)logEvent;
   80   }
   81   
   82   /* Function for Chart: '<Root>/Infusion Manager Sub-System' */
   83   static void INFUSION_MGR_Functional_resetForNewInfusion
   84     (B_INFUSION_MGR_Functional_c_T *localB, DW_INFUSION_MGR_Functional_f_T
   85      *localDW)
   86   {
   87     /* Graphical Function 'resetForNewInfusion': '<S1>:3956' */
   88     /* Transition: '<S1>:3958' */
   89     localDW->sbolus_timer = 0U;
   90     localDW->pbolus_timer = 0U;
   91     localDW->number_pbolus = 0U;
   92     localDW->sbolusInter_timer = 0U;
   93     localB->IM_OUT_Flow_Rate_Commanded = 0U;
   94     localB->IM_OUT_Actual_Infusion_Duration = 0U;
   95     INFUSION_MGR_Functional_writeLog(1.0, localB);
   96   }
   97   
   98   /* Function for Chart: '<Root>/Infusion Manager Sub-System' */
   99   static void INFUSION_MGR_Functional_exit_internal_ACTIVE
  100     (DW_INFUSION_MGR_Functional_f_T *localDW)
  101   {
  102     /* Exit Internal 'ACTIVE': '<S1>:3905' */
  103     /* Exit Internal 'Arbiter': '<S1>:3913' */
  104     localDW->is_Arbiter_d = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  105     localDW->is_active_Arbiter_c = 0U;
  106   
  107     /* Exit Internal 'INTERMITTENT': '<S1>:3936' */
  108     if (localDW->is_INTERMITTENT == INFUSION_MGR_Functional_IN_ON) {
  109       /* Exit 'ON': '<S1>:3941' */
  110       localDW->sbolus_timer++;
  111       localDW->sbolus_req = FALSE;
  112       localDW->is_INTERMITTENT = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  113     } else {
  114       localDW->is_INTERMITTENT = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  115     }
  116   
  117     localDW->is_active_INTERMITTENT = 0U;
  118   
  119     /* Exit Internal 'PATIENT': '<S1>:3927' */
  120     if (localDW->is_PATIENT == INFUSION_MGR_Functional_IN_ON_b) {
  121       /* Exit 'ON': '<S1>:3934' */
  122       localDW->pbolus_timer++;
  123       localDW->is_PATIENT = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  124     } else {
  125       localDW->is_PATIENT = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  126     }
  127   
  128     localDW->is_active_PATIENT = 0U;
  129   
  130     /* Exit Internal 'BASAL': '<S1>:3907' */
  131     localDW->is_BASAL = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  132     localDW->is_active_BASAL = 0U;
  133   }
  134   
  135   /* Function for Chart: '<Root>/Infusion Manager Sub-System' */
  136   static void INFUSION_MGR_Functional_exit_internal_PAUSED
  137     (B_INFUSION_MGR_Functional_c_T *localB, DW_INFUSION_MGR_Functional_f_T
  138      *localDW)
  139   {
  140     /* Exit Internal 'PAUSED': '<S1>:3876' */
  141     /* Exit Internal 'Arbiter': '<S1>:3877' */
  142     switch (localDW->is_Arbiter) {
  143      case INFUSION_MGR_Functional_IN_Manual_Paused_KVO:
  144       /* Exit 'Manual_Paused_KVO': '<S1>:3892' */
  145       localB->IM_OUT_Flow_Rate_Commanded = localB->Flow_Rate_KVO;
  146       localB->IM_OUT_Current_System_Mode = 8U;
  147       localDW->is_Arbiter = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  148       break;
  149   
  150      case INFUSION_MGR_Functional_IN_Paused_KVO:
  151       /* Exit 'Paused_KVO': '<S1>:3891' */
  152       localB->IM_OUT_Flow_Rate_Commanded = localB->Flow_Rate_KVO;
  153       localB->IM_OUT_Current_System_Mode = 7U;
  154       localDW->is_Arbiter = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  155       break;
  156   
  157      case INFUSION_MGR_Functional_IN_Paused_NoKVO:
  158       /* Exit 'Paused_NoKVO': '<S1>:3890' */
  159       localB->IM_OUT_Flow_Rate_Commanded = 0U;
  160       localB->IM_OUT_Current_System_Mode = 6U;
  161       localDW->is_Arbiter = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  162       break;
  163   
  164      default:
  165       localDW->is_Arbiter = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  166       break;
  167     }
  168   
  169     localDW->is_active_Arbiter = 0U;
  170   
  171     /* Exit Internal 'Manual_Paused': '<S1>:3899' */
  172     localDW->is_Manual_Paused = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  173     localDW->is_active_Manual_Paused = 0U;
  174   
  175     /* Exit Internal 'Alarm_Paused': '<S1>:3893' */
  176     localDW->is_Alarm_Paused = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  177     localDW->is_active_Alarm_Paused = 0U;
  178   }
  179   
  180   /* Function for Chart: '<Root>/Infusion Manager Sub-System' */
  181   static void INFUSION_MGR_Functional_TherapyExitOperations
  182     (B_INFUSION_MGR_Functional_c_T *localB)
  183   {
  184     /* Graphical Function 'TherapyExitOperations': '<S1>:3953' */
  185     /* Transition: '<S1>:3955' */
  186     localB->IM_OUT_Flow_Rate_Commanded = 0U;
  187     localB->IM_OUT_New_Infusion = FALSE;
  188   }
  189   
  190   /* Function for Chart: '<Root>/Infusion Manager Sub-System' */
  191   static real_T INFUSION_MGR_Functional_sbolus_trigger
  192     (B_INFUSION_MGR_Functional_c_T *localB, DW_INFUSION_MGR_Functional_f_T
  193      *localDW)
  194   {
  195     real_T sb;
  196   
  197     /* Graphical Function 'sbolus_trigger': '<S1>:3943' */
  198     /* Transition: '<S1>:3947' */
  199     sb = 0.0;
  200     if (!(((real_T)localDW->sbolusInter_timer >
  201            INFUSION_MGR_Functional_Step_Scaling_Factor
  202            (localB->Interval_Intermittent_Bolus)) || ((real_T)
  203           localDW->sbolusInter_timer < INFUSION_MGR_Functional_Step_Scaling_Factor
  204           (localB->Interval_Intermittent_Bolus)) || (!((real_T)
  205            localDW->sbolusInter_timer ==
  206            INFUSION_MGR_Functional_Step_Scaling_Factor
  207            (localB->Interval_Intermittent_Bolus))))) {
  208       /* Transition: '<S1>:3949' */
  209       sb = 1.0;
  210       localDW->sbolusInter_timer = 0U;
  211     } else {
  212       /* Transition: '<S1>:3948' */
  213     }
  214   
  215     return sb;
  216   }
  217   
  218   /* Function for Chart: '<Root>/Infusion Manager Sub-System' */
  219   static void INFUSION_MGR_Functional_enter_internal_ACTIVE
  220     (B_INFUSION_MGR_Functional_c_T *localB, DW_INFUSION_MGR_Functional_f_T
  221      *localDW)
  222   {
  223     /* Entry Internal 'ACTIVE': '<S1>:3905' */
  224     localDW->is_active_BASAL = 1U;
  225   
  226     /* Entry Internal 'BASAL': '<S1>:3907' */
  227     /* Transition: '<S1>:3908' */
  228     localDW->is_BASAL = INFUSION_MGR_Functional_IN_ON;
  229     localDW->is_active_PATIENT = 1U;
  230   
  231     /* Entry Internal 'PATIENT': '<S1>:3927' */
  232     if (localDW->inPatientBolus) {
  233       /* Transition: '<S1>:3930' */
  234       localDW->is_PATIENT = INFUSION_MGR_Functional_IN_LOCKOUT;
  235   
  236       /* Entry 'LOCKOUT': '<S1>:3935' */
  237       localDW->lock_timer++;
  238     } else {
  239       /* Transition: '<S1>:3928' */
  240       localDW->is_PATIENT = INFUSION_MGR_Functional_IN_OFF_b;
  241   
  242       /* Entry 'OFF': '<S1>:3933' */
  243       localDW->pbolus_timer = 0U;
  244       localDW->inPatientBolus = FALSE;
  245     }
  246   
  247     localDW->is_active_INTERMITTENT = 1U;
  248   
  249     /* Entry 'INTERMITTENT': '<S1>:3936' */
  250     localDW->sbolusInter_timer++;
  251   
  252     /* Entry Internal 'INTERMITTENT': '<S1>:3936' */
  253     /* Transition: '<S1>:3937' */
  254     localDW->is_INTERMITTENT = INFUSION_MGR_Functional_IN_OFF;
  255   
  256     /* Entry 'OFF': '<S1>:3940' */
  257     localDW->sbolus_timer = 0U;
  258     localDW->sbolus_req = FALSE;
  259     localDW->sbolus_req = (INFUSION_MGR_Functional_sbolus_trigger(localB, localDW)
  260       != 0.0);
  261     localDW->is_active_Arbiter_c = 1U;
  262   
  263     /* Entry Internal 'Arbiter': '<S1>:3913' */
  264     /* Transition: '<S1>:3916' */
  265     if (localDW->is_PATIENT == INFUSION_MGR_Functional_IN_ON_b) {
  266       /* Transition: '<S1>:3917' */
  267       localDW->is_Arbiter_d = INFUSION_MGR_Functional_IN_Patient_Bolus;
  268   
  269       /* Entry 'Patient_Bolus': '<S1>:3924' */
  270       localB->IM_OUT_Flow_Rate_Commanded = localB->Flow_Rate_Patient_Bolus;
  271       localB->IM_OUT_Current_System_Mode = 4U;
  272     } else if (localDW->is_INTERMITTENT == INFUSION_MGR_Functional_IN_ON) {
  273       /* Transition: '<S1>:3918' */
  274       localDW->is_Arbiter_d = INFUSION_MGR_Functional_IN_Intermittent_Bolus;
  275   
  276       /* Entry 'Intermittent_Bolus': '<S1>:3925' */
  277       localB->IM_OUT_Flow_Rate_Commanded = localB->Flow_Rate_Intermittent_Bolus;
  278       localB->IM_OUT_Current_System_Mode = 3U;
  279     } else {
  280       /* Transition: '<S1>:3919' */
  281       localDW->is_Arbiter_d = INFUSION_MGR_Functional_IN_Basal;
  282   
  283       /* Entry 'Basal': '<S1>:3926' */
  284       localB->IM_OUT_Flow_Rate_Commanded = localB->Flow_Rate_Basal;
  285       localB->IM_OUT_Current_System_Mode = 2U;
  286     }
  287   }
  288   
  289   /* Function for Chart: '<Root>/Infusion Manager Sub-System' */
  290   static void INFUSION_MGR_Functional_enter_internal_PAUSED
  291     (B_INFUSION_MGR_Functional_c_T *localB, DW_INFUSION_MGR_Functional_f_T
  292      *localDW)
  293   {
  294     /* Entry Internal 'PAUSED': '<S1>:3876' */
  295     localDW->is_active_Alarm_Paused = 1U;
  296   
  297     /* Entry Internal 'Alarm_Paused': '<S1>:3893' */
  298     if (localB->Highest_Level_Alarm >= 3) {
  299       /* Transition: '<S1>:3964' */
  300       localDW->is_Alarm_Paused = INFUSION_MGR_Functional_IN_ON;
  301     } else {
  302       /* Transition: '<S1>:3894' */
  303       localDW->is_Alarm_Paused = INFUSION_MGR_Functional_IN_OFF;
  304     }
  305   
  306     localDW->is_active_Manual_Paused = 1U;
  307   
  308     /* Entry Internal 'Manual_Paused': '<S1>:3899' */
  309     if (localB->Infusion_Inhibit) {
  310       /* Transition: '<S1>:3965' */
  311       localDW->is_Manual_Paused = INFUSION_MGR_Functional_IN_ON;
  312     } else {
  313       /* Transition: '<S1>:3900' */
  314       localDW->is_Manual_Paused = INFUSION_MGR_Functional_IN_OFF;
  315     }
  316   
  317     localDW->is_active_Arbiter = 1U;
  318   
  319     /* Entry Internal 'Arbiter': '<S1>:3877' */
  320     /* Transition: '<S1>:3881' */
  321     if ((localDW->is_Alarm_Paused == INFUSION_MGR_Functional_IN_ON) &&
  322         (localB->Highest_Level_Alarm == 4)) {
  323       /* Transition: '<S1>:3882' */
  324       localDW->is_Arbiter = INFUSION_MGR_Functional_IN_Paused_NoKVO;
  325   
  326       /* Entry 'Paused_NoKVO': '<S1>:3890' */
  327       localB->IM_OUT_Flow_Rate_Commanded = 0U;
  328       localB->IM_OUT_Current_System_Mode = 6U;
  329     } else if ((localDW->is_Alarm_Paused == INFUSION_MGR_Functional_IN_ON) &&
  330                (localB->Highest_Level_Alarm == 3)) {
  331       /* Transition: '<S1>:3884' */
  332       localDW->is_Arbiter = INFUSION_MGR_Functional_IN_Paused_KVO;
  333   
  334       /* Entry 'Paused_KVO': '<S1>:3891' */
  335       localB->IM_OUT_Flow_Rate_Commanded = localB->Flow_Rate_KVO;
  336       localB->IM_OUT_Current_System_Mode = 7U;
  337     } else {
  338       /* Transition: '<S1>:3883' */
  339       localDW->is_Arbiter = INFUSION_MGR_Functional_IN_Manual_Paused_KVO;
  340   
  341       /* Entry 'Manual_Paused_KVO': '<S1>:3892' */
  342       localB->IM_OUT_Flow_Rate_Commanded = localB->Flow_Rate_KVO;
  343       localB->IM_OUT_Current_System_Mode = 8U;
  344     }
  345   }
  346   
  347   /* Function for Chart: '<Root>/Infusion Manager Sub-System' */
  348   static void INFUSION_MGR_Functional_resetAllInfusionDetails
  349     (B_INFUSION_MGR_Functional_c_T *localB, DW_INFUSION_MGR_Functional_f_T
  350      *localDW)
  351   {
  352     /* Graphical Function 'resetAllInfusionDetails': '<S1>:3959' */
  353     /* Transition: '<S1>:3961' */
  354     INFUSION_MGR_Functional_resetForNewInfusion(localB, localDW);
  355     localDW->lock_timer = 0U;
  356     localDW->inPatientBolus = FALSE;
  357     localDW->number_pbolus = 0U;
  358   }
  359   
  360   /* Function for Chart: '<Root>/Infusion Manager Sub-System' */
  361   static void INFUSION_MGR_Functional_THERAPY(B_INFUSION_MGR_Functional_c_T
  362     *localB, DW_INFUSION_MGR_Functional_f_T *localDW)
  363   {
  364     /* During 'THERAPY': '<S1>:3867' */
  365     if ((localB->Infusion_Initiate && localB->Reservoir_Empty) ||
  366         (localB->Configured < 1) || localB->Infusion_Cancel) {
  367       /* Transition: '<S1>:3987' */
  368       /* Exit Internal 'THERAPY': '<S1>:3867' */
  369       switch (localDW->is_THERAPY) {
  370        case INFUSION_MGR_Functional_IN_ACTIVE:
  371         INFUSION_MGR_Functional_exit_internal_ACTIVE(localDW);
  372         localDW->is_THERAPY = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  373         break;
  374   
  375        case INFUSION_MGR_Functional_IN_PAUSED:
  376         INFUSION_MGR_Functional_exit_internal_PAUSED(localB, localDW);
  377         localDW->is_THERAPY = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  378         break;
  379   
  380        default:
  381         localDW->is_THERAPY = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  382         break;
  383       }
  384   
  385       /* Exit 'THERAPY': '<S1>:3867' */
  386       INFUSION_MGR_Functional_TherapyExitOperations(localB);
  387       localDW->is_Infusion_Manager = INFUSION_MGR_Functional_IN_IDLE;
  388   
  389       /* Entry 'IDLE': '<S1>:3866' */
  390       localB->IM_OUT_Current_System_Mode = 1U;
  391       localB->IM_OUT_Flow_Rate_Commanded = 0U;
  392       INFUSION_MGR_Functional_resetAllInfusionDetails(localB, localDW);
  393     } else if (localB->Infusion_Initiate && (localB->Configured == 1) &&
  394                localB->Reservoir_Empty) {
  395       /* Transition: '<S1>:3861' */
  396       INFUSION_MGR_Functional_resetForNewInfusion(localB, localDW);
  397   
  398       /* Transition: '<S1>:3863' */
  399       localB->IM_OUT_New_Infusion = TRUE;
  400   
  401       /* Exit Internal 'THERAPY': '<S1>:3867' */
  402       switch (localDW->is_THERAPY) {
  403        case INFUSION_MGR_Functional_IN_ACTIVE:
  404         INFUSION_MGR_Functional_exit_internal_ACTIVE(localDW);
  405         localDW->is_THERAPY = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  406         break;
  407   
  408        case INFUSION_MGR_Functional_IN_PAUSED:
  409         INFUSION_MGR_Functional_exit_internal_PAUSED(localB, localDW);
  410         localDW->is_THERAPY = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  411         break;
  412   
  413        default:
  414         localDW->is_THERAPY = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  415         break;
  416       }
  417   
  418       /* Exit 'THERAPY': '<S1>:3867' */
  419       INFUSION_MGR_Functional_TherapyExitOperations(localB);
  420       localDW->is_Infusion_Manager = INFUSION_MGR_Functional_IN_THERAPY;
  421   
  422       /* Entry Internal 'THERAPY': '<S1>:3867' */
  423       if (localB->Infusion_Inhibit || (localB->Highest_Level_Alarm >= 3)) {
  424         /* Transition: '<S1>:3994' */
  425         localDW->is_THERAPY = INFUSION_MGR_Functional_IN_PAUSED;
  426         INFUSION_MGR_Functional_enter_internal_PAUSED(localB, localDW);
  427       } else {
  428         /* Transition: '<S1>:3875' */
  429         localDW->is_THERAPY = INFUSION_MGR_Functional_IN_ACTIVE;
  430         INFUSION_MGR_Functional_enter_internal_ACTIVE(localB, localDW);
  431       }
  432     } else {
  433       if (((real_T)localB->IM_OUT_Actual_Infusion_Duration >=
  434            INFUSION_MGR_Functional_Step_Scaling_Factor((uint8_T)
  435             (localB->Infusion_Total_Duration - 1))) || (localB->Volume_Infused >=
  436            localB->VTBI_Total)) {
  437         /* Transition: '<S1>:3865' */
  438         /* Exit Internal 'THERAPY': '<S1>:3867' */
  439         switch (localDW->is_THERAPY) {
  440          case INFUSION_MGR_Functional_IN_ACTIVE:
  441           INFUSION_MGR_Functional_exit_internal_ACTIVE(localDW);
  442           localDW->is_THERAPY = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  443           break;
  444   
  445          case INFUSION_MGR_Functional_IN_PAUSED:
  446           INFUSION_MGR_Functional_exit_internal_PAUSED(localB, localDW);
  447           localDW->is_THERAPY = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  448           break;
  449   
  450          default:
  451           localDW->is_THERAPY = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  452           break;
  453         }
  454   
  455         /* Exit 'THERAPY': '<S1>:3867' */
  456         INFUSION_MGR_Functional_TherapyExitOperations(localB);
  457         localDW->is_Infusion_Manager = INFUSION_MGR_Functional_IN_IDLE;
  458   
  459         /* Entry 'IDLE': '<S1>:3866' */
  460         localB->IM_OUT_Current_System_Mode = 1U;
  461         localB->IM_OUT_Flow_Rate_Commanded = 0U;
  462         INFUSION_MGR_Functional_resetAllInfusionDetails(localB, localDW);
  463       } else {
  464         localB->IM_OUT_New_Infusion = FALSE;
  465         if (localDW->is_THERAPY == INFUSION_MGR_Functional_IN_ACTIVE) {
  466           /* During 'ACTIVE': '<S1>:3905' */
  467           if (localB->Infusion_Inhibit || (localB->Highest_Level_Alarm >= 3)) {
  468             /* Transition: '<S1>:3871' */
  469             INFUSION_MGR_Functional_exit_internal_ACTIVE(localDW);
  470             localDW->is_THERAPY = INFUSION_MGR_Functional_IN_PAUSED;
  471             INFUSION_MGR_Functional_enter_internal_PAUSED(localB, localDW);
  472           } else {
  473             /* During 'BASAL': '<S1>:3907' */
  474             if (localDW->is_BASAL == INFUSION_MGR_Functional_IN_OFF) {
  475               /* During 'OFF': '<S1>:3912' */
  476               if (localB->Infusion_Initiate) {
  477                 /* Transition: '<S1>:3909' */
  478                 localDW->is_BASAL = INFUSION_MGR_Functional_IN_ON;
  479               }
  480             } else {
  481               /* During 'ON': '<S1>:3911' */
  482               if ((real_T)localB->IM_OUT_Actual_Infusion_Duration >=
  483                   INFUSION_MGR_Functional_Step_Scaling_Factor((uint8_T)
  484                    (localB->Infusion_Total_Duration - 1))) {
  485                 /* Transition: '<S1>:3910' */
  486                 localDW->is_BASAL = INFUSION_MGR_Functional_IN_OFF;
  487               }
  488             }
  489   
  490             /* During 'PATIENT': '<S1>:3927' */
  491             switch (localDW->is_PATIENT) {
  492              case INFUSION_MGR_Functional_IN_LOCKOUT:
  493               /* During 'LOCKOUT': '<S1>:3935' */
  494               if ((real_T)localDW->lock_timer >=
  495                   INFUSION_MGR_Functional_Step_Scaling_Factor((uint8_T)
  496                    (localB->Lockout_Period_Patient_Bolus - 1))) {
  497                 /* Transition: '<S1>:3931' */
  498                 localDW->is_PATIENT = INFUSION_MGR_Functional_IN_OFF_b;
  499   
  500                 /* Entry 'OFF': '<S1>:3933' */
  501                 localDW->pbolus_timer = 0U;
  502                 localDW->inPatientBolus = FALSE;
  503               } else {
  504                 localDW->lock_timer++;
  505               }
  506               break;
  507   
  508              case INFUSION_MGR_Functional_IN_OFF_b:
  509               /* During 'OFF': '<S1>:3933' */
  510               if (localB->Patient_Bolus_Request && (localB->Highest_Level_Alarm <
  511                    2) && (localDW->number_pbolus <
  512                           localB->Max_Number_of_Patient_Bolus)) {
  513                 /* Transition: '<S1>:3929' */
  514                 localDW->is_PATIENT = INFUSION_MGR_Functional_IN_ON_b;
  515   
  516                 /* Entry 'ON': '<S1>:3934' */
  517                 localDW->number_pbolus++;
  518                 localDW->inPatientBolus = TRUE;
  519                 localDW->pbolus_timer++;
  520               }
  521               break;
  522   
  523              default:
  524               /* During 'ON': '<S1>:3934' */
  525               if (((real_T)localDW->pbolus_timer >=
  526                    INFUSION_MGR_Functional_Step_Scaling_Factor((uint8_T)
  527                     (localB->Duration_Patient_Bolus - 1))) ||
  528                   (localB->Highest_Level_Alarm == 2)) {
  529                 /* Transition: '<S1>:3932' */
  530                 localDW->lock_timer = 0U;
  531   
  532                 /* Exit 'ON': '<S1>:3934' */
  533                 localDW->pbolus_timer++;
  534                 localDW->is_PATIENT = INFUSION_MGR_Functional_IN_LOCKOUT;
  535   
  536                 /* Entry 'LOCKOUT': '<S1>:3935' */
  537                 localDW->lock_timer++;
  538               } else {
  539                 localDW->pbolus_timer++;
  540               }
  541               break;
  542             }
  543   
  544             /* During 'INTERMITTENT': '<S1>:3936' */
  545             localDW->sbolusInter_timer++;
  546             if (localDW->is_INTERMITTENT == INFUSION_MGR_Functional_IN_OFF) {
  547               /* During 'OFF': '<S1>:3940' */
  548               if (localDW->sbolus_req && (localB->Highest_Level_Alarm < 2)) {
  549                 /* Transition: '<S1>:3938' */
  550                 localDW->is_INTERMITTENT = INFUSION_MGR_Functional_IN_ON;
  551               } else {
  552                 localDW->sbolus_req = (INFUSION_MGR_Functional_sbolus_trigger
  553                   (localB, localDW) != 0.0);
  554               }
  555             } else {
  556               /* During 'ON': '<S1>:3941' */
  557               if (((real_T)localDW->sbolus_timer >=
  558                    INFUSION_MGR_Functional_Step_Scaling_Factor((uint8_T)
  559                     (localB->Duration_Intermittent_Bolus - 1))) ||
  560                   (localB->Highest_Level_Alarm == 2)) {
  561                 /* Transition: '<S1>:3939' */
  562                 /* Exit 'ON': '<S1>:3941' */
  563                 localDW->is_INTERMITTENT = INFUSION_MGR_Functional_IN_OFF;
  564   
  565                 /* Entry 'OFF': '<S1>:3940' */
  566                 localDW->sbolus_timer = 0U;
  567                 localDW->sbolus_req = FALSE;
  568                 localDW->sbolus_req = (INFUSION_MGR_Functional_sbolus_trigger
  569                   (localB, localDW) != 0.0);
  570               } else {
  571                 localDW->sbolus_timer++;
  572                 localDW->sbolus_req = FALSE;
  573               }
  574             }
  575   
  576             /* During 'Arbiter': '<S1>:3913' */
  577             switch (localDW->is_Arbiter_d) {
  578              case INFUSION_MGR_Functional_IN_Basal:
  579               /* During 'Basal': '<S1>:3926' */
  580               /* Transition: '<S1>:3923' */
  581               /* Transition: '<S1>:3920' */
  582               localB->IM_OUT_Actual_Infusion_Duration++;
  583   
  584               /* Transition: '<S1>:4002' */
  585               if (localDW->is_PATIENT == INFUSION_MGR_Functional_IN_ON_b) {
  586                 /* Transition: '<S1>:3917' */
  587                 localDW->is_Arbiter_d = INFUSION_MGR_Functional_IN_Patient_Bolus;
  588   
  589                 /* Entry 'Patient_Bolus': '<S1>:3924' */
  590                 localB->IM_OUT_Flow_Rate_Commanded =
  591                   localB->Flow_Rate_Patient_Bolus;
  592                 localB->IM_OUT_Current_System_Mode = 4U;
  593               } else if (localDW->is_INTERMITTENT == INFUSION_MGR_Functional_IN_ON)
  594               {
  595                 /* Transition: '<S1>:3918' */
  596                 localDW->is_Arbiter_d =
  597                   INFUSION_MGR_Functional_IN_Intermittent_Bolus;
  598   
  599                 /* Entry 'Intermittent_Bolus': '<S1>:3925' */
  600                 localB->IM_OUT_Flow_Rate_Commanded =
  601                   localB->Flow_Rate_Intermittent_Bolus;
  602                 localB->IM_OUT_Current_System_Mode = 3U;
  603               } else {
  604                 /* Transition: '<S1>:3919' */
  605                 localDW->is_Arbiter_d = INFUSION_MGR_Functional_IN_Basal;
  606   
  607                 /* Entry 'Basal': '<S1>:3926' */
  608                 localB->IM_OUT_Flow_Rate_Commanded = localB->Flow_Rate_Basal;
  609                 localB->IM_OUT_Current_System_Mode = 2U;
  610               }
  611               break;
  612   
  613              case INFUSION_MGR_Functional_IN_Intermittent_Bolus:
  614               /* During 'Intermittent_Bolus': '<S1>:3925' */
  615               /* Transition: '<S1>:3922' */
  616               /* Transition: '<S1>:3920' */
  617               localB->IM_OUT_Actual_Infusion_Duration++;
  618   
  619               /* Transition: '<S1>:4002' */
  620               if (localDW->is_PATIENT == INFUSION_MGR_Functional_IN_ON_b) {
  621                 /* Transition: '<S1>:3917' */
  622                 localDW->is_Arbiter_d = INFUSION_MGR_Functional_IN_Patient_Bolus;
  623   
  624                 /* Entry 'Patient_Bolus': '<S1>:3924' */
  625                 localB->IM_OUT_Flow_Rate_Commanded =
  626                   localB->Flow_Rate_Patient_Bolus;
  627                 localB->IM_OUT_Current_System_Mode = 4U;
  628               } else if (localDW->is_INTERMITTENT == INFUSION_MGR_Functional_IN_ON)
  629               {
  630                 /* Transition: '<S1>:3918' */
  631                 localDW->is_Arbiter_d =
  632                   INFUSION_MGR_Functional_IN_Intermittent_Bolus;
  633   
  634                 /* Entry 'Intermittent_Bolus': '<S1>:3925' */
  635                 localB->IM_OUT_Flow_Rate_Commanded =
  636                   localB->Flow_Rate_Intermittent_Bolus;
  637                 localB->IM_OUT_Current_System_Mode = 3U;
  638               } else {
  639                 /* Transition: '<S1>:3919' */
  640                 localDW->is_Arbiter_d = INFUSION_MGR_Functional_IN_Basal;
  641   
  642                 /* Entry 'Basal': '<S1>:3926' */
  643                 localB->IM_OUT_Flow_Rate_Commanded = localB->Flow_Rate_Basal;
  644                 localB->IM_OUT_Current_System_Mode = 2U;
  645               }
  646               break;
  647   
  648              default:
  649               /* During 'Patient_Bolus': '<S1>:3924' */
  650               /* Transition: '<S1>:3921' */
  651               /* Transition: '<S1>:3920' */
  652               localB->IM_OUT_Actual_Infusion_Duration++;
  653   
  654               /* Transition: '<S1>:4002' */
  655               if (localDW->is_PATIENT == INFUSION_MGR_Functional_IN_ON_b) {
  656                 /* Transition: '<S1>:3917' */
  657                 localDW->is_Arbiter_d = INFUSION_MGR_Functional_IN_Patient_Bolus;
  658   
  659                 /* Entry 'Patient_Bolus': '<S1>:3924' */
  660                 localB->IM_OUT_Flow_Rate_Commanded =
  661                   localB->Flow_Rate_Patient_Bolus;
  662                 localB->IM_OUT_Current_System_Mode = 4U;
  663               } else if (localDW->is_INTERMITTENT == INFUSION_MGR_Functional_IN_ON)
  664               {
  665                 /* Transition: '<S1>:3918' */
  666                 localDW->is_Arbiter_d =
  667                   INFUSION_MGR_Functional_IN_Intermittent_Bolus;
  668   
  669                 /* Entry 'Intermittent_Bolus': '<S1>:3925' */
  670                 localB->IM_OUT_Flow_Rate_Commanded =
  671                   localB->Flow_Rate_Intermittent_Bolus;
  672                 localB->IM_OUT_Current_System_Mode = 3U;
  673               } else {
  674                 /* Transition: '<S1>:3919' */
  675                 localDW->is_Arbiter_d = INFUSION_MGR_Functional_IN_Basal;
  676   
  677                 /* Entry 'Basal': '<S1>:3926' */
  678                 localB->IM_OUT_Flow_Rate_Commanded = localB->Flow_Rate_Basal;
  679                 localB->IM_OUT_Current_System_Mode = 2U;
  680               }
  681               break;
  682             }
  683           }
  684         } else {
  685           /* During 'PAUSED': '<S1>:3876' */
  686           if (localB->Infusion_Initiate && (localB->Highest_Level_Alarm < 3) &&
  687               (!localB->Infusion_Inhibit)) {
  688             /* Transition: '<S1>:3870' */
  689             INFUSION_MGR_Functional_exit_internal_PAUSED(localB, localDW);
  690             localDW->is_THERAPY = INFUSION_MGR_Functional_IN_ACTIVE;
  691             INFUSION_MGR_Functional_enter_internal_ACTIVE(localB, localDW);
  692           } else {
  693             /* During 'Alarm_Paused': '<S1>:3893' */
  694             if (localDW->is_Alarm_Paused == INFUSION_MGR_Functional_IN_OFF) {
  695               /* During 'OFF': '<S1>:3897' */
  696               if (localB->Highest_Level_Alarm >= 3) {
  697                 /* Transition: '<S1>:3895' */
  698                 localDW->is_Alarm_Paused = INFUSION_MGR_Functional_IN_ON;
  699               }
  700             } else {
  701               /* During 'ON': '<S1>:3898' */
  702               if (localB->Infusion_Initiate && (localB->Highest_Level_Alarm < 3))
  703               {
  704                 /* Transition: '<S1>:3896' */
  705                 localDW->is_Alarm_Paused = INFUSION_MGR_Functional_IN_OFF;
  706               }
  707             }
  708   
  709             /* During 'Manual_Paused': '<S1>:3899' */
  710             if (localDW->is_Manual_Paused == INFUSION_MGR_Functional_IN_OFF) {
  711               /* During 'OFF': '<S1>:3903' */
  712               if (localB->Infusion_Inhibit) {
  713                 /* Transition: '<S1>:3901' */
  714                 localDW->is_Manual_Paused = INFUSION_MGR_Functional_IN_ON;
  715               }
  716             } else {
  717               /* During 'ON': '<S1>:3904' */
  718               if (localB->Infusion_Initiate && (!localB->Infusion_Inhibit)) {
  719                 /* Transition: '<S1>:3902' */
  720                 localDW->is_Manual_Paused = INFUSION_MGR_Functional_IN_OFF;
  721               }
  722             }
  723   
  724             /* During 'Arbiter': '<S1>:3877' */
  725             switch (localDW->is_Arbiter) {
  726              case INFUSION_MGR_Functional_IN_Manual_Paused_KVO:
  727               /* During 'Manual_Paused_KVO': '<S1>:3892' */
  728               /* Transition: '<S1>:3888' */
  729               /* Transition: '<S1>:3889' */
  730               /* Transition: '<S1>:3885' */
  731               if ((localDW->is_Alarm_Paused == INFUSION_MGR_Functional_IN_ON) &&
  732                   (localB->Highest_Level_Alarm == 4)) {
  733                 /* Transition: '<S1>:3882' */
  734                 /* Exit 'Manual_Paused_KVO': '<S1>:3892' */
  735                 localDW->is_Arbiter = INFUSION_MGR_Functional_IN_Paused_NoKVO;
  736   
  737                 /* Entry 'Paused_NoKVO': '<S1>:3890' */
  738                 localB->IM_OUT_Flow_Rate_Commanded = 0U;
  739                 localB->IM_OUT_Current_System_Mode = 6U;
  740               } else if ((localDW->is_Alarm_Paused ==
  741                           INFUSION_MGR_Functional_IN_ON) &&
  742                          (localB->Highest_Level_Alarm == 3)) {
  743                 /* Transition: '<S1>:3884' */
  744                 /* Exit 'Manual_Paused_KVO': '<S1>:3892' */
  745                 localDW->is_Arbiter = INFUSION_MGR_Functional_IN_Paused_KVO;
  746   
  747                 /* Entry 'Paused_KVO': '<S1>:3891' */
  748                 localB->IM_OUT_Flow_Rate_Commanded = localB->Flow_Rate_KVO;
  749                 localB->IM_OUT_Current_System_Mode = 7U;
  750               } else {
  751                 /* Transition: '<S1>:3883' */
  752                 /* Exit 'Manual_Paused_KVO': '<S1>:3892' */
  753                 localDW->is_Arbiter = INFUSION_MGR_Functional_IN_Manual_Paused_KVO;
  754   
  755                 /* Entry 'Manual_Paused_KVO': '<S1>:3892' */
  756                 localB->IM_OUT_Flow_Rate_Commanded = localB->Flow_Rate_KVO;
  757                 localB->IM_OUT_Current_System_Mode = 8U;
  758               }
  759               break;
  760   
  761              case INFUSION_MGR_Functional_IN_Paused_KVO:
  762               /* During 'Paused_KVO': '<S1>:3891' */
  763               /* Transition: '<S1>:3887' */
  764               /* Transition: '<S1>:3889' */
  765               /* Transition: '<S1>:3885' */
  766               if ((localDW->is_Alarm_Paused == INFUSION_MGR_Functional_IN_ON) &&
  767                   (localB->Highest_Level_Alarm == 4)) {
  768                 /* Transition: '<S1>:3882' */
  769                 /* Exit 'Paused_KVO': '<S1>:3891' */
  770                 localDW->is_Arbiter = INFUSION_MGR_Functional_IN_Paused_NoKVO;
  771   
  772                 /* Entry 'Paused_NoKVO': '<S1>:3890' */
  773                 localB->IM_OUT_Flow_Rate_Commanded = 0U;
  774                 localB->IM_OUT_Current_System_Mode = 6U;
  775               } else if ((localDW->is_Alarm_Paused ==
  776                           INFUSION_MGR_Functional_IN_ON) &&
  777                          (localB->Highest_Level_Alarm == 3)) {
  778                 /* Transition: '<S1>:3884' */
  779                 /* Exit 'Paused_KVO': '<S1>:3891' */
  780                 localDW->is_Arbiter = INFUSION_MGR_Functional_IN_Paused_KVO;
  781   
  782                 /* Entry 'Paused_KVO': '<S1>:3891' */
  783                 localB->IM_OUT_Flow_Rate_Commanded = localB->Flow_Rate_KVO;
  784                 localB->IM_OUT_Current_System_Mode = 7U;
  785               } else {
  786                 /* Transition: '<S1>:3883' */
  787                 /* Exit 'Paused_KVO': '<S1>:3891' */
  788                 localDW->is_Arbiter = INFUSION_MGR_Functional_IN_Manual_Paused_KVO;
  789   
  790                 /* Entry 'Manual_Paused_KVO': '<S1>:3892' */
  791                 localB->IM_OUT_Flow_Rate_Commanded = localB->Flow_Rate_KVO;
  792                 localB->IM_OUT_Current_System_Mode = 8U;
  793               }
  794               break;
  795   
  796              default:
  797               /* During 'Paused_NoKVO': '<S1>:3890' */
  798               /* Transition: '<S1>:3886' */
  799               /* Transition: '<S1>:3889' */
  800               /* Transition: '<S1>:3885' */
  801               if ((localDW->is_Alarm_Paused == INFUSION_MGR_Functional_IN_ON) &&
  802                   (localB->Highest_Level_Alarm == 4)) {
  803                 /* Transition: '<S1>:3882' */
  804                 /* Exit 'Paused_NoKVO': '<S1>:3890' */
  805                 localDW->is_Arbiter = INFUSION_MGR_Functional_IN_Paused_NoKVO;
  806   
  807                 /* Entry 'Paused_NoKVO': '<S1>:3890' */
  808                 localB->IM_OUT_Flow_Rate_Commanded = 0U;
  809                 localB->IM_OUT_Current_System_Mode = 6U;
  810               } else if ((localDW->is_Alarm_Paused ==
  811                           INFUSION_MGR_Functional_IN_ON) &&
  812                          (localB->Highest_Level_Alarm == 3)) {
  813                 /* Transition: '<S1>:3884' */
  814                 /* Exit 'Paused_NoKVO': '<S1>:3890' */
  815                 localDW->is_Arbiter = INFUSION_MGR_Functional_IN_Paused_KVO;
  816   
  817                 /* Entry 'Paused_KVO': '<S1>:3891' */
  818                 localB->IM_OUT_Flow_Rate_Commanded = localB->Flow_Rate_KVO;
  819                 localB->IM_OUT_Current_System_Mode = 7U;
  820               } else {
  821                 /* Transition: '<S1>:3883' */
  822                 /* Exit 'Paused_NoKVO': '<S1>:3890' */
  823                 localDW->is_Arbiter = INFUSION_MGR_Functional_IN_Manual_Paused_KVO;
  824   
  825                 /* Entry 'Manual_Paused_KVO': '<S1>:3892' */
  826                 localB->IM_OUT_Flow_Rate_Commanded = localB->Flow_Rate_KVO;
  827                 localB->IM_OUT_Current_System_Mode = 8U;
  828               }
  829               break;
  830             }
  831           }
  832         }
  833       }
  834     }
  835   }
  836   
  837   /* Initial conditions for referenced model: 'INFUSION_MGR_Functional' */
  838   void INFUSION_MGR_Functional_Init(B_INFUSION_MGR_Functional_c_T *localB,
  839     DW_INFUSION_MGR_Functional_f_T *localDW)
  840   {
  841     /* InitializeConditions for Chart: '<Root>/Infusion Manager Sub-System' */
  842     localDW->is_Infusion_Manager = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  843     localDW->is_THERAPY = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  844     localDW->is_active_Arbiter_c = 0U;
  845     localDW->is_Arbiter_d = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  846     localDW->is_active_BASAL = 0U;
  847     localDW->is_BASAL = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  848     localDW->is_active_INTERMITTENT = 0U;
  849     localDW->is_INTERMITTENT = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  850     localDW->is_active_PATIENT = 0U;
  851     localDW->is_PATIENT = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  852     localDW->is_active_Alarm_Paused = 0U;
  853     localDW->is_Alarm_Paused = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  854     localDW->is_active_Arbiter = 0U;
  855     localDW->is_Arbiter = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  856     localDW->is_active_Manual_Paused = 0U;
  857     localDW->is_Manual_Paused = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  858     localDW->is_active_c2_INFUSION_MGR_Functional = 0U;
  859     localDW->is_c2_INFUSION_MGR_Functional =
  860       INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  861     localDW->sbolus_req = FALSE;
  862     localDW->sbolus_timer = 0U;
  863     localDW->pbolus_timer = 0U;
  864     localDW->lock_timer = 0U;
  865     localDW->number_pbolus = 0U;
  866     localDW->inPatientBolus = FALSE;
  867     localDW->sbolusInter_timer = 0U;
  868     localB->IM_OUT_Flow_Rate_Commanded = 0U;
  869     localB->IM_OUT_Current_System_Mode = 0U;
  870     localB->IM_OUT_New_Infusion = FALSE;
  871     localB->IM_OUT_Log_Message_ID = 0U;
  872     localB->IM_OUT_Actual_Infusion_Duration = 0U;
  873   }
  874   
  875   /* Output and update for referenced model: 'INFUSION_MGR_Functional' */
  876   void INFUSION_MGR_Functional(const Top_Level_Mode_Outputs *rtu_TLM_MODE_IN,
  877     const Operator_Commands *rtu_OP_CMD_IN, const Patient_Inputs *rtu_PATIENT_IN,
  878     const Config_Outputs *rtu_CONFIG_IN, const Alarm_Outputs *rtu_ALARM_IN, const
  879     System_Status_Outputs *rtu_SYS_STAT_IN, Infusion_Manager_Outputs *rty_IM_OUT,
  880     B_INFUSION_MGR_Functional_c_T *localB, DW_INFUSION_MGR_Functional_f_T *localDW)
  881   {
  882     /* BusSelector: '<Root>/BusConversion_InsertedFor_ALARM_IN_at_outport_0' */
  883     localB->Highest_Level_Alarm = rtu_ALARM_IN->Highest_Level_Alarm;
  884   
  885     /* BusSelector: '<Root>/BusConversion_InsertedFor_CONFIG_IN_at_outport_0' */
  886     localB->Infusion_Total_Duration = rtu_CONFIG_IN->Infusion_Total_Duration;
  887     localB->VTBI_Total = rtu_CONFIG_IN->VTBI_Total;
  888     localB->Flow_Rate_Basal = rtu_CONFIG_IN->Flow_Rate_Basal;
  889     localB->Flow_Rate_Intermittent_Bolus =
  890       rtu_CONFIG_IN->Flow_Rate_Intermittent_Bolus;
  891     localB->Duration_Intermittent_Bolus =
  892       rtu_CONFIG_IN->Duration_Intermittent_Bolus;
  893     localB->Interval_Intermittent_Bolus =
  894       rtu_CONFIG_IN->Interval_Intermittent_Bolus;
  895     localB->Flow_Rate_Patient_Bolus = rtu_CONFIG_IN->Flow_Rate_Patient_Bolus;
  896     localB->Duration_Patient_Bolus = rtu_CONFIG_IN->Duration_Patient_Bolus;
  897     localB->Lockout_Period_Patient_Bolus =
  898       rtu_CONFIG_IN->Lockout_Period_Patient_Bolus;
  899     localB->Max_Number_of_Patient_Bolus =
  900       rtu_CONFIG_IN->Max_Number_of_Patient_Bolus;
  901     localB->Flow_Rate_KVO = rtu_CONFIG_IN->Flow_Rate_KVO;
  902     localB->Configured = rtu_CONFIG_IN->Configured;
  903   
  904     /* BusSelector: '<Root>/BusConversion_InsertedFor_OP_CMD_IN_at_outport_0' */
  905     localB->Infusion_Initiate = rtu_OP_CMD_IN->Infusion_Initiate;
  906     localB->Infusion_Inhibit = rtu_OP_CMD_IN->Infusion_Inhibit;
  907     localB->Infusion_Cancel = rtu_OP_CMD_IN->Infusion_Cancel;
  908   
  909     /* BusSelector: '<Root>/BusConversion_InsertedFor_PATIENT_IN_at_outport_0' */
  910     localB->Patient_Bolus_Request = rtu_PATIENT_IN->Patient_Bolus_Request;
  911   
  912     /* BusSelector: '<Root>/BusConversion_InsertedFor_SYS_STAT_IN_at_outport_0' */
  913     localB->Reservoir_Empty = rtu_SYS_STAT_IN->Reservoir_Empty;
  914     localB->Volume_Infused = rtu_SYS_STAT_IN->Volume_Infused;
  915   
  916     /* Chart: '<Root>/Infusion Manager Sub-System' incorporates:
  917      *  BusSelector: '<Root>/BusConversion_InsertedFor_TLM_MODE_IN_at_outport_0'
  918      */
  919     /* Gateway: Infusion Manager Sub-System */
  920     /* During: Infusion Manager Sub-System */
  921     if (localDW->is_active_c2_INFUSION_MGR_Functional == 0U) {
  922       /* Entry: Infusion Manager Sub-System */
  923       localDW->is_active_c2_INFUSION_MGR_Functional = 1U;
  924   
  925       /* Entry Internal: Infusion Manager Sub-System */
  926       if (rtu_TLM_MODE_IN->System_On) {
  927         /* Transition: '<S1>:3986' */
  928         localDW->is_c2_INFUSION_MGR_Functional =
  929           INFUSION_MGR_Functional_IN_Infusion_Manager;
  930   
  931         /* Entry Internal 'Infusion_Manager': '<S1>:3858' */
  932         /* Transition: '<S1>:3860' */
  933         localDW->is_Infusion_Manager = INFUSION_MGR_Functional_IN_IDLE;
  934   
  935         /* Entry 'IDLE': '<S1>:3866' */
  936         localB->IM_OUT_Current_System_Mode = 1U;
  937         localB->IM_OUT_Flow_Rate_Commanded = 0U;
  938         INFUSION_MGR_Functional_resetAllInfusionDetails(localB, localDW);
  939       } else {
  940         /* Transition: '<S1>:3744' */
  941         localDW->is_c2_INFUSION_MGR_Functional = INFUSION_MGR_Functional_IN_NOT_ON;
  942   
  943         /* Entry 'NOT_ON': '<S1>:3740' */
  944         localB->IM_OUT_Current_System_Mode = 0U;
  945         localB->IM_OUT_Flow_Rate_Commanded = 0U;
  946       }
  947     } else if (localDW->is_c2_INFUSION_MGR_Functional ==
  948                INFUSION_MGR_Functional_IN_Infusion_Manager) {
  949       /* During 'Infusion_Manager': '<S1>:3858' */
  950       if (!rtu_TLM_MODE_IN->System_On) {
  951         /* Transition: '<S1>:3732' */
  952         /* Exit Internal 'Infusion_Manager': '<S1>:3858' */
  953         switch (localDW->is_Infusion_Manager) {
  954          case INFUSION_MGR_Functional_IN_IDLE:
  955           /* Exit 'IDLE': '<S1>:3866' */
  956           localB->IM_OUT_Current_System_Mode = 1U;
  957           localB->IM_OUT_Flow_Rate_Commanded = 0U;
  958           INFUSION_MGR_Functional_resetAllInfusionDetails(localB, localDW);
  959           localDW->is_Infusion_Manager =
  960             INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  961           break;
  962   
  963          case INFUSION_MGR_Functional_IN_THERAPY:
  964           /* Exit Internal 'THERAPY': '<S1>:3867' */
  965           switch (localDW->is_THERAPY) {
  966            case INFUSION_MGR_Functional_IN_ACTIVE:
  967             INFUSION_MGR_Functional_exit_internal_ACTIVE(localDW);
  968             localDW->is_THERAPY = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  969             break;
  970   
  971            case INFUSION_MGR_Functional_IN_PAUSED:
  972             INFUSION_MGR_Functional_exit_internal_PAUSED(localB, localDW);
  973             localDW->is_THERAPY = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  974             break;
  975   
  976            default:
  977             localDW->is_THERAPY = INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  978             break;
  979           }
  980   
  981           /* Exit 'THERAPY': '<S1>:3867' */
  982           INFUSION_MGR_Functional_TherapyExitOperations(localB);
  983           localDW->is_Infusion_Manager =
  984             INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  985           break;
  986   
  987          default:
  988           localDW->is_Infusion_Manager =
  989             INFUSION_MGR_Functional_IN_NO_ACTIVE_CHILD;
  990           break;
  991         }
  992   
  993         localDW->is_c2_INFUSION_MGR_Functional = INFUSION_MGR_Functional_IN_NOT_ON;
  994   
  995         /* Entry 'NOT_ON': '<S1>:3740' */
  996         localB->IM_OUT_Current_System_Mode = 0U;
  997         localB->IM_OUT_Flow_Rate_Commanded = 0U;
  998       } else if (localDW->is_Infusion_Manager == INFUSION_MGR_Functional_IN_IDLE)
  999       {
 1000         /* During 'IDLE': '<S1>:3866' */
 1001         if (localB->Infusion_Cancel || localB->Infusion_Inhibit) {
 1002           /* Transition: '<S1>:3993' */
 1003           /* Exit 'IDLE': '<S1>:3866' */
 1004           localB->IM_OUT_Current_System_Mode = 1U;
 1005           localB->IM_OUT_Flow_Rate_Commanded = 0U;
 1006           INFUSION_MGR_Functional_resetAllInfusionDetails(localB, localDW);
 1007           localDW->is_Infusion_Manager = INFUSION_MGR_Functional_IN_IDLE;
 1008   
 1009           /* Entry 'IDLE': '<S1>:3866' */
 1010           localB->IM_OUT_Current_System_Mode = 1U;
 1011           localB->IM_OUT_Flow_Rate_Commanded = 0U;
 1012           INFUSION_MGR_Functional_resetAllInfusionDetails(localB, localDW);
 1013         } else if (localB->Infusion_Initiate && (localB->Configured > 0) &&
 1014                    (!localB->Reservoir_Empty)) {
 1015           /* Transition: '<S1>:3864' */
 1016           INFUSION_MGR_Functional_resetAllInfusionDetails(localB, localDW);
 1017   
 1018           /* Transition: '<S1>:3863' */
 1019           localB->IM_OUT_New_Infusion = TRUE;
 1020   
 1021           /* Exit 'IDLE': '<S1>:3866' */
 1022           localB->IM_OUT_Current_System_Mode = 1U;
 1023           localB->IM_OUT_Flow_Rate_Commanded = 0U;
 1024           INFUSION_MGR_Functional_resetAllInfusionDetails(localB, localDW);
 1025           localDW->is_Infusion_Manager = INFUSION_MGR_Functional_IN_THERAPY;
 1026   
 1027           /* Entry Internal 'THERAPY': '<S1>:3867' */
 1028           if (localB->Infusion_Inhibit || (localB->Highest_Level_Alarm >= 3)) {
 1029             /* Transition: '<S1>:3994' */
 1030             localDW->is_THERAPY = INFUSION_MGR_Functional_IN_PAUSED;
 1031             INFUSION_MGR_Functional_enter_internal_PAUSED(localB, localDW);
 1032           } else {
 1033             /* Transition: '<S1>:3875' */
 1034             localDW->is_THERAPY = INFUSION_MGR_Functional_IN_ACTIVE;
 1035             INFUSION_MGR_Functional_enter_internal_ACTIVE(localB, localDW);
 1036           }
 1037         } else {
 1038           localB->IM_OUT_Current_System_Mode = 1U;
 1039           localB->IM_OUT_Flow_Rate_Commanded = 0U;
 1040         }
 1041       } else {
 1042         INFUSION_MGR_Functional_THERAPY(localB, localDW);
 1043       }
 1044     } else {
 1045       /* During 'NOT_ON': '<S1>:3740' */
 1046       if (rtu_TLM_MODE_IN->System_On) {
 1047         /* Transition: '<S1>:3741' */
 1048         /* Exit 'NOT_ON': '<S1>:3740' */
 1049         localDW->is_c2_INFUSION_MGR_Functional =
 1050           INFUSION_MGR_Functional_IN_Infusion_Manager;
 1051   
 1052         /* Entry Internal 'Infusion_Manager': '<S1>:3858' */
 1053         /* Transition: '<S1>:3860' */
 1054         localDW->is_Infusion_Manager = INFUSION_MGR_Functional_IN_IDLE;
 1055   
 1056         /* Entry 'IDLE': '<S1>:3866' */
 1057         localB->IM_OUT_Current_System_Mode = 1U;
 1058         localB->IM_OUT_Flow_Rate_Commanded = 0U;
 1059         INFUSION_MGR_Functional_resetAllInfusionDetails(localB, localDW);
 1060       } else {
 1061         localB->IM_OUT_Current_System_Mode = 0U;
 1062         localB->IM_OUT_Flow_Rate_Commanded = 0U;
 1063       }
 1064     }
 1065   
 1066     /* End of Chart: '<Root>/Infusion Manager Sub-System' */
 1067   
 1068     /* BusCreator: '<Root>/BusConversion_InsertedFor_IM_OUT_at_inport_0' */
 1069     rty_IM_OUT->Commanded_Flow_Rate = localB->IM_OUT_Flow_Rate_Commanded;
 1070     rty_IM_OUT->Current_System_Mode = localB->IM_OUT_Current_System_Mode;
 1071     rty_IM_OUT->New_Infusion = localB->IM_OUT_New_Infusion;
 1072     rty_IM_OUT->Log_Message_ID = localB->IM_OUT_Log_Message_ID;
 1073     rty_IM_OUT->Actual_Infusion_Duration = localB->IM_OUT_Actual_Infusion_Duration;
 1074   }
 1075   
 1076   /* Model initialize function */
 1077   void INFUSION_MGR_Functional_initialize(const char_T **rt_errorStatus,
 1078     RT_MODEL_INFUSION_MGR_Functional_T *const INFUSION_MGR_Functional_M,
 1079     B_INFUSION_MGR_Functional_c_T *localB, DW_INFUSION_MGR_Functional_f_T *localDW)
 1080   {
 1081     /* Registration code */
 1082   
 1083     /* initialize error status */
 1084     rtmSetErrorStatusPointer(INFUSION_MGR_Functional_M, rt_errorStatus);
 1085   
 1086     /* block I/O */
 1087     (void) memset(((void *) localB), 0,
 1088                   sizeof(B_INFUSION_MGR_Functional_c_T));
 1089   
 1090     /* states (dwork) */
 1091     (void) memset((void *)localDW, 0,
 1092                   sizeof(DW_INFUSION_MGR_Functional_f_T));
 1093   }
 1094