1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\r
6 * This source code is free software; you can redistribute it and/or modify it
\r
7 * under the terms of the GNU General Public License version 2 as published by the
\r
8 * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
\r
10 * This program is distributed in the hope that it will be useful, but
\r
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\r
14 * -------------------------------- Arctic Core ------------------------------*/
\r
16 // 904 PC-Lint MISRA 14.7: OK. Allow VALIDATE, VALIDATE_RV and VALIDATE_NO_RV to return value.
\r
17 //lint -emacro(904,VALIDATE_RV,VALIDATE_NO_RV,VALIDATE)
\r
18 // 522 PC-Lint exception for empty functions
\r
19 //lint -esym(522,storeFreezeFrameDataEvtMem)
\r
20 //lint -esym(522,deleteFreezeFrameDataPriMem)
\r
21 //lint -esym(522,storeFreezeFrameDataPreInit)
\r
22 //lint -esym(522,storeFreezeFrameDataPriMem)
\r
23 //lint -esym(522,updateFreezeFrameOccurrencePreInit)
\r
27 * General requirements
\r
30 /** @req DEM151.partially */
\r
32 /** @req DEM013.14229-1 */
\r
35 /** @req DEM113 */ /** @req DEM174 */
\r
49 //#include "SchM_Dem.h"
\r
55 #define DEBOUNCE_FDC_TEST_FAILED 127
\r
56 #define DEBOUNCE_FDC_TEST_PASSED -128
\r
58 #if ( DEM_DEV_ERROR_DETECT == STD_ON )
\r
61 #define VALIDATE_RV(_exp,_api,_err,_rv ) \
\r
63 Det_ReportError(MODULE_ID_DEM, 0, _api, _err); \
\r
67 #define VALIDATE_NO_RV(_exp,_api,_err ) \
\r
69 Det_ReportError(MODULE_ID_DEM, 0, _api, _err); \
\r
72 #define DET_REPORTERROR(_x,_y,_z,_q) Det_ReportError(_x, _y, _z, _q)
\r
75 #define VALIDATE_RV(_exp,_api,_err,_rv )
\r
76 #define VALIDATE_NO_RV(_exp,_api,_err )
\r
77 #define DET_REPORTERROR(_x,_y,_z,_q)
\r
80 #if (DEM_OBD_SUPPORT == STD_ON)
\r
81 #error "DEM_OBD_SUPPORT is set to STD_ON, this is not supported by the code."
\r
84 #if (DEM_PTO_SUPPORT == STD_ON)
\r
85 #error "DEM_PTO_SUPPORT is set to STD_ON, this is not supported by the code."
\r
88 #if (DEM_TYPE_OF_DTC_SUPPORTED != 0x01)
\r
89 #error "DEM_TYPE_OF_DTC_SUPPORTED is not set to 1 (ISO14229-1), only ISO14229-1 is currently supported by the code."
\r
97 typedef uint16 ChecksumType;
\r
101 Dem_EventStatusExtendedType dtcStatusMask;
\r
102 Dem_DTCKindType dtcKind;
\r
103 Dem_DTCOriginType dtcOrigin;
\r
104 Dem_FilterWithSeverityType filterWithSeverity;
\r
105 Dem_DTCSeverityType dtcSeverityMask;
\r
106 Dem_FilterForFDCType filterForFaultDetectionCounter;
\r
110 // DisableDtcStorageType
\r
112 boolean storageDisabled;
\r
113 Dem_DTCGroupType dtcGroup;
\r
114 Dem_DTCKindType dtcKind;
\r
115 } DisableDtcStorageType;
\r
117 // For keeping track of the events status
\r
119 Dem_EventIdType eventId;
\r
120 const Dem_EventParameterType *eventParamRef;
\r
121 sint8 faultDetectionCounter;
\r
122 uint16 occurrence; /** @req DEM011 */
\r
123 Dem_EventStatusExtendedType eventStatusExtended; /** @req DEM006 */
\r
124 boolean errorStatusChanged;
\r
125 } EventStatusRecType;
\r
128 // Types for storing different event data on event memory
\r
130 Dem_EventIdType eventId;
\r
132 ChecksumType checksum;
\r
136 Dem_EventIdType eventId;
\r
139 sint8 data[DEM_MAX_SIZE_FF_DATA];
\r
140 ChecksumType checksum;
\r
141 } FreezeFrameRecType;
\r
144 Dem_EventIdType eventId;
\r
146 uint8 data[DEM_MAX_SIZE_EXT_DATA];
\r
147 ChecksumType checksum;
\r
154 DEM_UNINITIALIZED = 0,
\r
155 DEM_PREINITIALIZED,
\r
157 } Dem_StateType; /** @req DEM169 */
\r
160 static Dem_StateType demState = DEM_UNINITIALIZED;
\r
162 // Help pointer to configuration set
\r
163 static const Dem_ConfigSetType *configSet;
\r
166 * Allocation of DTC filter parameters
\r
168 static DtcFilterType dtcFilter;
\r
171 * Allocation of Disable/Enable DTC storage parameters
\r
173 static DisableDtcStorageType disableDtcStorage;
\r
176 * Allocation of operation cycle state list
\r
178 static Dem_OperationCycleStateType operationCycleStateList[DEM_OPERATION_CYCLE_ID_ENDMARK];
\r
181 * Allocation of local event status buffer
\r
183 static EventStatusRecType eventStatusBuffer[DEM_MAX_NUMBER_EVENT];
\r
186 * Allocation of pre-init event memory (used between pre-init and init)
\r
189 static FreezeFrameRecType preInitFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRE_INIT];
\r
190 static ExtDataRecType preInitExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRE_INIT];
\r
193 * Allocation of primary event memory ramlog (after init) in uninitialized memory
\r
196 static EventRecType priMemEventBuffer[DEM_MAX_NUMBER_EVENT_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
197 static FreezeFrameRecType priMemFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
198 static ExtDataRecType priMemExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
202 * Procedure: zeroPriMemBuffers
\r
203 * Description: Fill the primary buffers with zeroes
\r
205 //lint -e957 PC-Lint exception - Used only by DemTest
\r
206 void demZeroPriMemBuffers(void)
\r
208 memset(priMemEventBuffer, 0, sizeof(priMemEventBuffer));
\r
209 memset(priMemFreezeFrameBuffer, 0, sizeof(priMemFreezeFrameBuffer));
\r
210 memset(priMemExtDataBuffer, 0, sizeof(priMemExtDataBuffer));
\r
215 * Procedure: calcChecksum
\r
216 * Description: Calculate checksum over *data to *(data+nrOfBytes-1) area
\r
218 static ChecksumType calcChecksum(void *data, uint16 nrOfBytes)
\r
221 uint8 *byte = (uint8*)data;
\r
222 ChecksumType sum = 0;
\r
224 for (i = 0; i < nrOfBytes; i++) {
\r
233 * Procedure: checkDtcKind
\r
234 * Description: Return TRUE if "dtcKind" match the events DTCKind or "dtcKind"
\r
235 * is "DEM_DTC_KIND_ALL_DTCS" otherwise FALSE.
\r
237 static boolean checkDtcKind(Dem_DTCKindType dtcKind, const Dem_EventParameterType *eventParam)
\r
239 boolean result = FALSE;
\r
241 if (dtcKind == DEM_DTC_KIND_ALL_DTCS) {
\r
245 if (eventParam->DTCClassRef != NULL) {
\r
246 if (eventParam->DTCClassRef->DTCKind == dtcKind) {
\r
256 * Procedure: checkDtcGroup
\r
257 * Description: Return TRUE if "dtc" match the events DTC or "dtc" is
\r
258 * "DEM_DTC_GROUP_ALL_DTCS" otherwise FALSE.
\r
260 static boolean checkDtcGroup(uint32 dtc, const Dem_EventParameterType *eventParam)
\r
262 boolean result = FALSE;
\r
264 if (dtc == DEM_DTC_GROUP_ALL_DTCS) {
\r
268 if (eventParam->DTCClassRef != NULL) {
\r
269 if (eventParam->DTCClassRef->DTC == dtc) {
\r
279 * Procedure: checkDtcOrigin
\r
280 * Description: Return TRUE if "dtcOrigin" match any of the events DTCOrigin otherwise FALSE.
\r
282 static boolean checkDtcOrigin(Dem_DTCOriginType dtcOrigin, const Dem_EventParameterType *eventParam)
\r
284 boolean result = FALSE;
\r
285 boolean dtcOriginFound = FALSE;
\r
288 for (i = 0;(i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound); i++){
\r
289 dtcOriginFound = (eventParam->EventClass->EventDestination[i] == dtcOrigin);
\r
292 if (dtcOriginFound) {
\r
300 * Procedure: checkDtcSeverityMask
\r
301 * Description: Return TRUE if "dtcSeverityMask" match any of the events DTC severity otherwise FALSE.
\r
303 // PC-Lint (715 etc): Remove errors until function is filled.
\r
304 //lint -e{715} Symbol not referenced
\r
305 static boolean checkDtcSeverityMask(Dem_DTCSeverityType dtcSeverityMask, const Dem_EventParameterType *eventParam)
\r
307 boolean result = TRUE;
\r
309 // TODO: This function is optional, may be implemented here.
\r
316 * Procedure: checkDtcFaultDetectionCounterMask
\r
317 * Description: TBD.
\r
319 // PC-Lint (715 etc): Remove errors until function is filled.
\r
320 //lint -e{715} Symbol not referenced
\r
321 static boolean checkDtcFaultDetectionCounter(const Dem_EventParameterType *eventParam)
\r
323 boolean result = TRUE;
\r
325 // TODO: Not implemented yet.
\r
332 * Procedure: lookupEventStatusRec
\r
333 * Description: Returns the pointer to event id parameters of "eventId" in "*eventStatusBuffer",
\r
334 * if not found NULL is returned.
\r
336 static void lookupEventStatusRec(Dem_EventIdType eventId, EventStatusRecType **const eventStatusRec)
\r
339 boolean eventIdFound = FALSE;
\r
341 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!eventIdFound); i++) {
\r
342 eventIdFound = (eventStatusBuffer[i].eventId == eventId);
\r
345 if (eventIdFound) {
\r
346 *eventStatusRec = &eventStatusBuffer[i-1];
\r
348 *eventStatusRec = NULL;
\r
354 * Procedure: lookupEventIdParameter
\r
355 * Description: Returns the pointer to event id parameters of "eventId" in "*eventIdParam",
\r
356 * if not found NULL is returned.
\r
358 static void lookupEventIdParameter(Dem_EventIdType eventId, const Dem_EventParameterType **const eventIdParam)
\r
360 const Dem_EventParameterType *EventIdParamList = configSet->EventParameter;
\r
362 // Lookup the correct event id parameters
\r
364 while ((EventIdParamList[i].EventID != eventId) && (!EventIdParamList[i].Arc_EOL)) {
\r
368 if (!EventIdParamList[i].Arc_EOL) {
\r
369 *eventIdParam = &EventIdParamList[i];
\r
371 *eventIdParam = NULL;
\r
377 * Procedure: preDebounceNone
\r
378 * Description: Returns the result of the debouncing.
\r
380 static Dem_EventStatusType preDebounceNone(const Dem_EventStatusType reportedStatus, const EventStatusRecType* statusRecord) {
\r
381 Dem_EventStatusType returnCode;
\r
382 (void)statusRecord; // Just to get rid of PC-Lint warnings
\r
384 switch (reportedStatus) {
\r
385 case DEM_EVENT_STATUS_FAILED: /** @req DEM091.NoneFailed */
\r
386 case DEM_EVENT_STATUS_PASSED: /** @req DEM091.NonePassed */
\r
387 // Already debounced, do nothing.
\r
391 // TODO: What to do with PREFAIL and PREPASSED on no debouncing?
\r
392 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_NONE_ID, DEM_E_PARAM_DATA);
\r
396 returnCode = reportedStatus;
\r
402 * Procedure: preDebounceCounterBased
\r
403 * Description: Returns the result of the debouncing.
\r
405 static Dem_EventStatusType preDebounceCounterBased(Dem_EventStatusType reportedStatus, EventStatusRecType* statusRecord) {
\r
406 Dem_EventStatusType returnCode;
\r
407 const Dem_PreDebounceCounterBasedType* pdVars = statusRecord->eventParamRef->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceCounterBased;
\r
409 switch (reportedStatus) {
\r
410 case DEM_EVENT_STATUS_PREFAILED:
\r
411 if (statusRecord->faultDetectionCounter < DEBOUNCE_FDC_TEST_FAILED) {
\r
412 if ((pdVars->JumpUp) && (statusRecord->faultDetectionCounter < 0)) {
\r
413 statusRecord->faultDetectionCounter = 0;
\r
415 if (((sint16)statusRecord->faultDetectionCounter + (sint8)pdVars->CountInStepSize) < DEBOUNCE_FDC_TEST_FAILED) {
\r
416 statusRecord->faultDetectionCounter += (sint8)pdVars->CountInStepSize;
\r
418 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED;
\r
424 case DEM_EVENT_STATUS_PREPASSED:
\r
425 if (statusRecord->faultDetectionCounter > DEBOUNCE_FDC_TEST_PASSED) {
\r
426 if ((pdVars->JumpDown) && (statusRecord->faultDetectionCounter > 0)) {
\r
427 statusRecord->faultDetectionCounter = 0;
\r
429 if (((sint16)statusRecord->faultDetectionCounter - (sint8)pdVars->CountOutStepSize) > DEBOUNCE_FDC_TEST_PASSED) {
\r
430 statusRecord->faultDetectionCounter -= (sint8)pdVars->CountOutStepSize;
\r
432 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED;
\r
438 case DEM_EVENT_STATUS_FAILED:
\r
439 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED; /** @req DEM091.CounterFailed */
\r
442 case DEM_EVENT_STATUS_PASSED:
\r
443 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED; /** @req DEM091.CounterPassed */
\r
447 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_COUNTER_BASED_ID, DEM_E_PARAM_DATA);
\r
452 switch (statusRecord->faultDetectionCounter) {
\r
453 case DEBOUNCE_FDC_TEST_FAILED:
\r
454 returnCode = DEM_EVENT_STATUS_FAILED;
\r
457 case DEBOUNCE_FDC_TEST_PASSED:
\r
458 returnCode = DEM_EVENT_STATUS_PASSED;
\r
462 returnCode = reportedStatus;
\r
471 * Procedure: updateEventStatusRec
\r
472 * Description: Update the status of "eventId", if not exist and "createIfNotExist" is
\r
473 * true a new record is created
\r
475 static void updateEventStatusRec(const Dem_EventParameterType *eventParam, Dem_EventStatusType eventStatus, boolean createIfNotExist, EventStatusRecType *eventStatusRec)
\r
477 EventStatusRecType *eventStatusRecPtr;
\r
482 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
484 if ((eventStatusRecPtr == NULL) && (createIfNotExist)) {
\r
485 // Search for free position
\r
486 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
488 if (eventStatusRecPtr != NULL) {
\r
489 // Create new event record
\r
490 eventStatusRecPtr->eventId = eventParam->EventID;
\r
491 eventStatusRecPtr->eventParamRef = eventParam;
\r
492 eventStatusRecPtr->faultDetectionCounter = 0;
\r
493 eventStatusRecPtr->occurrence = 0;
\r
494 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
495 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
498 // Error: Event status buffer full
\r
499 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
504 if (eventStatusRecPtr != NULL) {
\r
505 // Handle debouncing
\r
506 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
507 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName) { /** @req DEM004 */ /** @req DEM342 */
\r
508 case DEM_NO_PRE_DEBOUNCE:
\r
509 eventStatus = preDebounceNone(eventStatus, eventStatusRecPtr);
\r
512 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
513 eventStatus = preDebounceCounterBased(eventStatus, eventStatusRecPtr);
\r
517 // Don't know how to handle this.
\r
518 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
523 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
525 // Check test failed
\r
526 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
527 if (!(eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED)) {
\r
528 eventStatusRecPtr->occurrence++;
\r
529 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
531 /** @req DEM036 */ /** @req DEM379.PendingSet */
\r
532 eventStatusRecPtr->eventStatusExtended |= (DEM_TEST_FAILED | DEM_TEST_FAILED_THIS_OPERATION_CYCLE | DEM_TEST_FAILED_SINCE_LAST_CLEAR | DEM_PENDING_DTC);
\r
533 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
536 // Check test passed
\r
537 if (eventStatus == DEM_EVENT_STATUS_PASSED) {
\r
538 if (eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED) {
\r
539 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
542 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED;
\r
543 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
547 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
550 // Copy an empty record to return data
\r
551 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
552 eventStatusRec->faultDetectionCounter = 0;
\r
553 eventStatusRec->occurrence = 0;
\r
554 eventStatusRec->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
555 eventStatusRec->errorStatusChanged = FALSE;
\r
558 Irq_Restore(state);
\r
563 * Procedure: mergeEventStatusRec
\r
564 * Description: Update the occurrence counter of status, if not exist a new record is created
\r
566 static void mergeEventStatusRec(const EventRecType *eventRec)
\r
568 EventStatusRecType *eventStatusRecPtr;
\r
573 lookupEventStatusRec(eventRec->eventId, &eventStatusRecPtr);
\r
575 if (eventStatusRecPtr != NULL) {
\r
576 // Update occurrence counter, rest of pre init state is kept.
\r
577 eventStatusRecPtr->occurrence += eventRec->occurrence;
\r
581 // Search for free position
\r
582 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
584 if (eventStatusRecPtr != NULL) {
\r
585 // Create new event, from stored event
\r
586 eventStatusRecPtr->eventId = eventRec->eventId;
\r
587 lookupEventIdParameter(eventRec->eventId, &eventStatusRecPtr->eventParamRef);
\r
588 eventStatusRecPtr->faultDetectionCounter = 0;
\r
589 eventStatusRecPtr->occurrence = eventRec->occurrence;
\r
590 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
591 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
594 // Error: Event status buffer full
\r
595 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_MERGE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
599 Irq_Restore(state);
\r
604 * Procedure: deleteEventStatusRec
\r
605 * Description: Delete the status record of "eventParam->eventId" from "eventStatusBuffer".
\r
607 static void deleteEventStatusRec(const Dem_EventParameterType *eventParam)
\r
609 EventStatusRecType *eventStatusRecPtr;
\r
614 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
616 if (eventStatusRecPtr != NULL) {
\r
617 // Delete event record
\r
618 memset(eventStatusRecPtr, 0, sizeof(EventStatusRecType));
\r
621 Irq_Restore(state);
\r
626 * Procedure: getEventStatusRec
\r
627 * Description: Returns the status record of "eventId" in "eventStatusRec"
\r
629 static void getEventStatusRec(Dem_EventIdType eventId, EventStatusRecType *eventStatusRec)
\r
631 EventStatusRecType *eventStatusRecPtr;
\r
634 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
636 if (eventStatusRecPtr != NULL) {
\r
638 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
641 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
647 * Procedure: lookupDtcEvent
\r
648 * Description: Returns TRUE if the DTC was found and "eventStatusRec" points
\r
649 * to the event record found.
\r
651 static boolean lookupDtcEvent(uint32 dtc, EventStatusRecType **eventStatusRec)
\r
653 boolean dtcFound = FALSE;
\r
656 *eventStatusRec = NULL;
\r
658 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!dtcFound); i++) {
\r
659 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
660 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
663 if (eventStatusBuffer[i].eventParamRef->DTCClassRef->DTC == dtc) {
\r
664 *eventStatusRec = &eventStatusBuffer[i];
\r
676 * Procedure: matchEventWithDtcFilter
\r
677 * Description: Returns TRUE if the event pointed by "event" fulfill
\r
678 * the "dtcFilter" global filter settings.
\r
680 static boolean matchEventWithDtcFilter(const EventStatusRecType *eventRec)
\r
682 boolean dtcMatch = FALSE;
\r
685 if ((dtcFilter.dtcStatusMask == DEM_DTC_STATUS_MASK_ALL) || (eventRec->eventStatusExtended & dtcFilter.dtcStatusMask)) {
\r
686 if (eventRec->eventParamRef != NULL) {
\r
689 if (checkDtcKind(dtcFilter.dtcKind, eventRec->eventParamRef)) {
\r
692 if (checkDtcOrigin(dtcFilter.dtcOrigin, eventRec->eventParamRef)) {
\r
695 if ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
696 || ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES) && (checkDtcSeverityMask(dtcFilter.dtcSeverityMask, eventRec->eventParamRef)))) {
\r
698 // Check fault detection counter
\r
699 if ((dtcFilter.filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO)
\r
700 || ((dtcFilter.filterWithSeverity == DEM_FILTER_FOR_FDC_YES) && (checkDtcFaultDetectionCounter(eventRec->eventParamRef)))) {
\r
713 // PC-Lint (715 etc): Remove errors until function is filled.
\r
714 //lint -e{715} Symbol not referenced
\r
715 static void getFreezeFrameData(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
718 freezeFrame->eventId = DEM_EVENT_ID_NULL; // Not supported yet
\r
722 // PC-Lint (715 etc): Remove errors until function is filled.
\r
723 //lint -e{715} Symbol not referenced
\r
724 static void storeFreezeFrameDataPreInit(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
730 // PC-Lint (715 etc): Remove errors until function is filled.
\r
731 //lint -e{715} Symbol not referenced
\r
732 static void updateFreezeFrameOccurrencePreInit(const EventRecType *EventBuffer)
\r
739 * Procedure: getExtendedData
\r
740 * Description: Collects the extended data according to "eventParam" and return it in "extData",
\r
741 * if not found eventId is set to DEM_EVENT_ID_NULL.
\r
743 static void getExtendedData(const Dem_EventParameterType *eventParam, ExtDataRecType *extData)
\r
745 Std_ReturnType callbackReturnCode;
\r
747 uint16 storeIndex = 0;
\r
750 // Clear ext data record
\r
751 memset(extData, 0, sizeof(ExtDataRecType));
\r
753 // Check if any pointer to extended data class
\r
754 if (eventParam->ExtendedDataClassRef != NULL) {
\r
755 // Request extended data and copy it to the buffer
\r
756 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL); i++) {
\r
757 recordSize = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
758 if ((storeIndex + recordSize) <= DEM_MAX_SIZE_EXT_DATA) {
\r
759 callbackReturnCode = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->CallbackGetExtDataRecord(&extData->data[storeIndex]); /** @req DEM282 */
\r
760 if (callbackReturnCode != E_OK) {
\r
761 // Callback data currently not available, clear space.
\r
762 memset(&extData->data[storeIndex], 0xFF, recordSize);
\r
764 storeIndex += recordSize;
\r
767 // Error: Size of extended data record is bigger than reserved space.
\r
768 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GET_EXTENDED_DATA_ID, DEM_E_EXT_DATA_TOO_BIG);
\r
769 break; // Break the loop
\r
774 // Check if any data has been stored
\r
775 if (storeIndex != 0) {
\r
776 extData->eventId = eventParam->EventID;
\r
777 extData->dataSize = storeIndex;
\r
778 extData->checksum = calcChecksum(extData, sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
781 extData->eventId = DEM_EVENT_ID_NULL;
\r
782 extData->dataSize = storeIndex;
\r
783 extData->checksum = 0;
\r
789 * Procedure: storeExtendedDataPreInit
\r
790 * Description: Store the extended data pointed by "extendedData" to the "preInitExtDataBuffer",
\r
791 * if non existent a new entry is created.
\r
793 static void storeExtendedDataPreInit(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
795 boolean eventIdFound = FALSE;
\r
796 boolean eventIdFreePositionFound=FALSE;
\r
801 // Check if already stored
\r
802 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) && (!eventIdFound); i++){
\r
803 eventIdFound = (preInitExtDataBuffer[i].eventId == eventParam->EventID);
\r
807 // Yes, overwrite existing
\r
808 memcpy(&preInitExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
811 // No, lookup first free position
\r
812 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) && (!eventIdFreePositionFound); i++){
\r
813 if(preInitExtDataBuffer[i].eventId ==0){
\r
814 eventIdFreePositionFound=TRUE;
\r
818 if (eventIdFreePositionFound) {
\r
819 memcpy(&preInitExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
822 // Error: Pre init extended data buffer full
\r
823 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRE_INIT_ID, DEM_E_PRE_INIT_EXT_DATA_BUFF_FULL);
\r
827 Irq_Restore(state);
\r
831 * Procedure: storeEventPriMem
\r
832 * Description: Store the event data of "eventStatus->eventId" in "priMemEventBuffer",
\r
833 * if non existent a new entry is created.
\r
835 static void storeEventPriMem(const Dem_EventParameterType *eventParam, const EventStatusRecType *eventStatus)
\r
837 boolean eventIdFound = FALSE;
\r
838 boolean eventIdFreePositionFound=FALSE;
\r
843 (void)*eventParam; // Currently not used, do this to avoid warning
\r
846 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
847 eventIdFound = (priMemEventBuffer[i].eventId == eventStatus->eventId);
\r
850 if (eventIdFound) {
\r
851 // Update event found
\r
852 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
853 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
856 // Search for free position
\r
857 for (i=0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFreePositionFound); i++){
\r
858 eventIdFreePositionFound = (priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
862 if (eventIdFreePositionFound) {
\r
863 priMemEventBuffer[i-1].eventId = eventStatus->eventId;
\r
864 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
865 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
868 // Error: Pri mem event buffer full
\r
869 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EVENT_PRI_MEM_ID, DEM_E_PRI_MEM_EVENT_BUFF_FULL);
\r
873 Irq_Restore(state);
\r
877 * Procedure: deleteEventPriMem
\r
878 * Description: Delete the event data of "eventParam->eventId" from "priMemEventBuffer".
\r
880 static void deleteEventPriMem(const Dem_EventParameterType *eventParam)
\r
882 boolean eventIdFound = FALSE;
\r
889 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
890 eventIdFound = (priMemEventBuffer[i].eventId == eventParam->EventID);
\r
893 if (eventIdFound) {
\r
894 // Delete event found
\r
895 memset(&priMemEventBuffer[i-1], 0, sizeof(EventRecType));
\r
898 Irq_Restore(state);
\r
902 * Procedure: storeEventEvtMem
\r
903 * Description: Store the event data of "eventStatus->eventId" in event memory according to
\r
904 * "eventParam" destination option.
\r
906 static void storeEventEvtMem(const Dem_EventParameterType *eventParam, const EventStatusRecType *eventStatus)
\r
910 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION)
\r
911 && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
912 switch (eventParam->EventClass->EventDestination[i])
\r
914 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
915 storeEventPriMem(eventParam, eventStatus); /** @req DEM010 */
\r
918 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
919 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
920 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
921 // Not yet supported
\r
922 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
932 * Procedure: storeExtendedDataPriMem
\r
933 * Description: Store the extended data pointed by "extendedData" to the "priMemExtDataBuffer",
\r
934 * if non existent a new entry is created.
\r
936 static void storeExtendedDataPriMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData) /** @req DEM041 */
\r
938 boolean eventIdFound = FALSE;
\r
939 boolean eventIdFreePositionFound=FALSE;
\r
944 // Check if already stored
\r
945 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
946 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
949 if (eventIdFound) {
\r
950 // Yes, overwrite existing
\r
951 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
954 // No, lookup first free position
\r
955 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFreePositionFound); i++){
\r
956 eventIdFreePositionFound = (priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
958 if (eventIdFreePositionFound) {
\r
959 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
962 // Error: Pri mem extended data buffer full
\r
963 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRI_MEM_ID, DEM_E_PRI_MEM_EXT_DATA_BUFF_FULL);
\r
967 Irq_Restore(state);
\r
971 * Procedure: deleteExtendedDataPriMem
\r
972 * Description: Delete the extended data of "eventParam->eventId" from "priMemExtDataBuffer".
\r
974 static void deleteExtendedDataPriMem(const Dem_EventParameterType *eventParam)
\r
976 boolean eventIdFound = FALSE;
\r
981 // Check if already stored
\r
982 for (i = 0;(i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
983 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
986 if (eventIdFound) {
\r
987 // Yes, clear record
\r
988 memset(&priMemExtDataBuffer[i-1], 0, sizeof(ExtDataRecType));
\r
991 Irq_Restore(state);
\r
995 * Procedure: storeExtendedDataEvtMem
\r
996 * Description: Store the extended data in event memory according to
\r
997 * "eventParam" destination option
\r
999 static void storeExtendedDataEvtMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
1003 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
1004 switch (eventParam->EventClass->EventDestination[i])
\r
1006 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1007 storeExtendedDataPriMem(eventParam, extendedData);
\r
1010 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1011 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1012 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1013 // Not yet supported
\r
1014 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1025 * Procedure: lookupExtendedDataRecNumParam
\r
1026 * Description: Returns TRUE if the requested extended data number was found among the configured records for the event.
\r
1027 * "extDataRecClassPtr" returns a pointer to the record class, "posInExtData" returns the position in stored extended data.
\r
1029 static boolean lookupExtendedDataRecNumParam(uint8 extendedDataNumber, const Dem_EventParameterType *eventParam, Dem_ExtendedDataRecordClassType const **extDataRecClassPtr, uint16 *posInExtData)
\r
1031 boolean recNumFound = FALSE;
\r
1033 if (eventParam->ExtendedDataClassRef != NULL) {
\r
1034 uint16 byteCnt = 0;
\r
1037 // Request extended data and copy it to the buffer
\r
1038 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL) && (!recNumFound); i++) {
\r
1039 if (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->RecordNumber == extendedDataNumber) {
\r
1040 *extDataRecClassPtr = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i];
\r
1041 *posInExtData = byteCnt;
\r
1042 recNumFound = TRUE;
\r
1044 byteCnt += eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
1048 return recNumFound;
\r
1053 * Procedure: lookupExtendedDataPriMem
\r
1054 * Description: Returns TRUE if the requested event id is found, "extData" points to the found data.
\r
1056 static boolean lookupExtendedDataPriMem(Dem_EventIdType eventId, ExtDataRecType **extData)
\r
1058 boolean eventIdFound = FALSE;
\r
1061 // Lookup corresponding extended data
\r
1062 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++) {
\r
1063 eventIdFound = (priMemExtDataBuffer[i].eventId == eventId);
\r
1066 if (eventIdFound) {
\r
1067 // Yes, return pointer
\r
1068 *extData = &priMemExtDataBuffer[i-1];
\r
1071 return eventIdFound;
\r
1074 // PC-Lint (715 etc): Remove errors until function is filled.
\r
1075 //lint -e{715} Symbol not referenced
\r
1076 static void storeFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1082 // PC-Lint (715 etc): Remove errors until function is filled.
\r
1083 //lint -e{715} Symbol not referenced
\r
1084 static void deleteFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam)
\r
1091 * Procedure: storeFreezeFrameDataEvtMem
\r
1092 * Description: Store the freeze frame data in event memory according to
\r
1093 * "eventParam" destination option
\r
1095 static void storeFreezeFrameDataEvtMem(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1099 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
1100 switch (eventParam->EventClass->EventDestination[i])
\r
1102 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1103 storeFreezeFrameDataPriMem(eventParam, freezeFrame);
\r
1106 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1107 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1108 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1109 // Not yet supported
\r
1110 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1121 * Procedure: handlePreInitEvent
\r
1122 * Description: Handle the updating of event status and storing of
\r
1123 * event related data in preInit buffers.
\r
1125 static void handlePreInitEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1127 const Dem_EventParameterType *eventParam;
\r
1128 EventStatusRecType eventStatusLocal;
\r
1129 FreezeFrameRecType freezeFrameLocal;
\r
1130 ExtDataRecType extendedDataLocal;
\r
1132 // Find configuration for this event
\r
1133 lookupEventIdParameter(eventId, &eventParam);
\r
1134 if (eventParam != NULL) {
\r
1135 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1136 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1137 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
1138 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1141 updateEventStatusRec(eventParam, eventStatus, FALSE, &eventStatusLocal);
\r
1144 if (eventStatusLocal.errorStatusChanged) {
\r
1146 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1147 // Collect freeze frame data
\r
1148 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1149 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1150 storeFreezeFrameDataPreInit(eventParam, &freezeFrameLocal);
\r
1153 // Collect extended data
\r
1154 getExtendedData(eventParam, &extendedDataLocal);
\r
1155 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1156 storeExtendedDataPreInit(eventParam, &extendedDataLocal);
\r
1162 // Operation cycle not started
\r
1163 // TODO: Report error?
\r
1167 // Operation cycle not set
\r
1168 // TODO: Report error?
\r
1172 // Event ID not configured
\r
1173 // TODO: Report error?
\r
1179 * Procedure: handleEvent
\r
1180 * Description: Handle the updating of event status and storing of
\r
1181 * event related data in event memory.
\r
1183 static Std_ReturnType handleEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1185 Std_ReturnType returnCode = E_OK;
\r
1186 const Dem_EventParameterType *eventParam;
\r
1187 EventStatusRecType eventStatusLocal;
\r
1188 FreezeFrameRecType freezeFrameLocal;
\r
1189 ExtDataRecType extendedDataLocal;
\r
1191 // Find configuration for this event
\r
1192 lookupEventIdParameter(eventId, &eventParam);
\r
1193 if (eventParam != NULL) {
\r
1194 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1195 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1196 if ((!((disableDtcStorage.storageDisabled) && (checkDtcGroup(disableDtcStorage.dtcGroup, eventParam)) && (checkDtcKind(disableDtcStorage.dtcKind, eventParam))))) {
\r
1197 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1198 if (eventStatusLocal.errorStatusChanged) {
\r
1199 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1200 storeEventEvtMem(eventParam, &eventStatusLocal); /** @req DEM184 */
\r
1201 // Collect freeze frame data
\r
1202 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1203 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1204 storeFreezeFrameDataEvtMem(eventParam, &freezeFrameLocal); /** @req DEM190 */
\r
1207 // Collect extended data
\r
1208 getExtendedData(eventParam, &extendedDataLocal);
\r
1209 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL)
\r
1211 storeExtendedDataEvtMem(eventParam, &extendedDataLocal);
\r
1218 // Operation cycle not started
\r
1219 returnCode = E_NOT_OK;
\r
1223 // Operation cycle not set
\r
1224 returnCode = E_NOT_OK;
\r
1228 // Event ID not configured
\r
1229 returnCode = E_NOT_OK;
\r
1232 return returnCode;
\r
1237 * Procedure: resetEventStatus
\r
1238 * Description: Resets the events status of eventId.
\r
1240 static void resetEventStatus(Dem_EventIdType eventId)
\r
1242 EventStatusRecType *eventStatusRecPtr;
\r
1246 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
1247 if (eventStatusRecPtr != NULL) {
\r
1248 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED; /** @req DEM187 */
\r
1251 Irq_Restore(state);
\r
1256 * Procedure: getEventStatus
\r
1257 * Description: Returns the extended event status bitmask of eventId in "eventStatusExtended".
\r
1259 static void getEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended)
\r
1261 EventStatusRecType eventStatusLocal;
\r
1263 // Get recorded status
\r
1264 getEventStatusRec(eventId, &eventStatusLocal);
\r
1265 if (eventStatusLocal.eventId == eventId) {
\r
1266 *eventStatusExtended = eventStatusLocal.eventStatusExtended; /** @req DEM051 */
\r
1269 // Event Id not found, no report received.
\r
1270 *eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1276 * Procedure: getEventFailed
\r
1277 * Description: Returns the TRUE or FALSE of "eventId" in "eventFailed" depending on current status.
\r
1279 static void getEventFailed(Dem_EventIdType eventId, boolean *eventFailed)
\r
1281 EventStatusRecType eventStatusLocal;
\r
1283 // Get recorded status
\r
1284 getEventStatusRec(eventId, &eventStatusLocal);
\r
1285 if (eventStatusLocal.eventId == eventId) {
\r
1286 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) { /** @req DEM052 */
\r
1287 *eventFailed = TRUE;
\r
1290 *eventFailed = FALSE;
\r
1294 // Event Id not found, assume ok.
\r
1295 *eventFailed = FALSE;
\r
1301 * Procedure: getEventTested
\r
1302 * Description: Returns the TRUE or FALSE of "eventId" in "eventTested" depending on
\r
1303 * current status the "test not completed this operation cycle" bit.
\r
1305 static void getEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1307 EventStatusRecType eventStatusLocal;
\r
1309 // Get recorded status
\r
1310 getEventStatusRec(eventId, &eventStatusLocal);
\r
1311 if (eventStatusLocal.eventId == eventId) {
\r
1312 if ( !(eventStatusLocal.eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE)) { /** @req DEM053 */
\r
1313 *eventTested = TRUE;
\r
1316 *eventTested = FALSE;
\r
1320 // Event Id not found, not tested.
\r
1321 *eventTested = FALSE;
\r
1327 * Procedure: getFaultDetectionCounter
\r
1328 * Description: Returns pre debounce counter of "eventId" in "counter" and return value E_OK if
\r
1329 * the counter was available else E_NOT_OK.
\r
1331 static Std_ReturnType getFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1333 Std_ReturnType returnCode = E_NOT_OK;
\r
1334 const Dem_EventParameterType *eventParam;
\r
1336 lookupEventIdParameter(eventId, &eventParam);
\r
1337 if (eventParam != NULL) {
\r
1338 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
1339 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName)
\r
1341 case DEM_NO_PRE_DEBOUNCE:
\r
1342 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal != NULL) {
\r
1343 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc != NULL) {
\r
1344 returnCode = eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc(counter); /** @req DEM204.None */ /** @req DEM264 */ /** @req DEM265 */
\r
1349 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
1351 EventStatusRecType *eventStatusRec;
\r
1353 lookupEventStatusRec(eventId, &eventStatusRec);
\r
1354 if (eventStatusRec != NULL) {
\r
1355 *counter = eventStatusRec->faultDetectionCounter; /** @req DEM204.Counter */
\r
1359 returnCode = E_OK;
\r
1363 case DEM_PRE_DEBOUNCE_FREQUENCY_BASED:
\r
1364 case DEM_PRE_DEBOUNCE_TIME_BASED:
\r
1365 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1369 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_PARAM_DATA);
\r
1375 return returnCode;
\r
1380 * Procedure: setOperationCycleState
\r
1381 * Description: Change the operation state of "operationCycleId" to "cycleState" and updates stored
\r
1382 * event connected to this cycle id.
\r
1383 * Returns E_OK if operation was successful else E_NOT_OK.
\r
1385 static Std_ReturnType setOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState) /** @req DEM338 */
\r
1388 Std_ReturnType returnCode = E_OK;
\r
1390 if (operationCycleId < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1391 switch (cycleState)
\r
1393 case DEM_CYCLE_STATE_START:
\r
1394 operationCycleStateList[operationCycleId] = cycleState;
\r
1395 // Lookup event ID
\r
1396 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1397 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1398 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED_THIS_OPERATION_CYCLE;
\r
1399 eventStatusBuffer[i].eventStatusExtended |= DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
1404 case DEM_CYCLE_STATE_END:
\r
1405 operationCycleStateList[operationCycleId] = cycleState;
\r
1406 // Lookup event ID
\r
1407 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1408 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1409 if ((!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_FAILED_THIS_OPERATION_CYCLE)) && (!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE))) {
\r
1410 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_PENDING_DTC; // Clear pendingDTC bit /** @req DEM379.PendingClear
\r
1416 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
1417 returnCode = E_NOT_OK;
\r
1422 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
1423 returnCode = E_NOT_OK;
\r
1426 return returnCode;
\r
1430 //==============================================================================//
\r
1432 // E X T E R N A L F U N C T I O N S //
\r
1434 //==============================================================================//
\r
1436 /*********************************************
\r
1437 * Interface for upper layer modules (8.3.1) *
\r
1438 *********************************************/
\r
1441 * Procedure: Dem_GetVersionInfo
\r
1444 // Defined in Dem.h
\r
1447 /***********************************************
\r
1448 * Interface ECU State Manager <-> DEM (8.3.2) *
\r
1449 ***********************************************/
\r
1452 * Procedure: Dem_PreInit
\r
1455 void Dem_PreInit(void)
\r
1457 /** @req DEM180 */
\r
1460 VALIDATE_NO_RV(DEM_Config.ConfigSet != NULL, DEM_PREINIT_ID, DEM_E_CONFIG_PTR_INVALID);
\r
1462 configSet = DEM_Config.ConfigSet;
\r
1464 // Initializion of operation cycle states.
\r
1465 for (i = 0; i < DEM_OPERATION_CYCLE_ID_ENDMARK; i++) {
\r
1466 operationCycleStateList[i] = DEM_CYCLE_STATE_END;
\r
1469 // Initialize the event status buffer
\r
1470 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1471 eventStatusBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1472 eventStatusBuffer[i].eventParamRef = NULL;
\r
1473 eventStatusBuffer[i].faultDetectionCounter = 0;
\r
1474 eventStatusBuffer[i].occurrence = 0;
\r
1475 eventStatusBuffer[i].eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1476 eventStatusBuffer[i].errorStatusChanged = FALSE;
\r
1479 // Initialize the pre init buffers
\r
1480 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1481 preInitFreezeFrameBuffer[i].checksum = 0;
\r
1482 preInitFreezeFrameBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1483 preInitFreezeFrameBuffer[i].occurrence = 0;
\r
1484 preInitFreezeFrameBuffer[i].dataSize = 0;
\r
1485 for (j = 0; j < DEM_MAX_SIZE_FF_DATA;j++){
\r
1486 preInitFreezeFrameBuffer[i].data[j] = 0;
\r
1490 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1491 preInitExtDataBuffer[i].checksum = 0;
\r
1492 preInitExtDataBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1493 preInitExtDataBuffer[i].dataSize = 0;
\r
1494 for (j = 0; j < DEM_MAX_SIZE_EXT_DATA;j++){
\r
1495 preInitExtDataBuffer[i].data[j] = 0;
\r
1499 disableDtcStorage.storageDisabled = FALSE;
\r
1501 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_START); /** @req DEM047 */
\r
1503 demState = DEM_PREINITIALIZED;
\r
1508 * Procedure: Dem_Init
\r
1511 void Dem_Init(void)
\r
1514 ChecksumType cSum;
\r
1515 const Dem_EventParameterType *eventParam;
\r
1518 * Validate and read out saved error log from non volatile memory
\r
1521 // Validate event records stored in primary memory
\r
1522 for (i = 0; i < DEM_MAX_NUMBER_EVENT_PRI_MEM; i++) {
\r
1523 cSum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
1524 if ((cSum != priMemEventBuffer[i].checksum) || (priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1525 // Unlegal record, clear the record
\r
1526 memset(&priMemEventBuffer[i], 0, sizeof(EventRecType));
\r
1529 // Valid, update current status
\r
1530 mergeEventStatusRec(&priMemEventBuffer[i]);
\r
1532 // Update occurrence counter on pre init stored freeze frames
\r
1533 updateFreezeFrameOccurrencePreInit(&priMemEventBuffer[i]);
\r
1537 // Validate extended data records stored in primary memory
\r
1538 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM; i++) {
\r
1539 cSum = calcChecksum(&priMemExtDataBuffer[i], sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
1540 if ((cSum != priMemExtDataBuffer[i].checksum) || (priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1541 // Unlegal record, clear the record
\r
1542 memset(&priMemExtDataBuffer[i], 0, sizeof(ExtDataRecType));
\r
1546 // Validate freeze frame records stored in primary memory
\r
1547 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++) {
\r
1548 cSum = calcChecksum(&priMemFreezeFrameBuffer[i], sizeof(FreezeFrameRecType)-sizeof(ChecksumType));
\r
1549 if ((cSum != priMemFreezeFrameBuffer[i].checksum) || (priMemFreezeFrameBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1550 // Unlegal record, clear the record
\r
1551 memset(&priMemFreezeFrameBuffer[i], 0, sizeof(FreezeFrameRecType));
\r
1556 * Handle errors stored in temporary buffer (if any)
\r
1559 // Transfer updated event data to event memory
\r
1560 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1561 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1562 // Update the event memory
\r
1563 lookupEventIdParameter(eventStatusBuffer[i].eventId, &eventParam);
\r
1564 storeEventEvtMem(eventParam, &eventStatusBuffer[i]);
\r
1568 // Transfer extended data to event memory if necessary
\r
1569 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1570 if (preInitExtDataBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1571 lookupEventIdParameter(preInitExtDataBuffer[i].eventId, &eventParam);
\r
1572 storeExtendedDataEvtMem(eventParam, &preInitExtDataBuffer[i]);
\r
1576 // Transfer freeze frames to event memory
\r
1577 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1578 if (preInitFreezeFrameBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1579 lookupEventIdParameter(preInitFreezeFrameBuffer[i].eventId, &eventParam);
\r
1580 storeFreezeFrameDataEvtMem(eventParam, &preInitFreezeFrameBuffer[i]);
\r
1584 // Init the dtc filter
\r
1585 dtcFilter.dtcStatusMask = DEM_DTC_STATUS_MASK_ALL; // All allowed
\r
1586 dtcFilter.dtcKind = DEM_DTC_KIND_ALL_DTCS; // All kinds of DTCs
\r
1587 dtcFilter.dtcOrigin = DEM_DTC_ORIGIN_PRIMARY_MEMORY; // Primary memory
\r
1588 dtcFilter.filterWithSeverity = DEM_FILTER_WITH_SEVERITY_NO; // No Severity filtering
\r
1589 dtcFilter.dtcSeverityMask = DEM_SEVERITY_NO_SEVERITY; // Not used when filterWithSeverity is FALSE
\r
1590 dtcFilter.filterForFaultDetectionCounter = DEM_FILTER_FOR_FDC_NO; // No fault detection counter filtering
\r
1592 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1594 disableDtcStorage.storageDisabled = FALSE;
\r
1596 demState = DEM_INITIALIZED;
\r
1601 * Procedure: Dem_shutdown
\r
1604 void Dem_Shutdown(void)
\r
1606 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_END); /** @req DEM047 */
\r
1608 demState = DEM_UNINITIALIZED; /** @req DEM368 */
\r
1613 * Interface for basic software scheduler
\r
1615 void Dem_MainFunction(void)
\r
1617 /** @req DEM125 */
\r
1622 /***************************************************
\r
1623 * Interface SW-Components via RTE <-> DEM (8.3.3) *
\r
1624 ***************************************************/
\r
1627 * Procedure: Dem_SetEventStatus
\r
1630 Std_ReturnType Dem_SetEventStatus(Dem_EventIdType eventId, Dem_EventStatusType eventStatus) /** @req DEM330 */
\r
1632 Std_ReturnType returnCode = E_OK;
\r
1634 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1636 returnCode = handleEvent(eventId, eventStatus);
\r
1640 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1641 returnCode = E_NOT_OK;
\r
1644 return returnCode;
\r
1649 * Procedure: Dem_ResetEventStatus
\r
1652 Std_ReturnType Dem_ResetEventStatus(Dem_EventIdType eventId) /** @req DEM331 */
\r
1654 Std_ReturnType returnCode = E_OK;
\r
1656 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1658 resetEventStatus(eventId); /** @req DEM186 */
\r
1662 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_RESETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1663 returnCode = E_NOT_OK;
\r
1666 return returnCode;
\r
1671 * Procedure: Dem_GetEventStatus
\r
1674 Std_ReturnType Dem_GetEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended) /** @req DEM332 */
\r
1676 Std_ReturnType returnCode = E_OK;
\r
1678 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1680 getEventStatus(eventId, eventStatusExtended);
\r
1684 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1685 returnCode = E_NOT_OK;
\r
1688 return returnCode;
\r
1693 * Procedure: Dem_GetEventFailed
\r
1696 Std_ReturnType Dem_GetEventFailed(Dem_EventIdType eventId, boolean *eventFailed) /** @req DEM333 */
\r
1698 Std_ReturnType returnCode = E_OK;
\r
1700 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1702 getEventFailed(eventId, eventFailed);
\r
1706 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTFAILED_ID, DEM_E_UNINIT);
\r
1707 returnCode = E_NOT_OK;
\r
1710 return returnCode;
\r
1715 * Procedure: Dem_GetEventTested
\r
1718 Std_ReturnType Dem_GetEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1720 Std_ReturnType returnCode = E_OK;
\r
1722 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1724 getEventTested(eventId, eventTested);
\r
1728 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTTESTED_ID, DEM_E_UNINIT);
\r
1729 returnCode = E_NOT_OK;
\r
1732 return returnCode;
\r
1737 * Procedure: Dem_GetFaultDetectionCounter
\r
1740 Std_ReturnType Dem_GetFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1742 Std_ReturnType returnCode = E_OK;
\r
1744 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1746 returnCode = getFaultDetectionCounter(eventId, counter);
\r
1750 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_UNINIT);
\r
1751 returnCode = E_NOT_OK;
\r
1754 return returnCode;
\r
1759 * Procedure: Dem_SetOperationCycleState
\r
1762 Std_ReturnType Dem_SetOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState)
\r
1764 Std_ReturnType returnCode = E_OK;
\r
1766 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1768 returnCode = setOperationCycleState(operationCycleId, cycleState);
\r
1773 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_UNINIT);
\r
1774 returnCode = E_NOT_OK;
\r
1777 return returnCode;
\r
1782 * Procedure: Dem_GetDTCOfEvent
\r
1785 Std_ReturnType Dem_GetDTCOfEvent(Dem_EventIdType eventId, Dem_DTCKindType dtcKind, uint32* dtcOfEvent)
\r
1787 Std_ReturnType returnCode = E_NO_DTC_AVAILABLE;
\r
1788 const Dem_EventParameterType *eventParam;
\r
1790 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1792 lookupEventIdParameter(eventId, &eventParam);
\r
1794 if (eventParam != NULL) {
\r
1795 if (checkDtcKind(dtcKind, eventParam)) {
\r
1796 if (eventParam->DTCClassRef != NULL) {
\r
1797 *dtcOfEvent = eventParam->DTCClassRef->DTC; /** @req DEM269 */
\r
1798 returnCode = E_OK;
\r
1803 // Event Id not found
\r
1804 returnCode = E_NOT_OK;
\r
1809 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETDTCOFEVENT_ID, DEM_UNINITIALIZED);
\r
1810 returnCode = E_NOT_OK;
\r
1813 return returnCode;
\r
1817 /********************************************
\r
1818 * Interface BSW-Components <-> DEM (8.3.4) *
\r
1819 ********************************************/
\r
1822 * Procedure: Dem_ReportErrorStatus
\r
1825 void Dem_ReportErrorStatus( Dem_EventIdType eventId, Dem_EventStatusType eventStatus ) /** @req DEM107 */
\r
1828 switch (demState) {
\r
1829 case DEM_PREINITIALIZED:
\r
1830 // Update status and check if is to be stored
\r
1831 if ((eventStatus == DEM_EVENT_STATUS_PASSED) || (eventStatus == DEM_EVENT_STATUS_FAILED)) {
\r
1832 handlePreInitEvent(eventId, eventStatus); /** @req DEM168 */
\r
1836 case DEM_INITIALIZED:
\r
1837 (void)handleEvent(eventId, eventStatus); /** @req DEM167 */
\r
1840 case DEM_UNINITIALIZED:
\r
1842 // Uninitialized can not do anything
\r
1843 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_REPORTERRORSTATUS_ID, DEM_E_UNINIT);
\r
1847 } // switch (demState)
\r
1850 /*********************************
\r
1851 * Interface DCM <-> DEM (8.3.5) *
\r
1852 *********************************/
\r
1854 * Procedure: Dem_GetDTCStatusAvailabilityMask
\r
1857 Std_ReturnType Dem_GetDTCStatusAvailabilityMask(uint8 *dtcStatusMask) /** @req DEM014 */
\r
1859 *dtcStatusMask = DEM_DTC_STATUS_AVAILABILITY_MASK; // User configuration mask
\r
1860 *dtcStatusMask &= DEM_TEST_FAILED // Mask with supported bits /** @req DEM060 */
\r
1861 | DEM_TEST_FAILED_THIS_OPERATION_CYCLE
\r
1863 // | DEM_CONFIRMED_DTC TODO: Add support for this bit
\r
1864 | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR
\r
1865 | DEM_TEST_FAILED_SINCE_LAST_CLEAR
\r
1866 | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE
\r
1867 // | DEM_WARNING_INDICATOR_REQUESTED TODO: Add support for this bit
\r
1875 * Procedure: Dem_SetDTCFilter
\r
1878 Dem_ReturnSetDTCFilterType Dem_SetDTCFilter(uint8 dtcStatusMask,
\r
1879 Dem_DTCKindType dtcKind,
\r
1880 Dem_DTCOriginType dtcOrigin,
\r
1881 Dem_FilterWithSeverityType filterWithSeverity,
\r
1882 Dem_DTCSeverityType dtcSeverityMask,
\r
1883 Dem_FilterForFDCType filterForFaultDetectionCounter)
\r
1885 Dem_ReturnSetDTCFilterType returnCode = DEM_FILTER_ACCEPTED;
\r
1887 if (demState == DEM_INITIALIZED) {
\r
1888 // Check dtcKind parameter
\r
1889 VALIDATE_RV((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS), DEM_SETDTCFILTER_ID, DEM_E_PARAM_DATA, DEM_WRONG_FILTER);
\r
1891 // Check dtcOrigin parameter
\r
1892 VALIDATE_RV((dtcOrigin == DEM_DTC_ORIGIN_SECONDARY_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_PRIMARY_MEMORY)
\r
1893 || (dtcOrigin == DEM_DTC_ORIGIN_PERMANENT_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_MIRROR_MEMORY), DEM_SETDTCFILTER_ID, DEM_E_PARAM_DATA, DEM_WRONG_FILTER);
\r
1895 // Check filterWithSeverity and dtcSeverityMask parameter
\r
1896 VALIDATE_RV(((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
1897 || ((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES)
\r
1898 && (!(dtcSeverityMask & (Dem_DTCSeverityType)~(DEM_SEVERITY_MAINTENANCE_ONLY | DEM_SEVERITY_CHECK_AT_NEXT_FALT | DEM_SEVERITY_CHECK_IMMEDIATELY))))), DEM_SETDTCFILTER_ID, DEM_E_PARAM_DATA, DEM_WRONG_FILTER);
\r
1900 // Check filterForFaultDetectionCounter parameter
\r
1901 VALIDATE_RV((filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_YES) || (filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO), DEM_SETDTCFILTER_ID, DEM_E_PARAM_DATA, DEM_WRONG_FILTER);
\r
1903 // Yes all parameters correct, set the new filters. /** @req DEM057 */
\r
1904 dtcFilter.dtcStatusMask = dtcStatusMask;
\r
1905 dtcFilter.dtcKind = dtcKind;
\r
1906 dtcFilter.dtcOrigin = dtcOrigin;
\r
1907 dtcFilter.filterWithSeverity = filterWithSeverity;
\r
1908 dtcFilter.dtcSeverityMask = dtcSeverityMask;
\r
1909 dtcFilter.filterForFaultDetectionCounter = filterForFaultDetectionCounter;
\r
1910 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1912 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETDTCFILTER_ID, DEM_E_UNINIT);
\r
1913 returnCode = DEM_WRONG_FILTER;
\r
1916 return returnCode;
\r
1921 * Procedure: Dem_GetStatusOfDTC
\r
1924 Dem_ReturnGetStatusOfDTCType Dem_GetStatusOfDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, Dem_EventStatusExtendedType* status) {
\r
1925 Dem_ReturnGetStatusOfDTCType returnCode = DEM_STATUS_FAILED;
\r
1926 EventStatusRecType *eventRec;
\r
1928 if (demState == DEM_INITIALIZED) {
\r
1929 if (lookupDtcEvent(dtc, &eventRec)) {
\r
1930 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
1931 if (checkDtcOrigin(dtcOrigin,eventRec->eventParamRef)) {
\r
1932 *status = eventRec->eventStatusExtended; /** @req DEM059 */
\r
1933 returnCode = DEM_STATUS_OK;
\r
1936 returnCode = DEM_STATUS_WRONG_DTCORIGIN; /** @req DEM171 */
\r
1940 returnCode = DEM_STATUS_WRONG_DTCKIND;
\r
1944 returnCode = DEM_STATUS_WRONG_DTC; /** @req DEM172 */
\r
1947 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETSTATUSOFDTC_ID, DEM_E_UNINIT);
\r
1948 returnCode = DEM_STATUS_FAILED;
\r
1951 return returnCode;
\r
1956 * Procedure: Dem_GetNumberOfFilteredDtc
\r
1959 Dem_ReturnGetNumberOfFilteredDTCType Dem_GetNumberOfFilteredDtc(uint16 *numberOfFilteredDTC) {
\r
1961 uint16 numberOfFaults = 0;
\r
1962 Dem_ReturnGetNumberOfFilteredDTCType returnCode = DEM_NUMBER_OK;
\r
1964 if (demState == DEM_INITIALIZED) {
\r
1965 //Dem_DisableEventStatusUpdate();
\r
1967 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1968 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1969 if (matchEventWithDtcFilter(&eventStatusBuffer[i])) {
\r
1970 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
1977 //Dem_EnableEventStatusUpdate();
\r
1979 *numberOfFilteredDTC = numberOfFaults; /** @req DEM061 */
\r
1981 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETNUMBEROFFILTEREDDTC_ID, DEM_E_UNINIT);
\r
1982 returnCode = DEM_NUMBER_FAILED;
\r
1985 return returnCode;
\r
1990 * Procedure: Dem_GetNextFilteredDTC
\r
1993 Dem_ReturnGetNextFilteredDTCType Dem_GetNextFilteredDTC(uint32 *dtc, Dem_EventStatusExtendedType *dtcStatus)
\r
1995 Dem_ReturnGetNextFilteredDTCType returnCode = DEM_FILTERED_OK;
\r
1996 boolean dtcFound = FALSE;
\r
1998 if (demState == DEM_INITIALIZED) {
\r
1999 // TODO: This job should be done in an more advanced way according to Dem217
\r
2000 while ((!dtcFound) && (dtcFilter.faultIndex != 0)) {
\r
2001 dtcFilter.faultIndex--;
\r
2002 if (eventStatusBuffer[dtcFilter.faultIndex].eventId != DEM_EVENT_ID_NULL) {
\r
2003 if (matchEventWithDtcFilter(&eventStatusBuffer[dtcFilter.faultIndex])) {
\r
2004 if (eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef != NULL) {
\r
2005 *dtc = eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef->DTC; /** @req DEM216 */
\r
2006 *dtcStatus = eventStatusBuffer[dtcFilter.faultIndex].eventStatusExtended;
\r
2014 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
2015 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
2018 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETNEXTFILTEREDDTC_ID, DEM_E_UNINIT);
\r
2019 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
2022 return returnCode;
\r
2027 * Procedure: Dem_GetTranslationType
\r
2030 Dem_ReturnTypeOfDtcSupportedType Dem_GetTranslationType(void)
\r
2032 return DEM_TYPE_OF_DTC_SUPPORTED; /** @req DEM231 */
\r
2037 * Procedure: Dem_ClearDTC
\r
2040 Dem_ReturnClearDTCType Dem_ClearDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin) /** @req DEM009 */
\r
2042 Dem_ReturnClearDTCType returnCode = DEM_CLEAR_OK;
\r
2043 Dem_EventIdType eventId;
\r
2044 const Dem_EventParameterType *eventParam;
\r
2047 if (demState == DEM_INITIALIZED) {
\r
2048 // Loop through the event buffer
\r
2049 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2050 eventId = eventStatusBuffer[i].eventId;
\r
2051 if (eventId != DEM_EVENT_ID_NULL) {
\r
2052 eventParam = eventStatusBuffer[i].eventParamRef;
\r
2053 if (eventParam != NULL) {
\r
2054 //lint --e(506) PC-Lint exception Misra 13.7, 14.1 Allow configuration variables in boolean expression
\r
2055 //lint --e(774) PC-Lint exception Related to MISRA 13.7
\r
2056 if ((DEM_CLEAR_ALL_EVENTS == STD_ON) || (eventParam->DTCClassRef != NULL)) {
\r
2057 if (checkDtcKind(dtcKind, eventParam)) {
\r
2058 if (checkDtcGroup(dtc, eventParam)) {
\r
2059 boolean dtcOriginFound = FALSE;
\r
2060 for (j = 0; (j < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound) ; j++){
\r
2061 dtcOriginFound =(eventParam->EventClass->EventDestination[j] == dtcOrigin);
\r
2063 //if (j-1 < DEM_MAX_NR_OF_EVENT_DESTINATION) {
\r
2064 if (dtcOriginFound) {
\r
2065 // Yes! All conditions met.
\r
2066 switch (dtcOrigin)
\r
2068 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2069 /** @req DEM077 */
\r
2070 deleteEventPriMem(eventParam);
\r
2071 deleteFreezeFrameDataPriMem(eventParam);
\r
2072 deleteExtendedDataPriMem(eventParam);
\r
2073 deleteEventStatusRec(eventParam); // TODO: Shall this be done or just resetting the status?
\r
2076 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2077 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2078 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2079 // Not yet supported
\r
2080 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2081 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2084 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2093 // Fatal error, no event parameters found for the stored event!
\r
2094 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNEXPECTED_EXECUTION);
\r
2099 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNINIT);
\r
2100 returnCode = DEM_CLEAR_FAILED;
\r
2103 return returnCode;
\r
2108 * Procedure: Dem_DisableDTCStorage
\r
2111 Dem_ReturnControlDTCStorageType Dem_DisableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind) /** @req DEM035 */
\r
2113 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2115 if (demState == DEM_INITIALIZED) {
\r
2116 // Check dtcGroup parameter
\r
2117 if (dtcGroup == DEM_DTC_GROUP_ALL_DTCS) {
\r
2118 // Check dtcKind parameter
\r
2119 if ((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS)) {
\r
2120 /** @req DEM079 */
\r
2121 disableDtcStorage.dtcGroup = dtcGroup;
\r
2122 disableDtcStorage.dtcKind = dtcKind;
\r
2123 disableDtcStorage.storageDisabled = TRUE;
\r
2125 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2128 returnCode = DEM_CONTROL_DTC_WRONG_DTCGROUP;
\r
2131 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_DISABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
2132 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2135 return returnCode;
\r
2140 * Procedure: Dem_EnableDTCStorage
\r
2143 Dem_ReturnControlDTCStorageType Dem_EnableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind)
\r
2145 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2147 if (demState == DEM_INITIALIZED) {
\r
2148 // TODO: Behavior is not defined if group or kind do not match active settings, therefore the filter is just switched off.
\r
2149 (void)dtcGroup; (void)dtcKind; // Just to make get rid of PC-Lint warnings
\r
2150 disableDtcStorage.storageDisabled = FALSE; /** @req DEM080 */
\r
2152 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_ENABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
2153 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2156 return returnCode;
\r
2160 * Procedure: Dem_GetExtendedDataRecordByDTC
\r
2163 Dem_ReturnGetExtendedDataRecordByDTCType Dem_GetExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint8 *destBuffer, uint16 *bufSize)
\r
2165 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_RECORD_WRONG_DTC;
\r
2166 EventStatusRecType *eventRec;
\r
2167 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2168 ExtDataRecType *extData;
\r
2169 uint16 posInExtData = 0;
\r
2171 if (demState == DEM_INITIALIZED) {
\r
2172 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2173 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2174 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2175 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2176 if (*bufSize >= extendedDataRecordClass->DataSize) {
\r
2177 switch (dtcOrigin)
\r
2179 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2180 if (lookupExtendedDataPriMem(eventRec->eventId, &extData)) {
\r
2181 // Yes all conditions met, copy the extended data record to destination buffer.
\r
2182 memcpy(destBuffer, &extData->data[posInExtData], extendedDataRecordClass->DataSize); /** @req DEM075 */
\r
2183 *bufSize = extendedDataRecordClass->DataSize;
\r
2184 returnCode = DEM_RECORD_OK;
\r
2187 // The record number is legal but no record was found for the DTC
\r
2189 returnCode = DEM_RECORD_OK;
\r
2193 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2194 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2195 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2196 // Not yet supported
\r
2197 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2198 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2201 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2206 returnCode = DEM_RECORD_BUFFERSIZE;
\r
2210 returnCode = DEM_RECORD_NUMBER;
\r
2214 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2218 returnCode = DEM_RECORD_DTCKIND;
\r
2222 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
2223 returnCode = DEM_RECORD_WRONG_DTC;
\r
2226 return returnCode;
\r
2231 * Procedure: Dem_GetSizeOfExtendedDataRecordByDTC
\r
2234 Dem_ReturnGetSizeOfExtendedDataRecordByDTCType Dem_GetSizeOfExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint16 *sizeOfExtendedDataRecord)
\r
2236 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2237 EventStatusRecType *eventRec;
\r
2238 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2239 uint16 posInExtData;
\r
2241 if (demState == DEM_INITIALIZED) {
\r
2242 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2243 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2244 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2245 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2246 *sizeOfExtendedDataRecord = extendedDataRecordClass->DataSize; /** @req DEM076 */
\r
2247 returnCode = DEM_GET_SIZEOFEDRBYDTC_OK;
\r
2250 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_RNUM;
\r
2254 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCOR;
\r
2258 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCKI;
\r
2262 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETSIZEOFEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
2263 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2266 return returnCode;
\r
2269 /***********************************
\r
2270 * OBD-specific Interfaces (8.3.6) *
\r
2271 ***********************************/
\r