Library for the master controller

Dependents:   Test_Controller_Master AEB

Controller_Master.c

Committer:
AndreaAndreoli
Date:
2016-07-10
Revision:
3:66d07e7a134a
Parent:
2:d114feef8f3b

File content as of revision 3:66d07e7a134a:

/*
 * 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.
 *
 * File: Controller_Master.c
 *
 * Code generated for Simulink model 'Controller_Master'.
 *
 * Model version                  : 1.7
 * Simulink Coder version         : 8.10 (R2016a) 10-Feb-2016
 * C/C++ source code generated on : Sun Jul 10 14:56:51 2016
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: ARM Compatible->ARM Cortex
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "Controller_Master.h"

/* Named constants for Chart: '<S1>/AEB_QA' */
#define Controller_M_IN_NO_ACTIVE_CHILD ((uint8_T)0U)
#define Controller_Master_IN_ACCELERATE ((uint8_T)1U)
#define Controller_Master_IN_AEB_ACTIVE ((uint8_T)1U)
#define Controller_Master_IN_BRAKE     ((uint8_T)1U)
#define Controller_Master_IN_BRAKE_d   ((uint8_T)2U)
#define Controller_Master_IN_ERR       ((uint8_T)1U)
#define Controller_Master_IN_IDLE      ((uint8_T)2U)
#define Controller_Master_IN_IDLE_k    ((uint8_T)3U)
#define Controller_Master_IN_OK        ((uint8_T)2U)
#define Controller_Master_IN_QA_ACTIVE ((uint8_T)2U)
#define Controller_Master_IN_READY     ((uint8_T)3U)
#define Controller_Master_IN_WARNING   ((uint8_T)3U)

/* Named constants for Chart: '<S1>/select_command' */
#define Controller_Master_IN_BLINK     ((uint8_T)1U)
#define Controller_Master_IN_BLINK_OFF ((uint8_T)1U)
#define Controller_Master_IN_BLINK_ON  ((uint8_T)2U)
#define Controller_Master_IN_OFF1      ((uint8_T)2U)
#define Controller_Master_IN_ON        ((uint8_T)3U)

/* Forward declaration for local functions */
static void Controller_Master_AEB_QA(real_T Controller_Master_U_V, real_T
  Controller_Master_U_D_M, boolean_T Controller_Master_U_QA_EN, uint8_T
  *Controller_Master_Y_BRAKE, uint8_T *Controller_Master_Y_ACC, uint8_T
  *Controller_Master_Y_LED_RED, uint8_T *Controller_Master_Y_LED_GREEN, uint8_T *
  Controller_Master_Y_MASTER, B_Controller_Master_T *Controller_Master_B,
  DW_Controller_Master_T *Controller_Master_DW);

/*===========*
 * Constants *
 *===========*/
#define RT_PI                          3.14159265358979323846
#define RT_PIF                         3.1415927F
#define RT_LN_10                       2.30258509299404568402
#define RT_LN_10F                      2.3025851F
#define RT_LOG10E                      0.43429448190325182765
#define RT_LOG10EF                     0.43429449F
#define RT_E                           2.7182818284590452354
#define RT_EF                          2.7182817F

/*
 * UNUSED_PARAMETER(x)
 *   Used to specify that a function parameter (argument) is required but not
 *   accessed by the function body.
 */
#ifndef UNUSED_PARAMETER
# if defined(__LCC__)
#   define UNUSED_PARAMETER(x)                                   /* do nothing */
# else

/*
 * This is the semi-ANSI standard way of indicating that an
 * unused function parameter is required.
 */
#   define UNUSED_PARAMETER(x)         (void) (x)
# endif
#endif

/* Function for Chart: '<S1>/AEB_QA' */
static void Controller_Master_AEB_QA(real_T Controller_Master_U_V, real_T
  Controller_Master_U_D_M, boolean_T Controller_Master_U_QA_EN, uint8_T
  *Controller_Master_Y_BRAKE, uint8_T *Controller_Master_Y_ACC, uint8_T
  *Controller_Master_Y_LED_RED, uint8_T *Controller_Master_Y_LED_GREEN, uint8_T *
  Controller_Master_Y_MASTER, B_Controller_Master_T *Controller_Master_B,
  DW_Controller_Master_T *Controller_Master_DW)
{
  real_T K;

  /* During 'AEB_QA': '<S2>:35' */
  /* During 'ERRORS_CHECK_THREAD': '<S2>:33' */
  if (Controller_Master_DW->is_ERRORS_CHECK_THREAD != Controller_Master_IN_ERR)
  {
    /* Inport: '<Root>/V' incorporates:
     *  Inport: '<Root>/D_M'
     */
    /* During 'OK': '<S2>:37' */
    /* '<S2>:46:1' sf_internal_predicateOutput = ... */
    /* '<S2>:46:1' V > 180 || D > 200 || D < 0; */
    if ((Controller_Master_U_V > 180.0) || (Controller_Master_U_D_M > 200.0) ||
        (Controller_Master_U_D_M < 0.0)) {
      /* Transition: '<S2>:46' */
      Controller_Master_DW->is_ERRORS_CHECK_THREAD = Controller_Master_IN_ERR;

      /* Entry 'ERR': '<S2>:42' */
      /* '<S2>:42:1' Led_Red = uint8(1); */
      *Controller_Master_Y_LED_RED = 1U;

      /* '<S2>:42:1' Master = uint8(0) ; */
      *Controller_Master_Y_MASTER = 0U;

      /* '<S2>:42:3' En = false; */
      Controller_Master_DW->En = false;

      /* '<S2>:42:3' Brake = uint8(0); */
      *Controller_Master_Y_BRAKE = 0U;

      /* '<S2>:42:4' Led_Blue = 0; */
      Controller_Master_B->Led_Blue = 0.0;

      /* '<S2>:42:5' Acc = uint8(0); */
      *Controller_Master_Y_ACC = 0U;

      /* '<S2>:42:6' Led_Green = uint8(0); */
      *Controller_Master_Y_LED_GREEN = 0U;
    } else {
      /* '<S2>:43:1' sf_internal_predicateOutput = ... */
      /* '<S2>:43:1' D == 0; */
      if (Controller_Master_U_D_M == 0.0) {
        /* Transition: '<S2>:43' */
        Controller_Master_DW->is_ERRORS_CHECK_THREAD = Controller_Master_IN_ERR;

        /* Entry 'ERR': '<S2>:42' */
        /* '<S2>:42:1' Led_Red = uint8(1); */
        *Controller_Master_Y_LED_RED = 1U;

        /* '<S2>:42:1' Master = uint8(0) ; */
        *Controller_Master_Y_MASTER = 0U;

        /* '<S2>:42:3' En = false; */
        Controller_Master_DW->En = false;

        /* '<S2>:42:3' Brake = uint8(0); */
        *Controller_Master_Y_BRAKE = 0U;

        /* '<S2>:42:4' Led_Blue = 0; */
        Controller_Master_B->Led_Blue = 0.0;

        /* '<S2>:42:5' Acc = uint8(0); */
        *Controller_Master_Y_ACC = 0U;

        /* '<S2>:42:6' Led_Green = uint8(0); */
        *Controller_Master_Y_LED_GREEN = 0U;
      }
    }
  } else {
    /* During 'ERR': '<S2>:42' */
  }

  /* During 'APPLICATION_THREAD': '<S2>:80' */
  switch (Controller_Master_DW->is_APPLICATION_THREAD) {
   case Controller_Master_IN_AEB_ACTIVE:
    /* During 'AEB_ACTIVE': '<S2>:89' */
    /* '<S2>:83:1' sf_internal_predicateOutput = ... */
    /* '<S2>:83:1' En == false; */
    if (!Controller_Master_DW->En) {
      /* Transition: '<S2>:83' */
      /* Exit Internal 'AEB_ACTIVE': '<S2>:89' */
      Controller_Master_DW->is_AEB_ACTIVE = Controller_M_IN_NO_ACTIVE_CHILD;

      /* Exit 'AEB_ACTIVE': '<S2>:89' */
      /* '<S2>:89:2' Brake = uint8(0); */
      /* '<S2>:89:3' Led_Blue = 0; */
      Controller_Master_DW->is_APPLICATION_THREAD = Controller_Master_IN_READY;

      /* Entry 'READY': '<S2>:98' */
      /* '<S2>:98:1' Brake = uint8(0); */
      *Controller_Master_Y_BRAKE = 0U;

      /* '<S2>:98:1' Led_Blue = 0; */
      Controller_Master_B->Led_Blue = 0.0;

      /* '<S2>:98:1' Led_Green = uint8(0); */
      *Controller_Master_Y_LED_GREEN = 0U;

      /* '<S2>:98:4' Acc = uint8(0); */
      *Controller_Master_Y_ACC = 0U;
    } else {
      /* Inport: '<Root>/QA_EN' incorporates:
       *  Inport: '<Root>/V'
       */
      /* '<S2>:85:1' sf_internal_predicateOutput = ... */
      /* '<S2>:85:1' QA_En == true && V<30; */
      if (Controller_Master_U_QA_EN && (Controller_Master_U_V < 30.0)) {
        /* Transition: '<S2>:85' */
        /* Exit Internal 'AEB_ACTIVE': '<S2>:89' */
        Controller_Master_DW->is_AEB_ACTIVE = Controller_M_IN_NO_ACTIVE_CHILD;

        /* Exit 'AEB_ACTIVE': '<S2>:89' */
        /* '<S2>:89:2' Brake = uint8(0); */
        /* '<S2>:89:3' Led_Blue = 0; */
        Controller_Master_DW->is_APPLICATION_THREAD =
          Controller_Master_IN_QA_ACTIVE;

        /* Entry 'QA_ACTIVE': '<S2>:101' */
        /* '<S2>:101:1' K = (V^2)/D; */
        /* Entry Internal 'QA_ACTIVE': '<S2>:101' */
        /* Transition: '<S2>:102' */
        Controller_Master_DW->is_QA_ACTIVE = Controller_Master_IN_IDLE_k;

        /* Entry 'IDLE': '<S2>:107' */
        /* '<S2>:107:1' Brake = uint8(0); */
        *Controller_Master_Y_BRAKE = 0U;

        /* '<S2>:107:1' Led_Blue = 0; */
        Controller_Master_B->Led_Blue = 0.0;

        /* '<S2>:107:1' Led_Green = uint8(0); */
        *Controller_Master_Y_LED_GREEN = 0U;

        /* '<S2>:107:4' Acc = uint8(0); */
        *Controller_Master_Y_ACC = 0U;
      } else {
        /* Inport: '<Root>/D_M' */
        /* '<S2>:89:1' K = (V^2)/D; */
        K = Controller_Master_U_V * Controller_Master_U_V /
          Controller_Master_U_D_M;
        switch (Controller_Master_DW->is_AEB_ACTIVE) {
         case Controller_Master_IN_BRAKE:
          /* During 'BRAKE': '<S2>:97' */
          /* '<S2>:94:1' sf_internal_predicateOutput = ... */
          /* '<S2>:94:1' K < 100; */
          if (K < 100.0) {
            /* Transition: '<S2>:94' */
            Controller_Master_DW->is_AEB_ACTIVE = Controller_Master_IN_WARNING;

            /* Entry 'WARNING': '<S2>:96' */
            /* '<S2>:96:1' Brake = uint8(0); */
            *Controller_Master_Y_BRAKE = 0U;
          }
          break;

         case Controller_Master_IN_IDLE:
          /* During 'IDLE': '<S2>:95' */
          /* '<S2>:91:1' sf_internal_predicateOutput = ... */
          /* '<S2>:91:1' K >= 70; */
          if (K >= 70.0) {
            /* Transition: '<S2>:91' */
            Controller_Master_DW->is_AEB_ACTIVE = Controller_Master_IN_WARNING;

            /* Entry 'WARNING': '<S2>:96' */
            /* '<S2>:96:1' Brake = uint8(0); */
            *Controller_Master_Y_BRAKE = 0U;
          }
          break;

         default:
          /* During 'WARNING': '<S2>:96' */
          /* '<S2>:93:1' sf_internal_predicateOutput = ... */
          /* '<S2>:93:1' K  >= 100; */
          if (K >= 100.0) {
            /* Transition: '<S2>:93' */
            Controller_Master_DW->is_AEB_ACTIVE = Controller_Master_IN_BRAKE;

            /* Entry 'BRAKE': '<S2>:97' */
            /* '<S2>:97:1' Brake = uint8(1); */
            *Controller_Master_Y_BRAKE = 1U;

            /* '<S2>:97:1' Led_Blue = 1; */
            Controller_Master_B->Led_Blue = 1.0;
          } else {
            /* '<S2>:92:1' sf_internal_predicateOutput = ... */
            /* '<S2>:92:1' K < 70; */
            if (K < 70.0) {
              /* Transition: '<S2>:92' */
              Controller_Master_DW->is_AEB_ACTIVE = Controller_Master_IN_IDLE;

              /* Entry 'IDLE': '<S2>:95' */
              /* '<S2>:95:1' Brake = uint8(0); */
              *Controller_Master_Y_BRAKE = 0U;

              /* '<S2>:95:1' Led_Blue = 0; */
              Controller_Master_B->Led_Blue = 0.0;
            } else {
              /* '<S2>:96:1' Led_Blue = (K-70)/30; */
              Controller_Master_B->Led_Blue = (K - 70.0) / 30.0;
            }
          }
          break;
        }
      }
    }
    break;

   case Controller_Master_IN_QA_ACTIVE:
    /* Inport: '<Root>/QA_EN' incorporates:
     *  Inport: '<Root>/V'
     */
    /* During 'QA_ACTIVE': '<S2>:101' */
    /* '<S2>:86:1' sf_internal_predicateOutput = ... */
    /* '<S2>:86:1' QA_En ~= true || V>=30; */
    if ((!Controller_Master_U_QA_EN) || (Controller_Master_U_V >= 30.0)) {
      /* Transition: '<S2>:86' */
      /* Exit Internal 'QA_ACTIVE': '<S2>:101' */
      Controller_Master_DW->is_QA_ACTIVE = Controller_M_IN_NO_ACTIVE_CHILD;

      /* Exit 'QA_ACTIVE': '<S2>:101' */
      /* '<S2>:101:2' Brake = uint8(0); */
      /* '<S2>:101:3' Led_Blue = 0; */
      /* '<S2>:101:4' Led_Green = uint8(0); */
      *Controller_Master_Y_LED_GREEN = 0U;

      /* '<S2>:101:5' Acc = uint8(0); */
      *Controller_Master_Y_ACC = 0U;
      Controller_Master_DW->is_APPLICATION_THREAD =
        Controller_Master_IN_AEB_ACTIVE;

      /* Entry 'AEB_ACTIVE': '<S2>:89' */
      /* '<S2>:89:1' K = (V^2)/D; */
      /* Entry Internal 'AEB_ACTIVE': '<S2>:89' */
      /* Transition: '<S2>:90' */
      Controller_Master_DW->is_AEB_ACTIVE = Controller_Master_IN_IDLE;

      /* Entry 'IDLE': '<S2>:95' */
      /* '<S2>:95:1' Brake = uint8(0); */
      *Controller_Master_Y_BRAKE = 0U;

      /* '<S2>:95:1' Led_Blue = 0; */
      Controller_Master_B->Led_Blue = 0.0;
    } else {
      /* '<S2>:84:1' sf_internal_predicateOutput = ... */
      /* '<S2>:84:1' En == false; */
      if (!Controller_Master_DW->En) {
        /* Transition: '<S2>:84' */
        /* Exit Internal 'QA_ACTIVE': '<S2>:101' */
        Controller_Master_DW->is_QA_ACTIVE = Controller_M_IN_NO_ACTIVE_CHILD;

        /* Exit 'QA_ACTIVE': '<S2>:101' */
        /* '<S2>:101:2' Brake = uint8(0); */
        /* '<S2>:101:3' Led_Blue = 0; */
        /* '<S2>:101:4' Led_Green = uint8(0); */
        /* '<S2>:101:5' Acc = uint8(0); */
        Controller_Master_DW->is_APPLICATION_THREAD = Controller_Master_IN_READY;

        /* Entry 'READY': '<S2>:98' */
        /* '<S2>:98:1' Brake = uint8(0); */
        *Controller_Master_Y_BRAKE = 0U;

        /* '<S2>:98:1' Led_Blue = 0; */
        Controller_Master_B->Led_Blue = 0.0;

        /* '<S2>:98:1' Led_Green = uint8(0); */
        *Controller_Master_Y_LED_GREEN = 0U;

        /* '<S2>:98:4' Acc = uint8(0); */
        *Controller_Master_Y_ACC = 0U;
      } else {
        /* Inport: '<Root>/D_M' */
        /* '<S2>:101:1' K = (V^2)/D; */
        K = Controller_Master_U_V * Controller_Master_U_V /
          Controller_Master_U_D_M;
        switch (Controller_Master_DW->is_QA_ACTIVE) {
         case Controller_Master_IN_ACCELERATE:
          /* During 'ACCELERATE': '<S2>:108' */
          /* '<S2>:103:1' sf_internal_predicateOutput = ... */
          /* '<S2>:103:1' K  >= 100; */
          if (K >= 100.0) {
            /* Transition: '<S2>:103' */
            Controller_Master_DW->is_QA_ACTIVE = Controller_Master_IN_IDLE_k;

            /* Entry 'IDLE': '<S2>:107' */
            /* '<S2>:107:1' Brake = uint8(0); */
            *Controller_Master_Y_BRAKE = 0U;

            /* '<S2>:107:1' Led_Blue = 0; */
            Controller_Master_B->Led_Blue = 0.0;

            /* '<S2>:107:1' Led_Green = uint8(0); */
            *Controller_Master_Y_LED_GREEN = 0U;

            /* '<S2>:107:4' Acc = uint8(0); */
            *Controller_Master_Y_ACC = 0U;
          }
          break;

         case Controller_Master_IN_BRAKE_d:
          /* During 'BRAKE': '<S2>:109' */
          /* '<S2>:105:1' sf_internal_predicateOutput = ... */
          /* '<S2>:105:1' K <= 100; */
          if (K <= 100.0) {
            /* Transition: '<S2>:105' */
            Controller_Master_DW->is_QA_ACTIVE = Controller_Master_IN_IDLE_k;

            /* Entry 'IDLE': '<S2>:107' */
            /* '<S2>:107:1' Brake = uint8(0); */
            *Controller_Master_Y_BRAKE = 0U;

            /* '<S2>:107:1' Led_Blue = 0; */
            Controller_Master_B->Led_Blue = 0.0;

            /* '<S2>:107:1' Led_Green = uint8(0); */
            *Controller_Master_Y_LED_GREEN = 0U;

            /* '<S2>:107:4' Acc = uint8(0); */
            *Controller_Master_Y_ACC = 0U;
          }
          break;

         default:
          /* During 'IDLE': '<S2>:107' */
          /* '<S2>:104:1' sf_internal_predicateOutput = ... */
          /* '<S2>:104:1' K  > 100; */
          if (K > 100.0) {
            /* Transition: '<S2>:104' */
            Controller_Master_DW->is_QA_ACTIVE = Controller_Master_IN_BRAKE_d;

            /* Entry 'BRAKE': '<S2>:109' */
            /* '<S2>:109:1' Brake = uint8(1); */
            *Controller_Master_Y_BRAKE = 1U;

            /* '<S2>:109:1' Led_Blue = 1; */
            Controller_Master_B->Led_Blue = 1.0;
          } else {
            /* '<S2>:106:1' sf_internal_predicateOutput = ... */
            /* '<S2>:106:1' K < 100; */
            if (K < 100.0) {
              /* Transition: '<S2>:106' */
              Controller_Master_DW->is_QA_ACTIVE =
                Controller_Master_IN_ACCELERATE;

              /* Entry 'ACCELERATE': '<S2>:108' */
              /* '<S2>:108:1' Led_Green = uint8(1); */
              *Controller_Master_Y_LED_GREEN = 1U;

              /* '<S2>:108:1' Acc = uint8(1); */
              *Controller_Master_Y_ACC = 1U;
            }
          }
          break;
        }
      }
    }
    break;

   default:
    /* During 'READY': '<S2>:98' */
    /* '<S2>:82:1' sf_internal_predicateOutput = ... */
    /* '<S2>:82:1' En == true; */
    if (Controller_Master_DW->En) {
      /* Transition: '<S2>:82' */
      Controller_Master_DW->is_APPLICATION_THREAD =
        Controller_Master_IN_AEB_ACTIVE;

      /* Entry 'AEB_ACTIVE': '<S2>:89' */
      /* '<S2>:89:1' K = (V^2)/D; */
      /* Entry Internal 'AEB_ACTIVE': '<S2>:89' */
      /* Transition: '<S2>:90' */
      Controller_Master_DW->is_AEB_ACTIVE = Controller_Master_IN_IDLE;

      /* Entry 'IDLE': '<S2>:95' */
      /* '<S2>:95:1' Brake = uint8(0); */
      *Controller_Master_Y_BRAKE = 0U;

      /* '<S2>:95:1' Led_Blue = 0; */
      Controller_Master_B->Led_Blue = 0.0;
    }
    break;
  }
}

/* Model step function */
void Controller_Master_step(RT_MODEL_Controller_Master_T *const
  Controller_Master_M, real_T Controller_Master_U_V, real_T
  Controller_Master_U_D_M, boolean_T Controller_Master_U_QA_EN, uint8_T
  *Controller_Master_Y_BRAKE, uint8_T *Controller_Master_Y_ACC, uint8_T
  *Controller_Master_Y_LED_RED, uint8_T *Controller_Master_Y_LED_GREEN, uint8_T *
  Controller_Master_Y_LED_BLUE, uint8_T *Controller_Master_Y_MASTER)
{
  B_Controller_Master_T *Controller_Master_B = ((B_Controller_Master_T *)
    Controller_Master_M->ModelData.blockIO);
  DW_Controller_Master_T *Controller_Master_DW = ((DW_Controller_Master_T *)
    Controller_Master_M->ModelData.dwork);

  /* Outputs for Atomic SubSystem: '<Root>/Controller_Master' */
  /* Chart: '<S1>/AEB_QA' */
  /* Gateway: Controller_Master/AEB_QA */
  /* During: Controller_Master/AEB_QA */
  if (Controller_Master_DW->is_active_c3_Controller_Master == 0U) {
    /* Entry: Controller_Master/AEB_QA */
    Controller_Master_DW->is_active_c3_Controller_Master = 1U;

    /* Entry Internal: Controller_Master/AEB_QA */
    /* Entry Internal 'AEB_QA': '<S2>:35' */
    /* Entry Internal 'ERRORS_CHECK_THREAD': '<S2>:33' */
    /* Transition: '<S2>:38' */
    Controller_Master_DW->is_ERRORS_CHECK_THREAD = Controller_Master_IN_OK;

    /* Outport: '<Root>/LED_RED' */
    /* Entry 'OK': '<S2>:37' */
    /* '<S2>:37:1' Led_Red =uint8(0); */
    *Controller_Master_Y_LED_RED = 0U;

    /* Outport: '<Root>/MASTER' */
    /* '<S2>:37:1' Master = uint8(1); */
    *Controller_Master_Y_MASTER = 1U;

    /* Entry Internal 'APPLICATION_THREAD': '<S2>:80' */
    /* Transition: '<S2>:81' */
    Controller_Master_DW->is_APPLICATION_THREAD = Controller_Master_IN_READY;

    /* Outport: '<Root>/BRAKE' */
    /* Entry 'READY': '<S2>:98' */
    /* '<S2>:98:1' Brake = uint8(0); */
    *Controller_Master_Y_BRAKE = 0U;

    /* '<S2>:98:1' Led_Blue = 0; */
    Controller_Master_B->Led_Blue = 0.0;

    /* Outport: '<Root>/LED_GREEN' */
    /* '<S2>:98:1' Led_Green = uint8(0); */
    *Controller_Master_Y_LED_GREEN = 0U;

    /* Outport: '<Root>/ACC' */
    /* '<S2>:98:4' Acc = uint8(0); */
    *Controller_Master_Y_ACC = 0U;
  } else {
    Controller_Master_AEB_QA(Controller_Master_U_V, Controller_Master_U_D_M,
      Controller_Master_U_QA_EN, Controller_Master_Y_BRAKE,
      Controller_Master_Y_ACC, Controller_Master_Y_LED_RED,
      Controller_Master_Y_LED_GREEN, Controller_Master_Y_MASTER,
      Controller_Master_B, Controller_Master_DW);
  }

  /* End of Chart: '<S1>/AEB_QA' */

  /* Chart: '<S1>/select_command' */
  if (Controller_Master_DW->temporalCounter_i1 < MAX_uint32_T) {
    Controller_Master_DW->temporalCounter_i1++;
  }

  /* Gateway: Controller_Master/select_command */
  /* During: Controller_Master/select_command */
  if (Controller_Master_DW->is_active_c2_Controller_Master == 0U) {
    /* Entry: Controller_Master/select_command */
    Controller_Master_DW->is_active_c2_Controller_Master = 1U;

    /* Entry Internal: Controller_Master/select_command */
    /* Transition: '<S3>:2' */
    Controller_Master_DW->is_c2_Controller_Master = Controller_Master_IN_OFF1;

    /* Outport: '<Root>/LED_BLUE' */
    /* Entry 'OFF1': '<S3>:3' */
    /* '<S3>:3:1' led = uint8(0); */
    *Controller_Master_Y_LED_BLUE = 0U;
  } else {
    switch (Controller_Master_DW->is_c2_Controller_Master) {
     case Controller_Master_IN_BLINK:
      /* During 'BLINK': '<S3>:20' */
      /* '<S3>:7:1' sf_internal_predicateOutput = ... */
      /* '<S3>:7:1' enable == 1; */
      if (Controller_Master_B->Led_Blue == 1.0) {
        /* Transition: '<S3>:7' */
        /* Exit Internal 'BLINK': '<S3>:20' */
        Controller_Master_DW->is_BLINK = Controller_M_IN_NO_ACTIVE_CHILD;
        Controller_Master_DW->is_c2_Controller_Master = Controller_Master_IN_ON;

        /* Outport: '<Root>/LED_BLUE' */
        /* Entry 'ON': '<S3>:6' */
        /* '<S3>:6:1' led = uint8(1); */
        *Controller_Master_Y_LED_BLUE = 1U;
      } else {
        /* '<S3>:21:1' sf_internal_predicateOutput = ... */
        /* '<S3>:21:1' enable == 0; */
        if (Controller_Master_B->Led_Blue == 0.0) {
          /* Transition: '<S3>:21' */
          /* Exit Internal 'BLINK': '<S3>:20' */
          Controller_Master_DW->is_BLINK = Controller_M_IN_NO_ACTIVE_CHILD;
          Controller_Master_DW->is_c2_Controller_Master =
            Controller_Master_IN_OFF1;

          /* Outport: '<Root>/LED_BLUE' */
          /* Entry 'OFF1': '<S3>:3' */
          /* '<S3>:3:1' led = uint8(0); */
          *Controller_Master_Y_LED_BLUE = 0U;
        } else if (Controller_Master_DW->is_BLINK ==
                   Controller_Master_IN_BLINK_OFF) {
          /* During 'BLINK_OFF': '<S3>:11' */
          /* '<S3>:14:1' sf_internal_predicateOutput = ... */
          /* '<S3>:14:1' after(1-enable,sec); */
          if (Controller_Master_DW->temporalCounter_i1 >= (uint32_T)ceil((1.0 -
                Controller_Master_B->Led_Blue) / 0.1 - 1.0E-9)) {
            /* Transition: '<S3>:14' */
            Controller_Master_DW->is_BLINK = Controller_Master_IN_BLINK_ON;
            Controller_Master_DW->temporalCounter_i1 = 0U;

            /* Outport: '<Root>/LED_BLUE' */
            /* Entry 'BLINK_ON': '<S3>:13' */
            /* '<S3>:13:1' led = uint8(1); */
            *Controller_Master_Y_LED_BLUE = 1U;
          }
        } else {
          /* During 'BLINK_ON': '<S3>:13' */
          /* '<S3>:15:1' sf_internal_predicateOutput = ... */
          /* '<S3>:15:1' after(0.1,sec); */
          if (Controller_Master_DW->temporalCounter_i1 >= 1U) {
            /* Transition: '<S3>:15' */
            Controller_Master_DW->is_BLINK = Controller_Master_IN_BLINK_OFF;
            Controller_Master_DW->temporalCounter_i1 = 0U;

            /* Outport: '<Root>/LED_BLUE' */
            /* Entry 'BLINK_OFF': '<S3>:11' */
            /* '<S3>:11:1' led = uint8(0); */
            *Controller_Master_Y_LED_BLUE = 0U;
          }
        }
      }
      break;

     case Controller_Master_IN_OFF1:
      /* During 'OFF1': '<S3>:3' */
      /* '<S3>:22:1' sf_internal_predicateOutput = ... */
      /* '<S3>:22:1' enable == 1; */
      if (Controller_Master_B->Led_Blue == 1.0) {
        /* Transition: '<S3>:22' */
        Controller_Master_DW->is_c2_Controller_Master = Controller_Master_IN_ON;

        /* Outport: '<Root>/LED_BLUE' */
        /* Entry 'ON': '<S3>:6' */
        /* '<S3>:6:1' led = uint8(1); */
        *Controller_Master_Y_LED_BLUE = 1U;
      } else {
        /* '<S3>:12:1' sf_internal_predicateOutput = ... */
        /* '<S3>:12:1' enable >0 && enable <1; */
        if ((Controller_Master_B->Led_Blue > 0.0) &&
            (Controller_Master_B->Led_Blue < 1.0)) {
          /* Transition: '<S3>:12' */
          Controller_Master_DW->is_c2_Controller_Master =
            Controller_Master_IN_BLINK;

          /* Entry Internal 'BLINK': '<S3>:20' */
          /* Transition: '<S3>:24' */
          Controller_Master_DW->is_BLINK = Controller_Master_IN_BLINK_OFF;
          Controller_Master_DW->temporalCounter_i1 = 0U;

          /* Outport: '<Root>/LED_BLUE' */
          /* Entry 'BLINK_OFF': '<S3>:11' */
          /* '<S3>:11:1' led = uint8(0); */
          *Controller_Master_Y_LED_BLUE = 0U;
        }
      }
      break;

     default:
      /* During 'ON': '<S3>:6' */
      /* '<S3>:4:1' sf_internal_predicateOutput = ... */
      /* '<S3>:4:1' enable == 0; */
      if (Controller_Master_B->Led_Blue == 0.0) {
        /* Transition: '<S3>:4' */
        Controller_Master_DW->is_c2_Controller_Master =
          Controller_Master_IN_OFF1;

        /* Outport: '<Root>/LED_BLUE' */
        /* Entry 'OFF1': '<S3>:3' */
        /* '<S3>:3:1' led = uint8(0); */
        *Controller_Master_Y_LED_BLUE = 0U;
      } else {
        /* '<S3>:23:1' sf_internal_predicateOutput = ... */
        /* '<S3>:23:1' enable >0 && enable <1; */
        if ((Controller_Master_B->Led_Blue > 0.0) &&
            (Controller_Master_B->Led_Blue < 1.0)) {
          /* Transition: '<S3>:23' */
          Controller_Master_DW->is_c2_Controller_Master =
            Controller_Master_IN_BLINK;

          /* Entry Internal 'BLINK': '<S3>:20' */
          /* Transition: '<S3>:24' */
          Controller_Master_DW->is_BLINK = Controller_Master_IN_BLINK_OFF;
          Controller_Master_DW->temporalCounter_i1 = 0U;

          /* Outport: '<Root>/LED_BLUE' */
          /* Entry 'BLINK_OFF': '<S3>:11' */
          /* '<S3>:11:1' led = uint8(0); */
          *Controller_Master_Y_LED_BLUE = 0U;
        }
      }
      break;
    }
  }

  /* End of Chart: '<S1>/select_command' */
  /* End of Outputs for SubSystem: '<Root>/Controller_Master' */
}

/* Model initialize function */
void Controller_Master_initialize(RT_MODEL_Controller_Master_T *const
  Controller_Master_M, real_T *Controller_Master_U_V, real_T
  *Controller_Master_U_D_M, uint8_T *Controller_Master_U_Slave, boolean_T
  *Controller_Master_U_QA_EN, uint8_T *Controller_Master_Y_BRAKE, uint8_T
  *Controller_Master_Y_ACC, uint8_T *Controller_Master_Y_LED_RED, uint8_T
  *Controller_Master_Y_LED_GREEN, uint8_T *Controller_Master_Y_LED_BLUE, uint8_T
  *Controller_Master_Y_MASTER)
{
  DW_Controller_Master_T *Controller_Master_DW = ((DW_Controller_Master_T *)
    Controller_Master_M->ModelData.dwork);
  B_Controller_Master_T *Controller_Master_B = ((B_Controller_Master_T *)
    Controller_Master_M->ModelData.blockIO);

  /* Registration code */

  /* block I/O */
  (void) memset(((void *) Controller_Master_B), 0,
                sizeof(B_Controller_Master_T));

  /* states (dwork) */
  (void) memset((void *)Controller_Master_DW, 0,
                sizeof(DW_Controller_Master_T));

  /* external inputs */
  (*Controller_Master_U_V) = 0.0;
  (*Controller_Master_U_D_M) = 0.0;
  (*Controller_Master_U_Slave) = 0U;
  (*Controller_Master_U_QA_EN) = false;

  /* external outputs */
  (*Controller_Master_Y_BRAKE) = 0U;
  (*Controller_Master_Y_ACC) = 0U;
  (*Controller_Master_Y_LED_RED) = 0U;
  (*Controller_Master_Y_LED_GREEN) = 0U;
  (*Controller_Master_Y_LED_BLUE) = 0U;
  (*Controller_Master_Y_MASTER) = 0U;

  /* SystemInitialize for Atomic SubSystem: '<Root>/Controller_Master' */
  /* SystemInitialize for Chart: '<S1>/AEB_QA' */
  Controller_Master_DW->is_APPLICATION_THREAD = Controller_M_IN_NO_ACTIVE_CHILD;
  Controller_Master_DW->is_AEB_ACTIVE = Controller_M_IN_NO_ACTIVE_CHILD;
  Controller_Master_DW->is_QA_ACTIVE = Controller_M_IN_NO_ACTIVE_CHILD;
  Controller_Master_DW->is_ERRORS_CHECK_THREAD = Controller_M_IN_NO_ACTIVE_CHILD;
  Controller_Master_DW->is_active_c3_Controller_Master = 0U;
  Controller_Master_DW->En = true;

  /* SystemInitialize for Chart: '<S1>/select_command' */
  Controller_Master_DW->is_BLINK = Controller_M_IN_NO_ACTIVE_CHILD;
  Controller_Master_DW->temporalCounter_i1 = 0U;
  Controller_Master_DW->is_active_c2_Controller_Master = 0U;
  Controller_Master_DW->is_c2_Controller_Master =
    Controller_M_IN_NO_ACTIVE_CHILD;

  /* End of SystemInitialize for SubSystem: '<Root>/Controller_Master' */
}

/* Model terminate function */
void Controller_Master_terminate(RT_MODEL_Controller_Master_T *const
  Controller_Master_M)
{
  /* (no terminate code required) */
  UNUSED_PARAMETER(Controller_Master_M);
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */