 

/*
 * This is a template file. It defines integration functions necessary to complete RTA-BSW.
 * The integrator must complete the templates before deploying software containing functions defined in this file.
 * Once templates have been completed, the integrator should delete the #error line.
 * Note: The integrator is responsible for updates made to this file.
 *
 * To remove the following error define the macro NOT_READY_FOR_TESTING_OR_DEPLOYMENT with a compiler option (e.g. -D NOT_READY_FOR_TESTING_OR_DEPLOYMENT)
 * The removal of the error only allows the user to proceed with the building phase
 */
/* #ifndef NOT_READY_FOR_TESTING_OR_DEPLOYMENT
#error The content of this file is a template which provides empty stubs. The content of this file must be completed by the integrator accordingly to project specific requirements
#else
#warning The content of this file is a template which provides empty stubs. The content of this file must be completed by the integrator accordingly to project specific requirements
#endif */ /* NOT_READY_FOR_TESTING_OR_DEPLOYMENT */



#ifndef DEM_PRJCHRONOSORTING_H
#define DEM_PRJCHRONOSORTING_H

/**
 * \file
 * \ingroup DEM_PRJ_TPL
 * \brief Retrieval of DTC information in custom order
 *
 * If DemEnableReportingChronologicalOrderHooks is enabled, these functions are use to retrieve the DTC data in
 * chronological order. (Other orders are also possible but chronological is the main use case.)
 */

#include "Dem_Cfg_DTCs.h"

#if (DEM_CFG_REPORT_CHRONOLOGICAL_ORDER_HOOKS_ENABLED)
#include "Dem_DTCFilter.h"

/*****************************************************************/
/*Sanity Check for External processing of DTCFiltermainfunction*/
#if (DEM_CFG_DTCFILTER_EXTERNALPROCESSING == DEM_CFG_DTCFILTER_EXTERNALPROCESSING_ON)
#error Reporting DTCs in Chronological order is not supported along with DTC filter External Processing Enabled(demGeneral.demGeneralRB.demExternalProcessing.demDtcFilter == TRUE).
#endif
/*****************************************************************/
#define DEM_START_SEC_ROM_CODE
#include "Dem_Cfg_MemMap.h"

/**
 * \brief Return whether a filter operation with project-specific sorting is currently running.
 *
 * If it returns FALSE, Dem-internal retrieval code will be called instead of the project-specific functions. Shall
 * return FALSE if there was no successful Dem_PrjChronoSetDTCfilter() after the latest Dem_PrjChronoDTCFilterInit().
 */
Dem_boolean_least Dem_PrjChronoIsSortEnabled(void);

/**
 * \brief Called in Dem_Init() and Dem_SetDTCFilter() to reset the current filter state.
 */
void Dem_PrjChronoDTCFilterInit(void);

/**
 * Not called from Dem. Intended to be called internally from the project-specific code to get a new counter value for
 * the specified event memory which is then used for chronological sorting.
 */
uint32 Dem_PrjChronoGetNewEvMemSortId(uint16_least MemId);

/**
 * \brief Called when the event is reported as failed.
 *
 * Should update the internal time stamp to keep track of the chronological order.
 *
 * \param LocId             Location index of the memory entry where the event is stored.
 * \param MemId             Id of the event memory where the event is stored (primary, secondary or mirror)
 * \param StatusOld         Old value of the status byte in event memory
 * \param StatusNew         New value of the status byte
 * \param[in,out] WriteSts  Indicates whether the event memory location needs to be saved after the method returns. Set
 *                          `*WriteSts |= DEM_EVMEM_WRITEMASK_DATA;` to save the location.
 */
void Dem_PrjChronoEvMemUpdateSortId(uint16_least LocId,uint16_least MemId,uint16_least StatusOld,uint16_least StatusNew,uint16_least *WriteSts);

/**
 * \brief Called in Dem_SetDTCFilter() to set the new filter criteria
 *
 * \param[in] DTCFilter Contains the filter criteria that should be matched.
 * \return              TRUE if the filter was successfully set. If FALSE is returned, the Dem-internal iterators are
 *                      initialized instead.
 */
Dem_boolean_least Dem_PrjChronoSetDTCfilter(Dem_DTCFilterState* DTCFilter);

/**
 * \brief Called in the Dem_DTCFilterMainFunction() in the Dem_Main task.
 *
 * Used to do backgroundprocessing to speed up the response to Dem_PrjChronoGetNextFilteredDTCID().
 *
 * \param DTCFilter  Contains the filter criteria that should be matched.
 */
void Dem_PrjChronoMainFunction(Dem_DTCFilterState* DTCFilter);

/**
 * \brief Called in the Dem_GetNextFilteredDTC* functions to retrieve the next DTC in the custom order
 *
 * \param[out] dtcId      The Dem-internal DTC identifier of the next DTC. Is used to retrieve additional information
 *                        for the DTC (like the fault detection counter or severity)
 * \param[out] DTC        DTC value as returned by `Dem_DtcGetCode(*dtcId)`
 * \param[out] DTCStatus  The UDS status of the next DTC
 * \return                The status of the request:
 *                        - DEM_FILTERED_OK: when the next DTC is successfully returned
 *                        - DEM_FILTERED_NO_MATCHING_DTC: when there is no (more) DTC to return
 *                        - DEM_FILTERED_WRONG_DTCKIND: should not be returned
 *                        - DEM_FILTERED_PENDING: The filter is not yet ready to return the next DTC, but it is still
 *                          processing and there could be another DTC returned in the future
 */
Dem_ReturnGetNextFilteredDTCType Dem_PrjChronoGetNextFilteredDTCID (Dem_DtcIdType* dtcId, uint32* DTC, uint8* DTCStatus);

/**
 * \brief Get the number of DTCs matched by the filter currently active.
 *
 * \param[out] NumberOfFilteredDTC  The total number of DTCs matched by the filter
 * \return                          The status of the request:
 *                                  - DEM_NUMBER_OK: The total number of matched DTCs was returned successfully
 *                                  - DEM_NUMBER_FAILED: The total number of matched DTCs can not be calculated
 *                                  - DEM_NUMBER_PENDING: The total number of matched DTCs is not yet known, but could
 *                                    be known in the future (e.g. after the processing in Dem_PrjChronoMainFunction()
 *                                    is complete)
 */
Dem_ReturnGetNumberOfFilteredDTCType Dem_PrjChronoGetNumberOfFilteredDTC(uint16* NumberOfFilteredDTC);

#define DEM_STOP_SEC_ROM_CODE
#include "Dem_Cfg_MemMap.h"

#endif

#endif /* INCLUDE_PROTECTION */

