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: OK. Allow VALIDATE, VALIDATE_RV and VALIDATE_NO_RV to return value.
\r
17 //lint -emacro(904,VALIDATE_RV,VALIDATE_NO_RV,VALIDATE)
\r
22 * General requirements
\r
25 /** @req DEM151.partially */
\r
27 /** @req DEM013.14229-1 */
\r
30 /** @req DEM113 */ /** @req DEM174 */
\r
44 //#include "SchM_Dem.h"
\r
46 #include "McuExtensions.h"
\r
51 #define DEBOUNCE_FDC_TEST_FAILED 127
\r
52 #define DEBOUNCE_FDC_TEST_PASSED -128
\r
54 #if ( DEM_DEV_ERROR_DETECT == STD_ON )
\r
57 #define VALIDATE_RV(_exp,_api,_err,_rv ) \
\r
59 Det_ReportError(MODULE_ID_DEM, 0, _api, _err); \
\r
63 #define VALIDATE_NO_RV(_exp,_api,_err ) \
\r
65 Det_ReportError(MODULE_ID_DEM, 0, _api, _err); \
\r
68 #define DET_REPORTERROR(_x,_y,_z,_q) Det_ReportError(_x, _y, _z, _q)
\r
71 #define VALIDATE_RV(_exp,_api,_err,_rv )
\r
72 #define VALIDATE_NO_RV(_exp,_api,_err )
\r
73 #define DET_REPORTERROR(_x,_y,_z,_q)
\r
81 typedef uint16 ChecksumType;
\r
85 Dem_EventStatusExtendedType dtcStatusMask;
\r
86 Dem_DTCKindType dtcKind;
\r
87 Dem_DTCOriginType dtcOrigin;
\r
88 Dem_FilterWithSeverityType filterWithSeverity;
\r
89 Dem_DTCSeverityType dtcSeverityMask;
\r
90 Dem_FilterForFDCType filterForFaultDetectionCounter;
\r
94 // DisableDtcStorageType
\r
96 boolean storageDisabled;
\r
97 Dem_DTCGroupType dtcGroup;
\r
98 Dem_DTCKindType dtcKind;
\r
99 } DisableDtcStorageType;
\r
101 // For keeping track of the events status
\r
103 Dem_EventIdType eventId;
\r
104 const Dem_EventParameterType *eventParamRef;
\r
105 sint8 faultDetectionCounter;
\r
106 uint16 occurrence; /** @req DEM011 */
\r
107 Dem_EventStatusExtendedType eventStatusExtended; /** @req DEM006 */
\r
108 boolean errorStatusChanged;
\r
109 } EventStatusRecType;
\r
112 // Types for storing different event data on event memory
\r
114 Dem_EventIdType eventId;
\r
116 ChecksumType checksum;
\r
120 Dem_EventIdType eventId;
\r
123 sint8 data[DEM_MAX_SIZE_FF_DATA];
\r
124 ChecksumType checksum;
\r
125 } FreezeFrameRecType;
\r
128 Dem_EventIdType eventId;
\r
130 uint8 data[DEM_MAX_SIZE_EXT_DATA];
\r
131 ChecksumType checksum;
\r
138 DEM_UNINITIALIZED = 0,
\r
139 DEM_PREINITIALIZED,
\r
141 } Dem_StateType; /** @req DEM169 */
\r
144 static Dem_StateType demState = DEM_UNINITIALIZED;
\r
146 // Help pointer to configuration set
\r
147 static const Dem_ConfigSetType *configSet;
\r
150 * Allocation of DTC filter parameters
\r
152 static DtcFilterType dtcFilter;
\r
155 * Allocation of Disable/Enable DTC storage parameters
\r
157 static DisableDtcStorageType disableDtcStorage;
\r
160 * Allocation of operation cycle state list
\r
162 static Dem_OperationCycleStateType operationCycleStateList[DEM_OPERATION_CYCLE_ID_ENDMARK];
\r
165 * Allocation of local event status buffer
\r
167 static EventStatusRecType eventStatusBuffer[DEM_MAX_NUMBER_EVENT];
\r
170 * Allocation of pre-init event memory (used between pre-init and init)
\r
173 static FreezeFrameRecType preInitFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRE_INIT];
\r
174 static ExtDataRecType preInitExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRE_INIT];
\r
177 * Allocation of primary event memory ramlog (after init) in uninitialized memory
\r
180 static EventRecType priMemEventBuffer[DEM_MAX_NUMBER_EVENT_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
181 static FreezeFrameRecType priMemFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
182 static ExtDataRecType priMemExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
186 * Procedure: zeroPriMemBuffers
\r
187 * Description: Fill the primary buffers with zeroes
\r
189 void demZeroPriMemBuffers(void) // 957 PC-Lint (MISRA 8.1): OK. Used only by DemTest
\r
191 memset(priMemEventBuffer, 0, sizeof(priMemEventBuffer));
\r
192 memset(priMemFreezeFrameBuffer, 0, sizeof(priMemFreezeFrameBuffer));
\r
193 memset(priMemExtDataBuffer, 0, sizeof(priMemExtDataBuffer));
\r
198 * Procedure: calcChecksum
\r
199 * Description: Calculate checksum over *data to *(data+nrOfBytes-1) area
\r
201 static ChecksumType calcChecksum(void *data, uint16 nrOfBytes)
\r
204 uint8 *byte = (uint8*)data;
\r
205 ChecksumType sum = 0;
\r
207 for (i = 0; i < nrOfBytes; i++) {
\r
215 * Procedure: checkDtcKind
\r
216 * Description: Return TRUE if "dtcKind" match the events DTCKind or "dtcKind"
\r
217 * is "DEM_DTC_KIND_ALL_DTCS" otherwise FALSE.
\r
219 static boolean checkDtcKind(Dem_DTCKindType dtcKind, const Dem_EventParameterType *eventParam)
\r
221 boolean result = FALSE;
\r
223 if (dtcKind == DEM_DTC_KIND_ALL_DTCS) {
\r
227 if (eventParam->DTCClassRef != NULL) {
\r
228 if (eventParam->DTCClassRef->DTCKind == dtcKind) {
\r
238 * Procedure: checkDtcGroup
\r
239 * Description: Return TRUE if "dtc" match the events DTC or "dtc" is
\r
240 * "DEM_DTC_GROUP_ALL_DTCS" otherwise FALSE.
\r
242 static boolean checkDtcGroup(uint32 dtc, const Dem_EventParameterType *eventParam)
\r
244 boolean result = FALSE;
\r
246 if (dtc == DEM_DTC_GROUP_ALL_DTCS) {
\r
250 if (eventParam->DTCClassRef != NULL) {
\r
251 if (eventParam->DTCClassRef->DTC == dtc) {
\r
261 * Procedure: checkDtcOrigin
\r
262 * Description: Return TRUE if "dtcOrigin" match any of the events DTCOrigin otherwise FALSE.
\r
264 static boolean checkDtcOrigin(Dem_DTCOriginType dtcOrigin, const Dem_EventParameterType *eventParam)
\r
266 boolean result = FALSE;
\r
267 boolean dtcOriginFound = FALSE;
\r
270 for (i = 0;(i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound); i++){
\r
271 dtcOriginFound = (eventParam->EventClass->EventDestination[i] == dtcOrigin);
\r
274 if (dtcOriginFound) {
\r
282 * Procedure: checkDtcSeverityMask
\r
283 * Description: Return TRUE if "dtcSeverityMask" match any of the events DTC severity otherwise FALSE.
\r
285 // PC-Lint (715 etc): Remove errors until function is filled.
\r
287 static boolean checkDtcSeverityMask(Dem_DTCSeverityType dtcSeverityMask, const Dem_EventParameterType *eventParam)
\r
289 boolean result = TRUE;
\r
291 // TODO: This function is optional, may be implemented here.
\r
299 * Procedure: checkDtcFaultDetectionCounterMask
\r
300 * Description: TBD.
\r
302 // PC-Lint (715 etc): Remove errors until function is filled.
\r
304 static boolean checkDtcFaultDetectionCounter(const Dem_EventParameterType *eventParam)
\r
306 boolean result = TRUE;
\r
308 // TODO: Not implemented yet.
\r
315 * Procedure: lookupEventStatusRec
\r
316 * Description: Returns the pointer to event id parameters of "eventId" in "*eventStatusBuffer",
\r
317 * if not found NULL is returned.
\r
319 static void lookupEventStatusRec(Dem_EventIdType eventId, EventStatusRecType **const eventStatusRec)
\r
322 boolean eventIdFound = FALSE;
\r
324 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!eventIdFound); i++) {
\r
325 eventIdFound = (eventStatusBuffer[i].eventId == eventId);
\r
328 if (eventIdFound) {
\r
329 *eventStatusRec = &eventStatusBuffer[i-1];
\r
331 *eventStatusRec = NULL;
\r
337 * Procedure: lookupEventIdParameter
\r
338 * Description: Returns the pointer to event id parameters of "eventId" in "*eventIdParam",
\r
339 * if not found NULL is returned.
\r
341 static void lookupEventIdParameter(Dem_EventIdType eventId, const Dem_EventParameterType **const eventIdParam)
\r
343 const Dem_EventParameterType *EventIdParamList = configSet->EventParameter;
\r
345 // Lookup the correct event id parameters
\r
347 while ((EventIdParamList[i].EventID != eventId) && (!EventIdParamList[i].Arc_EOL)) {
\r
351 if (!EventIdParamList[i].Arc_EOL) {
\r
352 *eventIdParam = &EventIdParamList[i];
\r
354 *eventIdParam = NULL;
\r
360 * Procedure: preDebounceNone
\r
361 * Description: Returns the result of the debouncing.
\r
363 static Dem_EventStatusType preDebounceNone(const Dem_EventStatusType reportedStatus, const EventStatusRecType* statusRecord) {
\r
364 Dem_EventStatusType returnCode;
\r
365 (void)statusRecord; // Just to get rid of PC-Lint warnings
\r
367 switch (reportedStatus) {
\r
368 case DEM_EVENT_STATUS_FAILED: /** @req DEM091.NoneFailed */
\r
369 case DEM_EVENT_STATUS_PASSED: /** @req DEM091.NonePassed */
\r
370 // Already debounced, do nothing.
\r
374 // TODO: What to do with PREFAIL and PREPASSED on no debouncing?
\r
375 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_NONE_ID, DEM_E_PARAM_DATA);
\r
379 returnCode = reportedStatus;
\r
385 * Procedure: preDebounceCounterBased
\r
386 * Description: Returns the result of the debouncing.
\r
388 static Dem_EventStatusType preDebounceCounterBased(Dem_EventStatusType reportedStatus, EventStatusRecType* statusRecord) {
\r
389 Dem_EventStatusType returnCode;
\r
390 const Dem_PreDebounceCounterBasedType* pdVars = statusRecord->eventParamRef->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceCounterBased;
\r
392 switch (reportedStatus) {
\r
393 case DEM_EVENT_STATUS_PREFAILED:
\r
394 if (statusRecord->faultDetectionCounter < DEBOUNCE_FDC_TEST_FAILED) {
\r
395 if ((pdVars->JumpUp) && (statusRecord->faultDetectionCounter < 0)) {
\r
396 statusRecord->faultDetectionCounter = 0;
\r
398 if (((sint16)statusRecord->faultDetectionCounter + (sint8)pdVars->CountInStepSize) < DEBOUNCE_FDC_TEST_FAILED) {
\r
399 statusRecord->faultDetectionCounter += (sint8)pdVars->CountInStepSize;
\r
401 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED;
\r
407 case DEM_EVENT_STATUS_PREPASSED:
\r
408 if (statusRecord->faultDetectionCounter > DEBOUNCE_FDC_TEST_PASSED) {
\r
409 if ((pdVars->JumpDown) && (statusRecord->faultDetectionCounter > 0)) {
\r
410 statusRecord->faultDetectionCounter = 0;
\r
412 if (((sint16)statusRecord->faultDetectionCounter - (sint8)pdVars->CountOutStepSize) > DEBOUNCE_FDC_TEST_PASSED) {
\r
413 statusRecord->faultDetectionCounter -= (sint8)pdVars->CountOutStepSize;
\r
415 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED;
\r
421 case DEM_EVENT_STATUS_FAILED:
\r
422 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED; /** @req DEM091.CounterFailed */
\r
425 case DEM_EVENT_STATUS_PASSED:
\r
426 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED; /** @req DEM091.CounterPassed */
\r
430 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_COUNTER_BASED_ID, DEM_E_PARAM_DATA);
\r
435 switch (statusRecord->faultDetectionCounter) {
\r
436 case DEBOUNCE_FDC_TEST_FAILED:
\r
437 returnCode = DEM_EVENT_STATUS_FAILED;
\r
440 case DEBOUNCE_FDC_TEST_PASSED:
\r
441 returnCode = DEM_EVENT_STATUS_PASSED;
\r
445 returnCode = reportedStatus;
\r
454 * Procedure: updateEventStatusRec
\r
455 * Description: Update the status of "eventId", if not exist and "createIfNotExist" is
\r
456 * true a new record is created
\r
458 static void updateEventStatusRec(const Dem_EventParameterType *eventParam, Dem_EventStatusType eventStatus, boolean createIfNotExist, EventStatusRecType *eventStatusRec)
\r
460 EventStatusRecType *eventStatusRecPtr;
\r
461 imask_t state = McuE_EnterCriticalSection();
\r
464 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
466 if ((eventStatusRecPtr == NULL) && (createIfNotExist)) {
\r
467 // Search for free position
\r
468 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
470 if (eventStatusRecPtr != NULL) {
\r
471 // Create new event record
\r
472 eventStatusRecPtr->eventId = eventParam->EventID;
\r
473 eventStatusRecPtr->eventParamRef = eventParam;
\r
474 eventStatusRecPtr->faultDetectionCounter = 0;
\r
475 eventStatusRecPtr->occurrence = 0;
\r
476 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
477 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
480 // Error: Event status buffer full
\r
481 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
486 if (eventStatusRecPtr != NULL) {
\r
487 // Handle debouncing
\r
488 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
489 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName) { /** @req DEM004 */ /** @req DEM342 */
\r
490 case DEM_NO_PRE_DEBOUNCE:
\r
491 eventStatus = preDebounceNone(eventStatus, eventStatusRecPtr);
\r
494 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
495 eventStatus = preDebounceCounterBased(eventStatus, eventStatusRecPtr);
\r
499 // Don't know how to handle this.
\r
500 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
505 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
507 // Check test failed
\r
508 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
509 if (!(eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED)) {
\r
510 eventStatusRecPtr->occurrence++;
\r
511 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
513 /** @req DEM036 */ /** @req DEM379.PendingSet */
\r
514 eventStatusRecPtr->eventStatusExtended |= (DEM_TEST_FAILED | DEM_TEST_FAILED_THIS_OPERATION_CYCLE | DEM_TEST_FAILED_SINCE_LAST_CLEAR | DEM_PENDING_DTC);
\r
515 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
518 // Check test passed
\r
519 if (eventStatus == DEM_EVENT_STATUS_PASSED) {
\r
520 if (eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED) {
\r
521 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
524 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED;
\r
525 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
529 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
532 // Copy an empty record to return data
\r
533 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
534 eventStatusRec->faultDetectionCounter = 0;
\r
535 eventStatusRec->occurrence = 0;
\r
536 eventStatusRec->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
537 eventStatusRec->errorStatusChanged = FALSE;
\r
540 McuE_ExitCriticalSection(state);
\r
545 * Procedure: mergeEventStatusRec
\r
546 * Description: Update the occurrence counter of status, if not exist a new record is created
\r
548 static void mergeEventStatusRec(const EventRecType *eventRec)
\r
550 EventStatusRecType *eventStatusRecPtr;
\r
551 imask_t state = McuE_EnterCriticalSection();
\r
554 lookupEventStatusRec(eventRec->eventId, &eventStatusRecPtr);
\r
556 if (eventStatusRecPtr != NULL) {
\r
557 // Update occurrence counter, rest of pre init state is kept.
\r
558 eventStatusRecPtr->occurrence += eventRec->occurrence;
\r
562 // Search for free position
\r
563 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
565 if (eventStatusRecPtr != NULL) {
\r
566 // Create new event, from stored event
\r
567 eventStatusRecPtr->eventId = eventRec->eventId;
\r
568 lookupEventIdParameter(eventRec->eventId, &eventStatusRecPtr->eventParamRef);
\r
569 eventStatusRecPtr->faultDetectionCounter = 0;
\r
570 eventStatusRecPtr->occurrence = eventRec->occurrence;
\r
571 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
572 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
575 // Error: Event status buffer full
\r
576 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_MERGE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
580 McuE_ExitCriticalSection(state);
\r
585 * Procedure: deleteEventStatusRec
\r
586 * Description: Delete the status record of "eventParam->eventId" from "eventStatusBuffer".
\r
588 static void deleteEventStatusRec(const Dem_EventParameterType *eventParam)
\r
590 EventStatusRecType *eventStatusRecPtr;
\r
591 imask_t state = McuE_EnterCriticalSection();
\r
594 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
596 if (eventStatusRecPtr != NULL) {
\r
597 // Delete event record
\r
598 memset(eventStatusRecPtr, 0, sizeof(EventStatusRecType));
\r
601 McuE_ExitCriticalSection(state);
\r
606 * Procedure: getEventStatusRec
\r
607 * Description: Returns the status record of "eventId" in "eventStatusRec"
\r
609 static void getEventStatusRec(Dem_EventIdType eventId, EventStatusRecType *eventStatusRec)
\r
611 EventStatusRecType *eventStatusRecPtr;
\r
614 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
616 if (eventStatusRecPtr != NULL) {
\r
618 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
621 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
627 * Procedure: lookupDtcEvent
\r
628 * Description: Returns TRUE if the DTC was found and "eventStatusRec" points
\r
629 * to the event record found.
\r
631 static boolean lookupDtcEvent(uint32 dtc, EventStatusRecType **eventStatusRec)
\r
633 boolean dtcFound = FALSE;
\r
636 *eventStatusRec = NULL;
\r
638 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!dtcFound); i++) {
\r
639 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
640 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
643 if (eventStatusBuffer[i].eventParamRef->DTCClassRef->DTC == dtc) {
\r
644 *eventStatusRec = &eventStatusBuffer[i];
\r
656 * Procedure: matchEventWithDtcFilter
\r
657 * Description: Returns TRUE if the event pointed by "event" fulfill
\r
658 * the "dtcFilter" global filter settings.
\r
660 static boolean matchEventWithDtcFilter(const EventStatusRecType *eventRec)
\r
662 boolean dtcMatch = FALSE;
\r
665 if ((dtcFilter.dtcStatusMask == DEM_DTC_STATUS_MASK_ALL) || (eventRec->eventStatusExtended & dtcFilter.dtcStatusMask)) {
\r
666 if (eventRec->eventParamRef != NULL) {
\r
669 if (checkDtcKind(dtcFilter.dtcKind, eventRec->eventParamRef)) {
\r
672 if (checkDtcOrigin(dtcFilter.dtcOrigin, eventRec->eventParamRef)) {
\r
675 if ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
676 || ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES) && (checkDtcSeverityMask(dtcFilter.dtcSeverityMask, eventRec->eventParamRef)))) {
\r
678 // Check fault detection counter
\r
679 if ((dtcFilter.filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO)
\r
680 || ((dtcFilter.filterWithSeverity == DEM_FILTER_FOR_FDC_YES) && (checkDtcFaultDetectionCounter(eventRec->eventParamRef)))) {
\r
693 // PC-Lint (715 etc): Remove errors until function is filled.
\r
695 static void getFreezeFrameData(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
698 freezeFrame->eventId = DEM_EVENT_ID_NULL; // Not supported yet
\r
702 // PC-Lint (715 etc): Remove errors until function is filled.
\r
704 static void storeFreezeFrameDataPreInit(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
710 // PC-Lint (715 etc): Remove errors until function is filled.
\r
712 static void updateFreezeFrameOccurrencePreInit(const EventRecType *EventBuffer)
\r
716 //lint -restore // PC-lint: Restore to original error-setting.
\r
719 * Procedure: getExtendedData
\r
720 * Description: Collects the extended data according to "eventParam" and return it in "extData",
\r
721 * if not found eventId is set to DEM_EVENT_ID_NULL.
\r
723 static void getExtendedData(const Dem_EventParameterType *eventParam, ExtDataRecType *extData)
\r
725 Std_ReturnType callbackReturnCode;
\r
727 uint16 storeIndex = 0;
\r
730 // Clear ext data record
\r
731 memset(extData, 0, sizeof(ExtDataRecType));
\r
733 // Check if any pointer to extended data class
\r
734 if (eventParam->ExtendedDataClassRef != NULL) {
\r
735 // Request extended data and copy it to the buffer
\r
736 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL); i++) {
\r
737 recordSize = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
738 if ((storeIndex + recordSize) <= DEM_MAX_SIZE_EXT_DATA) {
\r
739 callbackReturnCode = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->CallbackGetExtDataRecord(&extData->data[storeIndex]); /** @req DEM282 */
\r
740 if (callbackReturnCode != E_OK) {
\r
741 // Callback data currently not available, clear space.
\r
742 memset(&extData->data[storeIndex], 0xFF, recordSize); // PC-Lint OK
\r
744 storeIndex += recordSize;
\r
747 // Error: Size of extended data record is bigger than reserved space.
\r
748 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GET_EXTENDED_DATA_ID, DEM_E_EXT_DATA_TOO_BIG);
\r
749 break; // Break the loop
\r
754 // Check if any data has been stored
\r
755 if (storeIndex != 0) {
\r
756 extData->eventId = eventParam->EventID;
\r
757 extData->dataSize = storeIndex;
\r
758 extData->checksum = calcChecksum(extData, sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
761 extData->eventId = DEM_EVENT_ID_NULL;
\r
762 extData->dataSize = storeIndex;
\r
763 extData->checksum = 0;
\r
769 * Procedure: storeExtendedDataPreInit
\r
770 * Description: Store the extended data pointed by "extendedData" to the "preInitExtDataBuffer",
\r
771 * if non existent a new entry is created.
\r
773 static void storeExtendedDataPreInit(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
775 boolean eventIdFound = FALSE;
\r
776 boolean eventIdFreePositionFound=FALSE;
\r
778 imask_t state = McuE_EnterCriticalSection();
\r
780 // Check if already stored
\r
781 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) && (!eventIdFound); i++){
\r
782 eventIdFound = (preInitExtDataBuffer[i].eventId == eventParam->EventID);
\r
786 // Yes, overwrite existing
\r
787 /*lint -esym(669,memcpy) -e826 */ /* supress lintwarning 669 and 826 locally. */
\r
788 memcpy(&preInitExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType)); // 826,669 PC-Lint: OK. TA BORT ERROR! Lint does not recognise the size of the preInitExtDataBuffer record correctly.
\r
791 // No, lookup first free position
\r
792 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) && (!eventIdFreePositionFound); i++){
\r
793 if(preInitExtDataBuffer[i].eventId ==0){
\r
794 eventIdFreePositionFound=TRUE;
\r
798 if (eventIdFreePositionFound) {
\r
799 memcpy(&preInitExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
802 // Error: Pre init extended data buffer full
\r
803 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRE_INIT_ID, DEM_E_PRE_INIT_EXT_DATA_BUFF_FULL);
\r
807 McuE_ExitCriticalSection(state);
\r
811 * Procedure: storeEventPriMem
\r
812 * Description: Store the event data of "eventStatus->eventId" in "priMemEventBuffer",
\r
813 * if non existent a new entry is created.
\r
815 static void storeEventPriMem(const Dem_EventParameterType *eventParam, const EventStatusRecType *eventStatus)
\r
817 boolean eventIdFound = FALSE;
\r
818 boolean eventIdFreePositionFound=FALSE;
\r
820 imask_t state = McuE_EnterCriticalSection();
\r
823 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
824 eventIdFound = (priMemEventBuffer[i].eventId == eventStatus->eventId);
\r
827 if (eventIdFound) {
\r
828 // Update event found
\r
829 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
830 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
833 // Search for free position
\r
834 for (i=0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFreePositionFound); i++){
\r
835 eventIdFreePositionFound = (priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
839 if (eventIdFreePositionFound) {
\r
840 priMemEventBuffer[i-1].eventId = eventStatus->eventId;
\r
841 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
842 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
845 // Error: Pri mem event buffer full
\r
846 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EVENT_PRI_MEM_ID, DEM_E_PRI_MEM_EVENT_BUFF_FULL);
\r
850 McuE_ExitCriticalSection(state);
\r
854 * Procedure: deleteEventPriMem
\r
855 * Description: Delete the event data of "eventParam->eventId" from "priMemEventBuffer".
\r
857 static void deleteEventPriMem(const Dem_EventParameterType *eventParam)
\r
859 boolean eventIdFound = FALSE;
\r
861 imask_t state = McuE_EnterCriticalSection();
\r
865 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
866 eventIdFound = (priMemEventBuffer[i].eventId == eventParam->EventID);
\r
869 if (eventIdFound) {
\r
870 // Delete event found
\r
871 memset(&priMemEventBuffer[i-1], 0, sizeof(EventRecType));
\r
874 McuE_ExitCriticalSection(state);
\r
878 * Procedure: storeEventEvtMem
\r
879 * Description: Store the event data of "eventStatus->eventId" in event memory according to
\r
880 * "eventParam" destination option.
\r
882 static void storeEventEvtMem(const Dem_EventParameterType *eventParam, const EventStatusRecType *eventStatus)
\r
886 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION)
\r
887 && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
888 switch (eventParam->EventClass->EventDestination[i])
\r
890 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
891 storeEventPriMem(eventParam, eventStatus); /** @req DEM010 */
\r
894 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
895 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
896 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
897 // Not yet supported
\r
898 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
908 * Procedure: storeExtendedDataPriMem
\r
909 * Description: Store the extended data pointed by "extendedData" to the "priMemExtDataBuffer",
\r
910 * if non existent a new entry is created.
\r
912 static void storeExtendedDataPriMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData) /** @req DEM041 */
\r
914 boolean eventIdFound = FALSE;
\r
915 boolean eventIdFreePositionFound=FALSE;
\r
917 imask_t state = McuE_EnterCriticalSection();
\r
919 // Check if already stored
\r
920 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
921 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
924 if (eventIdFound) {
\r
925 // Yes, overwrite existing
\r
926 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
929 // No, lookup first free position
\r
930 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFreePositionFound); i++){
\r
931 eventIdFreePositionFound = (priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
933 if (eventIdFreePositionFound) {
\r
934 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
937 // Error: Pri mem extended data buffer full
\r
938 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRI_MEM_ID, DEM_E_PRI_MEM_EXT_DATA_BUFF_FULL);
\r
942 McuE_ExitCriticalSection(state);
\r
946 * Procedure: deleteExtendedDataPriMem
\r
947 * Description: Delete the extended data of "eventParam->eventId" from "priMemExtDataBuffer".
\r
949 static void deleteExtendedDataPriMem(const Dem_EventParameterType *eventParam)
\r
951 boolean eventIdFound = FALSE;
\r
953 imask_t state = McuE_EnterCriticalSection();
\r
955 // Check if already stored
\r
956 for (i = 0;(i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
957 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
960 if (eventIdFound) {
\r
961 // Yes, clear record
\r
962 memset(&priMemExtDataBuffer[i-1], 0, sizeof(ExtDataRecType));
\r
965 McuE_ExitCriticalSection(state);
\r
969 * Procedure: storeExtendedDataEvtMem
\r
970 * Description: Store the extended data in event memory according to
\r
971 * "eventParam" destination option
\r
973 static void storeExtendedDataEvtMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
977 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
978 switch (eventParam->EventClass->EventDestination[i])
\r
980 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
981 storeExtendedDataPriMem(eventParam, extendedData);
\r
984 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
985 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
986 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
987 // Not yet supported
\r
988 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
999 * Procedure: lookupExtendedDataRecNumParam
\r
1000 * Description: Returns TRUE if the requested extended data number was found among the configured records for the event.
\r
1001 * "extDataRecClassPtr" returns a pointer to the record class, "posInExtData" returns the position in stored extended data.
\r
1003 static boolean lookupExtendedDataRecNumParam(uint8 extendedDataNumber, const Dem_EventParameterType *eventParam, Dem_ExtendedDataRecordClassType const **extDataRecClassPtr, uint16 *posInExtData)
\r
1005 boolean recNumFound = FALSE;
\r
1007 if (eventParam->ExtendedDataClassRef != NULL) {
\r
1008 Dem_ExtendedDataRecordClassType const* const* extDataRecClassRefList = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef;
\r
1009 uint16 byteCnt = 0;
\r
1012 // Request extended data and copy it to the buffer
\r
1013 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (extDataRecClassRefList[i] != NULL) && (!recNumFound); i++) {
\r
1014 if (extDataRecClassRefList[i]->RecordNumber == extendedDataNumber) {
\r
1015 *extDataRecClassPtr = extDataRecClassRefList[i];
\r
1016 *posInExtData = byteCnt;
\r
1017 recNumFound = TRUE;
\r
1019 byteCnt += extDataRecClassRefList[i]->DataSize;
\r
1023 return recNumFound;
\r
1028 * Procedure: lookupExtendedDataPriMem
\r
1029 * Description: Returns TRUE if the requested event id is found, "extData" points to the found data.
\r
1031 static boolean lookupExtendedDataPriMem(Dem_EventIdType eventId, ExtDataRecType **extData)
\r
1033 boolean eventIdFound = FALSE;
\r
1036 // Lookup corresponding extended data
\r
1037 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++) {
\r
1038 eventIdFound = (priMemExtDataBuffer[i].eventId == eventId);
\r
1041 if (eventIdFound) {
\r
1042 // Yes, return pointer
\r
1043 *extData = &priMemExtDataBuffer[i-1];
\r
1046 return eventIdFound;
\r
1049 // PC-Lint (715 etc): Remove errors until function is filled.
\r
1051 static void storeFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1057 // PC-Lint (715 etc): Remove errors until function is filled.
\r
1059 static void deleteFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam)
\r
1067 * Procedure: storeFreezeFrameDataEvtMem
\r
1068 * Description: Store the freeze frame data in event memory according to
\r
1069 * "eventParam" destination option
\r
1071 static void storeFreezeFrameDataEvtMem(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1075 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
1076 switch (eventParam->EventClass->EventDestination[i])
\r
1078 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1079 storeFreezeFrameDataPriMem(eventParam, freezeFrame);
\r
1082 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1083 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1084 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1085 // Not yet supported
\r
1086 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1096 * Procedure: handlePreInitEvent
\r
1097 * Description: Handle the updating of event status and storing of
\r
1098 * event related data in preInit buffers.
\r
1100 static void handlePreInitEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1102 const Dem_EventParameterType *eventParam;
\r
1103 EventStatusRecType eventStatusLocal;
\r
1104 FreezeFrameRecType freezeFrameLocal;
\r
1105 ExtDataRecType extendedDataLocal;
\r
1107 // Find configuration for this event
\r
1108 lookupEventIdParameter(eventId, &eventParam);
\r
1109 if (eventParam != NULL) {
\r
1110 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1111 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1112 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
1113 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1116 updateEventStatusRec(eventParam, eventStatus, FALSE, &eventStatusLocal);
\r
1119 if (eventStatusLocal.errorStatusChanged) {
\r
1121 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1122 // Collect freeze frame data
\r
1123 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1124 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1125 storeFreezeFrameDataPreInit(eventParam, &freezeFrameLocal);
\r
1128 // Collect extended data
\r
1129 getExtendedData(eventParam, &extendedDataLocal);
\r
1130 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1131 storeExtendedDataPreInit(eventParam, &extendedDataLocal);
\r
1137 // Operation cycle not started
\r
1138 // TODO: Report error?
\r
1142 // Operation cycle not set
\r
1143 // TODO: Report error?
\r
1147 // Event ID not configured
\r
1148 // TODO: Report error?
\r
1154 * Procedure: handleEvent
\r
1155 * Description: Handle the updating of event status and storing of
\r
1156 * event related data in event memory.
\r
1158 static Std_ReturnType handleEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1160 Std_ReturnType returnCode = E_OK;
\r
1161 const Dem_EventParameterType *eventParam;
\r
1162 EventStatusRecType eventStatusLocal;
\r
1163 FreezeFrameRecType freezeFrameLocal;
\r
1164 ExtDataRecType extendedDataLocal;
\r
1166 // Find configuration for this event
\r
1167 lookupEventIdParameter(eventId, &eventParam);
\r
1168 if (eventParam != NULL) {
\r
1169 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1170 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1171 if ((!((disableDtcStorage.storageDisabled) && (checkDtcGroup(disableDtcStorage.dtcGroup, eventParam)) && (checkDtcKind(disableDtcStorage.dtcKind, eventParam))))) {
\r
1172 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1173 if (eventStatusLocal.errorStatusChanged) {
\r
1174 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1175 storeEventEvtMem(eventParam, &eventStatusLocal); /** @req DEM184 */
\r
1176 // Collect freeze frame data
\r
1177 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1178 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1179 storeFreezeFrameDataEvtMem(eventParam, &freezeFrameLocal); /** @req DEM190 */
\r
1182 // Collect extended data
\r
1183 getExtendedData(eventParam, &extendedDataLocal);
\r
1184 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL)
\r
1186 storeExtendedDataEvtMem(eventParam, &extendedDataLocal);
\r
1193 // Operation cycle not started
\r
1194 returnCode = E_NOT_OK;
\r
1198 // Operation cycle not set
\r
1199 returnCode = E_NOT_OK;
\r
1203 // Event ID not configured
\r
1204 returnCode = E_NOT_OK;
\r
1207 return returnCode;
\r
1212 * Procedure: resetEventStatus
\r
1213 * Description: Resets the events status of eventId.
\r
1215 static void resetEventStatus(Dem_EventIdType eventId)
\r
1217 imask_t state = McuE_EnterCriticalSection();
\r
1218 EventStatusRecType *eventStatusRecPtr;
\r
1220 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
1221 if (eventStatusRecPtr != NULL) {
\r
1222 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED; /** @req DEM187 */
\r
1225 McuE_ExitCriticalSection(state);
\r
1230 * Procedure: getEventStatus
\r
1231 * Description: Returns the extended event status bitmask of eventId in "eventStatusExtended".
\r
1233 static void getEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended)
\r
1235 EventStatusRecType eventStatusLocal;
\r
1237 // Get recorded status
\r
1238 getEventStatusRec(eventId, &eventStatusLocal);
\r
1239 if (eventStatusLocal.eventId == eventId) {
\r
1240 *eventStatusExtended = eventStatusLocal.eventStatusExtended; /** @req DEM051 */
\r
1243 // Event Id not found, no report received.
\r
1244 *eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1250 * Procedure: getEventFailed
\r
1251 * Description: Returns the TRUE or FALSE of "eventId" in "eventFailed" depending on current status.
\r
1253 static void getEventFailed(Dem_EventIdType eventId, boolean *eventFailed)
\r
1255 EventStatusRecType eventStatusLocal;
\r
1257 // Get recorded status
\r
1258 getEventStatusRec(eventId, &eventStatusLocal);
\r
1259 if (eventStatusLocal.eventId == eventId) {
\r
1260 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) { /** @req DEM052 */
\r
1261 *eventFailed = TRUE;
\r
1264 *eventFailed = FALSE;
\r
1268 // Event Id not found, assume ok.
\r
1269 *eventFailed = FALSE;
\r
1275 * Procedure: getEventTested
\r
1276 * Description: Returns the TRUE or FALSE of "eventId" in "eventTested" depending on
\r
1277 * current status the "test not completed this operation cycle" bit.
\r
1279 static void getEventTested(Dem_EventIdType eventId, boolean *eventTested)
\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_NOT_COMPLETED_THIS_OPERATION_CYCLE)) { /** @req DEM053 */
\r
1287 *eventTested = TRUE;
\r
1290 *eventTested = FALSE;
\r
1294 // Event Id not found, not tested.
\r
1295 *eventTested = FALSE;
\r
1301 * Procedure: getFaultDetectionCounter
\r
1302 * Description: Returns pre debounce counter of "eventId" in "counter" and return value E_OK if
\r
1303 * the counter was available else E_NOT_OK.
\r
1305 static Std_ReturnType getFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1307 Std_ReturnType returnCode = E_NOT_OK;
\r
1308 const Dem_EventParameterType *eventParam;
\r
1310 lookupEventIdParameter(eventId, &eventParam);
\r
1311 if (eventParam != NULL) {
\r
1312 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
1313 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName)
\r
1315 case DEM_NO_PRE_DEBOUNCE:
\r
1316 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal != NULL) {
\r
1317 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc != NULL) {
\r
1318 returnCode = eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc(counter); /** @req DEM204.None */ /** @req DEM264 */ /** @req DEM265 */
\r
1323 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
1325 EventStatusRecType *eventStatusRec;
\r
1327 lookupEventStatusRec(eventId, &eventStatusRec);
\r
1328 if (eventStatusRec != NULL) {
\r
1329 *counter = eventStatusRec->faultDetectionCounter; /** @req DEM204.Counter */
\r
1333 returnCode = E_OK;
\r
1337 case DEM_PRE_DEBOUNCE_FREQUENCY_BASED:
\r
1338 case DEM_PRE_DEBOUNCE_TIME_BASED:
\r
1339 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1343 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_PARAM_DATA);
\r
1349 return returnCode;
\r
1354 * Procedure: setOperationCycleState
\r
1355 * Description: Change the operation state of "operationCycleId" to "cycleState" and updates stored
\r
1356 * event connected to this cycle id.
\r
1357 * Returns E_OK if operation was successful else E_NOT_OK.
\r
1359 static Std_ReturnType setOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState) /** @req DEM338 */
\r
1362 Std_ReturnType returnCode = E_OK;
\r
1364 if (operationCycleId < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1365 switch (cycleState)
\r
1367 case DEM_CYCLE_STATE_START:
\r
1368 operationCycleStateList[operationCycleId] = cycleState;
\r
1369 // Lookup event ID
\r
1370 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1371 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1372 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED_THIS_OPERATION_CYCLE;
\r
1373 eventStatusBuffer[i].eventStatusExtended |= DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
1378 case DEM_CYCLE_STATE_END:
\r
1379 operationCycleStateList[operationCycleId] = cycleState;
\r
1380 // Lookup event ID
\r
1381 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1382 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1383 if ((!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_FAILED_THIS_OPERATION_CYCLE)) && (!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE))) {
\r
1384 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_PENDING_DTC; // Clear pendingDTC bit /** @req DEM379.PendingClear
\r
1390 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
1391 returnCode = E_NOT_OK;
\r
1396 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
1397 returnCode = E_NOT_OK;
\r
1400 return returnCode;
\r
1404 //==============================================================================//
\r
1406 // E X T E R N A L F U N C T I O N S //
\r
1408 //==============================================================================//
\r
1410 /*********************************************
\r
1411 * Interface for upper layer modules (8.3.1) *
\r
1412 *********************************************/
\r
1415 * Procedure: Dem_GetVersionInfo
\r
1418 // Defined in Dem.h
\r
1421 /***********************************************
\r
1422 * Interface ECU State Manager <-> DEM (8.3.2) *
\r
1423 ***********************************************/
\r
1426 * Procedure: Dem_PreInit
\r
1429 void Dem_PreInit(void)
\r
1431 /** @req DEM180 */
\r
1434 VALIDATE_NO_RV(DEM_Config.ConfigSet != NULL, DEM_PREINIT_ID, DEM_E_CONFIG_PTR_INVALID);
\r
1436 configSet = DEM_Config.ConfigSet;
\r
1438 // Initializion of operation cycle states.
\r
1439 for (i = 0; i < DEM_OPERATION_CYCLE_ID_ENDMARK; i++) {
\r
1440 operationCycleStateList[i] = DEM_CYCLE_STATE_END;
\r
1443 // Initialize the event status buffer
\r
1444 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1445 eventStatusBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1446 eventStatusBuffer[i].eventParamRef = NULL;
\r
1447 eventStatusBuffer[i].faultDetectionCounter = 0;
\r
1448 eventStatusBuffer[i].occurrence = 0;
\r
1449 eventStatusBuffer[i].eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1450 eventStatusBuffer[i].errorStatusChanged = FALSE;
\r
1453 // Initialize the pre init buffers
\r
1454 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1455 preInitFreezeFrameBuffer[i].checksum = 0;
\r
1456 preInitFreezeFrameBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1457 preInitFreezeFrameBuffer[i].occurrence = 0;
\r
1458 preInitFreezeFrameBuffer[i].dataSize = 0;
\r
1459 for (j = 0; j < DEM_MAX_SIZE_FF_DATA;j++){
\r
1460 preInitFreezeFrameBuffer[i].data[j] = 0;
\r
1464 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1465 preInitExtDataBuffer[i].checksum = 0;
\r
1466 preInitExtDataBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1467 preInitExtDataBuffer[i].dataSize = 0;
\r
1468 for (j = 0; j < DEM_MAX_SIZE_EXT_DATA;j++){
\r
1469 preInitExtDataBuffer[i].data[j] = 0;
\r
1473 disableDtcStorage.storageDisabled = FALSE;
\r
1475 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_START); /** @req DEM047 */
\r
1477 demState = DEM_PREINITIALIZED;
\r
1482 * Procedure: Dem_Init
\r
1485 void Dem_Init(void)
\r
1488 ChecksumType cSum;
\r
1489 const Dem_EventParameterType *eventParam;
\r
1492 * Validate and read out saved error log from non volatile memory
\r
1495 // Validate event records stored in primary memory
\r
1496 for (i = 0; i < DEM_MAX_NUMBER_EVENT_PRI_MEM; i++) {
\r
1497 cSum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
1498 if ((cSum != priMemEventBuffer[i].checksum) || (priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1499 // Unlegal record, clear the record
\r
1500 memset(&priMemEventBuffer[i], 0, sizeof(EventRecType));
\r
1503 // Valid, update current status
\r
1504 mergeEventStatusRec(&priMemEventBuffer[i]);
\r
1506 // Update occurrence counter on pre init stored freeze frames
\r
1507 updateFreezeFrameOccurrencePreInit(&priMemEventBuffer[i]);
\r
1511 // Validate extended data records stored in primary memory
\r
1512 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM; i++) {
\r
1513 cSum = calcChecksum(&priMemExtDataBuffer[i], sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
1514 if ((cSum != priMemExtDataBuffer[i].checksum) || (priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1515 // Unlegal record, clear the record
\r
1516 memset(&priMemExtDataBuffer[i], 0, sizeof(ExtDataRecType));
\r
1520 // Validate freeze frame records stored in primary memory
\r
1521 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++) {
\r
1522 cSum = calcChecksum(&priMemFreezeFrameBuffer[i], sizeof(FreezeFrameRecType)-sizeof(ChecksumType));
\r
1523 if ((cSum != priMemFreezeFrameBuffer[i].checksum) || (priMemFreezeFrameBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1524 // Unlegal record, clear the record
\r
1525 memset(&priMemFreezeFrameBuffer[i], 0, sizeof(FreezeFrameRecType));
\r
1530 * Handle errors stored in temporary buffer (if any)
\r
1533 // Transfer updated event data to event memory
\r
1534 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1535 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1536 // Update the event memory
\r
1537 lookupEventIdParameter(eventStatusBuffer[i].eventId, &eventParam);
\r
1538 storeEventEvtMem(eventParam, &eventStatusBuffer[i]);
\r
1542 // Transfer extended data to event memory if necessary
\r
1543 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1544 if (preInitExtDataBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1545 lookupEventIdParameter(preInitExtDataBuffer[i].eventId, &eventParam);
\r
1546 storeExtendedDataEvtMem(eventParam, &preInitExtDataBuffer[i]);
\r
1550 // Transfer freeze frames to event memory
\r
1551 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1552 if (preInitFreezeFrameBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1553 lookupEventIdParameter(preInitFreezeFrameBuffer[i].eventId, &eventParam);
\r
1554 storeFreezeFrameDataEvtMem(eventParam, &preInitFreezeFrameBuffer[i]);
\r
1558 // Init the dtc filter
\r
1559 dtcFilter.dtcStatusMask = DEM_DTC_STATUS_MASK_ALL; // All allowed
\r
1560 dtcFilter.dtcKind = DEM_DTC_KIND_ALL_DTCS; // All kinds of DTCs
\r
1561 dtcFilter.dtcOrigin = DEM_DTC_ORIGIN_PRIMARY_MEMORY; // Primary memory
\r
1562 dtcFilter.filterWithSeverity = DEM_FILTER_WITH_SEVERITY_NO; // No Severity filtering
\r
1563 dtcFilter.dtcSeverityMask = DEM_SEVERITY_NO_SEVERITY; // Not used when filterWithSeverity is FALSE
\r
1564 dtcFilter.filterForFaultDetectionCounter = DEM_FILTER_FOR_FDC_NO; // No fault detection counter filtering
\r
1566 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1568 disableDtcStorage.storageDisabled = FALSE;
\r
1570 demState = DEM_INITIALIZED;
\r
1575 * Procedure: Dem_shutdown
\r
1578 void Dem_Shutdown(void)
\r
1580 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_END); /** @req DEM047 */
\r
1582 demState = DEM_UNINITIALIZED; /** @req DEM368 */
\r
1587 * Interface for basic software scheduler
\r
1589 void Dem_MainFunction(void)
\r
1591 /** @req DEM125 */
\r
1596 /***************************************************
\r
1597 * Interface SW-Components via RTE <-> DEM (8.3.3) *
\r
1598 ***************************************************/
\r
1601 * Procedure: Dem_SetEventStatus
\r
1604 Std_ReturnType Dem_SetEventStatus(Dem_EventIdType eventId, Dem_EventStatusType eventStatus) /** @req DEM330 */
\r
1606 Std_ReturnType returnCode = E_OK;
\r
1608 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1610 returnCode = handleEvent(eventId, eventStatus);
\r
1614 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1615 returnCode = E_NOT_OK;
\r
1618 return returnCode;
\r
1623 * Procedure: Dem_ResetEventStatus
\r
1626 Std_ReturnType Dem_ResetEventStatus(Dem_EventIdType eventId) /** @req DEM331 */
\r
1628 Std_ReturnType returnCode = E_OK;
\r
1630 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1632 resetEventStatus(eventId); /** @req DEM186 */
\r
1636 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_RESETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1637 returnCode = E_NOT_OK;
\r
1640 return returnCode;
\r
1645 * Procedure: Dem_GetEventStatus
\r
1648 Std_ReturnType Dem_GetEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended) /** @req DEM332 */
\r
1650 Std_ReturnType returnCode = E_OK;
\r
1652 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1654 getEventStatus(eventId, eventStatusExtended);
\r
1658 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1659 returnCode = E_NOT_OK;
\r
1662 return returnCode;
\r
1667 * Procedure: Dem_GetEventFailed
\r
1670 Std_ReturnType Dem_GetEventFailed(Dem_EventIdType eventId, boolean *eventFailed) /** @req DEM333 */
\r
1672 Std_ReturnType returnCode = E_OK;
\r
1674 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1676 getEventFailed(eventId, eventFailed);
\r
1680 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTFAILED_ID, DEM_E_UNINIT);
\r
1681 returnCode = E_NOT_OK;
\r
1684 return returnCode;
\r
1689 * Procedure: Dem_GetEventTested
\r
1692 Std_ReturnType Dem_GetEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1694 Std_ReturnType returnCode = E_OK;
\r
1696 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1698 getEventTested(eventId, eventTested);
\r
1702 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTTESTED_ID, DEM_E_UNINIT);
\r
1703 returnCode = E_NOT_OK;
\r
1706 return returnCode;
\r
1711 * Procedure: Dem_GetFaultDetectionCounter
\r
1714 Std_ReturnType Dem_GetFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1716 Std_ReturnType returnCode = E_OK;
\r
1718 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1720 returnCode = getFaultDetectionCounter(eventId, counter);
\r
1724 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_UNINIT);
\r
1725 returnCode = E_NOT_OK;
\r
1728 return returnCode;
\r
1733 * Procedure: Dem_SetOperationCycleState
\r
1736 Std_ReturnType Dem_SetOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState)
\r
1738 Std_ReturnType returnCode = E_OK;
\r
1740 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1742 returnCode = setOperationCycleState(operationCycleId, cycleState);
\r
1747 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_UNINIT);
\r
1748 returnCode = E_NOT_OK;
\r
1751 return returnCode;
\r
1756 * Procedure: Dem_GetDTCOfEvent
\r
1759 Std_ReturnType Dem_GetDTCOfEvent(Dem_EventIdType eventId, Dem_DTCKindType dtcKind, uint32* dtcOfEvent)
\r
1761 Std_ReturnType returnCode = E_NO_DTC_AVAILABLE;
\r
1762 const Dem_EventParameterType *eventParam;
\r
1764 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1766 lookupEventIdParameter(eventId, &eventParam);
\r
1768 if (eventParam != NULL) {
\r
1769 if (checkDtcKind(dtcKind, eventParam)) {
\r
1770 if (eventParam->DTCClassRef != NULL) {
\r
1771 *dtcOfEvent = eventParam->DTCClassRef->DTC; /** @req DEM269 */
\r
1772 returnCode = E_OK;
\r
1777 // Event Id not found
\r
1778 returnCode = E_NOT_OK;
\r
1783 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETDTCOFEVENT_ID, DEM_UNINITIALIZED);
\r
1784 returnCode = E_NOT_OK;
\r
1787 return returnCode;
\r
1791 /********************************************
\r
1792 * Interface BSW-Components <-> DEM (8.3.4) *
\r
1793 ********************************************/
\r
1796 * Procedure: Dem_ReportErrorStatus
\r
1799 void Dem_ReportErrorStatus( Dem_EventIdType eventId, Dem_EventStatusType eventStatus ) /** @req DEM107 */
\r
1802 switch (demState) {
\r
1803 case DEM_PREINITIALIZED:
\r
1804 // Update status and check if is to be stored
\r
1805 if ((eventStatus == DEM_EVENT_STATUS_PASSED) || (eventStatus == DEM_EVENT_STATUS_FAILED)) {
\r
1806 handlePreInitEvent(eventId, eventStatus); /** @req DEM168 */
\r
1810 case DEM_INITIALIZED:
\r
1811 (void)handleEvent(eventId, eventStatus); /** @req DEM167 */
\r
1814 case DEM_UNINITIALIZED:
\r
1816 // Uninitialized can not do anything
\r
1817 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_REPORTERRORSTATUS_ID, DEM_E_UNINIT);
\r
1821 } // switch (demState)
\r
1824 /*********************************
\r
1825 * Interface DCM <-> DEM (8.3.5) *
\r
1826 *********************************/
\r
1828 * Procedure: Dem_GetDTCStatusAvailabilityMask
\r
1831 Std_ReturnType Dem_GetDTCStatusAvailabilityMask(uint8 *dtcStatusMask) /** @req DEM014 */
\r
1833 *dtcStatusMask = DEM_DTC_STATUS_AVAILABILITY_MASK; // User configuration mask
\r
1834 *dtcStatusMask &= DEM_TEST_FAILED // Mask with supported bits /** @req DEM060 */
\r
1835 | DEM_TEST_FAILED_THIS_OPERATION_CYCLE
\r
1837 // | DEM_CONFIRMED_DTC TODO: Add support for this bit
\r
1838 | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR
\r
1839 | DEM_TEST_FAILED_SINCE_LAST_CLEAR
\r
1840 | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE
\r
1841 // | DEM_WARNING_INDICATOR_REQUESTED TODO: Add support for this bit
\r
1849 * Procedure: Dem_SetDTCFilter
\r
1852 Dem_ReturnSetDTCFilterType Dem_SetDTCFilter(uint8 dtcStatusMask,
\r
1853 Dem_DTCKindType dtcKind,
\r
1854 Dem_DTCOriginType dtcOrigin,
\r
1855 Dem_FilterWithSeverityType filterWithSeverity,
\r
1856 Dem_DTCSeverityType dtcSeverityMask,
\r
1857 Dem_FilterForFDCType filterForFaultDetectionCounter)
\r
1859 Dem_ReturnSetDTCFilterType returnCode = DEM_FILTER_ACCEPTED;
\r
1861 if (demState == DEM_INITIALIZED) {
\r
1862 // Check dtcKind parameter
\r
1863 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
1865 // Check dtcOrigin parameter
\r
1866 VALIDATE_RV((dtcOrigin == DEM_DTC_ORIGIN_SECONDARY_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_PRIMARY_MEMORY)
\r
1867 || (dtcOrigin == DEM_DTC_ORIGIN_PERMANENT_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_MIRROR_MEMORY), DEM_SETDTCFILTER_ID, DEM_E_PARAM_DATA, DEM_WRONG_FILTER);
\r
1869 // Check filterWithSeverity and dtcSeverityMask parameter
\r
1870 VALIDATE_RV(((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
1871 || ((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES)
\r
1872 && (!(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
1874 // Check filterForFaultDetectionCounter parameter
\r
1875 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
1877 // Yes all parameters correct, set the new filters. /** @req DEM057 */
\r
1878 dtcFilter.dtcStatusMask = dtcStatusMask;
\r
1879 dtcFilter.dtcKind = dtcKind;
\r
1880 dtcFilter.dtcOrigin = dtcOrigin;
\r
1881 dtcFilter.filterWithSeverity = filterWithSeverity;
\r
1882 dtcFilter.dtcSeverityMask = dtcSeverityMask;
\r
1883 dtcFilter.filterForFaultDetectionCounter = filterForFaultDetectionCounter;
\r
1884 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1886 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETDTCFILTER_ID, DEM_E_UNINIT);
\r
1887 returnCode = DEM_WRONG_FILTER;
\r
1890 return returnCode;
\r
1895 * Procedure: Dem_GetStatusOfDTC
\r
1898 Dem_ReturnGetStatusOfDTCType Dem_GetStatusOfDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, Dem_EventStatusExtendedType* status) {
\r
1899 Dem_ReturnGetStatusOfDTCType returnCode = DEM_STATUS_FAILED;
\r
1900 EventStatusRecType *eventRec;
\r
1902 if (demState == DEM_INITIALIZED) {
\r
1903 if (lookupDtcEvent(dtc, &eventRec)) {
\r
1904 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
1905 if (checkDtcOrigin(dtcOrigin,eventRec->eventParamRef)) {
\r
1906 *status = eventRec->eventStatusExtended; /** @req DEM059 */
\r
1907 returnCode = DEM_STATUS_OK;
\r
1910 returnCode = DEM_STATUS_WRONG_DTCORIGIN; /** @req DEM171 */
\r
1914 returnCode = DEM_STATUS_WRONG_DTCKIND;
\r
1918 returnCode = DEM_STATUS_WRONG_DTC; /** @req DEM172 */
\r
1921 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETSTATUSOFDTC_ID, DEM_E_UNINIT);
\r
1922 returnCode = DEM_STATUS_FAILED;
\r
1925 return returnCode;
\r
1930 * Procedure: Dem_GetNumberOfFilteredDtc
\r
1933 Dem_ReturnGetNumberOfFilteredDTCType Dem_GetNumberOfFilteredDtc(uint16 *numberOfFilteredDTC) {
\r
1935 uint16 numberOfFaults = 0;
\r
1936 Dem_ReturnGetNumberOfFilteredDTCType returnCode = DEM_NUMBER_OK;
\r
1938 if (demState == DEM_INITIALIZED) {
\r
1939 //Dem_DisableEventStatusUpdate();
\r
1941 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1942 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1943 if (matchEventWithDtcFilter(&eventStatusBuffer[i])) {
\r
1944 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
1951 //Dem_EnableEventStatusUpdate();
\r
1953 *numberOfFilteredDTC = numberOfFaults; /** @req DEM061 */
\r
1955 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETNUMBEROFFILTEREDDTC_ID, DEM_E_UNINIT);
\r
1956 returnCode = DEM_NUMBER_FAILED;
\r
1959 return returnCode;
\r
1964 * Procedure: Dem_GetNextFilteredDTC
\r
1967 Dem_ReturnGetNextFilteredDTCType Dem_GetNextFilteredDTC(uint32 *dtc, Dem_EventStatusExtendedType *dtcStatus)
\r
1969 Dem_ReturnGetNextFilteredDTCType returnCode = DEM_FILTERED_OK;
\r
1970 boolean dtcFound = FALSE;
\r
1972 if (demState == DEM_INITIALIZED) {
\r
1973 // TODO: This job should be done in an more advanced way according to Dem217
\r
1974 while ((!dtcFound) && (dtcFilter.faultIndex != 0)) {
\r
1975 dtcFilter.faultIndex--;
\r
1976 if (eventStatusBuffer[dtcFilter.faultIndex].eventId != DEM_EVENT_ID_NULL) {
\r
1977 if (matchEventWithDtcFilter(&eventStatusBuffer[dtcFilter.faultIndex])) {
\r
1978 if (eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef != NULL) {
\r
1979 *dtc = eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef->DTC; /** @req DEM216 */
\r
1980 *dtcStatus = eventStatusBuffer[dtcFilter.faultIndex].eventStatusExtended;
\r
1988 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1989 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
1992 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETNEXTFILTEREDDTC_ID, DEM_E_UNINIT);
\r
1993 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
1996 return returnCode;
\r
2001 * Procedure: Dem_GetTranslationType
\r
2004 Dem_ReturnTypeOfDtcSupportedType Dem_GetTranslationType(void)
\r
2006 return DEM_TYPE_OF_DTC_SUPPORTED; /** @req DEM231 */
\r
2011 * Procedure: Dem_ClearDTC
\r
2014 Dem_ReturnClearDTCType Dem_ClearDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin) /** @req DEM009 */
\r
2016 Dem_ReturnClearDTCType returnCode = DEM_CLEAR_OK;
\r
2017 Dem_EventIdType eventId;
\r
2018 const Dem_EventParameterType *eventParam;
\r
2021 if (demState == DEM_INITIALIZED) {
\r
2022 // Loop through the event buffer
\r
2023 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2024 eventId = eventStatusBuffer[i].eventId;
\r
2025 if (eventId != DEM_EVENT_ID_NULL) {
\r
2026 eventParam = eventStatusBuffer[i].eventParamRef;
\r
2027 if (eventParam != NULL) {
\r
2028 if ((DEM_CLEAR_ALL_EVENTS == STD_ON) || (eventParam->DTCClassRef != NULL)) {
\r
2029 if (checkDtcKind(dtcKind, eventParam)) {
\r
2030 if (checkDtcGroup(dtc, eventParam)) {
\r
2031 boolean dtcOriginFound = FALSE;
\r
2032 for (j = 0; (j < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound) ; j++){
\r
2033 dtcOriginFound =(eventParam->EventClass->EventDestination[j] == dtcOrigin);
\r
2035 //if (j-1 < DEM_MAX_NR_OF_EVENT_DESTINATION) {
\r
2036 if (dtcOriginFound) {
\r
2037 // Yes! All conditions met.
\r
2038 switch (dtcOrigin)
\r
2040 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2041 /** @req DEM077 */
\r
2042 deleteEventPriMem(eventParam);
\r
2043 deleteFreezeFrameDataPriMem(eventParam);
\r
2044 deleteExtendedDataPriMem(eventParam);
\r
2045 deleteEventStatusRec(eventParam); // TODO: Shall this be done or just resetting the status?
\r
2048 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2049 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2050 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2051 // Not yet supported
\r
2052 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2053 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2056 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2065 // Fatal error, no event parameters found for the stored event!
\r
2066 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNEXPECTED_EXECUTION);
\r
2071 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNINIT);
\r
2072 returnCode = DEM_CLEAR_FAILED;
\r
2075 return returnCode;
\r
2080 * Procedure: Dem_DisableDTCStorage
\r
2083 Dem_ReturnControlDTCStorageType Dem_DisableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind) /** @req DEM035 */
\r
2085 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2087 if (demState == DEM_INITIALIZED) {
\r
2088 // Check dtcGroup parameter
\r
2089 if (dtcGroup == DEM_DTC_GROUP_ALL_DTCS) {
\r
2090 // Check dtcKind parameter
\r
2091 if ((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS)) {
\r
2092 /** @req DEM079 */
\r
2093 disableDtcStorage.dtcGroup = dtcGroup;
\r
2094 disableDtcStorage.dtcKind = dtcKind;
\r
2095 disableDtcStorage.storageDisabled = TRUE;
\r
2097 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2100 returnCode = DEM_CONTROL_DTC_WRONG_DTCGROUP;
\r
2103 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_DISABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
2104 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2107 return returnCode;
\r
2112 * Procedure: Dem_EnableDTCStorage
\r
2115 Dem_ReturnControlDTCStorageType Dem_EnableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind)
\r
2117 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2119 if (demState == DEM_INITIALIZED) {
\r
2120 // TODO: Behavior is not defined if group or kind do not match active settings, therefore the filter is just switched off.
\r
2121 (void)dtcGroup; (void)dtcKind; // Just to make get rid of PC-Lint warnings
\r
2122 disableDtcStorage.storageDisabled = FALSE; /** @req DEM080 */
\r
2124 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_ENABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
2125 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2128 return returnCode;
\r
2132 * Procedure: Dem_GetExtendedDataRecordByDTC
\r
2135 Dem_ReturnGetExtendedDataRecordByDTCType Dem_GetExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint8 *destBuffer, uint16 *bufSize)
\r
2137 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_RECORD_WRONG_DTC;
\r
2138 EventStatusRecType *eventRec;
\r
2139 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2140 ExtDataRecType *extData;
\r
2141 uint16 posInExtData = 0;
\r
2143 if (demState == DEM_INITIALIZED) {
\r
2144 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2145 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2146 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2147 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2148 if (*bufSize >= extendedDataRecordClass->DataSize) {
\r
2149 switch (dtcOrigin)
\r
2151 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2152 if (lookupExtendedDataPriMem(eventRec->eventId, &extData)) {
\r
2153 // Yes all conditions met, copy the extended data record to destination buffer.
\r
2154 memcpy(destBuffer, &extData->data[posInExtData], extendedDataRecordClass->DataSize); /** @req DEM075 */ // 960 PC-Lint OK
\r
2155 *bufSize = extendedDataRecordClass->DataSize;
\r
2156 returnCode = DEM_RECORD_OK;
\r
2159 // The record number is legal but no record was found for the DTC
\r
2161 returnCode = DEM_RECORD_OK;
\r
2165 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2166 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2167 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2168 // Not yet supported
\r
2169 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2170 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2173 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2178 returnCode = DEM_RECORD_BUFFERSIZE;
\r
2182 returnCode = DEM_RECORD_NUMBER;
\r
2186 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2190 returnCode = DEM_RECORD_DTCKIND;
\r
2194 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
2195 returnCode = DEM_RECORD_WRONG_DTC;
\r
2198 return returnCode;
\r
2203 * Procedure: Dem_GetSizeOfExtendedDataRecordByDTC
\r
2206 Dem_ReturnGetSizeOfExtendedDataRecordByDTCType Dem_GetSizeOfExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint16 *sizeOfExtendedDataRecord)
\r
2208 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2209 EventStatusRecType *eventRec;
\r
2210 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2211 uint16 posInExtData;
\r
2213 if (demState == DEM_INITIALIZED) {
\r
2214 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2215 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2216 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2217 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2218 *sizeOfExtendedDataRecord = extendedDataRecordClass->DataSize; /** @req DEM076 */
\r
2219 returnCode = DEM_GET_SIZEOFEDRBYDTC_OK;
\r
2222 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_RNUM;
\r
2226 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCOR;
\r
2230 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCKI;
\r
2234 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETSIZEOFEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
2235 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2238 return returnCode;
\r
2241 /***********************************
\r
2242 * OBD-specific Interfaces (8.3.6) *
\r
2243 ***********************************/
\r