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 data on event memory
\r
137 Dem_EventIdType eventId;
\r
139 Dem_EventStatusExtendedType eventStatusExtended;
\r
140 ChecksumType checksum;
\r
144 Dem_EventIdType eventId;
\r
146 uint8 data[DEM_MAX_SIZE_EXT_DATA];
\r
147 ChecksumType checksum;
\r
154 DEM_UNINITIALIZED = 0,
\r
155 DEM_PREINITIALIZED,
\r
157 } Dem_StateType; /** @req DEM169 */
\r
160 static Dem_StateType demState = DEM_UNINITIALIZED;
\r
162 // Help pointer to configuration set
\r
163 static const Dem_ConfigSetType *configSet;
\r
166 * Allocation of DTC filter parameters
\r
168 static DtcFilterType dtcFilter;
\r
171 * Allocation of Disable/Enable DTC storage parameters
\r
173 static DisableDtcStorageType disableDtcStorage;
\r
176 * Allocation of operation cycle state list
\r
178 static Dem_OperationCycleStateType operationCycleStateList[DEM_OPERATION_CYCLE_ID_ENDMARK];
\r
181 * Allocation of local event status buffer
\r
183 static EventStatusRecType eventStatusBuffer[DEM_MAX_NUMBER_EVENT];
\r
186 * Allocation of pre-init event memory (used between pre-init and init)
\r
189 static FreezeFrameRecType preInitFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRE_INIT];
\r
190 static ExtDataRecType preInitExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRE_INIT];
\r
193 * Allocation of primary event memory ramlog (after init) in uninitialized memory
\r
196 EventRecType priMemEventBuffer[DEM_MAX_NUMBER_EVENT_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
197 static FreezeFrameRecType priMemFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
198 //FreezeFrameRecType FreezeFrameMirrorBuffer[DEM_MAX_NUMBER_FF_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
199 extern FreezeFrameRecType* FreezeFrameMirrorBuffer[];
\r
200 static ExtDataRecType priMemExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
201 HealingRecType priMemAgingBuffer[DEM_MAX_NUMBER_AGING_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
202 extern HealingRecType HealingMirrorBuffer[DEM_MAX_NUMBER_AGING_PRI_MEM];
\r
204 /* block in NVRam, use for freezeframe */
\r
205 extern const NvM_BlockIdType FreezeFrameBlockId[DEM_MAX_NUMBER_FF_DATA_PRI_MEM];
\r
206 /* block in NVRam, use for aging */
\r
207 extern const NvM_BlockIdType HealingBlockId;
\r
211 *Allocation of freezeFrame storage timestamp,record the time order
\r
213 /**private variable for freezeframe */
\r
214 static uint32 FF_TimeStamp = 0;
\r
217 * TRUE: priMemFreezeFrameBuffer changed,
\r
218 * FALSE: priMemFreezeFrameBuffer not changed
\r
220 static boolean FFIsModified = FALSE;
\r
223 * TRUE: priMemAgingBuffer changed,
\r
224 * FALSE: priMemAgingBuffer not changed
\r
226 static boolean AgingIsModified = FALSE;
\r
229 * Procedure: zeroPriMemBuffers
\r
230 * Description: Fill the primary buffers with zeroes
\r
233 //lint -e84 //PC-Lint exception, size 0 is OK.
\r
234 //lint -e957 PC-Lint exception - Used only by DemTest
\r
235 void demZeroPriMemBuffers(void)
\r
237 memset(priMemEventBuffer, 0, sizeof(priMemEventBuffer));
\r
238 memset(priMemFreezeFrameBuffer, 0, sizeof(priMemFreezeFrameBuffer));
\r
239 memset(priMemExtDataBuffer, 0, sizeof(priMemExtDataBuffer));
\r
244 * Procedure: calcChecksum
\r
245 * Description: Calculate checksum over *data to *(data+nrOfBytes-1) area
\r
247 static ChecksumType calcChecksum(void *data, uint16 nrOfBytes)
\r
250 uint8 *byte = (uint8*)data;
\r
251 ChecksumType sum = 0;
\r
253 for (i = 0; i < nrOfBytes; i++) {
\r
262 * Procedure: checkDtcKind
\r
263 * Description: Return TRUE if "dtcKind" match the events DTCKind or "dtcKind"
\r
264 * is "DEM_DTC_KIND_ALL_DTCS" otherwise FALSE.
\r
266 static boolean checkDtcKind(Dem_DTCKindType dtcKind, const Dem_EventParameterType *eventParam)
\r
268 boolean result = FALSE;
\r
270 if (dtcKind == DEM_DTC_KIND_ALL_DTCS) {
\r
274 if (eventParam->DTCClassRef != NULL) {
\r
275 if (eventParam->DTCClassRef->DTCKind == dtcKind) {
\r
285 * Procedure: checkDtcGroup
\r
286 * Description: Return TRUE if "dtc" match the events DTC or "dtc" is
\r
287 * "DEM_DTC_GROUP_ALL_DTCS" otherwise FALSE.
\r
289 static boolean checkDtcGroup(uint32 dtc, const Dem_EventParameterType *eventParam)
\r
291 boolean result = FALSE;
\r
293 if (dtc == DEM_DTC_GROUP_ALL_DTCS) {
\r
297 if (eventParam->DTCClassRef != NULL) {
\r
298 if (eventParam->DTCClassRef->DTC == dtc) {
\r
308 * Procedure: checkDtcOrigin
\r
309 * Description: Return TRUE if "dtcOrigin" match any of the events DTCOrigin otherwise FALSE.
\r
311 static boolean checkDtcOrigin(Dem_DTCOriginType dtcOrigin, const Dem_EventParameterType *eventParam)
\r
313 boolean result = FALSE;
\r
314 boolean dtcOriginFound = FALSE;
\r
317 for (i = 0;(i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound); i++){
\r
318 dtcOriginFound = (eventParam->EventClass->EventDestination[i] == dtcOrigin);
\r
321 if (dtcOriginFound) {
\r
329 * Procedure: checkDtcSeverityMask
\r
330 * Description: Return TRUE if "dtcSeverityMask" match any of the events DTC severity otherwise FALSE.
\r
332 // PC-Lint (715 etc): Remove errors until function is filled.
\r
333 //lint -e{715} Symbol not referenced
\r
334 static boolean checkDtcSeverityMask(Dem_DTCSeverityType dtcSeverityMask, const Dem_EventParameterType *eventParam)
\r
336 boolean result = TRUE;
\r
338 // TODO: This function is optional, may be implemented here.
\r
345 * Procedure: checkDtcFaultDetectionCounterMask
\r
346 * Description: TBD.
\r
348 // PC-Lint (715 etc): Remove errors until function is filled.
\r
349 //lint -e{715} Symbol not referenced
\r
350 static boolean checkDtcFaultDetectionCounter(const Dem_EventParameterType *eventParam)
\r
352 boolean result = TRUE;
\r
354 // TODO: Not implemented yet.
\r
361 * Procedure: lookupEventStatusRec
\r
362 * Description: Returns the pointer to event id parameters of "eventId" in "*eventStatusBuffer",
\r
363 * if not found NULL is returned.
\r
365 static void lookupEventStatusRec(Dem_EventIdType eventId, EventStatusRecType **const eventStatusRec)
\r
368 boolean eventIdFound = FALSE;
\r
370 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!eventIdFound); i++) {
\r
371 eventIdFound = (eventStatusBuffer[i].eventId == eventId);
\r
374 if (eventIdFound) {
\r
375 *eventStatusRec = &eventStatusBuffer[i-1];
\r
377 *eventStatusRec = NULL;
\r
383 * Procedure: lookupEventIdParameter
\r
384 * Description: Returns the pointer to event id parameters of "eventId" in "*eventIdParam",
\r
385 * if not found NULL is returned.
\r
387 static void lookupEventIdParameter(Dem_EventIdType eventId, const Dem_EventParameterType **const eventIdParam)
\r
389 const Dem_EventParameterType *EventIdParamList = configSet->EventParameter;
\r
391 /* Lookup the correct event id parameters */
\r
393 while ((EventIdParamList[i].EventID != eventId) && (!EventIdParamList[i].Arc_EOL)) {
\r
397 if (!EventIdParamList[i].Arc_EOL) {
\r
398 *eventIdParam = &EventIdParamList[i];
\r
400 *eventIdParam = NULL;
\r
406 * Procedure: preDebounceNone
\r
407 * Description: Returns the result of the debouncing.
\r
409 static Dem_EventStatusType preDebounceNone(const Dem_EventStatusType reportedStatus, const EventStatusRecType* statusRecord) {
\r
410 Dem_EventStatusType returnCode;
\r
411 (void)statusRecord; // Just to get rid of PC-Lint warnings
\r
413 switch (reportedStatus) {
\r
414 case DEM_EVENT_STATUS_FAILED: /** @req DEM091.NoneFailed */
\r
415 case DEM_EVENT_STATUS_PASSED: /** @req DEM091.NonePassed */
\r
416 // Already debounced, do nothing.
\r
420 // TODO: What to do with PREFAIL and PREPASSED on no debouncing?
\r
421 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_NONE_ID, DEM_E_PARAM_DATA);
\r
425 returnCode = reportedStatus;
\r
431 * Procedure: preDebounceCounterBased
\r
432 * Description: Returns the result of the debouncing.
\r
434 static Dem_EventStatusType preDebounceCounterBased(Dem_EventStatusType reportedStatus, EventStatusRecType* statusRecord) {
\r
435 Dem_EventStatusType returnCode;
\r
436 const Dem_PreDebounceCounterBasedType* pdVars = statusRecord->eventParamRef->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceCounterBased;
\r
438 switch (reportedStatus) {
\r
439 case DEM_EVENT_STATUS_PREFAILED:
\r
440 if (statusRecord->faultDetectionCounter < DEBOUNCE_FDC_TEST_FAILED) {
\r
441 if ((pdVars->JumpUp) && (statusRecord->faultDetectionCounter < 0)) {
\r
442 statusRecord->faultDetectionCounter = 0;
\r
444 if (((sint16)statusRecord->faultDetectionCounter + (sint8)pdVars->CountInStepSize) < DEBOUNCE_FDC_TEST_FAILED) {
\r
445 statusRecord->faultDetectionCounter += (sint8)pdVars->CountInStepSize;
\r
447 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED;
\r
453 case DEM_EVENT_STATUS_PREPASSED:
\r
454 if (statusRecord->faultDetectionCounter > DEBOUNCE_FDC_TEST_PASSED) {
\r
455 if ((pdVars->JumpDown) && (statusRecord->faultDetectionCounter > 0)) {
\r
456 statusRecord->faultDetectionCounter = 0;
\r
458 if (((sint16)statusRecord->faultDetectionCounter - (sint8)pdVars->CountOutStepSize) > DEBOUNCE_FDC_TEST_PASSED) {
\r
459 statusRecord->faultDetectionCounter -= (sint8)pdVars->CountOutStepSize;
\r
461 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED;
\r
467 case DEM_EVENT_STATUS_FAILED:
\r
468 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED; /** @req DEM091.CounterFailed */
\r
471 case DEM_EVENT_STATUS_PASSED:
\r
472 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED; /** @req DEM091.CounterPassed */
\r
476 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_COUNTER_BASED_ID, DEM_E_PARAM_DATA);
\r
481 switch (statusRecord->faultDetectionCounter) {
\r
482 case DEBOUNCE_FDC_TEST_FAILED:
\r
483 returnCode = DEM_EVENT_STATUS_FAILED;
\r
486 case DEBOUNCE_FDC_TEST_PASSED:
\r
487 returnCode = DEM_EVENT_STATUS_PASSED;
\r
491 returnCode = reportedStatus;
\r
500 * Procedure: updateEventStatusRec
\r
501 * Description: Update the status of "eventId", if not exist and "createIfNotExist" is
\r
502 * true a new record is created
\r
504 static void updateEventStatusRec(const Dem_EventParameterType *eventParam, Dem_EventStatusType eventStatus, boolean createIfNotExist, EventStatusRecType *eventStatusRec)
\r
506 EventStatusRecType *eventStatusRecPtr;
\r
507 sint8 faultCounterBeforeDebounce = 0;
\r
508 sint8 faultCounterAfterDebounce = 0;
\r
512 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
514 if ((eventStatusRecPtr == NULL) && (createIfNotExist)) {
\r
515 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
516 if (eventStatusRecPtr != NULL) {
\r
517 eventStatusRecPtr->eventId = eventParam->EventID;
\r
518 eventStatusRecPtr->eventParamRef = eventParam;
\r
519 eventStatusRecPtr->faultDetectionCounter = 0;
\r
520 eventStatusRecPtr->occurrence = 0;
\r
521 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
522 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
525 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
530 if (eventStatusRecPtr != NULL) {
\r
531 faultCounterBeforeDebounce = eventStatusRecPtr->faultDetectionCounter;
\r
533 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
534 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName) { /** @req DEM004 */ /** @req DEM342 */
\r
535 case DEM_NO_PRE_DEBOUNCE:
\r
536 eventStatus = preDebounceNone(eventStatus, eventStatusRecPtr);
\r
539 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
540 eventStatus = preDebounceCounterBased(eventStatus, eventStatusRecPtr);
\r
544 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
548 faultCounterAfterDebounce = eventStatusRecPtr->faultDetectionCounter;
\r
550 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
552 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
553 if (!(eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED)) {
\r
554 eventStatusRecPtr->occurrence++;
\r
555 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
557 /** @req DEM036 */ /** @req DEM379.PendingSet */
\r
558 eventStatusRecPtr->eventStatusExtended |= (DEM_TEST_FAILED | DEM_TEST_FAILED_THIS_OPERATION_CYCLE | DEM_TEST_FAILED_SINCE_LAST_CLEAR | DEM_PENDING_DTC | DEM_CONFIRMED_DTC);
\r
559 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
562 if (eventStatus == DEM_EVENT_STATUS_PASSED) {
\r
563 if (eventStatusRecPtr->eventStatusExtended & (DEM_TEST_FAILED | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE)) {
\r
564 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
567 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED;
\r
568 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
571 if ((eventStatus == DEM_EVENT_STATUS_PREFAILED)\
\r
572 && (faultCounterBeforeDebounce <= 0) && (faultCounterAfterDebounce > 0)){
\r
573 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
576 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
579 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
580 eventStatusRec->faultDetectionCounter = 0;
\r
581 eventStatusRec->occurrence = 0;
\r
582 eventStatusRec->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
583 eventStatusRec->errorStatusChanged = FALSE;
\r
586 Irq_Restore(state);
\r
591 * Procedure: mergeEventStatusRec
\r
592 * Description: Update the occurrence counter of status, if not exist a new record is created
\r
594 static void mergeEventStatusRec(const EventRecType *eventRec)
\r
596 EventStatusRecType *eventStatusRecPtr;
\r
601 lookupEventStatusRec(eventRec->eventId, &eventStatusRecPtr);
\r
603 if (eventStatusRecPtr != NULL) {
\r
604 // Update occurrence counter.
\r
605 eventStatusRecPtr->occurrence += eventRec->occurrence;
\r
606 // Merge event status extended with stored
\r
607 // TEST_FAILED_SINCE_LAST_CLEAR should be set if set if set in either
\r
608 eventStatusRecPtr->eventStatusExtended |= (Dem_EventStatusExtendedType)(eventRec->eventStatusExtended & DEM_TEST_FAILED_SINCE_LAST_CLEAR);
\r
609 // DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR should cleared if cleared in either
\r
610 eventStatusRecPtr->eventStatusExtended |= (Dem_EventStatusExtendedType)(eventRec->eventStatusExtended & eventStatusRecPtr->eventStatusExtended & DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR);
\r
611 // DEM_PENDING_DTC and DEM_CONFIRMED_DTC should be set if set in either
\r
612 eventStatusRecPtr->eventStatusExtended |= (Dem_EventStatusExtendedType)(eventRec->eventStatusExtended & (DEM_PENDING_DTC | DEM_CONFIRMED_DTC));
\r
616 // Search for free position
\r
617 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
619 if (eventStatusRecPtr != NULL) {
\r
620 // Create new event, from stored event
\r
621 eventStatusRecPtr->eventId = eventRec->eventId;
\r
622 lookupEventIdParameter(eventRec->eventId, &eventStatusRecPtr->eventParamRef);
\r
623 eventStatusRecPtr->faultDetectionCounter = 0;
\r
624 eventStatusRecPtr->occurrence = eventRec->occurrence;
\r
625 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
626 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
629 // Error: Event status buffer full
\r
630 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_MERGE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
634 Irq_Restore(state);
\r
638 * Procedure: resetEventStatusRec
\r
639 * Description: Reset the status record of "eventParam->eventId" from "eventStatusBuffer".
\r
641 static void resetEventStatusRec(const Dem_EventParameterType *eventParam)
\r
643 EventStatusRecType *eventStatusRecPtr;
\r
648 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
650 if (eventStatusRecPtr != NULL) {
\r
651 // Reset event record
\r
652 eventStatusRecPtr->faultDetectionCounter = 0;
\r
653 eventStatusRecPtr->eventStatusExtended = (DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR);
\r
654 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
655 eventStatusRecPtr->occurrence = 0;
\r
658 Irq_Restore(state);
\r
662 * Procedure: getEventStatusRec
\r
663 * Description: Returns the status record of "eventId" in "eventStatusRec"
\r
665 static void getEventStatusRec(Dem_EventIdType eventId, EventStatusRecType *eventStatusRec)
\r
667 EventStatusRecType *eventStatusRecPtr;
\r
670 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
672 if (eventStatusRecPtr != NULL) {
\r
674 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
677 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
683 * Procedure: lookupDtcEvent
\r
684 * Description: Returns TRUE if the DTC was found and "eventStatusRec" points
\r
685 * to the event record found.
\r
687 static boolean lookupDtcEvent(uint32 dtc, EventStatusRecType **eventStatusRec)
\r
689 boolean dtcFound = FALSE;
\r
692 *eventStatusRec = NULL;
\r
694 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!dtcFound); i++) {
\r
695 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
696 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
699 if (eventStatusBuffer[i].eventParamRef->DTCClassRef->DTC == dtc) {
\r
700 *eventStatusRec = &eventStatusBuffer[i];
\r
712 * Procedure: matchEventWithDtcFilter
\r
713 * Description: Returns TRUE if the event pointed by "event" fulfill
\r
714 * the "dtcFilter" global filter settings.
\r
716 static boolean matchEventWithDtcFilter(const EventStatusRecType *eventRec)
\r
718 boolean dtcMatch = FALSE;
\r
721 if ((dtcFilter.dtcStatusMask == DEM_DTC_STATUS_MASK_ALL) || (eventRec->eventStatusExtended & dtcFilter.dtcStatusMask)) {
\r
722 if (eventRec->eventParamRef != NULL) {
\r
725 if (checkDtcKind(dtcFilter.dtcKind, eventRec->eventParamRef)) {
\r
728 if (checkDtcOrigin(dtcFilter.dtcOrigin, eventRec->eventParamRef)) {
\r
731 if ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
732 || ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES) && (checkDtcSeverityMask(dtcFilter.dtcSeverityMask, eventRec->eventParamRef)))) {
\r
734 // Check fault detection counter
\r
735 if ((dtcFilter.filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO)
\r
736 || ((dtcFilter.filterWithSeverity == DEM_FILTER_FOR_FDC_YES) && (checkDtcFaultDetectionCounter(eventRec->eventParamRef)))) {
\r
748 * Procedure: bubbleSort
\r
749 * Description: bubble sort
\r
751 static void bubbleSort(FreezeFrameRecType *freezeFrameBuf, uint16 length)
\r
753 FreezeFrameRecType temp;
\r
757 //Bubble sort:rearrange priMemFreezeFrameBuffer from little to big
\r
758 for(i=0;i<length;i++){
\r
759 for(j=length-1; j > i; j--){
\r
760 if(freezeFrameBuf[i].timeStamp > freezeFrameBuf[j].timeStamp){
\r
761 //exchange buffer data
\r
762 memcpy(&temp,&freezeFrameBuf[i],sizeof(FreezeFrameRecType));
\r
763 memcpy(&freezeFrameBuf[i],&freezeFrameBuf[j],sizeof(FreezeFrameRecType));
\r
764 memcpy(&freezeFrameBuf[j],&temp,sizeof(FreezeFrameRecType));
\r
772 * Procedure: retrieveEventStatusBit
\r
773 * Description: retrieve Event Status Bit
\r
775 static boolean retrieveEventStatusBit(FreezeFrameRecType *freezeFrameBuf,
\r
777 Dem_EventStatusExtendedType nBit,
\r
778 FreezeFrameRecType **freezeFrame)
\r
780 boolean freezeFrameFound = FALSE;
\r
784 for(i=0;i<length;i++){
\r
785 for(j=0; (j < DEM_MAX_NUMBER_EVENT) && (!freezeFrameFound); j++){
\r
786 freezeFrameFound = (eventStatusBuffer[j].eventId == freezeFrameBuf[i].eventId)\
\r
787 && (!(eventStatusBuffer[j].eventStatusExtended & nBit));
\r
788 if(freezeFrameFound == TRUE){
\r
789 *freezeFrame = &freezeFrameBuf[i];
\r
794 return freezeFrameFound;
\r
799 * Procedure: lookupFreezeFrameForDisplacementPreInit
\r
800 * Description: implement displacement strategy preinit:1.find out the oldest "not confirmed" DTC
\r
801 * 2.find out the oldest inactive DTC,inactive:testFailed is not set
\r
802 * 3.find ou the oldest active DTC,active:testFailed is set
\r
804 static boolean lookupFreezeFrameForDisplacementPreInit(FreezeFrameRecType **freezeFrame)
\r
806 boolean freezeFrameFound = FALSE;
\r
808 /* Bubble sort:rearrange priMemFreezeFrameBuffer from little to big */
\r
809 bubbleSort(preInitFreezeFrameBuffer, DEM_MAX_NUMBER_FF_DATA_PRE_INIT);
\r
811 /* find out the oldest not confirmed dtc */
\r
812 freezeFrameFound = retrieveEventStatusBit(preInitFreezeFrameBuffer, DEM_MAX_NUMBER_FF_DATA_PRE_INIT, DEM_CONFIRMED_DTC, freezeFrame);
\r
814 /* if all confirmed,lookup the oldest inactive dtc */
\r
815 if(freezeFrameFound == FALSE){
\r
816 freezeFrameFound = retrieveEventStatusBit(preInitFreezeFrameBuffer, DEM_MAX_NUMBER_FF_DATA_PRE_INIT, DEM_TEST_FAILED, freezeFrame);
\r
819 /* if all confirmed,lookup the oldest active dtc */
\r
820 if(freezeFrameFound == FALSE){
\r
821 *freezeFrame = &preInitFreezeFrameBuffer[0];
\r
822 freezeFrameFound = TRUE;
\r
825 return freezeFrameFound;
\r
829 * Procedure: lookupFreezeFrameForDisplacement
\r
830 * Description: implement displacement strategy:1.find out the oldest "not confirmed" DTC
\r
831 * 2.find out the oldest inactive DTC,inactive:testFailed is not set
\r
832 * 3.find ou the oldest active DTC,active:testFailed is set
\r
834 static boolean lookupFreezeFrameForDisplacement(FreezeFrameRecType **freezeFrame)
\r
836 boolean freezeFrameFound = FALSE;
\r
838 bubbleSort(priMemFreezeFrameBuffer, DEM_MAX_NUMBER_FF_DATA_PRI_MEM);
\r
840 /* Find out the oldest not confirmed dtc */
\r
841 freezeFrameFound = retrieveEventStatusBit(priMemFreezeFrameBuffer, DEM_MAX_NUMBER_FF_DATA_PRI_MEM, DEM_CONFIRMED_DTC, freezeFrame);
\r
843 /* If all confirmed, lookup the oldest inactive dtc */
\r
844 if(freezeFrameFound == FALSE){
\r
845 freezeFrameFound = retrieveEventStatusBit(priMemFreezeFrameBuffer, DEM_MAX_NUMBER_FF_DATA_PRI_MEM, DEM_TEST_FAILED, freezeFrame);
\r
848 /* If all confirmed,lookup the oldest active dtc */
\r
849 if(freezeFrameFound == FALSE){
\r
850 *freezeFrame = &priMemFreezeFrameBuffer[0];
\r
851 freezeFrameFound = TRUE;
\r
854 return freezeFrameFound;
\r
857 * Procedure: rearrangeFreezeFrameTimeStamp
\r
858 * Description: rearrange FF timestamp when timestamp is beyond DEM_MAX_TIMESTAMP_FOR_REARRANGEMENT
\r
860 static void rearrangeFreezeFrameTimeStamp(uint32 *timeStamp)
\r
862 FreezeFrameRecType temp;
\r
867 /* Bubble sort:rearrange priMemFreezeFrameBuffer from little to big */
\r
868 for(i=0;i<DEM_MAX_NUMBER_FF_DATA_PRI_MEM;i++){
\r
869 if(priMemFreezeFrameBuffer[i].eventId != DEM_EVENT_ID_NULL){
\r
870 for(j=DEM_MAX_NUMBER_FF_DATA_PRI_MEM-1; j > i; j--){
\r
871 if(priMemFreezeFrameBuffer[j].eventId != DEM_EVENT_ID_NULL){
\r
872 if(priMemFreezeFrameBuffer[i].timeStamp > priMemFreezeFrameBuffer[j].timeStamp){
\r
873 //exchange buffer data
\r
874 memcpy(&temp,&priMemFreezeFrameBuffer[i],sizeof(FreezeFrameRecType));
\r
875 memcpy(&priMemFreezeFrameBuffer[i],&priMemFreezeFrameBuffer[j],sizeof(FreezeFrameRecType));
\r
876 memcpy(&priMemFreezeFrameBuffer[j],&temp,sizeof(FreezeFrameRecType));
\r
882 priMemFreezeFrameBuffer[i].timeStamp = k++;
\r
886 /* update the current timeStamp */
\r
891 * Procedure: getFreezeFrameData
\r
892 * Description: get FF data according configuration
\r
894 static void getFreezeFrameData(const Dem_EventParameterType *eventParam,
\r
895 FreezeFrameRecType *freezeFrame,
\r
896 Dem_EventStatusType eventStatus,
\r
897 EventStatusRecType *eventStatusRec)
\r
899 Dem_FreezeFrameStorageConditonType prefailedOrFailed;
\r
900 Std_ReturnType callbackReturnCode;
\r
902 uint16 storeIndex = 0;
\r
903 uint16 recordSize = 0;
\r
905 const Dem_FreezeFrameClassType *FreezeFrameLocal = NULL;
\r
906 Dcm_NegativeResponseCodeType errorCode;//should include Dcm_Lcfg.h
\r
908 /* clear FF data record */
\r
909 memset(freezeFrame, 0, sizeof(FreezeFrameRecType ));
\r
911 /* check if prefailed or failed */
\r
912 if(eventStatusRec->eventStatusExtended & DEM_TEST_FAILED){
\r
913 prefailedOrFailed = FAILED;//confirm the FF is stored for failed
\r
917 if(eventStatus == DEM_EVENT_STATUS_PREFAILED){
\r
918 prefailedOrFailed = PREFAILED;//confirm the FF is stored for prefailed
\r
921 prefailedOrFailed = FF_STORAGE_CONDITION_WRONG;
\r
922 freezeFrame->eventId = DEM_EVENT_ID_NULL;
\r
927 /* Find out the corresponding FF class */
\r
928 for(i = 0;(i<DEM_MAX_NR_OF_CLASSES_IN_FREEZEFRAME_DATA) && (eventParam->FreezeFrameClassRef[i] != NULL);i++){
\r
929 if(eventParam->FreezeFrameClassRef[i]->FFStorageCondition == prefailedOrFailed){
\r
930 FreezeFrameLocal = eventParam->FreezeFrameClassRef[i];
\r
935 if(FreezeFrameLocal != NULL){
\r
936 if(FreezeFrameLocal->FFIdClassRef != NULL){
\r
937 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_FREEZEFRAME_DATA) && (!(FreezeFrameLocal->FFIdClassRef[i].Arc_EOL)); i++) {
\r
938 if(FreezeFrameLocal->FFIdClassRef[i].PidOrDidUsePort == FALSE){
\r
939 if(FreezeFrameLocal->FFIdClassRef[i].DidReadDataLengthFnc != NULL){
\r
940 callbackReturnCode = FreezeFrameLocal->FFIdClassRef[i].DidReadDataLengthFnc(&recordSize);
\r
941 if(callbackReturnCode != E_OK){
\r
942 //if fail to read data length,discard the storage of FF
\r
943 freezeFrame->eventId = DEM_EVENT_ID_NULL;
\r
944 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GET_FREEZEFRAME_ID, DEM_READ_DATA_LENGTH_FAILED);
\r
948 /* if no readDidDataLengthFunction, then try the PidOrDidSize. */
\r
950 recordSize = FreezeFrameLocal->FFIdClassRef[i].PidOrDidSize;
\r
952 /* read out the did data */
\r
953 if ((storeIndex + recordSize + DEM_DID_IDENTIFIER_SIZE_OF_BYTES) <= DEM_MAX_SIZE_FF_DATA) {
\r
955 freezeFrame->data[storeIndex] = (FreezeFrameLocal->FFIdClassRef[i].DidIdentifier>> 8) & 0xFFu;
\r
957 freezeFrame->data[storeIndex] = FreezeFrameLocal->FFIdClassRef[i].DidIdentifier & 0xFFu;
\r
960 if(FreezeFrameLocal->FFIdClassRef[i].DidConditionCheckReadFnc != NULL){
\r
961 callbackReturnCode = FreezeFrameLocal->FFIdClassRef[i].DidConditionCheckReadFnc(&errorCode);
\r
962 if ((callbackReturnCode == E_OK) && (errorCode == DCM_E_POSITIVERESPONSE)) {
\r
963 if(FreezeFrameLocal->FFIdClassRef[i].DidReadFnc!= NULL){
\r
964 callbackReturnCode = FreezeFrameLocal->FFIdClassRef[i].DidReadFnc(&freezeFrame->data[storeIndex]);
\r
965 if (callbackReturnCode != E_OK) {
\r
966 memset(&freezeFrame->data[storeIndex], DEM_FREEZEFRAME_DEFAULT_VALUE, recordSize);
\r
968 storeIndex += recordSize;
\r
972 memset(&freezeFrame->data[storeIndex], DEM_FREEZEFRAME_DEFAULT_VALUE, recordSize);
\r
973 storeIndex += recordSize;
\r
978 memset(&freezeFrame->data[storeIndex], DEM_FREEZEFRAME_DEFAULT_VALUE, recordSize);
\r
979 storeIndex += recordSize;
\r
983 memset(&freezeFrame->data[storeIndex], DEM_FREEZEFRAME_DEFAULT_VALUE, recordSize);
\r
984 storeIndex += recordSize;
\r
989 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GET_FREEZEFRAME_ID, DEM_E_FF_TOO_BIG);
\r
994 //TODO:RTE should provide the port
\r
995 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GET_FREEZEFRAME_ID, DEM_DSP_DID_USE_PORT_IS_TRUE);
\r
1002 /* create an empty FF */
\r
1003 freezeFrame->eventId = DEM_EVENT_ID_NULL;
\r
1006 /* Check if any data has been stored */
\r
1007 if (storeIndex != 0) {
\r
1008 freezeFrame->eventId = eventParam->EventID;
\r
1009 freezeFrame->occurrence = eventStatusRec->occurrence;
\r
1010 freezeFrame->dataSize = storeIndex;
\r
1011 freezeFrame->recordNumber = FreezeFrameLocal->FFRecordNumber;
\r
1014 if(FF_TimeStamp > DEM_MAX_TIMESTAMP_FOR_REARRANGEMENT){
\r
1015 rearrangeFreezeFrameTimeStamp(&FF_TimeStamp);
\r
1018 freezeFrame->timeStamp = FF_TimeStamp;
\r
1022 Irq_Restore(state);
\r
1024 freezeFrame->checksum = calcChecksum(freezeFrame, sizeof(FreezeFrameRecType)-sizeof(ChecksumType));
\r
1027 freezeFrame->eventId = DEM_EVENT_ID_NULL;
\r
1028 freezeFrame->dataSize = storeIndex;
\r
1029 freezeFrame->checksum = 0;
\r
1035 * Procedure: storeFreezeFrameDataPreInit
\r
1036 * Description: store FF in before preInitFreezeFrameBuffer DEM's full initialization
\r
1038 static void storeFreezeFrameDataPreInit(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1040 boolean eventIdFound = FALSE;
\r
1041 boolean eventIdFreePositionFound=FALSE;
\r
1042 FreezeFrameRecType *freezeFrameLocal = NULL;
\r
1048 /* Check if already stored */
\r
1049 for (i = 0; (i<DEM_MAX_NUMBER_FF_DATA_PRE_INIT) && (!eventIdFound); i++){
\r
1050 eventIdFound = ((preInitFreezeFrameBuffer[i].eventId == eventParam->EventID) && (preInitFreezeFrameBuffer[i].recordNumber== freezeFrame->recordNumber));
\r
1054 /* overwrite existing */
\r
1055 memcpy(&preInitFreezeFrameBuffer[i-1], freezeFrame, sizeof(FreezeFrameRecType));
\r
1058 /* lookup first free position */
\r
1059 for (i = 0; (i<DEM_MAX_NUMBER_FF_DATA_PRE_INIT) && (!eventIdFreePositionFound); i++){
\r
1060 if(preInitFreezeFrameBuffer[i].eventId == DEM_EVENT_ID_NULL){
\r
1061 eventIdFreePositionFound=TRUE;
\r
1065 if (eventIdFreePositionFound) {
\r
1066 memcpy(&preInitFreezeFrameBuffer[i-1], freezeFrame, sizeof(FreezeFrameRecType));
\r
1069 /* do displacement */
\r
1070 if(lookupFreezeFrameForDisplacementPreInit(&freezeFrameLocal)){
\r
1071 memcpy(freezeFrameLocal, freezeFrame, sizeof(FreezeFrameRecType));
\r
1074 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_FF_DATA_PRE_INIT_ID, DEM_E_PRE_INIT_FF_DATA_BUFF_FULL);
\r
1079 Irq_Restore(state);
\r
1084 * Procedure: updateFreezeFrameOccurrencePreInit
\r
1085 * Description: update the occurrence in preInitFreezeFrameBuffer according to the occurrence stored in priMemEventBuffer
\r
1087 static void updateFreezeFrameOccurrencePreInit(const EventRecType *EventBuffer)
\r
1091 for (i = 0; i<DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++){
\r
1092 if(preInitFreezeFrameBuffer[i].eventId == EventBuffer->eventId){
\r
1093 preInitFreezeFrameBuffer[i].occurrence += EventBuffer->occurrence;
\r
1099 * Procedure: initCurrentFreezeFrameTimeStamp
\r
1100 * Description: initialize current timestamp and update the corresponding timestamp in preInitFreezeFrameBuffer
\r
1102 static void initCurrentFreezeFrameTimeStamp(uint32 *timeStampPtr)
\r
1110 /* Find out the biggest timestamp in the last power on */
\r
1111 for (i = 0; i<DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++){
\r
1112 if((priMemFreezeFrameBuffer[i].eventId != DEM_EVENT_ID_NULL) &&
\r
1113 (priMemFreezeFrameBuffer[i].timeStamp > temp)){
\r
1114 temp = priMemFreezeFrameBuffer[i].timeStamp;
\r
1118 for (i = 0; i<DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++){
\r
1119 if(preInitFreezeFrameBuffer[i].eventId != DEM_EVENT_ID_NULL){
\r
1120 preInitFreezeFrameBuffer[i].timeStamp += temp;
\r
1123 *timeStampPtr += temp;
\r
1124 Irq_Restore(state);
\r
1128 * Procedure: getExtendedData
\r
1129 * Description: Collects the extended data according to "eventParam" and return it in "extData",
\r
1130 * if not found eventId is set to DEM_EVENT_ID_NULL.
\r
1132 static void getExtendedData(const Dem_EventParameterType *eventParam, ExtDataRecType *extData)
\r
1134 Std_ReturnType callbackReturnCode;
\r
1136 uint16 storeIndex = 0;
\r
1137 uint16 recordSize;
\r
1139 // Clear ext data record
\r
1140 memset(extData, 0, sizeof(ExtDataRecType));
\r
1142 // Check if any pointer to extended data class
\r
1143 if (eventParam->ExtendedDataClassRef != NULL) {
\r
1144 // Request extended data and copy it to the buffer
\r
1145 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL); i++) {
\r
1146 recordSize = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
1147 if ((storeIndex + recordSize) <= DEM_MAX_SIZE_EXT_DATA) {
\r
1148 callbackReturnCode = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->CallbackGetExtDataRecord(&extData->data[storeIndex]); /** @req DEM282 */
\r
1149 if (callbackReturnCode != E_OK) {
\r
1150 // Callback data currently not available, clear space.
\r
1151 memset(&extData->data[storeIndex], 0xFF, recordSize);
\r
1153 storeIndex += recordSize;
\r
1156 // Error: Size of extended data record is bigger than reserved space.
\r
1157 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GET_EXTENDED_DATA_ID, DEM_E_EXT_DATA_TOO_BIG);
\r
1158 break; // Break the loop
\r
1163 // Check if any data has been stored
\r
1164 if (storeIndex != 0) {
\r
1165 extData->eventId = eventParam->EventID;
\r
1166 extData->dataSize = storeIndex;
\r
1167 extData->checksum = calcChecksum(extData, sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
1170 extData->eventId = DEM_EVENT_ID_NULL;
\r
1171 extData->dataSize = storeIndex;
\r
1172 extData->checksum = 0;
\r
1178 * Procedure: storeExtendedDataPreInit
\r
1179 * Description: Store the extended data pointed by "extendedData" to the "preInitExtDataBuffer",
\r
1180 * if non existent a new entry is created.
\r
1182 static void storeExtendedDataPreInit(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
1184 boolean eventIdFound = FALSE;
\r
1185 boolean eventIdFreePositionFound=FALSE;
\r
1190 // Check if already stored
\r
1191 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) && (!eventIdFound); i++){
\r
1192 eventIdFound = (preInitExtDataBuffer[i].eventId == eventParam->EventID);
\r
1196 // Yes, overwrite existing
\r
1197 memcpy(&preInitExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
1200 // No, lookup first free position
\r
1201 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) && (!eventIdFreePositionFound); i++){
\r
1202 if(preInitExtDataBuffer[i].eventId ==0){
\r
1203 eventIdFreePositionFound=TRUE;
\r
1207 if (eventIdFreePositionFound) {
\r
1208 memcpy(&preInitExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
1211 // Error: Pre init extended data buffer full
\r
1212 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRE_INIT_ID, DEM_E_PRE_INIT_EXT_DATA_BUFF_FULL);
\r
1216 Irq_Restore(state);
\r
1220 * Procedure: storeEventPriMem
\r
1221 * Description: Store the event data of "eventStatus->eventId" in "priMemEventBuffer",
\r
1222 * if non existent a new entry is created.
\r
1224 static void storeEventPriMem(const Dem_EventParameterType *eventParam, const EventStatusRecType *eventStatus)
\r
1226 boolean eventIdFound = FALSE;
\r
1227 boolean eventIdFreePositionFound=FALSE;
\r
1232 (void)*eventParam; // Currently not used, do this to avoid warning
\r
1234 // Lookup event ID
\r
1235 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
1236 eventIdFound = (priMemEventBuffer[i].eventId == eventStatus->eventId);
\r
1239 if (eventIdFound) {
\r
1240 // Update event found
\r
1241 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
1242 priMemEventBuffer[i-1].eventStatusExtended = eventStatus->eventStatusExtended;
\r
1243 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
1246 // Search for free position
\r
1247 for (i=0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFreePositionFound); i++){
\r
1248 eventIdFreePositionFound = (priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
1252 if (eventIdFreePositionFound) {
\r
1253 priMemEventBuffer[i-1].eventId = eventStatus->eventId;
\r
1254 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
1255 priMemEventBuffer[i-1].eventStatusExtended = eventStatus->eventStatusExtended;
\r
1256 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
1259 // Error: Pri mem event buffer full
\r
1260 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EVENT_PRI_MEM_ID, DEM_E_PRI_MEM_EVENT_BUFF_FULL);
\r
1264 Irq_Restore(state);
\r
1268 * Procedure: deleteEventPriMem
\r
1269 * Description: Delete the event data of "eventParam->eventId" from "priMemEventBuffer".
\r
1271 static void deleteEventPriMem(const Dem_EventParameterType *eventParam)
\r
1273 boolean eventIdFound = FALSE;
\r
1278 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
1279 eventIdFound = (priMemEventBuffer[i].eventId == eventParam->EventID);
\r
1282 if (eventIdFound) {
\r
1283 memset(&priMemEventBuffer[i-1], 0, sizeof(EventRecType));
\r
1286 Irq_Restore(state);
\r
1290 * Procedure: storeEventEvtMem
\r
1291 * Description: Store the event data of "eventStatus->eventId" in event memory according to
\r
1292 * "eventParam" destination option.
\r
1294 static void storeEventEvtMem(const Dem_EventParameterType *eventParam, const EventStatusRecType *eventStatus)
\r
1298 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION)
\r
1299 && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
1300 switch (eventParam->EventClass->EventDestination[i])
\r
1302 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1303 storeEventPriMem(eventParam, eventStatus); /** @req DEM010 */
\r
1306 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1307 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1308 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1309 // Not yet supported
\r
1310 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1320 * Procedure: storeExtendedDataPriMem
\r
1321 * Description: Store the extended data pointed by "extendedData" to the "priMemExtDataBuffer",
\r
1322 * if non existent a new entry is created.
\r
1324 static void storeExtendedDataPriMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData) /** @req DEM041 */
\r
1326 boolean eventIdFound = FALSE;
\r
1327 boolean eventIdFreePositionFound=FALSE;
\r
1332 // Check if already stored
\r
1333 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
1334 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
1337 if (eventIdFound) {
\r
1338 // Yes, overwrite existing
\r
1339 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
1342 // No, lookup first free position
\r
1343 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFreePositionFound); i++){
\r
1344 eventIdFreePositionFound = (priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
1346 if (eventIdFreePositionFound) {
\r
1347 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
1350 // Error: Pri mem extended data buffer full
\r
1351 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRI_MEM_ID, DEM_E_PRI_MEM_EXT_DATA_BUFF_FULL);
\r
1355 Irq_Restore(state);
\r
1359 * Procedure: deleteExtendedDataPriMem
\r
1360 * Description: Delete the extended data of "eventParam->eventId" from "priMemExtDataBuffer".
\r
1362 static void deleteExtendedDataPriMem(const Dem_EventParameterType *eventParam)
\r
1364 boolean eventIdFound = FALSE;
\r
1369 // Check if already stored
\r
1370 for (i = 0;(i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
1371 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
1374 if (eventIdFound) {
\r
1375 // Yes, clear record
\r
1376 memset(&priMemExtDataBuffer[i-1], 0, sizeof(ExtDataRecType));
\r
1379 Irq_Restore(state);
\r
1383 * Procedure: storeExtendedDataEvtMem
\r
1384 * Description: Store the extended data in event memory according to
\r
1385 * "eventParam" destination option
\r
1387 static void storeExtendedDataEvtMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
1391 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
1392 switch (eventParam->EventClass->EventDestination[i])
\r
1394 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1395 storeExtendedDataPriMem(eventParam, extendedData);
\r
1398 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1399 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1400 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1401 // Not yet supported
\r
1402 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1413 * Procedure: lookupExtendedDataRecNumParam
\r
1414 * Description: Returns TRUE if the requested extended data number was found among the configured records for the event.
\r
1415 * "extDataRecClassPtr" returns a pointer to the record class, "posInExtData" returns the position in stored extended data.
\r
1417 static boolean lookupExtendedDataRecNumParam(uint8 extendedDataNumber, const Dem_EventParameterType *eventParam, Dem_ExtendedDataRecordClassType const **extDataRecClassPtr, uint16 *posInExtData)
\r
1419 boolean recNumFound = FALSE;
\r
1421 if (eventParam->ExtendedDataClassRef != NULL) {
\r
1422 uint16 byteCnt = 0;
\r
1425 // Request extended data and copy it to the buffer
\r
1426 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL) && (!recNumFound); i++) {
\r
1427 if (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->RecordNumber == extendedDataNumber) {
\r
1428 *extDataRecClassPtr = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i];
\r
1429 *posInExtData = byteCnt;
\r
1430 recNumFound = TRUE;
\r
1432 byteCnt += eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
1436 return recNumFound;
\r
1441 * Procedure: lookupExtendedDataPriMem
\r
1442 * Description: Returns TRUE if the requested event id is found, "extData" points to the found data.
\r
1444 static boolean lookupExtendedDataPriMem(Dem_EventIdType eventId, ExtDataRecType **extData)
\r
1446 boolean eventIdFound = FALSE;
\r
1449 // Lookup corresponding extended data
\r
1450 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++) {
\r
1451 eventIdFound = (priMemExtDataBuffer[i].eventId == eventId);
\r
1454 if (eventIdFound) {
\r
1455 // Yes, return pointer
\r
1456 *extData = &priMemExtDataBuffer[i-1];
\r
1459 return eventIdFound;
\r
1462 * Procedure: copyNvmMirror
\r
1463 * Description: Copies Nvram to buffer
\r
1466 Std_ReturnType copyNvmMirror(const NvM_BlockIdType BlockId, uint8 *dstPtr, const uint8 *srcPtr, uint8 len)
\r
1469 #if (DEM_USE_NVM == STD_ON)
\r
1470 Std_ReturnType blockReadStatus = E_NOT_OK;
\r
1471 NvM_RequestResultType requestResult;
\r
1473 if( BlockId != 0 ) {
\r
1474 NvM_GetErrorStatus(BlockId, &requestResult);
\r
1475 if(requestResult != NVM_REQ_PENDING ) {
\r
1476 memcpy(dstPtr, srcPtr, len);
\r
1477 blockReadStatus = E_OK;
\r
1481 return blockReadStatus;
\r
1487 * Procedure: writeNvmMirror
\r
1488 * Description: store data in NVRam
\r
1490 Std_ReturnType writeNvmMirror(const NvM_BlockIdType BlockId, uint8 *dstPtr, const uint8 *srcPtr, uint8 len)
\r
1492 #if (DEM_USE_NVM == STD_ON)
\r
1493 Std_ReturnType blockWriteStatus = E_NOT_OK;
\r
1494 NvM_RequestResultType requestResult;
\r
1496 if( BlockId != 0 ) {
\r
1497 NvM_GetErrorStatus(BlockId, &requestResult);
\r
1498 if(requestResult != NVM_REQ_PENDING ) {
\r
1499 memcpy(dstPtr, srcPtr, len);
\r
1500 (void)NvM_WriteBlock(BlockId, (const uint8*)dstPtr);
\r
1501 blockWriteStatus = E_OK;
\r
1505 return blockWriteStatus;
\r
1512 * Procedure: storeAgingRecPerMem
\r
1513 * Description: store aging records in NVRam
\r
1515 static void storeAgingRecPerMem(const NvM_BlockIdType AgingBlockId)
\r
1521 if( E_NOT_OK == writeNvmMirror(AgingBlockId, (uint8 *)HealingMirrorBuffer, (const uint8 *)priMemAgingBuffer, sizeof(priMemAgingBuffer)) ){
\r
1522 AgingIsModified = TRUE;
\r
1525 Irq_Restore(state);
\r
1528 * Procedure: deleteAgingRecPriMem
\r
1529 * Description: delete aging record in primary memory
\r
1531 static void deleteAgingRecPriMem(const Dem_EventParameterType *eventParam)
\r
1538 for (i = 0; i<DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++){
\r
1539 if (priMemAgingBuffer[i].eventId == eventParam->EventID){
\r
1540 memset(&priMemAgingBuffer[i], 0, sizeof(HealingRecType));
\r
1544 Irq_Restore(state);
\r
1548 * Procedure: storeFreezeFrameDataPriMem
\r
1549 * Description: store FreezeFrame data record in primary memory
\r
1551 static void storeFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1553 boolean eventIdFound = FALSE;
\r
1554 boolean eventIdFreePositionFound=FALSE;
\r
1555 boolean displacementPositionFound=FALSE;
\r
1556 FreezeFrameRecType *freezeFrameLocal;
\r
1562 /* Check if already stored */
\r
1563 for (i = 0; (i<DEM_MAX_NUMBER_FF_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
1564 eventIdFound = ((priMemFreezeFrameBuffer[i].eventId == eventParam->EventID) && (priMemFreezeFrameBuffer[i].recordNumber == freezeFrame->recordNumber));
\r
1567 if (eventIdFound) {
\r
1568 memcpy(&priMemFreezeFrameBuffer[i-1], freezeFrame, sizeof(FreezeFrameRecType));
\r
1571 for (i = 0; (i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM) && (!eventIdFreePositionFound); i++){
\r
1572 eventIdFreePositionFound = (priMemFreezeFrameBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
1574 if (eventIdFreePositionFound) {
\r
1575 memcpy(&priMemFreezeFrameBuffer[i-1], freezeFrame, sizeof(FreezeFrameRecType));
\r
1578 displacementPositionFound = lookupFreezeFrameForDisplacement(&freezeFrameLocal);
\r
1579 if(displacementPositionFound){
\r
1580 memcpy(freezeFrameLocal, freezeFrame, sizeof(FreezeFrameRecType));
\r
1583 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_FF_DATA_PRI_MEM_ID, DEM_E_PRI_MEM_FF_DATA_BUFF_FULL);
\r
1588 Irq_Restore(state);
\r
1591 * Procedure: storeFreezeFrameDataPerMem
\r
1592 * Description: Store the freeze frame data in NVRam
\r
1595 static void storeFreezeFrameDataPerMem()
\r
1601 for(uint16 i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++){
\r
1602 if(memcmp(&priMemFreezeFrameBuffer[i], FreezeFrameMirrorBuffer[i], sizeof(FreezeFrameRecType))){
\r
1603 if( E_NOT_OK == writeNvmMirror(FreezeFrameBlockId[i], (uint8 *)FreezeFrameMirrorBuffer[i], (const uint8 *)&priMemFreezeFrameBuffer[i], sizeof(FreezeFrameRecType)) ) {
\r
1604 FFIsModified = TRUE;
\r
1609 Irq_Restore(state);
\r
1612 // PC-Lint (715 etc): Remove errors until function is filled.
\r
1613 //lint -e{715} Symbol not referenced
\r
1614 static void deleteFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam)
\r
1621 for (i = 0; i<DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++){
\r
1622 if (priMemFreezeFrameBuffer[i].eventId == eventParam->EventID){
\r
1623 memset(&priMemFreezeFrameBuffer[i], 0, sizeof(FreezeFrameRecType));
\r
1628 Irq_Restore(state);
\r
1632 * Procedure: storeFreezeFrameDataEvtMem
\r
1633 * Description: Store the freeze frame data in event memory according to
\r
1634 * "eventParam" destination option
\r
1636 static void storeFreezeFrameDataEvtMem(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1640 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
1641 switch (eventParam->EventClass->EventDestination[i])
\r
1643 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1644 storeFreezeFrameDataPriMem(eventParam, freezeFrame);
\r
1645 storeFreezeFrameDataPerMem();
\r
1648 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1649 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1650 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1651 // Not yet supported
\r
1652 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1662 * Procedure: lookupFreezeFrameDataRecNumParam
\r
1663 * Description: Returns TRUE if the requested freezeFrame data number was found among the configured records for the event.
\r
1664 * "freezeFrameClassPtr" returns a pointer to the record class.
\r
1666 static boolean lookupFreezeFrameDataRecNumParam(uint8 recordNumber, const Dem_EventParameterType *eventParam, Dem_FreezeFrameClassType const **freezeFrameClassPtr)
\r
1668 boolean recNumFound = FALSE;
\r
1671 if (eventParam->FreezeFrameClassRef != NULL) {
\r
1672 for (i = 0; (i < DEM_MAX_NR_OF_CLASSES_IN_FREEZEFRAME_DATA) && (eventParam->FreezeFrameClassRef[i] != NULL) && (!recNumFound); i++) {
\r
1673 if (eventParam->FreezeFrameClassRef[i]->FFRecordNumber == recordNumber) {
\r
1674 *freezeFrameClassPtr = eventParam->FreezeFrameClassRef[i];
\r
1675 recNumFound = TRUE;
\r
1680 return recNumFound;
\r
1684 * Procedure: lookupFreezeFrameDataSize
\r
1685 * Description: Returns TRUE if the requested freezeFrame data size was obtained successfully from the configuration.
\r
1686 * "dataSize" returns a pointer to the data size.
\r
1688 static boolean lookupFreezeFrameDataSize(uint8 recordNumber, Dem_FreezeFrameClassType const **freezeFrameClassPtr, uint16 *dataSize)
\r
1690 Std_ReturnType callbackReturnCode;
\r
1691 boolean dataSizeFound = TRUE;
\r
1692 uint16 dataSizeLocal = 0;
\r
1695 if (*freezeFrameClassPtr != NULL) {
\r
1696 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_FREEZEFRAME_DATA) && ((*freezeFrameClassPtr)->FFIdClassRef[i].Arc_EOL != TRUE); i++) {
\r
1697 if((*freezeFrameClassPtr)->FFIdClassRef[i].DidReadDataLengthFnc != NULL){
\r
1698 callbackReturnCode = (*freezeFrameClassPtr)->FFIdClassRef[i].DidReadDataLengthFnc(&dataSizeLocal);
\r
1699 if(callbackReturnCode != E_OK){
\r
1700 return (dataSizeFound = FALSE);
\r
1704 dataSizeLocal = (*freezeFrameClassPtr)->FFIdClassRef[i].PidOrDidSize;
\r
1707 *dataSize += dataSizeLocal + DEM_DID_IDENTIFIER_SIZE_OF_BYTES;
\r
1712 return dataSizeFound;
\r
1716 * Procedure: lookupFreezeFrameDataPriMem
\r
1717 * Description: Returns TRUE if the requested event id is found, "freezeFrame" points to the found data.
\r
1719 static boolean lookupFreezeFrameDataPriMem(Dem_EventIdType eventId,uint8 recordNumber, FreezeFrameRecType **freezeFrame)
\r
1721 boolean eventIdFound = FALSE;
\r
1724 for (i = 0; (i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM) && (!eventIdFound); i++) {
\r
1725 eventIdFound = ((priMemFreezeFrameBuffer[i].eventId == eventId) && (priMemFreezeFrameBuffer[i].recordNumber == recordNumber));
\r
1728 if (eventIdFound) {
\r
1729 *freezeFrame = &priMemFreezeFrameBuffer[i-1];
\r
1732 return eventIdFound;
\r
1736 * Procedure: handlePreInitEvent
\r
1737 * Description: Handle the updating of event status and storing of
\r
1738 * event related data in preInit buffers.
\r
1740 static void handlePreInitEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1742 const Dem_EventParameterType *eventParam;
\r
1743 EventStatusRecType eventStatusLocal;
\r
1744 FreezeFrameRecType freezeFrameLocal;
\r
1745 ExtDataRecType extendedDataLocal;
\r
1747 lookupEventIdParameter(eventId, &eventParam);
\r
1748 if (eventParam != NULL) {
\r
1749 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1750 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1751 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
1752 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1755 updateEventStatusRec(eventParam, eventStatus, FALSE, &eventStatusLocal);
\r
1758 if (eventStatusLocal.errorStatusChanged) {
\r
1759 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1760 getExtendedData(eventParam, &extendedDataLocal);
\r
1761 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1762 storeExtendedDataPreInit(eventParam, &extendedDataLocal);
\r
1764 getFreezeFrameData(eventParam, &freezeFrameLocal,eventStatus,&eventStatusLocal);
\r
1765 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1766 storeFreezeFrameDataPreInit(eventParam, &freezeFrameLocal);
\r
1774 // Operation cycle not started
\r
1775 // TODO: Report error?
\r
1779 // Operation cycle not set
\r
1780 // TODO: Report error?
\r
1784 // Event ID not configured
\r
1785 // TODO: Report error?
\r
1791 * Procedure: handleEvent
\r
1792 * Description: Handle the updating of event status and storing of
\r
1793 * event related data in event memory.
\r
1795 static Std_ReturnType handleEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1797 Std_ReturnType returnCode = E_OK;
\r
1798 const Dem_EventParameterType *eventParam;
\r
1799 EventStatusRecType eventStatusLocal;
\r
1800 FreezeFrameRecType freezeFrameLocal;
\r
1801 ExtDataRecType extendedDataLocal;
\r
1802 Dem_EventStatusType eventStatusTemp = eventStatus;
\r
1804 lookupEventIdParameter(eventId, &eventParam);
\r
1805 if (eventParam != NULL) {
\r
1806 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1807 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1808 if ((!((disableDtcStorage.storageDisabled) && (checkDtcGroup(disableDtcStorage.dtcGroup, eventParam)) && (checkDtcKind(disableDtcStorage.dtcKind, eventParam))))) {
\r
1809 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1810 if (eventStatusLocal.errorStatusChanged) {
\r
1811 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1812 storeEventEvtMem(eventParam, &eventStatusLocal); /** @req DEM184 */
\r
1813 getExtendedData(eventParam, &extendedDataLocal);
\r
1814 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL)
\r
1816 storeExtendedDataEvtMem(eventParam, &extendedDataLocal);
\r
1820 if ((eventStatusTemp == DEM_EVENT_STATUS_PREFAILED)
\r
1821 || (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED)){
\r
1822 getFreezeFrameData(eventParam, &freezeFrameLocal,eventStatus,&eventStatusLocal);
\r
1823 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1824 storeFreezeFrameDataEvtMem(eventParam, &freezeFrameLocal); /** @req DEM190 */
\r
1834 // Operation cycle not started
\r
1835 returnCode = E_NOT_OK;
\r
1839 // Operation cycle not set
\r
1840 returnCode = E_NOT_OK;
\r
1844 // Event ID not configured
\r
1845 returnCode = E_NOT_OK;
\r
1848 return returnCode;
\r
1853 * Procedure: resetEventStatus
\r
1854 * Description: Resets the events status of eventId.
\r
1856 static void resetEventStatus(Dem_EventIdType eventId)
\r
1858 EventStatusRecType *eventStatusRecPtr;
\r
1862 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
1863 if (eventStatusRecPtr != NULL) {
\r
1864 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED; /** @req DEM187 */
\r
1867 Irq_Restore(state);
\r
1872 * Procedure: getEventStatus
\r
1873 * Description: Returns the extended event status bitmask of eventId in "eventStatusExtended".
\r
1875 static void getEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended)
\r
1877 EventStatusRecType eventStatusLocal;
\r
1879 // Get recorded status
\r
1880 getEventStatusRec(eventId, &eventStatusLocal);
\r
1881 if (eventStatusLocal.eventId == eventId) {
\r
1882 *eventStatusExtended = eventStatusLocal.eventStatusExtended; /** @req DEM051 */
\r
1885 // Event Id not found, no report received.
\r
1886 *eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1892 * Procedure: getEventFailed
\r
1893 * Description: Returns the TRUE or FALSE of "eventId" in "eventFailed" depending on current status.
\r
1895 static void getEventFailed(Dem_EventIdType eventId, boolean *eventFailed)
\r
1897 EventStatusRecType eventStatusLocal;
\r
1899 // Get recorded status
\r
1900 getEventStatusRec(eventId, &eventStatusLocal);
\r
1901 if (eventStatusLocal.eventId == eventId) {
\r
1902 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) { /** @req DEM052 */
\r
1903 *eventFailed = TRUE;
\r
1906 *eventFailed = FALSE;
\r
1910 // Event Id not found, assume ok.
\r
1911 *eventFailed = FALSE;
\r
1917 * Procedure: getEventTested
\r
1918 * Description: Returns the TRUE or FALSE of "eventId" in "eventTested" depending on
\r
1919 * current status the "test not completed this operation cycle" bit.
\r
1921 static void getEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1923 EventStatusRecType eventStatusLocal;
\r
1925 // Get recorded status
\r
1926 getEventStatusRec(eventId, &eventStatusLocal);
\r
1927 if (eventStatusLocal.eventId == eventId) {
\r
1928 if ( !(eventStatusLocal.eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE)) { /** @req DEM053 */
\r
1929 *eventTested = TRUE;
\r
1932 *eventTested = FALSE;
\r
1936 // Event Id not found, not tested.
\r
1937 *eventTested = FALSE;
\r
1943 * Procedure: getFaultDetectionCounter
\r
1944 * Description: Returns pre debounce counter of "eventId" in "counter" and return value E_OK if
\r
1945 * the counter was available else E_NOT_OK.
\r
1947 static Std_ReturnType getFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1949 Std_ReturnType returnCode = E_NOT_OK;
\r
1950 const Dem_EventParameterType *eventParam;
\r
1952 lookupEventIdParameter(eventId, &eventParam);
\r
1953 if (eventParam != NULL) {
\r
1954 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
1955 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName)
\r
1957 case DEM_NO_PRE_DEBOUNCE:
\r
1958 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal != NULL) {
\r
1959 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc != NULL) {
\r
1960 returnCode = eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc(counter); /** @req DEM204.None */ /** @req DEM264 */ /** @req DEM265 */
\r
1965 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
1967 EventStatusRecType *eventStatusRec;
\r
1969 lookupEventStatusRec(eventId, &eventStatusRec);
\r
1970 if (eventStatusRec != NULL) {
\r
1971 *counter = eventStatusRec->faultDetectionCounter; /** @req DEM204.Counter */
\r
1975 returnCode = E_OK;
\r
1979 case DEM_PRE_DEBOUNCE_FREQUENCY_BASED:
\r
1980 case DEM_PRE_DEBOUNCE_TIME_BASED:
\r
1981 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1985 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_PARAM_DATA);
\r
1991 return returnCode;
\r
1994 * Procedure: deleteEventMemory
\r
1995 * Description: If aging of an event occurs, the Dem module shall delete the event from
\r
1996 * the event memory including its event related data
\r
1998 static void deleteEventMemory(const Dem_EventParameterType *eventParam)
\r
2002 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
2003 switch (eventParam->EventClass->EventDestination[i])
\r
2005 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2006 deleteEventPriMem(eventParam);
\r
2007 deleteFreezeFrameDataPriMem(eventParam);
\r
2008 deleteExtendedDataPriMem(eventParam);
\r
2009 storeFreezeFrameDataPerMem();
\r
2012 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2013 //TODO:need to add corresponding event and extended deleting functions
\r
2017 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2018 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2019 // Not yet supported
\r
2020 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2031 * Procedure: lookupAgingRecPriMem
\r
2032 * Description: Returns the pointer to event id parameters of "eventId" in "*priMemAgingBuffer",
\r
2033 * if not found NULL is returned.
\r
2035 static boolean lookupAgingRecPriMem(Dem_EventIdType eventId, const HealingRecType **agingRec)
\r
2038 boolean agingRecFound = FALSE;
\r
2040 for (i = 0; i < DEM_MAX_NUMBER_AGING_PRI_MEM && (!agingRecFound); i++) {
\r
2041 if(priMemAgingBuffer[i].eventId == eventId){
\r
2042 agingRecFound = TRUE;
\r
2047 if(agingRecFound){
\r
2048 *agingRec = &priMemAgingBuffer[i-1];
\r
2054 return agingRecFound;
\r
2060 * Procedure: handleAging
\r
2061 * Description: according to the operation state of "operationCycleId" to "cycleState" , handle the aging relatived data
\r
2062 * Returns E_OK if operation was successful else E_NOT_OK.
\r
2064 static Std_ReturnType handleAging(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState)
\r
2067 Std_ReturnType returnCode = E_OK;
\r
2068 HealingRecType *agingRecLocal = NULL;
\r
2069 boolean agingRecFound = FALSE;
\r
2071 if (operationCycleId < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
2072 switch (cycleState)
\r
2074 case DEM_CYCLE_STATE_START:
\r
2077 case DEM_CYCLE_STATE_END:/** @req Dem490 */
\r
2078 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2079 if(eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL){
\r
2080 if(eventStatusBuffer[i].eventParamRef != NULL){
\r
2081 if(eventStatusBuffer[i].eventParamRef->EventClass != NULL){
\r
2082 if((eventStatusBuffer[i].eventParamRef->EventClass->HealingAllowed == TRUE)\
\r
2083 && (eventStatusBuffer[i].eventParamRef->EventClass->HealingCycleRef == operationCycleId)){
\r
2084 if((eventStatusBuffer[i].eventStatusExtended & DEM_CONFIRMED_DTC)\
\r
2085 && (!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_FAILED))\
\r
2086 && (!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE))){
\r
2087 agingRecFound = lookupAgingRecPriMem(eventStatusBuffer[i].eventId, (const HealingRecType **)(&agingRecLocal));
\r
2088 if(agingRecFound){
\r
2089 agingRecLocal->agingCounter++;/** @req Dem489 */
\r
2090 agingRecLocal->checksum = calcChecksum(agingRecLocal,sizeof(HealingRecType) - sizeof(ChecksumType));
\r
2091 if(agingRecLocal->agingCounter > eventStatusBuffer[i].eventParamRef->EventClass->HealingCycleCounter){
\r
2092 //deleteEventMemory(eventStatusBuffer[i].eventParamRef); /** @req Dem497 */
\r
2094 deleteAgingRecPriMem(eventStatusBuffer[i].eventParamRef);
\r
2096 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)(~DEM_CONFIRMED_DTC);
\r
2097 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)(~DEM_PENDING_DTC);
\r
2098 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)(~DEM_WARNING_INDICATOR_REQUESTED);
\r
2100 /* Set the flag,start up the storage of NVRam in main function. */
\r
2101 AgingIsModified = TRUE;
\r
2104 /* If it does exist,establish a new record for the corresponding event */
\r
2105 agingRecFound = lookupAgingRecPriMem(DEM_EVENT_ID_NULL, (const HealingRecType **)(&agingRecLocal));
\r
2106 if(agingRecFound){
\r
2107 agingRecLocal->eventId = eventStatusBuffer[i].eventId;
\r
2108 agingRecLocal->agingCounter++;
\r
2109 agingRecLocal->checksum = calcChecksum(agingRecLocal,sizeof(HealingRecType) - sizeof(ChecksumType));
\r
2110 AgingIsModified = TRUE;
\r
2113 /* primary memory of aging records is full. */
\r
2118 /* If the status bit testFailed (bit 0) is set during the operation cycle, the counter shall be reset. */
\r
2119 if(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_FAILED){
\r
2120 agingRecFound = lookupAgingRecPriMem(eventStatusBuffer[i].eventId, (const HealingRecType **)(&agingRecLocal));
\r
2121 if(agingRecFound){
\r
2122 if(agingRecLocal->agingCounter){
\r
2123 agingRecLocal->agingCounter = 0;
\r
2124 agingRecLocal->checksum = calcChecksum(agingRecLocal,sizeof(HealingRecType) - sizeof(ChecksumType));
\r
2125 AgingIsModified = TRUE;
\r
2137 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
2138 returnCode = E_NOT_OK;
\r
2143 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
2144 returnCode = E_NOT_OK;
\r
2147 return returnCode;
\r
2152 * Procedure: setOperationCycleState
\r
2153 * Description: Change the operation state of "operationCycleId" to "cycleState" and updates stored
\r
2154 * event connected to this cycle id.
\r
2155 * Returns E_OK if operation was successful else E_NOT_OK.
\r
2157 static Std_ReturnType setOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState) /** @req DEM338 */
\r
2160 Std_ReturnType returnCode = E_OK;
\r
2162 if (operationCycleId < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
2163 switch (cycleState)
\r
2165 case DEM_CYCLE_STATE_START:
\r
2166 operationCycleStateList[operationCycleId] = cycleState;
\r
2167 // Lookup event ID
\r
2168 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2169 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
2170 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED_THIS_OPERATION_CYCLE;
\r
2171 eventStatusBuffer[i].eventStatusExtended |= DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
2176 case DEM_CYCLE_STATE_END:
\r
2177 operationCycleStateList[operationCycleId] = cycleState;
\r
2178 // Lookup event ID
\r
2179 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2180 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
2181 if ((!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_FAILED_THIS_OPERATION_CYCLE)) && (!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE))) {
\r
2182 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_PENDING_DTC; // Clear pendingDTC bit /** @req DEM379.PendingClear
\r
2183 storeEventEvtMem(eventStatusBuffer[i].eventParamRef, &eventStatusBuffer[i]);
\r
2189 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
2190 returnCode = E_NOT_OK;
\r
2195 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
2196 returnCode = E_NOT_OK;
\r
2199 return returnCode;
\r
2203 //==============================================================================//
\r
2205 // E X T E R N A L F U N C T I O N S //
\r
2207 //==============================================================================//
\r
2209 /*********************************************
\r
2210 * Interface for upper layer modules (8.3.1) *
\r
2211 *********************************************/
\r
2214 * Procedure: Dem_GetVersionInfo
\r
2217 // Defined in Dem.h
\r
2220 /***********************************************
\r
2221 * Interface ECU State Manager <-> DEM (8.3.2) *
\r
2222 ***********************************************/
\r
2225 * Procedure: Dem_PreInit
\r
2228 void Dem_PreInit(void)
\r
2230 /** @req DEM180 */
\r
2233 EventStatusRecType *eventStatusRecPtr;
\r
2234 const Dem_EventParameterType *eventIdParamList;
\r
2236 VALIDATE_NO_RV(DEM_Config.ConfigSet != NULL, DEM_PREINIT_ID, DEM_E_CONFIG_PTR_INVALID);
\r
2238 configSet = DEM_Config.ConfigSet;
\r
2240 // Initializion of operation cycle states.
\r
2241 for (i = 0; i < DEM_OPERATION_CYCLE_ID_ENDMARK; i++) {
\r
2242 operationCycleStateList[i] = DEM_CYCLE_STATE_END;
\r
2245 // Initialize the event status buffer
\r
2246 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2247 eventStatusBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
2248 eventStatusBuffer[i].eventParamRef = NULL;
\r
2249 eventStatusBuffer[i].faultDetectionCounter = 0;
\r
2250 eventStatusBuffer[i].occurrence = 0;
\r
2251 eventStatusBuffer[i].eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
2252 eventStatusBuffer[i].errorStatusChanged = FALSE;
\r
2255 // Insert all supported events into event status buffer
\r
2257 eventIdParamList = configSet->EventParameter;
\r
2258 while( !eventIdParamList[index].Arc_EOL ) {
\r
2259 // Find next free position in event status buffer
\r
2260 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
2261 if(NULL != eventStatusRecPtr) {
\r
2262 eventStatusRecPtr->eventId = eventIdParamList[index].EventID;
\r
2263 eventStatusRecPtr->eventParamRef = &eventIdParamList[index];
\r
2265 // event status buffer is full
\r
2266 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREINIT_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
2272 //lint -e568 -e685 //PC-Lint exception.
\r
2273 //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
2274 // Initialize the pre init buffers
\r
2275 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
2276 preInitFreezeFrameBuffer[i].checksum = 0;
\r
2277 preInitFreezeFrameBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
2278 preInitFreezeFrameBuffer[i].occurrence = 0;
\r
2279 preInitFreezeFrameBuffer[i].dataSize = 0;
\r
2280 for (j = 0; j < DEM_MAX_SIZE_FF_DATA;j++){
\r
2281 preInitFreezeFrameBuffer[i].data[j] = 0;
\r
2286 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
2287 preInitExtDataBuffer[i].checksum = 0;
\r
2288 preInitExtDataBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
2289 preInitExtDataBuffer[i].dataSize = 0;
\r
2290 for (j = 0; j < DEM_MAX_SIZE_EXT_DATA;j++){
\r
2291 preInitExtDataBuffer[i].data[j] = 0;
\r
2295 disableDtcStorage.storageDisabled = FALSE;
\r
2297 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_START); /** @req DEM047 */
\r
2299 demState = DEM_PREINITIALIZED;
\r
2304 * Procedure: Dem_Init
\r
2307 void Dem_Init(void)
\r
2310 ChecksumType cSum;
\r
2311 const Dem_EventParameterType *eventParam;
\r
2313 if(DEM_PREINITIALIZED != demState){
\r
2315 * Dem_PreInit was has not been called since last time Dem_Shutdown was called.
\r
2316 * This suggests that we are resuming from sleep. According to section 5.7 in
\r
2317 * EcuM specification, RAM content is assumed to be still valid from the previous cycle.
\r
2318 * Do not read from saved error log since buffers already contains this data.
\r
2320 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_START);
\r
2324 for(i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++){
\r
2325 if( E_NOT_OK == copyNvmMirror(FreezeFrameBlockId[i], (uint8 *)&priMemFreezeFrameBuffer[i], (const uint8 *)&FreezeFrameMirrorBuffer[i], sizeof(FreezeFrameRecType)) ){
\r
2326 //TODO:NVM is busy or block id is 0,report error or what?
\r
2329 //recover Aging from NVRam to RAM
\r
2330 if(E_OK == copyNvmMirror(HealingBlockId, (uint8*)priMemAgingBuffer, (const uint8*)HealingMirrorBuffer, sizeof(priMemAgingBuffer)) ){
\r
2334 // Validate aging records stored in primary memory
\r
2335 for (i = 0; i < DEM_MAX_NUMBER_AGING_PRI_MEM; i++){
\r
2336 cSum = calcChecksum(&priMemAgingBuffer[i], sizeof(HealingRecType) - sizeof(ChecksumType));
\r
2337 if ((cSum != priMemAgingBuffer[i].checksum) || (priMemAgingBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
2338 // Unlegal record, clear the record
\r
2339 memset(&priMemAgingBuffer[i], 0, sizeof(HealingRecType));
\r
2340 AgingIsModified = TRUE;
\r
2344 // Validate event records stored in primary memory
\r
2345 for (i = 0; i < DEM_MAX_NUMBER_EVENT_PRI_MEM; i++) {
\r
2346 cSum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
2347 if ((cSum != priMemEventBuffer[i].checksum) || (priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
2348 // Unlegal record, clear the record
\r
2349 memset(&priMemEventBuffer[i], 0, sizeof(EventRecType));
\r
2352 // Valid, update current status
\r
2353 mergeEventStatusRec(&priMemEventBuffer[i]);
\r
2355 // Update occurrence counter on pre init stored freeze frames
\r
2356 updateFreezeFrameOccurrencePreInit(&priMemEventBuffer[i]);
\r
2360 //initialize the current timestamp and update the timestamp in pre init
\r
2361 initCurrentFreezeFrameTimeStamp(&FF_TimeStamp);//add by i-soft
\r
2363 // Validate extended data records stored in primary memory
\r
2364 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM; i++) {
\r
2365 cSum = calcChecksum(&priMemExtDataBuffer[i], sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
2366 if ((cSum != priMemExtDataBuffer[i].checksum) || (priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
2367 // Unlegal record, clear the record
\r
2368 memset(&priMemExtDataBuffer[i], 0, sizeof(ExtDataRecType));
\r
2372 //initialize the current timestamp and update the timestamp in pre init
\r
2373 initCurrentFreezeFrameTimeStamp(&FF_TimeStamp);
\r
2376 //lint -e568 //PC-Lint exception.
\r
2377 //lint -e685 //PC-Lint exception.
\r
2378 //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
2379 // Validate freeze frame records stored in primary memory
\r
2380 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++) {
\r
2381 cSum = calcChecksum(&priMemFreezeFrameBuffer[i], sizeof(FreezeFrameRecType)-sizeof(ChecksumType));
\r
2382 if ((cSum != priMemFreezeFrameBuffer[i].checksum) || (priMemFreezeFrameBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
2383 // Unlegal record, clear the record
\r
2384 memset(&priMemFreezeFrameBuffer[i], 0, sizeof(FreezeFrameRecType));
\r
2389 /* Transfer updated event data to event memory */
\r
2390 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2391 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
2392 lookupEventIdParameter(eventStatusBuffer[i].eventId, &eventParam);
\r
2393 storeEventEvtMem(eventParam, &eventStatusBuffer[i]);
\r
2397 /* Transfer extended data to event memory if necessary */
\r
2398 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
2399 if (preInitExtDataBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
2400 lookupEventIdParameter(preInitExtDataBuffer[i].eventId, &eventParam);
\r
2401 storeExtendedDataEvtMem(eventParam, &preInitExtDataBuffer[i]);
\r
2406 //lint -e568 //PC-Lint exception.
\r
2407 //lint -e685 //PC-Lint exception.
\r
2408 //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
2409 /* Transfer freeze frames to event memory */
\r
2410 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
2411 if (preInitFreezeFrameBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
2412 lookupEventIdParameter(preInitFreezeFrameBuffer[i].eventId, &eventParam);
\r
2413 storeFreezeFrameDataEvtMem(eventParam, &preInitFreezeFrameBuffer[i]);
\r
2419 // Init the dtc filter
\r
2420 dtcFilter.dtcStatusMask = DEM_DTC_STATUS_MASK_ALL; // All allowed
\r
2421 dtcFilter.dtcKind = DEM_DTC_KIND_ALL_DTCS; // All kinds of DTCs
\r
2422 dtcFilter.dtcOrigin = DEM_DTC_ORIGIN_PRIMARY_MEMORY; // Primary memory
\r
2423 dtcFilter.filterWithSeverity = DEM_FILTER_WITH_SEVERITY_NO; // No Severity filtering
\r
2424 dtcFilter.dtcSeverityMask = DEM_SEVERITY_NO_SEVERITY; // Not used when filterWithSeverity is FALSE
\r
2425 dtcFilter.filterForFaultDetectionCounter = DEM_FILTER_FOR_FDC_NO; // No fault detection counter filtering
\r
2427 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
2429 disableDtcStorage.storageDisabled = FALSE;
\r
2431 demState = DEM_INITIALIZED;
\r
2436 * Procedure: Dem_shutdown
\r
2439 void Dem_Shutdown(void)
\r
2441 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_END); /** @req DEM047 */
\r
2443 /* handleAging() should be called behind setOperationCycleState() */
\r
2444 (void)handleAging(DEM_ACTIVE, DEM_CYCLE_STATE_END);
\r
2446 demState = DEM_UNINITIALIZED; /** @req DEM368 */
\r
2451 * Interface for basic software scheduler
\r
2453 void Dem_MainFunction(void)/** @req DEM125 */
\r
2455 if (FFIsModified) {
\r
2456 storeFreezeFrameDataPerMem(FreezeFrameBlockId);
\r
2459 if (AgingIsModified) {
\r
2460 storeAgingRecPerMem(HealingBlockId);
\r
2465 /***************************************************
\r
2466 * Interface SW-Components via RTE <-> DEM (8.3.3) *
\r
2467 ***************************************************/
\r
2470 * Procedure: Dem_SetEventStatus
\r
2473 Std_ReturnType Dem_SetEventStatus(Dem_EventIdType eventId, Dem_EventStatusType eventStatus) /** @req DEM330 */
\r
2475 Std_ReturnType returnCode = E_OK;
\r
2477 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
2479 returnCode = handleEvent(eventId, eventStatus);
\r
2483 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
2484 returnCode = E_NOT_OK;
\r
2487 return returnCode;
\r
2492 * Procedure: Dem_ResetEventStatus
\r
2495 Std_ReturnType Dem_ResetEventStatus(Dem_EventIdType eventId) /** @req DEM331 */
\r
2497 Std_ReturnType returnCode = E_OK;
\r
2499 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
2501 resetEventStatus(eventId); /** @req DEM186 */
\r
2505 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_RESETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
2506 returnCode = E_NOT_OK;
\r
2509 return returnCode;
\r
2514 * Procedure: Dem_GetEventStatus
\r
2517 Std_ReturnType Dem_GetEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended) /** @req DEM332 */
\r
2519 Std_ReturnType returnCode = E_OK;
\r
2521 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
2523 getEventStatus(eventId, eventStatusExtended);
\r
2527 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
2528 returnCode = E_NOT_OK;
\r
2531 return returnCode;
\r
2536 * Procedure: Dem_GetEventFailed
\r
2539 Std_ReturnType Dem_GetEventFailed(Dem_EventIdType eventId, boolean *eventFailed) /** @req DEM333 */
\r
2541 Std_ReturnType returnCode = E_OK;
\r
2543 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
2545 getEventFailed(eventId, eventFailed);
\r
2549 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTFAILED_ID, DEM_E_UNINIT);
\r
2550 returnCode = E_NOT_OK;
\r
2553 return returnCode;
\r
2558 * Procedure: Dem_GetEventTested
\r
2561 Std_ReturnType Dem_GetEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
2563 Std_ReturnType returnCode = E_OK;
\r
2565 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
2567 getEventTested(eventId, eventTested);
\r
2571 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTTESTED_ID, DEM_E_UNINIT);
\r
2572 returnCode = E_NOT_OK;
\r
2575 return returnCode;
\r
2580 * Procedure: Dem_GetFaultDetectionCounter
\r
2583 Std_ReturnType Dem_GetFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
2585 Std_ReturnType returnCode = E_OK;
\r
2587 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
2589 returnCode = getFaultDetectionCounter(eventId, counter);
\r
2593 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_UNINIT);
\r
2594 returnCode = E_NOT_OK;
\r
2597 return returnCode;
\r
2602 * Procedure: Dem_SetOperationCycleState
\r
2605 Std_ReturnType Dem_SetOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState)
\r
2607 Std_ReturnType returnCode = E_OK;
\r
2609 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
2611 returnCode = setOperationCycleState(operationCycleId, cycleState);
\r
2612 (void)handleAging(operationCycleId, cycleState);
\r
2617 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_UNINIT);
\r
2618 returnCode = E_NOT_OK;
\r
2621 return returnCode;
\r
2626 * Procedure: Dem_GetDTCOfEvent
\r
2629 Std_ReturnType Dem_GetDTCOfEvent(Dem_EventIdType eventId, Dem_DTCKindType dtcKind, uint32* dtcOfEvent)
\r
2631 Std_ReturnType returnCode = E_NO_DTC_AVAILABLE;
\r
2632 const Dem_EventParameterType *eventParam;
\r
2634 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
2636 lookupEventIdParameter(eventId, &eventParam);
\r
2638 if (eventParam != NULL) {
\r
2639 if (checkDtcKind(dtcKind, eventParam)) {
\r
2640 if (eventParam->DTCClassRef != NULL) {
\r
2641 *dtcOfEvent = eventParam->DTCClassRef->DTC; /** @req DEM269 */
\r
2642 returnCode = E_OK;
\r
2647 // Event Id not found
\r
2648 returnCode = E_NOT_OK;
\r
2653 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETDTCOFEVENT_ID, DEM_UNINITIALIZED);
\r
2654 returnCode = E_NOT_OK;
\r
2657 return returnCode;
\r
2661 /********************************************
\r
2662 * Interface BSW-Components <-> DEM (8.3.4) *
\r
2663 ********************************************/
\r
2666 * Procedure: Dem_ReportErrorStatus
\r
2669 void Dem_ReportErrorStatus( Dem_EventIdType eventId, Dem_EventStatusType eventStatus ) /** @req DEM107 *//** @req DEM206 */
\r
2672 switch (demState) {
\r
2673 case DEM_PREINITIALIZED:
\r
2674 // Update status and check if is to be stored
\r
2675 if ((eventStatus == DEM_EVENT_STATUS_PASSED) || (eventStatus == DEM_EVENT_STATUS_FAILED)) {
\r
2676 handlePreInitEvent(eventId, eventStatus); /** @req DEM168 */
\r
2680 case DEM_INITIALIZED:
\r
2681 (void)handleEvent(eventId, eventStatus); /** @req DEM167 */
\r
2684 case DEM_UNINITIALIZED:
\r
2686 // Uninitialized can not do anything
\r
2687 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_REPORTERRORSTATUS_ID, DEM_E_UNINIT);
\r
2691 } // switch (demState)
\r
2694 /*********************************
\r
2695 * Interface DCM <-> DEM (8.3.5) *
\r
2696 *********************************/
\r
2698 * Procedure: Dem_GetDTCStatusAvailabilityMask
\r
2701 Std_ReturnType Dem_GetDTCStatusAvailabilityMask(uint8 *dtcStatusMask) /** @req DEM014 */
\r
2703 *dtcStatusMask = DEM_DTC_STATUS_AVAILABILITY_MASK; // User configuration mask
\r
2704 *dtcStatusMask &= DEM_TEST_FAILED // Mask with supported bits /** @req DEM060 */
\r
2705 | DEM_TEST_FAILED_THIS_OPERATION_CYCLE
\r
2707 | DEM_CONFIRMED_DTC
\r
2708 | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR
\r
2709 | DEM_TEST_FAILED_SINCE_LAST_CLEAR
\r
2710 | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE
\r
2711 // | DEM_WARNING_INDICATOR_REQUESTED TODO: Add support for this bit
\r
2719 * Procedure: Dem_SetDTCFilter
\r
2722 Dem_ReturnSetDTCFilterType Dem_SetDTCFilter(uint8 dtcStatusMask,
\r
2723 Dem_DTCKindType dtcKind,
\r
2724 Dem_DTCOriginType dtcOrigin,
\r
2725 Dem_FilterWithSeverityType filterWithSeverity,
\r
2726 Dem_DTCSeverityType dtcSeverityMask,
\r
2727 Dem_FilterForFDCType filterForFaultDetectionCounter)
\r
2729 Dem_ReturnSetDTCFilterType returnCode = DEM_FILTER_ACCEPTED;
\r
2731 if (demState == DEM_INITIALIZED) {
\r
2732 // Check dtcKind parameter
\r
2733 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
2735 // Check dtcOrigin parameter
\r
2736 VALIDATE_RV((dtcOrigin == DEM_DTC_ORIGIN_SECONDARY_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_PRIMARY_MEMORY)
\r
2737 || (dtcOrigin == DEM_DTC_ORIGIN_PERMANENT_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_MIRROR_MEMORY), DEM_SETDTCFILTER_ID, DEM_E_PARAM_DATA, DEM_WRONG_FILTER);
\r
2739 // Check filterWithSeverity and dtcSeverityMask parameter
\r
2740 VALIDATE_RV(((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
2741 || ((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES)
\r
2742 && (!(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
2744 // Check filterForFaultDetectionCounter parameter
\r
2745 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
2747 // Yes all parameters correct, set the new filters. /** @req DEM057 */
\r
2748 dtcFilter.dtcStatusMask = dtcStatusMask;
\r
2749 dtcFilter.dtcKind = dtcKind;
\r
2750 dtcFilter.dtcOrigin = dtcOrigin;
\r
2751 dtcFilter.filterWithSeverity = filterWithSeverity;
\r
2752 dtcFilter.dtcSeverityMask = dtcSeverityMask;
\r
2753 dtcFilter.filterForFaultDetectionCounter = filterForFaultDetectionCounter;
\r
2754 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
2756 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETDTCFILTER_ID, DEM_E_UNINIT);
\r
2757 returnCode = DEM_WRONG_FILTER;
\r
2760 return returnCode;
\r
2765 * Procedure: Dem_GetStatusOfDTC
\r
2768 Dem_ReturnGetStatusOfDTCType Dem_GetStatusOfDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, Dem_EventStatusExtendedType* status) {
\r
2769 Dem_ReturnGetStatusOfDTCType returnCode = DEM_STATUS_FAILED;
\r
2770 EventStatusRecType *eventRec;
\r
2772 if (demState == DEM_INITIALIZED) {
\r
2773 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2774 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2775 if (checkDtcOrigin(dtcOrigin,eventRec->eventParamRef)) {
\r
2776 *status = eventRec->eventStatusExtended; /** @req DEM059 */
\r
2777 returnCode = DEM_STATUS_OK;
\r
2780 returnCode = DEM_STATUS_WRONG_DTCORIGIN; /** @req DEM171 */
\r
2784 returnCode = DEM_STATUS_WRONG_DTCKIND;
\r
2788 returnCode = DEM_STATUS_WRONG_DTC; /** @req DEM172 */
\r
2791 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETSTATUSOFDTC_ID, DEM_E_UNINIT);
\r
2792 returnCode = DEM_STATUS_FAILED;
\r
2795 return returnCode;
\r
2800 * Procedure: Dem_GetNumberOfFilteredDtc
\r
2803 Dem_ReturnGetNumberOfFilteredDTCType Dem_GetNumberOfFilteredDtc(uint16 *numberOfFilteredDTC) {
\r
2805 uint16 numberOfFaults = 0;
\r
2806 Dem_ReturnGetNumberOfFilteredDTCType returnCode = DEM_NUMBER_OK;
\r
2808 if (demState == DEM_INITIALIZED) {
\r
2809 //Dem_DisableEventStatusUpdate();
\r
2811 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2812 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
2813 if (matchEventWithDtcFilter(&eventStatusBuffer[i])) {
\r
2814 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
2821 //Dem_EnableEventStatusUpdate();
\r
2823 *numberOfFilteredDTC = numberOfFaults; /** @req DEM061 */
\r
2825 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETNUMBEROFFILTEREDDTC_ID, DEM_E_UNINIT);
\r
2826 returnCode = DEM_NUMBER_FAILED;
\r
2829 return returnCode;
\r
2834 * Procedure: Dem_GetNextFilteredDTC
\r
2837 Dem_ReturnGetNextFilteredDTCType Dem_GetNextFilteredDTC(uint32 *dtc, Dem_EventStatusExtendedType *dtcStatus)
\r
2839 Dem_ReturnGetNextFilteredDTCType returnCode = DEM_FILTERED_OK;
\r
2840 boolean dtcFound = FALSE;
\r
2842 if (demState == DEM_INITIALIZED) {
\r
2843 // TODO: This job should be done in an more advanced way according to Dem217
\r
2844 while ((!dtcFound) && (dtcFilter.faultIndex != 0)) {
\r
2845 dtcFilter.faultIndex--;
\r
2846 if (eventStatusBuffer[dtcFilter.faultIndex].eventId != DEM_EVENT_ID_NULL) {
\r
2847 if (matchEventWithDtcFilter(&eventStatusBuffer[dtcFilter.faultIndex])) {
\r
2848 if (eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef != NULL) {
\r
2849 *dtc = eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef->DTC; /** @req DEM216 */
\r
2850 *dtcStatus = eventStatusBuffer[dtcFilter.faultIndex].eventStatusExtended;
\r
2858 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
2859 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
2862 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETNEXTFILTEREDDTC_ID, DEM_E_UNINIT);
\r
2863 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
2866 return returnCode;
\r
2871 * Procedure: Dem_GetTranslationType
\r
2874 Dem_ReturnTypeOfDtcSupportedType Dem_GetTranslationType(void)
\r
2876 return DEM_TYPE_OF_DTC_SUPPORTED; /** @req DEM231 */
\r
2881 * Procedure: Dem_ClearDTC
\r
2884 Dem_ReturnClearDTCType Dem_ClearDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin) /** @req DEM009 *//** @req DEM241 */
\r
2886 Dem_ReturnClearDTCType returnCode = DEM_CLEAR_OK;
\r
2887 Dem_EventIdType eventId;
\r
2888 const Dem_EventParameterType *eventParam;
\r
2891 if (demState == DEM_INITIALIZED) {
\r
2892 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2893 eventId = eventStatusBuffer[i].eventId;
\r
2894 if (eventId != DEM_EVENT_ID_NULL) {
\r
2895 eventParam = eventStatusBuffer[i].eventParamRef;
\r
2896 if (eventParam != NULL) {
\r
2897 //lint --e(506) PC-Lint exception Misra 13.7, 14.1 Allow configuration variables in boolean expression
\r
2898 //lint --e(774) PC-Lint exception Related to MISRA 13.7
\r
2899 if ((DEM_CLEAR_ALL_EVENTS == STD_ON) || (eventParam->DTCClassRef != NULL)) {
\r
2900 if (checkDtcKind(dtcKind, eventParam)) {
\r
2901 if (checkDtcGroup(dtc, eventParam)) {
\r
2902 boolean dtcOriginFound = FALSE;
\r
2903 for (j = 0; (j < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound) ; j++){
\r
2904 dtcOriginFound =(eventParam->EventClass->EventDestination[j] == dtcOrigin);
\r
2906 if (dtcOriginFound) {
\r
2907 switch (dtcOrigin)
\r
2909 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2910 /** @req DEM077 */
\r
2911 deleteEventPriMem(eventParam);
\r
2912 deleteFreezeFrameDataPriMem(eventParam);
\r
2913 deleteExtendedDataPriMem(eventParam);
\r
2914 resetEventStatusRec(eventParam);
\r
2915 storeFreezeFrameDataPerMem();
\r
2918 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2922 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2923 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2924 // Not yet supported
\r
2925 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2926 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2929 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2938 // Fatal error, no event parameters found for the stored event!
\r
2939 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNEXPECTED_EXECUTION);
\r
2944 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNINIT);
\r
2945 returnCode = DEM_CLEAR_FAILED;
\r
2948 return returnCode;
\r
2953 * Procedure: Dem_DisableDTCStorage
\r
2956 Dem_ReturnControlDTCStorageType Dem_DisableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind) /** @req DEM035 */
\r
2958 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2960 if (demState == DEM_INITIALIZED) {
\r
2961 // Check dtcGroup parameter
\r
2962 if (dtcGroup == DEM_DTC_GROUP_ALL_DTCS) {
\r
2963 // Check dtcKind parameter
\r
2964 if ((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS)) {
\r
2965 /** @req DEM079 */
\r
2966 disableDtcStorage.dtcGroup = dtcGroup;
\r
2967 disableDtcStorage.dtcKind = dtcKind;
\r
2968 disableDtcStorage.storageDisabled = TRUE;
\r
2970 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2973 returnCode = DEM_CONTROL_DTC_WRONG_DTCGROUP;
\r
2976 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_DISABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
2977 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2980 return returnCode;
\r
2985 * Procedure: Dem_EnableDTCStorage
\r
2988 Dem_ReturnControlDTCStorageType Dem_EnableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind)
\r
2990 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2992 if (demState == DEM_INITIALIZED) {
\r
2993 // TODO: Behavior is not defined if group or kind do not match active settings, therefore the filter is just switched off.
\r
2994 (void)dtcGroup; (void)dtcKind; // Just to make get rid of PC-Lint warnings
\r
2995 disableDtcStorage.storageDisabled = FALSE; /** @req DEM080 */
\r
2997 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_ENABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
2998 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
3001 return returnCode;
\r
3005 * Procedure: Dem_GetExtendedDataRecordByDTC
\r
3008 Dem_ReturnGetExtendedDataRecordByDTCType Dem_GetExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint8 *destBuffer, uint16 *bufSize)
\r
3010 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_RECORD_WRONG_DTC;
\r
3011 EventStatusRecType *eventRec;
\r
3012 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
3013 ExtDataRecType *extData;
\r
3014 uint16 posInExtData = 0;
\r
3016 if (demState == DEM_INITIALIZED) {
\r
3017 if (lookupDtcEvent(dtc, &eventRec)) {
\r
3018 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
3019 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
3020 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
3021 if (*bufSize >= extendedDataRecordClass->DataSize) {
\r
3022 switch (dtcOrigin)
\r
3024 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
3025 if (lookupExtendedDataPriMem(eventRec->eventId, &extData)) {
\r
3026 // Yes all conditions met, copy the extended data record to destination buffer.
\r
3027 memcpy(destBuffer, &extData->data[posInExtData], extendedDataRecordClass->DataSize); /** @req DEM075 */
\r
3028 *bufSize = extendedDataRecordClass->DataSize;
\r
3029 returnCode = DEM_RECORD_OK;
\r
3032 // The record number is legal but no record was found for the DTC
\r
3034 returnCode = DEM_RECORD_OK;
\r
3038 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
3039 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
3040 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
3041 // Not yet supported
\r
3042 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
3043 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
3046 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
3051 returnCode = DEM_RECORD_BUFFERSIZE;
\r
3055 returnCode = DEM_RECORD_NUMBER;
\r
3059 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
3063 returnCode = DEM_RECORD_DTCKIND;
\r
3067 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
3068 returnCode = DEM_RECORD_WRONG_DTC;
\r
3071 return returnCode;
\r
3076 * Procedure: Dem_GetSizeOfExtendedDataRecordByDTC
\r
3079 Dem_ReturnGetSizeOfExtendedDataRecordByDTCType Dem_GetSizeOfExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint16 *sizeOfExtendedDataRecord)
\r
3081 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
3082 EventStatusRecType *eventRec;
\r
3083 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
3084 uint16 posInExtData;
\r
3086 if (demState == DEM_INITIALIZED) {
\r
3087 if (lookupDtcEvent(dtc, &eventRec)) {
\r
3088 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
3089 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
3090 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
3091 *sizeOfExtendedDataRecord = extendedDataRecordClass->DataSize; /** @req DEM076 */
\r
3092 returnCode = DEM_GET_SIZEOFEDRBYDTC_OK;
\r
3095 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_RNUM;
\r
3099 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCOR;
\r
3103 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCKI;
\r
3107 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETSIZEOFEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
3108 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
3111 return returnCode;
\r
3115 * Procedure: Dem_GetFreezeFrameDataByDTC
\r
3118 /** @req DEM236 */
\r
3119 Dem_ReturnGetFreezeFrameDataByDTCType Dem_GetFreezeFrameDataByDTC(uint32 dtc,Dem_DTCKindType dtcKind,Dem_DTCOriginType dtcOrigin,uint8 recordNumber,uint8* destBuffer,uint8* bufSize)
\r
3121 Dem_ReturnGetFreezeFrameDataByDTCType returnCode = DEM_GET_FFDATABYDTC_WRONG_DTC;
\r
3122 EventStatusRecType *eventRec;
\r
3123 Dem_FreezeFrameClassType const *FFDataRecordClass = NULL;
\r
3124 FreezeFrameRecType *freezeframe;
\r
3125 uint16 FFDataSize = 0;
\r
3127 if (demState == DEM_INITIALIZED) {
\r
3128 if (lookupDtcEvent(dtc, &eventRec)) {
\r
3129 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
3130 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
3131 if (lookupFreezeFrameDataRecNumParam(recordNumber, eventRec->eventParamRef, &FFDataRecordClass)) {
\r
3132 if(lookupFreezeFrameDataSize(recordNumber, &FFDataRecordClass, &FFDataSize)){
\r
3133 if (*bufSize >= FFDataSize) {
\r
3134 switch (dtcOrigin)
\r
3136 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
3137 if (lookupFreezeFrameDataPriMem(eventRec->eventId,recordNumber, &freezeframe)) {
\r
3138 memcpy(destBuffer, freezeframe->data, FFDataSize); /** @req DEM071 */
\r
3139 *bufSize = FFDataSize;
\r
3140 returnCode = DEM_GET_FFDATABYDTC_OK;
\r
3144 returnCode = DEM_GET_FFDATABYDTC_OK;
\r
3148 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
3149 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
3150 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
3151 // Not yet supported
\r
3152 returnCode = DEM_GET_FFDATABYDTC_WRONG_DTCORIGIN;
\r
3153 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFREEZEFRAMEDATARECORDBYDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
3156 returnCode = DEM_GET_FFDATABYDTC_WRONG_DTCORIGIN;
\r
3161 returnCode = DEM_GET_FFDATABYDTC_BUFFERSIZE;
\r
3165 returnCode = DEM_GET_FFDATABYDTC_BUFFERSIZE;
\r
3169 returnCode = DEM_GET_FFDATABYDTC_RECORDNUMBER;
\r
3173 returnCode = DEM_GET_FFDATABYDTC_WRONG_DTCORIGIN;
\r
3177 returnCode = DEM_GET_FFDATABYDTC_WRONG_DTCKIND;
\r
3181 returnCode = DEM_GET_FFDATABYDTC_WRONG_DTC;
\r
3185 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFREEZEFRAMEDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
3186 returnCode = DEM_GET_ID_PENDING;
\r
3189 return returnCode;
\r
3195 * Procedure: Dem_GetFreezeFrameDataIdentifierByDTC
\r
3198 Dem_GetFreezeFameDataIdentifierByDTCType Dem_GetFreezeFrameDataIdentifierByDTC(uint32 dtc,
\r
3199 Dem_DTCKindType dtcKind,
\r
3200 Dem_DTCOriginType dtcOrigin,
\r
3201 uint8 recordNumber,
\r
3203 const uint16** dataId )/** @req DEM237 */
\r
3205 Dem_GetFreezeFameDataIdentifierByDTCType returnCode = DEM_GET_ID_WRONG_FF_TYPE;
\r
3206 Dem_FreezeFrameClassType const *FFDataRecordClass = NULL;
\r
3207 EventStatusRecType *eventRec;
\r
3210 if (demState == DEM_INITIALIZED) {
\r
3211 if (lookupDtcEvent(dtc, &eventRec)) {
\r
3212 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
3213 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
3214 if (lookupFreezeFrameDataRecNumParam(recordNumber, eventRec->eventParamRef, &FFDataRecordClass)) {
\r
3215 if(FFDataRecordClass->FFIdClassRef != NULL){
\r
3216 for(i=0; (i < DEM_MAX_NR_OF_RECORDS_IN_FREEZEFRAME_DATA) && (!(FFDataRecordClass->FFIdClassRef[i].Arc_EOL)); i++){
\r
3217 if(didNum < *arraySize){
\r
3218 dataId[didNum] = &FFDataRecordClass->FFIdClassRef[i].DidIdentifier;/** @req DEM073 */
\r
3220 returnCode = DEM_GET_ID_OK;
\r
3222 returnCode = DEM_GET_ID_WRONG_FF_TYPE;
\r
3225 *arraySize = didNum;
\r
3230 returnCode = DEM_GET_ID_WRONG_FF_TYPE;
\r
3234 returnCode = DEM_GET_ID_WRONG_DTCORIGIN;
\r
3238 returnCode = DEM_GET_ID_WRONG_DTCKIND;
\r
3242 returnCode = DEM_GET_ID_WRONG_DTC;
\r
3247 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFREEZEFRAMEDATAIDENTIFIERBYDTC_ID, DEM_E_UNINIT);
\r
3250 return returnCode;
\r
3255 * Procedure: Dem_GetSizeOfFreezeFrame
\r
3258 /** @req DEM238 */
\r
3259 Dem_ReturnGetSizeOfFreezeFrameType Dem_GetSizeOfFreezeFrame(uint32 dtc,Dem_DTCKindType dtcKind,Dem_DTCOriginType dtcOrigin,uint8 recordNumber,uint16* sizeOfFreezeFrame)
\r
3261 Dem_ReturnGetSizeOfFreezeFrameType returnCode = DEM_GET_SIZEOFFF_PENDING;
\r
3262 Dem_FreezeFrameClassType const *FFDataRecordClass = NULL;
\r
3263 Std_ReturnType callbackReturnCode;
\r
3264 EventStatusRecType *eventRec;
\r
3265 uint16 dataSize = 0;
\r
3268 if (demState == DEM_INITIALIZED) {
\r
3269 if (lookupDtcEvent(dtc, &eventRec)) {
\r
3270 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
3271 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
3272 if (lookupFreezeFrameDataRecNumParam(recordNumber, eventRec->eventParamRef, &FFDataRecordClass)) {
\r
3273 if(FFDataRecordClass->FFIdClassRef != NULL){
\r
3274 for(i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_FREEZEFRAME_DATA) && (!(FFDataRecordClass->FFIdClassRef[i].Arc_EOL)); i++){
\r
3275 /* read out the did size */
\r
3276 if(FFDataRecordClass->FFIdClassRef[i].DidReadDataLengthFnc != NULL){
\r
3277 callbackReturnCode = FFDataRecordClass->FFIdClassRef[i].DidReadDataLengthFnc(&dataSize);
\r
3278 if(callbackReturnCode != E_OK){
\r
3279 return (returnCode = DEM_GET_SIZEOFFF_PENDING);
\r
3283 dataSize = FFDataRecordClass->FFIdClassRef[i].PidOrDidSize;
\r
3285 *sizeOfFreezeFrame += dataSize+DEM_DID_IDENTIFIER_SIZE_OF_BYTES;/** @req DEM074 */
\r
3286 returnCode = DEM_GET_SIZEOFFF_OK;
\r
3291 returnCode = DEM_GET_SIZEOFFF_WRONG_RNUM;
\r
3295 returnCode = DEM_GET_SIZEOFFF_WRONG_DTCOR;
\r
3299 returnCode = DEM_GET_SIZEOFFF_WRONG_DTCKIND;
\r
3303 returnCode = DEM_GET_SIZEOFFF_WRONG_DTC;
\r
3308 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFREEZEFRAMEDATAIDENTIFIERBYDTC_ID, DEM_E_UNINIT);
\r
3309 returnCode = DEM_GET_SIZEOFFF_PENDING;
\r
3312 return returnCode;
\r
3318 #ifdef DEM_UNIT_TEST
\r
3319 void getFFDataPreInit(FreezeFrameRecType **buf)
\r
3321 *buf = &preInitFreezeFrameBuffer[0];
\r
3324 void getPriMemFFBufPtr(FreezeFrameRecType **buf)
\r
3326 *buf = &priMemFreezeFrameBuffer[0];
\r
3330 uint32 getCurTimeStamp()
\r
3332 return FF_TimeStamp;
\r
3335 void getPriMemEventRecBufPtr(EventStatusRecType **buf)
\r
3337 *buf = &eventStatusBuffer[0];
\r
3341 void getPriMemAgingBufPtr(HealingRecType **buf)
\r
3343 *buf = &priMemAgingBuffer[0];
\r
3352 /***********************************
\r
3353 * OBD-specific Interfaces (8.3.6) *
\r
3354 ***********************************/
\r