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
61 #define DEBOUNCE_FDC_TEST_FAILED 127
\r
62 #define DEBOUNCE_FDC_TEST_PASSED -128
\r
64 #if ( DEM_DEV_ERROR_DETECT == STD_ON )
\r
67 #define VALIDATE_RV(_exp,_api,_err,_rv ) \
\r
69 Det_ReportError(MODULE_ID_DEM, 0, _api, _err); \
\r
73 #define VALIDATE_NO_RV(_exp,_api,_err ) \
\r
75 Det_ReportError(MODULE_ID_DEM, 0, _api, _err); \
\r
78 #define DET_REPORTERROR(_x,_y,_z,_q) Det_ReportError(_x, _y, _z, _q)
\r
81 #define VALIDATE_RV(_exp,_api,_err,_rv )
\r
82 #define VALIDATE_NO_RV(_exp,_api,_err )
\r
83 #define DET_REPORTERROR(_x,_y,_z,_q)
\r
86 #if (DEM_OBD_SUPPORT == STD_ON)
\r
87 #error "DEM_OBD_SUPPORT is set to STD_ON, this is not supported by the code."
\r
90 #if (DEM_PTO_SUPPORT == STD_ON)
\r
91 #error "DEM_PTO_SUPPORT is set to STD_ON, this is not supported by the code."
\r
94 #if (DEM_TYPE_OF_DTC_SUPPORTED != 0x01)
\r
95 #error "DEM_TYPE_OF_DTC_SUPPORTED is not set to 1 (ISO14229-1), only ISO14229-1 is currently supported by the code."
\r
103 typedef uint16 ChecksumType;
\r
107 Dem_EventStatusExtendedType dtcStatusMask;
\r
108 Dem_DTCKindType dtcKind;
\r
109 Dem_DTCOriginType dtcOrigin;
\r
110 Dem_FilterWithSeverityType filterWithSeverity;
\r
111 Dem_DTCSeverityType dtcSeverityMask;
\r
112 Dem_FilterForFDCType filterForFaultDetectionCounter;
\r
116 // DisableDtcStorageType
\r
118 boolean storageDisabled;
\r
119 Dem_DTCGroupType dtcGroup;
\r
120 Dem_DTCKindType dtcKind;
\r
121 } DisableDtcStorageType;
\r
123 // For keeping track of the events status
\r
125 Dem_EventIdType eventId;
\r
126 const Dem_EventParameterType *eventParamRef;
\r
127 sint8 faultDetectionCounter;
\r
128 uint16 occurrence; /** @req DEM011 */
\r
129 Dem_EventStatusExtendedType eventStatusExtended; /** @req DEM006 */
\r
130 boolean errorStatusChanged;
\r
131 } EventStatusRecType;
\r
134 // Types for storing different event data on event memory
\r
136 Dem_EventIdType eventId;
\r
138 ChecksumType checksum;
\r
141 //lint -save -e43 //PC-Lint misunderstanding: Array of size 0 is OK.
\r
143 Dem_EventIdType eventId;
\r
146 sint8 data[DEM_MAX_SIZE_FF_DATA];
\r
147 ChecksumType checksum;
\r
148 } FreezeFrameRecType;
\r
152 Dem_EventIdType eventId;
\r
154 uint8 data[DEM_MAX_SIZE_EXT_DATA];
\r
155 ChecksumType checksum;
\r
162 DEM_UNINITIALIZED = 0,
\r
163 DEM_PREINITIALIZED,
\r
165 } Dem_StateType; /** @req DEM169 */
\r
168 static Dem_StateType demState = DEM_UNINITIALIZED;
\r
170 // Help pointer to configuration set
\r
171 static const Dem_ConfigSetType *configSet;
\r
174 * Allocation of DTC filter parameters
\r
176 static DtcFilterType dtcFilter;
\r
179 * Allocation of Disable/Enable DTC storage parameters
\r
181 static DisableDtcStorageType disableDtcStorage;
\r
184 * Allocation of operation cycle state list
\r
186 static Dem_OperationCycleStateType operationCycleStateList[DEM_OPERATION_CYCLE_ID_ENDMARK];
\r
189 * Allocation of local event status buffer
\r
191 static EventStatusRecType eventStatusBuffer[DEM_MAX_NUMBER_EVENT];
\r
194 * Allocation of pre-init event memory (used between pre-init and init)
\r
197 static FreezeFrameRecType preInitFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRE_INIT];
\r
198 static ExtDataRecType preInitExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRE_INIT];
\r
201 * Allocation of primary event memory ramlog (after init) in uninitialized memory
\r
204 static EventRecType priMemEventBuffer[DEM_MAX_NUMBER_EVENT_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
205 static FreezeFrameRecType priMemFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
206 static ExtDataRecType priMemExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
210 * Procedure: zeroPriMemBuffers
\r
211 * Description: Fill the primary buffers with zeroes
\r
214 //lint -e84 //PC-Lint exception, size 0 is OK.
\r
215 //lint -e957 PC-Lint exception - Used only by DemTest
\r
216 void demZeroPriMemBuffers(void)
\r
218 memset(priMemEventBuffer, 0, sizeof(priMemEventBuffer));
\r
219 memset(priMemFreezeFrameBuffer, 0, sizeof(priMemFreezeFrameBuffer));
\r
220 memset(priMemExtDataBuffer, 0, sizeof(priMemExtDataBuffer));
\r
225 * Procedure: calcChecksum
\r
226 * Description: Calculate checksum over *data to *(data+nrOfBytes-1) area
\r
228 static ChecksumType calcChecksum(void *data, uint16 nrOfBytes)
\r
231 uint8 *byte = (uint8*)data;
\r
232 ChecksumType sum = 0;
\r
234 for (i = 0; i < nrOfBytes; i++) {
\r
243 * Procedure: checkDtcKind
\r
244 * Description: Return TRUE if "dtcKind" match the events DTCKind or "dtcKind"
\r
245 * is "DEM_DTC_KIND_ALL_DTCS" otherwise FALSE.
\r
247 static boolean checkDtcKind(Dem_DTCKindType dtcKind, const Dem_EventParameterType *eventParam)
\r
249 boolean result = FALSE;
\r
251 if (dtcKind == DEM_DTC_KIND_ALL_DTCS) {
\r
255 if (eventParam->DTCClassRef != NULL) {
\r
256 if (eventParam->DTCClassRef->DTCKind == dtcKind) {
\r
266 * Procedure: checkDtcGroup
\r
267 * Description: Return TRUE if "dtc" match the events DTC or "dtc" is
\r
268 * "DEM_DTC_GROUP_ALL_DTCS" otherwise FALSE.
\r
270 static boolean checkDtcGroup(uint32 dtc, const Dem_EventParameterType *eventParam)
\r
272 boolean result = FALSE;
\r
274 if (dtc == DEM_DTC_GROUP_ALL_DTCS) {
\r
278 if (eventParam->DTCClassRef != NULL) {
\r
279 if (eventParam->DTCClassRef->DTC == dtc) {
\r
289 * Procedure: checkDtcOrigin
\r
290 * Description: Return TRUE if "dtcOrigin" match any of the events DTCOrigin otherwise FALSE.
\r
292 static boolean checkDtcOrigin(Dem_DTCOriginType dtcOrigin, const Dem_EventParameterType *eventParam)
\r
294 boolean result = FALSE;
\r
295 boolean dtcOriginFound = FALSE;
\r
298 for (i = 0;(i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound); i++){
\r
299 dtcOriginFound = (eventParam->EventClass->EventDestination[i] == dtcOrigin);
\r
302 if (dtcOriginFound) {
\r
310 * Procedure: checkDtcSeverityMask
\r
311 * Description: Return TRUE if "dtcSeverityMask" match any of the events DTC severity otherwise FALSE.
\r
313 // PC-Lint (715 etc): Remove errors until function is filled.
\r
314 //lint -e{715} Symbol not referenced
\r
315 static boolean checkDtcSeverityMask(Dem_DTCSeverityType dtcSeverityMask, const Dem_EventParameterType *eventParam)
\r
317 boolean result = TRUE;
\r
319 // TODO: This function is optional, may be implemented here.
\r
326 * Procedure: checkDtcFaultDetectionCounterMask
\r
327 * Description: TBD.
\r
329 // PC-Lint (715 etc): Remove errors until function is filled.
\r
330 //lint -e{715} Symbol not referenced
\r
331 static boolean checkDtcFaultDetectionCounter(const Dem_EventParameterType *eventParam)
\r
333 boolean result = TRUE;
\r
335 // TODO: Not implemented yet.
\r
342 * Procedure: lookupEventStatusRec
\r
343 * Description: Returns the pointer to event id parameters of "eventId" in "*eventStatusBuffer",
\r
344 * if not found NULL is returned.
\r
346 static void lookupEventStatusRec(Dem_EventIdType eventId, EventStatusRecType **const eventStatusRec)
\r
349 boolean eventIdFound = FALSE;
\r
351 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!eventIdFound); i++) {
\r
352 eventIdFound = (eventStatusBuffer[i].eventId == eventId);
\r
355 if (eventIdFound) {
\r
356 *eventStatusRec = &eventStatusBuffer[i-1];
\r
358 *eventStatusRec = NULL;
\r
364 * Procedure: lookupEventIdParameter
\r
365 * Description: Returns the pointer to event id parameters of "eventId" in "*eventIdParam",
\r
366 * if not found NULL is returned.
\r
368 static void lookupEventIdParameter(Dem_EventIdType eventId, const Dem_EventParameterType **const eventIdParam)
\r
370 const Dem_EventParameterType *EventIdParamList = configSet->EventParameter;
\r
372 // Lookup the correct event id parameters
\r
374 while ((EventIdParamList[i].EventID != eventId) && (!EventIdParamList[i].Arc_EOL)) {
\r
378 if (!EventIdParamList[i].Arc_EOL) {
\r
379 *eventIdParam = &EventIdParamList[i];
\r
381 *eventIdParam = NULL;
\r
387 * Procedure: preDebounceNone
\r
388 * Description: Returns the result of the debouncing.
\r
390 static Dem_EventStatusType preDebounceNone(const Dem_EventStatusType reportedStatus, const EventStatusRecType* statusRecord) {
\r
391 Dem_EventStatusType returnCode;
\r
392 (void)statusRecord; // Just to get rid of PC-Lint warnings
\r
394 switch (reportedStatus) {
\r
395 case DEM_EVENT_STATUS_FAILED: /** @req DEM091.NoneFailed */
\r
396 case DEM_EVENT_STATUS_PASSED: /** @req DEM091.NonePassed */
\r
397 // Already debounced, do nothing.
\r
401 // TODO: What to do with PREFAIL and PREPASSED on no debouncing?
\r
402 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_NONE_ID, DEM_E_PARAM_DATA);
\r
406 returnCode = reportedStatus;
\r
412 * Procedure: preDebounceCounterBased
\r
413 * Description: Returns the result of the debouncing.
\r
415 static Dem_EventStatusType preDebounceCounterBased(Dem_EventStatusType reportedStatus, EventStatusRecType* statusRecord) {
\r
416 Dem_EventStatusType returnCode;
\r
417 const Dem_PreDebounceCounterBasedType* pdVars = statusRecord->eventParamRef->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceCounterBased;
\r
419 switch (reportedStatus) {
\r
420 case DEM_EVENT_STATUS_PREFAILED:
\r
421 if (statusRecord->faultDetectionCounter < DEBOUNCE_FDC_TEST_FAILED) {
\r
422 if ((pdVars->JumpUp) && (statusRecord->faultDetectionCounter < 0)) {
\r
423 statusRecord->faultDetectionCounter = 0;
\r
425 if (((sint16)statusRecord->faultDetectionCounter + (sint8)pdVars->CountInStepSize) < DEBOUNCE_FDC_TEST_FAILED) {
\r
426 statusRecord->faultDetectionCounter += (sint8)pdVars->CountInStepSize;
\r
428 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED;
\r
434 case DEM_EVENT_STATUS_PREPASSED:
\r
435 if (statusRecord->faultDetectionCounter > DEBOUNCE_FDC_TEST_PASSED) {
\r
436 if ((pdVars->JumpDown) && (statusRecord->faultDetectionCounter > 0)) {
\r
437 statusRecord->faultDetectionCounter = 0;
\r
439 if (((sint16)statusRecord->faultDetectionCounter - (sint8)pdVars->CountOutStepSize) > DEBOUNCE_FDC_TEST_PASSED) {
\r
440 statusRecord->faultDetectionCounter -= (sint8)pdVars->CountOutStepSize;
\r
442 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED;
\r
448 case DEM_EVENT_STATUS_FAILED:
\r
449 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED; /** @req DEM091.CounterFailed */
\r
452 case DEM_EVENT_STATUS_PASSED:
\r
453 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED; /** @req DEM091.CounterPassed */
\r
457 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_COUNTER_BASED_ID, DEM_E_PARAM_DATA);
\r
462 switch (statusRecord->faultDetectionCounter) {
\r
463 case DEBOUNCE_FDC_TEST_FAILED:
\r
464 returnCode = DEM_EVENT_STATUS_FAILED;
\r
467 case DEBOUNCE_FDC_TEST_PASSED:
\r
468 returnCode = DEM_EVENT_STATUS_PASSED;
\r
472 returnCode = reportedStatus;
\r
481 * Procedure: updateEventStatusRec
\r
482 * Description: Update the status of "eventId", if not exist and "createIfNotExist" is
\r
483 * true a new record is created
\r
485 static void updateEventStatusRec(const Dem_EventParameterType *eventParam, Dem_EventStatusType eventStatus, boolean createIfNotExist, EventStatusRecType *eventStatusRec)
\r
487 EventStatusRecType *eventStatusRecPtr;
\r
492 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
494 if ((eventStatusRecPtr == NULL) && (createIfNotExist)) {
\r
495 // Search for free position
\r
496 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
498 if (eventStatusRecPtr != NULL) {
\r
499 // Create new event record
\r
500 eventStatusRecPtr->eventId = eventParam->EventID;
\r
501 eventStatusRecPtr->eventParamRef = eventParam;
\r
502 eventStatusRecPtr->faultDetectionCounter = 0;
\r
503 eventStatusRecPtr->occurrence = 0;
\r
504 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
505 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
508 // Error: Event status buffer full
\r
509 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
514 if (eventStatusRecPtr != NULL) {
\r
515 // Handle debouncing
\r
516 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
517 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName) { /** @req DEM004 */ /** @req DEM342 */
\r
518 case DEM_NO_PRE_DEBOUNCE:
\r
519 eventStatus = preDebounceNone(eventStatus, eventStatusRecPtr);
\r
522 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
523 eventStatus = preDebounceCounterBased(eventStatus, eventStatusRecPtr);
\r
527 // Don't know how to handle this.
\r
528 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
533 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
535 // Check test failed
\r
536 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
537 if (!(eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED)) {
\r
538 eventStatusRecPtr->occurrence++;
\r
539 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
541 /** @req DEM036 */ /** @req DEM379.PendingSet */
\r
542 eventStatusRecPtr->eventStatusExtended |= (DEM_TEST_FAILED | DEM_TEST_FAILED_THIS_OPERATION_CYCLE | DEM_TEST_FAILED_SINCE_LAST_CLEAR | DEM_PENDING_DTC);
\r
543 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
546 // Check test passed
\r
547 if (eventStatus == DEM_EVENT_STATUS_PASSED) {
\r
548 if (eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED) {
\r
549 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
552 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED;
\r
553 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
557 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
560 // Copy an empty record to return data
\r
561 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
562 eventStatusRec->faultDetectionCounter = 0;
\r
563 eventStatusRec->occurrence = 0;
\r
564 eventStatusRec->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
565 eventStatusRec->errorStatusChanged = FALSE;
\r
568 Irq_Restore(state);
\r
573 * Procedure: mergeEventStatusRec
\r
574 * Description: Update the occurrence counter of status, if not exist a new record is created
\r
576 static void mergeEventStatusRec(const EventRecType *eventRec)
\r
578 EventStatusRecType *eventStatusRecPtr;
\r
583 lookupEventStatusRec(eventRec->eventId, &eventStatusRecPtr);
\r
585 if (eventStatusRecPtr != NULL) {
\r
586 // Update occurrence counter, rest of pre init state is kept.
\r
587 eventStatusRecPtr->occurrence += eventRec->occurrence;
\r
591 // Search for free position
\r
592 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
594 if (eventStatusRecPtr != NULL) {
\r
595 // Create new event, from stored event
\r
596 eventStatusRecPtr->eventId = eventRec->eventId;
\r
597 lookupEventIdParameter(eventRec->eventId, &eventStatusRecPtr->eventParamRef);
\r
598 eventStatusRecPtr->faultDetectionCounter = 0;
\r
599 eventStatusRecPtr->occurrence = eventRec->occurrence;
\r
600 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
601 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
604 // Error: Event status buffer full
\r
605 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_MERGE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
609 Irq_Restore(state);
\r
614 * Procedure: deleteEventStatusRec
\r
615 * Description: Delete the status record of "eventParam->eventId" from "eventStatusBuffer".
\r
617 static void deleteEventStatusRec(const Dem_EventParameterType *eventParam)
\r
619 EventStatusRecType *eventStatusRecPtr;
\r
624 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
626 if (eventStatusRecPtr != NULL) {
\r
627 // Delete event record
\r
628 memset(eventStatusRecPtr, 0, sizeof(EventStatusRecType));
\r
631 Irq_Restore(state);
\r
636 * Procedure: getEventStatusRec
\r
637 * Description: Returns the status record of "eventId" in "eventStatusRec"
\r
639 static void getEventStatusRec(Dem_EventIdType eventId, EventStatusRecType *eventStatusRec)
\r
641 EventStatusRecType *eventStatusRecPtr;
\r
644 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
646 if (eventStatusRecPtr != NULL) {
\r
648 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
651 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
657 * Procedure: lookupDtcEvent
\r
658 * Description: Returns TRUE if the DTC was found and "eventStatusRec" points
\r
659 * to the event record found.
\r
661 static boolean lookupDtcEvent(uint32 dtc, EventStatusRecType **eventStatusRec)
\r
663 boolean dtcFound = FALSE;
\r
666 *eventStatusRec = NULL;
\r
668 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!dtcFound); i++) {
\r
669 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
670 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
673 if (eventStatusBuffer[i].eventParamRef->DTCClassRef->DTC == dtc) {
\r
674 *eventStatusRec = &eventStatusBuffer[i];
\r
686 * Procedure: matchEventWithDtcFilter
\r
687 * Description: Returns TRUE if the event pointed by "event" fulfill
\r
688 * the "dtcFilter" global filter settings.
\r
690 static boolean matchEventWithDtcFilter(const EventStatusRecType *eventRec)
\r
692 boolean dtcMatch = FALSE;
\r
695 if ((dtcFilter.dtcStatusMask == DEM_DTC_STATUS_MASK_ALL) || (eventRec->eventStatusExtended & dtcFilter.dtcStatusMask)) {
\r
696 if (eventRec->eventParamRef != NULL) {
\r
699 if (checkDtcKind(dtcFilter.dtcKind, eventRec->eventParamRef)) {
\r
702 if (checkDtcOrigin(dtcFilter.dtcOrigin, eventRec->eventParamRef)) {
\r
705 if ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
706 || ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES) && (checkDtcSeverityMask(dtcFilter.dtcSeverityMask, eventRec->eventParamRef)))) {
\r
708 // Check fault detection counter
\r
709 if ((dtcFilter.filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO)
\r
710 || ((dtcFilter.filterWithSeverity == DEM_FILTER_FOR_FDC_YES) && (checkDtcFaultDetectionCounter(eventRec->eventParamRef)))) {
\r
723 // PC-Lint (715 etc): Remove errors until function is filled.
\r
724 //lint -e{715} Symbol not referenced
\r
725 static void getFreezeFrameData(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
728 freezeFrame->eventId = DEM_EVENT_ID_NULL; // Not supported yet
\r
732 // PC-Lint (715 etc): Remove errors until function is filled.
\r
733 //lint -e{715} Symbol not referenced
\r
734 static void storeFreezeFrameDataPreInit(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
740 // PC-Lint (715 etc): Remove errors until function is filled.
\r
741 //lint -e{715} Symbol not referenced
\r
742 static void updateFreezeFrameOccurrencePreInit(const EventRecType *EventBuffer)
\r
749 * Procedure: getExtendedData
\r
750 * Description: Collects the extended data according to "eventParam" and return it in "extData",
\r
751 * if not found eventId is set to DEM_EVENT_ID_NULL.
\r
753 static void getExtendedData(const Dem_EventParameterType *eventParam, ExtDataRecType *extData)
\r
755 Std_ReturnType callbackReturnCode;
\r
757 uint16 storeIndex = 0;
\r
760 // Clear ext data record
\r
761 memset(extData, 0, sizeof(ExtDataRecType));
\r
763 // Check if any pointer to extended data class
\r
764 if (eventParam->ExtendedDataClassRef != NULL) {
\r
765 // Request extended data and copy it to the buffer
\r
766 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL); i++) {
\r
767 recordSize = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
768 if ((storeIndex + recordSize) <= DEM_MAX_SIZE_EXT_DATA) {
\r
769 callbackReturnCode = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->CallbackGetExtDataRecord(&extData->data[storeIndex]); /** @req DEM282 */
\r
770 if (callbackReturnCode != E_OK) {
\r
771 // Callback data currently not available, clear space.
\r
772 memset(&extData->data[storeIndex], 0xFF, recordSize);
\r
774 storeIndex += recordSize;
\r
777 // Error: Size of extended data record is bigger than reserved space.
\r
778 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GET_EXTENDED_DATA_ID, DEM_E_EXT_DATA_TOO_BIG);
\r
779 break; // Break the loop
\r
784 // Check if any data has been stored
\r
785 if (storeIndex != 0) {
\r
786 extData->eventId = eventParam->EventID;
\r
787 extData->dataSize = storeIndex;
\r
788 extData->checksum = calcChecksum(extData, sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
791 extData->eventId = DEM_EVENT_ID_NULL;
\r
792 extData->dataSize = storeIndex;
\r
793 extData->checksum = 0;
\r
799 * Procedure: storeExtendedDataPreInit
\r
800 * Description: Store the extended data pointed by "extendedData" to the "preInitExtDataBuffer",
\r
801 * if non existent a new entry is created.
\r
803 static void storeExtendedDataPreInit(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
805 boolean eventIdFound = FALSE;
\r
806 boolean eventIdFreePositionFound=FALSE;
\r
811 // Check if already stored
\r
812 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) && (!eventIdFound); i++){
\r
813 eventIdFound = (preInitExtDataBuffer[i].eventId == eventParam->EventID);
\r
817 // Yes, overwrite existing
\r
818 memcpy(&preInitExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
821 // No, lookup first free position
\r
822 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) && (!eventIdFreePositionFound); i++){
\r
823 if(preInitExtDataBuffer[i].eventId ==0){
\r
824 eventIdFreePositionFound=TRUE;
\r
828 if (eventIdFreePositionFound) {
\r
829 memcpy(&preInitExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
832 // Error: Pre init extended data buffer full
\r
833 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRE_INIT_ID, DEM_E_PRE_INIT_EXT_DATA_BUFF_FULL);
\r
837 Irq_Restore(state);
\r
841 * Procedure: storeEventPriMem
\r
842 * Description: Store the event data of "eventStatus->eventId" in "priMemEventBuffer",
\r
843 * if non existent a new entry is created.
\r
845 static void storeEventPriMem(const Dem_EventParameterType *eventParam, const EventStatusRecType *eventStatus)
\r
847 boolean eventIdFound = FALSE;
\r
848 boolean eventIdFreePositionFound=FALSE;
\r
853 (void)*eventParam; // Currently not used, do this to avoid warning
\r
856 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
857 eventIdFound = (priMemEventBuffer[i].eventId == eventStatus->eventId);
\r
860 if (eventIdFound) {
\r
861 // Update event found
\r
862 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
863 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
866 // Search for free position
\r
867 for (i=0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFreePositionFound); i++){
\r
868 eventIdFreePositionFound = (priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
872 if (eventIdFreePositionFound) {
\r
873 priMemEventBuffer[i-1].eventId = eventStatus->eventId;
\r
874 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
875 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
878 // Error: Pri mem event buffer full
\r
879 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EVENT_PRI_MEM_ID, DEM_E_PRI_MEM_EVENT_BUFF_FULL);
\r
883 Irq_Restore(state);
\r
887 * Procedure: deleteEventPriMem
\r
888 * Description: Delete the event data of "eventParam->eventId" from "priMemEventBuffer".
\r
890 static void deleteEventPriMem(const Dem_EventParameterType *eventParam)
\r
892 boolean eventIdFound = FALSE;
\r
899 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
900 eventIdFound = (priMemEventBuffer[i].eventId == eventParam->EventID);
\r
903 if (eventIdFound) {
\r
904 // Delete event found
\r
905 memset(&priMemEventBuffer[i-1], 0, sizeof(EventRecType));
\r
908 Irq_Restore(state);
\r
912 * Procedure: storeEventEvtMem
\r
913 * Description: Store the event data of "eventStatus->eventId" in event memory according to
\r
914 * "eventParam" destination option.
\r
916 static void storeEventEvtMem(const Dem_EventParameterType *eventParam, const EventStatusRecType *eventStatus)
\r
920 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION)
\r
921 && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
922 switch (eventParam->EventClass->EventDestination[i])
\r
924 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
925 storeEventPriMem(eventParam, eventStatus); /** @req DEM010 */
\r
928 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
929 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
930 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
931 // Not yet supported
\r
932 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
942 * Procedure: storeExtendedDataPriMem
\r
943 * Description: Store the extended data pointed by "extendedData" to the "priMemExtDataBuffer",
\r
944 * if non existent a new entry is created.
\r
946 static void storeExtendedDataPriMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData) /** @req DEM041 */
\r
948 boolean eventIdFound = FALSE;
\r
949 boolean eventIdFreePositionFound=FALSE;
\r
954 // Check if already stored
\r
955 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
956 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
959 if (eventIdFound) {
\r
960 // Yes, overwrite existing
\r
961 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
964 // No, lookup first free position
\r
965 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFreePositionFound); i++){
\r
966 eventIdFreePositionFound = (priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
968 if (eventIdFreePositionFound) {
\r
969 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
972 // Error: Pri mem extended data buffer full
\r
973 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRI_MEM_ID, DEM_E_PRI_MEM_EXT_DATA_BUFF_FULL);
\r
977 Irq_Restore(state);
\r
981 * Procedure: deleteExtendedDataPriMem
\r
982 * Description: Delete the extended data of "eventParam->eventId" from "priMemExtDataBuffer".
\r
984 static void deleteExtendedDataPriMem(const Dem_EventParameterType *eventParam)
\r
986 boolean eventIdFound = FALSE;
\r
991 // Check if already stored
\r
992 for (i = 0;(i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
993 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
996 if (eventIdFound) {
\r
997 // Yes, clear record
\r
998 memset(&priMemExtDataBuffer[i-1], 0, sizeof(ExtDataRecType));
\r
1001 Irq_Restore(state);
\r
1005 * Procedure: storeExtendedDataEvtMem
\r
1006 * Description: Store the extended data in event memory according to
\r
1007 * "eventParam" destination option
\r
1009 static void storeExtendedDataEvtMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
1013 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
1014 switch (eventParam->EventClass->EventDestination[i])
\r
1016 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1017 storeExtendedDataPriMem(eventParam, extendedData);
\r
1020 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1021 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1022 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1023 // Not yet supported
\r
1024 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1035 * Procedure: lookupExtendedDataRecNumParam
\r
1036 * Description: Returns TRUE if the requested extended data number was found among the configured records for the event.
\r
1037 * "extDataRecClassPtr" returns a pointer to the record class, "posInExtData" returns the position in stored extended data.
\r
1039 static boolean lookupExtendedDataRecNumParam(uint8 extendedDataNumber, const Dem_EventParameterType *eventParam, Dem_ExtendedDataRecordClassType const **extDataRecClassPtr, uint16 *posInExtData)
\r
1041 boolean recNumFound = FALSE;
\r
1043 if (eventParam->ExtendedDataClassRef != NULL) {
\r
1044 uint16 byteCnt = 0;
\r
1047 // Request extended data and copy it to the buffer
\r
1048 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL) && (!recNumFound); i++) {
\r
1049 if (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->RecordNumber == extendedDataNumber) {
\r
1050 *extDataRecClassPtr = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i];
\r
1051 *posInExtData = byteCnt;
\r
1052 recNumFound = TRUE;
\r
1054 byteCnt += eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
1058 return recNumFound;
\r
1063 * Procedure: lookupExtendedDataPriMem
\r
1064 * Description: Returns TRUE if the requested event id is found, "extData" points to the found data.
\r
1066 static boolean lookupExtendedDataPriMem(Dem_EventIdType eventId, ExtDataRecType **extData)
\r
1068 boolean eventIdFound = FALSE;
\r
1071 // Lookup corresponding extended data
\r
1072 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++) {
\r
1073 eventIdFound = (priMemExtDataBuffer[i].eventId == eventId);
\r
1076 if (eventIdFound) {
\r
1077 // Yes, return pointer
\r
1078 *extData = &priMemExtDataBuffer[i-1];
\r
1081 return eventIdFound;
\r
1084 // PC-Lint (715 etc): Remove errors until function is filled.
\r
1085 //lint -e{715} Symbol not referenced
\r
1086 static void storeFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1092 // PC-Lint (715 etc): Remove errors until function is filled.
\r
1093 //lint -e{715} Symbol not referenced
\r
1094 static void deleteFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam)
\r
1101 * Procedure: storeFreezeFrameDataEvtMem
\r
1102 * Description: Store the freeze frame data in event memory according to
\r
1103 * "eventParam" destination option
\r
1105 static void storeFreezeFrameDataEvtMem(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1109 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
1110 switch (eventParam->EventClass->EventDestination[i])
\r
1112 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1113 storeFreezeFrameDataPriMem(eventParam, freezeFrame);
\r
1116 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1117 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1118 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1119 // Not yet supported
\r
1120 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1131 * Procedure: handlePreInitEvent
\r
1132 * Description: Handle the updating of event status and storing of
\r
1133 * event related data in preInit buffers.
\r
1135 static void handlePreInitEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1137 const Dem_EventParameterType *eventParam;
\r
1138 EventStatusRecType eventStatusLocal;
\r
1139 FreezeFrameRecType freezeFrameLocal;
\r
1140 ExtDataRecType extendedDataLocal;
\r
1142 // Find configuration for this event
\r
1143 lookupEventIdParameter(eventId, &eventParam);
\r
1144 if (eventParam != NULL) {
\r
1145 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1146 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1147 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
1148 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1151 updateEventStatusRec(eventParam, eventStatus, FALSE, &eventStatusLocal);
\r
1154 if (eventStatusLocal.errorStatusChanged) {
\r
1156 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1157 // Collect freeze frame data
\r
1158 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1159 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1160 storeFreezeFrameDataPreInit(eventParam, &freezeFrameLocal);
\r
1163 // Collect extended data
\r
1164 getExtendedData(eventParam, &extendedDataLocal);
\r
1165 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1166 storeExtendedDataPreInit(eventParam, &extendedDataLocal);
\r
1172 // Operation cycle not started
\r
1173 // TODO: Report error?
\r
1177 // Operation cycle not set
\r
1178 // TODO: Report error?
\r
1182 // Event ID not configured
\r
1183 // TODO: Report error?
\r
1189 * Procedure: handleEvent
\r
1190 * Description: Handle the updating of event status and storing of
\r
1191 * event related data in event memory.
\r
1193 static Std_ReturnType handleEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1195 Std_ReturnType returnCode = E_OK;
\r
1196 const Dem_EventParameterType *eventParam;
\r
1197 EventStatusRecType eventStatusLocal;
\r
1198 FreezeFrameRecType freezeFrameLocal;
\r
1199 ExtDataRecType extendedDataLocal;
\r
1201 // Find configuration for this event
\r
1202 lookupEventIdParameter(eventId, &eventParam);
\r
1203 if (eventParam != NULL) {
\r
1204 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1205 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1206 if ((!((disableDtcStorage.storageDisabled) && (checkDtcGroup(disableDtcStorage.dtcGroup, eventParam)) && (checkDtcKind(disableDtcStorage.dtcKind, eventParam))))) {
\r
1207 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1208 if (eventStatusLocal.errorStatusChanged) {
\r
1209 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1210 storeEventEvtMem(eventParam, &eventStatusLocal); /** @req DEM184 */
\r
1211 // Collect freeze frame data
\r
1212 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1213 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1214 storeFreezeFrameDataEvtMem(eventParam, &freezeFrameLocal); /** @req DEM190 */
\r
1217 // Collect extended data
\r
1218 getExtendedData(eventParam, &extendedDataLocal);
\r
1219 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL)
\r
1221 storeExtendedDataEvtMem(eventParam, &extendedDataLocal);
\r
1228 // Operation cycle not started
\r
1229 returnCode = E_NOT_OK;
\r
1233 // Operation cycle not set
\r
1234 returnCode = E_NOT_OK;
\r
1238 // Event ID not configured
\r
1239 returnCode = E_NOT_OK;
\r
1242 return returnCode;
\r
1247 * Procedure: resetEventStatus
\r
1248 * Description: Resets the events status of eventId.
\r
1250 static void resetEventStatus(Dem_EventIdType eventId)
\r
1252 EventStatusRecType *eventStatusRecPtr;
\r
1256 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
1257 if (eventStatusRecPtr != NULL) {
\r
1258 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED; /** @req DEM187 */
\r
1261 Irq_Restore(state);
\r
1266 * Procedure: getEventStatus
\r
1267 * Description: Returns the extended event status bitmask of eventId in "eventStatusExtended".
\r
1269 static void getEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended)
\r
1271 EventStatusRecType eventStatusLocal;
\r
1273 // Get recorded status
\r
1274 getEventStatusRec(eventId, &eventStatusLocal);
\r
1275 if (eventStatusLocal.eventId == eventId) {
\r
1276 *eventStatusExtended = eventStatusLocal.eventStatusExtended; /** @req DEM051 */
\r
1279 // Event Id not found, no report received.
\r
1280 *eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1286 * Procedure: getEventFailed
\r
1287 * Description: Returns the TRUE or FALSE of "eventId" in "eventFailed" depending on current status.
\r
1289 static void getEventFailed(Dem_EventIdType eventId, boolean *eventFailed)
\r
1291 EventStatusRecType eventStatusLocal;
\r
1293 // Get recorded status
\r
1294 getEventStatusRec(eventId, &eventStatusLocal);
\r
1295 if (eventStatusLocal.eventId == eventId) {
\r
1296 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) { /** @req DEM052 */
\r
1297 *eventFailed = TRUE;
\r
1300 *eventFailed = FALSE;
\r
1304 // Event Id not found, assume ok.
\r
1305 *eventFailed = FALSE;
\r
1311 * Procedure: getEventTested
\r
1312 * Description: Returns the TRUE or FALSE of "eventId" in "eventTested" depending on
\r
1313 * current status the "test not completed this operation cycle" bit.
\r
1315 static void getEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1317 EventStatusRecType eventStatusLocal;
\r
1319 // Get recorded status
\r
1320 getEventStatusRec(eventId, &eventStatusLocal);
\r
1321 if (eventStatusLocal.eventId == eventId) {
\r
1322 if ( !(eventStatusLocal.eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE)) { /** @req DEM053 */
\r
1323 *eventTested = TRUE;
\r
1326 *eventTested = FALSE;
\r
1330 // Event Id not found, not tested.
\r
1331 *eventTested = FALSE;
\r
1337 * Procedure: getFaultDetectionCounter
\r
1338 * Description: Returns pre debounce counter of "eventId" in "counter" and return value E_OK if
\r
1339 * the counter was available else E_NOT_OK.
\r
1341 static Std_ReturnType getFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1343 Std_ReturnType returnCode = E_NOT_OK;
\r
1344 const Dem_EventParameterType *eventParam;
\r
1346 lookupEventIdParameter(eventId, &eventParam);
\r
1347 if (eventParam != NULL) {
\r
1348 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
1349 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName)
\r
1351 case DEM_NO_PRE_DEBOUNCE:
\r
1352 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal != NULL) {
\r
1353 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc != NULL) {
\r
1354 returnCode = eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc(counter); /** @req DEM204.None */ /** @req DEM264 */ /** @req DEM265 */
\r
1359 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
1361 EventStatusRecType *eventStatusRec;
\r
1363 lookupEventStatusRec(eventId, &eventStatusRec);
\r
1364 if (eventStatusRec != NULL) {
\r
1365 *counter = eventStatusRec->faultDetectionCounter; /** @req DEM204.Counter */
\r
1369 returnCode = E_OK;
\r
1373 case DEM_PRE_DEBOUNCE_FREQUENCY_BASED:
\r
1374 case DEM_PRE_DEBOUNCE_TIME_BASED:
\r
1375 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1379 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_PARAM_DATA);
\r
1385 return returnCode;
\r
1390 * Procedure: setOperationCycleState
\r
1391 * Description: Change the operation state of "operationCycleId" to "cycleState" and updates stored
\r
1392 * event connected to this cycle id.
\r
1393 * Returns E_OK if operation was successful else E_NOT_OK.
\r
1395 static Std_ReturnType setOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState) /** @req DEM338 */
\r
1398 Std_ReturnType returnCode = E_OK;
\r
1400 if (operationCycleId < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1401 switch (cycleState)
\r
1403 case DEM_CYCLE_STATE_START:
\r
1404 operationCycleStateList[operationCycleId] = cycleState;
\r
1405 // Lookup event ID
\r
1406 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1407 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1408 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED_THIS_OPERATION_CYCLE;
\r
1409 eventStatusBuffer[i].eventStatusExtended |= DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
1414 case DEM_CYCLE_STATE_END:
\r
1415 operationCycleStateList[operationCycleId] = cycleState;
\r
1416 // Lookup event ID
\r
1417 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1418 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1419 if ((!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_FAILED_THIS_OPERATION_CYCLE)) && (!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE))) {
\r
1420 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_PENDING_DTC; // Clear pendingDTC bit /** @req DEM379.PendingClear
\r
1426 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
1427 returnCode = E_NOT_OK;
\r
1432 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
1433 returnCode = E_NOT_OK;
\r
1436 return returnCode;
\r
1440 //==============================================================================//
\r
1442 // E X T E R N A L F U N C T I O N S //
\r
1444 //==============================================================================//
\r
1446 /*********************************************
\r
1447 * Interface for upper layer modules (8.3.1) *
\r
1448 *********************************************/
\r
1451 * Procedure: Dem_GetVersionInfo
\r
1454 // Defined in Dem.h
\r
1457 /***********************************************
\r
1458 * Interface ECU State Manager <-> DEM (8.3.2) *
\r
1459 ***********************************************/
\r
1462 * Procedure: Dem_PreInit
\r
1465 void Dem_PreInit(void)
\r
1467 /** @req DEM180 */
\r
1470 VALIDATE_NO_RV(DEM_Config.ConfigSet != NULL, DEM_PREINIT_ID, DEM_E_CONFIG_PTR_INVALID);
\r
1472 configSet = DEM_Config.ConfigSet;
\r
1474 // Initializion of operation cycle states.
\r
1475 for (i = 0; i < DEM_OPERATION_CYCLE_ID_ENDMARK; i++) {
\r
1476 operationCycleStateList[i] = DEM_CYCLE_STATE_END;
\r
1479 // Initialize the event status buffer
\r
1480 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1481 eventStatusBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1482 eventStatusBuffer[i].eventParamRef = NULL;
\r
1483 eventStatusBuffer[i].faultDetectionCounter = 0;
\r
1484 eventStatusBuffer[i].occurrence = 0;
\r
1485 eventStatusBuffer[i].eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1486 eventStatusBuffer[i].errorStatusChanged = FALSE;
\r
1490 //lint -e568 -e685 //PC-Lint exception.
\r
1491 //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
1492 // Initialize the pre init buffers
\r
1493 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1494 preInitFreezeFrameBuffer[i].checksum = 0;
\r
1495 preInitFreezeFrameBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1496 preInitFreezeFrameBuffer[i].occurrence = 0;
\r
1497 preInitFreezeFrameBuffer[i].dataSize = 0;
\r
1498 for (j = 0; j < DEM_MAX_SIZE_FF_DATA;j++){
\r
1499 preInitFreezeFrameBuffer[i].data[j] = 0;
\r
1504 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1505 preInitExtDataBuffer[i].checksum = 0;
\r
1506 preInitExtDataBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1507 preInitExtDataBuffer[i].dataSize = 0;
\r
1508 for (j = 0; j < DEM_MAX_SIZE_EXT_DATA;j++){
\r
1509 preInitExtDataBuffer[i].data[j] = 0;
\r
1513 disableDtcStorage.storageDisabled = FALSE;
\r
1515 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_START); /** @req DEM047 */
\r
1517 demState = DEM_PREINITIALIZED;
\r
1522 * Procedure: Dem_Init
\r
1525 void Dem_Init(void)
\r
1528 ChecksumType cSum;
\r
1529 const Dem_EventParameterType *eventParam;
\r
1532 * Validate and read out saved error log from non volatile memory
\r
1535 // Validate event records stored in primary memory
\r
1536 for (i = 0; i < DEM_MAX_NUMBER_EVENT_PRI_MEM; i++) {
\r
1537 cSum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
1538 if ((cSum != priMemEventBuffer[i].checksum) || (priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1539 // Unlegal record, clear the record
\r
1540 memset(&priMemEventBuffer[i], 0, sizeof(EventRecType));
\r
1543 // Valid, update current status
\r
1544 mergeEventStatusRec(&priMemEventBuffer[i]);
\r
1546 // Update occurrence counter on pre init stored freeze frames
\r
1547 updateFreezeFrameOccurrencePreInit(&priMemEventBuffer[i]);
\r
1551 // Validate extended data records stored in primary memory
\r
1552 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM; i++) {
\r
1553 cSum = calcChecksum(&priMemExtDataBuffer[i], sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
1554 if ((cSum != priMemExtDataBuffer[i].checksum) || (priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1555 // Unlegal record, clear the record
\r
1556 memset(&priMemExtDataBuffer[i], 0, sizeof(ExtDataRecType));
\r
1561 //lint -e568 //PC-Lint exception.
\r
1562 //lint -e685 //PC-Lint exception.
\r
1563 //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
1564 // Validate freeze frame records stored in primary memory
\r
1565 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++) {
\r
1566 cSum = calcChecksum(&priMemFreezeFrameBuffer[i], sizeof(FreezeFrameRecType)-sizeof(ChecksumType));
\r
1567 if ((cSum != priMemFreezeFrameBuffer[i].checksum) || (priMemFreezeFrameBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1568 // Unlegal record, clear the record
\r
1569 memset(&priMemFreezeFrameBuffer[i], 0, sizeof(FreezeFrameRecType));
\r
1575 * Handle errors stored in temporary buffer (if any)
\r
1578 // Transfer updated event data to event memory
\r
1579 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1580 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1581 // Update the event memory
\r
1582 lookupEventIdParameter(eventStatusBuffer[i].eventId, &eventParam);
\r
1583 storeEventEvtMem(eventParam, &eventStatusBuffer[i]);
\r
1587 // Transfer extended data to event memory if necessary
\r
1588 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1589 if (preInitExtDataBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1590 lookupEventIdParameter(preInitExtDataBuffer[i].eventId, &eventParam);
\r
1591 storeExtendedDataEvtMem(eventParam, &preInitExtDataBuffer[i]);
\r
1596 //lint -e568 //PC-Lint exception.
\r
1597 //lint -e685 //PC-Lint exception.
\r
1598 //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
1599 // Transfer freeze frames to event memory
\r
1600 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1601 if (preInitFreezeFrameBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1602 lookupEventIdParameter(preInitFreezeFrameBuffer[i].eventId, &eventParam);
\r
1603 storeFreezeFrameDataEvtMem(eventParam, &preInitFreezeFrameBuffer[i]);
\r
1608 // Init the dtc filter
\r
1609 dtcFilter.dtcStatusMask = DEM_DTC_STATUS_MASK_ALL; // All allowed
\r
1610 dtcFilter.dtcKind = DEM_DTC_KIND_ALL_DTCS; // All kinds of DTCs
\r
1611 dtcFilter.dtcOrigin = DEM_DTC_ORIGIN_PRIMARY_MEMORY; // Primary memory
\r
1612 dtcFilter.filterWithSeverity = DEM_FILTER_WITH_SEVERITY_NO; // No Severity filtering
\r
1613 dtcFilter.dtcSeverityMask = DEM_SEVERITY_NO_SEVERITY; // Not used when filterWithSeverity is FALSE
\r
1614 dtcFilter.filterForFaultDetectionCounter = DEM_FILTER_FOR_FDC_NO; // No fault detection counter filtering
\r
1616 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1618 disableDtcStorage.storageDisabled = FALSE;
\r
1620 demState = DEM_INITIALIZED;
\r
1625 * Procedure: Dem_shutdown
\r
1628 void Dem_Shutdown(void)
\r
1630 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_END); /** @req DEM047 */
\r
1632 demState = DEM_UNINITIALIZED; /** @req DEM368 */
\r
1637 * Interface for basic software scheduler
\r
1639 void Dem_MainFunction(void)
\r
1641 /** @req DEM125 */
\r
1646 /***************************************************
\r
1647 * Interface SW-Components via RTE <-> DEM (8.3.3) *
\r
1648 ***************************************************/
\r
1651 * Procedure: Dem_SetEventStatus
\r
1654 Std_ReturnType Dem_SetEventStatus(Dem_EventIdType eventId, Dem_EventStatusType eventStatus) /** @req DEM330 */
\r
1656 Std_ReturnType returnCode = E_OK;
\r
1658 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1660 returnCode = handleEvent(eventId, eventStatus);
\r
1664 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1665 returnCode = E_NOT_OK;
\r
1668 return returnCode;
\r
1673 * Procedure: Dem_ResetEventStatus
\r
1676 Std_ReturnType Dem_ResetEventStatus(Dem_EventIdType eventId) /** @req DEM331 */
\r
1678 Std_ReturnType returnCode = E_OK;
\r
1680 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1682 resetEventStatus(eventId); /** @req DEM186 */
\r
1686 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_RESETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1687 returnCode = E_NOT_OK;
\r
1690 return returnCode;
\r
1695 * Procedure: Dem_GetEventStatus
\r
1698 Std_ReturnType Dem_GetEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended) /** @req DEM332 */
\r
1700 Std_ReturnType returnCode = E_OK;
\r
1702 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1704 getEventStatus(eventId, eventStatusExtended);
\r
1708 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1709 returnCode = E_NOT_OK;
\r
1712 return returnCode;
\r
1717 * Procedure: Dem_GetEventFailed
\r
1720 Std_ReturnType Dem_GetEventFailed(Dem_EventIdType eventId, boolean *eventFailed) /** @req DEM333 */
\r
1722 Std_ReturnType returnCode = E_OK;
\r
1724 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1726 getEventFailed(eventId, eventFailed);
\r
1730 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTFAILED_ID, DEM_E_UNINIT);
\r
1731 returnCode = E_NOT_OK;
\r
1734 return returnCode;
\r
1739 * Procedure: Dem_GetEventTested
\r
1742 Std_ReturnType Dem_GetEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1744 Std_ReturnType returnCode = E_OK;
\r
1746 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1748 getEventTested(eventId, eventTested);
\r
1752 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTTESTED_ID, DEM_E_UNINIT);
\r
1753 returnCode = E_NOT_OK;
\r
1756 return returnCode;
\r
1761 * Procedure: Dem_GetFaultDetectionCounter
\r
1764 Std_ReturnType Dem_GetFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1766 Std_ReturnType returnCode = E_OK;
\r
1768 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1770 returnCode = getFaultDetectionCounter(eventId, counter);
\r
1774 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_UNINIT);
\r
1775 returnCode = E_NOT_OK;
\r
1778 return returnCode;
\r
1783 * Procedure: Dem_SetOperationCycleState
\r
1786 Std_ReturnType Dem_SetOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState)
\r
1788 Std_ReturnType returnCode = E_OK;
\r
1790 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1792 returnCode = setOperationCycleState(operationCycleId, cycleState);
\r
1797 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_UNINIT);
\r
1798 returnCode = E_NOT_OK;
\r
1801 return returnCode;
\r
1806 * Procedure: Dem_GetDTCOfEvent
\r
1809 Std_ReturnType Dem_GetDTCOfEvent(Dem_EventIdType eventId, Dem_DTCKindType dtcKind, uint32* dtcOfEvent)
\r
1811 Std_ReturnType returnCode = E_NO_DTC_AVAILABLE;
\r
1812 const Dem_EventParameterType *eventParam;
\r
1814 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1816 lookupEventIdParameter(eventId, &eventParam);
\r
1818 if (eventParam != NULL) {
\r
1819 if (checkDtcKind(dtcKind, eventParam)) {
\r
1820 if (eventParam->DTCClassRef != NULL) {
\r
1821 *dtcOfEvent = eventParam->DTCClassRef->DTC; /** @req DEM269 */
\r
1822 returnCode = E_OK;
\r
1827 // Event Id not found
\r
1828 returnCode = E_NOT_OK;
\r
1833 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETDTCOFEVENT_ID, DEM_UNINITIALIZED);
\r
1834 returnCode = E_NOT_OK;
\r
1837 return returnCode;
\r
1841 /********************************************
\r
1842 * Interface BSW-Components <-> DEM (8.3.4) *
\r
1843 ********************************************/
\r
1846 * Procedure: Dem_ReportErrorStatus
\r
1849 void Dem_ReportErrorStatus( Dem_EventIdType eventId, Dem_EventStatusType eventStatus ) /** @req DEM107 */
\r
1852 switch (demState) {
\r
1853 case DEM_PREINITIALIZED:
\r
1854 // Update status and check if is to be stored
\r
1855 if ((eventStatus == DEM_EVENT_STATUS_PASSED) || (eventStatus == DEM_EVENT_STATUS_FAILED)) {
\r
1856 handlePreInitEvent(eventId, eventStatus); /** @req DEM168 */
\r
1860 case DEM_INITIALIZED:
\r
1861 (void)handleEvent(eventId, eventStatus); /** @req DEM167 */
\r
1864 case DEM_UNINITIALIZED:
\r
1866 // Uninitialized can not do anything
\r
1867 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_REPORTERRORSTATUS_ID, DEM_E_UNINIT);
\r
1871 } // switch (demState)
\r
1874 /*********************************
\r
1875 * Interface DCM <-> DEM (8.3.5) *
\r
1876 *********************************/
\r
1878 * Procedure: Dem_GetDTCStatusAvailabilityMask
\r
1881 Std_ReturnType Dem_GetDTCStatusAvailabilityMask(uint8 *dtcStatusMask) /** @req DEM014 */
\r
1883 *dtcStatusMask = DEM_DTC_STATUS_AVAILABILITY_MASK; // User configuration mask
\r
1884 *dtcStatusMask &= DEM_TEST_FAILED // Mask with supported bits /** @req DEM060 */
\r
1885 | DEM_TEST_FAILED_THIS_OPERATION_CYCLE
\r
1887 // | DEM_CONFIRMED_DTC TODO: Add support for this bit
\r
1888 | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR
\r
1889 | DEM_TEST_FAILED_SINCE_LAST_CLEAR
\r
1890 | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE
\r
1891 // | DEM_WARNING_INDICATOR_REQUESTED TODO: Add support for this bit
\r
1899 * Procedure: Dem_SetDTCFilter
\r
1902 Dem_ReturnSetDTCFilterType Dem_SetDTCFilter(uint8 dtcStatusMask,
\r
1903 Dem_DTCKindType dtcKind,
\r
1904 Dem_DTCOriginType dtcOrigin,
\r
1905 Dem_FilterWithSeverityType filterWithSeverity,
\r
1906 Dem_DTCSeverityType dtcSeverityMask,
\r
1907 Dem_FilterForFDCType filterForFaultDetectionCounter)
\r
1909 Dem_ReturnSetDTCFilterType returnCode = DEM_FILTER_ACCEPTED;
\r
1911 if (demState == DEM_INITIALIZED) {
\r
1912 // Check dtcKind parameter
\r
1913 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
1915 // Check dtcOrigin parameter
\r
1916 VALIDATE_RV((dtcOrigin == DEM_DTC_ORIGIN_SECONDARY_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_PRIMARY_MEMORY)
\r
1917 || (dtcOrigin == DEM_DTC_ORIGIN_PERMANENT_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_MIRROR_MEMORY), DEM_SETDTCFILTER_ID, DEM_E_PARAM_DATA, DEM_WRONG_FILTER);
\r
1919 // Check filterWithSeverity and dtcSeverityMask parameter
\r
1920 VALIDATE_RV(((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
1921 || ((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES)
\r
1922 && (!(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
1924 // Check filterForFaultDetectionCounter parameter
\r
1925 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
1927 // Yes all parameters correct, set the new filters. /** @req DEM057 */
\r
1928 dtcFilter.dtcStatusMask = dtcStatusMask;
\r
1929 dtcFilter.dtcKind = dtcKind;
\r
1930 dtcFilter.dtcOrigin = dtcOrigin;
\r
1931 dtcFilter.filterWithSeverity = filterWithSeverity;
\r
1932 dtcFilter.dtcSeverityMask = dtcSeverityMask;
\r
1933 dtcFilter.filterForFaultDetectionCounter = filterForFaultDetectionCounter;
\r
1934 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1936 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETDTCFILTER_ID, DEM_E_UNINIT);
\r
1937 returnCode = DEM_WRONG_FILTER;
\r
1940 return returnCode;
\r
1945 * Procedure: Dem_GetStatusOfDTC
\r
1948 Dem_ReturnGetStatusOfDTCType Dem_GetStatusOfDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, Dem_EventStatusExtendedType* status) {
\r
1949 Dem_ReturnGetStatusOfDTCType returnCode = DEM_STATUS_FAILED;
\r
1950 EventStatusRecType *eventRec;
\r
1952 if (demState == DEM_INITIALIZED) {
\r
1953 if (lookupDtcEvent(dtc, &eventRec)) {
\r
1954 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
1955 if (checkDtcOrigin(dtcOrigin,eventRec->eventParamRef)) {
\r
1956 *status = eventRec->eventStatusExtended; /** @req DEM059 */
\r
1957 returnCode = DEM_STATUS_OK;
\r
1960 returnCode = DEM_STATUS_WRONG_DTCORIGIN; /** @req DEM171 */
\r
1964 returnCode = DEM_STATUS_WRONG_DTCKIND;
\r
1968 returnCode = DEM_STATUS_WRONG_DTC; /** @req DEM172 */
\r
1971 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETSTATUSOFDTC_ID, DEM_E_UNINIT);
\r
1972 returnCode = DEM_STATUS_FAILED;
\r
1975 return returnCode;
\r
1980 * Procedure: Dem_GetNumberOfFilteredDtc
\r
1983 Dem_ReturnGetNumberOfFilteredDTCType Dem_GetNumberOfFilteredDtc(uint16 *numberOfFilteredDTC) {
\r
1985 uint16 numberOfFaults = 0;
\r
1986 Dem_ReturnGetNumberOfFilteredDTCType returnCode = DEM_NUMBER_OK;
\r
1988 if (demState == DEM_INITIALIZED) {
\r
1989 //Dem_DisableEventStatusUpdate();
\r
1991 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1992 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1993 if (matchEventWithDtcFilter(&eventStatusBuffer[i])) {
\r
1994 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
2001 //Dem_EnableEventStatusUpdate();
\r
2003 *numberOfFilteredDTC = numberOfFaults; /** @req DEM061 */
\r
2005 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETNUMBEROFFILTEREDDTC_ID, DEM_E_UNINIT);
\r
2006 returnCode = DEM_NUMBER_FAILED;
\r
2009 return returnCode;
\r
2014 * Procedure: Dem_GetNextFilteredDTC
\r
2017 Dem_ReturnGetNextFilteredDTCType Dem_GetNextFilteredDTC(uint32 *dtc, Dem_EventStatusExtendedType *dtcStatus)
\r
2019 Dem_ReturnGetNextFilteredDTCType returnCode = DEM_FILTERED_OK;
\r
2020 boolean dtcFound = FALSE;
\r
2022 if (demState == DEM_INITIALIZED) {
\r
2023 // TODO: This job should be done in an more advanced way according to Dem217
\r
2024 while ((!dtcFound) && (dtcFilter.faultIndex != 0)) {
\r
2025 dtcFilter.faultIndex--;
\r
2026 if (eventStatusBuffer[dtcFilter.faultIndex].eventId != DEM_EVENT_ID_NULL) {
\r
2027 if (matchEventWithDtcFilter(&eventStatusBuffer[dtcFilter.faultIndex])) {
\r
2028 if (eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef != NULL) {
\r
2029 *dtc = eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef->DTC; /** @req DEM216 */
\r
2030 *dtcStatus = eventStatusBuffer[dtcFilter.faultIndex].eventStatusExtended;
\r
2038 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
2039 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
2042 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETNEXTFILTEREDDTC_ID, DEM_E_UNINIT);
\r
2043 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
2046 return returnCode;
\r
2051 * Procedure: Dem_GetTranslationType
\r
2054 Dem_ReturnTypeOfDtcSupportedType Dem_GetTranslationType(void)
\r
2056 return DEM_TYPE_OF_DTC_SUPPORTED; /** @req DEM231 */
\r
2061 * Procedure: Dem_ClearDTC
\r
2064 Dem_ReturnClearDTCType Dem_ClearDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin) /** @req DEM009 */
\r
2066 Dem_ReturnClearDTCType returnCode = DEM_CLEAR_OK;
\r
2067 Dem_EventIdType eventId;
\r
2068 const Dem_EventParameterType *eventParam;
\r
2071 if (demState == DEM_INITIALIZED) {
\r
2072 // Loop through the event buffer
\r
2073 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2074 eventId = eventStatusBuffer[i].eventId;
\r
2075 if (eventId != DEM_EVENT_ID_NULL) {
\r
2076 eventParam = eventStatusBuffer[i].eventParamRef;
\r
2077 if (eventParam != NULL) {
\r
2078 //lint --e(506) PC-Lint exception Misra 13.7, 14.1 Allow configuration variables in boolean expression
\r
2079 //lint --e(774) PC-Lint exception Related to MISRA 13.7
\r
2080 if ((DEM_CLEAR_ALL_EVENTS == STD_ON) || (eventParam->DTCClassRef != NULL)) {
\r
2081 if (checkDtcKind(dtcKind, eventParam)) {
\r
2082 if (checkDtcGroup(dtc, eventParam)) {
\r
2083 boolean dtcOriginFound = FALSE;
\r
2084 for (j = 0; (j < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound) ; j++){
\r
2085 dtcOriginFound =(eventParam->EventClass->EventDestination[j] == dtcOrigin);
\r
2087 //if (j-1 < DEM_MAX_NR_OF_EVENT_DESTINATION) {
\r
2088 if (dtcOriginFound) {
\r
2089 // Yes! All conditions met.
\r
2090 switch (dtcOrigin)
\r
2092 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2093 /** @req DEM077 */
\r
2094 deleteEventPriMem(eventParam);
\r
2095 deleteFreezeFrameDataPriMem(eventParam);
\r
2096 deleteExtendedDataPriMem(eventParam);
\r
2097 deleteEventStatusRec(eventParam); // TODO: Shall this be done or just resetting the status?
\r
2100 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2101 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2102 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2103 // Not yet supported
\r
2104 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2105 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2108 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2117 // Fatal error, no event parameters found for the stored event!
\r
2118 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNEXPECTED_EXECUTION);
\r
2123 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNINIT);
\r
2124 returnCode = DEM_CLEAR_FAILED;
\r
2127 return returnCode;
\r
2132 * Procedure: Dem_DisableDTCStorage
\r
2135 Dem_ReturnControlDTCStorageType Dem_DisableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind) /** @req DEM035 */
\r
2137 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2139 if (demState == DEM_INITIALIZED) {
\r
2140 // Check dtcGroup parameter
\r
2141 if (dtcGroup == DEM_DTC_GROUP_ALL_DTCS) {
\r
2142 // Check dtcKind parameter
\r
2143 if ((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS)) {
\r
2144 /** @req DEM079 */
\r
2145 disableDtcStorage.dtcGroup = dtcGroup;
\r
2146 disableDtcStorage.dtcKind = dtcKind;
\r
2147 disableDtcStorage.storageDisabled = TRUE;
\r
2149 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2152 returnCode = DEM_CONTROL_DTC_WRONG_DTCGROUP;
\r
2155 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_DISABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
2156 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2159 return returnCode;
\r
2164 * Procedure: Dem_EnableDTCStorage
\r
2167 Dem_ReturnControlDTCStorageType Dem_EnableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind)
\r
2169 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2171 if (demState == DEM_INITIALIZED) {
\r
2172 // TODO: Behavior is not defined if group or kind do not match active settings, therefore the filter is just switched off.
\r
2173 (void)dtcGroup; (void)dtcKind; // Just to make get rid of PC-Lint warnings
\r
2174 disableDtcStorage.storageDisabled = FALSE; /** @req DEM080 */
\r
2176 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_ENABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
2177 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2180 return returnCode;
\r
2184 * Procedure: Dem_GetExtendedDataRecordByDTC
\r
2187 Dem_ReturnGetExtendedDataRecordByDTCType Dem_GetExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint8 *destBuffer, uint16 *bufSize)
\r
2189 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_RECORD_WRONG_DTC;
\r
2190 EventStatusRecType *eventRec;
\r
2191 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2192 ExtDataRecType *extData;
\r
2193 uint16 posInExtData = 0;
\r
2195 if (demState == DEM_INITIALIZED) {
\r
2196 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2197 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2198 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2199 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2200 if (*bufSize >= extendedDataRecordClass->DataSize) {
\r
2201 switch (dtcOrigin)
\r
2203 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2204 if (lookupExtendedDataPriMem(eventRec->eventId, &extData)) {
\r
2205 // Yes all conditions met, copy the extended data record to destination buffer.
\r
2206 memcpy(destBuffer, &extData->data[posInExtData], extendedDataRecordClass->DataSize); /** @req DEM075 */
\r
2207 *bufSize = extendedDataRecordClass->DataSize;
\r
2208 returnCode = DEM_RECORD_OK;
\r
2211 // The record number is legal but no record was found for the DTC
\r
2213 returnCode = DEM_RECORD_OK;
\r
2217 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2218 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2219 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2220 // Not yet supported
\r
2221 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2222 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2225 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2230 returnCode = DEM_RECORD_BUFFERSIZE;
\r
2234 returnCode = DEM_RECORD_NUMBER;
\r
2238 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2242 returnCode = DEM_RECORD_DTCKIND;
\r
2246 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
2247 returnCode = DEM_RECORD_WRONG_DTC;
\r
2250 return returnCode;
\r
2255 * Procedure: Dem_GetSizeOfExtendedDataRecordByDTC
\r
2258 Dem_ReturnGetSizeOfExtendedDataRecordByDTCType Dem_GetSizeOfExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint16 *sizeOfExtendedDataRecord)
\r
2260 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2261 EventStatusRecType *eventRec;
\r
2262 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2263 uint16 posInExtData;
\r
2265 if (demState == DEM_INITIALIZED) {
\r
2266 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2267 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2268 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2269 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2270 *sizeOfExtendedDataRecord = extendedDataRecordClass->DataSize; /** @req DEM076 */
\r
2271 returnCode = DEM_GET_SIZEOFEDRBYDTC_OK;
\r
2274 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_RNUM;
\r
2278 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCOR;
\r
2282 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCKI;
\r
2286 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETSIZEOFEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
2287 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2290 return returnCode;
\r
2293 /***********************************
\r
2294 * OBD-specific Interfaces (8.3.6) *
\r
2295 ***********************************/
\r