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
19 // 522 PC-Lint exception for empty functions
\r
20 //lint -esym(522,storeFreezeFrameDataEvtMem)
\r
21 //lint -esym(522,deleteFreezeFrameDataPriMem)
\r
22 //lint -esym(522,storeFreezeFrameDataPreInit)
\r
23 //lint -esym(522,storeFreezeFrameDataPriMem)
\r
24 //lint -esym(522,updateFreezeFrameOccurrencePreInit)
\r
26 // PC-Lint misunderstanding of MISRA 8.12, 18.1: Empty arrays are OK as long as size 0 is specified.
\r
27 //lint -esym(85,preInitFreezeFrameBuffer)
\r
28 //lint -esym(85,priMemFreezeFrameBuffer)
\r
32 * General requirements
\r
35 /** @req DEM151.partially */
\r
37 /** @req DEM013.14229-1 */
\r
40 /** @req DEM113 */ /** @req DEM174 */
\r
54 //#include "SchM_Dem.h"
\r
57 #include "DEM_Types.h"
\r
58 #include "DEM_Lcfg.h"
\r
60 #define USE_DEBUG_PRINTF
\r
65 #define DEBOUNCE_FDC_TEST_FAILED 127
\r
66 #define DEBOUNCE_FDC_TEST_PASSED -128
\r
68 #if ( DEM_DEV_ERROR_DETECT == STD_ON )
\r
71 #define VALIDATE_RV(_exp,_api,_err,_rv ) \
\r
73 Det_ReportError(MODULE_ID_DEM, 0, _api, _err); \
\r
77 #define VALIDATE_NO_RV(_exp,_api,_err ) \
\r
79 Det_ReportError(MODULE_ID_DEM, 0, _api, _err); \
\r
82 #define DET_REPORTERROR(_x,_y,_z,_q) Det_ReportError(_x, _y, _z, _q)
\r
85 #define VALIDATE_RV(_exp,_api,_err,_rv )
\r
86 #define VALIDATE_NO_RV(_exp,_api,_err )
\r
87 #define DET_REPORTERROR(_x,_y,_z,_q)
\r
90 #if (DEM_OBD_SUPPORT == STD_ON)
\r
91 #error "DEM_OBD_SUPPORT is set to STD_ON, this is not supported by the code."
\r
94 #if (DEM_PTO_SUPPORT == STD_ON)
\r
95 #error "DEM_PTO_SUPPORT is set to STD_ON, this is not supported by the code."
\r
98 #if (DEM_TYPE_OF_DTC_SUPPORTED != 0x01)
\r
99 #error "DEM_TYPE_OF_DTC_SUPPORTED is not set to 1 (ISO14229-1), only ISO14229-1 is currently supported by the code."
\r
109 Dem_EventStatusExtendedType dtcStatusMask;
\r
110 Dem_DTCKindType dtcKind;
\r
111 Dem_DTCOriginType dtcOrigin;
\r
112 Dem_FilterWithSeverityType filterWithSeverity;
\r
113 Dem_DTCSeverityType dtcSeverityMask;
\r
114 Dem_FilterForFDCType filterForFaultDetectionCounter;
\r
118 // DisableDtcStorageType
\r
120 boolean storageDisabled;
\r
121 Dem_DTCGroupType dtcGroup;
\r
122 Dem_DTCKindType dtcKind;
\r
123 } DisableDtcStorageType;
\r
125 // For keeping track of the events status
\r
127 Dem_EventIdType eventId;
\r
128 const Dem_EventParameterType *eventParamRef;
\r
129 sint8 faultDetectionCounter;
\r
130 uint16 occurrence; /** @req DEM011 */
\r
131 Dem_EventStatusExtendedType eventStatusExtended; /** @req DEM006 */
\r
132 boolean errorStatusChanged;
\r
133 } EventStatusRecType;
\r
135 // Types for storing different event aging counter
\r
137 Dem_EventIdType eventId;
\r
138 uint8 agingCounter;/** @req Dem019 */
\r
139 ChecksumType checksum;
\r
142 // Types for storing different event data on event memory
\r
144 Dem_EventIdType eventId;
\r
146 Dem_EventStatusExtendedType eventStatusExtended;
\r
147 ChecksumType checksum;
\r
151 Dem_EventIdType eventId;
\r
153 uint8 data[DEM_MAX_SIZE_EXT_DATA];
\r
154 ChecksumType checksum;
\r
161 DEM_UNINITIALIZED = 0,
\r
162 DEM_PREINITIALIZED,
\r
164 } Dem_StateType; /** @req DEM169 */
\r
167 static Dem_StateType demState = DEM_UNINITIALIZED;
\r
169 // Help pointer to configuration set
\r
170 static const Dem_ConfigSetType *configSet;
\r
173 * Allocation of DTC filter parameters
\r
175 static DtcFilterType dtcFilter;
\r
178 * Allocation of Disable/Enable DTC storage parameters
\r
180 static DisableDtcStorageType disableDtcStorage;
\r
183 * Allocation of operation cycle state list
\r
185 static Dem_OperationCycleStateType operationCycleStateList[DEM_OPERATION_CYCLE_ID_ENDMARK];
\r
188 * Allocation of local event status buffer
\r
190 static EventStatusRecType eventStatusBuffer[DEM_MAX_NUMBER_EVENT];
\r
193 * Allocation of pre-init event memory (used between pre-init and init)
\r
196 static FreezeFrameRecType preInitFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRE_INIT];
\r
197 static ExtDataRecType preInitExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRE_INIT];
\r
200 * Allocation of primary event memory ramlog (after init) in uninitialized memory
\r
203 EventRecType priMemEventBuffer[DEM_MAX_NUMBER_EVENT_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
204 static FreezeFrameRecType priMemFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
205 //FreezeFrameRecType FreezeFrameMirrorBuffer[DEM_MAX_NUMBER_FF_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
206 extern FreezeFrameRecType* FreezeFrameMirrorBuffer[];
\r
207 static ExtDataRecType priMemExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
208 HealingRecType priMemAgingBuffer[DEM_MAX_NUMBER_AGING_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
209 extern HealingRecType HealingMirrorBuffer[DEM_MAX_NUMBER_AGING_PRI_MEM];
\r
211 /* block in NVRam, use for freezeframe */
\r
212 extern const NvM_BlockIdType FreezeFrameBlockId[DEM_MAX_NUMBER_FF_DATA_PRI_MEM];
\r
213 /* block in NVRam, use for aging */
\r
214 extern const NvM_BlockIdType AgingBlockId;
\r
218 *Allocation of freezeFrame storage timestamp,record the time order
\r
220 /**private variable for freezeframe */
\r
221 static uint32 FF_TimeStamp = 0;
\r
224 * TRUE: priMemFreezeFrameBuffer changed,
\r
225 * FALSE: priMemFreezeFrameBuffer not changed
\r
227 static boolean FFIsModified = FALSE;
\r
230 * TRUE: priMemAgingBuffer changed,
\r
231 * FALSE: priMemAgingBuffer not changed
\r
233 static boolean AgingIsModified = FALSE;
\r
236 * Procedure: zeroPriMemBuffers
\r
237 * Description: Fill the primary buffers with zeroes
\r
240 //lint -e84 //PC-Lint exception, size 0 is OK.
\r
241 //lint -e957 PC-Lint exception - Used only by DemTest
\r
242 void demZeroPriMemBuffers(void)
\r
244 memset(priMemEventBuffer, 0, sizeof(priMemEventBuffer));
\r
245 memset(priMemFreezeFrameBuffer, 0, sizeof(priMemFreezeFrameBuffer));
\r
246 memset(priMemExtDataBuffer, 0, sizeof(priMemExtDataBuffer));
\r
251 * Procedure: calcChecksum
\r
252 * Description: Calculate checksum over *data to *(data+nrOfBytes-1) area
\r
254 static ChecksumType calcChecksum(void *data, uint16 nrOfBytes)
\r
257 uint8 *byte = (uint8*)data;
\r
258 ChecksumType sum = 0;
\r
260 for (i = 0; i < nrOfBytes; i++) {
\r
269 * Procedure: checkDtcKind
\r
270 * Description: Return TRUE if "dtcKind" match the events DTCKind or "dtcKind"
\r
271 * is "DEM_DTC_KIND_ALL_DTCS" otherwise FALSE.
\r
273 static boolean checkDtcKind(Dem_DTCKindType dtcKind, const Dem_EventParameterType *eventParam)
\r
275 boolean result = FALSE;
\r
277 if (dtcKind == DEM_DTC_KIND_ALL_DTCS) {
\r
281 if (eventParam->DTCClassRef != NULL) {
\r
282 if (eventParam->DTCClassRef->DTCKind == dtcKind) {
\r
292 * Procedure: checkDtcGroup
\r
293 * Description: Return TRUE if "dtc" match the events DTC or "dtc" is
\r
294 * "DEM_DTC_GROUP_ALL_DTCS" otherwise FALSE.
\r
296 static boolean checkDtcGroup(uint32 dtc, const Dem_EventParameterType *eventParam)
\r
298 boolean result = FALSE;
\r
300 if (dtc == DEM_DTC_GROUP_ALL_DTCS) {
\r
304 if (eventParam->DTCClassRef != NULL) {
\r
305 if (eventParam->DTCClassRef->DTC == dtc) {
\r
315 * Procedure: checkDtcOrigin
\r
316 * Description: Return TRUE if "dtcOrigin" match any of the events DTCOrigin otherwise FALSE.
\r
318 static boolean checkDtcOrigin(Dem_DTCOriginType dtcOrigin, const Dem_EventParameterType *eventParam)
\r
320 boolean result = FALSE;
\r
321 boolean dtcOriginFound = FALSE;
\r
324 for (i = 0;(i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound); i++){
\r
325 dtcOriginFound = (eventParam->EventClass->EventDestination[i] == dtcOrigin);
\r
328 if (dtcOriginFound) {
\r
336 * Procedure: checkDtcSeverityMask
\r
337 * Description: Return TRUE if "dtcSeverityMask" match any of the events DTC severity otherwise FALSE.
\r
339 // PC-Lint (715 etc): Remove errors until function is filled.
\r
340 //lint -e{715} Symbol not referenced
\r
341 static boolean checkDtcSeverityMask(Dem_DTCSeverityType dtcSeverityMask, const Dem_EventParameterType *eventParam)
\r
343 boolean result = TRUE;
\r
345 // TODO: This function is optional, may be implemented here.
\r
352 * Procedure: checkDtcFaultDetectionCounterMask
\r
353 * Description: TBD.
\r
355 // PC-Lint (715 etc): Remove errors until function is filled.
\r
356 //lint -e{715} Symbol not referenced
\r
357 static boolean checkDtcFaultDetectionCounter(const Dem_EventParameterType *eventParam)
\r
359 boolean result = TRUE;
\r
361 // TODO: Not implemented yet.
\r
368 * Procedure: lookupEventStatusRec
\r
369 * Description: Returns the pointer to event id parameters of "eventId" in "*eventStatusBuffer",
\r
370 * if not found NULL is returned.
\r
372 static void lookupEventStatusRec(Dem_EventIdType eventId, EventStatusRecType **const eventStatusRec)
\r
375 boolean eventIdFound = FALSE;
\r
377 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!eventIdFound); i++) {
\r
378 eventIdFound = (eventStatusBuffer[i].eventId == eventId);
\r
381 if (eventIdFound) {
\r
382 *eventStatusRec = &eventStatusBuffer[i-1];
\r
384 *eventStatusRec = NULL;
\r
390 * Procedure: lookupEventIdParameter
\r
391 * Description: Returns the pointer to event id parameters of "eventId" in "*eventIdParam",
\r
392 * if not found NULL is returned.
\r
394 static void lookupEventIdParameter(Dem_EventIdType eventId, const Dem_EventParameterType **const eventIdParam)
\r
396 const Dem_EventParameterType *EventIdParamList = configSet->EventParameter;
\r
398 /* Lookup the correct event id parameters */
\r
400 while ((EventIdParamList[i].EventID != eventId) && (!EventIdParamList[i].Arc_EOL)) {
\r
404 if (!EventIdParamList[i].Arc_EOL) {
\r
405 *eventIdParam = &EventIdParamList[i];
\r
407 *eventIdParam = NULL;
\r
413 * Procedure: preDebounceNone
\r
414 * Description: Returns the result of the debouncing.
\r
416 static Dem_EventStatusType preDebounceNone(const Dem_EventStatusType reportedStatus, const EventStatusRecType* statusRecord) {
\r
417 Dem_EventStatusType returnCode;
\r
418 (void)statusRecord; // Just to get rid of PC-Lint warnings
\r
420 switch (reportedStatus) {
\r
421 case DEM_EVENT_STATUS_FAILED: /** @req DEM091.NoneFailed */
\r
422 case DEM_EVENT_STATUS_PASSED: /** @req DEM091.NonePassed */
\r
423 // Already debounced, do nothing.
\r
427 // TODO: What to do with PREFAIL and PREPASSED on no debouncing?
\r
428 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_NONE_ID, DEM_E_PARAM_DATA);
\r
432 returnCode = reportedStatus;
\r
438 * Procedure: preDebounceCounterBased
\r
439 * Description: Returns the result of the debouncing.
\r
441 static Dem_EventStatusType preDebounceCounterBased(Dem_EventStatusType reportedStatus, EventStatusRecType* statusRecord) {
\r
442 Dem_EventStatusType returnCode;
\r
443 const Dem_PreDebounceCounterBasedType* pdVars = statusRecord->eventParamRef->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceCounterBased;
\r
445 switch (reportedStatus) {
\r
446 case DEM_EVENT_STATUS_PREFAILED:
\r
447 if (statusRecord->faultDetectionCounter < DEBOUNCE_FDC_TEST_FAILED) {
\r
448 if ((pdVars->JumpUp) && (statusRecord->faultDetectionCounter < 0)) {
\r
449 statusRecord->faultDetectionCounter = 0;
\r
451 if (((sint16)statusRecord->faultDetectionCounter + (sint8)pdVars->CountInStepSize) < DEBOUNCE_FDC_TEST_FAILED) {
\r
452 statusRecord->faultDetectionCounter += (sint8)pdVars->CountInStepSize;
\r
454 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED;
\r
460 case DEM_EVENT_STATUS_PREPASSED:
\r
461 if (statusRecord->faultDetectionCounter > DEBOUNCE_FDC_TEST_PASSED) {
\r
462 if ((pdVars->JumpDown) && (statusRecord->faultDetectionCounter > 0)) {
\r
463 statusRecord->faultDetectionCounter = 0;
\r
465 if (((sint16)statusRecord->faultDetectionCounter - (sint8)pdVars->CountOutStepSize) > DEBOUNCE_FDC_TEST_PASSED) {
\r
466 statusRecord->faultDetectionCounter -= (sint8)pdVars->CountOutStepSize;
\r
468 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED;
\r
474 case DEM_EVENT_STATUS_FAILED:
\r
475 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED; /** @req DEM091.CounterFailed */
\r
478 case DEM_EVENT_STATUS_PASSED:
\r
479 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED; /** @req DEM091.CounterPassed */
\r
483 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_COUNTER_BASED_ID, DEM_E_PARAM_DATA);
\r
488 switch (statusRecord->faultDetectionCounter) {
\r
489 case DEBOUNCE_FDC_TEST_FAILED:
\r
490 returnCode = DEM_EVENT_STATUS_FAILED;
\r
493 case DEBOUNCE_FDC_TEST_PASSED:
\r
494 returnCode = DEM_EVENT_STATUS_PASSED;
\r
498 returnCode = reportedStatus;
\r
507 * Procedure: updateEventStatusRec
\r
508 * Description: Update the status of "eventId", if not exist and "createIfNotExist" is
\r
509 * true a new record is created
\r
511 static void updateEventStatusRec(const Dem_EventParameterType *eventParam, Dem_EventStatusType eventStatus, boolean createIfNotExist, EventStatusRecType *eventStatusRec)
\r
513 EventStatusRecType *eventStatusRecPtr;
\r
514 sint8 faultCounterBeforeDebounce = 0;
\r
515 sint8 faultCounterAfterDebounce = 0;
\r
519 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
521 if ((eventStatusRecPtr == NULL) && (createIfNotExist)) {
\r
522 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
523 if (eventStatusRecPtr != NULL) {
\r
524 eventStatusRecPtr->eventId = eventParam->EventID;
\r
525 eventStatusRecPtr->eventParamRef = eventParam;
\r
526 eventStatusRecPtr->faultDetectionCounter = 0;
\r
527 eventStatusRecPtr->occurrence = 0;
\r
528 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
529 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
532 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
537 if (eventStatusRecPtr != NULL) {
\r
538 faultCounterBeforeDebounce = eventStatusRecPtr->faultDetectionCounter;
\r
540 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
541 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName) { /** @req DEM004 */ /** @req DEM342 */
\r
542 case DEM_NO_PRE_DEBOUNCE:
\r
543 eventStatus = preDebounceNone(eventStatus, eventStatusRecPtr);
\r
546 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
547 eventStatus = preDebounceCounterBased(eventStatus, eventStatusRecPtr);
\r
551 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
555 faultCounterAfterDebounce = eventStatusRecPtr->faultDetectionCounter;
\r
557 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
559 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
560 if (!(eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED)) {
\r
561 eventStatusRecPtr->occurrence++;
\r
562 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
564 /** @req DEM036 */ /** @req DEM379.PendingSet */
\r
565 eventStatusRecPtr->eventStatusExtended |= (DEM_TEST_FAILED | DEM_TEST_FAILED_THIS_OPERATION_CYCLE | DEM_TEST_FAILED_SINCE_LAST_CLEAR | DEM_PENDING_DTC | DEM_CONFIRMED_DTC);
\r
566 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
569 if (eventStatus == DEM_EVENT_STATUS_PASSED) {
\r
570 if (eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED) {
\r
571 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
574 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED;
\r
575 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
578 if ((eventStatus == DEM_EVENT_STATUS_PREFAILED)\
\r
579 && (faultCounterBeforeDebounce <= 0) && (faultCounterAfterDebounce > 0)){
\r
580 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
583 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
586 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
587 eventStatusRec->faultDetectionCounter = 0;
\r
588 eventStatusRec->occurrence = 0;
\r
589 eventStatusRec->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
590 eventStatusRec->errorStatusChanged = FALSE;
\r
593 Irq_Restore(state);
\r
598 * Procedure: mergeEventStatusRec
\r
599 * Description: Update the occurrence counter of status, if not exist a new record is created
\r
601 static void mergeEventStatusRec(const EventRecType *eventRec)
\r
603 EventStatusRecType *eventStatusRecPtr;
\r
608 lookupEventStatusRec(eventRec->eventId, &eventStatusRecPtr);
\r
610 if (eventStatusRecPtr != NULL) {
\r
611 // Update occurrence counter.
\r
612 eventStatusRecPtr->occurrence += eventRec->occurrence;
\r
613 // Merge event status extended with stored
\r
614 // TEST_FAILED_SINCE_LAST_CLEAR should be set if set if set in either
\r
615 eventStatusRecPtr->eventStatusExtended |= (Dem_EventStatusExtendedType)(eventRec->eventStatusExtended & DEM_TEST_FAILED_SINCE_LAST_CLEAR);
\r
616 // DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR should cleared if cleared in either
\r
617 eventStatusRecPtr->eventStatusExtended |= (Dem_EventStatusExtendedType)(eventRec->eventStatusExtended & eventStatusRecPtr->eventStatusExtended & DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR);
\r
618 // DEM_PENDING_DTC and DEM_CONFIRMED_DTC should be set if set in either
\r
619 eventStatusRecPtr->eventStatusExtended |= (Dem_EventStatusExtendedType)(eventRec->eventStatusExtended & (DEM_PENDING_DTC | DEM_CONFIRMED_DTC));
\r
623 // Search for free position
\r
624 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
626 if (eventStatusRecPtr != NULL) {
\r
627 // Create new event, from stored event
\r
628 eventStatusRecPtr->eventId = eventRec->eventId;
\r
629 lookupEventIdParameter(eventRec->eventId, &eventStatusRecPtr->eventParamRef);
\r
630 eventStatusRecPtr->faultDetectionCounter = 0;
\r
631 eventStatusRecPtr->occurrence = eventRec->occurrence;
\r
632 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
633 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
636 // Error: Event status buffer full
\r
637 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_MERGE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
641 Irq_Restore(state);
\r
645 * Procedure: resetEventStatusRec
\r
646 * Description: Reset the status record of "eventParam->eventId" from "eventStatusBuffer".
\r
648 static void resetEventStatusRec(const Dem_EventParameterType *eventParam)
\r
650 EventStatusRecType *eventStatusRecPtr;
\r
655 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
657 if (eventStatusRecPtr != NULL) {
\r
658 // Reset event record
\r
659 eventStatusRecPtr->faultDetectionCounter = 0;
\r
660 eventStatusRecPtr->eventStatusExtended = (DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR);
\r
661 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
662 eventStatusRecPtr->occurrence = 0;
\r
665 Irq_Restore(state);
\r
669 * Procedure: getEventStatusRec
\r
670 * Description: Returns the status record of "eventId" in "eventStatusRec"
\r
672 static void getEventStatusRec(Dem_EventIdType eventId, EventStatusRecType *eventStatusRec)
\r
674 EventStatusRecType *eventStatusRecPtr;
\r
677 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
679 if (eventStatusRecPtr != NULL) {
\r
681 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
684 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
690 * Procedure: lookupDtcEvent
\r
691 * Description: Returns TRUE if the DTC was found and "eventStatusRec" points
\r
692 * to the event record found.
\r
694 static boolean lookupDtcEvent(uint32 dtc, EventStatusRecType **eventStatusRec)
\r
696 boolean dtcFound = FALSE;
\r
699 *eventStatusRec = NULL;
\r
701 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!dtcFound); i++) {
\r
702 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
703 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
706 if (eventStatusBuffer[i].eventParamRef->DTCClassRef->DTC == dtc) {
\r
707 *eventStatusRec = &eventStatusBuffer[i];
\r
719 * Procedure: matchEventWithDtcFilter
\r
720 * Description: Returns TRUE if the event pointed by "event" fulfill
\r
721 * the "dtcFilter" global filter settings.
\r
723 static boolean matchEventWithDtcFilter(const EventStatusRecType *eventRec)
\r
725 boolean dtcMatch = FALSE;
\r
728 if ((dtcFilter.dtcStatusMask == DEM_DTC_STATUS_MASK_ALL) || (eventRec->eventStatusExtended & dtcFilter.dtcStatusMask)) {
\r
729 if (eventRec->eventParamRef != NULL) {
\r
732 if (checkDtcKind(dtcFilter.dtcKind, eventRec->eventParamRef)) {
\r
735 if (checkDtcOrigin(dtcFilter.dtcOrigin, eventRec->eventParamRef)) {
\r
738 if ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
739 || ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES) && (checkDtcSeverityMask(dtcFilter.dtcSeverityMask, eventRec->eventParamRef)))) {
\r
741 // Check fault detection counter
\r
742 if ((dtcFilter.filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO)
\r
743 || ((dtcFilter.filterWithSeverity == DEM_FILTER_FOR_FDC_YES) && (checkDtcFaultDetectionCounter(eventRec->eventParamRef)))) {
\r
755 * Procedure: bubbleSort
\r
756 * Description: bubble sort
\r
758 static void bubbleSort(FreezeFrameRecType *freezeFrameBuf, uint16 length)
\r
760 FreezeFrameRecType temp;
\r
764 //Bubble sort:rearrange priMemFreezeFrameBuffer from little to big
\r
765 for(i=0;i<length;i++){
\r
766 for(j=length-1; j > i; j--){
\r
767 if(freezeFrameBuf[i].timeStamp > freezeFrameBuf[j].timeStamp){
\r
768 //exchange buffer data
\r
769 memcpy(&temp,&freezeFrameBuf[i],sizeof(FreezeFrameRecType));
\r
770 memcpy(&freezeFrameBuf[i],&freezeFrameBuf[j],sizeof(FreezeFrameRecType));
\r
771 memcpy(&freezeFrameBuf[j],&temp,sizeof(FreezeFrameRecType));
\r
779 * Procedure: retrieveEventStatusBit
\r
780 * Description: retrieve Event Status Bit
\r
782 static boolean retrieveEventStatusBit(FreezeFrameRecType *freezeFrameBuf,
\r
784 Dem_EventStatusExtendedType nBit,
\r
785 FreezeFrameRecType **freezeFrame)
\r
787 boolean freezeFrameFound = FALSE;
\r
791 for(i=0;i<length;i++){
\r
792 for(j=0; (j < DEM_MAX_NUMBER_EVENT) && (!freezeFrameFound); j++){
\r
793 freezeFrameFound = (eventStatusBuffer[j].eventId == freezeFrameBuf[i].eventId)\
\r
794 && (!(eventStatusBuffer[j].eventStatusExtended & nBit));
\r
795 if(freezeFrameFound == TRUE){
\r
796 *freezeFrame = &freezeFrameBuf[i];
\r
801 return freezeFrameFound;
\r
806 * Procedure: lookupFreezeFrameForDisplacementPreInit
\r
807 * Description: implement displacement strategy preinit:1.find out the oldest "not confirmed" DTC
\r
808 * 2.find out the oldest inactive DTC,inactive:testFailed is not set
\r
809 * 3.find ou the oldest active DTC,active:testFailed is set
\r
811 static boolean lookupFreezeFrameForDisplacementPreInit(FreezeFrameRecType **freezeFrame)
\r
813 boolean freezeFrameFound = FALSE;
\r
815 /* Bubble sort:rearrange priMemFreezeFrameBuffer from little to big */
\r
816 bubbleSort(preInitFreezeFrameBuffer, DEM_MAX_NUMBER_FF_DATA_PRE_INIT);
\r
818 /* find out the oldest not confirmed dtc */
\r
819 freezeFrameFound = retrieveEventStatusBit(preInitFreezeFrameBuffer, DEM_MAX_NUMBER_FF_DATA_PRE_INIT, DEM_CONFIRMED_DTC, freezeFrame);
\r
821 /* if all confirmed,lookup the oldest inactive dtc */
\r
822 if(freezeFrameFound == FALSE){
\r
823 freezeFrameFound = retrieveEventStatusBit(preInitFreezeFrameBuffer, DEM_MAX_NUMBER_FF_DATA_PRE_INIT, DEM_TEST_FAILED, freezeFrame);
\r
826 /* if all confirmed,lookup the oldest active dtc */
\r
827 if(freezeFrameFound == FALSE){
\r
828 *freezeFrame = &preInitFreezeFrameBuffer[0];
\r
829 freezeFrameFound = TRUE;
\r
832 return freezeFrameFound;
\r
836 * Procedure: lookupFreezeFrameForDisplacement
\r
837 * Description: implement displacement strategy:1.find out the oldest "not confirmed" DTC
\r
838 * 2.find out the oldest inactive DTC,inactive:testFailed is not set
\r
839 * 3.find ou the oldest active DTC,active:testFailed is set
\r
841 static boolean lookupFreezeFrameForDisplacement(FreezeFrameRecType **freezeFrame)
\r
843 boolean freezeFrameFound = FALSE;
\r
845 bubbleSort(priMemFreezeFrameBuffer, DEM_MAX_NUMBER_FF_DATA_PRI_MEM);
\r
847 /* Find out the oldest not confirmed dtc */
\r
848 freezeFrameFound = retrieveEventStatusBit(priMemFreezeFrameBuffer, DEM_MAX_NUMBER_FF_DATA_PRI_MEM, DEM_CONFIRMED_DTC, freezeFrame);
\r
850 /* If all confirmed, lookup the oldest inactive dtc */
\r
851 if(freezeFrameFound == FALSE){
\r
852 freezeFrameFound = retrieveEventStatusBit(priMemFreezeFrameBuffer, DEM_MAX_NUMBER_FF_DATA_PRI_MEM, DEM_TEST_FAILED, freezeFrame);
\r
855 /* If all confirmed,lookup the oldest active dtc */
\r
856 if(freezeFrameFound == FALSE){
\r
857 *freezeFrame = &priMemFreezeFrameBuffer[0];
\r
858 freezeFrameFound = TRUE;
\r
861 return freezeFrameFound;
\r
864 * Procedure: rearrangeFreezeFrameTimeStamp
\r
865 * Description: rearrange FF timestamp when timestamp is beyond DEM_MAX_TIMESTAMP_FOR_REARRANGEMENT
\r
867 static void rearrangeFreezeFrameTimeStamp(uint32 *timeStamp)
\r
869 FreezeFrameRecType temp;
\r
874 /* Bubble sort:rearrange priMemFreezeFrameBuffer from little to big */
\r
875 for(i=0;i<DEM_MAX_NUMBER_FF_DATA_PRI_MEM;i++){
\r
876 if(priMemFreezeFrameBuffer[i].eventId != DEM_EVENT_ID_NULL){
\r
877 for(j=DEM_MAX_NUMBER_FF_DATA_PRI_MEM-1; j > i; j--){
\r
878 if(priMemFreezeFrameBuffer[j].eventId != DEM_EVENT_ID_NULL){
\r
879 if(priMemFreezeFrameBuffer[i].timeStamp > priMemFreezeFrameBuffer[j].timeStamp){
\r
880 //exchange buffer data
\r
881 memcpy(&temp,&priMemFreezeFrameBuffer[i],sizeof(FreezeFrameRecType));
\r
882 memcpy(&priMemFreezeFrameBuffer[i],&priMemFreezeFrameBuffer[j],sizeof(FreezeFrameRecType));
\r
883 memcpy(&priMemFreezeFrameBuffer[j],&temp,sizeof(FreezeFrameRecType));
\r
889 priMemFreezeFrameBuffer[i].timeStamp = k++;
\r
893 /* update the current timeStamp */
\r
898 * Procedure: getFreezeFrameData
\r
899 * Description: get FF data according configuration
\r
901 static void getFreezeFrameData(const Dem_EventParameterType *eventParam,
\r
902 FreezeFrameRecType *freezeFrame,
\r
903 Dem_EventStatusType eventStatus,
\r
904 EventStatusRecType *eventStatusRec)
\r
906 Dem_FreezeFrameStorageConditonType prefailedOrFailed;
\r
907 Std_ReturnType callbackReturnCode;
\r
909 uint16 storeIndex = 0;
\r
910 uint16 recordSize = 0;
\r
912 const Dem_FreezeFrameClassType *FreezeFrameLocal = NULL;
\r
913 Dcm_NegativeResponseCodeType errorCode;//should include Dcm_Lcfg.h
\r
915 /* clear FF data record */
\r
916 memset(freezeFrame, 0, sizeof(FreezeFrameRecType ));
\r
918 /* check if prefailed or failed */
\r
919 if(eventStatusRec->eventStatusExtended & DEM_TEST_FAILED){
\r
920 prefailedOrFailed = FAILED;//confirm the FF is stored for failed
\r
924 if(eventStatus == DEM_EVENT_STATUS_PREFAILED){
\r
925 prefailedOrFailed = PREFAILED;//confirm the FF is stored for prefailed
\r
928 prefailedOrFailed = FF_STORAGE_CONDITION_WRONG;
\r
929 freezeFrame->eventId = DEM_EVENT_ID_NULL;
\r
934 /* Find out the corresponding FF class */
\r
935 for(i = 0;(i<DEM_MAX_NR_OF_CLASSES_IN_FREEZEFRAME_DATA) && (eventParam->FreezeFrameClassRef[i] != NULL);i++){
\r
936 if(eventParam->FreezeFrameClassRef[i]->FFStorageConditon == prefailedOrFailed){
\r
937 FreezeFrameLocal = eventParam->FreezeFrameClassRef[i];
\r
942 if(FreezeFrameLocal != NULL){
\r
943 if(FreezeFrameLocal->FFIdClassRef != NULL){
\r
944 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_FREEZEFRAME_DATA) && (!(FreezeFrameLocal->FFIdClassRef[i].Arc_EOL)); i++) {
\r
945 if(FreezeFrameLocal->FFIdClassRef[i].PidOrDidUsePort == FALSE){
\r
946 if(FreezeFrameLocal->FFIdClassRef[i].DidReadDataLengthFnc != NULL){
\r
947 callbackReturnCode = FreezeFrameLocal->FFIdClassRef[i].DidReadDataLengthFnc(&recordSize);
\r
948 if(callbackReturnCode != E_OK){
\r
949 //if fail to read data length,discard the storage of FF
\r
950 freezeFrame->eventId = DEM_EVENT_ID_NULL;
\r
951 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GET_FREEZEFRAME_ID, DEM_READ_DATA_LENGTH_FAILED);
\r
955 /* if no readDidDataLengthFunction, then try the PidOrDidSize. */
\r
957 recordSize = FreezeFrameLocal->FFIdClassRef[i].PidOrDidSize;
\r
959 /* read out the did data */
\r
960 if ((storeIndex + recordSize + DEM_DID_IDENTIFIER_SIZE_OF_BYTES) <= DEM_MAX_SIZE_FF_DATA) {
\r
962 freezeFrame->data[storeIndex] = (FreezeFrameLocal->FFIdClassRef[i].DidIdentifier>> 8) & 0xFFu;
\r
964 freezeFrame->data[storeIndex] = FreezeFrameLocal->FFIdClassRef[i].DidIdentifier & 0xFFu;
\r
967 if(FreezeFrameLocal->FFIdClassRef[i].DidConditionCheckReadFnc != NULL){
\r
968 callbackReturnCode = FreezeFrameLocal->FFIdClassRef[i].DidConditionCheckReadFnc(&errorCode);
\r
969 if ((callbackReturnCode == E_OK) && (errorCode == DCM_E_POSITIVERESPONSE)) {
\r
970 if(FreezeFrameLocal->FFIdClassRef[i].DidReadFnc!= NULL){
\r
971 callbackReturnCode = FreezeFrameLocal->FFIdClassRef[i].DidReadFnc(&freezeFrame->data[storeIndex]);
\r
972 if (callbackReturnCode != E_OK) {
\r
973 memset(&freezeFrame->data[storeIndex], DEM_FREEZEFRAME_DEFAULT_VALUE, recordSize);
\r
975 storeIndex += recordSize;
\r
979 memset(&freezeFrame->data[storeIndex], DEM_FREEZEFRAME_DEFAULT_VALUE, recordSize);
\r
980 storeIndex += recordSize;
\r
985 memset(&freezeFrame->data[storeIndex], DEM_FREEZEFRAME_DEFAULT_VALUE, recordSize);
\r
986 storeIndex += recordSize;
\r
990 memset(&freezeFrame->data[storeIndex], DEM_FREEZEFRAME_DEFAULT_VALUE, recordSize);
\r
991 storeIndex += recordSize;
\r
996 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GET_FREEZEFRAME_ID, DEM_E_FF_TOO_BIG);
\r
1001 //TODO:RTE should provide the port
\r
1002 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GET_FREEZEFRAME_ID, DEM_DSP_DID_USE_PORT_IS_TRUE);
\r
1009 /* create an empty FF */
\r
1010 freezeFrame->eventId = DEM_EVENT_ID_NULL;
\r
1013 /* Check if any data has been stored */
\r
1014 if (storeIndex != 0) {
\r
1015 freezeFrame->eventId = eventParam->EventID;
\r
1016 freezeFrame->occurrence = eventStatusRec->occurrence;
\r
1017 freezeFrame->dataSize = storeIndex;
\r
1018 freezeFrame->recordNumber = FreezeFrameLocal->FFRecordNumber;
\r
1021 if(FF_TimeStamp > DEM_MAX_TIMESTAMP_FOR_REARRANGEMENT){
\r
1022 rearrangeFreezeFrameTimeStamp(&FF_TimeStamp);
\r
1025 freezeFrame->timeStamp = FF_TimeStamp;
\r
1029 Irq_Restore(state);
\r
1031 freezeFrame->checksum = calcChecksum(freezeFrame, sizeof(FreezeFrameRecType)-sizeof(ChecksumType));
\r
1034 freezeFrame->eventId = DEM_EVENT_ID_NULL;
\r
1035 freezeFrame->dataSize = storeIndex;
\r
1036 freezeFrame->checksum = 0;
\r
1042 * Procedure: storeFreezeFrameDataPreInit
\r
1043 * Description: store FF in before preInitFreezeFrameBuffer DEM's full initialization
\r
1045 static void storeFreezeFrameDataPreInit(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1047 boolean eventIdFound = FALSE;
\r
1048 boolean eventIdFreePositionFound=FALSE;
\r
1049 FreezeFrameRecType *freezeFrameLocal = NULL;
\r
1055 /* Check if already stored */
\r
1056 for (i = 0; (i<DEM_MAX_NUMBER_FF_DATA_PRE_INIT) && (!eventIdFound); i++){
\r
1057 eventIdFound = ((preInitFreezeFrameBuffer[i].eventId == eventParam->EventID) && (preInitFreezeFrameBuffer[i].recordNumber== freezeFrame->recordNumber));
\r
1061 /* overwrite existing */
\r
1062 memcpy(&preInitFreezeFrameBuffer[i-1], freezeFrame, sizeof(FreezeFrameRecType));
\r
1065 /* lookup first free position */
\r
1066 for (i = 0; (i<DEM_MAX_NUMBER_FF_DATA_PRE_INIT) && (!eventIdFreePositionFound); i++){
\r
1067 if(preInitFreezeFrameBuffer[i].eventId == DEM_EVENT_ID_NULL){
\r
1068 eventIdFreePositionFound=TRUE;
\r
1072 if (eventIdFreePositionFound) {
\r
1073 memcpy(&preInitFreezeFrameBuffer[i-1], freezeFrame, sizeof(FreezeFrameRecType));
\r
1076 /* do displacement */
\r
1077 if(lookupFreezeFrameForDisplacementPreInit(&freezeFrameLocal)){
\r
1078 memcpy(freezeFrameLocal, freezeFrame, sizeof(FreezeFrameRecType));
\r
1081 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_FF_DATA_PRE_INIT_ID, DEM_E_PRE_INIT_FF_DATA_BUFF_FULL);
\r
1086 Irq_Restore(state);
\r
1091 * Procedure: updateFreezeFrameOccurrencePreInit
\r
1092 * Description: update the occurrence in preInitFreezeFrameBuffer according to the occurrence stored in priMemEventBuffer
\r
1094 static void updateFreezeFrameOccurrencePreInit(const EventRecType *EventBuffer)
\r
1098 for (i = 0; i<DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++){
\r
1099 if(preInitFreezeFrameBuffer[i].eventId == EventBuffer->eventId){
\r
1100 preInitFreezeFrameBuffer[i].occurrence += EventBuffer->occurrence;
\r
1106 * Procedure: initCurrentFreezeFrameTimeStamp
\r
1107 * Description: initialize current timestamp and update the corresponding timestamp in preInitFreezeFrameBuffer
\r
1109 static void initCurrentFreezeFrameTimeStamp(uint32 *timeStampPtr)
\r
1117 /* Find out the biggest timestamp in the last power on */
\r
1118 for (i = 0; i<DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++){
\r
1119 if((priMemFreezeFrameBuffer[i].eventId != DEM_EVENT_ID_NULL) &&
\r
1120 (priMemFreezeFrameBuffer[i].timeStamp > temp)){
\r
1121 temp = priMemFreezeFrameBuffer[i].timeStamp;
\r
1125 for (i = 0; i<DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++){
\r
1126 if(preInitFreezeFrameBuffer[i].eventId != DEM_EVENT_ID_NULL){
\r
1127 preInitFreezeFrameBuffer[i].timeStamp += temp;
\r
1130 *timeStampPtr += temp;
\r
1131 Irq_Restore(state);
\r
1135 * Procedure: getExtendedData
\r
1136 * Description: Collects the extended data according to "eventParam" and return it in "extData",
\r
1137 * if not found eventId is set to DEM_EVENT_ID_NULL.
\r
1139 static void getExtendedData(const Dem_EventParameterType *eventParam, ExtDataRecType *extData)
\r
1141 Std_ReturnType callbackReturnCode;
\r
1143 uint16 storeIndex = 0;
\r
1144 uint16 recordSize;
\r
1146 // Clear ext data record
\r
1147 memset(extData, 0, sizeof(ExtDataRecType));
\r
1149 // Check if any pointer to extended data class
\r
1150 if (eventParam->ExtendedDataClassRef != NULL) {
\r
1151 // Request extended data and copy it to the buffer
\r
1152 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL); i++) {
\r
1153 recordSize = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
1154 if ((storeIndex + recordSize) <= DEM_MAX_SIZE_EXT_DATA) {
\r
1155 callbackReturnCode = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->CallbackGetExtDataRecord(&extData->data[storeIndex]); /** @req DEM282 */
\r
1156 if (callbackReturnCode != E_OK) {
\r
1157 // Callback data currently not available, clear space.
\r
1158 memset(&extData->data[storeIndex], 0xFF, recordSize);
\r
1160 storeIndex += recordSize;
\r
1163 // Error: Size of extended data record is bigger than reserved space.
\r
1164 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GET_EXTENDED_DATA_ID, DEM_E_EXT_DATA_TOO_BIG);
\r
1165 break; // Break the loop
\r
1170 // Check if any data has been stored
\r
1171 if (storeIndex != 0) {
\r
1172 extData->eventId = eventParam->EventID;
\r
1173 extData->dataSize = storeIndex;
\r
1174 extData->checksum = calcChecksum(extData, sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
1177 extData->eventId = DEM_EVENT_ID_NULL;
\r
1178 extData->dataSize = storeIndex;
\r
1179 extData->checksum = 0;
\r
1185 * Procedure: storeExtendedDataPreInit
\r
1186 * Description: Store the extended data pointed by "extendedData" to the "preInitExtDataBuffer",
\r
1187 * if non existent a new entry is created.
\r
1189 static void storeExtendedDataPreInit(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
1191 boolean eventIdFound = FALSE;
\r
1192 boolean eventIdFreePositionFound=FALSE;
\r
1197 // Check if already stored
\r
1198 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) && (!eventIdFound); i++){
\r
1199 eventIdFound = (preInitExtDataBuffer[i].eventId == eventParam->EventID);
\r
1203 // Yes, overwrite existing
\r
1204 memcpy(&preInitExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
1207 // No, lookup first free position
\r
1208 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) && (!eventIdFreePositionFound); i++){
\r
1209 if(preInitExtDataBuffer[i].eventId ==0){
\r
1210 eventIdFreePositionFound=TRUE;
\r
1214 if (eventIdFreePositionFound) {
\r
1215 memcpy(&preInitExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
1218 // Error: Pre init extended data buffer full
\r
1219 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRE_INIT_ID, DEM_E_PRE_INIT_EXT_DATA_BUFF_FULL);
\r
1223 Irq_Restore(state);
\r
1227 * Procedure: storeEventPriMem
\r
1228 * Description: Store the event data of "eventStatus->eventId" in "priMemEventBuffer",
\r
1229 * if non existent a new entry is created.
\r
1231 static void storeEventPriMem(const Dem_EventParameterType *eventParam, const EventStatusRecType *eventStatus)
\r
1233 boolean eventIdFound = FALSE;
\r
1234 boolean eventIdFreePositionFound=FALSE;
\r
1239 (void)*eventParam; // Currently not used, do this to avoid warning
\r
1241 // Lookup event ID
\r
1242 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
1243 eventIdFound = (priMemEventBuffer[i].eventId == eventStatus->eventId);
\r
1246 if (eventIdFound) {
\r
1247 // Update event found
\r
1248 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
1249 priMemEventBuffer[i-1].eventStatusExtended = eventStatus->eventStatusExtended;
\r
1250 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
1253 // Search for free position
\r
1254 for (i=0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFreePositionFound); i++){
\r
1255 eventIdFreePositionFound = (priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
1259 if (eventIdFreePositionFound) {
\r
1260 priMemEventBuffer[i-1].eventId = eventStatus->eventId;
\r
1261 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
1262 priMemEventBuffer[i-1].eventStatusExtended = eventStatus->eventStatusExtended;
\r
1263 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
1266 // Error: Pri mem event buffer full
\r
1267 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EVENT_PRI_MEM_ID, DEM_E_PRI_MEM_EVENT_BUFF_FULL);
\r
1271 Irq_Restore(state);
\r
1275 * Procedure: deleteEventPriMem
\r
1276 * Description: Delete the event data of "eventParam->eventId" from "priMemEventBuffer".
\r
1278 static void deleteEventPriMem(const Dem_EventParameterType *eventParam)
\r
1280 boolean eventIdFound = FALSE;
\r
1285 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
1286 eventIdFound = (priMemEventBuffer[i].eventId == eventParam->EventID);
\r
1289 if (eventIdFound) {
\r
1290 memset(&priMemEventBuffer[i-1], 0, sizeof(EventRecType));
\r
1293 Irq_Restore(state);
\r
1297 * Procedure: storeEventEvtMem
\r
1298 * Description: Store the event data of "eventStatus->eventId" in event memory according to
\r
1299 * "eventParam" destination option.
\r
1301 static void storeEventEvtMem(const Dem_EventParameterType *eventParam, const EventStatusRecType *eventStatus)
\r
1305 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION)
\r
1306 && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
1307 switch (eventParam->EventClass->EventDestination[i])
\r
1309 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1310 storeEventPriMem(eventParam, eventStatus); /** @req DEM010 */
\r
1313 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1314 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1315 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1316 // Not yet supported
\r
1317 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1327 * Procedure: storeExtendedDataPriMem
\r
1328 * Description: Store the extended data pointed by "extendedData" to the "priMemExtDataBuffer",
\r
1329 * if non existent a new entry is created.
\r
1331 static void storeExtendedDataPriMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData) /** @req DEM041 */
\r
1333 boolean eventIdFound = FALSE;
\r
1334 boolean eventIdFreePositionFound=FALSE;
\r
1339 // Check if already stored
\r
1340 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
1341 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
1344 if (eventIdFound) {
\r
1345 // Yes, overwrite existing
\r
1346 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
1349 // No, lookup first free position
\r
1350 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFreePositionFound); i++){
\r
1351 eventIdFreePositionFound = (priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
1353 if (eventIdFreePositionFound) {
\r
1354 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
1357 // Error: Pri mem extended data buffer full
\r
1358 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRI_MEM_ID, DEM_E_PRI_MEM_EXT_DATA_BUFF_FULL);
\r
1362 Irq_Restore(state);
\r
1366 * Procedure: deleteExtendedDataPriMem
\r
1367 * Description: Delete the extended data of "eventParam->eventId" from "priMemExtDataBuffer".
\r
1369 static void deleteExtendedDataPriMem(const Dem_EventParameterType *eventParam)
\r
1371 boolean eventIdFound = FALSE;
\r
1376 // Check if already stored
\r
1377 for (i = 0;(i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
1378 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
1381 if (eventIdFound) {
\r
1382 // Yes, clear record
\r
1383 memset(&priMemExtDataBuffer[i-1], 0, sizeof(ExtDataRecType));
\r
1386 Irq_Restore(state);
\r
1390 * Procedure: storeExtendedDataEvtMem
\r
1391 * Description: Store the extended data in event memory according to
\r
1392 * "eventParam" destination option
\r
1394 static void storeExtendedDataEvtMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
1398 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
1399 switch (eventParam->EventClass->EventDestination[i])
\r
1401 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1402 storeExtendedDataPriMem(eventParam, extendedData);
\r
1405 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1406 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1407 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1408 // Not yet supported
\r
1409 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1420 * Procedure: lookupExtendedDataRecNumParam
\r
1421 * Description: Returns TRUE if the requested extended data number was found among the configured records for the event.
\r
1422 * "extDataRecClassPtr" returns a pointer to the record class, "posInExtData" returns the position in stored extended data.
\r
1424 static boolean lookupExtendedDataRecNumParam(uint8 extendedDataNumber, const Dem_EventParameterType *eventParam, Dem_ExtendedDataRecordClassType const **extDataRecClassPtr, uint16 *posInExtData)
\r
1426 boolean recNumFound = FALSE;
\r
1428 if (eventParam->ExtendedDataClassRef != NULL) {
\r
1429 uint16 byteCnt = 0;
\r
1432 // Request extended data and copy it to the buffer
\r
1433 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL) && (!recNumFound); i++) {
\r
1434 if (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->RecordNumber == extendedDataNumber) {
\r
1435 *extDataRecClassPtr = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i];
\r
1436 *posInExtData = byteCnt;
\r
1437 recNumFound = TRUE;
\r
1439 byteCnt += eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
1443 return recNumFound;
\r
1448 * Procedure: lookupExtendedDataPriMem
\r
1449 * Description: Returns TRUE if the requested event id is found, "extData" points to the found data.
\r
1451 static boolean lookupExtendedDataPriMem(Dem_EventIdType eventId, ExtDataRecType **extData)
\r
1453 boolean eventIdFound = FALSE;
\r
1456 // Lookup corresponding extended data
\r
1457 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++) {
\r
1458 eventIdFound = (priMemExtDataBuffer[i].eventId == eventId);
\r
1461 if (eventIdFound) {
\r
1462 // Yes, return pointer
\r
1463 *extData = &priMemExtDataBuffer[i-1];
\r
1466 return eventIdFound;
\r
1469 * Procedure: copyNvmMirror
\r
1470 * Description: Copies Nvram to buffer
\r
1473 Std_ReturnType copyNvmMirror(const NvM_BlockIdType BlockId, uint8 *dstPtr, const uint8 *srcPtr, uint8 len)
\r
1476 #if (DEM_USE_NVM == STD_ON)
\r
1477 Std_ReturnType blockReadStatus = E_NOT_OK;
\r
1478 NvM_RequestResultType requestResult;
\r
1480 if( BlockId != 0 ) {
\r
1481 NvM_GetErrorStatus(BlockId, &requestResult);
\r
1482 if(requestResult != NVM_REQ_PENDING ) {
\r
1483 memcpy(dstPtr, srcPtr, len);
\r
1484 blockReadStatus = E_OK;
\r
1488 return blockReadStatus;
\r
1494 * Procedure: writeNvmMirror
\r
1495 * Description: store data in NVRam
\r
1497 Std_ReturnType writeNvmMirror(const NvM_BlockIdType BlockId, uint8 *dstPtr, const uint8 *srcPtr, uint8 len)
\r
1499 #if (DEM_USE_NVM == STD_ON)
\r
1500 Std_ReturnType blockWriteStatus = E_NOT_OK;
\r
1501 NvM_RequestResultType requestResult;
\r
1503 if( BlockId != 0 ) {
\r
1504 NvM_GetErrorStatus(BlockId, &requestResult);
\r
1505 if(requestResult != NVM_REQ_PENDING ) {
\r
1506 memcpy(dstPtr, srcPtr, len);
\r
1507 (void)NvM_WriteBlock(BlockId, (const uint8*)dstPtr);
\r
1508 blockWriteStatus = E_OK;
\r
1512 return blockWriteStatus;
\r
1519 * Procedure: storeAgingRecPerMem
\r
1520 * Description: store aging records in NVRam
\r
1522 static void storeAgingRecPerMem(const NvM_BlockIdType AgingBlockId)
\r
1528 if( E_NOT_OK == writeNvmMirror(AgingBlockId, (uint8 *)HealingMirrorBuffer, (const uint8 *)priMemAgingBuffer, sizeof(priMemAgingBuffer)) ){
\r
1529 AgingIsModified = TRUE;
\r
1532 Irq_Restore(state);
\r
1535 * Procedure: deleteAgingRecPriMem
\r
1536 * Description: delete aging record in primary memory
\r
1538 static void deleteAgingRecPriMem(const Dem_EventParameterType *eventParam)
\r
1545 for (i = 0; i<DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++){
\r
1546 if (priMemAgingBuffer[i].eventId == eventParam->EventID){
\r
1547 memset(&priMemAgingBuffer[i], 0, sizeof(HealingRecType));
\r
1551 Irq_Restore(state);
\r
1555 * Procedure: storeFreezeFrameDataPriMem
\r
1556 * Description: store FreezeFrame data record in primary memory
\r
1558 static void storeFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1560 boolean eventIdFound = FALSE;
\r
1561 boolean eventIdFreePositionFound=FALSE;
\r
1562 boolean displacementPositionFound=FALSE;
\r
1563 FreezeFrameRecType *freezeFrameLocal;
\r
1569 /* Check if already stored */
\r
1570 for (i = 0; (i<DEM_MAX_NUMBER_FF_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
1571 eventIdFound = ((priMemFreezeFrameBuffer[i].eventId == eventParam->EventID) && (priMemFreezeFrameBuffer[i].recordNumber == freezeFrame->recordNumber));
\r
1574 if (eventIdFound) {
\r
1575 memcpy(&priMemFreezeFrameBuffer[i-1], freezeFrame, sizeof(FreezeFrameRecType));
\r
1578 for (i = 0; (i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM) && (!eventIdFreePositionFound); i++){
\r
1579 eventIdFreePositionFound = (priMemFreezeFrameBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
1581 if (eventIdFreePositionFound) {
\r
1582 memcpy(&priMemFreezeFrameBuffer[i-1], freezeFrame, sizeof(FreezeFrameRecType));
\r
1585 displacementPositionFound = lookupFreezeFrameForDisplacement(&freezeFrameLocal);
\r
1586 if(displacementPositionFound){
\r
1587 memcpy(freezeFrameLocal, freezeFrame, sizeof(FreezeFrameRecType));
\r
1590 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_FF_DATA_PRI_MEM_ID, DEM_E_PRI_MEM_FF_DATA_BUFF_FULL);
\r
1595 Irq_Restore(state);
\r
1598 * Procedure: storeFreezeFrameDataPerMem
\r
1599 * Description: Store the freeze frame data in NVRam
\r
1602 static void storeFreezeFrameDataPerMem()
\r
1608 for(uint16 i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++){
\r
1609 if(memcmp(&priMemFreezeFrameBuffer[i], FreezeFrameMirrorBuffer[i], sizeof(FreezeFrameRecType))){
\r
1610 if( E_NOT_OK == writeNvmMirror(FreezeFrameBlockId[i], (uint8 *)FreezeFrameMirrorBuffer[i], (const uint8 *)&priMemFreezeFrameBuffer[i], sizeof(FreezeFrameRecType)) ) {
\r
1611 FFIsModified = TRUE;
\r
1616 Irq_Restore(state);
\r
1619 // PC-Lint (715 etc): Remove errors until function is filled.
\r
1620 //lint -e{715} Symbol not referenced
\r
1621 static void deleteFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam)
\r
1628 for (i = 0; i<DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++){
\r
1629 if (priMemFreezeFrameBuffer[i].eventId == eventParam->EventID){
\r
1630 memset(&priMemFreezeFrameBuffer[i], 0, sizeof(FreezeFrameRecType));
\r
1635 Irq_Restore(state);
\r
1639 * Procedure: storeFreezeFrameDataEvtMem
\r
1640 * Description: Store the freeze frame data in event memory according to
\r
1641 * "eventParam" destination option
\r
1643 static void storeFreezeFrameDataEvtMem(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1647 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
1648 switch (eventParam->EventClass->EventDestination[i])
\r
1650 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1651 storeFreezeFrameDataPriMem(eventParam, freezeFrame);
\r
1652 storeFreezeFrameDataPerMem();
\r
1655 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1656 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1657 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1658 // Not yet supported
\r
1659 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1669 * Procedure: lookupFreezeFrameDataRecNumParam
\r
1670 * Description: Returns TRUE if the requested freezeFrame data number was found among the configured records for the event.
\r
1671 * "freezeFrameClassPtr" returns a pointer to the record class.
\r
1673 static boolean lookupFreezeFrameDataRecNumParam(uint8 recordNumber, const Dem_EventParameterType *eventParam, Dem_FreezeFrameClassType const **freezeFrameClassPtr)
\r
1675 boolean recNumFound = FALSE;
\r
1678 if (eventParam->FreezeFrameClassRef != NULL) {
\r
1679 for (i = 0; (i < DEM_MAX_NR_OF_CLASSES_IN_FREEZEFRAME_DATA) && (eventParam->FreezeFrameClassRef[i] != NULL) && (!recNumFound); i++) {
\r
1680 if (eventParam->FreezeFrameClassRef[i]->FFRecordNumber == recordNumber) {
\r
1681 *freezeFrameClassPtr = eventParam->FreezeFrameClassRef[i];
\r
1682 recNumFound = TRUE;
\r
1687 return recNumFound;
\r
1691 * Procedure: lookupFreezeFrameDataSize
\r
1692 * Description: Returns TRUE if the requested freezeFrame data size was obtained successfully from the configuration.
\r
1693 * "dataSize" returns a pointer to the data size.
\r
1695 static boolean lookupFreezeFrameDataSize(uint8 recordNumber, Dem_FreezeFrameClassType const **freezeFrameClassPtr, uint16 *dataSize)
\r
1697 Std_ReturnType callbackReturnCode;
\r
1698 boolean dataSizeFound = TRUE;
\r
1699 uint16 dataSizeLocal = 0;
\r
1702 if (*freezeFrameClassPtr != NULL) {
\r
1703 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_FREEZEFRAME_DATA) && ((*freezeFrameClassPtr)->FFIdClassRef[i].Arc_EOL != TRUE); i++) {
\r
1704 if((*freezeFrameClassPtr)->FFIdClassRef[i].DidReadDataLengthFnc != NULL){
\r
1705 callbackReturnCode = (*freezeFrameClassPtr)->FFIdClassRef[i].DidReadDataLengthFnc(&dataSizeLocal);
\r
1706 if(callbackReturnCode != E_OK){
\r
1707 return (dataSizeFound = FALSE);
\r
1711 dataSizeLocal = (*freezeFrameClassPtr)->FFIdClassRef[i].PidOrDidSize;
\r
1714 *dataSize += dataSizeLocal + DEM_DID_IDENTIFIER_SIZE_OF_BYTES;
\r
1719 return dataSizeFound;
\r
1723 * Procedure: lookupFreezeFrameDataPriMem
\r
1724 * Description: Returns TRUE if the requested event id is found, "freezeFrame" points to the found data.
\r
1726 static boolean lookupFreezeFrameDataPriMem(Dem_EventIdType eventId,uint8 recordNumber, FreezeFrameRecType **freezeFrame)
\r
1728 boolean eventIdFound = FALSE;
\r
1731 for (i = 0; (i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM) && (!eventIdFound); i++) {
\r
1732 eventIdFound = ((priMemFreezeFrameBuffer[i].eventId == eventId) && (priMemFreezeFrameBuffer[i].recordNumber == recordNumber));
\r
1735 if (eventIdFound) {
\r
1736 *freezeFrame = &priMemFreezeFrameBuffer[i-1];
\r
1739 return eventIdFound;
\r
1743 * Procedure: handlePreInitEvent
\r
1744 * Description: Handle the updating of event status and storing of
\r
1745 * event related data in preInit buffers.
\r
1747 static void handlePreInitEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1749 const Dem_EventParameterType *eventParam;
\r
1750 EventStatusRecType eventStatusLocal;
\r
1751 FreezeFrameRecType freezeFrameLocal;
\r
1752 ExtDataRecType extendedDataLocal;
\r
1754 lookupEventIdParameter(eventId, &eventParam);
\r
1755 if (eventParam != NULL) {
\r
1756 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1757 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1758 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
1759 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1762 updateEventStatusRec(eventParam, eventStatus, FALSE, &eventStatusLocal);
\r
1765 if (eventStatusLocal.errorStatusChanged) {
\r
1766 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1767 getExtendedData(eventParam, &extendedDataLocal);
\r
1768 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1769 storeExtendedDataPreInit(eventParam, &extendedDataLocal);
\r
1771 getFreezeFrameData(eventParam, &freezeFrameLocal,eventStatus,&eventStatusLocal);
\r
1772 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1773 storeFreezeFrameDataPreInit(eventParam, &freezeFrameLocal);
\r
1781 // Operation cycle not started
\r
1782 // TODO: Report error?
\r
1786 // Operation cycle not set
\r
1787 // TODO: Report error?
\r
1791 // Event ID not configured
\r
1792 // TODO: Report error?
\r
1798 * Procedure: handleEvent
\r
1799 * Description: Handle the updating of event status and storing of
\r
1800 * event related data in event memory.
\r
1802 static Std_ReturnType handleEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1804 Std_ReturnType returnCode = E_OK;
\r
1805 const Dem_EventParameterType *eventParam;
\r
1806 EventStatusRecType eventStatusLocal;
\r
1807 FreezeFrameRecType freezeFrameLocal;
\r
1808 ExtDataRecType extendedDataLocal;
\r
1809 Dem_EventStatusType eventStatusTemp = eventStatus;
\r
1811 lookupEventIdParameter(eventId, &eventParam);
\r
1812 if (eventParam != NULL) {
\r
1813 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1814 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1815 if ((!((disableDtcStorage.storageDisabled) && (checkDtcGroup(disableDtcStorage.dtcGroup, eventParam)) && (checkDtcKind(disableDtcStorage.dtcKind, eventParam))))) {
\r
1816 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1817 if (eventStatusLocal.errorStatusChanged) {
\r
1818 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1819 storeEventEvtMem(eventParam, &eventStatusLocal); /** @req DEM184 */
\r
1820 getExtendedData(eventParam, &extendedDataLocal);
\r
1821 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL)
\r
1823 storeExtendedDataEvtMem(eventParam, &extendedDataLocal);
\r
1827 if ((eventStatusTemp == DEM_EVENT_STATUS_PREFAILED)
\r
1828 || (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED)){
\r
1829 getFreezeFrameData(eventParam, &freezeFrameLocal,eventStatus,&eventStatusLocal);
\r
1830 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1831 storeFreezeFrameDataEvtMem(eventParam, &freezeFrameLocal); /** @req DEM190 */
\r
1841 // Operation cycle not started
\r
1842 returnCode = E_NOT_OK;
\r
1846 // Operation cycle not set
\r
1847 returnCode = E_NOT_OK;
\r
1851 // Event ID not configured
\r
1852 returnCode = E_NOT_OK;
\r
1855 return returnCode;
\r
1860 * Procedure: resetEventStatus
\r
1861 * Description: Resets the events status of eventId.
\r
1863 static void resetEventStatus(Dem_EventIdType eventId)
\r
1865 EventStatusRecType *eventStatusRecPtr;
\r
1869 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
1870 if (eventStatusRecPtr != NULL) {
\r
1871 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED; /** @req DEM187 */
\r
1874 Irq_Restore(state);
\r
1879 * Procedure: getEventStatus
\r
1880 * Description: Returns the extended event status bitmask of eventId in "eventStatusExtended".
\r
1882 static void getEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended)
\r
1884 EventStatusRecType eventStatusLocal;
\r
1886 // Get recorded status
\r
1887 getEventStatusRec(eventId, &eventStatusLocal);
\r
1888 if (eventStatusLocal.eventId == eventId) {
\r
1889 *eventStatusExtended = eventStatusLocal.eventStatusExtended; /** @req DEM051 */
\r
1892 // Event Id not found, no report received.
\r
1893 *eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1899 * Procedure: getEventFailed
\r
1900 * Description: Returns the TRUE or FALSE of "eventId" in "eventFailed" depending on current status.
\r
1902 static void getEventFailed(Dem_EventIdType eventId, boolean *eventFailed)
\r
1904 EventStatusRecType eventStatusLocal;
\r
1906 // Get recorded status
\r
1907 getEventStatusRec(eventId, &eventStatusLocal);
\r
1908 if (eventStatusLocal.eventId == eventId) {
\r
1909 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) { /** @req DEM052 */
\r
1910 *eventFailed = TRUE;
\r
1913 *eventFailed = FALSE;
\r
1917 // Event Id not found, assume ok.
\r
1918 *eventFailed = FALSE;
\r
1924 * Procedure: getEventTested
\r
1925 * Description: Returns the TRUE or FALSE of "eventId" in "eventTested" depending on
\r
1926 * current status the "test not completed this operation cycle" bit.
\r
1928 static void getEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1930 EventStatusRecType eventStatusLocal;
\r
1932 // Get recorded status
\r
1933 getEventStatusRec(eventId, &eventStatusLocal);
\r
1934 if (eventStatusLocal.eventId == eventId) {
\r
1935 if ( !(eventStatusLocal.eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE)) { /** @req DEM053 */
\r
1936 *eventTested = TRUE;
\r
1939 *eventTested = FALSE;
\r
1943 // Event Id not found, not tested.
\r
1944 *eventTested = FALSE;
\r
1950 * Procedure: getFaultDetectionCounter
\r
1951 * Description: Returns pre debounce counter of "eventId" in "counter" and return value E_OK if
\r
1952 * the counter was available else E_NOT_OK.
\r
1954 static Std_ReturnType getFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1956 Std_ReturnType returnCode = E_NOT_OK;
\r
1957 const Dem_EventParameterType *eventParam;
\r
1959 lookupEventIdParameter(eventId, &eventParam);
\r
1960 if (eventParam != NULL) {
\r
1961 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
1962 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName)
\r
1964 case DEM_NO_PRE_DEBOUNCE:
\r
1965 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal != NULL) {
\r
1966 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc != NULL) {
\r
1967 returnCode = eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc(counter); /** @req DEM204.None */ /** @req DEM264 */ /** @req DEM265 */
\r
1972 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
1974 EventStatusRecType *eventStatusRec;
\r
1976 lookupEventStatusRec(eventId, &eventStatusRec);
\r
1977 if (eventStatusRec != NULL) {
\r
1978 *counter = eventStatusRec->faultDetectionCounter; /** @req DEM204.Counter */
\r
1982 returnCode = E_OK;
\r
1986 case DEM_PRE_DEBOUNCE_FREQUENCY_BASED:
\r
1987 case DEM_PRE_DEBOUNCE_TIME_BASED:
\r
1988 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1992 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_PARAM_DATA);
\r
1998 return returnCode;
\r
2001 * Procedure: deleteEventMemory
\r
2002 * Description: If aging of an event occurs, the Dem module shall delete the event from
\r
2003 * the event memory including its event related data
\r
2005 static void deleteEventMemory(const Dem_EventParameterType *eventParam)
\r
2009 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
2010 switch (eventParam->EventClass->EventDestination[i])
\r
2012 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2013 deleteEventPriMem(eventParam);
\r
2014 deleteFreezeFrameDataPriMem(eventParam);
\r
2015 deleteExtendedDataPriMem(eventParam);
\r
2016 storeFreezeFrameDataPerMem();
\r
2019 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2020 //TODO:need to add corresponding event and extended deleting functions
\r
2024 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2025 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2026 // Not yet supported
\r
2027 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2038 * Procedure: lookupAgingRecPriMem
\r
2039 * Description: Returns the pointer to event id parameters of "eventId" in "*priMemAgingBuffer",
\r
2040 * if not found NULL is returned.
\r
2042 static boolean lookupAgingRecPriMem(Dem_EventIdType eventId, const HealingRecType **agingRec)
\r
2045 boolean agingRecFound = FALSE;
\r
2047 for (i = 0; i < DEM_MAX_NUMBER_AGING_PRI_MEM && (!agingRecFound); i++) {
\r
2048 if(priMemAgingBuffer[i].eventId == eventId){
\r
2049 agingRecFound = TRUE;
\r
2054 if(agingRecFound){
\r
2055 *agingRec = &priMemAgingBuffer[i-1];
\r
2061 return agingRecFound;
\r
2067 * Procedure: handleAging
\r
2068 * Description: according to the operation state of "operationCycleId" to "cycleState" , handle the aging relatived data
\r
2069 * Returns E_OK if operation was successful else E_NOT_OK.
\r
2071 static Std_ReturnType handleAging(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState)
\r
2074 Std_ReturnType returnCode = E_OK;
\r
2075 HealingRecType *agingRecLocal = NULL;
\r
2076 boolean agingRecFound = FALSE;
\r
2078 if (operationCycleId < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
2079 switch (cycleState)
\r
2081 case DEM_CYCLE_STATE_START:
\r
2084 case DEM_CYCLE_STATE_END:/** @req Dem490 */
\r
2085 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2086 if(eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL){
\r
2087 if(eventStatusBuffer[i].eventParamRef != NULL){
\r
2088 if(eventStatusBuffer[i].eventParamRef->EventClass != NULL){
\r
2089 if((eventStatusBuffer[i].eventParamRef->EventClass->HealingAllowed == TRUE)\
\r
2090 && (eventStatusBuffer[i].eventParamRef->EventClass->HealingCycleRef == operationCycleId)){
\r
2091 if((eventStatusBuffer[i].eventStatusExtended & DEM_CONFIRMED_DTC)\
\r
2092 && (!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_FAILED))\
\r
2093 && (!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE))){
\r
2094 agingRecFound = lookupAgingRecPriMem(eventStatusBuffer[i].eventId, (const HealingRecType **)(&agingRecLocal));
\r
2095 if(agingRecFound){
\r
2096 agingRecLocal->agingCounter++;/** @req Dem489 */
\r
2097 agingRecLocal->checksum = calcChecksum(agingRecLocal,sizeof(HealingRecType) - sizeof(ChecksumType));
\r
2098 if(agingRecLocal->agingCounter > eventStatusBuffer[i].eventParamRef->EventClass->HealingCycleCounter){
\r
2099 //deleteEventMemory(eventStatusBuffer[i].eventParamRef); /** @req Dem497 */
\r
2101 deleteAgingRecPriMem(eventStatusBuffer[i].eventParamRef);
\r
2103 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)(~DEM_CONFIRMED_DTC);
\r
2104 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)(~DEM_PENDING_DTC);
\r
2105 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)(~DEM_WARNING_INDICATOR_REQUESTED);
\r
2107 /* Set the flag,start up the storage of NVRam in main function. */
\r
2108 AgingIsModified = TRUE;
\r
2111 /* If it does exist,establish a new record for the corresponding event */
\r
2112 agingRecFound = lookupAgingRecPriMem(DEM_EVENT_ID_NULL, (const HealingRecType **)(&agingRecLocal));
\r
2113 if(agingRecFound){
\r
2114 agingRecLocal->eventId = eventStatusBuffer[i].eventId;
\r
2115 agingRecLocal->agingCounter++;
\r
2116 agingRecLocal->checksum = calcChecksum(agingRecLocal,sizeof(HealingRecType) - sizeof(ChecksumType));
\r
2117 AgingIsModified = TRUE;
\r
2120 /* primary memory of aging records is full. */
\r
2125 /* If the status bit testFailed (bit 0) is set during the operation cycle, the counter shall be reset. */
\r
2126 if(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_FAILED){
\r
2127 agingRecFound = lookupAgingRecPriMem(eventStatusBuffer[i].eventId, (const HealingRecType **)(&agingRecLocal));
\r
2128 if(agingRecFound){
\r
2129 if(agingRecLocal->agingCounter){
\r
2130 agingRecLocal->agingCounter = 0;
\r
2131 agingRecLocal->checksum = calcChecksum(agingRecLocal,sizeof(HealingRecType) - sizeof(ChecksumType));
\r
2132 AgingIsModified = TRUE;
\r
2144 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
2145 returnCode = E_NOT_OK;
\r
2150 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
2151 returnCode = E_NOT_OK;
\r
2154 return returnCode;
\r
2159 * Procedure: setOperationCycleState
\r
2160 * Description: Change the operation state of "operationCycleId" to "cycleState" and updates stored
\r
2161 * event connected to this cycle id.
\r
2162 * Returns E_OK if operation was successful else E_NOT_OK.
\r
2164 static Std_ReturnType setOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState) /** @req DEM338 */
\r
2167 Std_ReturnType returnCode = E_OK;
\r
2169 if (operationCycleId < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
2170 switch (cycleState)
\r
2172 case DEM_CYCLE_STATE_START:
\r
2173 operationCycleStateList[operationCycleId] = cycleState;
\r
2174 // Lookup event ID
\r
2175 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2176 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
2177 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED_THIS_OPERATION_CYCLE;
\r
2178 eventStatusBuffer[i].eventStatusExtended |= DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
2183 case DEM_CYCLE_STATE_END:
\r
2184 operationCycleStateList[operationCycleId] = cycleState;
\r
2185 // Lookup event ID
\r
2186 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2187 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
2188 if ((!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_FAILED_THIS_OPERATION_CYCLE)) && (!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE))) {
\r
2189 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_PENDING_DTC; // Clear pendingDTC bit /** @req DEM379.PendingClear
\r
2190 storeEventEvtMem(eventStatusBuffer[i].eventParamRef, &eventStatusBuffer[i]);
\r
2196 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
2197 returnCode = E_NOT_OK;
\r
2202 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
2203 returnCode = E_NOT_OK;
\r
2206 return returnCode;
\r
2210 //==============================================================================//
\r
2212 // E X T E R N A L F U N C T I O N S //
\r
2214 //==============================================================================//
\r
2216 /*********************************************
\r
2217 * Interface for upper layer modules (8.3.1) *
\r
2218 *********************************************/
\r
2221 * Procedure: Dem_GetVersionInfo
\r
2224 // Defined in Dem.h
\r
2227 /***********************************************
\r
2228 * Interface ECU State Manager <-> DEM (8.3.2) *
\r
2229 ***********************************************/
\r
2232 * Procedure: Dem_PreInit
\r
2235 void Dem_PreInit(void)
\r
2237 /** @req DEM180 */
\r
2240 EventStatusRecType *eventStatusRecPtr;
\r
2241 const Dem_EventParameterType *eventIdParamList;
\r
2243 VALIDATE_NO_RV(DEM_Config.ConfigSet != NULL, DEM_PREINIT_ID, DEM_E_CONFIG_PTR_INVALID);
\r
2245 configSet = DEM_Config.ConfigSet;
\r
2247 // Initializion of operation cycle states.
\r
2248 for (i = 0; i < DEM_OPERATION_CYCLE_ID_ENDMARK; i++) {
\r
2249 operationCycleStateList[i] = DEM_CYCLE_STATE_END;
\r
2252 // Initialize the event status buffer
\r
2253 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2254 eventStatusBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
2255 eventStatusBuffer[i].eventParamRef = NULL;
\r
2256 eventStatusBuffer[i].faultDetectionCounter = 0;
\r
2257 eventStatusBuffer[i].occurrence = 0;
\r
2258 eventStatusBuffer[i].eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
2259 eventStatusBuffer[i].errorStatusChanged = FALSE;
\r
2262 // Insert all supported events into event status buffer
\r
2264 eventIdParamList = configSet->EventParameter;
\r
2265 while( !eventIdParamList[index].Arc_EOL ) {
\r
2266 // Find next free position in event status buffer
\r
2267 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
2268 if(NULL != eventStatusRecPtr) {
\r
2269 eventStatusRecPtr->eventId = eventIdParamList[index].EventID;
\r
2270 eventStatusRecPtr->eventParamRef = &eventIdParamList[index];
\r
2272 // event status buffer is full
\r
2273 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREINIT_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
2279 //lint -e568 -e685 //PC-Lint exception.
\r
2280 //lint -e681 //PC-Lint exception to MISRA 14.1: Loop is not entered. This only happens when config variable is zero. Keep as it is for less complex code.
\r
2281 // Initialize the pre init buffers
\r
2282 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
2283 preInitFreezeFrameBuffer[i].checksum = 0;
\r
2284 preInitFreezeFrameBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
2285 preInitFreezeFrameBuffer[i].occurrence = 0;
\r
2286 preInitFreezeFrameBuffer[i].dataSize = 0;
\r
2287 for (j = 0; j < DEM_MAX_SIZE_FF_DATA;j++){
\r
2288 preInitFreezeFrameBuffer[i].data[j] = 0;
\r
2293 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
2294 preInitExtDataBuffer[i].checksum = 0;
\r
2295 preInitExtDataBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
2296 preInitExtDataBuffer[i].dataSize = 0;
\r
2297 for (j = 0; j < DEM_MAX_SIZE_EXT_DATA;j++){
\r
2298 preInitExtDataBuffer[i].data[j] = 0;
\r
2302 disableDtcStorage.storageDisabled = FALSE;
\r
2304 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_START); /** @req DEM047 */
\r
2306 demState = DEM_PREINITIALIZED;
\r
2311 * Procedure: Dem_Init
\r
2314 void Dem_Init(void)
\r
2317 ChecksumType cSum;
\r
2318 const Dem_EventParameterType *eventParam;
\r
2320 if(DEM_PREINITIALIZED != demState){
\r
2322 * Dem_PreInit was has not been called since last time Dem_Shutdown was called.
\r
2323 * This suggests that we are resuming from sleep. According to section 5.7 in
\r
2324 * EcuM specification, RAM content is assumed to be still valid from the previous cycle.
\r
2325 * Do not read from saved error log since buffers already contains this data.
\r
2327 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_START);
\r
2331 for(i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++){
\r
2332 if( E_NOT_OK == copyNvmMirror(FreezeFrameBlockId[i], (uint8 *)&priMemFreezeFrameBuffer[i], (const uint8 *)&FreezeFrameMirrorBuffer[i], sizeof(FreezeFrameRecType)) ){
\r
2333 //TODO:NVM is busy or block id is 0,report error or what?
\r
2336 //recover Aging from NVRam to RAM
\r
2337 if(E_OK == copyNvmMirror(AgingBlockId, (uint8*)priMemAgingBuffer, (const uint8*)HealingMirrorBuffer, sizeof(priMemAgingBuffer)) ){
\r
2341 // Validate aging records stored in primary memory
\r
2342 for (i = 0; i < DEM_MAX_NUMBER_AGING_PRI_MEM; i++){
\r
2343 cSum = calcChecksum(&priMemAgingBuffer[i], sizeof(HealingRecType) - sizeof(ChecksumType));
\r
2344 if ((cSum != priMemAgingBuffer[i].checksum) || (priMemAgingBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
2345 // Unlegal record, clear the record
\r
2346 memset(&priMemAgingBuffer[i], 0, sizeof(HealingRecType));
\r
2347 AgingIsModified = TRUE;
\r
2351 // Validate event records stored in primary memory
\r
2352 for (i = 0; i < DEM_MAX_NUMBER_EVENT_PRI_MEM; i++) {
\r
2353 cSum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
2354 if ((cSum != priMemEventBuffer[i].checksum) || (priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
2355 // Unlegal record, clear the record
\r
2356 memset(&priMemEventBuffer[i], 0, sizeof(EventRecType));
\r
2359 // Valid, update current status
\r
2360 mergeEventStatusRec(&priMemEventBuffer[i]);
\r
2362 // Update occurrence counter on pre init stored freeze frames
\r
2363 updateFreezeFrameOccurrencePreInit(&priMemEventBuffer[i]);
\r
2367 //initialize the current timestamp and update the timestamp in pre init
\r
2368 initCurrentFreezeFrameTimeStamp(&FF_TimeStamp);//add by i-soft
\r
2370 // Validate extended data records stored in primary memory
\r
2371 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM; i++) {
\r
2372 cSum = calcChecksum(&priMemExtDataBuffer[i], sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
2373 if ((cSum != priMemExtDataBuffer[i].checksum) || (priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
2374 // Unlegal record, clear the record
\r
2375 memset(&priMemExtDataBuffer[i], 0, sizeof(ExtDataRecType));
\r
2379 //initialize the current timestamp and update the timestamp in pre init
\r
2380 initCurrentFreezeFrameTimeStamp(&FF_TimeStamp);
\r
2383 //lint -e568 //PC-Lint exception.
\r
2384 //lint -e685 //PC-Lint exception.
\r
2385 //lint -e681 //PC-Lint exception to MISRA 14.1: Loop is not entered. This only happens when DEM_MAX_NUMBER_FF_DATA_PRE_INIT is zero. Keep as it is for less complex code.
\r
2386 // Validate freeze frame records stored in primary memory
\r
2387 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++) {
\r
2388 cSum = calcChecksum(&priMemFreezeFrameBuffer[i], sizeof(FreezeFrameRecType)-sizeof(ChecksumType));
\r
2389 if ((cSum != priMemFreezeFrameBuffer[i].checksum) || (priMemFreezeFrameBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
2390 // Unlegal record, clear the record
\r
2391 memset(&priMemFreezeFrameBuffer[i], 0, sizeof(FreezeFrameRecType));
\r
2396 /* Transfer updated event data to event memory */
\r
2397 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2398 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
2399 lookupEventIdParameter(eventStatusBuffer[i].eventId, &eventParam);
\r
2400 storeEventEvtMem(eventParam, &eventStatusBuffer[i]);
\r
2404 /* Transfer extended data to event memory if necessary */
\r
2405 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
2406 if (preInitExtDataBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
2407 lookupEventIdParameter(preInitExtDataBuffer[i].eventId, &eventParam);
\r
2408 storeExtendedDataEvtMem(eventParam, &preInitExtDataBuffer[i]);
\r
2413 //lint -e568 //PC-Lint exception.
\r
2414 //lint -e685 //PC-Lint exception.
\r
2415 //lint -e681 //PC-Lint exception to MISRA 14.1: Loop is not entered. This only happens when DEM_MAX_NUMBER_FF_DATA_PRE_INIT is zero. Keep as it is for less complex code.
\r
2416 /* Transfer freeze frames to event memory */
\r
2417 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
2418 if (preInitFreezeFrameBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
2419 lookupEventIdParameter(preInitFreezeFrameBuffer[i].eventId, &eventParam);
\r
2420 storeFreezeFrameDataEvtMem(eventParam, &preInitFreezeFrameBuffer[i]);
\r
2426 // Init the dtc filter
\r
2427 dtcFilter.dtcStatusMask = DEM_DTC_STATUS_MASK_ALL; // All allowed
\r
2428 dtcFilter.dtcKind = DEM_DTC_KIND_ALL_DTCS; // All kinds of DTCs
\r
2429 dtcFilter.dtcOrigin = DEM_DTC_ORIGIN_PRIMARY_MEMORY; // Primary memory
\r
2430 dtcFilter.filterWithSeverity = DEM_FILTER_WITH_SEVERITY_NO; // No Severity filtering
\r
2431 dtcFilter.dtcSeverityMask = DEM_SEVERITY_NO_SEVERITY; // Not used when filterWithSeverity is FALSE
\r
2432 dtcFilter.filterForFaultDetectionCounter = DEM_FILTER_FOR_FDC_NO; // No fault detection counter filtering
\r
2434 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
2436 disableDtcStorage.storageDisabled = FALSE;
\r
2438 demState = DEM_INITIALIZED;
\r
2443 * Procedure: Dem_shutdown
\r
2446 void Dem_Shutdown(void)
\r
2448 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_END); /** @req DEM047 */
\r
2450 /* handleAging() should be called behind setOperationCycleState() */
\r
2451 (void)handleAging(DEM_ACTIVE, DEM_CYCLE_STATE_END);
\r
2453 demState = DEM_UNINITIALIZED; /** @req DEM368 */
\r
2458 * Interface for basic software scheduler
\r
2460 void Dem_MainFunction(void)/** @req DEM125 */
\r
2462 if (FFIsModified) {
\r
2463 storeFreezeFrameDataPerMem(FreezeFrameBlockId);
\r
2466 if (AgingIsModified) {
\r
2467 storeAgingRecPerMem(AgingBlockId);
\r
2472 /***************************************************
\r
2473 * Interface SW-Components via RTE <-> DEM (8.3.3) *
\r
2474 ***************************************************/
\r
2477 * Procedure: Dem_SetEventStatus
\r
2480 Std_ReturnType Dem_SetEventStatus(Dem_EventIdType eventId, Dem_EventStatusType eventStatus) /** @req DEM330 */
\r
2482 Std_ReturnType returnCode = E_OK;
\r
2484 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
2486 returnCode = handleEvent(eventId, eventStatus);
\r
2490 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
2491 returnCode = E_NOT_OK;
\r
2494 return returnCode;
\r
2499 * Procedure: Dem_ResetEventStatus
\r
2502 Std_ReturnType Dem_ResetEventStatus(Dem_EventIdType eventId) /** @req DEM331 */
\r
2504 Std_ReturnType returnCode = E_OK;
\r
2506 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
2508 resetEventStatus(eventId); /** @req DEM186 */
\r
2512 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_RESETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
2513 returnCode = E_NOT_OK;
\r
2516 return returnCode;
\r
2521 * Procedure: Dem_GetEventStatus
\r
2524 Std_ReturnType Dem_GetEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended) /** @req DEM332 */
\r
2526 Std_ReturnType returnCode = E_OK;
\r
2528 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
2530 getEventStatus(eventId, eventStatusExtended);
\r
2534 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
2535 returnCode = E_NOT_OK;
\r
2538 return returnCode;
\r
2543 * Procedure: Dem_GetEventFailed
\r
2546 Std_ReturnType Dem_GetEventFailed(Dem_EventIdType eventId, boolean *eventFailed) /** @req DEM333 */
\r
2548 Std_ReturnType returnCode = E_OK;
\r
2550 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
2552 getEventFailed(eventId, eventFailed);
\r
2556 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTFAILED_ID, DEM_E_UNINIT);
\r
2557 returnCode = E_NOT_OK;
\r
2560 return returnCode;
\r
2565 * Procedure: Dem_GetEventTested
\r
2568 Std_ReturnType Dem_GetEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
2570 Std_ReturnType returnCode = E_OK;
\r
2572 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
2574 getEventTested(eventId, eventTested);
\r
2578 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTTESTED_ID, DEM_E_UNINIT);
\r
2579 returnCode = E_NOT_OK;
\r
2582 return returnCode;
\r
2587 * Procedure: Dem_GetFaultDetectionCounter
\r
2590 Std_ReturnType Dem_GetFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
2592 Std_ReturnType returnCode = E_OK;
\r
2594 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
2596 returnCode = getFaultDetectionCounter(eventId, counter);
\r
2600 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_UNINIT);
\r
2601 returnCode = E_NOT_OK;
\r
2604 return returnCode;
\r
2609 * Procedure: Dem_SetOperationCycleState
\r
2612 Std_ReturnType Dem_SetOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState)
\r
2614 Std_ReturnType returnCode = E_OK;
\r
2616 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
2618 returnCode = setOperationCycleState(operationCycleId, cycleState);
\r
2619 (void)handleAging(operationCycleId, cycleState);
\r
2624 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_UNINIT);
\r
2625 returnCode = E_NOT_OK;
\r
2628 return returnCode;
\r
2633 * Procedure: Dem_GetDTCOfEvent
\r
2636 Std_ReturnType Dem_GetDTCOfEvent(Dem_EventIdType eventId, Dem_DTCKindType dtcKind, uint32* dtcOfEvent)
\r
2638 Std_ReturnType returnCode = E_NO_DTC_AVAILABLE;
\r
2639 const Dem_EventParameterType *eventParam;
\r
2641 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
2643 lookupEventIdParameter(eventId, &eventParam);
\r
2645 if (eventParam != NULL) {
\r
2646 if (checkDtcKind(dtcKind, eventParam)) {
\r
2647 if (eventParam->DTCClassRef != NULL) {
\r
2648 *dtcOfEvent = eventParam->DTCClassRef->DTC; /** @req DEM269 */
\r
2649 returnCode = E_OK;
\r
2654 // Event Id not found
\r
2655 returnCode = E_NOT_OK;
\r
2660 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETDTCOFEVENT_ID, DEM_UNINITIALIZED);
\r
2661 returnCode = E_NOT_OK;
\r
2664 return returnCode;
\r
2668 /********************************************
\r
2669 * Interface BSW-Components <-> DEM (8.3.4) *
\r
2670 ********************************************/
\r
2673 * Procedure: Dem_ReportErrorStatus
\r
2676 void Dem_ReportErrorStatus( Dem_EventIdType eventId, Dem_EventStatusType eventStatus ) /** @req DEM107 *//** @req DEM206 */
\r
2679 switch (demState) {
\r
2680 case DEM_PREINITIALIZED:
\r
2681 // Update status and check if is to be stored
\r
2682 if ((eventStatus == DEM_EVENT_STATUS_PASSED) || (eventStatus == DEM_EVENT_STATUS_FAILED)) {
\r
2683 handlePreInitEvent(eventId, eventStatus); /** @req DEM168 */
\r
2687 case DEM_INITIALIZED:
\r
2688 (void)handleEvent(eventId, eventStatus); /** @req DEM167 */
\r
2691 case DEM_UNINITIALIZED:
\r
2693 // Uninitialized can not do anything
\r
2694 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_REPORTERRORSTATUS_ID, DEM_E_UNINIT);
\r
2698 } // switch (demState)
\r
2701 /*********************************
\r
2702 * Interface DCM <-> DEM (8.3.5) *
\r
2703 *********************************/
\r
2705 * Procedure: Dem_GetDTCStatusAvailabilityMask
\r
2708 Std_ReturnType Dem_GetDTCStatusAvailabilityMask(uint8 *dtcStatusMask) /** @req DEM014 */
\r
2710 *dtcStatusMask = DEM_DTC_STATUS_AVAILABILITY_MASK; // User configuration mask
\r
2711 *dtcStatusMask &= DEM_TEST_FAILED // Mask with supported bits /** @req DEM060 */
\r
2712 | DEM_TEST_FAILED_THIS_OPERATION_CYCLE
\r
2714 | DEM_CONFIRMED_DTC
\r
2715 | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR
\r
2716 | DEM_TEST_FAILED_SINCE_LAST_CLEAR
\r
2717 | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE
\r
2718 // | DEM_WARNING_INDICATOR_REQUESTED TODO: Add support for this bit
\r
2726 * Procedure: Dem_SetDTCFilter
\r
2729 Dem_ReturnSetDTCFilterType Dem_SetDTCFilter(uint8 dtcStatusMask,
\r
2730 Dem_DTCKindType dtcKind,
\r
2731 Dem_DTCOriginType dtcOrigin,
\r
2732 Dem_FilterWithSeverityType filterWithSeverity,
\r
2733 Dem_DTCSeverityType dtcSeverityMask,
\r
2734 Dem_FilterForFDCType filterForFaultDetectionCounter)
\r
2736 Dem_ReturnSetDTCFilterType returnCode = DEM_FILTER_ACCEPTED;
\r
2738 if (demState == DEM_INITIALIZED) {
\r
2739 // Check dtcKind parameter
\r
2740 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
2742 // Check dtcOrigin parameter
\r
2743 VALIDATE_RV((dtcOrigin == DEM_DTC_ORIGIN_SECONDARY_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_PRIMARY_MEMORY)
\r
2744 || (dtcOrigin == DEM_DTC_ORIGIN_PERMANENT_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_MIRROR_MEMORY), DEM_SETDTCFILTER_ID, DEM_E_PARAM_DATA, DEM_WRONG_FILTER);
\r
2746 // Check filterWithSeverity and dtcSeverityMask parameter
\r
2747 VALIDATE_RV(((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
2748 || ((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES)
\r
2749 && (!(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
2751 // Check filterForFaultDetectionCounter parameter
\r
2752 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
2754 // Yes all parameters correct, set the new filters. /** @req DEM057 */
\r
2755 dtcFilter.dtcStatusMask = dtcStatusMask;
\r
2756 dtcFilter.dtcKind = dtcKind;
\r
2757 dtcFilter.dtcOrigin = dtcOrigin;
\r
2758 dtcFilter.filterWithSeverity = filterWithSeverity;
\r
2759 dtcFilter.dtcSeverityMask = dtcSeverityMask;
\r
2760 dtcFilter.filterForFaultDetectionCounter = filterForFaultDetectionCounter;
\r
2761 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
2763 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETDTCFILTER_ID, DEM_E_UNINIT);
\r
2764 returnCode = DEM_WRONG_FILTER;
\r
2767 return returnCode;
\r
2772 * Procedure: Dem_GetStatusOfDTC
\r
2775 Dem_ReturnGetStatusOfDTCType Dem_GetStatusOfDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, Dem_EventStatusExtendedType* status) {
\r
2776 Dem_ReturnGetStatusOfDTCType returnCode = DEM_STATUS_FAILED;
\r
2777 EventStatusRecType *eventRec;
\r
2779 if (demState == DEM_INITIALIZED) {
\r
2780 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2781 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2782 if (checkDtcOrigin(dtcOrigin,eventRec->eventParamRef)) {
\r
2783 *status = eventRec->eventStatusExtended; /** @req DEM059 */
\r
2784 returnCode = DEM_STATUS_OK;
\r
2787 returnCode = DEM_STATUS_WRONG_DTCORIGIN; /** @req DEM171 */
\r
2791 returnCode = DEM_STATUS_WRONG_DTCKIND;
\r
2795 returnCode = DEM_STATUS_WRONG_DTC; /** @req DEM172 */
\r
2798 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETSTATUSOFDTC_ID, DEM_E_UNINIT);
\r
2799 returnCode = DEM_STATUS_FAILED;
\r
2802 return returnCode;
\r
2807 * Procedure: Dem_GetNumberOfFilteredDtc
\r
2810 Dem_ReturnGetNumberOfFilteredDTCType Dem_GetNumberOfFilteredDtc(uint16 *numberOfFilteredDTC) {
\r
2812 uint16 numberOfFaults = 0;
\r
2813 Dem_ReturnGetNumberOfFilteredDTCType returnCode = DEM_NUMBER_OK;
\r
2815 if (demState == DEM_INITIALIZED) {
\r
2816 //Dem_DisableEventStatusUpdate();
\r
2818 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2819 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
2820 if (matchEventWithDtcFilter(&eventStatusBuffer[i])) {
\r
2821 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
2828 //Dem_EnableEventStatusUpdate();
\r
2830 *numberOfFilteredDTC = numberOfFaults; /** @req DEM061 */
\r
2832 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETNUMBEROFFILTEREDDTC_ID, DEM_E_UNINIT);
\r
2833 returnCode = DEM_NUMBER_FAILED;
\r
2836 return returnCode;
\r
2841 * Procedure: Dem_GetNextFilteredDTC
\r
2844 Dem_ReturnGetNextFilteredDTCType Dem_GetNextFilteredDTC(uint32 *dtc, Dem_EventStatusExtendedType *dtcStatus)
\r
2846 Dem_ReturnGetNextFilteredDTCType returnCode = DEM_FILTERED_OK;
\r
2847 boolean dtcFound = FALSE;
\r
2849 if (demState == DEM_INITIALIZED) {
\r
2850 // TODO: This job should be done in an more advanced way according to Dem217
\r
2851 while ((!dtcFound) && (dtcFilter.faultIndex != 0)) {
\r
2852 dtcFilter.faultIndex--;
\r
2853 if (eventStatusBuffer[dtcFilter.faultIndex].eventId != DEM_EVENT_ID_NULL) {
\r
2854 if (matchEventWithDtcFilter(&eventStatusBuffer[dtcFilter.faultIndex])) {
\r
2855 if (eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef != NULL) {
\r
2856 *dtc = eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef->DTC; /** @req DEM216 */
\r
2857 *dtcStatus = eventStatusBuffer[dtcFilter.faultIndex].eventStatusExtended;
\r
2865 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
2866 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
2869 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETNEXTFILTEREDDTC_ID, DEM_E_UNINIT);
\r
2870 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
2873 return returnCode;
\r
2878 * Procedure: Dem_GetTranslationType
\r
2881 Dem_ReturnTypeOfDtcSupportedType Dem_GetTranslationType(void)
\r
2883 return DEM_TYPE_OF_DTC_SUPPORTED; /** @req DEM231 */
\r
2888 * Procedure: Dem_ClearDTC
\r
2891 Dem_ReturnClearDTCType Dem_ClearDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin) /** @req DEM009 *//** @req DEM241 */
\r
2893 Dem_ReturnClearDTCType returnCode = DEM_CLEAR_OK;
\r
2894 Dem_EventIdType eventId;
\r
2895 const Dem_EventParameterType *eventParam;
\r
2898 if (demState == DEM_INITIALIZED) {
\r
2899 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2900 eventId = eventStatusBuffer[i].eventId;
\r
2901 if (eventId != DEM_EVENT_ID_NULL) {
\r
2902 eventParam = eventStatusBuffer[i].eventParamRef;
\r
2903 if (eventParam != NULL) {
\r
2904 //lint --e(506) PC-Lint exception Misra 13.7, 14.1 Allow configuration variables in boolean expression
\r
2905 //lint --e(774) PC-Lint exception Related to MISRA 13.7
\r
2906 if ((DEM_CLEAR_ALL_EVENTS == STD_ON) || (eventParam->DTCClassRef != NULL)) {
\r
2907 if (checkDtcKind(dtcKind, eventParam)) {
\r
2908 if (checkDtcGroup(dtc, eventParam)) {
\r
2909 boolean dtcOriginFound = FALSE;
\r
2910 for (j = 0; (j < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound) ; j++){
\r
2911 dtcOriginFound =(eventParam->EventClass->EventDestination[j] == dtcOrigin);
\r
2913 if (dtcOriginFound) {
\r
2914 switch (dtcOrigin)
\r
2916 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2917 /** @req DEM077 */
\r
2918 deleteEventPriMem(eventParam);
\r
2919 deleteFreezeFrameDataPriMem(eventParam);
\r
2920 deleteExtendedDataPriMem(eventParam);
\r
2921 resetEventStatusRec(eventParam);
\r
2922 storeFreezeFrameDataPerMem();
\r
2925 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2929 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2930 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2931 // Not yet supported
\r
2932 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2933 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2936 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2945 // Fatal error, no event parameters found for the stored event!
\r
2946 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNEXPECTED_EXECUTION);
\r
2951 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNINIT);
\r
2952 returnCode = DEM_CLEAR_FAILED;
\r
2955 return returnCode;
\r
2960 * Procedure: Dem_DisableDTCStorage
\r
2963 Dem_ReturnControlDTCStorageType Dem_DisableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind) /** @req DEM035 */
\r
2965 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2967 if (demState == DEM_INITIALIZED) {
\r
2968 // Check dtcGroup parameter
\r
2969 if (dtcGroup == DEM_DTC_GROUP_ALL_DTCS) {
\r
2970 // Check dtcKind parameter
\r
2971 if ((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS)) {
\r
2972 /** @req DEM079 */
\r
2973 disableDtcStorage.dtcGroup = dtcGroup;
\r
2974 disableDtcStorage.dtcKind = dtcKind;
\r
2975 disableDtcStorage.storageDisabled = TRUE;
\r
2977 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2980 returnCode = DEM_CONTROL_DTC_WRONG_DTCGROUP;
\r
2983 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_DISABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
2984 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2987 return returnCode;
\r
2992 * Procedure: Dem_EnableDTCStorage
\r
2995 Dem_ReturnControlDTCStorageType Dem_EnableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind)
\r
2997 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2999 if (demState == DEM_INITIALIZED) {
\r
3000 // TODO: Behavior is not defined if group or kind do not match active settings, therefore the filter is just switched off.
\r
3001 (void)dtcGroup; (void)dtcKind; // Just to make get rid of PC-Lint warnings
\r
3002 disableDtcStorage.storageDisabled = FALSE; /** @req DEM080 */
\r
3004 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_ENABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
3005 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
3008 return returnCode;
\r
3012 * Procedure: Dem_GetExtendedDataRecordByDTC
\r
3015 Dem_ReturnGetExtendedDataRecordByDTCType Dem_GetExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint8 *destBuffer, uint16 *bufSize)
\r
3017 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_RECORD_WRONG_DTC;
\r
3018 EventStatusRecType *eventRec;
\r
3019 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
3020 ExtDataRecType *extData;
\r
3021 uint16 posInExtData = 0;
\r
3023 if (demState == DEM_INITIALIZED) {
\r
3024 if (lookupDtcEvent(dtc, &eventRec)) {
\r
3025 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
3026 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
3027 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
3028 if (*bufSize >= extendedDataRecordClass->DataSize) {
\r
3029 switch (dtcOrigin)
\r
3031 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
3032 if (lookupExtendedDataPriMem(eventRec->eventId, &extData)) {
\r
3033 // Yes all conditions met, copy the extended data record to destination buffer.
\r
3034 memcpy(destBuffer, &extData->data[posInExtData], extendedDataRecordClass->DataSize); /** @req DEM075 */
\r
3035 *bufSize = extendedDataRecordClass->DataSize;
\r
3036 returnCode = DEM_RECORD_OK;
\r
3039 // The record number is legal but no record was found for the DTC
\r
3041 returnCode = DEM_RECORD_OK;
\r
3045 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
3046 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
3047 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
3048 // Not yet supported
\r
3049 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
3050 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
3053 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
3058 returnCode = DEM_RECORD_BUFFERSIZE;
\r
3062 returnCode = DEM_RECORD_NUMBER;
\r
3066 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
3070 returnCode = DEM_RECORD_DTCKIND;
\r
3074 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
3075 returnCode = DEM_RECORD_WRONG_DTC;
\r
3078 return returnCode;
\r
3083 * Procedure: Dem_GetSizeOfExtendedDataRecordByDTC
\r
3086 Dem_ReturnGetSizeOfExtendedDataRecordByDTCType Dem_GetSizeOfExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint16 *sizeOfExtendedDataRecord)
\r
3088 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
3089 EventStatusRecType *eventRec;
\r
3090 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
3091 uint16 posInExtData;
\r
3093 if (demState == DEM_INITIALIZED) {
\r
3094 if (lookupDtcEvent(dtc, &eventRec)) {
\r
3095 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
3096 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
3097 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
3098 *sizeOfExtendedDataRecord = extendedDataRecordClass->DataSize; /** @req DEM076 */
\r
3099 returnCode = DEM_GET_SIZEOFEDRBYDTC_OK;
\r
3102 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_RNUM;
\r
3106 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCOR;
\r
3110 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCKI;
\r
3114 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETSIZEOFEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
3115 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
3118 return returnCode;
\r
3122 * Procedure: Dem_GetFreezeFrameDataByDTC
\r
3125 /** @req DEM236 */
\r
3126 Dem_ReturnGetFreezeFrameDataByDTCType Dem_GetFreezeFrameDataByDTC(uint32 dtc,Dem_DTCKindType dtcKind,Dem_DTCOriginType dtcOrigin,uint8 recordNumber,uint8* destBuffer,uint8* bufSize)
\r
3128 Dem_ReturnGetFreezeFrameDataByDTCType returnCode = DEM_GET_FFDATABYDTC_WRONG_DTC;
\r
3129 EventStatusRecType *eventRec;
\r
3130 Dem_FreezeFrameClassType const *FFDataRecordClass = NULL;
\r
3131 FreezeFrameRecType *freezeframe;
\r
3132 uint16 FFDataSize = 0;
\r
3134 if (demState == DEM_INITIALIZED) {
\r
3135 if (lookupDtcEvent(dtc, &eventRec)) {
\r
3136 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
3137 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
3138 if (lookupFreezeFrameDataRecNumParam(recordNumber, eventRec->eventParamRef, &FFDataRecordClass)) {
\r
3139 if(lookupFreezeFrameDataSize(recordNumber, &FFDataRecordClass, &FFDataSize)){
\r
3140 if (*bufSize >= FFDataSize) {
\r
3141 switch (dtcOrigin)
\r
3143 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
3144 if (lookupFreezeFrameDataPriMem(eventRec->eventId,recordNumber, &freezeframe)) {
\r
3145 memcpy(destBuffer, freezeframe->data, FFDataSize); /** @req DEM071 */
\r
3146 *bufSize = FFDataSize;
\r
3147 returnCode = DEM_GET_FFDATABYDTC_OK;
\r
3151 returnCode = DEM_GET_FFDATABYDTC_OK;
\r
3155 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
3156 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
3157 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
3158 // Not yet supported
\r
3159 returnCode = DEM_GET_FFDATABYDTC_WRONG_DTCORIGIN;
\r
3160 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFREEZEFRAMEDATARECORDBYDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
3163 returnCode = DEM_GET_FFDATABYDTC_WRONG_DTCORIGIN;
\r
3168 returnCode = DEM_GET_FFDATABYDTC_BUFFERSIZE;
\r
3172 returnCode = DEM_GET_FFDATABYDTC_BUFFERSIZE;
\r
3176 returnCode = DEM_GET_FFDATABYDTC_RECORDNUMBER;
\r
3180 returnCode = DEM_GET_FFDATABYDTC_WRONG_DTCORIGIN;
\r
3184 returnCode = DEM_GET_FFDATABYDTC_WRONG_DTCKIND;
\r
3188 returnCode = DEM_GET_FFDATABYDTC_WRONG_DTC;
\r
3192 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFREEZEFRAMEDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
3193 returnCode = DEM_GET_ID_PENDING;
\r
3196 return returnCode;
\r
3202 * Procedure: Dem_GetFreezeFrameDataIdentifierByDTC
\r
3205 Dem_GetFreezeFameDataIdentifierByDTCType Dem_GetFreezeFrameDataIdentifierByDTC(uint32 dtc,
\r
3206 Dem_DTCKindType dtcKind,
\r
3207 Dem_DTCOriginType dtcOrigin,
\r
3208 uint8 recordNumber,
\r
3210 const uint16** dataId )/** @req DEM237 */
\r
3212 Dem_GetFreezeFameDataIdentifierByDTCType returnCode = DEM_GET_ID_WRONG_FF_TYPE;
\r
3213 Dem_FreezeFrameClassType const *FFDataRecordClass = NULL;
\r
3214 EventStatusRecType *eventRec;
\r
3217 if (demState == DEM_INITIALIZED) {
\r
3218 if (lookupDtcEvent(dtc, &eventRec)) {
\r
3219 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
3220 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
3221 if (lookupFreezeFrameDataRecNumParam(recordNumber, eventRec->eventParamRef, &FFDataRecordClass)) {
\r
3222 if(FFDataRecordClass->FFIdClassRef != NULL){
\r
3223 for(i=0; (i < DEM_MAX_NR_OF_RECORDS_IN_FREEZEFRAME_DATA) && (!(FFDataRecordClass->FFIdClassRef[i].Arc_EOL)); i++){
\r
3224 if(didNum < *arraySize){
\r
3225 dataId[didNum] = &FFDataRecordClass->FFIdClassRef[i].DidIdentifier;/** @req DEM073 */
\r
3227 returnCode = DEM_GET_ID_OK;
\r
3229 returnCode = DEM_GET_ID_WRONG_FF_TYPE;
\r
3232 *arraySize = didNum;
\r
3237 returnCode = DEM_GET_ID_WRONG_FF_TYPE;
\r
3241 returnCode = DEM_GET_ID_WRONG_DTCORIGIN;
\r
3245 returnCode = DEM_GET_ID_WRONG_DTCKIND;
\r
3249 returnCode = DEM_GET_ID_WRONG_DTC;
\r
3254 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFREEZEFRAMEDATAIDENTIFIERBYDTC_ID, DEM_E_UNINIT);
\r
3257 return returnCode;
\r
3262 * Procedure: Dem_GetSizeOfFreezeFrame
\r
3265 /** @req DEM238 */
\r
3266 Dem_ReturnGetSizeOfFreezeFrameType Dem_GetSizeOfFreezeFrame(uint32 dtc,Dem_DTCKindType dtcKind,Dem_DTCOriginType dtcOrigin,uint8 recordNumber,uint16* sizeOfFreezeFrame)
\r
3268 Dem_ReturnGetSizeOfFreezeFrameType returnCode = DEM_GET_SIZEOFFF_PENDING;
\r
3269 Dem_FreezeFrameClassType const *FFDataRecordClass = NULL;
\r
3270 Std_ReturnType callbackReturnCode;
\r
3271 EventStatusRecType *eventRec;
\r
3272 uint16 dataSize = 0;
\r
3275 if (demState == DEM_INITIALIZED) {
\r
3276 if (lookupDtcEvent(dtc, &eventRec)) {
\r
3277 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
3278 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
3279 if (lookupFreezeFrameDataRecNumParam(recordNumber, eventRec->eventParamRef, &FFDataRecordClass)) {
\r
3280 if(FFDataRecordClass->FFIdClassRef != NULL){
\r
3281 for(i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_FREEZEFRAME_DATA) && (!(FFDataRecordClass->FFIdClassRef[i].Arc_EOL)); i++){
\r
3282 /* read out the did size */
\r
3283 if(FFDataRecordClass->FFIdClassRef[i].DidReadDataLengthFnc != NULL){
\r
3284 callbackReturnCode = FFDataRecordClass->FFIdClassRef[i].DidReadDataLengthFnc(&dataSize);
\r
3285 if(callbackReturnCode != E_OK){
\r
3286 return (returnCode = DEM_GET_SIZEOFFF_PENDING);
\r
3290 dataSize = FFDataRecordClass->FFIdClassRef[i].PidOrDidSize;
\r
3292 *sizeOfFreezeFrame += dataSize+DEM_DID_IDENTIFIER_SIZE_OF_BYTES;/** @req DEM074 */
\r
3293 returnCode = DEM_GET_SIZEOFFF_OK;
\r
3298 returnCode = DEM_GET_SIZEOFFF_WRONG_RNUM;
\r
3302 returnCode = DEM_GET_SIZEOFFF_WRONG_DTCOR;
\r
3306 returnCode = DEM_GET_SIZEOFFF_WRONG_DTCKIND;
\r
3310 returnCode = DEM_GET_SIZEOFFF_WRONG_DTC;
\r
3315 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFREEZEFRAMEDATAIDENTIFIERBYDTC_ID, DEM_E_UNINIT);
\r
3316 returnCode = DEM_GET_SIZEOFFF_PENDING;
\r
3319 return returnCode;
\r
3325 #ifdef DEM_UNIT_TEST
\r
3326 void getFFDataPreInit(FreezeFrameRecType **buf)
\r
3328 *buf = &preInitFreezeFrameBuffer[0];
\r
3331 void getPriMemFFBufPtr(FreezeFrameRecType **buf)
\r
3333 *buf = &priMemFreezeFrameBuffer[0];
\r
3337 uint32 getCurTimeStamp()
\r
3339 return FF_TimeStamp;
\r
3342 void getPriMemEventRecBufPtr(EventStatusRecType **buf)
\r
3344 *buf = &eventStatusBuffer[0];
\r
3348 void getPriMemAgingBufPtr(HealingRecType **buf)
\r
3350 *buf = &priMemAgingBuffer[0];
\r
3359 /***********************************
\r
3360 * OBD-specific Interfaces (8.3.6) *
\r
3361 ***********************************/
\r