1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\r
6 * This source code is free software; you can redistribute it and/or modify it
\r
7 * under the terms of the GNU General Public License version 2 as published by the
\r
8 * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
\r
10 * This program is distributed in the hope that it will be useful, but
\r
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\r
14 * -------------------------------- Arctic Core ------------------------------*/
\r
16 // 904 PC-Lint MISRA 14.7: OK. Allow VALIDATE, VALIDATE_RV and VALIDATE_NO_RV to return value.
\r
17 //lint -emacro(904,VALIDATE_RV,VALIDATE_NO_RV,VALIDATE)
\r
18 // 522 PC-Lint exception for empty functions
\r
19 //lint -esym(522,storeFreezeFrameDataEvtMem)
\r
20 //lint -esym(522,deleteFreezeFrameDataPriMem)
\r
21 //lint -esym(522,storeFreezeFrameDataPreInit)
\r
22 //lint -esym(522,storeFreezeFrameDataPriMem)
\r
23 //lint -esym(522,updateFreezeFrameOccurrencePreInit)
\r
27 * General requirements
\r
30 /** @req DEM151.partially */
\r
32 /** @req DEM013.14229-1 */
\r
35 /** @req DEM113 */ /** @req DEM174 */
\r
49 //#include "SchM_Dem.h"
\r
56 #define DEBOUNCE_FDC_TEST_FAILED 127
\r
57 #define DEBOUNCE_FDC_TEST_PASSED -128
\r
59 #if ( DEM_DEV_ERROR_DETECT == STD_ON )
\r
62 #define VALIDATE_RV(_exp,_api,_err,_rv ) \
\r
64 Det_ReportError(MODULE_ID_DEM, 0, _api, _err); \
\r
68 #define VALIDATE_NO_RV(_exp,_api,_err ) \
\r
70 Det_ReportError(MODULE_ID_DEM, 0, _api, _err); \
\r
73 #define DET_REPORTERROR(_x,_y,_z,_q) Det_ReportError(_x, _y, _z, _q)
\r
76 #define VALIDATE_RV(_exp,_api,_err,_rv )
\r
77 #define VALIDATE_NO_RV(_exp,_api,_err )
\r
78 #define DET_REPORTERROR(_x,_y,_z,_q)
\r
81 #if (DEM_OBD_SUPPORT == STD_ON)
\r
82 #error "DEM_OBD_SUPPORT is set to STD_ON, this is not supported by the code."
\r
85 #if (DEM_PTO_SUPPORT == STD_ON)
\r
86 #error "DEM_PTO_SUPPORT is set to STD_ON, this is not supported by the code."
\r
89 #if (DEM_TYPE_OF_DTC_SUPPORTED != 0x01)
\r
90 #error "DEM_TYPE_OF_DTC_SUPPORTED is not set to 1 (ISO14229-1), only ISO14229-1 is currently supported by the code."
\r
98 typedef uint16 ChecksumType;
\r
102 Dem_EventStatusExtendedType dtcStatusMask;
\r
103 Dem_DTCKindType dtcKind;
\r
104 Dem_DTCOriginType dtcOrigin;
\r
105 Dem_FilterWithSeverityType filterWithSeverity;
\r
106 Dem_DTCSeverityType dtcSeverityMask;
\r
107 Dem_FilterForFDCType filterForFaultDetectionCounter;
\r
111 // DisableDtcStorageType
\r
113 boolean storageDisabled;
\r
114 Dem_DTCGroupType dtcGroup;
\r
115 Dem_DTCKindType dtcKind;
\r
116 } DisableDtcStorageType;
\r
118 // For keeping track of the events status
\r
120 Dem_EventIdType eventId;
\r
121 const Dem_EventParameterType *eventParamRef;
\r
122 sint8 faultDetectionCounter;
\r
123 uint16 occurrence; /** @req DEM011 */
\r
124 Dem_EventStatusExtendedType eventStatusExtended; /** @req DEM006 */
\r
125 boolean errorStatusChanged;
\r
126 } EventStatusRecType;
\r
129 // Types for storing different event data on event memory
\r
131 Dem_EventIdType eventId;
\r
133 ChecksumType checksum;
\r
137 Dem_EventIdType eventId;
\r
140 sint8 data[DEM_MAX_SIZE_FF_DATA];
\r
141 ChecksumType checksum;
\r
142 } FreezeFrameRecType;
\r
145 Dem_EventIdType eventId;
\r
147 uint8 data[DEM_MAX_SIZE_EXT_DATA];
\r
148 ChecksumType checksum;
\r
155 DEM_UNINITIALIZED = 0,
\r
156 DEM_PREINITIALIZED,
\r
158 } Dem_StateType; /** @req DEM169 */
\r
161 static Dem_StateType demState = DEM_UNINITIALIZED;
\r
163 // Help pointer to configuration set
\r
164 static const Dem_ConfigSetType *configSet;
\r
167 * Allocation of DTC filter parameters
\r
169 static DtcFilterType dtcFilter;
\r
172 * Allocation of Disable/Enable DTC storage parameters
\r
174 static DisableDtcStorageType disableDtcStorage;
\r
177 * Allocation of operation cycle state list
\r
179 static Dem_OperationCycleStateType operationCycleStateList[DEM_OPERATION_CYCLE_ID_ENDMARK];
\r
182 * Allocation of local event status buffer
\r
184 static EventStatusRecType eventStatusBuffer[DEM_MAX_NUMBER_EVENT];
\r
187 * Allocation of pre-init event memory (used between pre-init and init)
\r
190 static FreezeFrameRecType preInitFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRE_INIT];
\r
191 static ExtDataRecType preInitExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRE_INIT];
\r
194 * Allocation of primary event memory ramlog (after init) in uninitialized memory
\r
197 static EventRecType priMemEventBuffer[DEM_MAX_NUMBER_EVENT_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
198 static FreezeFrameRecType priMemFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
199 static ExtDataRecType priMemExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
203 * Procedure: zeroPriMemBuffers
\r
204 * Description: Fill the primary buffers with zeroes
\r
206 //lint -e957 PC-Lint exception - Used only by DemTest
\r
207 void demZeroPriMemBuffers(void)
\r
209 memset(priMemEventBuffer, 0, sizeof(priMemEventBuffer));
\r
210 memset(priMemFreezeFrameBuffer, 0, sizeof(priMemFreezeFrameBuffer));
\r
211 memset(priMemExtDataBuffer, 0, sizeof(priMemExtDataBuffer));
\r
216 * Procedure: calcChecksum
\r
217 * Description: Calculate checksum over *data to *(data+nrOfBytes-1) area
\r
219 static ChecksumType calcChecksum(void *data, uint16 nrOfBytes)
\r
222 uint8 *byte = (uint8*)data;
\r
223 ChecksumType sum = 0;
\r
225 for (i = 0; i < nrOfBytes; i++) {
\r
234 * Procedure: checkDtcKind
\r
235 * Description: Return TRUE if "dtcKind" match the events DTCKind or "dtcKind"
\r
236 * is "DEM_DTC_KIND_ALL_DTCS" otherwise FALSE.
\r
238 static boolean checkDtcKind(Dem_DTCKindType dtcKind, const Dem_EventParameterType *eventParam)
\r
240 boolean result = FALSE;
\r
242 if (dtcKind == DEM_DTC_KIND_ALL_DTCS) {
\r
246 if (eventParam->DTCClassRef != NULL) {
\r
247 if (eventParam->DTCClassRef->DTCKind == dtcKind) {
\r
257 * Procedure: checkDtcGroup
\r
258 * Description: Return TRUE if "dtc" match the events DTC or "dtc" is
\r
259 * "DEM_DTC_GROUP_ALL_DTCS" otherwise FALSE.
\r
261 static boolean checkDtcGroup(uint32 dtc, const Dem_EventParameterType *eventParam)
\r
263 boolean result = FALSE;
\r
265 if (dtc == DEM_DTC_GROUP_ALL_DTCS) {
\r
269 if (eventParam->DTCClassRef != NULL) {
\r
270 if (eventParam->DTCClassRef->DTC == dtc) {
\r
280 * Procedure: checkDtcOrigin
\r
281 * Description: Return TRUE if "dtcOrigin" match any of the events DTCOrigin otherwise FALSE.
\r
283 static boolean checkDtcOrigin(Dem_DTCOriginType dtcOrigin, const Dem_EventParameterType *eventParam)
\r
285 boolean result = FALSE;
\r
286 boolean dtcOriginFound = FALSE;
\r
289 for (i = 0;(i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound); i++){
\r
290 dtcOriginFound = (eventParam->EventClass->EventDestination[i] == dtcOrigin);
\r
293 if (dtcOriginFound) {
\r
301 * Procedure: checkDtcSeverityMask
\r
302 * Description: Return TRUE if "dtcSeverityMask" match any of the events DTC severity otherwise FALSE.
\r
304 // PC-Lint (715 etc): Remove errors until function is filled.
\r
305 //lint -e{715} Symbol not referenced
\r
306 static boolean checkDtcSeverityMask(Dem_DTCSeverityType dtcSeverityMask, const Dem_EventParameterType *eventParam)
\r
308 boolean result = TRUE;
\r
310 // TODO: This function is optional, may be implemented here.
\r
317 * Procedure: checkDtcFaultDetectionCounterMask
\r
318 * Description: TBD.
\r
320 // PC-Lint (715 etc): Remove errors until function is filled.
\r
321 //lint -e{715} Symbol not referenced
\r
322 static boolean checkDtcFaultDetectionCounter(const Dem_EventParameterType *eventParam)
\r
324 boolean result = TRUE;
\r
326 // TODO: Not implemented yet.
\r
333 * Procedure: lookupEventStatusRec
\r
334 * Description: Returns the pointer to event id parameters of "eventId" in "*eventStatusBuffer",
\r
335 * if not found NULL is returned.
\r
337 static void lookupEventStatusRec(Dem_EventIdType eventId, EventStatusRecType **const eventStatusRec)
\r
340 boolean eventIdFound = FALSE;
\r
342 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!eventIdFound); i++) {
\r
343 eventIdFound = (eventStatusBuffer[i].eventId == eventId);
\r
346 if (eventIdFound) {
\r
347 *eventStatusRec = &eventStatusBuffer[i-1];
\r
349 *eventStatusRec = NULL;
\r
355 * Procedure: lookupEventIdParameter
\r
356 * Description: Returns the pointer to event id parameters of "eventId" in "*eventIdParam",
\r
357 * if not found NULL is returned.
\r
359 static void lookupEventIdParameter(Dem_EventIdType eventId, const Dem_EventParameterType **const eventIdParam)
\r
361 const Dem_EventParameterType *EventIdParamList = configSet->EventParameter;
\r
363 // Lookup the correct event id parameters
\r
365 while ((EventIdParamList[i].EventID != eventId) && (!EventIdParamList[i].Arc_EOL)) {
\r
369 if (!EventIdParamList[i].Arc_EOL) {
\r
370 *eventIdParam = &EventIdParamList[i];
\r
372 *eventIdParam = NULL;
\r
378 * Procedure: preDebounceNone
\r
379 * Description: Returns the result of the debouncing.
\r
381 static Dem_EventStatusType preDebounceNone(const Dem_EventStatusType reportedStatus, const EventStatusRecType* statusRecord) {
\r
382 Dem_EventStatusType returnCode;
\r
383 (void)statusRecord; // Just to get rid of PC-Lint warnings
\r
385 switch (reportedStatus) {
\r
386 case DEM_EVENT_STATUS_FAILED: /** @req DEM091.NoneFailed */
\r
387 case DEM_EVENT_STATUS_PASSED: /** @req DEM091.NonePassed */
\r
388 // Already debounced, do nothing.
\r
392 // TODO: What to do with PREFAIL and PREPASSED on no debouncing?
\r
393 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_NONE_ID, DEM_E_PARAM_DATA);
\r
397 returnCode = reportedStatus;
\r
403 * Procedure: preDebounceCounterBased
\r
404 * Description: Returns the result of the debouncing.
\r
406 static Dem_EventStatusType preDebounceCounterBased(Dem_EventStatusType reportedStatus, EventStatusRecType* statusRecord) {
\r
407 Dem_EventStatusType returnCode;
\r
408 const Dem_PreDebounceCounterBasedType* pdVars = statusRecord->eventParamRef->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceCounterBased;
\r
410 switch (reportedStatus) {
\r
411 case DEM_EVENT_STATUS_PREFAILED:
\r
412 if (statusRecord->faultDetectionCounter < DEBOUNCE_FDC_TEST_FAILED) {
\r
413 if ((pdVars->JumpUp) && (statusRecord->faultDetectionCounter < 0)) {
\r
414 statusRecord->faultDetectionCounter = 0;
\r
416 if (((sint16)statusRecord->faultDetectionCounter + (sint8)pdVars->CountInStepSize) < DEBOUNCE_FDC_TEST_FAILED) {
\r
417 statusRecord->faultDetectionCounter += (sint8)pdVars->CountInStepSize;
\r
419 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED;
\r
425 case DEM_EVENT_STATUS_PREPASSED:
\r
426 if (statusRecord->faultDetectionCounter > DEBOUNCE_FDC_TEST_PASSED) {
\r
427 if ((pdVars->JumpDown) && (statusRecord->faultDetectionCounter > 0)) {
\r
428 statusRecord->faultDetectionCounter = 0;
\r
430 if (((sint16)statusRecord->faultDetectionCounter - (sint8)pdVars->CountOutStepSize) > DEBOUNCE_FDC_TEST_PASSED) {
\r
431 statusRecord->faultDetectionCounter -= (sint8)pdVars->CountOutStepSize;
\r
433 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED;
\r
439 case DEM_EVENT_STATUS_FAILED:
\r
440 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED; /** @req DEM091.CounterFailed */
\r
443 case DEM_EVENT_STATUS_PASSED:
\r
444 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED; /** @req DEM091.CounterPassed */
\r
448 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_COUNTER_BASED_ID, DEM_E_PARAM_DATA);
\r
453 switch (statusRecord->faultDetectionCounter) {
\r
454 case DEBOUNCE_FDC_TEST_FAILED:
\r
455 returnCode = DEM_EVENT_STATUS_FAILED;
\r
458 case DEBOUNCE_FDC_TEST_PASSED:
\r
459 returnCode = DEM_EVENT_STATUS_PASSED;
\r
463 returnCode = reportedStatus;
\r
472 * Procedure: updateEventStatusRec
\r
473 * Description: Update the status of "eventId", if not exist and "createIfNotExist" is
\r
474 * true a new record is created
\r
476 static void updateEventStatusRec(const Dem_EventParameterType *eventParam, Dem_EventStatusType eventStatus, boolean createIfNotExist, EventStatusRecType *eventStatusRec)
\r
478 EventStatusRecType *eventStatusRecPtr;
\r
483 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
485 if ((eventStatusRecPtr == NULL) && (createIfNotExist)) {
\r
486 // Search for free position
\r
487 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
489 if (eventStatusRecPtr != NULL) {
\r
490 // Create new event record
\r
491 eventStatusRecPtr->eventId = eventParam->EventID;
\r
492 eventStatusRecPtr->eventParamRef = eventParam;
\r
493 eventStatusRecPtr->faultDetectionCounter = 0;
\r
494 eventStatusRecPtr->occurrence = 0;
\r
495 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
496 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
499 // Error: Event status buffer full
\r
500 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
505 if (eventStatusRecPtr != NULL) {
\r
506 // Handle debouncing
\r
507 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
508 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName) { /** @req DEM004 */ /** @req DEM342 */
\r
509 case DEM_NO_PRE_DEBOUNCE:
\r
510 eventStatus = preDebounceNone(eventStatus, eventStatusRecPtr);
\r
513 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
514 eventStatus = preDebounceCounterBased(eventStatus, eventStatusRecPtr);
\r
518 // Don't know how to handle this.
\r
519 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
524 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
526 // Check test failed
\r
527 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
528 if (!(eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED)) {
\r
529 eventStatusRecPtr->occurrence++;
\r
530 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
532 /** @req DEM036 */ /** @req DEM379.PendingSet */
\r
533 eventStatusRecPtr->eventStatusExtended |= (DEM_TEST_FAILED | DEM_TEST_FAILED_THIS_OPERATION_CYCLE | DEM_TEST_FAILED_SINCE_LAST_CLEAR | DEM_PENDING_DTC);
\r
534 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
537 // Check test passed
\r
538 if (eventStatus == DEM_EVENT_STATUS_PASSED) {
\r
539 if (eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED) {
\r
540 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
543 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED;
\r
544 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
548 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
551 // Copy an empty record to return data
\r
552 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
553 eventStatusRec->faultDetectionCounter = 0;
\r
554 eventStatusRec->occurrence = 0;
\r
555 eventStatusRec->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
556 eventStatusRec->errorStatusChanged = FALSE;
\r
559 Irq_Restore(state);
\r
564 * Procedure: mergeEventStatusRec
\r
565 * Description: Update the occurrence counter of status, if not exist a new record is created
\r
567 static void mergeEventStatusRec(const EventRecType *eventRec)
\r
569 EventStatusRecType *eventStatusRecPtr;
\r
574 lookupEventStatusRec(eventRec->eventId, &eventStatusRecPtr);
\r
576 if (eventStatusRecPtr != NULL) {
\r
577 // Update occurrence counter, rest of pre init state is kept.
\r
578 eventStatusRecPtr->occurrence += eventRec->occurrence;
\r
582 // Search for free position
\r
583 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
585 if (eventStatusRecPtr != NULL) {
\r
586 // Create new event, from stored event
\r
587 eventStatusRecPtr->eventId = eventRec->eventId;
\r
588 lookupEventIdParameter(eventRec->eventId, &eventStatusRecPtr->eventParamRef);
\r
589 eventStatusRecPtr->faultDetectionCounter = 0;
\r
590 eventStatusRecPtr->occurrence = eventRec->occurrence;
\r
591 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
592 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
595 // Error: Event status buffer full
\r
596 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_MERGE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
600 Irq_Restore(state);
\r
605 * Procedure: deleteEventStatusRec
\r
606 * Description: Delete the status record of "eventParam->eventId" from "eventStatusBuffer".
\r
608 static void deleteEventStatusRec(const Dem_EventParameterType *eventParam)
\r
610 EventStatusRecType *eventStatusRecPtr;
\r
615 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
617 if (eventStatusRecPtr != NULL) {
\r
618 // Delete event record
\r
619 memset(eventStatusRecPtr, 0, sizeof(EventStatusRecType));
\r
622 Irq_Restore(state);
\r
627 * Procedure: getEventStatusRec
\r
628 * Description: Returns the status record of "eventId" in "eventStatusRec"
\r
630 static void getEventStatusRec(Dem_EventIdType eventId, EventStatusRecType *eventStatusRec)
\r
632 EventStatusRecType *eventStatusRecPtr;
\r
635 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
637 if (eventStatusRecPtr != NULL) {
\r
639 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
642 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
648 * Procedure: lookupDtcEvent
\r
649 * Description: Returns TRUE if the DTC was found and "eventStatusRec" points
\r
650 * to the event record found.
\r
652 static boolean lookupDtcEvent(uint32 dtc, EventStatusRecType **eventStatusRec)
\r
654 boolean dtcFound = FALSE;
\r
657 *eventStatusRec = NULL;
\r
659 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!dtcFound); i++) {
\r
660 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
661 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
664 if (eventStatusBuffer[i].eventParamRef->DTCClassRef->DTC == dtc) {
\r
665 *eventStatusRec = &eventStatusBuffer[i];
\r
677 * Procedure: matchEventWithDtcFilter
\r
678 * Description: Returns TRUE if the event pointed by "event" fulfill
\r
679 * the "dtcFilter" global filter settings.
\r
681 static boolean matchEventWithDtcFilter(const EventStatusRecType *eventRec)
\r
683 boolean dtcMatch = FALSE;
\r
686 if ((dtcFilter.dtcStatusMask == DEM_DTC_STATUS_MASK_ALL) || (eventRec->eventStatusExtended & dtcFilter.dtcStatusMask)) {
\r
687 if (eventRec->eventParamRef != NULL) {
\r
690 if (checkDtcKind(dtcFilter.dtcKind, eventRec->eventParamRef)) {
\r
693 if (checkDtcOrigin(dtcFilter.dtcOrigin, eventRec->eventParamRef)) {
\r
696 if ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
697 || ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES) && (checkDtcSeverityMask(dtcFilter.dtcSeverityMask, eventRec->eventParamRef)))) {
\r
699 // Check fault detection counter
\r
700 if ((dtcFilter.filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO)
\r
701 || ((dtcFilter.filterWithSeverity == DEM_FILTER_FOR_FDC_YES) && (checkDtcFaultDetectionCounter(eventRec->eventParamRef)))) {
\r
714 // PC-Lint (715 etc): Remove errors until function is filled.
\r
715 //lint -e{715} Symbol not referenced
\r
716 static void getFreezeFrameData(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
719 freezeFrame->eventId = DEM_EVENT_ID_NULL; // Not supported yet
\r
723 // PC-Lint (715 etc): Remove errors until function is filled.
\r
724 //lint -e{715} Symbol not referenced
\r
725 static void storeFreezeFrameDataPreInit(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
731 // PC-Lint (715 etc): Remove errors until function is filled.
\r
732 //lint -e{715} Symbol not referenced
\r
733 static void updateFreezeFrameOccurrencePreInit(const EventRecType *EventBuffer)
\r
740 * Procedure: getExtendedData
\r
741 * Description: Collects the extended data according to "eventParam" and return it in "extData",
\r
742 * if not found eventId is set to DEM_EVENT_ID_NULL.
\r
744 static void getExtendedData(const Dem_EventParameterType *eventParam, ExtDataRecType *extData)
\r
746 Std_ReturnType callbackReturnCode;
\r
748 uint16 storeIndex = 0;
\r
751 // Clear ext data record
\r
752 memset(extData, 0, sizeof(ExtDataRecType));
\r
754 // Check if any pointer to extended data class
\r
755 if (eventParam->ExtendedDataClassRef != NULL) {
\r
756 // Request extended data and copy it to the buffer
\r
757 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL); i++) {
\r
758 recordSize = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
759 if ((storeIndex + recordSize) <= DEM_MAX_SIZE_EXT_DATA) {
\r
760 callbackReturnCode = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->CallbackGetExtDataRecord(&extData->data[storeIndex]); /** @req DEM282 */
\r
761 if (callbackReturnCode != E_OK) {
\r
762 // Callback data currently not available, clear space.
\r
763 memset(&extData->data[storeIndex], 0xFF, recordSize);
\r
765 storeIndex += recordSize;
\r
768 // Error: Size of extended data record is bigger than reserved space.
\r
769 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GET_EXTENDED_DATA_ID, DEM_E_EXT_DATA_TOO_BIG);
\r
770 break; // Break the loop
\r
775 // Check if any data has been stored
\r
776 if (storeIndex != 0) {
\r
777 extData->eventId = eventParam->EventID;
\r
778 extData->dataSize = storeIndex;
\r
779 extData->checksum = calcChecksum(extData, sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
782 extData->eventId = DEM_EVENT_ID_NULL;
\r
783 extData->dataSize = storeIndex;
\r
784 extData->checksum = 0;
\r
790 * Procedure: storeExtendedDataPreInit
\r
791 * Description: Store the extended data pointed by "extendedData" to the "preInitExtDataBuffer",
\r
792 * if non existent a new entry is created.
\r
794 static void storeExtendedDataPreInit(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
796 boolean eventIdFound = FALSE;
\r
797 boolean eventIdFreePositionFound=FALSE;
\r
802 // Check if already stored
\r
803 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) && (!eventIdFound); i++){
\r
804 eventIdFound = (preInitExtDataBuffer[i].eventId == eventParam->EventID);
\r
808 // Yes, overwrite existing
\r
809 memcpy(&preInitExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
812 // No, lookup first free position
\r
813 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) && (!eventIdFreePositionFound); i++){
\r
814 if(preInitExtDataBuffer[i].eventId ==0){
\r
815 eventIdFreePositionFound=TRUE;
\r
819 if (eventIdFreePositionFound) {
\r
820 memcpy(&preInitExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
823 // Error: Pre init extended data buffer full
\r
824 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRE_INIT_ID, DEM_E_PRE_INIT_EXT_DATA_BUFF_FULL);
\r
828 Irq_Restore(state);
\r
832 * Procedure: storeEventPriMem
\r
833 * Description: Store the event data of "eventStatus->eventId" in "priMemEventBuffer",
\r
834 * if non existent a new entry is created.
\r
836 static void storeEventPriMem(const Dem_EventParameterType *eventParam, const EventStatusRecType *eventStatus)
\r
838 boolean eventIdFound = FALSE;
\r
839 boolean eventIdFreePositionFound=FALSE;
\r
844 (void)*eventParam; // Currently not used, do this to avoid warning
\r
847 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
848 eventIdFound = (priMemEventBuffer[i].eventId == eventStatus->eventId);
\r
851 if (eventIdFound) {
\r
852 // Update event found
\r
853 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
854 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
857 // Search for free position
\r
858 for (i=0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFreePositionFound); i++){
\r
859 eventIdFreePositionFound = (priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
863 if (eventIdFreePositionFound) {
\r
864 priMemEventBuffer[i-1].eventId = eventStatus->eventId;
\r
865 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
866 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
869 // Error: Pri mem event buffer full
\r
870 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EVENT_PRI_MEM_ID, DEM_E_PRI_MEM_EVENT_BUFF_FULL);
\r
874 Irq_Restore(state);
\r
878 * Procedure: deleteEventPriMem
\r
879 * Description: Delete the event data of "eventParam->eventId" from "priMemEventBuffer".
\r
881 static void deleteEventPriMem(const Dem_EventParameterType *eventParam)
\r
883 boolean eventIdFound = FALSE;
\r
890 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
891 eventIdFound = (priMemEventBuffer[i].eventId == eventParam->EventID);
\r
894 if (eventIdFound) {
\r
895 // Delete event found
\r
896 memset(&priMemEventBuffer[i-1], 0, sizeof(EventRecType));
\r
899 Irq_Restore(state);
\r
903 * Procedure: storeEventEvtMem
\r
904 * Description: Store the event data of "eventStatus->eventId" in event memory according to
\r
905 * "eventParam" destination option.
\r
907 static void storeEventEvtMem(const Dem_EventParameterType *eventParam, const EventStatusRecType *eventStatus)
\r
911 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION)
\r
912 && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
913 switch (eventParam->EventClass->EventDestination[i])
\r
915 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
916 storeEventPriMem(eventParam, eventStatus); /** @req DEM010 */
\r
919 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
920 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
921 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
922 // Not yet supported
\r
923 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
933 * Procedure: storeExtendedDataPriMem
\r
934 * Description: Store the extended data pointed by "extendedData" to the "priMemExtDataBuffer",
\r
935 * if non existent a new entry is created.
\r
937 static void storeExtendedDataPriMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData) /** @req DEM041 */
\r
939 boolean eventIdFound = FALSE;
\r
940 boolean eventIdFreePositionFound=FALSE;
\r
945 // Check if already stored
\r
946 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
947 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
950 if (eventIdFound) {
\r
951 // Yes, overwrite existing
\r
952 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
955 // No, lookup first free position
\r
956 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFreePositionFound); i++){
\r
957 eventIdFreePositionFound = (priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
959 if (eventIdFreePositionFound) {
\r
960 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
963 // Error: Pri mem extended data buffer full
\r
964 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRI_MEM_ID, DEM_E_PRI_MEM_EXT_DATA_BUFF_FULL);
\r
968 Irq_Restore(state);
\r
972 * Procedure: deleteExtendedDataPriMem
\r
973 * Description: Delete the extended data of "eventParam->eventId" from "priMemExtDataBuffer".
\r
975 static void deleteExtendedDataPriMem(const Dem_EventParameterType *eventParam)
\r
977 boolean eventIdFound = FALSE;
\r
982 // Check if already stored
\r
983 for (i = 0;(i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
984 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
987 if (eventIdFound) {
\r
988 // Yes, clear record
\r
989 memset(&priMemExtDataBuffer[i-1], 0, sizeof(ExtDataRecType));
\r
992 Irq_Restore(state);
\r
996 * Procedure: storeExtendedDataEvtMem
\r
997 * Description: Store the extended data in event memory according to
\r
998 * "eventParam" destination option
\r
1000 static void storeExtendedDataEvtMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
1004 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
1005 switch (eventParam->EventClass->EventDestination[i])
\r
1007 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1008 storeExtendedDataPriMem(eventParam, extendedData);
\r
1011 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1012 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1013 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1014 // Not yet supported
\r
1015 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1026 * Procedure: lookupExtendedDataRecNumParam
\r
1027 * Description: Returns TRUE if the requested extended data number was found among the configured records for the event.
\r
1028 * "extDataRecClassPtr" returns a pointer to the record class, "posInExtData" returns the position in stored extended data.
\r
1030 static boolean lookupExtendedDataRecNumParam(uint8 extendedDataNumber, const Dem_EventParameterType *eventParam, Dem_ExtendedDataRecordClassType const **extDataRecClassPtr, uint16 *posInExtData)
\r
1032 boolean recNumFound = FALSE;
\r
1034 if (eventParam->ExtendedDataClassRef != NULL) {
\r
1035 uint16 byteCnt = 0;
\r
1038 // Request extended data and copy it to the buffer
\r
1039 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL) && (!recNumFound); i++) {
\r
1040 if (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->RecordNumber == extendedDataNumber) {
\r
1041 *extDataRecClassPtr = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i];
\r
1042 *posInExtData = byteCnt;
\r
1043 recNumFound = TRUE;
\r
1045 byteCnt += eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
1049 return recNumFound;
\r
1054 * Procedure: lookupExtendedDataPriMem
\r
1055 * Description: Returns TRUE if the requested event id is found, "extData" points to the found data.
\r
1057 static boolean lookupExtendedDataPriMem(Dem_EventIdType eventId, ExtDataRecType **extData)
\r
1059 boolean eventIdFound = FALSE;
\r
1062 // Lookup corresponding extended data
\r
1063 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++) {
\r
1064 eventIdFound = (priMemExtDataBuffer[i].eventId == eventId);
\r
1067 if (eventIdFound) {
\r
1068 // Yes, return pointer
\r
1069 *extData = &priMemExtDataBuffer[i-1];
\r
1072 return eventIdFound;
\r
1075 // PC-Lint (715 etc): Remove errors until function is filled.
\r
1076 //lint -e{715} Symbol not referenced
\r
1077 static void storeFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1083 // PC-Lint (715 etc): Remove errors until function is filled.
\r
1084 //lint -e{715} Symbol not referenced
\r
1085 static void deleteFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam)
\r
1092 * Procedure: storeFreezeFrameDataEvtMem
\r
1093 * Description: Store the freeze frame data in event memory according to
\r
1094 * "eventParam" destination option
\r
1096 static void storeFreezeFrameDataEvtMem(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1100 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
1101 switch (eventParam->EventClass->EventDestination[i])
\r
1103 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1104 storeFreezeFrameDataPriMem(eventParam, freezeFrame);
\r
1107 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1108 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1109 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1110 // Not yet supported
\r
1111 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1122 * Procedure: handlePreInitEvent
\r
1123 * Description: Handle the updating of event status and storing of
\r
1124 * event related data in preInit buffers.
\r
1126 static void handlePreInitEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1128 const Dem_EventParameterType *eventParam;
\r
1129 EventStatusRecType eventStatusLocal;
\r
1130 FreezeFrameRecType freezeFrameLocal;
\r
1131 ExtDataRecType extendedDataLocal;
\r
1133 // Find configuration for this event
\r
1134 lookupEventIdParameter(eventId, &eventParam);
\r
1135 if (eventParam != NULL) {
\r
1136 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1137 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1138 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
1139 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1142 updateEventStatusRec(eventParam, eventStatus, FALSE, &eventStatusLocal);
\r
1145 if (eventStatusLocal.errorStatusChanged) {
\r
1147 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1148 // Collect freeze frame data
\r
1149 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1150 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1151 storeFreezeFrameDataPreInit(eventParam, &freezeFrameLocal);
\r
1154 // Collect extended data
\r
1155 getExtendedData(eventParam, &extendedDataLocal);
\r
1156 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1157 storeExtendedDataPreInit(eventParam, &extendedDataLocal);
\r
1163 // Operation cycle not started
\r
1164 // TODO: Report error?
\r
1168 // Operation cycle not set
\r
1169 // TODO: Report error?
\r
1173 // Event ID not configured
\r
1174 // TODO: Report error?
\r
1180 * Procedure: handleEvent
\r
1181 * Description: Handle the updating of event status and storing of
\r
1182 * event related data in event memory.
\r
1184 static Std_ReturnType handleEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1186 Std_ReturnType returnCode = E_OK;
\r
1187 const Dem_EventParameterType *eventParam;
\r
1188 EventStatusRecType eventStatusLocal;
\r
1189 FreezeFrameRecType freezeFrameLocal;
\r
1190 ExtDataRecType extendedDataLocal;
\r
1192 // Find configuration for this event
\r
1193 lookupEventIdParameter(eventId, &eventParam);
\r
1194 if (eventParam != NULL) {
\r
1195 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1196 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1197 if ((!((disableDtcStorage.storageDisabled) && (checkDtcGroup(disableDtcStorage.dtcGroup, eventParam)) && (checkDtcKind(disableDtcStorage.dtcKind, eventParam))))) {
\r
1198 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1199 if (eventStatusLocal.errorStatusChanged) {
\r
1200 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1201 storeEventEvtMem(eventParam, &eventStatusLocal); /** @req DEM184 */
\r
1202 // Collect freeze frame data
\r
1203 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1204 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1205 storeFreezeFrameDataEvtMem(eventParam, &freezeFrameLocal); /** @req DEM190 */
\r
1208 // Collect extended data
\r
1209 getExtendedData(eventParam, &extendedDataLocal);
\r
1210 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL)
\r
1212 storeExtendedDataEvtMem(eventParam, &extendedDataLocal);
\r
1219 // Operation cycle not started
\r
1220 returnCode = E_NOT_OK;
\r
1224 // Operation cycle not set
\r
1225 returnCode = E_NOT_OK;
\r
1229 // Event ID not configured
\r
1230 returnCode = E_NOT_OK;
\r
1233 return returnCode;
\r
1238 * Procedure: resetEventStatus
\r
1239 * Description: Resets the events status of eventId.
\r
1241 static void resetEventStatus(Dem_EventIdType eventId)
\r
1243 EventStatusRecType *eventStatusRecPtr;
\r
1247 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
1248 if (eventStatusRecPtr != NULL) {
\r
1249 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED; /** @req DEM187 */
\r
1252 Irq_Restore(state);
\r
1257 * Procedure: getEventStatus
\r
1258 * Description: Returns the extended event status bitmask of eventId in "eventStatusExtended".
\r
1260 static void getEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended)
\r
1262 EventStatusRecType eventStatusLocal;
\r
1264 // Get recorded status
\r
1265 getEventStatusRec(eventId, &eventStatusLocal);
\r
1266 if (eventStatusLocal.eventId == eventId) {
\r
1267 *eventStatusExtended = eventStatusLocal.eventStatusExtended; /** @req DEM051 */
\r
1270 // Event Id not found, no report received.
\r
1271 *eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1277 * Procedure: getEventFailed
\r
1278 * Description: Returns the TRUE or FALSE of "eventId" in "eventFailed" depending on current status.
\r
1280 static void getEventFailed(Dem_EventIdType eventId, boolean *eventFailed)
\r
1282 EventStatusRecType eventStatusLocal;
\r
1284 // Get recorded status
\r
1285 getEventStatusRec(eventId, &eventStatusLocal);
\r
1286 if (eventStatusLocal.eventId == eventId) {
\r
1287 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) { /** @req DEM052 */
\r
1288 *eventFailed = TRUE;
\r
1291 *eventFailed = FALSE;
\r
1295 // Event Id not found, assume ok.
\r
1296 *eventFailed = FALSE;
\r
1302 * Procedure: getEventTested
\r
1303 * Description: Returns the TRUE or FALSE of "eventId" in "eventTested" depending on
\r
1304 * current status the "test not completed this operation cycle" bit.
\r
1306 static void getEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1308 EventStatusRecType eventStatusLocal;
\r
1310 // Get recorded status
\r
1311 getEventStatusRec(eventId, &eventStatusLocal);
\r
1312 if (eventStatusLocal.eventId == eventId) {
\r
1313 if ( !(eventStatusLocal.eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE)) { /** @req DEM053 */
\r
1314 *eventTested = TRUE;
\r
1317 *eventTested = FALSE;
\r
1321 // Event Id not found, not tested.
\r
1322 *eventTested = FALSE;
\r
1328 * Procedure: getFaultDetectionCounter
\r
1329 * Description: Returns pre debounce counter of "eventId" in "counter" and return value E_OK if
\r
1330 * the counter was available else E_NOT_OK.
\r
1332 static Std_ReturnType getFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1334 Std_ReturnType returnCode = E_NOT_OK;
\r
1335 const Dem_EventParameterType *eventParam;
\r
1337 lookupEventIdParameter(eventId, &eventParam);
\r
1338 if (eventParam != NULL) {
\r
1339 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
1340 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName)
\r
1342 case DEM_NO_PRE_DEBOUNCE:
\r
1343 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal != NULL) {
\r
1344 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc != NULL) {
\r
1345 returnCode = eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc(counter); /** @req DEM204.None */ /** @req DEM264 */ /** @req DEM265 */
\r
1350 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
1352 EventStatusRecType *eventStatusRec;
\r
1354 lookupEventStatusRec(eventId, &eventStatusRec);
\r
1355 if (eventStatusRec != NULL) {
\r
1356 *counter = eventStatusRec->faultDetectionCounter; /** @req DEM204.Counter */
\r
1360 returnCode = E_OK;
\r
1364 case DEM_PRE_DEBOUNCE_FREQUENCY_BASED:
\r
1365 case DEM_PRE_DEBOUNCE_TIME_BASED:
\r
1366 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1370 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_PARAM_DATA);
\r
1376 return returnCode;
\r
1381 * Procedure: setOperationCycleState
\r
1382 * Description: Change the operation state of "operationCycleId" to "cycleState" and updates stored
\r
1383 * event connected to this cycle id.
\r
1384 * Returns E_OK if operation was successful else E_NOT_OK.
\r
1386 static Std_ReturnType setOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState) /** @req DEM338 */
\r
1389 Std_ReturnType returnCode = E_OK;
\r
1391 if (operationCycleId < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1392 switch (cycleState)
\r
1394 case DEM_CYCLE_STATE_START:
\r
1395 operationCycleStateList[operationCycleId] = cycleState;
\r
1396 // Lookup event ID
\r
1397 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1398 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1399 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED_THIS_OPERATION_CYCLE;
\r
1400 eventStatusBuffer[i].eventStatusExtended |= DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
1405 case DEM_CYCLE_STATE_END:
\r
1406 operationCycleStateList[operationCycleId] = cycleState;
\r
1407 // Lookup event ID
\r
1408 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1409 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1410 if ((!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_FAILED_THIS_OPERATION_CYCLE)) && (!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE))) {
\r
1411 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_PENDING_DTC; // Clear pendingDTC bit /** @req DEM379.PendingClear
\r
1417 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
1418 returnCode = E_NOT_OK;
\r
1423 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
1424 returnCode = E_NOT_OK;
\r
1427 return returnCode;
\r
1431 //==============================================================================//
\r
1433 // E X T E R N A L F U N C T I O N S //
\r
1435 //==============================================================================//
\r
1437 /*********************************************
\r
1438 * Interface for upper layer modules (8.3.1) *
\r
1439 *********************************************/
\r
1442 * Procedure: Dem_GetVersionInfo
\r
1445 // Defined in Dem.h
\r
1448 /***********************************************
\r
1449 * Interface ECU State Manager <-> DEM (8.3.2) *
\r
1450 ***********************************************/
\r
1453 * Procedure: Dem_PreInit
\r
1456 void Dem_PreInit(void)
\r
1458 /** @req DEM180 */
\r
1461 VALIDATE_NO_RV(DEM_Config.ConfigSet != NULL, DEM_PREINIT_ID, DEM_E_CONFIG_PTR_INVALID);
\r
1463 configSet = DEM_Config.ConfigSet;
\r
1465 // Initializion of operation cycle states.
\r
1466 for (i = 0; i < DEM_OPERATION_CYCLE_ID_ENDMARK; i++) {
\r
1467 operationCycleStateList[i] = DEM_CYCLE_STATE_END;
\r
1470 // Initialize the event status buffer
\r
1471 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1472 eventStatusBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1473 eventStatusBuffer[i].eventParamRef = NULL;
\r
1474 eventStatusBuffer[i].faultDetectionCounter = 0;
\r
1475 eventStatusBuffer[i].occurrence = 0;
\r
1476 eventStatusBuffer[i].eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1477 eventStatusBuffer[i].errorStatusChanged = FALSE;
\r
1480 // Initialize the pre init buffers
\r
1481 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1482 preInitFreezeFrameBuffer[i].checksum = 0;
\r
1483 preInitFreezeFrameBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1484 preInitFreezeFrameBuffer[i].occurrence = 0;
\r
1485 preInitFreezeFrameBuffer[i].dataSize = 0;
\r
1486 for (j = 0; j < DEM_MAX_SIZE_FF_DATA;j++){
\r
1487 preInitFreezeFrameBuffer[i].data[j] = 0;
\r
1491 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1492 preInitExtDataBuffer[i].checksum = 0;
\r
1493 preInitExtDataBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1494 preInitExtDataBuffer[i].dataSize = 0;
\r
1495 for (j = 0; j < DEM_MAX_SIZE_EXT_DATA;j++){
\r
1496 preInitExtDataBuffer[i].data[j] = 0;
\r
1500 disableDtcStorage.storageDisabled = FALSE;
\r
1502 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_START); /** @req DEM047 */
\r
1504 demState = DEM_PREINITIALIZED;
\r
1509 * Procedure: Dem_Init
\r
1512 void Dem_Init(void)
\r
1515 ChecksumType cSum;
\r
1516 const Dem_EventParameterType *eventParam;
\r
1519 * Validate and read out saved error log from non volatile memory
\r
1522 // Validate event records stored in primary memory
\r
1523 for (i = 0; i < DEM_MAX_NUMBER_EVENT_PRI_MEM; i++) {
\r
1524 cSum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
1525 if ((cSum != priMemEventBuffer[i].checksum) || (priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1526 // Unlegal record, clear the record
\r
1527 memset(&priMemEventBuffer[i], 0, sizeof(EventRecType));
\r
1530 // Valid, update current status
\r
1531 mergeEventStatusRec(&priMemEventBuffer[i]);
\r
1533 // Update occurrence counter on pre init stored freeze frames
\r
1534 updateFreezeFrameOccurrencePreInit(&priMemEventBuffer[i]);
\r
1538 // Validate extended data records stored in primary memory
\r
1539 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM; i++) {
\r
1540 cSum = calcChecksum(&priMemExtDataBuffer[i], sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
1541 if ((cSum != priMemExtDataBuffer[i].checksum) || (priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1542 // Unlegal record, clear the record
\r
1543 memset(&priMemExtDataBuffer[i], 0, sizeof(ExtDataRecType));
\r
1547 // Validate freeze frame records stored in primary memory
\r
1548 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++) {
\r
1549 cSum = calcChecksum(&priMemFreezeFrameBuffer[i], sizeof(FreezeFrameRecType)-sizeof(ChecksumType));
\r
1550 if ((cSum != priMemFreezeFrameBuffer[i].checksum) || (priMemFreezeFrameBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1551 // Unlegal record, clear the record
\r
1552 memset(&priMemFreezeFrameBuffer[i], 0, sizeof(FreezeFrameRecType));
\r
1557 * Handle errors stored in temporary buffer (if any)
\r
1560 // Transfer updated event data to event memory
\r
1561 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1562 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1563 // Update the event memory
\r
1564 lookupEventIdParameter(eventStatusBuffer[i].eventId, &eventParam);
\r
1565 storeEventEvtMem(eventParam, &eventStatusBuffer[i]);
\r
1569 // Transfer extended data to event memory if necessary
\r
1570 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1571 if (preInitExtDataBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1572 lookupEventIdParameter(preInitExtDataBuffer[i].eventId, &eventParam);
\r
1573 storeExtendedDataEvtMem(eventParam, &preInitExtDataBuffer[i]);
\r
1577 // Transfer freeze frames to event memory
\r
1578 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1579 if (preInitFreezeFrameBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1580 lookupEventIdParameter(preInitFreezeFrameBuffer[i].eventId, &eventParam);
\r
1581 storeFreezeFrameDataEvtMem(eventParam, &preInitFreezeFrameBuffer[i]);
\r
1585 // Init the dtc filter
\r
1586 dtcFilter.dtcStatusMask = DEM_DTC_STATUS_MASK_ALL; // All allowed
\r
1587 dtcFilter.dtcKind = DEM_DTC_KIND_ALL_DTCS; // All kinds of DTCs
\r
1588 dtcFilter.dtcOrigin = DEM_DTC_ORIGIN_PRIMARY_MEMORY; // Primary memory
\r
1589 dtcFilter.filterWithSeverity = DEM_FILTER_WITH_SEVERITY_NO; // No Severity filtering
\r
1590 dtcFilter.dtcSeverityMask = DEM_SEVERITY_NO_SEVERITY; // Not used when filterWithSeverity is FALSE
\r
1591 dtcFilter.filterForFaultDetectionCounter = DEM_FILTER_FOR_FDC_NO; // No fault detection counter filtering
\r
1593 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1595 disableDtcStorage.storageDisabled = FALSE;
\r
1597 demState = DEM_INITIALIZED;
\r
1602 * Procedure: Dem_shutdown
\r
1605 void Dem_Shutdown(void)
\r
1607 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_END); /** @req DEM047 */
\r
1609 demState = DEM_UNINITIALIZED; /** @req DEM368 */
\r
1614 * Interface for basic software scheduler
\r
1616 void Dem_MainFunction(void)
\r
1618 /** @req DEM125 */
\r
1623 /***************************************************
\r
1624 * Interface SW-Components via RTE <-> DEM (8.3.3) *
\r
1625 ***************************************************/
\r
1628 * Procedure: Dem_SetEventStatus
\r
1631 Std_ReturnType Dem_SetEventStatus(Dem_EventIdType eventId, Dem_EventStatusType eventStatus) /** @req DEM330 */
\r
1633 Std_ReturnType returnCode = E_OK;
\r
1635 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1637 returnCode = handleEvent(eventId, eventStatus);
\r
1641 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1642 returnCode = E_NOT_OK;
\r
1645 return returnCode;
\r
1650 * Procedure: Dem_ResetEventStatus
\r
1653 Std_ReturnType Dem_ResetEventStatus(Dem_EventIdType eventId) /** @req DEM331 */
\r
1655 Std_ReturnType returnCode = E_OK;
\r
1657 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1659 resetEventStatus(eventId); /** @req DEM186 */
\r
1663 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_RESETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1664 returnCode = E_NOT_OK;
\r
1667 return returnCode;
\r
1672 * Procedure: Dem_GetEventStatus
\r
1675 Std_ReturnType Dem_GetEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended) /** @req DEM332 */
\r
1677 Std_ReturnType returnCode = E_OK;
\r
1679 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1681 getEventStatus(eventId, eventStatusExtended);
\r
1685 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1686 returnCode = E_NOT_OK;
\r
1689 return returnCode;
\r
1694 * Procedure: Dem_GetEventFailed
\r
1697 Std_ReturnType Dem_GetEventFailed(Dem_EventIdType eventId, boolean *eventFailed) /** @req DEM333 */
\r
1699 Std_ReturnType returnCode = E_OK;
\r
1701 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1703 getEventFailed(eventId, eventFailed);
\r
1707 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTFAILED_ID, DEM_E_UNINIT);
\r
1708 returnCode = E_NOT_OK;
\r
1711 return returnCode;
\r
1716 * Procedure: Dem_GetEventTested
\r
1719 Std_ReturnType Dem_GetEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1721 Std_ReturnType returnCode = E_OK;
\r
1723 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1725 getEventTested(eventId, eventTested);
\r
1729 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTTESTED_ID, DEM_E_UNINIT);
\r
1730 returnCode = E_NOT_OK;
\r
1733 return returnCode;
\r
1738 * Procedure: Dem_GetFaultDetectionCounter
\r
1741 Std_ReturnType Dem_GetFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1743 Std_ReturnType returnCode = E_OK;
\r
1745 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1747 returnCode = getFaultDetectionCounter(eventId, counter);
\r
1751 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_UNINIT);
\r
1752 returnCode = E_NOT_OK;
\r
1755 return returnCode;
\r
1760 * Procedure: Dem_SetOperationCycleState
\r
1763 Std_ReturnType Dem_SetOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState)
\r
1765 Std_ReturnType returnCode = E_OK;
\r
1767 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1769 returnCode = setOperationCycleState(operationCycleId, cycleState);
\r
1774 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_UNINIT);
\r
1775 returnCode = E_NOT_OK;
\r
1778 return returnCode;
\r
1783 * Procedure: Dem_GetDTCOfEvent
\r
1786 Std_ReturnType Dem_GetDTCOfEvent(Dem_EventIdType eventId, Dem_DTCKindType dtcKind, uint32* dtcOfEvent)
\r
1788 Std_ReturnType returnCode = E_NO_DTC_AVAILABLE;
\r
1789 const Dem_EventParameterType *eventParam;
\r
1791 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1793 lookupEventIdParameter(eventId, &eventParam);
\r
1795 if (eventParam != NULL) {
\r
1796 if (checkDtcKind(dtcKind, eventParam)) {
\r
1797 if (eventParam->DTCClassRef != NULL) {
\r
1798 *dtcOfEvent = eventParam->DTCClassRef->DTC; /** @req DEM269 */
\r
1799 returnCode = E_OK;
\r
1804 // Event Id not found
\r
1805 returnCode = E_NOT_OK;
\r
1810 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETDTCOFEVENT_ID, DEM_UNINITIALIZED);
\r
1811 returnCode = E_NOT_OK;
\r
1814 return returnCode;
\r
1818 /********************************************
\r
1819 * Interface BSW-Components <-> DEM (8.3.4) *
\r
1820 ********************************************/
\r
1823 * Procedure: Dem_ReportErrorStatus
\r
1826 void Dem_ReportErrorStatus( Dem_EventIdType eventId, Dem_EventStatusType eventStatus ) /** @req DEM107 */
\r
1829 switch (demState) {
\r
1830 case DEM_PREINITIALIZED:
\r
1831 // Update status and check if is to be stored
\r
1832 if ((eventStatus == DEM_EVENT_STATUS_PASSED) || (eventStatus == DEM_EVENT_STATUS_FAILED)) {
\r
1833 handlePreInitEvent(eventId, eventStatus); /** @req DEM168 */
\r
1837 case DEM_INITIALIZED:
\r
1838 (void)handleEvent(eventId, eventStatus); /** @req DEM167 */
\r
1841 case DEM_UNINITIALIZED:
\r
1843 // Uninitialized can not do anything
\r
1844 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_REPORTERRORSTATUS_ID, DEM_E_UNINIT);
\r
1848 } // switch (demState)
\r
1851 /*********************************
\r
1852 * Interface DCM <-> DEM (8.3.5) *
\r
1853 *********************************/
\r
1855 * Procedure: Dem_GetDTCStatusAvailabilityMask
\r
1858 Std_ReturnType Dem_GetDTCStatusAvailabilityMask(uint8 *dtcStatusMask) /** @req DEM014 */
\r
1860 *dtcStatusMask = DEM_DTC_STATUS_AVAILABILITY_MASK; // User configuration mask
\r
1861 *dtcStatusMask &= DEM_TEST_FAILED // Mask with supported bits /** @req DEM060 */
\r
1862 | DEM_TEST_FAILED_THIS_OPERATION_CYCLE
\r
1864 // | DEM_CONFIRMED_DTC TODO: Add support for this bit
\r
1865 | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR
\r
1866 | DEM_TEST_FAILED_SINCE_LAST_CLEAR
\r
1867 | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE
\r
1868 // | DEM_WARNING_INDICATOR_REQUESTED TODO: Add support for this bit
\r
1876 * Procedure: Dem_SetDTCFilter
\r
1879 Dem_ReturnSetDTCFilterType Dem_SetDTCFilter(uint8 dtcStatusMask,
\r
1880 Dem_DTCKindType dtcKind,
\r
1881 Dem_DTCOriginType dtcOrigin,
\r
1882 Dem_FilterWithSeverityType filterWithSeverity,
\r
1883 Dem_DTCSeverityType dtcSeverityMask,
\r
1884 Dem_FilterForFDCType filterForFaultDetectionCounter)
\r
1886 Dem_ReturnSetDTCFilterType returnCode = DEM_FILTER_ACCEPTED;
\r
1888 if (demState == DEM_INITIALIZED) {
\r
1889 // Check dtcKind parameter
\r
1890 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
1892 // Check dtcOrigin parameter
\r
1893 VALIDATE_RV((dtcOrigin == DEM_DTC_ORIGIN_SECONDARY_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_PRIMARY_MEMORY)
\r
1894 || (dtcOrigin == DEM_DTC_ORIGIN_PERMANENT_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_MIRROR_MEMORY), DEM_SETDTCFILTER_ID, DEM_E_PARAM_DATA, DEM_WRONG_FILTER);
\r
1896 // Check filterWithSeverity and dtcSeverityMask parameter
\r
1897 VALIDATE_RV(((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
1898 || ((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES)
\r
1899 && (!(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
1901 // Check filterForFaultDetectionCounter parameter
\r
1902 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
1904 // Yes all parameters correct, set the new filters. /** @req DEM057 */
\r
1905 dtcFilter.dtcStatusMask = dtcStatusMask;
\r
1906 dtcFilter.dtcKind = dtcKind;
\r
1907 dtcFilter.dtcOrigin = dtcOrigin;
\r
1908 dtcFilter.filterWithSeverity = filterWithSeverity;
\r
1909 dtcFilter.dtcSeverityMask = dtcSeverityMask;
\r
1910 dtcFilter.filterForFaultDetectionCounter = filterForFaultDetectionCounter;
\r
1911 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1913 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETDTCFILTER_ID, DEM_E_UNINIT);
\r
1914 returnCode = DEM_WRONG_FILTER;
\r
1917 return returnCode;
\r
1922 * Procedure: Dem_GetStatusOfDTC
\r
1925 Dem_ReturnGetStatusOfDTCType Dem_GetStatusOfDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, Dem_EventStatusExtendedType* status) {
\r
1926 Dem_ReturnGetStatusOfDTCType returnCode = DEM_STATUS_FAILED;
\r
1927 EventStatusRecType *eventRec;
\r
1929 if (demState == DEM_INITIALIZED) {
\r
1930 if (lookupDtcEvent(dtc, &eventRec)) {
\r
1931 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
1932 if (checkDtcOrigin(dtcOrigin,eventRec->eventParamRef)) {
\r
1933 *status = eventRec->eventStatusExtended; /** @req DEM059 */
\r
1934 returnCode = DEM_STATUS_OK;
\r
1937 returnCode = DEM_STATUS_WRONG_DTCORIGIN; /** @req DEM171 */
\r
1941 returnCode = DEM_STATUS_WRONG_DTCKIND;
\r
1945 returnCode = DEM_STATUS_WRONG_DTC; /** @req DEM172 */
\r
1948 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETSTATUSOFDTC_ID, DEM_E_UNINIT);
\r
1949 returnCode = DEM_STATUS_FAILED;
\r
1952 return returnCode;
\r
1957 * Procedure: Dem_GetNumberOfFilteredDtc
\r
1960 Dem_ReturnGetNumberOfFilteredDTCType Dem_GetNumberOfFilteredDtc(uint16 *numberOfFilteredDTC) {
\r
1962 uint16 numberOfFaults = 0;
\r
1963 Dem_ReturnGetNumberOfFilteredDTCType returnCode = DEM_NUMBER_OK;
\r
1965 if (demState == DEM_INITIALIZED) {
\r
1966 //Dem_DisableEventStatusUpdate();
\r
1968 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1969 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1970 if (matchEventWithDtcFilter(&eventStatusBuffer[i])) {
\r
1971 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
1978 //Dem_EnableEventStatusUpdate();
\r
1980 *numberOfFilteredDTC = numberOfFaults; /** @req DEM061 */
\r
1982 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETNUMBEROFFILTEREDDTC_ID, DEM_E_UNINIT);
\r
1983 returnCode = DEM_NUMBER_FAILED;
\r
1986 return returnCode;
\r
1991 * Procedure: Dem_GetNextFilteredDTC
\r
1994 Dem_ReturnGetNextFilteredDTCType Dem_GetNextFilteredDTC(uint32 *dtc, Dem_EventStatusExtendedType *dtcStatus)
\r
1996 Dem_ReturnGetNextFilteredDTCType returnCode = DEM_FILTERED_OK;
\r
1997 boolean dtcFound = FALSE;
\r
1999 if (demState == DEM_INITIALIZED) {
\r
2000 // TODO: This job should be done in an more advanced way according to Dem217
\r
2001 while ((!dtcFound) && (dtcFilter.faultIndex != 0)) {
\r
2002 dtcFilter.faultIndex--;
\r
2003 if (eventStatusBuffer[dtcFilter.faultIndex].eventId != DEM_EVENT_ID_NULL) {
\r
2004 if (matchEventWithDtcFilter(&eventStatusBuffer[dtcFilter.faultIndex])) {
\r
2005 if (eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef != NULL) {
\r
2006 *dtc = eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef->DTC; /** @req DEM216 */
\r
2007 *dtcStatus = eventStatusBuffer[dtcFilter.faultIndex].eventStatusExtended;
\r
2015 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
2016 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
2019 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETNEXTFILTEREDDTC_ID, DEM_E_UNINIT);
\r
2020 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
2023 return returnCode;
\r
2028 * Procedure: Dem_GetTranslationType
\r
2031 Dem_ReturnTypeOfDtcSupportedType Dem_GetTranslationType(void)
\r
2033 return DEM_TYPE_OF_DTC_SUPPORTED; /** @req DEM231 */
\r
2038 * Procedure: Dem_ClearDTC
\r
2041 Dem_ReturnClearDTCType Dem_ClearDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin) /** @req DEM009 */
\r
2043 Dem_ReturnClearDTCType returnCode = DEM_CLEAR_OK;
\r
2044 Dem_EventIdType eventId;
\r
2045 const Dem_EventParameterType *eventParam;
\r
2048 if (demState == DEM_INITIALIZED) {
\r
2049 // Loop through the event buffer
\r
2050 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2051 eventId = eventStatusBuffer[i].eventId;
\r
2052 if (eventId != DEM_EVENT_ID_NULL) {
\r
2053 eventParam = eventStatusBuffer[i].eventParamRef;
\r
2054 if (eventParam != NULL) {
\r
2055 //lint --e(506) PC-Lint exception Misra 13.7, 14.1 Allow configuration variables in boolean expression
\r
2056 //lint --e(774) PC-Lint exception Related to MISRA 13.7
\r
2057 if ((DEM_CLEAR_ALL_EVENTS == STD_ON) || (eventParam->DTCClassRef != NULL)) {
\r
2058 if (checkDtcKind(dtcKind, eventParam)) {
\r
2059 if (checkDtcGroup(dtc, eventParam)) {
\r
2060 boolean dtcOriginFound = FALSE;
\r
2061 for (j = 0; (j < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound) ; j++){
\r
2062 dtcOriginFound =(eventParam->EventClass->EventDestination[j] == dtcOrigin);
\r
2064 //if (j-1 < DEM_MAX_NR_OF_EVENT_DESTINATION) {
\r
2065 if (dtcOriginFound) {
\r
2066 // Yes! All conditions met.
\r
2067 switch (dtcOrigin)
\r
2069 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2070 /** @req DEM077 */
\r
2071 deleteEventPriMem(eventParam);
\r
2072 deleteFreezeFrameDataPriMem(eventParam);
\r
2073 deleteExtendedDataPriMem(eventParam);
\r
2074 deleteEventStatusRec(eventParam); // TODO: Shall this be done or just resetting the status?
\r
2077 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2078 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2079 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2080 // Not yet supported
\r
2081 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2082 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2085 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2094 // Fatal error, no event parameters found for the stored event!
\r
2095 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNEXPECTED_EXECUTION);
\r
2100 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNINIT);
\r
2101 returnCode = DEM_CLEAR_FAILED;
\r
2104 return returnCode;
\r
2109 * Procedure: Dem_DisableDTCStorage
\r
2112 Dem_ReturnControlDTCStorageType Dem_DisableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind) /** @req DEM035 */
\r
2114 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2116 if (demState == DEM_INITIALIZED) {
\r
2117 // Check dtcGroup parameter
\r
2118 if (dtcGroup == DEM_DTC_GROUP_ALL_DTCS) {
\r
2119 // Check dtcKind parameter
\r
2120 if ((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS)) {
\r
2121 /** @req DEM079 */
\r
2122 disableDtcStorage.dtcGroup = dtcGroup;
\r
2123 disableDtcStorage.dtcKind = dtcKind;
\r
2124 disableDtcStorage.storageDisabled = TRUE;
\r
2126 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2129 returnCode = DEM_CONTROL_DTC_WRONG_DTCGROUP;
\r
2132 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_DISABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
2133 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2136 return returnCode;
\r
2141 * Procedure: Dem_EnableDTCStorage
\r
2144 Dem_ReturnControlDTCStorageType Dem_EnableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind)
\r
2146 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2148 if (demState == DEM_INITIALIZED) {
\r
2149 // TODO: Behavior is not defined if group or kind do not match active settings, therefore the filter is just switched off.
\r
2150 (void)dtcGroup; (void)dtcKind; // Just to make get rid of PC-Lint warnings
\r
2151 disableDtcStorage.storageDisabled = FALSE; /** @req DEM080 */
\r
2153 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_ENABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
2154 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2157 return returnCode;
\r
2161 * Procedure: Dem_GetExtendedDataRecordByDTC
\r
2164 Dem_ReturnGetExtendedDataRecordByDTCType Dem_GetExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint8 *destBuffer, uint16 *bufSize)
\r
2166 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_RECORD_WRONG_DTC;
\r
2167 EventStatusRecType *eventRec;
\r
2168 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2169 ExtDataRecType *extData;
\r
2170 uint16 posInExtData = 0;
\r
2172 if (demState == DEM_INITIALIZED) {
\r
2173 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2174 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2175 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2176 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2177 if (*bufSize >= extendedDataRecordClass->DataSize) {
\r
2178 switch (dtcOrigin)
\r
2180 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2181 if (lookupExtendedDataPriMem(eventRec->eventId, &extData)) {
\r
2182 // Yes all conditions met, copy the extended data record to destination buffer.
\r
2183 memcpy(destBuffer, &extData->data[posInExtData], extendedDataRecordClass->DataSize); /** @req DEM075 */
\r
2184 *bufSize = extendedDataRecordClass->DataSize;
\r
2185 returnCode = DEM_RECORD_OK;
\r
2188 // The record number is legal but no record was found for the DTC
\r
2190 returnCode = DEM_RECORD_OK;
\r
2194 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2195 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2196 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2197 // Not yet supported
\r
2198 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2199 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2202 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2207 returnCode = DEM_RECORD_BUFFERSIZE;
\r
2211 returnCode = DEM_RECORD_NUMBER;
\r
2215 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2219 returnCode = DEM_RECORD_DTCKIND;
\r
2223 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
2224 returnCode = DEM_RECORD_WRONG_DTC;
\r
2227 return returnCode;
\r
2232 * Procedure: Dem_GetSizeOfExtendedDataRecordByDTC
\r
2235 Dem_ReturnGetSizeOfExtendedDataRecordByDTCType Dem_GetSizeOfExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint16 *sizeOfExtendedDataRecord)
\r
2237 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2238 EventStatusRecType *eventRec;
\r
2239 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2240 uint16 posInExtData;
\r
2242 if (demState == DEM_INITIALIZED) {
\r
2243 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2244 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2245 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2246 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2247 *sizeOfExtendedDataRecord = extendedDataRecordClass->DataSize; /** @req DEM076 */
\r
2248 returnCode = DEM_GET_SIZEOFEDRBYDTC_OK;
\r
2251 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_RNUM;
\r
2255 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCOR;
\r
2259 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCKI;
\r
2263 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETSIZEOFEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
2264 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2267 return returnCode;
\r
2270 /***********************************
\r
2271 * OBD-specific Interfaces (8.3.6) *
\r
2272 ***********************************/
\r