1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\r
6 * This source code is free software; you can redistribute it and/or modify it
\r
7 * under the terms of the GNU General Public License version 2 as published by the
\r
8 * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
\r
10 * This program is distributed in the hope that it will be useful, but
\r
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\r
14 * -------------------------------- Arctic Core ------------------------------*/
\r
16 // 904 PC-Lint MISRA 14.7: OK. Allow VALIDATE, VALIDATE_RV and VALIDATE_NO_RV to return value.
\r
17 //lint -emacro(904,VALIDATE_RV,VALIDATE_NO_RV,VALIDATE)
\r
18 // 522 PC-Lint exception for empty functions
\r
19 //lint -esym(522,storeFreezeFrameDataEvtMem)
\r
20 //lint -esym(522,deleteFreezeFrameDataPriMem)
\r
21 //lint -esym(522,storeFreezeFrameDataPreInit)
\r
22 //lint -esym(522,storeFreezeFrameDataPriMem)
\r
23 //lint -esym(522,updateFreezeFrameOccurrencePreInit)
\r
27 * General requirements
\r
30 /** @req DEM151.partially */
\r
32 /** @req DEM013.14229-1 */
\r
35 /** @req DEM113 */ /** @req DEM174 */
\r
49 //#include "SchM_Dem.h"
\r
51 #include "McuExtensions.h"
\r
56 #define DEBOUNCE_FDC_TEST_FAILED 127
\r
57 #define DEBOUNCE_FDC_TEST_PASSED -128
\r
59 #if ( DEM_DEV_ERROR_DETECT == STD_ON )
\r
62 #define VALIDATE_RV(_exp,_api,_err,_rv ) \
\r
64 Det_ReportError(MODULE_ID_DEM, 0, _api, _err); \
\r
68 #define VALIDATE_NO_RV(_exp,_api,_err ) \
\r
70 Det_ReportError(MODULE_ID_DEM, 0, _api, _err); \
\r
73 #define DET_REPORTERROR(_x,_y,_z,_q) Det_ReportError(_x, _y, _z, _q)
\r
76 #define VALIDATE_RV(_exp,_api,_err,_rv )
\r
77 #define VALIDATE_NO_RV(_exp,_api,_err )
\r
78 #define DET_REPORTERROR(_x,_y,_z,_q)
\r
81 #if (DEM_OBD_SUPPORT == STD_ON)
\r
82 #error "DEM_OBD_SUPPORT is set to STD_ON, this is not supported by the code."
\r
85 #if (DEM_PTO_SUPPORT == STD_ON)
\r
86 #error "DEM_PTO_SUPPORT is set to STD_ON, this is not supported by the code."
\r
89 #if (DEM_TYPE_OF_DTC_SUPPORTED != 0x01)
\r
90 #error "DEM_TYPE_OF_DTC_SUPPORTED is not set to 1 (ISO14229-1), only ISO14229-1 is currently supported by the code."
\r
98 typedef uint16 ChecksumType;
\r
102 Dem_EventStatusExtendedType dtcStatusMask;
\r
103 Dem_DTCKindType dtcKind;
\r
104 Dem_DTCOriginType dtcOrigin;
\r
105 Dem_FilterWithSeverityType filterWithSeverity;
\r
106 Dem_DTCSeverityType dtcSeverityMask;
\r
107 Dem_FilterForFDCType filterForFaultDetectionCounter;
\r
111 // DisableDtcStorageType
\r
113 boolean storageDisabled;
\r
114 Dem_DTCGroupType dtcGroup;
\r
115 Dem_DTCKindType dtcKind;
\r
116 } DisableDtcStorageType;
\r
118 // For keeping track of the events status
\r
120 Dem_EventIdType eventId;
\r
121 const Dem_EventParameterType *eventParamRef;
\r
122 sint8 faultDetectionCounter;
\r
123 uint16 occurrence; /** @req DEM011 */
\r
124 Dem_EventStatusExtendedType eventStatusExtended; /** @req DEM006 */
\r
125 boolean errorStatusChanged;
\r
126 } EventStatusRecType;
\r
129 // Types for storing different event data on event memory
\r
131 Dem_EventIdType eventId;
\r
133 ChecksumType checksum;
\r
137 Dem_EventIdType eventId;
\r
140 sint8 data[DEM_MAX_SIZE_FF_DATA];
\r
141 ChecksumType checksum;
\r
142 } FreezeFrameRecType;
\r
145 Dem_EventIdType eventId;
\r
147 uint8 data[DEM_MAX_SIZE_EXT_DATA];
\r
148 ChecksumType checksum;
\r
155 DEM_UNINITIALIZED = 0,
\r
156 DEM_PREINITIALIZED,
\r
158 } Dem_StateType; /** @req DEM169 */
\r
161 static Dem_StateType demState = DEM_UNINITIALIZED;
\r
163 // Help pointer to configuration set
\r
164 static const Dem_ConfigSetType *configSet;
\r
167 * Allocation of DTC filter parameters
\r
169 static DtcFilterType dtcFilter;
\r
172 * Allocation of Disable/Enable DTC storage parameters
\r
174 static DisableDtcStorageType disableDtcStorage;
\r
177 * Allocation of operation cycle state list
\r
179 static Dem_OperationCycleStateType operationCycleStateList[DEM_OPERATION_CYCLE_ID_ENDMARK];
\r
182 * Allocation of local event status buffer
\r
184 static EventStatusRecType eventStatusBuffer[DEM_MAX_NUMBER_EVENT];
\r
187 * Allocation of pre-init event memory (used between pre-init and init)
\r
190 static FreezeFrameRecType preInitFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRE_INIT];
\r
191 static ExtDataRecType preInitExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRE_INIT];
\r
194 * Allocation of primary event memory ramlog (after init) in uninitialized memory
\r
197 static EventRecType priMemEventBuffer[DEM_MAX_NUMBER_EVENT_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
198 static FreezeFrameRecType priMemFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
199 static ExtDataRecType priMemExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
203 * Procedure: zeroPriMemBuffers
\r
204 * Description: Fill the primary buffers with zeroes
\r
206 //lint -e957 PC-Lint exception - Used only by DemTest
\r
207 void demZeroPriMemBuffers(void)
\r
209 memset(priMemEventBuffer, 0, sizeof(priMemEventBuffer));
\r
210 memset(priMemFreezeFrameBuffer, 0, sizeof(priMemFreezeFrameBuffer));
\r
211 memset(priMemExtDataBuffer, 0, sizeof(priMemExtDataBuffer));
\r
216 * Procedure: calcChecksum
\r
217 * Description: Calculate checksum over *data to *(data+nrOfBytes-1) area
\r
219 static ChecksumType calcChecksum(void *data, uint16 nrOfBytes)
\r
222 uint8 *byte = (uint8*)data;
\r
223 ChecksumType sum = 0;
\r
225 for (i = 0; i < nrOfBytes; i++) {
\r
234 * Procedure: checkDtcKind
\r
235 * Description: Return TRUE if "dtcKind" match the events DTCKind or "dtcKind"
\r
236 * is "DEM_DTC_KIND_ALL_DTCS" otherwise FALSE.
\r
238 static boolean checkDtcKind(Dem_DTCKindType dtcKind, const Dem_EventParameterType *eventParam)
\r
240 boolean result = FALSE;
\r
242 if (dtcKind == DEM_DTC_KIND_ALL_DTCS) {
\r
246 if (eventParam->DTCClassRef != NULL) {
\r
247 if (eventParam->DTCClassRef->DTCKind == dtcKind) {
\r
257 * Procedure: checkDtcGroup
\r
258 * Description: Return TRUE if "dtc" match the events DTC or "dtc" is
\r
259 * "DEM_DTC_GROUP_ALL_DTCS" otherwise FALSE.
\r
261 static boolean checkDtcGroup(uint32 dtc, const Dem_EventParameterType *eventParam)
\r
263 boolean result = FALSE;
\r
265 if (dtc == DEM_DTC_GROUP_ALL_DTCS) {
\r
269 if (eventParam->DTCClassRef != NULL) {
\r
270 if (eventParam->DTCClassRef->DTC == dtc) {
\r
280 * Procedure: checkDtcOrigin
\r
281 * Description: Return TRUE if "dtcOrigin" match any of the events DTCOrigin otherwise FALSE.
\r
283 static boolean checkDtcOrigin(Dem_DTCOriginType dtcOrigin, const Dem_EventParameterType *eventParam)
\r
285 boolean result = FALSE;
\r
286 boolean dtcOriginFound = FALSE;
\r
289 for (i = 0;(i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound); i++){
\r
290 dtcOriginFound = (eventParam->EventClass->EventDestination[i] == dtcOrigin);
\r
293 if (dtcOriginFound) {
\r
301 * Procedure: checkDtcSeverityMask
\r
302 * Description: Return TRUE if "dtcSeverityMask" match any of the events DTC severity otherwise FALSE.
\r
304 // PC-Lint (715 etc): Remove errors until function is filled.
\r
305 //lint -e{715} Symbol not referenced
\r
306 static boolean checkDtcSeverityMask(Dem_DTCSeverityType dtcSeverityMask, const Dem_EventParameterType *eventParam)
\r
308 boolean result = TRUE;
\r
310 // TODO: This function is optional, may be implemented here.
\r
317 * Procedure: checkDtcFaultDetectionCounterMask
\r
318 * Description: TBD.
\r
320 // PC-Lint (715 etc): Remove errors until function is filled.
\r
321 //lint -e{715} Symbol not referenced
\r
322 static boolean checkDtcFaultDetectionCounter(const Dem_EventParameterType *eventParam)
\r
324 boolean result = TRUE;
\r
326 // TODO: Not implemented yet.
\r
333 * Procedure: lookupEventStatusRec
\r
334 * Description: Returns the pointer to event id parameters of "eventId" in "*eventStatusBuffer",
\r
335 * if not found NULL is returned.
\r
337 static void lookupEventStatusRec(Dem_EventIdType eventId, EventStatusRecType **const eventStatusRec)
\r
340 boolean eventIdFound = FALSE;
\r
342 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!eventIdFound); i++) {
\r
343 eventIdFound = (eventStatusBuffer[i].eventId == eventId);
\r
346 if (eventIdFound) {
\r
347 *eventStatusRec = &eventStatusBuffer[i-1];
\r
349 *eventStatusRec = NULL;
\r
355 * Procedure: lookupEventIdParameter
\r
356 * Description: Returns the pointer to event id parameters of "eventId" in "*eventIdParam",
\r
357 * if not found NULL is returned.
\r
359 static void lookupEventIdParameter(Dem_EventIdType eventId, const Dem_EventParameterType **const eventIdParam)
\r
361 const Dem_EventParameterType *EventIdParamList = configSet->EventParameter;
\r
363 // Lookup the correct event id parameters
\r
365 while ((EventIdParamList[i].EventID != eventId) && (!EventIdParamList[i].Arc_EOL)) {
\r
369 if (!EventIdParamList[i].Arc_EOL) {
\r
370 *eventIdParam = &EventIdParamList[i];
\r
372 *eventIdParam = NULL;
\r
378 * Procedure: preDebounceNone
\r
379 * Description: Returns the result of the debouncing.
\r
381 static Dem_EventStatusType preDebounceNone(const Dem_EventStatusType reportedStatus, const EventStatusRecType* statusRecord) {
\r
382 Dem_EventStatusType returnCode;
\r
383 (void)statusRecord; // Just to get rid of PC-Lint warnings
\r
385 switch (reportedStatus) {
\r
386 case DEM_EVENT_STATUS_FAILED: /** @req DEM091.NoneFailed */
\r
387 case DEM_EVENT_STATUS_PASSED: /** @req DEM091.NonePassed */
\r
388 // Already debounced, do nothing.
\r
392 // TODO: What to do with PREFAIL and PREPASSED on no debouncing?
\r
393 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_NONE_ID, DEM_E_PARAM_DATA);
\r
397 returnCode = reportedStatus;
\r
403 * Procedure: preDebounceCounterBased
\r
404 * Description: Returns the result of the debouncing.
\r
406 static Dem_EventStatusType preDebounceCounterBased(Dem_EventStatusType reportedStatus, EventStatusRecType* statusRecord) {
\r
407 Dem_EventStatusType returnCode;
\r
408 const Dem_PreDebounceCounterBasedType* pdVars = statusRecord->eventParamRef->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceCounterBased;
\r
410 switch (reportedStatus) {
\r
411 case DEM_EVENT_STATUS_PREFAILED:
\r
412 if (statusRecord->faultDetectionCounter < DEBOUNCE_FDC_TEST_FAILED) {
\r
413 if ((pdVars->JumpUp) && (statusRecord->faultDetectionCounter < 0)) {
\r
414 statusRecord->faultDetectionCounter = 0;
\r
416 if (((sint16)statusRecord->faultDetectionCounter + (sint8)pdVars->CountInStepSize) < DEBOUNCE_FDC_TEST_FAILED) {
\r
417 statusRecord->faultDetectionCounter += (sint8)pdVars->CountInStepSize;
\r
419 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED;
\r
425 case DEM_EVENT_STATUS_PREPASSED:
\r
426 if (statusRecord->faultDetectionCounter > DEBOUNCE_FDC_TEST_PASSED) {
\r
427 if ((pdVars->JumpDown) && (statusRecord->faultDetectionCounter > 0)) {
\r
428 statusRecord->faultDetectionCounter = 0;
\r
430 if (((sint16)statusRecord->faultDetectionCounter - (sint8)pdVars->CountOutStepSize) > DEBOUNCE_FDC_TEST_PASSED) {
\r
431 statusRecord->faultDetectionCounter -= (sint8)pdVars->CountOutStepSize;
\r
433 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED;
\r
439 case DEM_EVENT_STATUS_FAILED:
\r
440 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED; /** @req DEM091.CounterFailed */
\r
443 case DEM_EVENT_STATUS_PASSED:
\r
444 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED; /** @req DEM091.CounterPassed */
\r
448 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_COUNTER_BASED_ID, DEM_E_PARAM_DATA);
\r
453 switch (statusRecord->faultDetectionCounter) {
\r
454 case DEBOUNCE_FDC_TEST_FAILED:
\r
455 returnCode = DEM_EVENT_STATUS_FAILED;
\r
458 case DEBOUNCE_FDC_TEST_PASSED:
\r
459 returnCode = DEM_EVENT_STATUS_PASSED;
\r
463 returnCode = reportedStatus;
\r
472 * Procedure: updateEventStatusRec
\r
473 * Description: Update the status of "eventId", if not exist and "createIfNotExist" is
\r
474 * true a new record is created
\r
476 static void updateEventStatusRec(const Dem_EventParameterType *eventParam, Dem_EventStatusType eventStatus, boolean createIfNotExist, EventStatusRecType *eventStatusRec)
\r
478 EventStatusRecType *eventStatusRecPtr;
\r
479 imask_t state = McuE_EnterCriticalSection();
\r
482 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
484 if ((eventStatusRecPtr == NULL) && (createIfNotExist)) {
\r
485 // Search for free position
\r
486 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
488 if (eventStatusRecPtr != NULL) {
\r
489 // Create new event record
\r
490 eventStatusRecPtr->eventId = eventParam->EventID;
\r
491 eventStatusRecPtr->eventParamRef = eventParam;
\r
492 eventStatusRecPtr->faultDetectionCounter = 0;
\r
493 eventStatusRecPtr->occurrence = 0;
\r
494 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
495 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
498 // Error: Event status buffer full
\r
499 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
504 if (eventStatusRecPtr != NULL) {
\r
505 // Handle debouncing
\r
506 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
507 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName) { /** @req DEM004 */ /** @req DEM342 */
\r
508 case DEM_NO_PRE_DEBOUNCE:
\r
509 eventStatus = preDebounceNone(eventStatus, eventStatusRecPtr);
\r
512 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
513 eventStatus = preDebounceCounterBased(eventStatus, eventStatusRecPtr);
\r
517 // Don't know how to handle this.
\r
518 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
523 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
525 // Check test failed
\r
526 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
527 if (!(eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED)) {
\r
528 eventStatusRecPtr->occurrence++;
\r
529 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
531 /** @req DEM036 */ /** @req DEM379.PendingSet */
\r
532 eventStatusRecPtr->eventStatusExtended |= (DEM_TEST_FAILED | DEM_TEST_FAILED_THIS_OPERATION_CYCLE | DEM_TEST_FAILED_SINCE_LAST_CLEAR | DEM_PENDING_DTC);
\r
533 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
536 // Check test passed
\r
537 if (eventStatus == DEM_EVENT_STATUS_PASSED) {
\r
538 if (eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED) {
\r
539 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
542 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED;
\r
543 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
547 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
550 // Copy an empty record to return data
\r
551 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
552 eventStatusRec->faultDetectionCounter = 0;
\r
553 eventStatusRec->occurrence = 0;
\r
554 eventStatusRec->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
555 eventStatusRec->errorStatusChanged = FALSE;
\r
558 McuE_ExitCriticalSection(state);
\r
563 * Procedure: mergeEventStatusRec
\r
564 * Description: Update the occurrence counter of status, if not exist a new record is created
\r
566 static void mergeEventStatusRec(const EventRecType *eventRec)
\r
568 EventStatusRecType *eventStatusRecPtr;
\r
569 imask_t state = McuE_EnterCriticalSection();
\r
572 lookupEventStatusRec(eventRec->eventId, &eventStatusRecPtr);
\r
574 if (eventStatusRecPtr != NULL) {
\r
575 // Update occurrence counter, rest of pre init state is kept.
\r
576 eventStatusRecPtr->occurrence += eventRec->occurrence;
\r
580 // Search for free position
\r
581 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
583 if (eventStatusRecPtr != NULL) {
\r
584 // Create new event, from stored event
\r
585 eventStatusRecPtr->eventId = eventRec->eventId;
\r
586 lookupEventIdParameter(eventRec->eventId, &eventStatusRecPtr->eventParamRef);
\r
587 eventStatusRecPtr->faultDetectionCounter = 0;
\r
588 eventStatusRecPtr->occurrence = eventRec->occurrence;
\r
589 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
590 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
593 // Error: Event status buffer full
\r
594 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_MERGE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
598 McuE_ExitCriticalSection(state);
\r
603 * Procedure: deleteEventStatusRec
\r
604 * Description: Delete the status record of "eventParam->eventId" from "eventStatusBuffer".
\r
606 static void deleteEventStatusRec(const Dem_EventParameterType *eventParam)
\r
608 EventStatusRecType *eventStatusRecPtr;
\r
609 imask_t state = McuE_EnterCriticalSection();
\r
612 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
614 if (eventStatusRecPtr != NULL) {
\r
615 // Delete event record
\r
616 memset(eventStatusRecPtr, 0, sizeof(EventStatusRecType));
\r
619 McuE_ExitCriticalSection(state);
\r
624 * Procedure: getEventStatusRec
\r
625 * Description: Returns the status record of "eventId" in "eventStatusRec"
\r
627 static void getEventStatusRec(Dem_EventIdType eventId, EventStatusRecType *eventStatusRec)
\r
629 EventStatusRecType *eventStatusRecPtr;
\r
632 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
634 if (eventStatusRecPtr != NULL) {
\r
636 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
639 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
645 * Procedure: lookupDtcEvent
\r
646 * Description: Returns TRUE if the DTC was found and "eventStatusRec" points
\r
647 * to the event record found.
\r
649 static boolean lookupDtcEvent(uint32 dtc, EventStatusRecType **eventStatusRec)
\r
651 boolean dtcFound = FALSE;
\r
654 *eventStatusRec = NULL;
\r
656 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!dtcFound); i++) {
\r
657 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
658 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
661 if (eventStatusBuffer[i].eventParamRef->DTCClassRef->DTC == dtc) {
\r
662 *eventStatusRec = &eventStatusBuffer[i];
\r
674 * Procedure: matchEventWithDtcFilter
\r
675 * Description: Returns TRUE if the event pointed by "event" fulfill
\r
676 * the "dtcFilter" global filter settings.
\r
678 static boolean matchEventWithDtcFilter(const EventStatusRecType *eventRec)
\r
680 boolean dtcMatch = FALSE;
\r
683 if ((dtcFilter.dtcStatusMask == DEM_DTC_STATUS_MASK_ALL) || (eventRec->eventStatusExtended & dtcFilter.dtcStatusMask)) {
\r
684 if (eventRec->eventParamRef != NULL) {
\r
687 if (checkDtcKind(dtcFilter.dtcKind, eventRec->eventParamRef)) {
\r
690 if (checkDtcOrigin(dtcFilter.dtcOrigin, eventRec->eventParamRef)) {
\r
693 if ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
694 || ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES) && (checkDtcSeverityMask(dtcFilter.dtcSeverityMask, eventRec->eventParamRef)))) {
\r
696 // Check fault detection counter
\r
697 if ((dtcFilter.filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO)
\r
698 || ((dtcFilter.filterWithSeverity == DEM_FILTER_FOR_FDC_YES) && (checkDtcFaultDetectionCounter(eventRec->eventParamRef)))) {
\r
711 // PC-Lint (715 etc): Remove errors until function is filled.
\r
712 //lint -e{715} Symbol not referenced
\r
713 static void getFreezeFrameData(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
716 freezeFrame->eventId = DEM_EVENT_ID_NULL; // Not supported yet
\r
720 // PC-Lint (715 etc): Remove errors until function is filled.
\r
721 //lint -e{715} Symbol not referenced
\r
722 static void storeFreezeFrameDataPreInit(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
728 // PC-Lint (715 etc): Remove errors until function is filled.
\r
729 //lint -e{715} Symbol not referenced
\r
730 static void updateFreezeFrameOccurrencePreInit(const EventRecType *EventBuffer)
\r
737 * Procedure: getExtendedData
\r
738 * Description: Collects the extended data according to "eventParam" and return it in "extData",
\r
739 * if not found eventId is set to DEM_EVENT_ID_NULL.
\r
741 static void getExtendedData(const Dem_EventParameterType *eventParam, ExtDataRecType *extData)
\r
743 Std_ReturnType callbackReturnCode;
\r
745 uint16 storeIndex = 0;
\r
748 // Clear ext data record
\r
749 memset(extData, 0, sizeof(ExtDataRecType));
\r
751 // Check if any pointer to extended data class
\r
752 if (eventParam->ExtendedDataClassRef != NULL) {
\r
753 // Request extended data and copy it to the buffer
\r
754 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL); i++) {
\r
755 recordSize = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
756 if ((storeIndex + recordSize) <= DEM_MAX_SIZE_EXT_DATA) {
\r
757 callbackReturnCode = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->CallbackGetExtDataRecord(&extData->data[storeIndex]); /** @req DEM282 */
\r
758 if (callbackReturnCode != E_OK) {
\r
759 // Callback data currently not available, clear space.
\r
760 memset(&extData->data[storeIndex], 0xFF, recordSize);
\r
762 storeIndex += recordSize;
\r
765 // Error: Size of extended data record is bigger than reserved space.
\r
766 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GET_EXTENDED_DATA_ID, DEM_E_EXT_DATA_TOO_BIG);
\r
767 break; // Break the loop
\r
772 // Check if any data has been stored
\r
773 if (storeIndex != 0) {
\r
774 extData->eventId = eventParam->EventID;
\r
775 extData->dataSize = storeIndex;
\r
776 extData->checksum = calcChecksum(extData, sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
779 extData->eventId = DEM_EVENT_ID_NULL;
\r
780 extData->dataSize = storeIndex;
\r
781 extData->checksum = 0;
\r
787 * Procedure: storeExtendedDataPreInit
\r
788 * Description: Store the extended data pointed by "extendedData" to the "preInitExtDataBuffer",
\r
789 * if non existent a new entry is created.
\r
791 static void storeExtendedDataPreInit(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
793 boolean eventIdFound = FALSE;
\r
794 boolean eventIdFreePositionFound=FALSE;
\r
796 imask_t state = McuE_EnterCriticalSection();
\r
798 // Check if already stored
\r
799 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) && (!eventIdFound); i++){
\r
800 eventIdFound = (preInitExtDataBuffer[i].eventId == eventParam->EventID);
\r
804 // Yes, overwrite existing
\r
805 memcpy(&preInitExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
808 // No, lookup first free position
\r
809 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) && (!eventIdFreePositionFound); i++){
\r
810 if(preInitExtDataBuffer[i].eventId ==0){
\r
811 eventIdFreePositionFound=TRUE;
\r
815 if (eventIdFreePositionFound) {
\r
816 memcpy(&preInitExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
819 // Error: Pre init extended data buffer full
\r
820 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRE_INIT_ID, DEM_E_PRE_INIT_EXT_DATA_BUFF_FULL);
\r
824 McuE_ExitCriticalSection(state);
\r
828 * Procedure: storeEventPriMem
\r
829 * Description: Store the event data of "eventStatus->eventId" in "priMemEventBuffer",
\r
830 * if non existent a new entry is created.
\r
832 static void storeEventPriMem(const Dem_EventParameterType *eventParam, const EventStatusRecType *eventStatus)
\r
834 boolean eventIdFound = FALSE;
\r
835 boolean eventIdFreePositionFound=FALSE;
\r
837 imask_t state = McuE_EnterCriticalSection();
\r
839 (void)*eventParam; // Currently not used, do this to avoid warning
\r
842 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
843 eventIdFound = (priMemEventBuffer[i].eventId == eventStatus->eventId);
\r
846 if (eventIdFound) {
\r
847 // Update event found
\r
848 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
849 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
852 // Search for free position
\r
853 for (i=0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFreePositionFound); i++){
\r
854 eventIdFreePositionFound = (priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
858 if (eventIdFreePositionFound) {
\r
859 priMemEventBuffer[i-1].eventId = eventStatus->eventId;
\r
860 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
861 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
864 // Error: Pri mem event buffer full
\r
865 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EVENT_PRI_MEM_ID, DEM_E_PRI_MEM_EVENT_BUFF_FULL);
\r
869 McuE_ExitCriticalSection(state);
\r
873 * Procedure: deleteEventPriMem
\r
874 * Description: Delete the event data of "eventParam->eventId" from "priMemEventBuffer".
\r
876 static void deleteEventPriMem(const Dem_EventParameterType *eventParam)
\r
878 boolean eventIdFound = FALSE;
\r
880 imask_t state = McuE_EnterCriticalSection();
\r
884 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
885 eventIdFound = (priMemEventBuffer[i].eventId == eventParam->EventID);
\r
888 if (eventIdFound) {
\r
889 // Delete event found
\r
890 memset(&priMemEventBuffer[i-1], 0, sizeof(EventRecType));
\r
893 McuE_ExitCriticalSection(state);
\r
897 * Procedure: storeEventEvtMem
\r
898 * Description: Store the event data of "eventStatus->eventId" in event memory according to
\r
899 * "eventParam" destination option.
\r
901 static void storeEventEvtMem(const Dem_EventParameterType *eventParam, const EventStatusRecType *eventStatus)
\r
905 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION)
\r
906 && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
907 switch (eventParam->EventClass->EventDestination[i])
\r
909 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
910 storeEventPriMem(eventParam, eventStatus); /** @req DEM010 */
\r
913 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
914 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
915 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
916 // Not yet supported
\r
917 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
927 * Procedure: storeExtendedDataPriMem
\r
928 * Description: Store the extended data pointed by "extendedData" to the "priMemExtDataBuffer",
\r
929 * if non existent a new entry is created.
\r
931 static void storeExtendedDataPriMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData) /** @req DEM041 */
\r
933 boolean eventIdFound = FALSE;
\r
934 boolean eventIdFreePositionFound=FALSE;
\r
936 imask_t state = McuE_EnterCriticalSection();
\r
938 // Check if already stored
\r
939 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
940 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
943 if (eventIdFound) {
\r
944 // Yes, overwrite existing
\r
945 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
948 // No, lookup first free position
\r
949 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFreePositionFound); i++){
\r
950 eventIdFreePositionFound = (priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
952 if (eventIdFreePositionFound) {
\r
953 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
956 // Error: Pri mem extended data buffer full
\r
957 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRI_MEM_ID, DEM_E_PRI_MEM_EXT_DATA_BUFF_FULL);
\r
961 McuE_ExitCriticalSection(state);
\r
965 * Procedure: deleteExtendedDataPriMem
\r
966 * Description: Delete the extended data of "eventParam->eventId" from "priMemExtDataBuffer".
\r
968 static void deleteExtendedDataPriMem(const Dem_EventParameterType *eventParam)
\r
970 boolean eventIdFound = FALSE;
\r
972 imask_t state = McuE_EnterCriticalSection();
\r
974 // Check if already stored
\r
975 for (i = 0;(i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
976 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
979 if (eventIdFound) {
\r
980 // Yes, clear record
\r
981 memset(&priMemExtDataBuffer[i-1], 0, sizeof(ExtDataRecType));
\r
984 McuE_ExitCriticalSection(state);
\r
988 * Procedure: storeExtendedDataEvtMem
\r
989 * Description: Store the extended data in event memory according to
\r
990 * "eventParam" destination option
\r
992 static void storeExtendedDataEvtMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
996 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
997 switch (eventParam->EventClass->EventDestination[i])
\r
999 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1000 storeExtendedDataPriMem(eventParam, extendedData);
\r
1003 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1004 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1005 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1006 // Not yet supported
\r
1007 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1018 * Procedure: lookupExtendedDataRecNumParam
\r
1019 * Description: Returns TRUE if the requested extended data number was found among the configured records for the event.
\r
1020 * "extDataRecClassPtr" returns a pointer to the record class, "posInExtData" returns the position in stored extended data.
\r
1022 static boolean lookupExtendedDataRecNumParam(uint8 extendedDataNumber, const Dem_EventParameterType *eventParam, Dem_ExtendedDataRecordClassType const **extDataRecClassPtr, uint16 *posInExtData)
\r
1024 boolean recNumFound = FALSE;
\r
1026 if (eventParam->ExtendedDataClassRef != NULL) {
\r
1027 uint16 byteCnt = 0;
\r
1030 // Request extended data and copy it to the buffer
\r
1031 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL) && (!recNumFound); i++) {
\r
1032 if (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->RecordNumber == extendedDataNumber) {
\r
1033 *extDataRecClassPtr = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i];
\r
1034 *posInExtData = byteCnt;
\r
1035 recNumFound = TRUE;
\r
1037 byteCnt += eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
1041 return recNumFound;
\r
1046 * Procedure: lookupExtendedDataPriMem
\r
1047 * Description: Returns TRUE if the requested event id is found, "extData" points to the found data.
\r
1049 static boolean lookupExtendedDataPriMem(Dem_EventIdType eventId, ExtDataRecType **extData)
\r
1051 boolean eventIdFound = FALSE;
\r
1054 // Lookup corresponding extended data
\r
1055 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++) {
\r
1056 eventIdFound = (priMemExtDataBuffer[i].eventId == eventId);
\r
1059 if (eventIdFound) {
\r
1060 // Yes, return pointer
\r
1061 *extData = &priMemExtDataBuffer[i-1];
\r
1064 return eventIdFound;
\r
1067 // PC-Lint (715 etc): Remove errors until function is filled.
\r
1068 //lint -e{715} Symbol not referenced
\r
1069 static void storeFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1075 // PC-Lint (715 etc): Remove errors until function is filled.
\r
1076 //lint -e{715} Symbol not referenced
\r
1077 static void deleteFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam)
\r
1084 * Procedure: storeFreezeFrameDataEvtMem
\r
1085 * Description: Store the freeze frame data in event memory according to
\r
1086 * "eventParam" destination option
\r
1088 static void storeFreezeFrameDataEvtMem(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1092 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
1093 switch (eventParam->EventClass->EventDestination[i])
\r
1095 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1096 storeFreezeFrameDataPriMem(eventParam, freezeFrame);
\r
1099 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1100 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1101 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1102 // Not yet supported
\r
1103 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1114 * Procedure: handlePreInitEvent
\r
1115 * Description: Handle the updating of event status and storing of
\r
1116 * event related data in preInit buffers.
\r
1118 static void handlePreInitEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1120 const Dem_EventParameterType *eventParam;
\r
1121 EventStatusRecType eventStatusLocal;
\r
1122 FreezeFrameRecType freezeFrameLocal;
\r
1123 ExtDataRecType extendedDataLocal;
\r
1125 // Find configuration for this event
\r
1126 lookupEventIdParameter(eventId, &eventParam);
\r
1127 if (eventParam != NULL) {
\r
1128 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1129 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1130 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
1131 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1134 updateEventStatusRec(eventParam, eventStatus, FALSE, &eventStatusLocal);
\r
1137 if (eventStatusLocal.errorStatusChanged) {
\r
1139 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1140 // Collect freeze frame data
\r
1141 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1142 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1143 storeFreezeFrameDataPreInit(eventParam, &freezeFrameLocal);
\r
1146 // Collect extended data
\r
1147 getExtendedData(eventParam, &extendedDataLocal);
\r
1148 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1149 storeExtendedDataPreInit(eventParam, &extendedDataLocal);
\r
1155 // Operation cycle not started
\r
1156 // TODO: Report error?
\r
1160 // Operation cycle not set
\r
1161 // TODO: Report error?
\r
1165 // Event ID not configured
\r
1166 // TODO: Report error?
\r
1172 * Procedure: handleEvent
\r
1173 * Description: Handle the updating of event status and storing of
\r
1174 * event related data in event memory.
\r
1176 static Std_ReturnType handleEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1178 Std_ReturnType returnCode = E_OK;
\r
1179 const Dem_EventParameterType *eventParam;
\r
1180 EventStatusRecType eventStatusLocal;
\r
1181 FreezeFrameRecType freezeFrameLocal;
\r
1182 ExtDataRecType extendedDataLocal;
\r
1184 // Find configuration for this event
\r
1185 lookupEventIdParameter(eventId, &eventParam);
\r
1186 if (eventParam != NULL) {
\r
1187 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1188 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1189 if ((!((disableDtcStorage.storageDisabled) && (checkDtcGroup(disableDtcStorage.dtcGroup, eventParam)) && (checkDtcKind(disableDtcStorage.dtcKind, eventParam))))) {
\r
1190 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1191 if (eventStatusLocal.errorStatusChanged) {
\r
1192 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1193 storeEventEvtMem(eventParam, &eventStatusLocal); /** @req DEM184 */
\r
1194 // Collect freeze frame data
\r
1195 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1196 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1197 storeFreezeFrameDataEvtMem(eventParam, &freezeFrameLocal); /** @req DEM190 */
\r
1200 // Collect extended data
\r
1201 getExtendedData(eventParam, &extendedDataLocal);
\r
1202 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL)
\r
1204 storeExtendedDataEvtMem(eventParam, &extendedDataLocal);
\r
1211 // Operation cycle not started
\r
1212 returnCode = E_NOT_OK;
\r
1216 // Operation cycle not set
\r
1217 returnCode = E_NOT_OK;
\r
1221 // Event ID not configured
\r
1222 returnCode = E_NOT_OK;
\r
1225 return returnCode;
\r
1230 * Procedure: resetEventStatus
\r
1231 * Description: Resets the events status of eventId.
\r
1233 static void resetEventStatus(Dem_EventIdType eventId)
\r
1235 imask_t state = McuE_EnterCriticalSection();
\r
1236 EventStatusRecType *eventStatusRecPtr;
\r
1238 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
1239 if (eventStatusRecPtr != NULL) {
\r
1240 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED; /** @req DEM187 */
\r
1243 McuE_ExitCriticalSection(state);
\r
1248 * Procedure: getEventStatus
\r
1249 * Description: Returns the extended event status bitmask of eventId in "eventStatusExtended".
\r
1251 static void getEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended)
\r
1253 EventStatusRecType eventStatusLocal;
\r
1255 // Get recorded status
\r
1256 getEventStatusRec(eventId, &eventStatusLocal);
\r
1257 if (eventStatusLocal.eventId == eventId) {
\r
1258 *eventStatusExtended = eventStatusLocal.eventStatusExtended; /** @req DEM051 */
\r
1261 // Event Id not found, no report received.
\r
1262 *eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1268 * Procedure: getEventFailed
\r
1269 * Description: Returns the TRUE or FALSE of "eventId" in "eventFailed" depending on current status.
\r
1271 static void getEventFailed(Dem_EventIdType eventId, boolean *eventFailed)
\r
1273 EventStatusRecType eventStatusLocal;
\r
1275 // Get recorded status
\r
1276 getEventStatusRec(eventId, &eventStatusLocal);
\r
1277 if (eventStatusLocal.eventId == eventId) {
\r
1278 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) { /** @req DEM052 */
\r
1279 *eventFailed = TRUE;
\r
1282 *eventFailed = FALSE;
\r
1286 // Event Id not found, assume ok.
\r
1287 *eventFailed = FALSE;
\r
1293 * Procedure: getEventTested
\r
1294 * Description: Returns the TRUE or FALSE of "eventId" in "eventTested" depending on
\r
1295 * current status the "test not completed this operation cycle" bit.
\r
1297 static void getEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1299 EventStatusRecType eventStatusLocal;
\r
1301 // Get recorded status
\r
1302 getEventStatusRec(eventId, &eventStatusLocal);
\r
1303 if (eventStatusLocal.eventId == eventId) {
\r
1304 if ( !(eventStatusLocal.eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE)) { /** @req DEM053 */
\r
1305 *eventTested = TRUE;
\r
1308 *eventTested = FALSE;
\r
1312 // Event Id not found, not tested.
\r
1313 *eventTested = FALSE;
\r
1319 * Procedure: getFaultDetectionCounter
\r
1320 * Description: Returns pre debounce counter of "eventId" in "counter" and return value E_OK if
\r
1321 * the counter was available else E_NOT_OK.
\r
1323 static Std_ReturnType getFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1325 Std_ReturnType returnCode = E_NOT_OK;
\r
1326 const Dem_EventParameterType *eventParam;
\r
1328 lookupEventIdParameter(eventId, &eventParam);
\r
1329 if (eventParam != NULL) {
\r
1330 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
1331 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName)
\r
1333 case DEM_NO_PRE_DEBOUNCE:
\r
1334 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal != NULL) {
\r
1335 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc != NULL) {
\r
1336 returnCode = eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc(counter); /** @req DEM204.None */ /** @req DEM264 */ /** @req DEM265 */
\r
1341 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
1343 EventStatusRecType *eventStatusRec;
\r
1345 lookupEventStatusRec(eventId, &eventStatusRec);
\r
1346 if (eventStatusRec != NULL) {
\r
1347 *counter = eventStatusRec->faultDetectionCounter; /** @req DEM204.Counter */
\r
1351 returnCode = E_OK;
\r
1355 case DEM_PRE_DEBOUNCE_FREQUENCY_BASED:
\r
1356 case DEM_PRE_DEBOUNCE_TIME_BASED:
\r
1357 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1361 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_PARAM_DATA);
\r
1367 return returnCode;
\r
1372 * Procedure: setOperationCycleState
\r
1373 * Description: Change the operation state of "operationCycleId" to "cycleState" and updates stored
\r
1374 * event connected to this cycle id.
\r
1375 * Returns E_OK if operation was successful else E_NOT_OK.
\r
1377 static Std_ReturnType setOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState) /** @req DEM338 */
\r
1380 Std_ReturnType returnCode = E_OK;
\r
1382 if (operationCycleId < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1383 switch (cycleState)
\r
1385 case DEM_CYCLE_STATE_START:
\r
1386 operationCycleStateList[operationCycleId] = cycleState;
\r
1387 // Lookup event ID
\r
1388 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1389 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1390 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED_THIS_OPERATION_CYCLE;
\r
1391 eventStatusBuffer[i].eventStatusExtended |= DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
1396 case DEM_CYCLE_STATE_END:
\r
1397 operationCycleStateList[operationCycleId] = cycleState;
\r
1398 // Lookup event ID
\r
1399 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1400 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1401 if ((!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_FAILED_THIS_OPERATION_CYCLE)) && (!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE))) {
\r
1402 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_PENDING_DTC; // Clear pendingDTC bit /** @req DEM379.PendingClear
\r
1408 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
1409 returnCode = E_NOT_OK;
\r
1414 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
1415 returnCode = E_NOT_OK;
\r
1418 return returnCode;
\r
1422 //==============================================================================//
\r
1424 // E X T E R N A L F U N C T I O N S //
\r
1426 //==============================================================================//
\r
1428 /*********************************************
\r
1429 * Interface for upper layer modules (8.3.1) *
\r
1430 *********************************************/
\r
1433 * Procedure: Dem_GetVersionInfo
\r
1436 // Defined in Dem.h
\r
1439 /***********************************************
\r
1440 * Interface ECU State Manager <-> DEM (8.3.2) *
\r
1441 ***********************************************/
\r
1444 * Procedure: Dem_PreInit
\r
1447 void Dem_PreInit(void)
\r
1449 /** @req DEM180 */
\r
1452 VALIDATE_NO_RV(DEM_Config.ConfigSet != NULL, DEM_PREINIT_ID, DEM_E_CONFIG_PTR_INVALID);
\r
1454 configSet = DEM_Config.ConfigSet;
\r
1456 // Initializion of operation cycle states.
\r
1457 for (i = 0; i < DEM_OPERATION_CYCLE_ID_ENDMARK; i++) {
\r
1458 operationCycleStateList[i] = DEM_CYCLE_STATE_END;
\r
1461 // Initialize the event status buffer
\r
1462 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1463 eventStatusBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1464 eventStatusBuffer[i].eventParamRef = NULL;
\r
1465 eventStatusBuffer[i].faultDetectionCounter = 0;
\r
1466 eventStatusBuffer[i].occurrence = 0;
\r
1467 eventStatusBuffer[i].eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1468 eventStatusBuffer[i].errorStatusChanged = FALSE;
\r
1471 // Initialize the pre init buffers
\r
1472 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1473 preInitFreezeFrameBuffer[i].checksum = 0;
\r
1474 preInitFreezeFrameBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1475 preInitFreezeFrameBuffer[i].occurrence = 0;
\r
1476 preInitFreezeFrameBuffer[i].dataSize = 0;
\r
1477 for (j = 0; j < DEM_MAX_SIZE_FF_DATA;j++){
\r
1478 preInitFreezeFrameBuffer[i].data[j] = 0;
\r
1482 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1483 preInitExtDataBuffer[i].checksum = 0;
\r
1484 preInitExtDataBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1485 preInitExtDataBuffer[i].dataSize = 0;
\r
1486 for (j = 0; j < DEM_MAX_SIZE_EXT_DATA;j++){
\r
1487 preInitExtDataBuffer[i].data[j] = 0;
\r
1491 disableDtcStorage.storageDisabled = FALSE;
\r
1493 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_START); /** @req DEM047 */
\r
1495 demState = DEM_PREINITIALIZED;
\r
1500 * Procedure: Dem_Init
\r
1503 void Dem_Init(void)
\r
1506 ChecksumType cSum;
\r
1507 const Dem_EventParameterType *eventParam;
\r
1510 * Validate and read out saved error log from non volatile memory
\r
1513 // Validate event records stored in primary memory
\r
1514 for (i = 0; i < DEM_MAX_NUMBER_EVENT_PRI_MEM; i++) {
\r
1515 cSum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
1516 if ((cSum != priMemEventBuffer[i].checksum) || (priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1517 // Unlegal record, clear the record
\r
1518 memset(&priMemEventBuffer[i], 0, sizeof(EventRecType));
\r
1521 // Valid, update current status
\r
1522 mergeEventStatusRec(&priMemEventBuffer[i]);
\r
1524 // Update occurrence counter on pre init stored freeze frames
\r
1525 updateFreezeFrameOccurrencePreInit(&priMemEventBuffer[i]);
\r
1529 // Validate extended data records stored in primary memory
\r
1530 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM; i++) {
\r
1531 cSum = calcChecksum(&priMemExtDataBuffer[i], sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
1532 if ((cSum != priMemExtDataBuffer[i].checksum) || (priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1533 // Unlegal record, clear the record
\r
1534 memset(&priMemExtDataBuffer[i], 0, sizeof(ExtDataRecType));
\r
1538 // Validate freeze frame records stored in primary memory
\r
1539 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++) {
\r
1540 cSum = calcChecksum(&priMemFreezeFrameBuffer[i], sizeof(FreezeFrameRecType)-sizeof(ChecksumType));
\r
1541 if ((cSum != priMemFreezeFrameBuffer[i].checksum) || (priMemFreezeFrameBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1542 // Unlegal record, clear the record
\r
1543 memset(&priMemFreezeFrameBuffer[i], 0, sizeof(FreezeFrameRecType));
\r
1548 * Handle errors stored in temporary buffer (if any)
\r
1551 // Transfer updated event data to event memory
\r
1552 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1553 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1554 // Update the event memory
\r
1555 lookupEventIdParameter(eventStatusBuffer[i].eventId, &eventParam);
\r
1556 storeEventEvtMem(eventParam, &eventStatusBuffer[i]);
\r
1560 // Transfer extended data to event memory if necessary
\r
1561 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1562 if (preInitExtDataBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1563 lookupEventIdParameter(preInitExtDataBuffer[i].eventId, &eventParam);
\r
1564 storeExtendedDataEvtMem(eventParam, &preInitExtDataBuffer[i]);
\r
1568 // Transfer freeze frames to event memory
\r
1569 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1570 if (preInitFreezeFrameBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1571 lookupEventIdParameter(preInitFreezeFrameBuffer[i].eventId, &eventParam);
\r
1572 storeFreezeFrameDataEvtMem(eventParam, &preInitFreezeFrameBuffer[i]);
\r
1576 // Init the dtc filter
\r
1577 dtcFilter.dtcStatusMask = DEM_DTC_STATUS_MASK_ALL; // All allowed
\r
1578 dtcFilter.dtcKind = DEM_DTC_KIND_ALL_DTCS; // All kinds of DTCs
\r
1579 dtcFilter.dtcOrigin = DEM_DTC_ORIGIN_PRIMARY_MEMORY; // Primary memory
\r
1580 dtcFilter.filterWithSeverity = DEM_FILTER_WITH_SEVERITY_NO; // No Severity filtering
\r
1581 dtcFilter.dtcSeverityMask = DEM_SEVERITY_NO_SEVERITY; // Not used when filterWithSeverity is FALSE
\r
1582 dtcFilter.filterForFaultDetectionCounter = DEM_FILTER_FOR_FDC_NO; // No fault detection counter filtering
\r
1584 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1586 disableDtcStorage.storageDisabled = FALSE;
\r
1588 demState = DEM_INITIALIZED;
\r
1593 * Procedure: Dem_shutdown
\r
1596 void Dem_Shutdown(void)
\r
1598 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_END); /** @req DEM047 */
\r
1600 demState = DEM_UNINITIALIZED; /** @req DEM368 */
\r
1605 * Interface for basic software scheduler
\r
1607 void Dem_MainFunction(void)
\r
1609 /** @req DEM125 */
\r
1614 /***************************************************
\r
1615 * Interface SW-Components via RTE <-> DEM (8.3.3) *
\r
1616 ***************************************************/
\r
1619 * Procedure: Dem_SetEventStatus
\r
1622 Std_ReturnType Dem_SetEventStatus(Dem_EventIdType eventId, Dem_EventStatusType eventStatus) /** @req DEM330 */
\r
1624 Std_ReturnType returnCode = E_OK;
\r
1626 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1628 returnCode = handleEvent(eventId, eventStatus);
\r
1632 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1633 returnCode = E_NOT_OK;
\r
1636 return returnCode;
\r
1641 * Procedure: Dem_ResetEventStatus
\r
1644 Std_ReturnType Dem_ResetEventStatus(Dem_EventIdType eventId) /** @req DEM331 */
\r
1646 Std_ReturnType returnCode = E_OK;
\r
1648 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1650 resetEventStatus(eventId); /** @req DEM186 */
\r
1654 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_RESETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1655 returnCode = E_NOT_OK;
\r
1658 return returnCode;
\r
1663 * Procedure: Dem_GetEventStatus
\r
1666 Std_ReturnType Dem_GetEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended) /** @req DEM332 */
\r
1668 Std_ReturnType returnCode = E_OK;
\r
1670 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1672 getEventStatus(eventId, eventStatusExtended);
\r
1676 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1677 returnCode = E_NOT_OK;
\r
1680 return returnCode;
\r
1685 * Procedure: Dem_GetEventFailed
\r
1688 Std_ReturnType Dem_GetEventFailed(Dem_EventIdType eventId, boolean *eventFailed) /** @req DEM333 */
\r
1690 Std_ReturnType returnCode = E_OK;
\r
1692 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1694 getEventFailed(eventId, eventFailed);
\r
1698 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTFAILED_ID, DEM_E_UNINIT);
\r
1699 returnCode = E_NOT_OK;
\r
1702 return returnCode;
\r
1707 * Procedure: Dem_GetEventTested
\r
1710 Std_ReturnType Dem_GetEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1712 Std_ReturnType returnCode = E_OK;
\r
1714 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1716 getEventTested(eventId, eventTested);
\r
1720 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTTESTED_ID, DEM_E_UNINIT);
\r
1721 returnCode = E_NOT_OK;
\r
1724 return returnCode;
\r
1729 * Procedure: Dem_GetFaultDetectionCounter
\r
1732 Std_ReturnType Dem_GetFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1734 Std_ReturnType returnCode = E_OK;
\r
1736 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1738 returnCode = getFaultDetectionCounter(eventId, counter);
\r
1742 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_UNINIT);
\r
1743 returnCode = E_NOT_OK;
\r
1746 return returnCode;
\r
1751 * Procedure: Dem_SetOperationCycleState
\r
1754 Std_ReturnType Dem_SetOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState)
\r
1756 Std_ReturnType returnCode = E_OK;
\r
1758 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1760 returnCode = setOperationCycleState(operationCycleId, cycleState);
\r
1765 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_UNINIT);
\r
1766 returnCode = E_NOT_OK;
\r
1769 return returnCode;
\r
1774 * Procedure: Dem_GetDTCOfEvent
\r
1777 Std_ReturnType Dem_GetDTCOfEvent(Dem_EventIdType eventId, Dem_DTCKindType dtcKind, uint32* dtcOfEvent)
\r
1779 Std_ReturnType returnCode = E_NO_DTC_AVAILABLE;
\r
1780 const Dem_EventParameterType *eventParam;
\r
1782 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1784 lookupEventIdParameter(eventId, &eventParam);
\r
1786 if (eventParam != NULL) {
\r
1787 if (checkDtcKind(dtcKind, eventParam)) {
\r
1788 if (eventParam->DTCClassRef != NULL) {
\r
1789 *dtcOfEvent = eventParam->DTCClassRef->DTC; /** @req DEM269 */
\r
1790 returnCode = E_OK;
\r
1795 // Event Id not found
\r
1796 returnCode = E_NOT_OK;
\r
1801 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETDTCOFEVENT_ID, DEM_UNINITIALIZED);
\r
1802 returnCode = E_NOT_OK;
\r
1805 return returnCode;
\r
1809 /********************************************
\r
1810 * Interface BSW-Components <-> DEM (8.3.4) *
\r
1811 ********************************************/
\r
1814 * Procedure: Dem_ReportErrorStatus
\r
1817 void Dem_ReportErrorStatus( Dem_EventIdType eventId, Dem_EventStatusType eventStatus ) /** @req DEM107 */
\r
1820 switch (demState) {
\r
1821 case DEM_PREINITIALIZED:
\r
1822 // Update status and check if is to be stored
\r
1823 if ((eventStatus == DEM_EVENT_STATUS_PASSED) || (eventStatus == DEM_EVENT_STATUS_FAILED)) {
\r
1824 handlePreInitEvent(eventId, eventStatus); /** @req DEM168 */
\r
1828 case DEM_INITIALIZED:
\r
1829 (void)handleEvent(eventId, eventStatus); /** @req DEM167 */
\r
1832 case DEM_UNINITIALIZED:
\r
1834 // Uninitialized can not do anything
\r
1835 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_REPORTERRORSTATUS_ID, DEM_E_UNINIT);
\r
1839 } // switch (demState)
\r
1842 /*********************************
\r
1843 * Interface DCM <-> DEM (8.3.5) *
\r
1844 *********************************/
\r
1846 * Procedure: Dem_GetDTCStatusAvailabilityMask
\r
1849 Std_ReturnType Dem_GetDTCStatusAvailabilityMask(uint8 *dtcStatusMask) /** @req DEM014 */
\r
1851 *dtcStatusMask = DEM_DTC_STATUS_AVAILABILITY_MASK; // User configuration mask
\r
1852 *dtcStatusMask &= DEM_TEST_FAILED // Mask with supported bits /** @req DEM060 */
\r
1853 | DEM_TEST_FAILED_THIS_OPERATION_CYCLE
\r
1855 // | DEM_CONFIRMED_DTC TODO: Add support for this bit
\r
1856 | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR
\r
1857 | DEM_TEST_FAILED_SINCE_LAST_CLEAR
\r
1858 | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE
\r
1859 // | DEM_WARNING_INDICATOR_REQUESTED TODO: Add support for this bit
\r
1867 * Procedure: Dem_SetDTCFilter
\r
1870 Dem_ReturnSetDTCFilterType Dem_SetDTCFilter(uint8 dtcStatusMask,
\r
1871 Dem_DTCKindType dtcKind,
\r
1872 Dem_DTCOriginType dtcOrigin,
\r
1873 Dem_FilterWithSeverityType filterWithSeverity,
\r
1874 Dem_DTCSeverityType dtcSeverityMask,
\r
1875 Dem_FilterForFDCType filterForFaultDetectionCounter)
\r
1877 Dem_ReturnSetDTCFilterType returnCode = DEM_FILTER_ACCEPTED;
\r
1879 if (demState == DEM_INITIALIZED) {
\r
1880 // Check dtcKind parameter
\r
1881 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
1883 // Check dtcOrigin parameter
\r
1884 VALIDATE_RV((dtcOrigin == DEM_DTC_ORIGIN_SECONDARY_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_PRIMARY_MEMORY)
\r
1885 || (dtcOrigin == DEM_DTC_ORIGIN_PERMANENT_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_MIRROR_MEMORY), DEM_SETDTCFILTER_ID, DEM_E_PARAM_DATA, DEM_WRONG_FILTER);
\r
1887 // Check filterWithSeverity and dtcSeverityMask parameter
\r
1888 VALIDATE_RV(((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
1889 || ((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES)
\r
1890 && (!(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
1892 // Check filterForFaultDetectionCounter parameter
\r
1893 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
1895 // Yes all parameters correct, set the new filters. /** @req DEM057 */
\r
1896 dtcFilter.dtcStatusMask = dtcStatusMask;
\r
1897 dtcFilter.dtcKind = dtcKind;
\r
1898 dtcFilter.dtcOrigin = dtcOrigin;
\r
1899 dtcFilter.filterWithSeverity = filterWithSeverity;
\r
1900 dtcFilter.dtcSeverityMask = dtcSeverityMask;
\r
1901 dtcFilter.filterForFaultDetectionCounter = filterForFaultDetectionCounter;
\r
1902 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1904 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETDTCFILTER_ID, DEM_E_UNINIT);
\r
1905 returnCode = DEM_WRONG_FILTER;
\r
1908 return returnCode;
\r
1913 * Procedure: Dem_GetStatusOfDTC
\r
1916 Dem_ReturnGetStatusOfDTCType Dem_GetStatusOfDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, Dem_EventStatusExtendedType* status) {
\r
1917 Dem_ReturnGetStatusOfDTCType returnCode = DEM_STATUS_FAILED;
\r
1918 EventStatusRecType *eventRec;
\r
1920 if (demState == DEM_INITIALIZED) {
\r
1921 if (lookupDtcEvent(dtc, &eventRec)) {
\r
1922 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
1923 if (checkDtcOrigin(dtcOrigin,eventRec->eventParamRef)) {
\r
1924 *status = eventRec->eventStatusExtended; /** @req DEM059 */
\r
1925 returnCode = DEM_STATUS_OK;
\r
1928 returnCode = DEM_STATUS_WRONG_DTCORIGIN; /** @req DEM171 */
\r
1932 returnCode = DEM_STATUS_WRONG_DTCKIND;
\r
1936 returnCode = DEM_STATUS_WRONG_DTC; /** @req DEM172 */
\r
1939 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETSTATUSOFDTC_ID, DEM_E_UNINIT);
\r
1940 returnCode = DEM_STATUS_FAILED;
\r
1943 return returnCode;
\r
1948 * Procedure: Dem_GetNumberOfFilteredDtc
\r
1951 Dem_ReturnGetNumberOfFilteredDTCType Dem_GetNumberOfFilteredDtc(uint16 *numberOfFilteredDTC) {
\r
1953 uint16 numberOfFaults = 0;
\r
1954 Dem_ReturnGetNumberOfFilteredDTCType returnCode = DEM_NUMBER_OK;
\r
1956 if (demState == DEM_INITIALIZED) {
\r
1957 //Dem_DisableEventStatusUpdate();
\r
1959 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1960 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1961 if (matchEventWithDtcFilter(&eventStatusBuffer[i])) {
\r
1962 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
1969 //Dem_EnableEventStatusUpdate();
\r
1971 *numberOfFilteredDTC = numberOfFaults; /** @req DEM061 */
\r
1973 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETNUMBEROFFILTEREDDTC_ID, DEM_E_UNINIT);
\r
1974 returnCode = DEM_NUMBER_FAILED;
\r
1977 return returnCode;
\r
1982 * Procedure: Dem_GetNextFilteredDTC
\r
1985 Dem_ReturnGetNextFilteredDTCType Dem_GetNextFilteredDTC(uint32 *dtc, Dem_EventStatusExtendedType *dtcStatus)
\r
1987 Dem_ReturnGetNextFilteredDTCType returnCode = DEM_FILTERED_OK;
\r
1988 boolean dtcFound = FALSE;
\r
1990 if (demState == DEM_INITIALIZED) {
\r
1991 // TODO: This job should be done in an more advanced way according to Dem217
\r
1992 while ((!dtcFound) && (dtcFilter.faultIndex != 0)) {
\r
1993 dtcFilter.faultIndex--;
\r
1994 if (eventStatusBuffer[dtcFilter.faultIndex].eventId != DEM_EVENT_ID_NULL) {
\r
1995 if (matchEventWithDtcFilter(&eventStatusBuffer[dtcFilter.faultIndex])) {
\r
1996 if (eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef != NULL) {
\r
1997 *dtc = eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef->DTC; /** @req DEM216 */
\r
1998 *dtcStatus = eventStatusBuffer[dtcFilter.faultIndex].eventStatusExtended;
\r
2006 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
2007 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
2010 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETNEXTFILTEREDDTC_ID, DEM_E_UNINIT);
\r
2011 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
2014 return returnCode;
\r
2019 * Procedure: Dem_GetTranslationType
\r
2022 Dem_ReturnTypeOfDtcSupportedType Dem_GetTranslationType(void)
\r
2024 return DEM_TYPE_OF_DTC_SUPPORTED; /** @req DEM231 */
\r
2029 * Procedure: Dem_ClearDTC
\r
2032 Dem_ReturnClearDTCType Dem_ClearDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin) /** @req DEM009 */
\r
2034 Dem_ReturnClearDTCType returnCode = DEM_CLEAR_OK;
\r
2035 Dem_EventIdType eventId;
\r
2036 const Dem_EventParameterType *eventParam;
\r
2039 if (demState == DEM_INITIALIZED) {
\r
2040 // Loop through the event buffer
\r
2041 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2042 eventId = eventStatusBuffer[i].eventId;
\r
2043 if (eventId != DEM_EVENT_ID_NULL) {
\r
2044 eventParam = eventStatusBuffer[i].eventParamRef;
\r
2045 if (eventParam != NULL) {
\r
2046 //lint --e(506) PC-Lint exception Misra 13.7, 14.1 Allow configuration variables in boolean expression
\r
2047 //lint --e(774) PC-Lint exception Related to MISRA 13.7
\r
2048 if ((DEM_CLEAR_ALL_EVENTS == STD_ON) || (eventParam->DTCClassRef != NULL)) {
\r
2049 if (checkDtcKind(dtcKind, eventParam)) {
\r
2050 if (checkDtcGroup(dtc, eventParam)) {
\r
2051 boolean dtcOriginFound = FALSE;
\r
2052 for (j = 0; (j < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound) ; j++){
\r
2053 dtcOriginFound =(eventParam->EventClass->EventDestination[j] == dtcOrigin);
\r
2055 //if (j-1 < DEM_MAX_NR_OF_EVENT_DESTINATION) {
\r
2056 if (dtcOriginFound) {
\r
2057 // Yes! All conditions met.
\r
2058 switch (dtcOrigin)
\r
2060 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2061 /** @req DEM077 */
\r
2062 deleteEventPriMem(eventParam);
\r
2063 deleteFreezeFrameDataPriMem(eventParam);
\r
2064 deleteExtendedDataPriMem(eventParam);
\r
2065 deleteEventStatusRec(eventParam); // TODO: Shall this be done or just resetting the status?
\r
2068 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2069 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2070 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2071 // Not yet supported
\r
2072 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2073 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2076 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2085 // Fatal error, no event parameters found for the stored event!
\r
2086 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNEXPECTED_EXECUTION);
\r
2091 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNINIT);
\r
2092 returnCode = DEM_CLEAR_FAILED;
\r
2095 return returnCode;
\r
2100 * Procedure: Dem_DisableDTCStorage
\r
2103 Dem_ReturnControlDTCStorageType Dem_DisableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind) /** @req DEM035 */
\r
2105 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2107 if (demState == DEM_INITIALIZED) {
\r
2108 // Check dtcGroup parameter
\r
2109 if (dtcGroup == DEM_DTC_GROUP_ALL_DTCS) {
\r
2110 // Check dtcKind parameter
\r
2111 if ((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS)) {
\r
2112 /** @req DEM079 */
\r
2113 disableDtcStorage.dtcGroup = dtcGroup;
\r
2114 disableDtcStorage.dtcKind = dtcKind;
\r
2115 disableDtcStorage.storageDisabled = TRUE;
\r
2117 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2120 returnCode = DEM_CONTROL_DTC_WRONG_DTCGROUP;
\r
2123 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_DISABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
2124 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2127 return returnCode;
\r
2132 * Procedure: Dem_EnableDTCStorage
\r
2135 Dem_ReturnControlDTCStorageType Dem_EnableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind)
\r
2137 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2139 if (demState == DEM_INITIALIZED) {
\r
2140 // TODO: Behavior is not defined if group or kind do not match active settings, therefore the filter is just switched off.
\r
2141 (void)dtcGroup; (void)dtcKind; // Just to make get rid of PC-Lint warnings
\r
2142 disableDtcStorage.storageDisabled = FALSE; /** @req DEM080 */
\r
2144 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_ENABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
2145 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2148 return returnCode;
\r
2152 * Procedure: Dem_GetExtendedDataRecordByDTC
\r
2155 Dem_ReturnGetExtendedDataRecordByDTCType Dem_GetExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint8 *destBuffer, uint16 *bufSize)
\r
2157 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_RECORD_WRONG_DTC;
\r
2158 EventStatusRecType *eventRec;
\r
2159 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2160 ExtDataRecType *extData;
\r
2161 uint16 posInExtData = 0;
\r
2163 if (demState == DEM_INITIALIZED) {
\r
2164 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2165 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2166 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2167 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2168 if (*bufSize >= extendedDataRecordClass->DataSize) {
\r
2169 switch (dtcOrigin)
\r
2171 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2172 if (lookupExtendedDataPriMem(eventRec->eventId, &extData)) {
\r
2173 // Yes all conditions met, copy the extended data record to destination buffer.
\r
2174 memcpy(destBuffer, &extData->data[posInExtData], extendedDataRecordClass->DataSize); /** @req DEM075 */
\r
2175 *bufSize = extendedDataRecordClass->DataSize;
\r
2176 returnCode = DEM_RECORD_OK;
\r
2179 // The record number is legal but no record was found for the DTC
\r
2181 returnCode = DEM_RECORD_OK;
\r
2185 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2186 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2187 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2188 // Not yet supported
\r
2189 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2190 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2193 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2198 returnCode = DEM_RECORD_BUFFERSIZE;
\r
2202 returnCode = DEM_RECORD_NUMBER;
\r
2206 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2210 returnCode = DEM_RECORD_DTCKIND;
\r
2214 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
2215 returnCode = DEM_RECORD_WRONG_DTC;
\r
2218 return returnCode;
\r
2223 * Procedure: Dem_GetSizeOfExtendedDataRecordByDTC
\r
2226 Dem_ReturnGetSizeOfExtendedDataRecordByDTCType Dem_GetSizeOfExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint16 *sizeOfExtendedDataRecord)
\r
2228 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2229 EventStatusRecType *eventRec;
\r
2230 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2231 uint16 posInExtData;
\r
2233 if (demState == DEM_INITIALIZED) {
\r
2234 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2235 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2236 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2237 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2238 *sizeOfExtendedDataRecord = extendedDataRecordClass->DataSize; /** @req DEM076 */
\r
2239 returnCode = DEM_GET_SIZEOFEDRBYDTC_OK;
\r
2242 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_RNUM;
\r
2246 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCOR;
\r
2250 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCKI;
\r
2254 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETSIZEOFEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
2255 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2258 return returnCode;
\r
2261 /***********************************
\r
2262 * OBD-specific Interfaces (8.3.6) *
\r
2263 ***********************************/
\r