/*
 * File: rt_sys_P417_SWTL_App_0.c
 *
 * Code generated for Simulink model 'P417_SWTL_App'.
 *
 * Model version                  : 1.148
 * Simulink Coder version         : 8.13 (R2017b) 24-Jul-2017
 * C/C++ source code generated on : Tue Dec 20 16:43:44 2022
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "rt_sys_P417_SWTL_App_0.h"

/* Include model header file for global data */
#include "P417_SWTL_App.h"
#include "P417_SWTL_App_private.h"

/* Named constants for Chart: '<S87>/Fault_Debounce_Chart' */
#define P417_SWTL_Ap_IN_NO_ACTIVE_CHILD ((uint8_T)0U)
#define P417_SWTL_App_IN_Fault_Recovery ((uint8_T)1U)
#define P417_SWTL_App_IN_Fault_confirm ((uint8_T)2U)
#define P417_SWTL_App_IN_Fault_happened ((uint8_T)3U)
#define P417_SWTL_App_IN_Fault_off     ((uint8_T)4U)

/*
 * System initialize for atomic system:
 *    '<S87>/Fault_Debounce_Chart'
 *    '<S35>/Fault_Debounce_Chart'
 *    '<S37>/Fault_Debounce_Chart'
 */
void P417__Fault_Debounce_Chart_Init(uint8_T *rty_Fault_confirmed,
  DW_Fault_Debounce_Chart_P417__T *localDW)
{
  localDW->temporalCounter_i1 = 0U;
  localDW->is_active_c2_Debounce_Models = 0U;
  localDW->is_c2_Debounce_Models = P417_SWTL_Ap_IN_NO_ACTIVE_CHILD;
  *rty_Fault_confirmed = 0U;
}

/*
 * Output and update for atomic system:
 *    '<S87>/Fault_Debounce_Chart'
 *    '<S35>/Fault_Debounce_Chart'
 *    '<S37>/Fault_Debounce_Chart'
 */
void P417_SWTL__Fault_Debounce_Chart(uint8_T rtu_Fault_in, uint8_T
  *rty_Fault_confirmed, DW_Fault_Debounce_Chart_P417__T *localDW, uint8_T
  rtp_Fault_confirm_count, uint8_T rtp_Fault_recovery_count)
{
  /* Chart: '<S87>/Fault_Debounce_Chart' */
  if (localDW->temporalCounter_i1 < 255U) {
    localDW->temporalCounter_i1++;
  }

  if (localDW->is_active_c2_Debounce_Models == 0U) {
    localDW->is_active_c2_Debounce_Models = 1U;
    localDW->is_c2_Debounce_Models = P417_SWTL_App_IN_Fault_off;
    *rty_Fault_confirmed = 0U;
  } else {
    switch (localDW->is_c2_Debounce_Models) {
     case P417_SWTL_App_IN_Fault_Recovery:
      if (rtu_Fault_in == 1) {
        localDW->is_c2_Debounce_Models = P417_SWTL_App_IN_Fault_happened;
        localDW->temporalCounter_i1 = 0U;
      } else {
        if (localDW->temporalCounter_i1 >= rtp_Fault_recovery_count) {
          localDW->is_c2_Debounce_Models = P417_SWTL_App_IN_Fault_off;
          *rty_Fault_confirmed = 0U;
        }
      }
      break;

     case P417_SWTL_App_IN_Fault_confirm:
      *rty_Fault_confirmed = 1U;
      if (rtu_Fault_in == 0) {
        localDW->is_c2_Debounce_Models = P417_SWTL_App_IN_Fault_Recovery;
        localDW->temporalCounter_i1 = 0U;
      }
      break;

     case P417_SWTL_App_IN_Fault_happened:
      if (localDW->temporalCounter_i1 >= rtp_Fault_confirm_count) {
        localDW->is_c2_Debounce_Models = P417_SWTL_App_IN_Fault_confirm;
        *rty_Fault_confirmed = 1U;
      } else {
        if (rtu_Fault_in == 0) {
          localDW->is_c2_Debounce_Models = P417_SWTL_App_IN_Fault_Recovery;
          localDW->temporalCounter_i1 = 0U;
        }
      }
      break;

     default:
      *rty_Fault_confirmed = 0U;
      if (rtu_Fault_in == 1) {
        localDW->is_c2_Debounce_Models = P417_SWTL_App_IN_Fault_happened;
        localDW->temporalCounter_i1 = 0U;
      }
      break;
    }
  }

  /* End of Chart: '<S87>/Fault_Debounce_Chart' */
}

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