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 //lint -e957 PC-Lint exception - Used only by DemTest
\r
190 void demZeroPriMemBuffers(void)
\r
192 memset(priMemEventBuffer, 0, sizeof(priMemEventBuffer));
\r
193 memset(priMemFreezeFrameBuffer, 0, sizeof(priMemFreezeFrameBuffer));
\r
194 memset(priMemExtDataBuffer, 0, sizeof(priMemExtDataBuffer));
\r
199 * Procedure: calcChecksum
\r
200 * Description: Calculate checksum over *data to *(data+nrOfBytes-1) area
\r
202 static ChecksumType calcChecksum(void *data, uint16 nrOfBytes)
\r
205 uint8 *byte = (uint8*)data;
\r
206 ChecksumType sum = 0;
\r
208 for (i = 0; i < nrOfBytes; i++) {
\r
217 * Procedure: checkDtcKind
\r
218 * Description: Return TRUE if "dtcKind" match the events DTCKind or "dtcKind"
\r
219 * is "DEM_DTC_KIND_ALL_DTCS" otherwise FALSE.
\r
221 static boolean checkDtcKind(Dem_DTCKindType dtcKind, const Dem_EventParameterType *eventParam)
\r
223 boolean result = FALSE;
\r
225 if (dtcKind == DEM_DTC_KIND_ALL_DTCS) {
\r
229 if (eventParam->DTCClassRef != NULL) {
\r
230 if (eventParam->DTCClassRef->DTCKind == dtcKind) {
\r
240 * Procedure: checkDtcGroup
\r
241 * Description: Return TRUE if "dtc" match the events DTC or "dtc" is
\r
242 * "DEM_DTC_GROUP_ALL_DTCS" otherwise FALSE.
\r
244 static boolean checkDtcGroup(uint32 dtc, const Dem_EventParameterType *eventParam)
\r
246 boolean result = FALSE;
\r
248 if (dtc == DEM_DTC_GROUP_ALL_DTCS) {
\r
252 if (eventParam->DTCClassRef != NULL) {
\r
253 if (eventParam->DTCClassRef->DTC == dtc) {
\r
263 * Procedure: checkDtcOrigin
\r
264 * Description: Return TRUE if "dtcOrigin" match any of the events DTCOrigin otherwise FALSE.
\r
266 static boolean checkDtcOrigin(Dem_DTCOriginType dtcOrigin, const Dem_EventParameterType *eventParam)
\r
268 boolean result = FALSE;
\r
269 boolean dtcOriginFound = FALSE;
\r
272 for (i = 0;(i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound); i++){
\r
273 dtcOriginFound = (eventParam->EventClass->EventDestination[i] == dtcOrigin);
\r
276 if (dtcOriginFound) {
\r
284 * Procedure: checkDtcSeverityMask
\r
285 * Description: Return TRUE if "dtcSeverityMask" match any of the events DTC severity otherwise FALSE.
\r
287 // PC-Lint (715 etc): Remove errors until function is filled.
\r
288 //lint -e{715} Symbol not referenced
\r
289 static boolean checkDtcSeverityMask(Dem_DTCSeverityType dtcSeverityMask, const Dem_EventParameterType *eventParam)
\r
291 boolean result = TRUE;
\r
293 // TODO: This function is optional, may be implemented here.
\r
300 * Procedure: checkDtcFaultDetectionCounterMask
\r
301 * Description: TBD.
\r
303 // PC-Lint (715 etc): Remove errors until function is filled.
\r
304 //lint -e{715} Symbol not referenced
\r
305 static boolean checkDtcFaultDetectionCounter(const Dem_EventParameterType *eventParam)
\r
307 boolean result = TRUE;
\r
309 // TODO: Not implemented yet.
\r
316 * Procedure: lookupEventStatusRec
\r
317 * Description: Returns the pointer to event id parameters of "eventId" in "*eventStatusBuffer",
\r
318 * if not found NULL is returned.
\r
320 static void lookupEventStatusRec(Dem_EventIdType eventId, EventStatusRecType **const eventStatusRec)
\r
323 boolean eventIdFound = FALSE;
\r
325 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!eventIdFound); i++) {
\r
326 eventIdFound = (eventStatusBuffer[i].eventId == eventId);
\r
329 if (eventIdFound) {
\r
330 *eventStatusRec = &eventStatusBuffer[i-1];
\r
332 *eventStatusRec = NULL;
\r
338 * Procedure: lookupEventIdParameter
\r
339 * Description: Returns the pointer to event id parameters of "eventId" in "*eventIdParam",
\r
340 * if not found NULL is returned.
\r
342 static void lookupEventIdParameter(Dem_EventIdType eventId, const Dem_EventParameterType **const eventIdParam)
\r
344 const Dem_EventParameterType *EventIdParamList = configSet->EventParameter;
\r
346 // Lookup the correct event id parameters
\r
348 while ((EventIdParamList[i].EventID != eventId) && (!EventIdParamList[i].Arc_EOL)) {
\r
352 if (!EventIdParamList[i].Arc_EOL) {
\r
353 *eventIdParam = &EventIdParamList[i];
\r
355 *eventIdParam = NULL;
\r
361 * Procedure: preDebounceNone
\r
362 * Description: Returns the result of the debouncing.
\r
364 static Dem_EventStatusType preDebounceNone(const Dem_EventStatusType reportedStatus, const EventStatusRecType* statusRecord) {
\r
365 Dem_EventStatusType returnCode;
\r
366 (void)statusRecord; // Just to get rid of PC-Lint warnings
\r
368 switch (reportedStatus) {
\r
369 case DEM_EVENT_STATUS_FAILED: /** @req DEM091.NoneFailed */
\r
370 case DEM_EVENT_STATUS_PASSED: /** @req DEM091.NonePassed */
\r
371 // Already debounced, do nothing.
\r
375 // TODO: What to do with PREFAIL and PREPASSED on no debouncing?
\r
376 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_NONE_ID, DEM_E_PARAM_DATA);
\r
380 returnCode = reportedStatus;
\r
386 * Procedure: preDebounceCounterBased
\r
387 * Description: Returns the result of the debouncing.
\r
389 static Dem_EventStatusType preDebounceCounterBased(Dem_EventStatusType reportedStatus, EventStatusRecType* statusRecord) {
\r
390 Dem_EventStatusType returnCode;
\r
391 const Dem_PreDebounceCounterBasedType* pdVars = statusRecord->eventParamRef->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceCounterBased;
\r
393 switch (reportedStatus) {
\r
394 case DEM_EVENT_STATUS_PREFAILED:
\r
395 if (statusRecord->faultDetectionCounter < DEBOUNCE_FDC_TEST_FAILED) {
\r
396 if ((pdVars->JumpUp) && (statusRecord->faultDetectionCounter < 0)) {
\r
397 statusRecord->faultDetectionCounter = 0;
\r
399 if (((sint16)statusRecord->faultDetectionCounter + (sint8)pdVars->CountInStepSize) < DEBOUNCE_FDC_TEST_FAILED) {
\r
400 statusRecord->faultDetectionCounter += (sint8)pdVars->CountInStepSize;
\r
402 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED;
\r
408 case DEM_EVENT_STATUS_PREPASSED:
\r
409 if (statusRecord->faultDetectionCounter > DEBOUNCE_FDC_TEST_PASSED) {
\r
410 if ((pdVars->JumpDown) && (statusRecord->faultDetectionCounter > 0)) {
\r
411 statusRecord->faultDetectionCounter = 0;
\r
413 if (((sint16)statusRecord->faultDetectionCounter - (sint8)pdVars->CountOutStepSize) > DEBOUNCE_FDC_TEST_PASSED) {
\r
414 statusRecord->faultDetectionCounter -= (sint8)pdVars->CountOutStepSize;
\r
416 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED;
\r
422 case DEM_EVENT_STATUS_FAILED:
\r
423 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED; /** @req DEM091.CounterFailed */
\r
426 case DEM_EVENT_STATUS_PASSED:
\r
427 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED; /** @req DEM091.CounterPassed */
\r
431 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_COUNTER_BASED_ID, DEM_E_PARAM_DATA);
\r
436 switch (statusRecord->faultDetectionCounter) {
\r
437 case DEBOUNCE_FDC_TEST_FAILED:
\r
438 returnCode = DEM_EVENT_STATUS_FAILED;
\r
441 case DEBOUNCE_FDC_TEST_PASSED:
\r
442 returnCode = DEM_EVENT_STATUS_PASSED;
\r
446 returnCode = reportedStatus;
\r
455 * Procedure: updateEventStatusRec
\r
456 * Description: Update the status of "eventId", if not exist and "createIfNotExist" is
\r
457 * true a new record is created
\r
459 static void updateEventStatusRec(const Dem_EventParameterType *eventParam, Dem_EventStatusType eventStatus, boolean createIfNotExist, EventStatusRecType *eventStatusRec)
\r
461 EventStatusRecType *eventStatusRecPtr;
\r
462 imask_t state = McuE_EnterCriticalSection();
\r
465 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
467 if ((eventStatusRecPtr == NULL) && (createIfNotExist)) {
\r
468 // Search for free position
\r
469 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
471 if (eventStatusRecPtr != NULL) {
\r
472 // Create new event record
\r
473 eventStatusRecPtr->eventId = eventParam->EventID;
\r
474 eventStatusRecPtr->eventParamRef = eventParam;
\r
475 eventStatusRecPtr->faultDetectionCounter = 0;
\r
476 eventStatusRecPtr->occurrence = 0;
\r
477 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
478 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
481 // Error: Event status buffer full
\r
482 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
487 if (eventStatusRecPtr != NULL) {
\r
488 // Handle debouncing
\r
489 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
490 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName) { /** @req DEM004 */ /** @req DEM342 */
\r
491 case DEM_NO_PRE_DEBOUNCE:
\r
492 eventStatus = preDebounceNone(eventStatus, eventStatusRecPtr);
\r
495 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
496 eventStatus = preDebounceCounterBased(eventStatus, eventStatusRecPtr);
\r
500 // Don't know how to handle this.
\r
501 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
506 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
508 // Check test failed
\r
509 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
510 if (!(eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED)) {
\r
511 eventStatusRecPtr->occurrence++;
\r
512 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
514 /** @req DEM036 */ /** @req DEM379.PendingSet */
\r
515 eventStatusRecPtr->eventStatusExtended |= (DEM_TEST_FAILED | DEM_TEST_FAILED_THIS_OPERATION_CYCLE | DEM_TEST_FAILED_SINCE_LAST_CLEAR | DEM_PENDING_DTC);
\r
516 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
519 // Check test passed
\r
520 if (eventStatus == DEM_EVENT_STATUS_PASSED) {
\r
521 if (eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED) {
\r
522 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
525 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED;
\r
526 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
530 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
533 // Copy an empty record to return data
\r
534 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
535 eventStatusRec->faultDetectionCounter = 0;
\r
536 eventStatusRec->occurrence = 0;
\r
537 eventStatusRec->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
538 eventStatusRec->errorStatusChanged = FALSE;
\r
541 McuE_ExitCriticalSection(state);
\r
546 * Procedure: mergeEventStatusRec
\r
547 * Description: Update the occurrence counter of status, if not exist a new record is created
\r
549 static void mergeEventStatusRec(const EventRecType *eventRec)
\r
551 EventStatusRecType *eventStatusRecPtr;
\r
552 imask_t state = McuE_EnterCriticalSection();
\r
555 lookupEventStatusRec(eventRec->eventId, &eventStatusRecPtr);
\r
557 if (eventStatusRecPtr != NULL) {
\r
558 // Update occurrence counter, rest of pre init state is kept.
\r
559 eventStatusRecPtr->occurrence += eventRec->occurrence;
\r
563 // Search for free position
\r
564 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
566 if (eventStatusRecPtr != NULL) {
\r
567 // Create new event, from stored event
\r
568 eventStatusRecPtr->eventId = eventRec->eventId;
\r
569 lookupEventIdParameter(eventRec->eventId, &eventStatusRecPtr->eventParamRef);
\r
570 eventStatusRecPtr->faultDetectionCounter = 0;
\r
571 eventStatusRecPtr->occurrence = eventRec->occurrence;
\r
572 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
573 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
576 // Error: Event status buffer full
\r
577 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_MERGE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
581 McuE_ExitCriticalSection(state);
\r
586 * Procedure: deleteEventStatusRec
\r
587 * Description: Delete the status record of "eventParam->eventId" from "eventStatusBuffer".
\r
589 static void deleteEventStatusRec(const Dem_EventParameterType *eventParam)
\r
591 EventStatusRecType *eventStatusRecPtr;
\r
592 imask_t state = McuE_EnterCriticalSection();
\r
595 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
597 if (eventStatusRecPtr != NULL) {
\r
598 // Delete event record
\r
599 memset(eventStatusRecPtr, 0, sizeof(EventStatusRecType));
\r
602 McuE_ExitCriticalSection(state);
\r
607 * Procedure: getEventStatusRec
\r
608 * Description: Returns the status record of "eventId" in "eventStatusRec"
\r
610 static void getEventStatusRec(Dem_EventIdType eventId, EventStatusRecType *eventStatusRec)
\r
612 EventStatusRecType *eventStatusRecPtr;
\r
615 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
617 if (eventStatusRecPtr != NULL) {
\r
619 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
622 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
628 * Procedure: lookupDtcEvent
\r
629 * Description: Returns TRUE if the DTC was found and "eventStatusRec" points
\r
630 * to the event record found.
\r
632 static boolean lookupDtcEvent(uint32 dtc, EventStatusRecType **eventStatusRec)
\r
634 boolean dtcFound = FALSE;
\r
637 *eventStatusRec = NULL;
\r
639 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!dtcFound); i++) {
\r
640 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
641 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
644 if (eventStatusBuffer[i].eventParamRef->DTCClassRef->DTC == dtc) {
\r
645 *eventStatusRec = &eventStatusBuffer[i];
\r
657 * Procedure: matchEventWithDtcFilter
\r
658 * Description: Returns TRUE if the event pointed by "event" fulfill
\r
659 * the "dtcFilter" global filter settings.
\r
661 static boolean matchEventWithDtcFilter(const EventStatusRecType *eventRec)
\r
663 boolean dtcMatch = FALSE;
\r
666 if ((dtcFilter.dtcStatusMask == DEM_DTC_STATUS_MASK_ALL) || (eventRec->eventStatusExtended & dtcFilter.dtcStatusMask)) {
\r
667 if (eventRec->eventParamRef != NULL) {
\r
670 if (checkDtcKind(dtcFilter.dtcKind, eventRec->eventParamRef)) {
\r
673 if (checkDtcOrigin(dtcFilter.dtcOrigin, eventRec->eventParamRef)) {
\r
676 if ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
677 || ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES) && (checkDtcSeverityMask(dtcFilter.dtcSeverityMask, eventRec->eventParamRef)))) {
\r
679 // Check fault detection counter
\r
680 if ((dtcFilter.filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO)
\r
681 || ((dtcFilter.filterWithSeverity == DEM_FILTER_FOR_FDC_YES) && (checkDtcFaultDetectionCounter(eventRec->eventParamRef)))) {
\r
694 // PC-Lint (715 etc): Remove errors until function is filled.
\r
695 //lint -e{715} Symbol not referenced
\r
696 static void getFreezeFrameData(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
699 freezeFrame->eventId = DEM_EVENT_ID_NULL; // Not supported yet
\r
703 // PC-Lint (715 etc): Remove errors until function is filled.
\r
704 //lint -e{715} Symbol not referenced
\r
705 static void storeFreezeFrameDataPreInit(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
711 // PC-Lint (715 etc): Remove errors until function is filled.
\r
712 //lint -e{715} Symbol not referenced
\r
713 static void updateFreezeFrameOccurrencePreInit(const EventRecType *EventBuffer)
\r
720 * Procedure: getExtendedData
\r
721 * Description: Collects the extended data according to "eventParam" and return it in "extData",
\r
722 * if not found eventId is set to DEM_EVENT_ID_NULL.
\r
724 static void getExtendedData(const Dem_EventParameterType *eventParam, ExtDataRecType *extData)
\r
726 Std_ReturnType callbackReturnCode;
\r
728 uint16 storeIndex = 0;
\r
731 // Clear ext data record
\r
732 memset(extData, 0, sizeof(ExtDataRecType));
\r
734 // Check if any pointer to extended data class
\r
735 if (eventParam->ExtendedDataClassRef != NULL) {
\r
736 // Request extended data and copy it to the buffer
\r
737 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL); i++) {
\r
738 recordSize = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
739 if ((storeIndex + recordSize) <= DEM_MAX_SIZE_EXT_DATA) {
\r
740 callbackReturnCode = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->CallbackGetExtDataRecord(&extData->data[storeIndex]); /** @req DEM282 */
\r
741 if (callbackReturnCode != E_OK) {
\r
742 // Callback data currently not available, clear space.
\r
743 memset(&extData->data[storeIndex], 0xFF, recordSize);
\r
745 storeIndex += recordSize;
\r
748 // Error: Size of extended data record is bigger than reserved space.
\r
749 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GET_EXTENDED_DATA_ID, DEM_E_EXT_DATA_TOO_BIG);
\r
750 break; // Break the loop
\r
755 // Check if any data has been stored
\r
756 if (storeIndex != 0) {
\r
757 extData->eventId = eventParam->EventID;
\r
758 extData->dataSize = storeIndex;
\r
759 extData->checksum = calcChecksum(extData, sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
762 extData->eventId = DEM_EVENT_ID_NULL;
\r
763 extData->dataSize = storeIndex;
\r
764 extData->checksum = 0;
\r
770 * Procedure: storeExtendedDataPreInit
\r
771 * Description: Store the extended data pointed by "extendedData" to the "preInitExtDataBuffer",
\r
772 * if non existent a new entry is created.
\r
774 static void storeExtendedDataPreInit(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
776 boolean eventIdFound = FALSE;
\r
777 boolean eventIdFreePositionFound=FALSE;
\r
779 imask_t state = McuE_EnterCriticalSection();
\r
781 // Check if already stored
\r
782 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) && (!eventIdFound); i++){
\r
783 eventIdFound = (preInitExtDataBuffer[i].eventId == eventParam->EventID);
\r
787 // Yes, overwrite existing
\r
788 memcpy(&preInitExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\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
822 (void)*eventParam; // Currently not used, do this to avoid warning
\r
825 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
826 eventIdFound = (priMemEventBuffer[i].eventId == eventStatus->eventId);
\r
829 if (eventIdFound) {
\r
830 // Update event found
\r
831 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
832 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
835 // Search for free position
\r
836 for (i=0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFreePositionFound); i++){
\r
837 eventIdFreePositionFound = (priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
841 if (eventIdFreePositionFound) {
\r
842 priMemEventBuffer[i-1].eventId = eventStatus->eventId;
\r
843 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
844 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
847 // Error: Pri mem event buffer full
\r
848 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EVENT_PRI_MEM_ID, DEM_E_PRI_MEM_EVENT_BUFF_FULL);
\r
852 McuE_ExitCriticalSection(state);
\r
856 * Procedure: deleteEventPriMem
\r
857 * Description: Delete the event data of "eventParam->eventId" from "priMemEventBuffer".
\r
859 static void deleteEventPriMem(const Dem_EventParameterType *eventParam)
\r
861 boolean eventIdFound = FALSE;
\r
863 imask_t state = McuE_EnterCriticalSection();
\r
867 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
868 eventIdFound = (priMemEventBuffer[i].eventId == eventParam->EventID);
\r
871 if (eventIdFound) {
\r
872 // Delete event found
\r
873 memset(&priMemEventBuffer[i-1], 0, sizeof(EventRecType));
\r
876 McuE_ExitCriticalSection(state);
\r
880 * Procedure: storeEventEvtMem
\r
881 * Description: Store the event data of "eventStatus->eventId" in event memory according to
\r
882 * "eventParam" destination option.
\r
884 static void storeEventEvtMem(const Dem_EventParameterType *eventParam, const EventStatusRecType *eventStatus)
\r
888 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION)
\r
889 && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
890 switch (eventParam->EventClass->EventDestination[i])
\r
892 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
893 storeEventPriMem(eventParam, eventStatus); /** @req DEM010 */
\r
896 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
897 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
898 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
899 // Not yet supported
\r
900 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
910 * Procedure: storeExtendedDataPriMem
\r
911 * Description: Store the extended data pointed by "extendedData" to the "priMemExtDataBuffer",
\r
912 * if non existent a new entry is created.
\r
914 static void storeExtendedDataPriMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData) /** @req DEM041 */
\r
916 boolean eventIdFound = FALSE;
\r
917 boolean eventIdFreePositionFound=FALSE;
\r
919 imask_t state = McuE_EnterCriticalSection();
\r
921 // Check if already stored
\r
922 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
923 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
926 if (eventIdFound) {
\r
927 // Yes, overwrite existing
\r
928 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
931 // No, lookup first free position
\r
932 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFreePositionFound); i++){
\r
933 eventIdFreePositionFound = (priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
935 if (eventIdFreePositionFound) {
\r
936 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
939 // Error: Pri mem extended data buffer full
\r
940 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRI_MEM_ID, DEM_E_PRI_MEM_EXT_DATA_BUFF_FULL);
\r
944 McuE_ExitCriticalSection(state);
\r
948 * Procedure: deleteExtendedDataPriMem
\r
949 * Description: Delete the extended data of "eventParam->eventId" from "priMemExtDataBuffer".
\r
951 static void deleteExtendedDataPriMem(const Dem_EventParameterType *eventParam)
\r
953 boolean eventIdFound = FALSE;
\r
955 imask_t state = McuE_EnterCriticalSection();
\r
957 // Check if already stored
\r
958 for (i = 0;(i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
959 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
962 if (eventIdFound) {
\r
963 // Yes, clear record
\r
964 memset(&priMemExtDataBuffer[i-1], 0, sizeof(ExtDataRecType));
\r
967 McuE_ExitCriticalSection(state);
\r
971 * Procedure: storeExtendedDataEvtMem
\r
972 * Description: Store the extended data in event memory according to
\r
973 * "eventParam" destination option
\r
975 static void storeExtendedDataEvtMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
979 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
980 switch (eventParam->EventClass->EventDestination[i])
\r
982 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
983 storeExtendedDataPriMem(eventParam, extendedData);
\r
986 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
987 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
988 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
989 // Not yet supported
\r
990 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1001 * Procedure: lookupExtendedDataRecNumParam
\r
1002 * Description: Returns TRUE if the requested extended data number was found among the configured records for the event.
\r
1003 * "extDataRecClassPtr" returns a pointer to the record class, "posInExtData" returns the position in stored extended data.
\r
1005 static boolean lookupExtendedDataRecNumParam(uint8 extendedDataNumber, const Dem_EventParameterType *eventParam, Dem_ExtendedDataRecordClassType const **extDataRecClassPtr, uint16 *posInExtData)
\r
1007 boolean recNumFound = FALSE;
\r
1009 if (eventParam->ExtendedDataClassRef != NULL) {
\r
1010 uint16 byteCnt = 0;
\r
1013 // Request extended data and copy it to the buffer
\r
1014 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL) && (!recNumFound); i++) {
\r
1015 if (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->RecordNumber == extendedDataNumber) {
\r
1016 *extDataRecClassPtr = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i];
\r
1017 *posInExtData = byteCnt;
\r
1018 recNumFound = TRUE;
\r
1020 byteCnt += eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
1024 return recNumFound;
\r
1029 * Procedure: lookupExtendedDataPriMem
\r
1030 * Description: Returns TRUE if the requested event id is found, "extData" points to the found data.
\r
1032 static boolean lookupExtendedDataPriMem(Dem_EventIdType eventId, ExtDataRecType **extData)
\r
1034 boolean eventIdFound = FALSE;
\r
1037 // Lookup corresponding extended data
\r
1038 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++) {
\r
1039 eventIdFound = (priMemExtDataBuffer[i].eventId == eventId);
\r
1042 if (eventIdFound) {
\r
1043 // Yes, return pointer
\r
1044 *extData = &priMemExtDataBuffer[i-1];
\r
1047 return eventIdFound;
\r
1050 // PC-Lint (715 etc): Remove errors until function is filled.
\r
1051 //lint -e{715} Symbol not referenced
\r
1052 static void storeFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1058 // PC-Lint (715 etc): Remove errors until function is filled.
\r
1059 //lint -e{715} Symbol not referenced
\r
1060 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 //lint --e(506) PC-Lint exception Misra 13.7, 14.1 Allow configuration variables in boolean expression
\r
2029 //lint --e(774) PC-Lint exception Related to MISRA 13.7
\r
2030 if ((DEM_CLEAR_ALL_EVENTS == STD_ON) || (eventParam->DTCClassRef != NULL)) {
\r
2031 if (checkDtcKind(dtcKind, eventParam)) {
\r
2032 if (checkDtcGroup(dtc, eventParam)) {
\r
2033 boolean dtcOriginFound = FALSE;
\r
2034 for (j = 0; (j < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound) ; j++){
\r
2035 dtcOriginFound =(eventParam->EventClass->EventDestination[j] == dtcOrigin);
\r
2037 //if (j-1 < DEM_MAX_NR_OF_EVENT_DESTINATION) {
\r
2038 if (dtcOriginFound) {
\r
2039 // Yes! All conditions met.
\r
2040 switch (dtcOrigin)
\r
2042 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2043 /** @req DEM077 */
\r
2044 deleteEventPriMem(eventParam);
\r
2045 deleteFreezeFrameDataPriMem(eventParam);
\r
2046 deleteExtendedDataPriMem(eventParam);
\r
2047 deleteEventStatusRec(eventParam); // TODO: Shall this be done or just resetting the status?
\r
2050 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2051 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2052 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2053 // Not yet supported
\r
2054 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2055 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2058 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2067 // Fatal error, no event parameters found for the stored event!
\r
2068 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNEXPECTED_EXECUTION);
\r
2073 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNINIT);
\r
2074 returnCode = DEM_CLEAR_FAILED;
\r
2077 return returnCode;
\r
2082 * Procedure: Dem_DisableDTCStorage
\r
2085 Dem_ReturnControlDTCStorageType Dem_DisableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind) /** @req DEM035 */
\r
2087 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2089 if (demState == DEM_INITIALIZED) {
\r
2090 // Check dtcGroup parameter
\r
2091 if (dtcGroup == DEM_DTC_GROUP_ALL_DTCS) {
\r
2092 // Check dtcKind parameter
\r
2093 if ((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS)) {
\r
2094 /** @req DEM079 */
\r
2095 disableDtcStorage.dtcGroup = dtcGroup;
\r
2096 disableDtcStorage.dtcKind = dtcKind;
\r
2097 disableDtcStorage.storageDisabled = TRUE;
\r
2099 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2102 returnCode = DEM_CONTROL_DTC_WRONG_DTCGROUP;
\r
2105 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_DISABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
2106 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2109 return returnCode;
\r
2114 * Procedure: Dem_EnableDTCStorage
\r
2117 Dem_ReturnControlDTCStorageType Dem_EnableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind)
\r
2119 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2121 if (demState == DEM_INITIALIZED) {
\r
2122 // TODO: Behavior is not defined if group or kind do not match active settings, therefore the filter is just switched off.
\r
2123 (void)dtcGroup; (void)dtcKind; // Just to make get rid of PC-Lint warnings
\r
2124 disableDtcStorage.storageDisabled = FALSE; /** @req DEM080 */
\r
2126 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_ENABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
2127 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2130 return returnCode;
\r
2134 * Procedure: Dem_GetExtendedDataRecordByDTC
\r
2137 Dem_ReturnGetExtendedDataRecordByDTCType Dem_GetExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint8 *destBuffer, uint16 *bufSize)
\r
2139 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_RECORD_WRONG_DTC;
\r
2140 EventStatusRecType *eventRec;
\r
2141 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2142 ExtDataRecType *extData;
\r
2143 uint16 posInExtData = 0;
\r
2145 if (demState == DEM_INITIALIZED) {
\r
2146 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2147 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2148 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2149 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2150 if (*bufSize >= extendedDataRecordClass->DataSize) {
\r
2151 switch (dtcOrigin)
\r
2153 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2154 if (lookupExtendedDataPriMem(eventRec->eventId, &extData)) {
\r
2155 // Yes all conditions met, copy the extended data record to destination buffer.
\r
2156 memcpy(destBuffer, &extData->data[posInExtData], extendedDataRecordClass->DataSize); /** @req DEM075 */
\r
2157 *bufSize = extendedDataRecordClass->DataSize;
\r
2158 returnCode = DEM_RECORD_OK;
\r
2161 // The record number is legal but no record was found for the DTC
\r
2163 returnCode = DEM_RECORD_OK;
\r
2167 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2168 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2169 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2170 // Not yet supported
\r
2171 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2172 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2175 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2180 returnCode = DEM_RECORD_BUFFERSIZE;
\r
2184 returnCode = DEM_RECORD_NUMBER;
\r
2188 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2192 returnCode = DEM_RECORD_DTCKIND;
\r
2196 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
2197 returnCode = DEM_RECORD_WRONG_DTC;
\r
2200 return returnCode;
\r
2205 * Procedure: Dem_GetSizeOfExtendedDataRecordByDTC
\r
2208 Dem_ReturnGetSizeOfExtendedDataRecordByDTCType Dem_GetSizeOfExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint16 *sizeOfExtendedDataRecord)
\r
2210 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2211 EventStatusRecType *eventRec;
\r
2212 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2213 uint16 posInExtData;
\r
2215 if (demState == DEM_INITIALIZED) {
\r
2216 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2217 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2218 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2219 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2220 *sizeOfExtendedDataRecord = extendedDataRecordClass->DataSize; /** @req DEM076 */
\r
2221 returnCode = DEM_GET_SIZEOFEDRBYDTC_OK;
\r
2224 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_RNUM;
\r
2228 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCOR;
\r
2232 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCKI;
\r
2236 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETSIZEOFEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
2237 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2240 return returnCode;
\r
2243 /***********************************
\r
2244 * OBD-specific Interfaces (8.3.6) *
\r
2245 ***********************************/
\r