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
18 // 522 PC-Lint exception for empty functions
\r
19 //lint -esym(522,deleteFreezeFrameDataPriMem)
\r
20 //lint -esym(522,storeFreezeFrameDataPreInit)
\r
21 //lint -esym(522,storeFreezeFrameDataPriMem)
\r
22 //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
51 #include "McuExtensions.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
86 typedef uint16 ChecksumType;
\r
90 Dem_EventStatusExtendedType dtcStatusMask;
\r
91 Dem_DTCKindType dtcKind;
\r
92 Dem_DTCOriginType dtcOrigin;
\r
93 Dem_FilterWithSeverityType filterWithSeverity;
\r
94 Dem_DTCSeverityType dtcSeverityMask;
\r
95 Dem_FilterForFDCType filterForFaultDetectionCounter;
\r
99 // DisableDtcStorageType
\r
101 boolean storageDisabled;
\r
102 Dem_DTCGroupType dtcGroup;
\r
103 Dem_DTCKindType dtcKind;
\r
104 } DisableDtcStorageType;
\r
106 // For keeping track of the events status
\r
108 Dem_EventIdType eventId;
\r
109 const Dem_EventParameterType *eventParamRef;
\r
110 sint8 faultDetectionCounter;
\r
111 uint16 occurrence; /** @req DEM011 */
\r
112 Dem_EventStatusExtendedType eventStatusExtended; /** @req DEM006 */
\r
113 boolean errorStatusChanged;
\r
114 } EventStatusRecType;
\r
117 // Types for storing different event data on event memory
\r
119 Dem_EventIdType eventId;
\r
121 ChecksumType checksum;
\r
125 Dem_EventIdType eventId;
\r
128 sint8 data[DEM_MAX_SIZE_FF_DATA];
\r
129 ChecksumType checksum;
\r
130 } FreezeFrameRecType;
\r
133 Dem_EventIdType eventId;
\r
135 uint8 data[DEM_MAX_SIZE_EXT_DATA];
\r
136 ChecksumType checksum;
\r
143 DEM_UNINITIALIZED = 0,
\r
144 DEM_PREINITIALIZED,
\r
146 } Dem_StateType; /** @req DEM169 */
\r
149 static Dem_StateType demState = DEM_UNINITIALIZED;
\r
151 // Help pointer to configuration set
\r
152 static const Dem_ConfigSetType *configSet;
\r
155 * Allocation of DTC filter parameters
\r
157 static DtcFilterType dtcFilter;
\r
160 * Allocation of Disable/Enable DTC storage parameters
\r
162 static DisableDtcStorageType disableDtcStorage;
\r
165 * Allocation of operation cycle state list
\r
167 static Dem_OperationCycleStateType operationCycleStateList[DEM_OPERATION_CYCLE_ID_ENDMARK];
\r
170 * Allocation of local event status buffer
\r
172 static EventStatusRecType eventStatusBuffer[DEM_MAX_NUMBER_EVENT];
\r
175 * Allocation of pre-init event memory (used between pre-init and init)
\r
178 static FreezeFrameRecType preInitFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRE_INIT];
\r
179 static ExtDataRecType preInitExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRE_INIT];
\r
182 * Allocation of primary event memory ramlog (after init) in uninitialized memory
\r
185 static EventRecType priMemEventBuffer[DEM_MAX_NUMBER_EVENT_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
186 static FreezeFrameRecType priMemFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
187 static ExtDataRecType priMemExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
191 * Procedure: zeroPriMemBuffers
\r
192 * Description: Fill the primary buffers with zeroes
\r
194 //lint -e957 PC-Lint exception - Used only by DemTest
\r
195 void demZeroPriMemBuffers(void)
\r
197 memset(priMemEventBuffer, 0, sizeof(priMemEventBuffer));
\r
198 memset(priMemFreezeFrameBuffer, 0, sizeof(priMemFreezeFrameBuffer));
\r
199 memset(priMemExtDataBuffer, 0, sizeof(priMemExtDataBuffer));
\r
204 * Procedure: calcChecksum
\r
205 * Description: Calculate checksum over *data to *(data+nrOfBytes-1) area
\r
207 static ChecksumType calcChecksum(void *data, uint16 nrOfBytes)
\r
210 uint8 *byte = (uint8*)data;
\r
211 ChecksumType sum = 0;
\r
213 for (i = 0; i < nrOfBytes; i++) {
\r
222 * Procedure: checkDtcKind
\r
223 * Description: Return TRUE if "dtcKind" match the events DTCKind or "dtcKind"
\r
224 * is "DEM_DTC_KIND_ALL_DTCS" otherwise FALSE.
\r
226 static boolean checkDtcKind(Dem_DTCKindType dtcKind, const Dem_EventParameterType *eventParam)
\r
228 boolean result = FALSE;
\r
230 if (dtcKind == DEM_DTC_KIND_ALL_DTCS) {
\r
234 if (eventParam->DTCClassRef != NULL) {
\r
235 if (eventParam->DTCClassRef->DTCKind == dtcKind) {
\r
245 * Procedure: checkDtcGroup
\r
246 * Description: Return TRUE if "dtc" match the events DTC or "dtc" is
\r
247 * "DEM_DTC_GROUP_ALL_DTCS" otherwise FALSE.
\r
249 static boolean checkDtcGroup(uint32 dtc, const Dem_EventParameterType *eventParam)
\r
251 boolean result = FALSE;
\r
253 if (dtc == DEM_DTC_GROUP_ALL_DTCS) {
\r
257 if (eventParam->DTCClassRef != NULL) {
\r
258 if (eventParam->DTCClassRef->DTC == dtc) {
\r
268 * Procedure: checkDtcOrigin
\r
269 * Description: Return TRUE if "dtcOrigin" match any of the events DTCOrigin otherwise FALSE.
\r
271 static boolean checkDtcOrigin(Dem_DTCOriginType dtcOrigin, const Dem_EventParameterType *eventParam)
\r
273 boolean result = FALSE;
\r
274 boolean dtcOriginFound = FALSE;
\r
277 for (i = 0;(i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound); i++){
\r
278 dtcOriginFound = (eventParam->EventClass->EventDestination[i] == dtcOrigin);
\r
281 if (dtcOriginFound) {
\r
289 * Procedure: checkDtcSeverityMask
\r
290 * Description: Return TRUE if "dtcSeverityMask" match any of the events DTC severity otherwise FALSE.
\r
292 // PC-Lint (715 etc): Remove errors until function is filled.
\r
293 //lint -save -e715 Symbol not referenced
\r
294 static boolean checkDtcSeverityMask(Dem_DTCSeverityType dtcSeverityMask, const Dem_EventParameterType *eventParam)
\r
296 boolean result = TRUE;
\r
298 // TODO: This function is optional, may be implemented here.
\r
306 * Procedure: checkDtcFaultDetectionCounterMask
\r
307 * Description: TBD.
\r
309 // PC-Lint (715 etc): Remove errors until function is filled.
\r
310 //lint -save -e*715
\r
311 static boolean checkDtcFaultDetectionCounter(const Dem_EventParameterType *eventParam)
\r
313 boolean result = TRUE;
\r
315 // TODO: Not implemented yet.
\r
322 * Procedure: lookupEventStatusRec
\r
323 * Description: Returns the pointer to event id parameters of "eventId" in "*eventStatusBuffer",
\r
324 * if not found NULL is returned.
\r
326 static void lookupEventStatusRec(Dem_EventIdType eventId, EventStatusRecType **const eventStatusRec)
\r
329 boolean eventIdFound = FALSE;
\r
331 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!eventIdFound); i++) {
\r
332 eventIdFound = (eventStatusBuffer[i].eventId == eventId);
\r
335 if (eventIdFound) {
\r
336 *eventStatusRec = &eventStatusBuffer[i-1];
\r
338 *eventStatusRec = NULL;
\r
344 * Procedure: lookupEventIdParameter
\r
345 * Description: Returns the pointer to event id parameters of "eventId" in "*eventIdParam",
\r
346 * if not found NULL is returned.
\r
348 static void lookupEventIdParameter(Dem_EventIdType eventId, const Dem_EventParameterType **const eventIdParam)
\r
350 const Dem_EventParameterType *EventIdParamList = configSet->EventParameter;
\r
352 // Lookup the correct event id parameters
\r
354 while ((EventIdParamList[i].EventID != eventId) && (!EventIdParamList[i].Arc_EOL)) {
\r
358 if (!EventIdParamList[i].Arc_EOL) {
\r
359 *eventIdParam = &EventIdParamList[i];
\r
361 *eventIdParam = NULL;
\r
367 * Procedure: preDebounceNone
\r
368 * Description: Returns the result of the debouncing.
\r
370 static Dem_EventStatusType preDebounceNone(const Dem_EventStatusType reportedStatus, const EventStatusRecType* statusRecord) {
\r
371 Dem_EventStatusType returnCode;
\r
372 (void)statusRecord; // Just to get rid of PC-Lint warnings
\r
374 switch (reportedStatus) {
\r
375 case DEM_EVENT_STATUS_FAILED: /** @req DEM091.NoneFailed */
\r
376 case DEM_EVENT_STATUS_PASSED: /** @req DEM091.NonePassed */
\r
377 // Already debounced, do nothing.
\r
381 // TODO: What to do with PREFAIL and PREPASSED on no debouncing?
\r
382 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_NONE_ID, DEM_E_PARAM_DATA);
\r
386 returnCode = reportedStatus;
\r
392 * Procedure: preDebounceCounterBased
\r
393 * Description: Returns the result of the debouncing.
\r
395 static Dem_EventStatusType preDebounceCounterBased(Dem_EventStatusType reportedStatus, EventStatusRecType* statusRecord) {
\r
396 Dem_EventStatusType returnCode;
\r
397 const Dem_PreDebounceCounterBasedType* pdVars = statusRecord->eventParamRef->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceCounterBased;
\r
399 switch (reportedStatus) {
\r
400 case DEM_EVENT_STATUS_PREFAILED:
\r
401 if (statusRecord->faultDetectionCounter < DEBOUNCE_FDC_TEST_FAILED) {
\r
402 if ((pdVars->JumpUp) && (statusRecord->faultDetectionCounter < 0)) {
\r
403 statusRecord->faultDetectionCounter = 0;
\r
405 if (((sint16)statusRecord->faultDetectionCounter + (sint8)pdVars->CountInStepSize) < DEBOUNCE_FDC_TEST_FAILED) {
\r
406 statusRecord->faultDetectionCounter += (sint8)pdVars->CountInStepSize;
\r
408 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED;
\r
414 case DEM_EVENT_STATUS_PREPASSED:
\r
415 if (statusRecord->faultDetectionCounter > DEBOUNCE_FDC_TEST_PASSED) {
\r
416 if ((pdVars->JumpDown) && (statusRecord->faultDetectionCounter > 0)) {
\r
417 statusRecord->faultDetectionCounter = 0;
\r
419 if (((sint16)statusRecord->faultDetectionCounter - (sint8)pdVars->CountOutStepSize) > DEBOUNCE_FDC_TEST_PASSED) {
\r
420 statusRecord->faultDetectionCounter -= (sint8)pdVars->CountOutStepSize;
\r
422 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED;
\r
428 case DEM_EVENT_STATUS_FAILED:
\r
429 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED; /** @req DEM091.CounterFailed */
\r
432 case DEM_EVENT_STATUS_PASSED:
\r
433 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED; /** @req DEM091.CounterPassed */
\r
437 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_COUNTER_BASED_ID, DEM_E_PARAM_DATA);
\r
442 switch (statusRecord->faultDetectionCounter) {
\r
443 case DEBOUNCE_FDC_TEST_FAILED:
\r
444 returnCode = DEM_EVENT_STATUS_FAILED;
\r
447 case DEBOUNCE_FDC_TEST_PASSED:
\r
448 returnCode = DEM_EVENT_STATUS_PASSED;
\r
452 returnCode = reportedStatus;
\r
461 * Procedure: updateEventStatusRec
\r
462 * Description: Update the status of "eventId", if not exist and "createIfNotExist" is
\r
463 * true a new record is created
\r
465 static void updateEventStatusRec(const Dem_EventParameterType *eventParam, Dem_EventStatusType eventStatus, boolean createIfNotExist, EventStatusRecType *eventStatusRec)
\r
467 EventStatusRecType *eventStatusRecPtr;
\r
468 imask_t state = McuE_EnterCriticalSection();
\r
471 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
473 if ((eventStatusRecPtr == NULL) && (createIfNotExist)) {
\r
474 // Search for free position
\r
475 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
477 if (eventStatusRecPtr != NULL) {
\r
478 // Create new event record
\r
479 eventStatusRecPtr->eventId = eventParam->EventID;
\r
480 eventStatusRecPtr->eventParamRef = eventParam;
\r
481 eventStatusRecPtr->faultDetectionCounter = 0;
\r
482 eventStatusRecPtr->occurrence = 0;
\r
483 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
484 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
487 // Error: Event status buffer full
\r
488 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
493 if (eventStatusRecPtr != NULL) {
\r
494 // Handle debouncing
\r
495 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
496 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName) { /** @req DEM004 */ /** @req DEM342 */
\r
497 case DEM_NO_PRE_DEBOUNCE:
\r
498 eventStatus = preDebounceNone(eventStatus, eventStatusRecPtr);
\r
501 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
502 eventStatus = preDebounceCounterBased(eventStatus, eventStatusRecPtr);
\r
506 // Don't know how to handle this.
\r
507 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
512 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
514 // Check test failed
\r
515 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
516 if (!(eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED)) {
\r
517 eventStatusRecPtr->occurrence++;
\r
518 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
520 /** @req DEM036 */ /** @req DEM379.PendingSet */
\r
521 eventStatusRecPtr->eventStatusExtended |= (DEM_TEST_FAILED | DEM_TEST_FAILED_THIS_OPERATION_CYCLE | DEM_TEST_FAILED_SINCE_LAST_CLEAR | DEM_PENDING_DTC);
\r
522 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
525 // Check test passed
\r
526 if (eventStatus == DEM_EVENT_STATUS_PASSED) {
\r
527 if (eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED) {
\r
528 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
531 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED;
\r
532 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
536 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
539 // Copy an empty record to return data
\r
540 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
541 eventStatusRec->faultDetectionCounter = 0;
\r
542 eventStatusRec->occurrence = 0;
\r
543 eventStatusRec->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
544 eventStatusRec->errorStatusChanged = FALSE;
\r
547 McuE_ExitCriticalSection(state);
\r
552 * Procedure: mergeEventStatusRec
\r
553 * Description: Update the occurrence counter of status, if not exist a new record is created
\r
555 static void mergeEventStatusRec(const EventRecType *eventRec)
\r
557 EventStatusRecType *eventStatusRecPtr;
\r
558 imask_t state = McuE_EnterCriticalSection();
\r
561 lookupEventStatusRec(eventRec->eventId, &eventStatusRecPtr);
\r
563 if (eventStatusRecPtr != NULL) {
\r
564 // Update occurrence counter, rest of pre init state is kept.
\r
565 eventStatusRecPtr->occurrence += eventRec->occurrence;
\r
569 // Search for free position
\r
570 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
572 if (eventStatusRecPtr != NULL) {
\r
573 // Create new event, from stored event
\r
574 eventStatusRecPtr->eventId = eventRec->eventId;
\r
575 lookupEventIdParameter(eventRec->eventId, &eventStatusRecPtr->eventParamRef);
\r
576 eventStatusRecPtr->faultDetectionCounter = 0;
\r
577 eventStatusRecPtr->occurrence = eventRec->occurrence;
\r
578 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
579 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
582 // Error: Event status buffer full
\r
583 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_MERGE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
587 McuE_ExitCriticalSection(state);
\r
592 * Procedure: deleteEventStatusRec
\r
593 * Description: Delete the status record of "eventParam->eventId" from "eventStatusBuffer".
\r
595 static void deleteEventStatusRec(const Dem_EventParameterType *eventParam)
\r
597 EventStatusRecType *eventStatusRecPtr;
\r
598 imask_t state = McuE_EnterCriticalSection();
\r
601 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
603 if (eventStatusRecPtr != NULL) {
\r
604 // Delete event record
\r
605 memset(eventStatusRecPtr, 0, sizeof(EventStatusRecType));
\r
608 McuE_ExitCriticalSection(state);
\r
613 * Procedure: getEventStatusRec
\r
614 * Description: Returns the status record of "eventId" in "eventStatusRec"
\r
616 static void getEventStatusRec(Dem_EventIdType eventId, EventStatusRecType *eventStatusRec)
\r
618 EventStatusRecType *eventStatusRecPtr;
\r
621 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
623 if (eventStatusRecPtr != NULL) {
\r
625 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
628 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
634 * Procedure: lookupDtcEvent
\r
635 * Description: Returns TRUE if the DTC was found and "eventStatusRec" points
\r
636 * to the event record found.
\r
638 static boolean lookupDtcEvent(uint32 dtc, EventStatusRecType **eventStatusRec)
\r
640 boolean dtcFound = FALSE;
\r
643 *eventStatusRec = NULL;
\r
645 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!dtcFound); i++) {
\r
646 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
647 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
650 if (eventStatusBuffer[i].eventParamRef->DTCClassRef->DTC == dtc) {
\r
651 *eventStatusRec = &eventStatusBuffer[i];
\r
663 * Procedure: matchEventWithDtcFilter
\r
664 * Description: Returns TRUE if the event pointed by "event" fulfill
\r
665 * the "dtcFilter" global filter settings.
\r
667 static boolean matchEventWithDtcFilter(const EventStatusRecType *eventRec)
\r
669 boolean dtcMatch = FALSE;
\r
672 if ((dtcFilter.dtcStatusMask == DEM_DTC_STATUS_MASK_ALL) || (eventRec->eventStatusExtended & dtcFilter.dtcStatusMask)) {
\r
673 if (eventRec->eventParamRef != NULL) {
\r
676 if (checkDtcKind(dtcFilter.dtcKind, eventRec->eventParamRef)) {
\r
679 if (checkDtcOrigin(dtcFilter.dtcOrigin, eventRec->eventParamRef)) {
\r
682 if ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
683 || ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES) && (checkDtcSeverityMask(dtcFilter.dtcSeverityMask, eventRec->eventParamRef)))) {
\r
685 // Check fault detection counter
\r
686 if ((dtcFilter.filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO)
\r
687 || ((dtcFilter.filterWithSeverity == DEM_FILTER_FOR_FDC_YES) && (checkDtcFaultDetectionCounter(eventRec->eventParamRef)))) {
\r
700 // PC-Lint (715 etc): Remove errors until function is filled.
\r
701 //lint -save -e715 Symbol not referenced
\r
702 static void getFreezeFrameData(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
705 freezeFrame->eventId = DEM_EVENT_ID_NULL; // Not supported yet
\r
709 // PC-Lint (715 etc): Remove errors until function is filled.
\r
710 //lint -save -e715 Symbol not referenced
\r
711 static void storeFreezeFrameDataPreInit(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
717 // PC-Lint (715 etc): Remove errors until function is filled.
\r
718 //lint -save -e715 Symbol not referenced
\r
719 static void updateFreezeFrameOccurrencePreInit(const EventRecType *EventBuffer)
\r
723 //lint -restore // PC-lint: Restore to original error-setting.
\r
726 * Procedure: getExtendedData
\r
727 * Description: Collects the extended data according to "eventParam" and return it in "extData",
\r
728 * if not found eventId is set to DEM_EVENT_ID_NULL.
\r
730 static void getExtendedData(const Dem_EventParameterType *eventParam, ExtDataRecType *extData)
\r
732 Std_ReturnType callbackReturnCode;
\r
734 uint16 storeIndex = 0;
\r
737 // Clear ext data record
\r
738 memset(extData, 0, sizeof(ExtDataRecType));
\r
740 // Check if any pointer to extended data class
\r
741 if (eventParam->ExtendedDataClassRef != NULL) {
\r
742 // Request extended data and copy it to the buffer
\r
743 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL); i++) {
\r
744 recordSize = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
745 if ((storeIndex + recordSize) <= DEM_MAX_SIZE_EXT_DATA) {
\r
746 callbackReturnCode = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->CallbackGetExtDataRecord(&extData->data[storeIndex]); /** @req DEM282 */
\r
747 if (callbackReturnCode != E_OK) {
\r
748 // Callback data currently not available, clear space.
\r
749 memset(&extData->data[storeIndex], 0xFF, recordSize); // PC-Lint OK
\r
751 storeIndex += recordSize;
\r
754 // Error: Size of extended data record is bigger than reserved space.
\r
755 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GET_EXTENDED_DATA_ID, DEM_E_EXT_DATA_TOO_BIG);
\r
756 break; // Break the loop
\r
761 // Check if any data has been stored
\r
762 if (storeIndex != 0) {
\r
763 extData->eventId = eventParam->EventID;
\r
764 extData->dataSize = storeIndex;
\r
765 extData->checksum = calcChecksum(extData, sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
768 extData->eventId = DEM_EVENT_ID_NULL;
\r
769 extData->dataSize = storeIndex;
\r
770 extData->checksum = 0;
\r
776 * Procedure: storeExtendedDataPreInit
\r
777 * Description: Store the extended data pointed by "extendedData" to the "preInitExtDataBuffer",
\r
778 * if non existent a new entry is created.
\r
780 static void storeExtendedDataPreInit(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
782 boolean eventIdFound = FALSE;
\r
783 boolean eventIdFreePositionFound=FALSE;
\r
785 imask_t state = McuE_EnterCriticalSection();
\r
787 // Check if already stored
\r
788 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) && (!eventIdFound); i++){
\r
789 eventIdFound = (preInitExtDataBuffer[i].eventId == eventParam->EventID);
\r
793 // Yes, overwrite existing
\r
794 memcpy(&preInitExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
797 // No, lookup first free position
\r
798 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) && (!eventIdFreePositionFound); i++){
\r
799 if(preInitExtDataBuffer[i].eventId ==0){
\r
800 eventIdFreePositionFound=TRUE;
\r
804 if (eventIdFreePositionFound) {
\r
805 memcpy(&preInitExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
808 // Error: Pre init extended data buffer full
\r
809 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRE_INIT_ID, DEM_E_PRE_INIT_EXT_DATA_BUFF_FULL);
\r
813 McuE_ExitCriticalSection(state);
\r
817 * Procedure: storeEventPriMem
\r
818 * Description: Store the event data of "eventStatus->eventId" in "priMemEventBuffer",
\r
819 * if non existent a new entry is created.
\r
821 static void storeEventPriMem(const Dem_EventParameterType *eventParam, const EventStatusRecType *eventStatus)
\r
823 boolean eventIdFound = FALSE;
\r
824 boolean eventIdFreePositionFound=FALSE;
\r
826 imask_t state = McuE_EnterCriticalSection();
\r
828 (void)*eventParam; // Currently not used, do this to avoid warning
\r
831 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
832 eventIdFound = (priMemEventBuffer[i].eventId == eventStatus->eventId);
\r
835 if (eventIdFound) {
\r
836 // Update event found
\r
837 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
838 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
841 // Search for free position
\r
842 for (i=0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFreePositionFound); i++){
\r
843 eventIdFreePositionFound = (priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
847 if (eventIdFreePositionFound) {
\r
848 priMemEventBuffer[i-1].eventId = eventStatus->eventId;
\r
849 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
850 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
853 // Error: Pri mem event buffer full
\r
854 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EVENT_PRI_MEM_ID, DEM_E_PRI_MEM_EVENT_BUFF_FULL);
\r
858 McuE_ExitCriticalSection(state);
\r
862 * Procedure: deleteEventPriMem
\r
863 * Description: Delete the event data of "eventParam->eventId" from "priMemEventBuffer".
\r
865 static void deleteEventPriMem(const Dem_EventParameterType *eventParam)
\r
867 boolean eventIdFound = FALSE;
\r
869 imask_t state = McuE_EnterCriticalSection();
\r
873 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
874 eventIdFound = (priMemEventBuffer[i].eventId == eventParam->EventID);
\r
877 if (eventIdFound) {
\r
878 // Delete event found
\r
879 memset(&priMemEventBuffer[i-1], 0, sizeof(EventRecType));
\r
882 McuE_ExitCriticalSection(state);
\r
886 * Procedure: storeEventEvtMem
\r
887 * Description: Store the event data of "eventStatus->eventId" in event memory according to
\r
888 * "eventParam" destination option.
\r
890 static void storeEventEvtMem(const Dem_EventParameterType *eventParam, const EventStatusRecType *eventStatus)
\r
894 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION)
\r
895 && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
896 switch (eventParam->EventClass->EventDestination[i])
\r
898 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
899 storeEventPriMem(eventParam, eventStatus); /** @req DEM010 */
\r
902 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
903 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
904 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
905 // Not yet supported
\r
906 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
916 * Procedure: storeExtendedDataPriMem
\r
917 * Description: Store the extended data pointed by "extendedData" to the "priMemExtDataBuffer",
\r
918 * if non existent a new entry is created.
\r
920 static void storeExtendedDataPriMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData) /** @req DEM041 */
\r
922 boolean eventIdFound = FALSE;
\r
923 boolean eventIdFreePositionFound=FALSE;
\r
925 imask_t state = McuE_EnterCriticalSection();
\r
927 // Check if already stored
\r
928 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
929 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
932 if (eventIdFound) {
\r
933 // Yes, overwrite existing
\r
934 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
937 // No, lookup first free position
\r
938 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFreePositionFound); i++){
\r
939 eventIdFreePositionFound = (priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
941 if (eventIdFreePositionFound) {
\r
942 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
945 // Error: Pri mem extended data buffer full
\r
946 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRI_MEM_ID, DEM_E_PRI_MEM_EXT_DATA_BUFF_FULL);
\r
950 McuE_ExitCriticalSection(state);
\r
954 * Procedure: deleteExtendedDataPriMem
\r
955 * Description: Delete the extended data of "eventParam->eventId" from "priMemExtDataBuffer".
\r
957 static void deleteExtendedDataPriMem(const Dem_EventParameterType *eventParam)
\r
959 boolean eventIdFound = FALSE;
\r
961 imask_t state = McuE_EnterCriticalSection();
\r
963 // Check if already stored
\r
964 for (i = 0;(i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
965 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
968 if (eventIdFound) {
\r
969 // Yes, clear record
\r
970 memset(&priMemExtDataBuffer[i-1], 0, sizeof(ExtDataRecType));
\r
973 McuE_ExitCriticalSection(state);
\r
977 * Procedure: storeExtendedDataEvtMem
\r
978 * Description: Store the extended data in event memory according to
\r
979 * "eventParam" destination option
\r
981 static void storeExtendedDataEvtMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
985 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
986 switch (eventParam->EventClass->EventDestination[i])
\r
988 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
989 storeExtendedDataPriMem(eventParam, extendedData);
\r
992 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
993 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
994 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
995 // Not yet supported
\r
996 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1007 * Procedure: lookupExtendedDataRecNumParam
\r
1008 * Description: Returns TRUE if the requested extended data number was found among the configured records for the event.
\r
1009 * "extDataRecClassPtr" returns a pointer to the record class, "posInExtData" returns the position in stored extended data.
\r
1011 static boolean lookupExtendedDataRecNumParam(uint8 extendedDataNumber, const Dem_EventParameterType *eventParam, Dem_ExtendedDataRecordClassType const **extDataRecClassPtr, uint16 *posInExtData)
\r
1013 boolean recNumFound = FALSE;
\r
1015 if (eventParam->ExtendedDataClassRef != NULL) {
\r
1016 uint16 byteCnt = 0;
\r
1019 // Request extended data and copy it to the buffer
\r
1020 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL) && (!recNumFound); i++) {
\r
1021 if (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->RecordNumber == extendedDataNumber) {
\r
1022 *extDataRecClassPtr = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i];
\r
1023 *posInExtData = byteCnt;
\r
1024 recNumFound = TRUE;
\r
1026 byteCnt += eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
1030 return recNumFound;
\r
1035 * Procedure: lookupExtendedDataPriMem
\r
1036 * Description: Returns TRUE if the requested event id is found, "extData" points to the found data.
\r
1038 static boolean lookupExtendedDataPriMem(Dem_EventIdType eventId, ExtDataRecType **extData)
\r
1040 boolean eventIdFound = FALSE;
\r
1043 // Lookup corresponding extended data
\r
1044 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++) {
\r
1045 eventIdFound = (priMemExtDataBuffer[i].eventId == eventId);
\r
1048 if (eventIdFound) {
\r
1049 // Yes, return pointer
\r
1050 *extData = &priMemExtDataBuffer[i-1];
\r
1053 return eventIdFound;
\r
1056 // PC-Lint (715 etc): Remove errors until function is filled.
\r
1057 //lint -save -e715 Symbol not referenced
\r
1058 static void storeFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1064 // PC-Lint (715 etc): Remove errors until function is filled.
\r
1065 //lint -save -e715 Symbol not referenced
\r
1066 static void deleteFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam)
\r
1074 * Procedure: storeFreezeFrameDataEvtMem
\r
1075 * Description: Store the freeze frame data in event memory according to
\r
1076 * "eventParam" destination option
\r
1078 static void storeFreezeFrameDataEvtMem(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1082 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
1083 switch (eventParam->EventClass->EventDestination[i])
\r
1085 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1086 storeFreezeFrameDataPriMem(eventParam, freezeFrame);
\r
1089 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1090 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1091 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1092 // Not yet supported
\r
1093 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1103 * Procedure: handlePreInitEvent
\r
1104 * Description: Handle the updating of event status and storing of
\r
1105 * event related data in preInit buffers.
\r
1107 static void handlePreInitEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1109 const Dem_EventParameterType *eventParam;
\r
1110 EventStatusRecType eventStatusLocal;
\r
1111 FreezeFrameRecType freezeFrameLocal;
\r
1112 ExtDataRecType extendedDataLocal;
\r
1114 // Find configuration for this event
\r
1115 lookupEventIdParameter(eventId, &eventParam);
\r
1116 if (eventParam != NULL) {
\r
1117 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1118 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1119 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
1120 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1123 updateEventStatusRec(eventParam, eventStatus, FALSE, &eventStatusLocal);
\r
1126 if (eventStatusLocal.errorStatusChanged) {
\r
1128 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1129 // Collect freeze frame data
\r
1130 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1131 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1132 storeFreezeFrameDataPreInit(eventParam, &freezeFrameLocal);
\r
1135 // Collect extended data
\r
1136 getExtendedData(eventParam, &extendedDataLocal);
\r
1137 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1138 storeExtendedDataPreInit(eventParam, &extendedDataLocal);
\r
1144 // Operation cycle not started
\r
1145 // TODO: Report error?
\r
1149 // Operation cycle not set
\r
1150 // TODO: Report error?
\r
1154 // Event ID not configured
\r
1155 // TODO: Report error?
\r
1161 * Procedure: handleEvent
\r
1162 * Description: Handle the updating of event status and storing of
\r
1163 * event related data in event memory.
\r
1165 static Std_ReturnType handleEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1167 Std_ReturnType returnCode = E_OK;
\r
1168 const Dem_EventParameterType *eventParam;
\r
1169 EventStatusRecType eventStatusLocal;
\r
1170 FreezeFrameRecType freezeFrameLocal;
\r
1171 ExtDataRecType extendedDataLocal;
\r
1173 // Find configuration for this event
\r
1174 lookupEventIdParameter(eventId, &eventParam);
\r
1175 if (eventParam != NULL) {
\r
1176 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1177 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1178 if ((!((disableDtcStorage.storageDisabled) && (checkDtcGroup(disableDtcStorage.dtcGroup, eventParam)) && (checkDtcKind(disableDtcStorage.dtcKind, eventParam))))) {
\r
1179 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1180 if (eventStatusLocal.errorStatusChanged) {
\r
1181 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1182 storeEventEvtMem(eventParam, &eventStatusLocal); /** @req DEM184 */
\r
1183 // Collect freeze frame data
\r
1184 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1185 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1186 storeFreezeFrameDataEvtMem(eventParam, &freezeFrameLocal); /** @req DEM190 */
\r
1189 // Collect extended data
\r
1190 getExtendedData(eventParam, &extendedDataLocal);
\r
1191 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL)
\r
1193 storeExtendedDataEvtMem(eventParam, &extendedDataLocal);
\r
1200 // Operation cycle not started
\r
1201 returnCode = E_NOT_OK;
\r
1205 // Operation cycle not set
\r
1206 returnCode = E_NOT_OK;
\r
1210 // Event ID not configured
\r
1211 returnCode = E_NOT_OK;
\r
1214 return returnCode;
\r
1219 * Procedure: resetEventStatus
\r
1220 * Description: Resets the events status of eventId.
\r
1222 static void resetEventStatus(Dem_EventIdType eventId)
\r
1224 imask_t state = McuE_EnterCriticalSection();
\r
1225 EventStatusRecType *eventStatusRecPtr;
\r
1227 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
1228 if (eventStatusRecPtr != NULL) {
\r
1229 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED; /** @req DEM187 */
\r
1232 McuE_ExitCriticalSection(state);
\r
1237 * Procedure: getEventStatus
\r
1238 * Description: Returns the extended event status bitmask of eventId in "eventStatusExtended".
\r
1240 static void getEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended)
\r
1242 EventStatusRecType eventStatusLocal;
\r
1244 // Get recorded status
\r
1245 getEventStatusRec(eventId, &eventStatusLocal);
\r
1246 if (eventStatusLocal.eventId == eventId) {
\r
1247 *eventStatusExtended = eventStatusLocal.eventStatusExtended; /** @req DEM051 */
\r
1250 // Event Id not found, no report received.
\r
1251 *eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1257 * Procedure: getEventFailed
\r
1258 * Description: Returns the TRUE or FALSE of "eventId" in "eventFailed" depending on current status.
\r
1260 static void getEventFailed(Dem_EventIdType eventId, boolean *eventFailed)
\r
1262 EventStatusRecType eventStatusLocal;
\r
1264 // Get recorded status
\r
1265 getEventStatusRec(eventId, &eventStatusLocal);
\r
1266 if (eventStatusLocal.eventId == eventId) {
\r
1267 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) { /** @req DEM052 */
\r
1268 *eventFailed = TRUE;
\r
1271 *eventFailed = FALSE;
\r
1275 // Event Id not found, assume ok.
\r
1276 *eventFailed = FALSE;
\r
1282 * Procedure: getEventTested
\r
1283 * Description: Returns the TRUE or FALSE of "eventId" in "eventTested" depending on
\r
1284 * current status the "test not completed this operation cycle" bit.
\r
1286 static void getEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1288 EventStatusRecType eventStatusLocal;
\r
1290 // Get recorded status
\r
1291 getEventStatusRec(eventId, &eventStatusLocal);
\r
1292 if (eventStatusLocal.eventId == eventId) {
\r
1293 if ( !(eventStatusLocal.eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE)) { /** @req DEM053 */
\r
1294 *eventTested = TRUE;
\r
1297 *eventTested = FALSE;
\r
1301 // Event Id not found, not tested.
\r
1302 *eventTested = FALSE;
\r
1308 * Procedure: getFaultDetectionCounter
\r
1309 * Description: Returns pre debounce counter of "eventId" in "counter" and return value E_OK if
\r
1310 * the counter was available else E_NOT_OK.
\r
1312 static Std_ReturnType getFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1314 Std_ReturnType returnCode = E_NOT_OK;
\r
1315 const Dem_EventParameterType *eventParam;
\r
1317 lookupEventIdParameter(eventId, &eventParam);
\r
1318 if (eventParam != NULL) {
\r
1319 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
1320 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName)
\r
1322 case DEM_NO_PRE_DEBOUNCE:
\r
1323 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal != NULL) {
\r
1324 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc != NULL) {
\r
1325 returnCode = eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc(counter); /** @req DEM204.None */ /** @req DEM264 */ /** @req DEM265 */
\r
1330 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
1332 EventStatusRecType *eventStatusRec;
\r
1334 lookupEventStatusRec(eventId, &eventStatusRec);
\r
1335 if (eventStatusRec != NULL) {
\r
1336 *counter = eventStatusRec->faultDetectionCounter; /** @req DEM204.Counter */
\r
1340 returnCode = E_OK;
\r
1344 case DEM_PRE_DEBOUNCE_FREQUENCY_BASED:
\r
1345 case DEM_PRE_DEBOUNCE_TIME_BASED:
\r
1346 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1350 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_PARAM_DATA);
\r
1356 return returnCode;
\r
1361 * Procedure: setOperationCycleState
\r
1362 * Description: Change the operation state of "operationCycleId" to "cycleState" and updates stored
\r
1363 * event connected to this cycle id.
\r
1364 * Returns E_OK if operation was successful else E_NOT_OK.
\r
1366 static Std_ReturnType setOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState) /** @req DEM338 */
\r
1369 Std_ReturnType returnCode = E_OK;
\r
1371 if (operationCycleId < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1372 switch (cycleState)
\r
1374 case DEM_CYCLE_STATE_START:
\r
1375 operationCycleStateList[operationCycleId] = cycleState;
\r
1376 // Lookup event ID
\r
1377 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1378 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1379 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED_THIS_OPERATION_CYCLE;
\r
1380 eventStatusBuffer[i].eventStatusExtended |= DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
1385 case DEM_CYCLE_STATE_END:
\r
1386 operationCycleStateList[operationCycleId] = cycleState;
\r
1387 // Lookup event ID
\r
1388 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1389 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1390 if ((!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_FAILED_THIS_OPERATION_CYCLE)) && (!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE))) {
\r
1391 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_PENDING_DTC; // Clear pendingDTC bit /** @req DEM379.PendingClear
\r
1397 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
1398 returnCode = E_NOT_OK;
\r
1403 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
1404 returnCode = E_NOT_OK;
\r
1407 return returnCode;
\r
1411 //==============================================================================//
\r
1413 // E X T E R N A L F U N C T I O N S //
\r
1415 //==============================================================================//
\r
1417 /*********************************************
\r
1418 * Interface for upper layer modules (8.3.1) *
\r
1419 *********************************************/
\r
1422 * Procedure: Dem_GetVersionInfo
\r
1425 // Defined in Dem.h
\r
1428 /***********************************************
\r
1429 * Interface ECU State Manager <-> DEM (8.3.2) *
\r
1430 ***********************************************/
\r
1433 * Procedure: Dem_PreInit
\r
1436 void Dem_PreInit(void)
\r
1438 /** @req DEM180 */
\r
1441 VALIDATE_NO_RV(DEM_Config.ConfigSet != NULL, DEM_PREINIT_ID, DEM_E_CONFIG_PTR_INVALID);
\r
1443 configSet = DEM_Config.ConfigSet;
\r
1445 // Initializion of operation cycle states.
\r
1446 for (i = 0; i < DEM_OPERATION_CYCLE_ID_ENDMARK; i++) {
\r
1447 operationCycleStateList[i] = DEM_CYCLE_STATE_END;
\r
1450 // Initialize the event status buffer
\r
1451 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1452 eventStatusBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1453 eventStatusBuffer[i].eventParamRef = NULL;
\r
1454 eventStatusBuffer[i].faultDetectionCounter = 0;
\r
1455 eventStatusBuffer[i].occurrence = 0;
\r
1456 eventStatusBuffer[i].eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1457 eventStatusBuffer[i].errorStatusChanged = FALSE;
\r
1460 // Initialize the pre init buffers
\r
1461 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1462 preInitFreezeFrameBuffer[i].checksum = 0;
\r
1463 preInitFreezeFrameBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1464 preInitFreezeFrameBuffer[i].occurrence = 0;
\r
1465 preInitFreezeFrameBuffer[i].dataSize = 0;
\r
1466 for (j = 0; j < DEM_MAX_SIZE_FF_DATA;j++){
\r
1467 preInitFreezeFrameBuffer[i].data[j] = 0;
\r
1471 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1472 preInitExtDataBuffer[i].checksum = 0;
\r
1473 preInitExtDataBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1474 preInitExtDataBuffer[i].dataSize = 0;
\r
1475 for (j = 0; j < DEM_MAX_SIZE_EXT_DATA;j++){
\r
1476 preInitExtDataBuffer[i].data[j] = 0;
\r
1480 disableDtcStorage.storageDisabled = FALSE;
\r
1482 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_START); /** @req DEM047 */
\r
1484 demState = DEM_PREINITIALIZED;
\r
1489 * Procedure: Dem_Init
\r
1492 void Dem_Init(void)
\r
1495 ChecksumType cSum;
\r
1496 const Dem_EventParameterType *eventParam;
\r
1499 * Validate and read out saved error log from non volatile memory
\r
1502 // Validate event records stored in primary memory
\r
1503 for (i = 0; i < DEM_MAX_NUMBER_EVENT_PRI_MEM; i++) {
\r
1504 cSum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
1505 if ((cSum != priMemEventBuffer[i].checksum) || (priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1506 // Unlegal record, clear the record
\r
1507 memset(&priMemEventBuffer[i], 0, sizeof(EventRecType));
\r
1510 // Valid, update current status
\r
1511 mergeEventStatusRec(&priMemEventBuffer[i]);
\r
1513 // Update occurrence counter on pre init stored freeze frames
\r
1514 updateFreezeFrameOccurrencePreInit(&priMemEventBuffer[i]);
\r
1518 // Validate extended data records stored in primary memory
\r
1519 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM; i++) {
\r
1520 cSum = calcChecksum(&priMemExtDataBuffer[i], sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
1521 if ((cSum != priMemExtDataBuffer[i].checksum) || (priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1522 // Unlegal record, clear the record
\r
1523 memset(&priMemExtDataBuffer[i], 0, sizeof(ExtDataRecType));
\r
1527 // Validate freeze frame records stored in primary memory
\r
1528 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++) {
\r
1529 cSum = calcChecksum(&priMemFreezeFrameBuffer[i], sizeof(FreezeFrameRecType)-sizeof(ChecksumType));
\r
1530 if ((cSum != priMemFreezeFrameBuffer[i].checksum) || (priMemFreezeFrameBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1531 // Unlegal record, clear the record
\r
1532 memset(&priMemFreezeFrameBuffer[i], 0, sizeof(FreezeFrameRecType));
\r
1537 * Handle errors stored in temporary buffer (if any)
\r
1540 // Transfer updated event data to event memory
\r
1541 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1542 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1543 // Update the event memory
\r
1544 lookupEventIdParameter(eventStatusBuffer[i].eventId, &eventParam);
\r
1545 storeEventEvtMem(eventParam, &eventStatusBuffer[i]);
\r
1549 // Transfer extended data to event memory if necessary
\r
1550 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1551 if (preInitExtDataBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1552 lookupEventIdParameter(preInitExtDataBuffer[i].eventId, &eventParam);
\r
1553 storeExtendedDataEvtMem(eventParam, &preInitExtDataBuffer[i]);
\r
1557 // Transfer freeze frames to event memory
\r
1558 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1559 if (preInitFreezeFrameBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1560 lookupEventIdParameter(preInitFreezeFrameBuffer[i].eventId, &eventParam);
\r
1561 storeFreezeFrameDataEvtMem(eventParam, &preInitFreezeFrameBuffer[i]);
\r
1565 // Init the dtc filter
\r
1566 dtcFilter.dtcStatusMask = DEM_DTC_STATUS_MASK_ALL; // All allowed
\r
1567 dtcFilter.dtcKind = DEM_DTC_KIND_ALL_DTCS; // All kinds of DTCs
\r
1568 dtcFilter.dtcOrigin = DEM_DTC_ORIGIN_PRIMARY_MEMORY; // Primary memory
\r
1569 dtcFilter.filterWithSeverity = DEM_FILTER_WITH_SEVERITY_NO; // No Severity filtering
\r
1570 dtcFilter.dtcSeverityMask = DEM_SEVERITY_NO_SEVERITY; // Not used when filterWithSeverity is FALSE
\r
1571 dtcFilter.filterForFaultDetectionCounter = DEM_FILTER_FOR_FDC_NO; // No fault detection counter filtering
\r
1573 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1575 disableDtcStorage.storageDisabled = FALSE;
\r
1577 demState = DEM_INITIALIZED;
\r
1582 * Procedure: Dem_shutdown
\r
1585 void Dem_Shutdown(void)
\r
1587 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_END); /** @req DEM047 */
\r
1589 demState = DEM_UNINITIALIZED; /** @req DEM368 */
\r
1594 * Interface for basic software scheduler
\r
1596 void Dem_MainFunction(void)
\r
1598 /** @req DEM125 */
\r
1603 /***************************************************
\r
1604 * Interface SW-Components via RTE <-> DEM (8.3.3) *
\r
1605 ***************************************************/
\r
1608 * Procedure: Dem_SetEventStatus
\r
1611 Std_ReturnType Dem_SetEventStatus(Dem_EventIdType eventId, Dem_EventStatusType eventStatus) /** @req DEM330 */
\r
1613 Std_ReturnType returnCode = E_OK;
\r
1615 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1617 returnCode = handleEvent(eventId, eventStatus);
\r
1621 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1622 returnCode = E_NOT_OK;
\r
1625 return returnCode;
\r
1630 * Procedure: Dem_ResetEventStatus
\r
1633 Std_ReturnType Dem_ResetEventStatus(Dem_EventIdType eventId) /** @req DEM331 */
\r
1635 Std_ReturnType returnCode = E_OK;
\r
1637 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1639 resetEventStatus(eventId); /** @req DEM186 */
\r
1643 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_RESETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1644 returnCode = E_NOT_OK;
\r
1647 return returnCode;
\r
1652 * Procedure: Dem_GetEventStatus
\r
1655 Std_ReturnType Dem_GetEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended) /** @req DEM332 */
\r
1657 Std_ReturnType returnCode = E_OK;
\r
1659 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1661 getEventStatus(eventId, eventStatusExtended);
\r
1665 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1666 returnCode = E_NOT_OK;
\r
1669 return returnCode;
\r
1674 * Procedure: Dem_GetEventFailed
\r
1677 Std_ReturnType Dem_GetEventFailed(Dem_EventIdType eventId, boolean *eventFailed) /** @req DEM333 */
\r
1679 Std_ReturnType returnCode = E_OK;
\r
1681 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1683 getEventFailed(eventId, eventFailed);
\r
1687 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTFAILED_ID, DEM_E_UNINIT);
\r
1688 returnCode = E_NOT_OK;
\r
1691 return returnCode;
\r
1696 * Procedure: Dem_GetEventTested
\r
1699 Std_ReturnType Dem_GetEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1701 Std_ReturnType returnCode = E_OK;
\r
1703 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1705 getEventTested(eventId, eventTested);
\r
1709 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTTESTED_ID, DEM_E_UNINIT);
\r
1710 returnCode = E_NOT_OK;
\r
1713 return returnCode;
\r
1718 * Procedure: Dem_GetFaultDetectionCounter
\r
1721 Std_ReturnType Dem_GetFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1723 Std_ReturnType returnCode = E_OK;
\r
1725 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1727 returnCode = getFaultDetectionCounter(eventId, counter);
\r
1731 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_UNINIT);
\r
1732 returnCode = E_NOT_OK;
\r
1735 return returnCode;
\r
1740 * Procedure: Dem_SetOperationCycleState
\r
1743 Std_ReturnType Dem_SetOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState)
\r
1745 Std_ReturnType returnCode = E_OK;
\r
1747 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1749 returnCode = setOperationCycleState(operationCycleId, cycleState);
\r
1754 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_UNINIT);
\r
1755 returnCode = E_NOT_OK;
\r
1758 return returnCode;
\r
1763 * Procedure: Dem_GetDTCOfEvent
\r
1766 Std_ReturnType Dem_GetDTCOfEvent(Dem_EventIdType eventId, Dem_DTCKindType dtcKind, uint32* dtcOfEvent)
\r
1768 Std_ReturnType returnCode = E_NO_DTC_AVAILABLE;
\r
1769 const Dem_EventParameterType *eventParam;
\r
1771 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1773 lookupEventIdParameter(eventId, &eventParam);
\r
1775 if (eventParam != NULL) {
\r
1776 if (checkDtcKind(dtcKind, eventParam)) {
\r
1777 if (eventParam->DTCClassRef != NULL) {
\r
1778 *dtcOfEvent = eventParam->DTCClassRef->DTC; /** @req DEM269 */
\r
1779 returnCode = E_OK;
\r
1784 // Event Id not found
\r
1785 returnCode = E_NOT_OK;
\r
1790 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETDTCOFEVENT_ID, DEM_UNINITIALIZED);
\r
1791 returnCode = E_NOT_OK;
\r
1794 return returnCode;
\r
1798 /********************************************
\r
1799 * Interface BSW-Components <-> DEM (8.3.4) *
\r
1800 ********************************************/
\r
1803 * Procedure: Dem_ReportErrorStatus
\r
1806 void Dem_ReportErrorStatus( Dem_EventIdType eventId, Dem_EventStatusType eventStatus ) /** @req DEM107 */
\r
1809 switch (demState) {
\r
1810 case DEM_PREINITIALIZED:
\r
1811 // Update status and check if is to be stored
\r
1812 if ((eventStatus == DEM_EVENT_STATUS_PASSED) || (eventStatus == DEM_EVENT_STATUS_FAILED)) {
\r
1813 handlePreInitEvent(eventId, eventStatus); /** @req DEM168 */
\r
1817 case DEM_INITIALIZED:
\r
1818 (void)handleEvent(eventId, eventStatus); /** @req DEM167 */
\r
1821 case DEM_UNINITIALIZED:
\r
1823 // Uninitialized can not do anything
\r
1824 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_REPORTERRORSTATUS_ID, DEM_E_UNINIT);
\r
1828 } // switch (demState)
\r
1831 /*********************************
\r
1832 * Interface DCM <-> DEM (8.3.5) *
\r
1833 *********************************/
\r
1835 * Procedure: Dem_GetDTCStatusAvailabilityMask
\r
1838 Std_ReturnType Dem_GetDTCStatusAvailabilityMask(uint8 *dtcStatusMask) /** @req DEM014 */
\r
1840 *dtcStatusMask = DEM_DTC_STATUS_AVAILABILITY_MASK; // User configuration mask
\r
1841 *dtcStatusMask &= DEM_TEST_FAILED // Mask with supported bits /** @req DEM060 */
\r
1842 | DEM_TEST_FAILED_THIS_OPERATION_CYCLE
\r
1844 // | DEM_CONFIRMED_DTC TODO: Add support for this bit
\r
1845 | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR
\r
1846 | DEM_TEST_FAILED_SINCE_LAST_CLEAR
\r
1847 | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE
\r
1848 // | DEM_WARNING_INDICATOR_REQUESTED TODO: Add support for this bit
\r
1856 * Procedure: Dem_SetDTCFilter
\r
1859 Dem_ReturnSetDTCFilterType Dem_SetDTCFilter(uint8 dtcStatusMask,
\r
1860 Dem_DTCKindType dtcKind,
\r
1861 Dem_DTCOriginType dtcOrigin,
\r
1862 Dem_FilterWithSeverityType filterWithSeverity,
\r
1863 Dem_DTCSeverityType dtcSeverityMask,
\r
1864 Dem_FilterForFDCType filterForFaultDetectionCounter)
\r
1866 Dem_ReturnSetDTCFilterType returnCode = DEM_FILTER_ACCEPTED;
\r
1868 if (demState == DEM_INITIALIZED) {
\r
1869 // Check dtcKind parameter
\r
1870 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
1872 // Check dtcOrigin parameter
\r
1873 VALIDATE_RV((dtcOrigin == DEM_DTC_ORIGIN_SECONDARY_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_PRIMARY_MEMORY)
\r
1874 || (dtcOrigin == DEM_DTC_ORIGIN_PERMANENT_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_MIRROR_MEMORY), DEM_SETDTCFILTER_ID, DEM_E_PARAM_DATA, DEM_WRONG_FILTER);
\r
1876 // Check filterWithSeverity and dtcSeverityMask parameter
\r
1877 VALIDATE_RV(((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
1878 || ((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES)
\r
1879 && (!(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
1881 // Check filterForFaultDetectionCounter parameter
\r
1882 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
1884 // Yes all parameters correct, set the new filters. /** @req DEM057 */
\r
1885 dtcFilter.dtcStatusMask = dtcStatusMask;
\r
1886 dtcFilter.dtcKind = dtcKind;
\r
1887 dtcFilter.dtcOrigin = dtcOrigin;
\r
1888 dtcFilter.filterWithSeverity = filterWithSeverity;
\r
1889 dtcFilter.dtcSeverityMask = dtcSeverityMask;
\r
1890 dtcFilter.filterForFaultDetectionCounter = filterForFaultDetectionCounter;
\r
1891 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1893 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETDTCFILTER_ID, DEM_E_UNINIT);
\r
1894 returnCode = DEM_WRONG_FILTER;
\r
1897 return returnCode;
\r
1902 * Procedure: Dem_GetStatusOfDTC
\r
1905 Dem_ReturnGetStatusOfDTCType Dem_GetStatusOfDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, Dem_EventStatusExtendedType* status) {
\r
1906 Dem_ReturnGetStatusOfDTCType returnCode = DEM_STATUS_FAILED;
\r
1907 EventStatusRecType *eventRec;
\r
1909 if (demState == DEM_INITIALIZED) {
\r
1910 if (lookupDtcEvent(dtc, &eventRec)) {
\r
1911 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
1912 if (checkDtcOrigin(dtcOrigin,eventRec->eventParamRef)) {
\r
1913 *status = eventRec->eventStatusExtended; /** @req DEM059 */
\r
1914 returnCode = DEM_STATUS_OK;
\r
1917 returnCode = DEM_STATUS_WRONG_DTCORIGIN; /** @req DEM171 */
\r
1921 returnCode = DEM_STATUS_WRONG_DTCKIND;
\r
1925 returnCode = DEM_STATUS_WRONG_DTC; /** @req DEM172 */
\r
1928 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETSTATUSOFDTC_ID, DEM_E_UNINIT);
\r
1929 returnCode = DEM_STATUS_FAILED;
\r
1932 return returnCode;
\r
1937 * Procedure: Dem_GetNumberOfFilteredDtc
\r
1940 Dem_ReturnGetNumberOfFilteredDTCType Dem_GetNumberOfFilteredDtc(uint16 *numberOfFilteredDTC) {
\r
1942 uint16 numberOfFaults = 0;
\r
1943 Dem_ReturnGetNumberOfFilteredDTCType returnCode = DEM_NUMBER_OK;
\r
1945 if (demState == DEM_INITIALIZED) {
\r
1946 //Dem_DisableEventStatusUpdate();
\r
1948 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1949 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1950 if (matchEventWithDtcFilter(&eventStatusBuffer[i])) {
\r
1951 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
1958 //Dem_EnableEventStatusUpdate();
\r
1960 *numberOfFilteredDTC = numberOfFaults; /** @req DEM061 */
\r
1962 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETNUMBEROFFILTEREDDTC_ID, DEM_E_UNINIT);
\r
1963 returnCode = DEM_NUMBER_FAILED;
\r
1966 return returnCode;
\r
1971 * Procedure: Dem_GetNextFilteredDTC
\r
1974 Dem_ReturnGetNextFilteredDTCType Dem_GetNextFilteredDTC(uint32 *dtc, Dem_EventStatusExtendedType *dtcStatus)
\r
1976 Dem_ReturnGetNextFilteredDTCType returnCode = DEM_FILTERED_OK;
\r
1977 boolean dtcFound = FALSE;
\r
1979 if (demState == DEM_INITIALIZED) {
\r
1980 // TODO: This job should be done in an more advanced way according to Dem217
\r
1981 while ((!dtcFound) && (dtcFilter.faultIndex != 0)) {
\r
1982 dtcFilter.faultIndex--;
\r
1983 if (eventStatusBuffer[dtcFilter.faultIndex].eventId != DEM_EVENT_ID_NULL) {
\r
1984 if (matchEventWithDtcFilter(&eventStatusBuffer[dtcFilter.faultIndex])) {
\r
1985 if (eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef != NULL) {
\r
1986 *dtc = eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef->DTC; /** @req DEM216 */
\r
1987 *dtcStatus = eventStatusBuffer[dtcFilter.faultIndex].eventStatusExtended;
\r
1995 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1996 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
1999 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETNEXTFILTEREDDTC_ID, DEM_E_UNINIT);
\r
2000 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
2003 return returnCode;
\r
2008 * Procedure: Dem_GetTranslationType
\r
2011 Dem_ReturnTypeOfDtcSupportedType Dem_GetTranslationType(void)
\r
2013 return DEM_TYPE_OF_DTC_SUPPORTED; /** @req DEM231 */
\r
2018 * Procedure: Dem_ClearDTC
\r
2021 Dem_ReturnClearDTCType Dem_ClearDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin) /** @req DEM009 */
\r
2023 Dem_ReturnClearDTCType returnCode = DEM_CLEAR_OK;
\r
2024 Dem_EventIdType eventId;
\r
2025 const Dem_EventParameterType *eventParam;
\r
2028 if (demState == DEM_INITIALIZED) {
\r
2029 // Loop through the event buffer
\r
2030 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2031 eventId = eventStatusBuffer[i].eventId;
\r
2032 if (eventId != DEM_EVENT_ID_NULL) {
\r
2033 eventParam = eventStatusBuffer[i].eventParamRef;
\r
2034 if (eventParam != NULL) {
\r
2035 //lint -e506 PC-Lint exception Misra 13.7, 14.1 Allow configuration variables in boolean expression
\r
2036 //lint -e774 PC-Lint exception Related to MISRA 13.7
\r
2037 if ((DEM_CLEAR_ALL_EVENTS == STD_ON) || (eventParam->DTCClassRef != NULL)) {
\r
2038 if (checkDtcKind(dtcKind, eventParam)) {
\r
2039 if (checkDtcGroup(dtc, eventParam)) {
\r
2040 boolean dtcOriginFound = FALSE;
\r
2041 for (j = 0; (j < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound) ; j++){
\r
2042 dtcOriginFound =(eventParam->EventClass->EventDestination[j] == dtcOrigin);
\r
2044 //if (j-1 < DEM_MAX_NR_OF_EVENT_DESTINATION) {
\r
2045 if (dtcOriginFound) {
\r
2046 // Yes! All conditions met.
\r
2047 switch (dtcOrigin)
\r
2049 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2050 /** @req DEM077 */
\r
2051 deleteEventPriMem(eventParam);
\r
2052 deleteFreezeFrameDataPriMem(eventParam);
\r
2053 deleteExtendedDataPriMem(eventParam);
\r
2054 deleteEventStatusRec(eventParam); // TODO: Shall this be done or just resetting the status?
\r
2057 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2058 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2059 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2060 // Not yet supported
\r
2061 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2062 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2065 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2074 // Fatal error, no event parameters found for the stored event!
\r
2075 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNEXPECTED_EXECUTION);
\r
2080 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNINIT);
\r
2081 returnCode = DEM_CLEAR_FAILED;
\r
2084 return returnCode;
\r
2089 * Procedure: Dem_DisableDTCStorage
\r
2092 Dem_ReturnControlDTCStorageType Dem_DisableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind) /** @req DEM035 */
\r
2094 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2096 if (demState == DEM_INITIALIZED) {
\r
2097 // Check dtcGroup parameter
\r
2098 if (dtcGroup == DEM_DTC_GROUP_ALL_DTCS) {
\r
2099 // Check dtcKind parameter
\r
2100 if ((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS)) {
\r
2101 /** @req DEM079 */
\r
2102 disableDtcStorage.dtcGroup = dtcGroup;
\r
2103 disableDtcStorage.dtcKind = dtcKind;
\r
2104 disableDtcStorage.storageDisabled = TRUE;
\r
2106 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2109 returnCode = DEM_CONTROL_DTC_WRONG_DTCGROUP;
\r
2112 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_DISABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
2113 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2116 return returnCode;
\r
2121 * Procedure: Dem_EnableDTCStorage
\r
2124 Dem_ReturnControlDTCStorageType Dem_EnableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind)
\r
2126 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2128 if (demState == DEM_INITIALIZED) {
\r
2129 // TODO: Behavior is not defined if group or kind do not match active settings, therefore the filter is just switched off.
\r
2130 (void)dtcGroup; (void)dtcKind; // Just to make get rid of PC-Lint warnings
\r
2131 disableDtcStorage.storageDisabled = FALSE; /** @req DEM080 */
\r
2133 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_ENABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
2134 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2137 return returnCode;
\r
2141 * Procedure: Dem_GetExtendedDataRecordByDTC
\r
2144 Dem_ReturnGetExtendedDataRecordByDTCType Dem_GetExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint8 *destBuffer, uint16 *bufSize)
\r
2146 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_RECORD_WRONG_DTC;
\r
2147 EventStatusRecType *eventRec;
\r
2148 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2149 ExtDataRecType *extData;
\r
2150 uint16 posInExtData = 0;
\r
2152 if (demState == DEM_INITIALIZED) {
\r
2153 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2154 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2155 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2156 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2157 if (*bufSize >= extendedDataRecordClass->DataSize) {
\r
2158 switch (dtcOrigin)
\r
2160 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2161 if (lookupExtendedDataPriMem(eventRec->eventId, &extData)) {
\r
2162 // Yes all conditions met, copy the extended data record to destination buffer.
\r
2163 memcpy(destBuffer, &extData->data[posInExtData], extendedDataRecordClass->DataSize); /** @req DEM075 */ // 960 PC-Lint OK
\r
2164 *bufSize = extendedDataRecordClass->DataSize;
\r
2165 returnCode = DEM_RECORD_OK;
\r
2168 // The record number is legal but no record was found for the DTC
\r
2170 returnCode = DEM_RECORD_OK;
\r
2174 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2175 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2176 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2177 // Not yet supported
\r
2178 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2179 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2182 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2187 returnCode = DEM_RECORD_BUFFERSIZE;
\r
2191 returnCode = DEM_RECORD_NUMBER;
\r
2195 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2199 returnCode = DEM_RECORD_DTCKIND;
\r
2203 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
2204 returnCode = DEM_RECORD_WRONG_DTC;
\r
2207 return returnCode;
\r
2212 * Procedure: Dem_GetSizeOfExtendedDataRecordByDTC
\r
2215 Dem_ReturnGetSizeOfExtendedDataRecordByDTCType Dem_GetSizeOfExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint16 *sizeOfExtendedDataRecord)
\r
2217 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2218 EventStatusRecType *eventRec;
\r
2219 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2220 uint16 posInExtData;
\r
2222 if (demState == DEM_INITIALIZED) {
\r
2223 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2224 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2225 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2226 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2227 *sizeOfExtendedDataRecord = extendedDataRecordClass->DataSize; /** @req DEM076 */
\r
2228 returnCode = DEM_GET_SIZEOFEDRBYDTC_OK;
\r
2231 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_RNUM;
\r
2235 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCOR;
\r
2239 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCKI;
\r
2243 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETSIZEOFEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
2244 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2247 return returnCode;
\r
2250 /***********************************
\r
2251 * OBD-specific Interfaces (8.3.6) *
\r
2252 ***********************************/
\r