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
21 * General requirements
\r
23 /** @req DEM014.14229-1 */
\r
26 /** @req DEM113 */ /** @req DEM174 */
\r
36 //#include "SchM_Dem.h"
\r
43 #define DEBOUNCE_FDC_TEST_FAILED 127
\r
44 #define DEBOUNCE_FDC_TEST_PASSED -128
\r
50 typedef uint16 ChecksumType;
\r
54 Dem_EventStatusExtendedType dtcStatusMask;
\r
55 Dem_DTCKindType dtcKind;
\r
56 Dem_DTCOriginType dtcOrigin;
\r
57 Dem_FilterWithSeverityType filterWithSeverity;
\r
58 Dem_DTCSeverityType dtcSeverityMask;
\r
59 Dem_FilterForFDCType filterForFaultDetectionCounter;
\r
63 // DisableDtcStorageType
\r
65 boolean storageDisabled;
\r
66 Dem_DTCGroupType dtcGroup;
\r
67 Dem_DTCKindType dtcKind;
\r
68 } DisableDtcStorageType;
\r
70 // For keeping track of the events status
\r
72 Dem_EventIdType eventId;
\r
73 const Dem_EventParameterType *eventParamRef;
\r
74 sint8 faultDetectionCounter;
\r
75 uint16 occurrence; /** @req DEM011 */
\r
76 Dem_EventStatusExtendedType eventStatusExtended; /** @req DEM006 */
\r
77 boolean errorStatusChanged;
\r
78 } EventStatusRecType;
\r
81 // Types for storing different event data on event memory
\r
83 Dem_EventIdType eventId;
\r
85 ChecksumType checksum;
\r
89 Dem_EventIdType eventId;
\r
92 sint8 data[DEM_MAX_SIZE_FF_DATA];
\r
93 ChecksumType checksum;
\r
94 } FreezeFrameRecType;
\r
97 Dem_EventIdType eventId;
\r
99 uint8 data[DEM_MAX_SIZE_EXT_DATA];
\r
100 ChecksumType checksum;
\r
107 DEM_UNINITIALIZED = 0,
\r
108 DEM_PREINITIALIZED,
\r
110 } Dem_StateType; /** @req DEM169 */
\r
113 static Dem_StateType demState = DEM_UNINITIALIZED;
\r
115 // Help pointer to configuration set
\r
116 static const Dem_ConfigSetType *configSet;
\r
119 * Allocation of DTC filter parameters
\r
121 static DtcFilterType dtcFilter;
\r
124 * Allocation of Disable/Enable DTC storage parameters
\r
126 static DisableDtcStorageType disableDtcStorage;
\r
129 * Allocation of operation cycle state list
\r
131 static Dem_OperationCycleStateType operationCycleStateList[DEM_OPERATION_CYCLE_ID_ENDMARK];
\r
134 * Allocation of local event status buffer
\r
136 static EventStatusRecType eventStatusBuffer[DEM_MAX_NUMBER_EVENT];
\r
139 * Allocation of pre-init event memory (used between pre-init and init)
\r
142 static FreezeFrameRecType preInitFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRE_INIT];
\r
143 static ExtDataRecType preInitExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRE_INIT];
\r
146 * Allocation of primary event memory ramlog (after init) in uninitialized memory
\r
149 static EventRecType priMemEventBuffer[DEM_MAX_NUMBER_EVENT_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
150 static FreezeFrameRecType priMemFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
151 static ExtDataRecType priMemExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
155 * Procedure: zeroPriMemBuffers
\r
156 * Description: Fill the primary buffers with zeroes
\r
158 void demZeroPriMemBuffers(void)
\r
160 memset(priMemEventBuffer, 0, sizeof(priMemEventBuffer));
\r
161 memset(priMemFreezeFrameBuffer, 0, sizeof(priMemFreezeFrameBuffer));
\r
162 memset(priMemExtDataBuffer, 0, sizeof(priMemExtDataBuffer));
\r
167 * Procedure: calcChecksum
\r
168 * Description: Calculate checksum over *data to *(data+nrOfBytes-1) area
\r
170 static ChecksumType calcChecksum(void *data, uint16 nrOfBytes)
\r
173 uint8 *ptr = (uint8*)data;
\r
174 ChecksumType sum = 0;
\r
176 for (i = 0; i < nrOfBytes; i++)
\r
184 * Procedure: checkDtcKind
\r
185 * Description: Return TRUE if "dtcKind" match the events DTCKind or "dtcKind"
\r
186 * is "DEM_DTC_KIND_ALL_DTCS" otherwise FALSE.
\r
188 static boolean checkDtcKind(Dem_DTCKindType dtcKind, const Dem_EventParameterType *eventParam)
\r
190 boolean result = FALSE;
\r
192 if (dtcKind == DEM_DTC_KIND_ALL_DTCS) {
\r
196 if (eventParam->DTCClassRef != NULL) {
\r
197 if (eventParam->DTCClassRef->DTCKind == dtcKind) {
\r
207 * Procedure: checkDtcGroup
\r
208 * Description: Return TRUE if "dtc" match the events DTC or "dtc" is
\r
209 * "DEM_DTC_GROUP_ALL_DTCS" otherwise FALSE.
\r
211 static boolean checkDtcGroup(uint32 dtc, const Dem_EventParameterType *eventParam)
\r
213 boolean result = FALSE;
\r
215 if (dtc == DEM_DTC_GROUP_ALL_DTCS) {
\r
219 if (eventParam->DTCClassRef != NULL) {
\r
220 if (eventParam->DTCClassRef->DTC == dtc) {
\r
230 * Procedure: checkDtcOrigin
\r
231 * Description: Return TRUE if "dtcOrigin" match any of the events DTCOrigin otherwise FALSE.
\r
233 static boolean checkDtcOrigin(Dem_DTCOriginType dtcOrigin, const Dem_EventParameterType *eventParam)
\r
235 boolean result = FALSE;
\r
238 for (i = 0; (eventParam->EventClass->EventDestination[i] != dtcOrigin) && (i < DEM_MAX_NR_OF_EVENT_DESTINATION); i++);
\r
240 if (i < DEM_MAX_NR_OF_EVENT_DESTINATION) {
\r
249 * Procedure: checkDtcSeverityMask
\r
250 * Description: Return TRUE if "dtcSeverityMask" match any of the events DTC severity otherwise FALSE.
\r
252 static boolean checkDtcSeverityMask(Dem_DTCSeverityType dtcSeverityMask, const Dem_EventParameterType *eventParam)
\r
254 boolean result = TRUE;
\r
256 // TODO: This function is optional, may be implemented here.
\r
263 * Procedure: checkDtcFaultDetectionCounterMask
\r
264 * Description: TBD.
\r
266 static boolean checkDtcFaultDetectionCounter(const Dem_EventParameterType *eventParam)
\r
268 boolean result = TRUE;
\r
270 // TODO: Not implemented yet.
\r
277 * Procedure: lookupEventStatusRec
\r
278 * Description: Returns the pointer to event id parameters of "eventId" in "*eventStatusBuffer",
\r
279 * if not found NULL is returned.
\r
281 static void lookupEventStatusRec(Dem_EventIdType eventId, EventStatusRecType **const eventStatusRec)
\r
283 EventStatusRecType *eventStatusRecPtr = eventStatusBuffer;
\r
285 while ((eventStatusRecPtr->eventId != eventId) && (eventStatusRecPtr < &eventStatusBuffer[DEM_MAX_NUMBER_EVENT])) {
\r
286 eventStatusRecPtr++;
\r
289 if (eventStatusRecPtr < &eventStatusBuffer[DEM_MAX_NUMBER_EVENT]) {
\r
290 *eventStatusRec = eventStatusRecPtr;
\r
292 *eventStatusRec = NULL;
\r
298 * Procedure: lookupEventIdParameter
\r
299 * Description: Returns the pointer to event id parameters of "eventId" in "*eventIdParam",
\r
300 * if not found NULL is returned.
\r
302 static void lookupEventIdParameter(Dem_EventIdType eventId, const Dem_EventParameterType **const eventIdParam)
\r
304 const Dem_EventParameterType *EventIdParamPtr = configSet->EventParameter;
\r
306 // Lookup the correct event id parameters
\r
307 while ((EventIdParamPtr->EventID != eventId) && !EventIdParamPtr->Arc_EOL) {
\r
311 if (!EventIdParamPtr->Arc_EOL) {
\r
312 *eventIdParam = EventIdParamPtr;
\r
314 *eventIdParam = NULL;
\r
320 * Procedure: preDebounceNone
\r
321 * Description: Returns the result of the debouncing.
\r
323 static Dem_EventStatusType preDebounceNone(Dem_EventStatusType reportedStatus, EventStatusRecType* statusRecord) {
\r
324 Dem_EventStatusType returnCode;
\r
326 switch (reportedStatus) {
\r
327 case DEM_EVENT_STATUS_FAILED: /** @req DEM191.NoneFailed */
\r
328 case DEM_EVENT_STATUS_PASSED: /** @req DEM191.NonePassed */
\r
329 // Already debounced, do nothing.
\r
333 // TODO: What to do with PREFAIL and PREPASSED on no debouncing?
\r
334 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
335 Det_ReportError(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_NONE_ID, DEM_E_PARAM_DATA); /** @req DEM117 */
\r
340 returnCode = reportedStatus;
\r
346 * Procedure: preDebounceCounterBased
\r
347 * Description: Returns the result of the debouncing.
\r
349 static Dem_EventStatusType preDebounceCounterBased(Dem_EventStatusType reportedStatus, EventStatusRecType* statusRecord) {
\r
350 Dem_EventStatusType returnCode;
\r
351 const Dem_PreDebounceCounterBasedType* pdVars = statusRecord->eventParamRef->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceCounterBased;
\r
353 switch (reportedStatus) {
\r
354 case DEM_EVENT_STATUS_PREFAILED:
\r
355 if (statusRecord->faultDetectionCounter < DEBOUNCE_FDC_TEST_FAILED) {
\r
356 if (pdVars->JumpUp && (statusRecord->faultDetectionCounter < 0)) {
\r
357 statusRecord->faultDetectionCounter = 0;
\r
359 if (((sint16)statusRecord->faultDetectionCounter + pdVars->CountInStepSize) < DEBOUNCE_FDC_TEST_FAILED) {
\r
360 statusRecord->faultDetectionCounter += pdVars->CountInStepSize;
\r
362 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED;
\r
368 case DEM_EVENT_STATUS_PREPASSED:
\r
369 if (statusRecord->faultDetectionCounter > DEBOUNCE_FDC_TEST_PASSED) {
\r
370 if (pdVars->JumpDown && (statusRecord->faultDetectionCounter > 0)) {
\r
371 statusRecord->faultDetectionCounter = 0;
\r
373 if (((sint16)statusRecord->faultDetectionCounter - pdVars->CountOutStepSize) > DEBOUNCE_FDC_TEST_PASSED) {
\r
374 statusRecord->faultDetectionCounter -= pdVars->CountOutStepSize;
\r
376 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED;
\r
382 case DEM_EVENT_STATUS_FAILED:
\r
383 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED; /** @req DEM191.CounterFailed */
\r
386 case DEM_EVENT_STATUS_PASSED:
\r
387 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED; /** @req DEM191.CounterPassed */
\r
391 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
392 Det_ReportError(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_COUNTER_BASED_ID, DEM_E_PARAM_DATA); /** @req DEM117 */
\r
398 switch (statusRecord->faultDetectionCounter) {
\r
399 case DEBOUNCE_FDC_TEST_FAILED:
\r
400 returnCode = DEM_EVENT_STATUS_FAILED;
\r
403 case DEBOUNCE_FDC_TEST_PASSED:
\r
404 returnCode = DEM_EVENT_STATUS_PASSED;
\r
408 returnCode = reportedStatus;
\r
417 * Procedure: updateEventStatusRec
\r
418 * Description: Update the status of "eventId", if not exist and "createIfNotExist" is
\r
419 * true a new record is created
\r
421 static void updateEventStatusRec(const Dem_EventParameterType *eventParam, Dem_EventStatusType eventStatus, boolean createIfNotExist, EventStatusRecType *eventStatusRec)
\r
423 EventStatusRecType *eventStatusRecPtr;
\r
424 imask_t state = McuE_EnterCriticalSection();
\r
427 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
429 if ((eventStatusRecPtr == NULL) && (createIfNotExist)) {
\r
430 // Search for free position
\r
431 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
433 if (eventStatusRecPtr != NULL) {
\r
434 // Create new event record
\r
435 eventStatusRecPtr->eventId = eventParam->EventID;
\r
436 eventStatusRecPtr->eventParamRef = eventParam;
\r
437 eventStatusRecPtr->faultDetectionCounter = 0;
\r
438 eventStatusRecPtr->occurrence = 0;
\r
439 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
440 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
443 // Error: Event status buffer full
\r
444 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
445 Det_ReportError(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL); /** @req DEM117 */
\r
451 if (eventStatusRecPtr != NULL) {
\r
452 // Handle debouncing
\r
453 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName) { /** @req DEM004 */ /** @req DEM342 */
\r
454 case DEM_NO_PRE_DEBOUNCE:
\r
455 eventStatus = preDebounceNone(eventStatus, eventStatusRecPtr);
\r
458 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
459 eventStatus = preDebounceCounterBased(eventStatus, eventStatusRecPtr);
\r
463 // Don't know how to handle this.
\r
464 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
465 Det_ReportError(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
471 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
473 // Check test failed
\r
474 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
475 if (!(eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED)) {
\r
476 eventStatusRecPtr->occurrence++;
\r
477 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
479 /** @req DEM036.Failed */ /** @req DEM379.PendingSet */
\r
480 eventStatusRecPtr->eventStatusExtended |= (DEM_TEST_FAILED | DEM_TEST_FAILED_THIS_OPERATION_CYCLE | DEM_TEST_FAILED_SINCE_LAST_CLEAR | DEM_PENDING_DTC);
\r
481 eventStatusRecPtr->eventStatusExtended &= ~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
484 // Check test passed
\r
485 if (eventStatus == DEM_EVENT_STATUS_PASSED) {
\r
486 if (eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED) {
\r
487 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
489 /** @req DEM036.Passed */
\r
490 eventStatusRecPtr->eventStatusExtended &= ~DEM_TEST_FAILED;
\r
491 eventStatusRecPtr->eventStatusExtended &= ~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
495 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
498 // Copy an empty record to return data
\r
499 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
500 eventStatusRecPtr->faultDetectionCounter = 0;
\r
501 eventStatusRec->occurrence = 0;
\r
502 eventStatusRec->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
503 eventStatusRec->errorStatusChanged = FALSE;
\r
506 McuE_ExitCriticalSection(state);
\r
511 * Procedure: mergeEventStatusRec
\r
512 * Description: Update the occurrence counter of status, if not exist a new record is created
\r
514 static void mergeEventStatusRec(EventRecType *eventRec)
\r
516 EventStatusRecType *eventStatusRecPtr;
\r
517 imask_t state = McuE_EnterCriticalSection();
\r
520 lookupEventStatusRec(eventRec->eventId, &eventStatusRecPtr);
\r
522 if (eventStatusRecPtr != NULL) {
\r
523 // Update occurrence counter, rest of pre init state is kept.
\r
524 eventStatusRecPtr->occurrence += eventRec->occurrence;
\r
528 // Search for free position
\r
529 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
531 if (eventStatusRecPtr != NULL) {
\r
532 // Create new event, from stored event
\r
533 eventStatusRecPtr->eventId = eventRec->eventId;
\r
534 lookupEventIdParameter(eventRec->eventId, &eventStatusRecPtr->eventParamRef);
\r
535 eventStatusRecPtr->faultDetectionCounter = 0;
\r
536 eventStatusRecPtr->occurrence = eventRec->occurrence;
\r
537 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
538 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
541 // Error: Event status buffer full
\r
542 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
543 Det_ReportError(MODULE_ID_DEM, 0, DEM_MERGE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL); /** @req DEM117 */
\r
548 McuE_ExitCriticalSection(state);
\r
553 * Procedure: deleteEventStatusRec
\r
554 * Description: Delete the status record of "eventParam->eventId" from "eventStatusBuffer".
\r
556 static void deleteEventStatusRec(const Dem_EventParameterType *eventParam)
\r
558 EventStatusRecType *eventStatusRecPtr;
\r
559 imask_t state = McuE_EnterCriticalSection();
\r
562 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
564 if (eventStatusRecPtr != NULL) {
\r
565 // Delete event record
\r
566 memset(eventStatusRecPtr, 0, sizeof(EventStatusRecType));
\r
569 McuE_ExitCriticalSection(state);
\r
574 * Procedure: getEventStatusRec
\r
575 * Description: Returns the status record of "eventId" in "eventStatusRec"
\r
577 static void getEventStatusRec(Dem_EventIdType eventId, EventStatusRecType *eventStatusRec)
\r
579 EventStatusRecType *eventStatusRecPtr;
\r
582 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
584 if (eventStatusRecPtr != NULL) {
\r
586 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
589 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
595 * Procedure: lookupDtcEvent
\r
596 * Description: Returns TRUE if the DTC was found and "eventStatusRec" points
\r
597 * to the event record found.
\r
599 static boolean lookupDtcEvent(uint32 dtc, EventStatusRecType **eventStatusRec)
\r
601 boolean dtcFound = FALSE;
\r
604 *eventStatusRec = NULL;
\r
606 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && !dtcFound; i++) {
\r
607 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
608 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
611 if (eventStatusBuffer[i].eventParamRef->DTCClassRef->DTC == dtc) {
\r
612 *eventStatusRec = &eventStatusBuffer[i];
\r
624 * Procedure: matchEventWithDtcFilter
\r
625 * Description: Returns TRUE if the event pointed by "event" fulfill
\r
626 * the "dtcFilter" global filter settings.
\r
628 static boolean matchEventWithDtcFilter(const EventStatusRecType *eventRec)
\r
630 boolean dtcMatch = FALSE;
\r
633 if ((dtcFilter.dtcStatusMask == DEM_DTC_STATUS_MASK_ALL) || (eventRec->eventStatusExtended & dtcFilter.dtcStatusMask)) {
\r
634 if (eventRec->eventParamRef != NULL) {
\r
637 if (checkDtcKind(dtcFilter.dtcKind, eventRec->eventParamRef)) {
\r
640 if (checkDtcOrigin(dtcFilter.dtcOrigin, eventRec->eventParamRef)) {
\r
643 if ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
644 || ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES) && checkDtcSeverityMask(dtcFilter.dtcSeverityMask, eventRec->eventParamRef))) {
\r
646 // Check fault detection counter
\r
647 if ((dtcFilter.filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO)
\r
648 || ((dtcFilter.filterWithSeverity == DEM_FILTER_FOR_FDC_YES) && checkDtcFaultDetectionCounter(eventRec->eventParamRef))) {
\r
661 static void getFreezeFrameData(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
664 freezeFrame->eventId = DEM_EVENT_ID_NULL; // Not supported yet
\r
668 static void storeFreezeFrameDataPreInit(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
674 static void updateFreezeFrameOccurrencePreInit(EventRecType *EventBuffer)
\r
681 * Procedure: getExtendedData
\r
682 * Description: Collects the extended data according to "eventParam" and return it in "extData",
\r
683 * if not found eventId is set to DEM_EVENT_ID_NULL.
\r
685 static void getExtendedData(const Dem_EventParameterType *eventParam, ExtDataRecType *extData)
\r
687 Std_ReturnType callbackReturnCode;
\r
689 uint16 storeIndex = 0;
\r
692 // Clear ext data record
\r
693 memset(extData, 0, sizeof(ExtDataRecType));
\r
695 // Check if any pointer to extended data class
\r
696 if (eventParam->ExtendedDataClassRef != NULL) {
\r
697 // Request extended data and copy it to the buffer
\r
698 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL); i++) {
\r
699 recordSize = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
700 if ((storeIndex + recordSize) <= DEM_MAX_SIZE_EXT_DATA) {
\r
701 callbackReturnCode = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->CallbackGetExtDataRecord(&extData->data[storeIndex]); /** @req DEM282 */
\r
702 if (callbackReturnCode != E_OK) {
\r
703 // Callback data currently not available, clear space.
\r
704 memset(&extData->data[storeIndex], 0xFF, recordSize);
\r
706 storeIndex += recordSize;
\r
709 // Error: Size of extended data record is bigger than reserved space.
\r
710 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
711 Det_ReportError(MODULE_ID_DEM, 0, DEM_GET_EXTENDED_DATA_ID, DEM_E_EXT_DATA_TOO_BIG); /** @req DEM117 */
\r
713 break; // Break the loop
\r
718 // Check if any data has been stored
\r
719 if (storeIndex != 0) {
\r
720 extData->eventId = eventParam->EventID;
\r
721 extData->dataSize = storeIndex;
\r
722 extData->checksum = calcChecksum(extData, sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
725 extData->eventId = DEM_EVENT_ID_NULL;
\r
726 extData->dataSize = storeIndex;
\r
727 extData->checksum = 0;
\r
733 * Procedure: storeExtendedDataPreInit
\r
734 * Description: Store the extended data pointed by "extendedData" to the "preInitExtDataBuffer",
\r
735 * if non existent a new entry is created.
\r
737 static void storeExtendedDataPreInit(const Dem_EventParameterType *eventParam, ExtDataRecType *extendedData)
\r
740 imask_t state = McuE_EnterCriticalSection();
\r
742 // Check if already stored
\r
743 for (i = 0; (preInitExtDataBuffer[i].eventId != eventParam->EventID) && (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT); i++);
\r
745 if (i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) {
\r
746 // Yes, overwrite existing
\r
747 memcpy(&preInitExtDataBuffer[i], extendedData, sizeof(ExtDataRecType));
\r
750 // No, lookup first free position
\r
751 for (i = 0; (preInitExtDataBuffer[i].eventId !=0) && (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT); i++);
\r
753 if (i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) {
\r
754 memcpy(&preInitExtDataBuffer[i], extendedData, sizeof(ExtDataRecType));
\r
757 // Error: Pre init extended data buffer full
\r
758 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
759 Det_ReportError(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRE_INIT_ID, DEM_E_PRE_INIT_EXT_DATA_BUFF_FULL); /** @req DEM117 */
\r
764 McuE_ExitCriticalSection(state);
\r
769 * Procedure: storeEventPriMem
\r
770 * Description: Store the event data of "eventStatus->eventId" in "priMemEventBuffer",
\r
771 * if non existent a new entry is created.
\r
773 static void storeEventPriMem(const Dem_EventParameterType *eventParam, EventStatusRecType *eventStatus)
\r
776 imask_t state = McuE_EnterCriticalSection();
\r
780 for (i = 0; (priMemEventBuffer[i].eventId != eventStatus->eventId) && (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI); i++);
\r
782 if (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) {
\r
783 // Update event found
\r
784 priMemEventBuffer[i].occurrence = eventStatus->occurrence;
\r
785 priMemEventBuffer[i].checksum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
788 // Search for free position
\r
789 for (i=0; (priMemEventBuffer[i].eventId != DEM_EVENT_ID_NULL) && (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI); i++);
\r
791 if (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) {
\r
792 priMemEventBuffer[i].eventId = eventStatus->eventId;
\r
793 priMemEventBuffer[i].occurrence = eventStatus->occurrence;
\r
794 priMemEventBuffer[i].checksum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
797 // Error: Pri mem event buffer full
\r
798 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
799 Det_ReportError(MODULE_ID_DEM, 0, DEM_STORE_EVENT_PRI_MEM_ID, DEM_E_PRI_MEM_EVENT_BUFF_FULL); /** @req DEM117 */
\r
804 McuE_ExitCriticalSection(state);
\r
809 * Procedure: deleteEventPriMem
\r
810 * Description: Delete the event data of "eventParam->eventId" from "priMemEventBuffer".
\r
812 static void deleteEventPriMem(const Dem_EventParameterType *eventParam)
\r
815 imask_t state = McuE_EnterCriticalSection();
\r
819 for (i = 0; (priMemEventBuffer[i].eventId != eventParam->EventID) && (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI); i++);
\r
821 if (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) {
\r
822 // Delete event found
\r
823 memset(&priMemEventBuffer[i], 0, sizeof(EventRecType));
\r
826 McuE_ExitCriticalSection(state);
\r
831 * Procedure: storeEventEvtMem
\r
832 * Description: Store the event data of "eventStatus->eventId" in event memory according to
\r
833 * "eventParam" destination option.
\r
835 static void storeEventEvtMem(const Dem_EventParameterType *eventParam, EventStatusRecType *eventStatus)
\r
839 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != NULL); i++) {
\r
840 switch (eventParam->EventClass->EventDestination[i])
\r
842 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
843 storeEventPriMem(eventParam, eventStatus); /** @req DEM010 */
\r
846 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
847 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
848 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
849 // Not yet supported
\r
850 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
851 Det_ReportError(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
862 * Procedure: storeExtendedDataPriMem
\r
863 * Description: Store the extended data pointed by "extendedData" to the "priMemExtDataBuffer",
\r
864 * if non existent a new entry is created.
\r
866 static void storeExtendedDataPriMem(const Dem_EventParameterType *eventParam, ExtDataRecType *extendedData) /** @req DEM041 */
\r
869 imask_t state = McuE_EnterCriticalSection();
\r
871 // Check if already stored
\r
872 for (i = 0; (priMemExtDataBuffer[i].eventId != eventParam->EventID) && (i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM); i++);
\r
874 if (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) {
\r
875 // Yes, overwrite existing
\r
876 memcpy(&priMemExtDataBuffer[i], extendedData, sizeof(ExtDataRecType));
\r
879 // No, lookup first free position
\r
880 for (i = 0; (priMemExtDataBuffer[i].eventId != DEM_EVENT_ID_NULL) && (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM); i++);
\r
881 if (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) {
\r
882 memcpy(&priMemExtDataBuffer[i], extendedData, sizeof(ExtDataRecType));
\r
885 // Error: Pri mem extended data buffer full
\r
886 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
887 Det_ReportError(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRI_MEM_ID, DEM_E_PRI_MEM_EXT_DATA_BUFF_FULL); /** @req DEM117 */
\r
892 McuE_ExitCriticalSection(state);
\r
897 * Procedure: deleteExtendedDataPriMem
\r
898 * Description: Delete the extended data of "eventParam->eventId" from "priMemExtDataBuffer".
\r
900 static void deleteExtendedDataPriMem(const Dem_EventParameterType *eventParam)
\r
903 imask_t state = McuE_EnterCriticalSection();
\r
905 // Check if already stored
\r
906 for (i = 0; (priMemExtDataBuffer[i].eventId != eventParam->EventID) && (i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM); i++);
\r
908 if (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) {
\r
909 // Yes, clear record
\r
910 memset(&priMemExtDataBuffer[i], 0, sizeof(ExtDataRecType));
\r
913 McuE_ExitCriticalSection(state);
\r
918 * Procedure: storeExtendedDataEvtMem
\r
919 * Description: Store the extended data in event memory according to
\r
920 * "eventParam" destination option
\r
922 static void storeExtendedDataEvtMem(const Dem_EventParameterType *eventParam, ExtDataRecType *extendedData)
\r
926 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != NULL); i++) {
\r
927 switch (eventParam->EventClass->EventDestination[i])
\r
929 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
930 storeExtendedDataPriMem(eventParam, extendedData);
\r
933 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
934 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
935 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
936 // Not yet supported
\r
937 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
938 Det_ReportError(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
950 * Procedure: lookupExtendedDataRecNumParam
\r
951 * Description: Returns TRUE if the requested extended data number was found among the configured records for the event.
\r
952 * "extDataRecClassPtr" returns a pointer to the record class, "posInExtData" returns the position in stored extended data.
\r
954 static boolean lookupExtendedDataRecNumParam(uint8 extendedDataNumber, const Dem_EventParameterType *eventParam, Dem_ExtendedDataRecordClassType const **extDataRecClassPtr, uint8 *posInExtData)
\r
956 boolean recNumFound = FALSE;
\r
958 if (eventParam->ExtendedDataClassRef != NULL) {
\r
959 Dem_ExtendedDataRecordClassType const* const* extDataRecClassRefList = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef;
\r
960 uint16 byteCnt = 0;
\r
963 // Request extended data and copy it to the buffer
\r
964 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (extDataRecClassRefList[i] != NULL) && !recNumFound; i++) {
\r
965 if (extDataRecClassRefList[i]->RecordNumber == extendedDataNumber) {
\r
966 *extDataRecClassPtr = extDataRecClassRefList[i];
\r
967 *posInExtData = byteCnt;
\r
968 recNumFound = TRUE;
\r
970 byteCnt += extDataRecClassRefList[i]->DataSize;
\r
974 return recNumFound;
\r
979 * Procedure: lookupExtendedDataPriMem
\r
980 * Description: Returns TRUE if the requested event id is found, "extData" points to the found data.
\r
982 static boolean lookupExtendedDataPriMem(Dem_EventIdType eventId, ExtDataRecType **extData)
\r
984 boolean eventIdFound = FALSE;
\r
987 // Lookup corresponding extended data
\r
988 for (i = 0; (priMemExtDataBuffer[i].eventId != eventId) && (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM); i++);
\r
990 if (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) {
\r
991 // Yes, return pointer
\r
992 *extData = &priMemExtDataBuffer[i];
\r
993 eventIdFound = TRUE;
\r
996 return eventIdFound;
\r
1000 static void storeFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
1006 static void deleteFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam)
\r
1013 * Procedure: storeFreezeFrameDataEvtMem
\r
1014 * Description: Store the freeze frame data in event memory according to
\r
1015 * "eventParam" destination option
\r
1017 static void storeFreezeFrameDataEvtMem(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
1021 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != NULL); i++) {
\r
1022 switch (eventParam->EventClass->EventDestination[i])
\r
1024 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1025 storeFreezeFrameDataPriMem(eventParam, freezeFrame);
\r
1028 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1029 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1030 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1031 // Not yet supported
\r
1032 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1033 Det_ReportError(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
1044 * Procedure: handlePreInitEvent
\r
1045 * Description: Handle the updating of event status and storing of
\r
1046 * event related data in preInit buffers.
\r
1048 static void handlePreInitEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1050 const Dem_EventParameterType *eventParam;
\r
1051 EventStatusRecType eventStatusLocal;
\r
1052 FreezeFrameRecType freezeFrameLocal;
\r
1053 ExtDataRecType extendedDataLocal;
\r
1055 // Find configuration for this event
\r
1056 lookupEventIdParameter(eventId, &eventParam);
\r
1057 if (eventParam != NULL) {
\r
1058 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1059 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1060 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
1061 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1064 updateEventStatusRec(eventParam, eventStatus, FALSE, &eventStatusLocal);
\r
1067 if (eventStatusLocal.errorStatusChanged) {
\r
1069 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1070 // Collect freeze frame data
\r
1071 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1072 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1073 storeFreezeFrameDataPreInit(eventParam, &freezeFrameLocal);
\r
1076 // Collect extended data
\r
1077 getExtendedData(eventParam, &extendedDataLocal);
\r
1078 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1079 storeExtendedDataPreInit(eventParam, &extendedDataLocal);
\r
1085 // Operation cycle not started
\r
1086 // TODO: Report error?
\r
1090 // Operation cycle not set
\r
1091 // TODO: Report error?
\r
1095 // Event ID not configured
\r
1096 // TODO: Report error?
\r
1102 * Procedure: handleEvent
\r
1103 * Description: Handle the updating of event status and storing of
\r
1104 * event related data in event memory.
\r
1106 static Std_ReturnType handleEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1108 Std_ReturnType returnCode = E_OK;
\r
1109 const Dem_EventParameterType *eventParam;
\r
1110 EventStatusRecType eventStatusLocal;
\r
1111 FreezeFrameRecType freezeFrameLocal;
\r
1112 ExtDataRecType extendedDataLocal;
\r
1114 // Find configuration for this event
\r
1115 lookupEventIdParameter(eventId, &eventParam);
\r
1116 if (eventParam != NULL) {
\r
1117 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1118 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1119 if (!(disableDtcStorage.storageDisabled && checkDtcGroup(disableDtcStorage.dtcGroup, eventParam) && checkDtcKind(disableDtcStorage.dtcKind, eventParam))) {
\r
1120 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1121 if (eventStatusLocal.errorStatusChanged) {
\r
1122 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1123 storeEventEvtMem(eventParam, &eventStatusLocal); /** @req DEM184 */
\r
1124 // Collect freeze frame data
\r
1125 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1126 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1127 storeFreezeFrameDataEvtMem(eventParam, &freezeFrameLocal); /** @req DEM190 */
\r
1130 // Collect extended data
\r
1131 getExtendedData(eventParam, &extendedDataLocal);
\r
1132 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL)
\r
1134 storeExtendedDataEvtMem(eventParam, &extendedDataLocal);
\r
1141 // Operation cycle not started
\r
1142 returnCode = E_NOT_OK;
\r
1146 // Operation cycle not set
\r
1147 returnCode = E_NOT_OK;
\r
1151 // Event ID not configured
\r
1152 returnCode = E_NOT_OK;
\r
1155 return returnCode;
\r
1160 * Procedure: resetEventStatus
\r
1161 * Description: Resets the events status of eventId.
\r
1163 static void resetEventStatus(Dem_EventIdType eventId)
\r
1165 imask_t state = McuE_EnterCriticalSection();
\r
1166 EventStatusRecType *eventStatusRecPtr;
\r
1168 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
1169 if (eventStatusRecPtr != NULL) {
\r
1170 eventStatusRecPtr->eventStatusExtended &= ~DEM_TEST_FAILED; /** @req DEM187 */
\r
1173 McuE_ExitCriticalSection(state);
\r
1178 * Procedure: getEventStatus
\r
1179 * Description: Returns the extended event status bitmask of eventId in "eventStatusExtended".
\r
1181 static void getEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended)
\r
1183 EventStatusRecType eventStatusLocal;
\r
1185 // Get recorded status
\r
1186 getEventStatusRec(eventId, &eventStatusLocal);
\r
1187 if (eventStatusLocal.eventId == eventId) {
\r
1188 *eventStatusExtended = eventStatusLocal.eventStatusExtended; /** @req DEM051 */
\r
1191 // Event Id not found, no report received.
\r
1192 *eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1198 * Procedure: getEventFailed
\r
1199 * Description: Returns the TRUE or FALSE of "eventId" in "eventFailed" depending on current status.
\r
1201 static void getEventFailed(Dem_EventIdType eventId, boolean *eventFailed)
\r
1203 EventStatusRecType eventStatusLocal;
\r
1205 // Get recorded status
\r
1206 getEventStatusRec(eventId, &eventStatusLocal);
\r
1207 if (eventStatusLocal.eventId == eventId) {
\r
1208 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) { /** @req DEM052 */
\r
1209 *eventFailed = TRUE;
\r
1212 *eventFailed = FALSE;
\r
1216 // Event Id not found, assume ok.
\r
1217 *eventFailed = FALSE;
\r
1223 * Procedure: getEventTested
\r
1224 * Description: Returns the TRUE or FALSE of "eventId" in "eventTested" depending on
\r
1225 * current status the "test not completed this operation cycle" bit.
\r
1227 static void getEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1229 EventStatusRecType eventStatusLocal;
\r
1231 // Get recorded status
\r
1232 getEventStatusRec(eventId, &eventStatusLocal);
\r
1233 if (eventStatusLocal.eventId == eventId) {
\r
1234 if ( !(eventStatusLocal.eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE)) { /** @req DEM053 */
\r
1235 *eventTested = TRUE;
\r
1238 *eventTested = FALSE;
\r
1242 // Event Id not found, not tested.
\r
1243 *eventTested = FALSE;
\r
1249 * Procedure: getFaultDetectionCounter
\r
1250 * Description: Returns pre debounce counter of "eventId" in "counter" and return value E_OK if
\r
1251 * the counter was available else E_NOT_OK.
\r
1253 static Std_ReturnType getFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1255 Std_ReturnType returnCode = E_NOT_OK;
\r
1256 const Dem_EventParameterType *eventParam;
\r
1258 lookupEventIdParameter(eventId, &eventParam);
\r
1259 if (eventParam != NULL) {
\r
1260 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
1261 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName)
\r
1263 case DEM_NO_PRE_DEBOUNCE:
\r
1264 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal != NULL) {
\r
1265 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc != NULL) {
\r
1266 returnCode = eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc(counter); /** @req DEM204.None */ /** @req DEM264 */ /** @req DEM265 */
\r
1271 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
1273 EventStatusRecType *eventStatusRec;
\r
1275 lookupEventStatusRec(eventId, &eventStatusRec);
\r
1276 if (eventStatusRec != NULL) {
\r
1277 *counter = eventStatusRec->faultDetectionCounter; /** @req DEM204.Counter */
\r
1281 returnCode = E_OK;
\r
1285 case DEM_PRE_DEBOUNCE_FREQUENCY_BASED:
\r
1286 case DEM_PRE_DEBOUNCE_TIME_BASED:
\r
1287 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1288 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
1293 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1294 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_PARAM_DATA); /** @req DEM117 */
\r
1301 return returnCode;
\r
1306 * Procedure: setOperationCycleState
\r
1307 * Description: Change the operation state of "operationCycleId" to "cycleState" and updates stored
\r
1308 * event connected to this cycle id.
\r
1309 * Returns E_OK if operation was successful else E_NOT_OK.
\r
1311 static Std_ReturnType setOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState) /** @req DEM338 */
\r
1314 Std_ReturnType returnCode = E_OK;
\r
1316 if (operationCycleId < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1317 switch (cycleState)
\r
1319 case DEM_CYCLE_STATE_START:
\r
1320 operationCycleStateList[operationCycleId] = cycleState;
\r
1321 // Lookup event ID
\r
1322 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1323 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1324 eventStatusBuffer[i].eventStatusExtended &= ~DEM_TEST_FAILED_THIS_OPERATION_CYCLE;
\r
1325 eventStatusBuffer[i].eventStatusExtended |= DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
1330 case DEM_CYCLE_STATE_END:
\r
1331 operationCycleStateList[operationCycleId] = cycleState;
\r
1332 // Lookup event ID
\r
1333 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1334 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1335 if (!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_FAILED_THIS_OPERATION_CYCLE) && !(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE)) {
\r
1336 eventStatusBuffer[i].eventStatusExtended &= ~DEM_PENDING_DTC; // Clear pendingDTC bit /** @req DEM379.PendingClear
\r
1342 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1343 Det_ReportError(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA); /** @req DEM117 */
\r
1345 returnCode = E_NOT_OK;
\r
1350 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1351 Det_ReportError(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA); /** @req DEM117 */
\r
1353 returnCode = E_NOT_OK;
\r
1356 return returnCode;
\r
1360 //==============================================================================//
\r
1362 // E X T E R N A L F U N C T I O N S //
\r
1364 //==============================================================================//
\r
1366 /*********************************************
\r
1367 * Interface for upper layer modules (8.3.1) *
\r
1368 *********************************************/
\r
1371 * Procedure: Dem_GetVersionInfo
\r
1374 // Defined in Dem.h
\r
1377 /***********************************************
\r
1378 * Interface ECU State Manager <-> DEM (8.3.2) *
\r
1379 ***********************************************/
\r
1382 * Procedure: Dem_PreInit
\r
1385 void Dem_PreInit(void)
\r
1387 /** @req DEM180 */
\r
1390 if (DEM_Config.ConfigSet == NULL) {
\r
1391 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1392 Det_ReportError(MODULE_ID_DEM, 0, DEM_PREINIT_ID, DEM_E_CONFIG_PTR_INVALID); /** @req DEM117 */
\r
1396 configSet = DEM_Config.ConfigSet;
\r
1399 // Initializion of operation cycle states.
\r
1400 for (i = 0; i < DEM_OPERATION_CYCLE_ID_ENDMARK; i++) {
\r
1401 operationCycleStateList[i] = DEM_CYCLE_STATE_END;
\r
1404 // Initialize the event status buffer
\r
1405 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1406 eventStatusBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1407 eventStatusBuffer[i].eventParamRef = NULL;
\r
1408 eventStatusBuffer[i].faultDetectionCounter = 0;
\r
1409 eventStatusBuffer[i].occurrence = 0;
\r
1410 eventStatusBuffer[i].eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1411 eventStatusBuffer[i].errorStatusChanged = FALSE;
\r
1414 // Initialize the pre init buffers
\r
1415 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1416 preInitFreezeFrameBuffer[i].checksum = 0;
\r
1417 preInitFreezeFrameBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1418 preInitFreezeFrameBuffer[i].occurrence = 0;
\r
1419 preInitFreezeFrameBuffer[i].dataSize = 0;
\r
1420 for (j = 0; j < DEM_MAX_SIZE_FF_DATA;j++)
\r
1421 preInitFreezeFrameBuffer[i].data[j] = 0;
\r
1424 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1425 preInitExtDataBuffer[i].checksum = 0;
\r
1426 preInitExtDataBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1427 preInitExtDataBuffer[i].dataSize = 0;
\r
1428 for (j = 0; j < DEM_MAX_SIZE_EXT_DATA;j++)
\r
1429 preInitExtDataBuffer[i].data[j] = 0;
\r
1432 disableDtcStorage.storageDisabled = FALSE;
\r
1434 setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_START); /** @req DEM047 */
\r
1436 demState = DEM_PREINITIALIZED;
\r
1441 * Procedure: Dem_Init
\r
1444 void Dem_Init(void)
\r
1447 ChecksumType cSum;
\r
1448 const Dem_EventParameterType *eventParam;
\r
1451 * Validate and read out saved error log from non volatile memory
\r
1454 // Validate event records stored in primary memory
\r
1455 for (i = 0; i < DEM_MAX_NUMBER_EVENT_PRI_MEM; i++) {
\r
1456 cSum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
1457 if ((cSum != priMemEventBuffer[i].checksum) || priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL) {
\r
1458 // Unlegal record, clear the record
\r
1459 memset(&priMemEventBuffer[i], 0, sizeof(EventRecType));
\r
1462 // Valid, update current status
\r
1463 mergeEventStatusRec(&priMemEventBuffer[i]);
\r
1465 // Update occurrence counter on pre init stored freeze frames
\r
1466 updateFreezeFrameOccurrencePreInit(&priMemEventBuffer[i]);
\r
1470 // Validate extended data records stored in primary memory
\r
1471 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM; i++) {
\r
1472 cSum = calcChecksum(&priMemExtDataBuffer[i], sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
1473 if ((cSum != priMemExtDataBuffer[i].checksum) || priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL) {
\r
1474 // Unlegal record, clear the record
\r
1475 memset(&priMemExtDataBuffer[i], 0, sizeof(ExtDataRecType));
\r
1479 // Validate freeze frame records stored in primary memory
\r
1480 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++) {
\r
1481 cSum = calcChecksum(&priMemFreezeFrameBuffer[i], sizeof(FreezeFrameRecType)-sizeof(ChecksumType));
\r
1482 if ((cSum != priMemFreezeFrameBuffer[i].checksum) || (priMemFreezeFrameBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1483 // Unlegal record, clear the record
\r
1484 memset(&priMemFreezeFrameBuffer[i], 0, sizeof(FreezeFrameRecType));
\r
1489 * Handle errors stored in temporary buffer (if any)
\r
1492 // Transfer updated event data to event memory
\r
1493 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1494 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1495 // Update the event memory
\r
1496 lookupEventIdParameter(eventStatusBuffer[i].eventId, &eventParam);
\r
1497 storeEventEvtMem(eventParam, &eventStatusBuffer[i]);
\r
1501 // Transfer extended data to event memory if necessary
\r
1502 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1503 if (preInitExtDataBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1504 lookupEventIdParameter(preInitExtDataBuffer[i].eventId, &eventParam);
\r
1505 storeExtendedDataEvtMem(eventParam, &preInitExtDataBuffer[i]);
\r
1509 // Transfer freeze frames to event memory
\r
1510 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1511 if (preInitFreezeFrameBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1512 lookupEventIdParameter(preInitFreezeFrameBuffer[i].eventId, &eventParam);
\r
1513 storeFreezeFrameDataEvtMem(eventParam, &preInitFreezeFrameBuffer[i]);
\r
1517 // Init the dtc filter
\r
1518 dtcFilter.dtcStatusMask = DEM_DTC_STATUS_MASK_ALL; // All allowed
\r
1519 dtcFilter.dtcKind = DEM_DTC_KIND_ALL_DTCS; // All kinds of DTCs
\r
1520 dtcFilter.dtcOrigin = DEM_DTC_ORIGIN_PRIMARY_MEMORY; // Primary memory
\r
1521 dtcFilter.filterWithSeverity = DEM_FILTER_WITH_SEVERITY_NO; // No Severity filtering
\r
1522 dtcFilter.dtcSeverityMask = DEM_SEVERITY_NO_SEVERITY; // Not used when filterWithSeverity is FALSE
\r
1523 dtcFilter.filterForFaultDetectionCounter = DEM_FILTER_FOR_FDC_NO; // No fault detection counter filtering
\r
1525 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1527 disableDtcStorage.storageDisabled = FALSE;
\r
1529 demState = DEM_INITIALIZED;
\r
1534 * Procedure: Dem_shutdown
\r
1537 void Dem_Shutdown(void)
\r
1539 setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_END); /** @req DEM047 */
\r
1541 demState = DEM_UNINITIALIZED; /** @req DEM368 */
\r
1546 * Interface for basic software scheduler
\r
1548 void Dem_MainFunction(void)
\r
1550 /** @req DEM125 */
\r
1555 /***************************************************
\r
1556 * Interface SW-Components via RTE <-> DEM (8.3.3) *
\r
1557 ***************************************************/
\r
1560 * Procedure: Dem_SetEventStatus
\r
1563 Std_ReturnType Dem_SetEventStatus(Dem_EventIdType eventId, Dem_EventStatusType eventStatus) /** @req DEM330 */
\r
1565 Std_ReturnType returnCode = E_OK;
\r
1567 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1569 returnCode = handleEvent(eventId, eventStatus);
\r
1573 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1574 Det_ReportError(MODULE_ID_DEM, 0, DEM_SETEVENTSTATUS_ID, DEM_E_UNINIT); /** @req DEM124.SetEventStatus */ /** @req DEM117 */
\r
1576 returnCode = E_NOT_OK; /** @req DEM370.SetEventStatus */
\r
1579 return returnCode;
\r
1584 * Procedure: Dem_ResetEventStatus
\r
1587 Std_ReturnType Dem_ResetEventStatus(Dem_EventIdType eventId) /** @req DEM331 */
\r
1589 Std_ReturnType returnCode = E_OK;
\r
1591 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1593 resetEventStatus(eventId);
\r
1597 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1598 Det_ReportError(MODULE_ID_DEM, 0, DEM_RESETEVENTSTATUS_ID, DEM_E_UNINIT); /** @req DEM124.ResetEventStatus */ /** @req DEM117 */
\r
1600 returnCode = E_NOT_OK; /** @req DEM370.ResetEventStatus */
\r
1603 return returnCode;
\r
1608 * Procedure: Dem_GetEventStatus
\r
1611 Std_ReturnType Dem_GetEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended) /** @req DEM332 */
\r
1613 Std_ReturnType returnCode = E_OK;
\r
1615 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1617 getEventStatus(eventId, eventStatusExtended);
\r
1621 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1622 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETEVENTSTATUS_ID, DEM_E_UNINIT); /** @req DEM124.GetEventStatus */ /** @req DEM117 */
\r
1624 returnCode = E_NOT_OK; /** @req DEM370.GetEventStatus */
\r
1627 return returnCode;
\r
1632 * Procedure: Dem_GetEventFailed
\r
1635 Std_ReturnType Dem_GetEventFailed(Dem_EventIdType eventId, boolean *eventFailed) /** @req DEM333 */
\r
1637 Std_ReturnType returnCode = E_OK;
\r
1639 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1641 getEventFailed(eventId, eventFailed);
\r
1645 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1646 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETEVENTFAILED_ID, DEM_E_UNINIT); /** @req DEM124.GetEventFailed */ /** @req DEM117 */
\r
1648 returnCode = E_NOT_OK; /** @req DEM370.GetEventFailed */
\r
1651 return returnCode;
\r
1656 * Procedure: Dem_GetEventTested
\r
1659 Std_ReturnType Dem_GetEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1661 Std_ReturnType returnCode = E_OK;
\r
1663 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1665 getEventTested(eventId, eventTested);
\r
1669 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1670 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETEVENTTESTED_ID, DEM_E_UNINIT); /** @req DEM124.GetEventTested */ /** @req DEM117 */
\r
1672 returnCode = E_NOT_OK; /** @req DEM370.GetEventTested */
\r
1675 return returnCode;
\r
1680 * Procedure: Dem_GetFaultDetectionCounter
\r
1683 Std_ReturnType Dem_GetFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1685 Std_ReturnType returnCode = E_OK;
\r
1687 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1689 returnCode = getFaultDetectionCounter(eventId, counter);
\r
1693 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1694 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_UNINIT); /** @req DEM124.GetFaultDetectionCounter */ /** @req DEM117 */
\r
1696 returnCode = E_NOT_OK; /** @req DEM370.GetFaultDetectionCounter */
\r
1699 return returnCode;
\r
1704 * Procedure: Dem_SetOperationCycleState
\r
1707 Std_ReturnType Dem_SetOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState)
\r
1709 Std_ReturnType returnCode = E_OK;
\r
1711 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1713 returnCode = setOperationCycleState(operationCycleId, cycleState);
\r
1718 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1719 Det_ReportError(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_UNINIT); /** @req DEM124.SetOperationCycleState */ /** @req DEM117 */
\r
1721 returnCode = E_NOT_OK; /** @req DEM370.SetOperationCycleState */
\r
1724 return returnCode;
\r
1729 * Procedure: Dem_GetDTCOfEvent
\r
1732 Std_ReturnType Dem_GetDTCOfEvent(Dem_EventIdType eventId, Dem_DTCKindType dtcKind, uint32* dtcOfEvent)
\r
1734 Std_ReturnType returnCode = E_NO_DTC_AVAILABLE;
\r
1735 const Dem_EventParameterType *eventParam;
\r
1737 lookupEventIdParameter(eventId, &eventParam);
\r
1739 if (eventParam != NULL) {
\r
1740 if (checkDtcKind(dtcKind, eventParam)) {
\r
1741 if (eventParam->DTCClassRef != NULL) {
\r
1742 *dtcOfEvent = eventParam->DTCClassRef->DTC; /** @req DEM269 */
\r
1743 returnCode = E_OK;
\r
1748 // Event Id not found
\r
1749 returnCode = E_NOT_OK;
\r
1752 return returnCode;
\r
1756 /********************************************
\r
1757 * Interface BSW-Components <-> DEM (8.3.4) *
\r
1758 ********************************************/
\r
1761 * Procedure: Dem_ReportErrorStatus
\r
1764 void Dem_ReportErrorStatus( Dem_EventIdType eventId, Dem_EventStatusType eventStatus ) /** @req DEM107 */
\r
1767 switch (demState) {
\r
1768 case DEM_PREINITIALIZED:
\r
1769 // Update status and check if is to be stored
\r
1770 if ((eventStatus == DEM_EVENT_STATUS_PASSED) || (eventStatus == DEM_EVENT_STATUS_FAILED)) {
\r
1771 handlePreInitEvent(eventId, eventStatus); /** @req DEM168 */
\r
1775 case DEM_INITIALIZED:
\r
1776 (void)handleEvent(eventId, eventStatus); /** @req DEM167 */
\r
1779 case DEM_UNINITIALIZED:
\r
1781 // Uninitialized can not do anything
\r
1782 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1783 Det_ReportError(MODULE_ID_DEM, 0, DEM_REPORTERRORSTATUS_ID, DEM_E_UNINIT); /** @req DEM124.ReportErrorStatus */ /** @req DEM364 */ /** @req DEM117 */
\r
1787 } // switch (demState)
\r
1790 /*********************************
\r
1791 * Interface DCM <-> DEM (8.3.5) *
\r
1792 *********************************/
\r
1794 * Procedure: Dem_GetDTCStatusAvailabilityMask
\r
1797 Std_ReturnType Dem_GetDTCStatusAvailabilityMask(uint8 *dtcStatusMask) /** @req DEM014 */
\r
1799 *dtcStatusMask = DEM_DTC_STATUS_AVAILABILITY_MASK; // User configuration mask
\r
1800 *dtcStatusMask &= DEM_TEST_FAILED // Mask with supported bits /** @req DEM060 */
\r
1801 | DEM_TEST_FAILED_THIS_OPERATION_CYCLE
\r
1803 // | DEM_CONFIRMED_DTC TODO: Add support for this bit
\r
1804 | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR
\r
1805 | DEM_TEST_FAILED_SINCE_LAST_CLEAR
\r
1806 | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE
\r
1807 // | DEM_WARNING_INDICATOR_REQUESTED TODO: Add support for this bit
\r
1815 * Procedure: Dem_SetDTCFilter
\r
1818 Dem_ReturnSetDTCFilterType Dem_SetDTCFilter(uint8 dtcStatusMask,
\r
1819 Dem_DTCKindType dtcKind,
\r
1820 Dem_DTCOriginType dtcOrigin,
\r
1821 Dem_FilterWithSeverityType filterWithSeverity,
\r
1822 Dem_DTCSeverityType dtcSeverityMask,
\r
1823 Dem_FilterForFDCType filterForFaultDetectionCounter) {
\r
1825 Dem_ReturnSetDTCFilterType returnCode = DEM_WRONG_FILTER;
\r
1827 // Check dtcKind parameter
\r
1828 if ((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS)) {
\r
1830 // Check dtcOrigin parameter
\r
1831 if ((dtcOrigin == DEM_DTC_ORIGIN_SECONDARY_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_PRIMARY_MEMORY)
\r
1832 || (dtcOrigin == DEM_DTC_ORIGIN_PERMANENT_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_MIRROR_MEMORY)) {
\r
1834 // Check filterWithSeverity and dtcSeverityMask parameter
\r
1835 if ((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
1836 || ((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES) && !(dtcSeverityMask & ~(DEM_SEVERITY_MAINTENANCE_ONLY | DEM_SEVERITY_CHECK_AT_NEXT_FALT | DEM_SEVERITY_CHECK_IMMEDIATELY)))){
\r
1838 // Check filterForFaultDetectionCounter parameter
\r
1839 if ((filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_YES) || (filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO)) {
\r
1840 // Yes all parameters correct, set the new filters. /** @req DEM057 */
\r
1841 dtcFilter.dtcStatusMask = dtcStatusMask;
\r
1842 dtcFilter.dtcKind = dtcKind;
\r
1843 dtcFilter.dtcOrigin = dtcOrigin;
\r
1844 dtcFilter.filterWithSeverity = filterWithSeverity;
\r
1845 dtcFilter.dtcSeverityMask = dtcSeverityMask;
\r
1846 dtcFilter.filterForFaultDetectionCounter = filterForFaultDetectionCounter;
\r
1847 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1848 returnCode = DEM_FILTER_ACCEPTED;
\r
1854 return returnCode;
\r
1859 * Procedure: Dem_GetStatusOfDTC
\r
1862 Dem_ReturnGetStatusOfDTCType Dem_GetStatusOfDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, Dem_EventStatusExtendedType* status) {
\r
1863 Dem_ReturnGetStatusOfDTCType returnCode = DEM_STATUS_FAILED;
\r
1864 EventStatusRecType *eventRec;
\r
1866 if (lookupDtcEvent(dtc, &eventRec)) {
\r
1867 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
1868 if (checkDtcOrigin(dtcOrigin,eventRec->eventParamRef)) {
\r
1869 *status = eventRec->eventStatusExtended; /** @req DEM059 */
\r
1870 returnCode = DEM_STATUS_OK;
\r
1873 returnCode = DEM_STATUS_WRONG_DTCORIGIN; /** @req DEM171 */
\r
1877 returnCode = DEM_STATUS_WRONG_DTCKIND;
\r
1881 returnCode = DEM_STATUS_WRONG_DTC; /** @req DEM172 */
\r
1884 return returnCode;
\r
1889 * Procedure: Dem_GetNumberOfFilteredDtc
\r
1892 Dem_ReturnGetNumberOfFilteredDTCType Dem_GetNumberOfFilteredDtc(uint16 *numberOfFilteredDTC) {
\r
1894 uint16 numberOfFaults = 0;
\r
1896 //Dem_DisableEventStatusUpdate();
\r
1898 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1899 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1900 if (matchEventWithDtcFilter(&eventStatusBuffer[i])) {
\r
1901 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
1908 //Dem_EnableEventStatusUpdate();
\r
1910 *numberOfFilteredDTC = numberOfFaults; /** @req DEM061 */
\r
1912 return DEM_NUMBER_OK;
\r
1917 * Procedure: Dem_GetNextFilteredDTC
\r
1920 Dem_ReturnGetNextFilteredDTCType Dem_GetNextFilteredDTC(uint32 *dtc, Dem_EventStatusExtendedType *dtcStatus)
\r
1922 Dem_ReturnGetNextFilteredDTCType returnCode = DEM_FILTERED_OK;
\r
1923 boolean dtcFound = FALSE;
\r
1925 // TODO: This job should be done in an more advanced way according to Dem217
\r
1926 while (!dtcFound && (dtcFilter.faultIndex != 0)) {
\r
1927 dtcFilter.faultIndex--;
\r
1928 if (eventStatusBuffer[dtcFilter.faultIndex].eventId != DEM_EVENT_ID_NULL) {
\r
1929 if (matchEventWithDtcFilter(&eventStatusBuffer[dtcFilter.faultIndex])) {
\r
1930 if (eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef != NULL) {
\r
1931 *dtc = eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef->DTC; /** @req DEM216 */
\r
1932 *dtcStatus = eventStatusBuffer[dtcFilter.faultIndex].eventStatusExtended;
\r
1940 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1941 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
1944 return returnCode;
\r
1949 * Procedure: Dem_GetTranslationType
\r
1952 Dem_ReturnTypeOfDtcSupportedType Dem_GetTranslationType(void)
\r
1954 return DEM_TYPE_OF_DTC_SUPPORTED; /** @req DEM231 */
\r
1959 * Procedure: Dem_ClearDTC
\r
1962 Dem_ReturnClearDTCType Dem_ClearDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin) /** @req DEM009 */
\r
1964 Dem_ReturnClearDTCType returnCode = DEM_CLEAR_OK;
\r
1965 Dem_EventIdType eventId;
\r
1966 const Dem_EventParameterType *eventParam;
\r
1969 // Loop through the event buffer
\r
1970 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1971 eventId = eventStatusBuffer[i].eventId;
\r
1972 if (eventId != DEM_EVENT_ID_NULL) {
\r
1973 eventParam = eventStatusBuffer[i].eventParamRef;
\r
1974 if (eventParam != NULL) {
\r
1975 if (DEM_CLEAR_ALL_EVENTS | (eventParam->DTCClassRef != NULL)) {
\r
1976 if (checkDtcKind(dtcKind, eventParam)) {
\r
1977 if (checkDtcGroup(dtc, eventParam)) {
\r
1978 for (j = 0; (j < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[j] != dtcOrigin); j++);
\r
1979 if (j < DEM_MAX_NR_OF_EVENT_DESTINATION) {
\r
1980 // Yes! All conditions met.
\r
1981 switch (dtcOrigin)
\r
1983 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1984 /** @req DEM077 */
\r
1985 deleteEventPriMem(eventParam);
\r
1986 deleteFreezeFrameDataPriMem(eventParam);
\r
1987 deleteExtendedDataPriMem(eventParam);
\r
1988 deleteEventStatusRec(eventParam); // TODO: Shall this be done or just resetting the status?
\r
1991 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1992 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1993 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1994 // Not yet supported
\r
1995 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
1996 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1997 Det_ReportError(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
2001 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2010 // Fatal error, no event parameters found for the stored event!
\r
2011 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
2012 Det_ReportError(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNEXPECTED_EXECUTION); /** @req DEM117 */
\r
2018 return returnCode;
\r
2023 * Procedure: Dem_DisableDTCStorage
\r
2026 Dem_ReturnControlDTCStorageType Dem_DisableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind) /** @req DEM35 */
\r
2028 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2030 // Check dtcGroup parameter
\r
2031 if (dtcGroup == DEM_DTC_GROUP_ALL_DTCS) {
\r
2032 // Check dtcKind parameter
\r
2033 if ((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS)) {
\r
2034 /** @req DEM079 */
\r
2035 disableDtcStorage.dtcGroup = dtcGroup;
\r
2036 disableDtcStorage.dtcKind = dtcKind;
\r
2037 disableDtcStorage.storageDisabled = TRUE;
\r
2039 returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2043 returnCode = DEM_CONTROL_DTC_WRONG_DTCGROUP;
\r
2046 return returnCode;
\r
2051 * Procedure: Dem_EnableDTCStorage
\r
2054 Dem_ReturnControlDTCStorageType Dem_EnableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind)
\r
2056 // TODO: Behavior is not defined if group or kind do not match active settings, therefore the filter is just switched off.
\r
2057 disableDtcStorage.storageDisabled = FALSE; /** @req DEM080 */
\r
2059 return DEM_CONTROL_DTC_STORAGE_OK;
\r
2063 * Procedure: Dem_GetExtendedDataRecordByDTC
\r
2066 Dem_ReturnGetExtendedDataRecordByDTCType Dem_GetExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint8 *destBuffer, uint8 *bufSize)
\r
2068 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_RECORD_WRONG_DTC;
\r
2069 EventStatusRecType *eventRec;
\r
2070 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2071 ExtDataRecType *extData;
\r
2072 uint8 posInExtData = 0;
\r
2074 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2075 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2076 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2077 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2078 if (*bufSize >= extendedDataRecordClass->DataSize) {
\r
2079 switch (dtcOrigin)
\r
2081 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2082 if (lookupExtendedDataPriMem(eventRec->eventId, &extData)) {
\r
2083 // Yes all conditions met, copy the extended data record to destination buffer.
\r
2084 memcpy(destBuffer, &extData->data[posInExtData], extendedDataRecordClass->DataSize); /** @req DEM075 */
\r
2085 *bufSize = extendedDataRecordClass->DataSize;
\r
2086 returnCode = DEM_RECORD_OK;
\r
2089 // The record number is legal but no record was found for the DTC
\r
2091 returnCode = DEM_RECORD_OK;
\r
2095 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2096 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2097 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2098 // Not yet supported
\r
2099 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2100 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
2101 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
2105 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2110 returnCode = DEM_RECORD_BUFFERSIZE;
\r
2114 returnCode = DEM_RECORD_NUMBER;
\r
2118 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2122 returnCode = DEM_RECORD_DTCKIND;
\r
2126 return returnCode;
\r
2131 * Procedure: Dem_GetSizeOfExtendedDataRecordByDTC
\r
2134 Dem_ReturnGetSizeOfExtendedDataRecordByDTCType Dem_GetSizeOfExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint16 *sizeOfExtendedDataRecord)
\r
2136 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2137 EventStatusRecType *eventRec;
\r
2138 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2139 uint8 posInExtData;
\r
2141 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2142 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2143 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2144 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2145 *sizeOfExtendedDataRecord = extendedDataRecordClass->DataSize; /** @req DEM076 */
\r
2146 returnCode = DEM_GET_SIZEOFEDRBYDTC_OK;
\r
2149 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_RNUM;
\r
2153 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCOR;
\r
2157 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCKI;
\r
2161 return returnCode;
\r
2164 /***********************************
\r
2165 * OBD-specific Interfaces (8.3.6) *
\r
2166 ***********************************/
\r