/***********************************************************************************************************************
 *  FILE DESCRIPTION
 *  ------------------------------------------------------------------------------------------------------------------*/
/** \file
 *  \brief         Diagnostic services supported in boot mode
 *                 Data structure creation for state machine
 *
 *  --------------------------------------------------------------------------------------------------------------------
 *  COPYRIGHT
 *  --------------------------------------------------------------------------------------------------------------------
 *  \par Copyright
 *  \verbatim
 *  Copyright (c) 2026 by Vector Informatik GmbH.                                                  All rights reserved.
 *
 *                This software is copyright protected and proprietary to Vector Informatik GmbH.
 *                Vector Informatik GmbH grants to you only those rights as set out in the license conditions.
 *                All other rights remain with Vector Informatik GmbH.
 *  \endverbatim
 */
/**********************************************************************************************************************/

/***********************************************************************************************************************
 *  REVISION HISTORY
 *  --------------------------------------------------------------------------------------------------------------------
 *  Version    Date        Author       Change Id        Description
 *  --------------------------------------------------------------------------------------------------------------------
 *  05.00.00   2022-08-15  vistmo       FBL-5514         Support Additional OTA functionality
 *                                      ESCAN00112435    No changes
 *                                      ESCAN00112575    No changes
 *  05.01.00   2022-10-04  jschmitding  FBL-5917         No changes
 *                                      ESCAN00113919    No changes
 *  05.01.01   2022-10-17  fmenke       ESCAN00112879    No changes
 *  05.01.02   2023-01-13  fmenke       ESCAN00112890    No changes
 *                                      ESCAN00113612    No changes
 *  05.02.00   2023-02-09  vistmo       ESCAN00112972    No changes
 *                                      ESCAN00113292    No changes
 *                                      ESCAN00113835    No changes
 *                                      ESCAN00113843    No changes
 *                                      ESCAN00113764    No changes
 *                                      FBL-6438         No changes
 *  05.02.01   2023-05-11  fmenke       ESCAN00113831    No changes
 *  05.03.00   2023-07-24  fmenke       FBL-7335         No changes
 *  05.03.01   2023-08-31  lhopfhauer   ESCAN00115494    No changes
 *  05.03.02   2024-07-16  erizk        ESCAN00117344    No changes
 *  05.03.03   2025-02-06  virchl       ESCAN00118587    No changes
 *  05.04.00   2025-02-28  jjohnson     FBL-10065        No changes
 *  05.04.01   2025-06-10  jostravsky   ESCAN00120315    No changes
 *  05.04.02   2025-07-08  visarcmijo   ESCAN00119833    No changes
 *  05.05.00   2025-09-01  fmenke       FBL-11218        No changes
 *                                      ESCAN00120917    No changes
 *  05.06.00   2025-10-28  mpatil       FBL-11690        No changes
 *  05.07.00   2026-01-13  dganesh      FBL-12162        No changes
 **********************************************************************************************************************/

/***********************************************************************************************************************
 *  VERSION
 **********************************************************************************************************************/

#if ( FBLDIAG_14229_FORD_VERSION != 0x0507u ) || \
    ( FBLDIAG_14229_FORD_RELEASE_VERSION != 0x00u )
# error "Error in fbl_diag.imp: State machine implementation and source are inconsistent!"
#endif

/* PRQA S 0342 EOF */ /* MD_MSR_Rule20.10_0342 */
/* PRQA S 0883 EOF */ /* MD_FblDiag_0883 */

/* --------------------------------------------------------------------------- */
/* Implementation type: Output                                                 */
/* --------------------------------------------------------------------------- */
/* Output according to FBL_DIAG_STATE_DEF and FBL_DIAG_IMPL_OUTPUT             */
/* , e.g. FBL_DIAG_STATE_DEF = kDiagService ## name,                           */
/* FBL_DIAG_IMPL_OUTPUT = FBL_DIAG_STATE_RESULT,                               */
/* --------------------------------------------------------------------------- */
#if ( FBL_DIAG_IMPL_TYPE == FBL_DIAG_IMPL_TYPE_OUTPUT )
FBL_DIAG_IMPL_OUTPUT
#endif

/* --------------------------------------------------------------------------- */
/* Implementation type: State bitmap                                           */
/* --------------------------------------------------------------------------- */
/* Generate state bitmap entries                                               */
/* --------------------------------------------------------------------------- */
#if ( FBL_DIAG_IMPL_TYPE == FBL_DIAG_IMPL_TYPE_STATEBITMAP )
# define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax) set
# if (FBL_DIAG_STATE_RESULT != kDiagStateNone)
   STATE_BUILDARRAYENTRIES(FBL_DIAG_STATE_RESULT),
# endif
# undef FBL_DIAG_STATE_DEF

# define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax) unset
# if (FBL_DIAG_STATE_RESULT != kDiagStateNone)
   STATE_BUILDARRAYENTRIES(FBL_DIAG_STATE_RESULT),
# endif
# undef FBL_DIAG_STATE_DEF

# define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax) add
# if (FBL_DIAG_STATE_RESULT != kDiagStateNone)
   STATE_BUILDARRAYENTRIES(FBL_DIAG_STATE_RESULT),
# endif
# undef FBL_DIAG_STATE_DEF

# define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax) clear
# if (FBL_DIAG_STATE_RESULT != kDiagStateNone)
   STATE_BUILDARRAYENTRIES(FBL_DIAG_STATE_RESULT),
# endif
# undef FBL_DIAG_STATE_DEF

# define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax) clearFail
# if (FBL_DIAG_STATE_RESULT != kDiagStateNone)
   STATE_BUILDARRAYENTRIES(FBL_DIAG_STATE_RESULT),
# endif
# undef FBL_DIAG_STATE_DEF
#endif

/* --------------------------------------------------------------------------- */
/* Implementation type: Service property                                       */
/* --------------------------------------------------------------------------- */
/* Generate the service properties, including service IDs, references to child */
/* node lists and handler functions                                            */
/* --------------------------------------------------------------------------- */
#if ( FBL_DIAG_IMPL_TYPE == FBL_DIAG_IMPL_TYPE_SERVICEPROPERTY )
# if defined( None )
#  undef None
# endif
# define None   0xFFFFFFFFu

# if defined( FBL_DIAG_ENABLE_RAM_STATETABLES )
#  define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax)  set
#  if (FBL_DIAG_STATE_RESULT != kDiagStateNone)
#   define USAGE_MASK_SET         0x01u
#  else
#   define USAGE_MASK_SET         0x00u
#  endif
#  undef FBL_DIAG_STATE_DEF

#  define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax)  unset
#  if (FBL_DIAG_STATE_RESULT != kDiagStateNone)
#   define USAGE_MASK_UNSET       0x02u
#  else
#   define USAGE_MASK_UNSET       0x00u
#  endif
#  undef FBL_DIAG_STATE_DEF

#  define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax)  add
#  if (FBL_DIAG_STATE_RESULT != kDiagStateNone)
#   define USAGE_MASK_ADD         0x04u
#  else
#   define USAGE_MASK_ADD         0x00u
#  endif
#  undef FBL_DIAG_STATE_DEF

#  define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax)  clear
#  if (FBL_DIAG_STATE_RESULT != kDiagStateNone)
#   define USAGE_MASK_CLEAR       0x08u
#  else
#   define USAGE_MASK_CLEAR       0x00u
#  endif
#  undef FBL_DIAG_STATE_DEF

#  define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax)  clearFail
#  if (FBL_DIAG_STATE_RESULT != kDiagStateNone)
#   define USAGE_MASK_CLEARFAIL   0x10u
#  else
#   define USAGE_MASK_CLEARFAIL   0x00u
#  endif
#  undef FBL_DIAG_STATE_DEF
# endif

   {

# if defined( FBL_DIAG_SERVICE_LIST_HANDLES )
# else
#  define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax)  firstChild
#  if (FBL_DIAG_STATE_RESULT != None)
#   undef FBL_DIAG_STATE_DEF
#   define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax) &kDiagSubFctTbl_ ## name

      FBL_DIAG_STATE_RESULT,
#  else
      kDiagNoSubServices,
#  endif
#  undef FBL_DIAG_STATE_DEF
# endif

# if defined( FBL_DIAG_STATE_ARRAYS )
#  if !defined( STATE_PREFIX )
#   define STATE_PREFIX   {
#  endif
#  if !defined( STATE_POSTFIX )
#   define STATE_POSTFIX  }
#  endif
# else
#  if !defined( STATE_PREFIX )
#   define STATE_PREFIX
#  endif
#  if !defined( STATE_POSTFIX )
#   define STATE_POSTFIX
#  endif
# endif

# define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax)  checks
# if defined( FBL_DIAG_CHECK_LIST_HANDLES )
#  define FBL_DIAG_STATE_DEF_CHECKIDX(checks)     ,checks
#  define FBL_DIAG_STATE_DEF_CHECKS(checks)
# else
#  if (FBL_DIAG_STATE_RESULT != None)
#   define FBL_DIAG_STATE_DEF_CHECKIDX(checks)
#   define FBL_DIAG_STATE_DEF_CHECKS(checks)      ,&checks
#  else
#   define FBL_DIAG_STATE_DEF_CHECKIDX(checks)
#   define FBL_DIAG_STATE_DEF_CHECKS(checks)      ,kDiagNoCheckList
#  endif
# endif
# undef FBL_DIAG_STATE_DEF

# if defined( FBL_DIAG_ENABLE_RAM_STATETABLES )
#  define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax) \
      kDiagSrvId_ ## name                                                                                                                 \
      FBL_DIAG_STATE_DEF_CHECKS( kDiag ## checks ## Table )                                                                               \
      ,rqlMin                                                                                                                             \
      ,rqlMax                                                                                                                             \
      ,(USAGE_MASK_SET | USAGE_MASK_UNSET | USAGE_MASK_ADD | USAGE_MASK_CLEAR | USAGE_MASK_CLEARFAIL)                                     \
      ,kServiceMainHandler ## handler                                                                                                                            \
      FBL_DIAG_STATE_DEF_CHECKIDX( kServiceCheckList ## checks )
# else
#  define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax) \
      kDiagSrvId_ ## name                                                                                                                 \
      FBL_DIAG_STATE_DEF_CHECKS( kDiag ## checks ## Table )                                                                               \
      ,rqlMin                                                                                                                             \
      ,rqlMax                                                                                                                             \
      ,STATE_PREFIX                                                                                                                       \
         STATE_BUILDARRAY(set)                                                                                                            \
         ,STATE_BUILDARRAY(unset)                                                                                                         \
         ,STATE_BUILDARRAY(add)                                                                                                           \
         ,STATE_BUILDARRAY(clear)                                                                                                         \
         ,STATE_BUILDARRAY(clearFail)                                                                                                     \
      STATE_POSTFIX                                                                                                                       \
      ,kServiceMainHandler ## handler                                                                                                                            \
      FBL_DIAG_STATE_DEF_CHECKIDX( kServiceCheckList ## checks )
# endif

FBL_DIAG_STATE_RESULT

# undef FBL_DIAG_STATE_DEF_CHECKIDX
# undef FBL_DIAG_STATE_DEF_CHECKS
# undef FBL_DIAG_STATE_DEF

# if defined( FBL_DIAG_SERVICE_LIST_HANDLES )
#  define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax)  firstChild
#  if (FBL_DIAG_STATE_RESULT != None)
#   undef FBL_DIAG_STATE_DEF
#   define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax) kDiagServiceListHandler_ ## name

      ,FBL_DIAG_STATE_RESULT
#  else
      ,kDiagServiceListHandler_None
#  endif
#  undef FBL_DIAG_STATE_DEF
# endif
   },

# if defined( FBL_DIAG_ENABLE_RAM_STATETABLES )
#  undef USAGE_MASK_SET
#  undef USAGE_MASK_UNSET
#  undef USAGE_MASK_ADD
#  undef USAGE_MASK_CLEAR
#  undef USAGE_MASK_CLEARFAIL
# endif
# undef None
#endif

/* --------------------------------------------------------------------------- */
/* Implementation type: Service list                                           */
/* --------------------------------------------------------------------------- */
/* Generate list of all services, referencing the service properties           */
/* --------------------------------------------------------------------------- */
#if ( FBL_DIAG_IMPL_TYPE == FBL_DIAG_IMPL_TYPE_SERVICELIST )
# if defined( None )
#  undef None
# endif
# define None   0xFFFFFFFFu

# define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax)  firstChild
# if (FBL_DIAG_STATE_RESULT != None)
#  undef FBL_DIAG_STATE_DEF
#  define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax) \
   V_MEMROM0 static V_MEMROM1 tServiceList V_MEMROM2 kDiagSubFctTbl_ ## name = \
   { \
      &kDiagServiceProperties[kDiagService ## firstChild] \
      ,(bufPos) \
      ,(sizeof(kDiagSrvId_ ## firstChild)/sizeof(kDiagSrvId_ ## firstChild [0])) \
      ,((kDiagService ## lastChild - kDiagService ## firstChild) + 1) \
   }

FBL_DIAG_STATE_RESULT;
# endif

# undef None
# undef FBL_DIAG_STATE_DEF
#endif

/* --------------------------------------------------------------------------- */
/* Implementation type: Service list handler                                   */
/* --------------------------------------------------------------------------- */
/* Generate list of child node references                                      */
/* --------------------------------------------------------------------------- */
#if ( FBL_DIAG_IMPL_TYPE == FBL_DIAG_IMPL_TYPE_SERVICELIST_HANDLER )
# if defined( None )
#  undef None
# endif
# define None   0xFFFFFFFFu

# define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax)  firstChild
# if (FBL_DIAG_STATE_RESULT != None)
#  undef FBL_DIAG_STATE_DEF
#  define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax)   &kDiagSubFctTbl_ ## name

FBL_DIAG_STATE_RESULT,
# endif

# undef None
# undef FBL_DIAG_STATE_DEF
#endif

/* --------------------------------------------------------------------------- */
/* Implementation type: Service list enumeration                               */
/* --------------------------------------------------------------------------- */
/* Generate list of handles to access service list handlers                    */
/* --------------------------------------------------------------------------- */
#if ( FBL_DIAG_IMPL_TYPE == FBL_DIAG_IMPL_TYPE_SERVICELIST_ENUM )
# if defined( None )
#  undef None
# endif
# define None   0xFFFFFFFFu

# define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax)  firstChild
# if (FBL_DIAG_STATE_RESULT != None)
#  undef FBL_DIAG_STATE_DEF
#  define FBL_DIAG_STATE_DEF(name, parent, firstChild, lastChild, bufPos, id, handler, checks, set, unset, add, clear, clearFail, rqlMin, rqlMax)   kDiagServiceListHandler_ ## name

FBL_DIAG_STATE_RESULT,
# endif

# undef None
# undef FBL_DIAG_STATE_DEF
#endif

/* --------------------------------------------------------------------------- */
/* Reset result define                                                         */
/* --------------------------------------------------------------------------- */
#undef FBL_DIAG_STATE_RESULT

/***********************************************************************************************************************
 *  END OF FILE: FBL_DIAG.IMP
 **********************************************************************************************************************/
