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
25 //#include "SchM_Dem.h"
\r
32 #define DEBOUNCE_FDC_TEST_FAILED 127
\r
33 #define DEBOUNCE_FDC_TEST_PASSED -128
\r
39 typedef uint16 ChecksumType;
\r
43 Dem_EventStatusExtendedType dtcStatusMask;
\r
44 Dem_DTCKindType dtcKind;
\r
45 Dem_DTCOriginType dtcOrigin;
\r
46 Dem_FilterWithSeverityType filterWithSeverity;
\r
47 Dem_DTCSeverityType dtcSeverityMask;
\r
48 Dem_FilterForFDCType filterForFaultDetectionCounter;
\r
52 // DisableDtcStorageType
\r
54 boolean storageDisabled;
\r
55 Dem_DTCGroupType dtcGroup;
\r
56 Dem_DTCKindType dtcKind;
\r
57 } DisableDtcStorageType;
\r
59 // For keeping track of the events status
\r
61 Dem_EventIdType eventId;
\r
62 const Dem_EventParameterType *eventParamRef;
\r
63 sint8 faultDetectionCounter;
\r
65 Dem_EventStatusExtendedType eventStatusExtended;
\r
66 boolean errorStatusChanged;
\r
67 } EventStatusRecType;
\r
70 // Types for storing different event data on event memory
\r
72 Dem_EventIdType eventId;
\r
74 ChecksumType checksum;
\r
78 Dem_EventIdType eventId;
\r
81 sint8 data[DEM_MAX_SIZE_FF_DATA];
\r
82 ChecksumType checksum;
\r
83 } FreezeFrameRecType;
\r
86 Dem_EventIdType eventId;
\r
88 uint8 data[DEM_MAX_SIZE_EXT_DATA];
\r
89 ChecksumType checksum;
\r
96 DEM_UNINITIALIZED = 0,
\r
102 static Dem_StateType demState = DEM_UNINITIALIZED;
\r
104 // Help pointer to configuration set
\r
105 static const Dem_ConfigSetType *configSet;
\r
108 * Allocation of DTC filter parameters
\r
110 static DtcFilterType dtcFilter;
\r
113 * Allocation of Disable/Enable DTC storage parameters
\r
115 static DisableDtcStorageType disableDtcStorage;
\r
118 * Allocation of operation cycle state list
\r
120 static Dem_OperationCycleStateType operationCycleStateList[DEM_OPERATION_CYCLE_ID_ENDMARK];
\r
123 * Allocation of local event status buffer
\r
125 static EventStatusRecType eventStatusBuffer[DEM_MAX_NUMBER_EVENT];
\r
128 * Allocation of pre-init event memory (used between pre-init and init)
\r
130 static FreezeFrameRecType preInitFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRE_INIT];
\r
131 static ExtDataRecType preInitExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRE_INIT];
\r
134 * Allocation of primary event memory ramlog (after init) in uninitialized memory
\r
136 static EventRecType priMemEventBuffer[DEM_MAX_NUMBER_EVENT_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
137 static FreezeFrameRecType priMemFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
138 static ExtDataRecType priMemExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
142 * Procedure: zeroPriMemBuffers
\r
143 * Description: Fill the primary buffers with zeroes
\r
145 void demZeroPriMemBuffers(void)
\r
147 memset(priMemEventBuffer, 0, sizeof(priMemEventBuffer));
\r
148 memset(priMemFreezeFrameBuffer, 0, sizeof(priMemFreezeFrameBuffer));
\r
149 memset(priMemExtDataBuffer, 0, sizeof(priMemExtDataBuffer));
\r
154 * Procedure: calcChecksum
\r
155 * Description: Calculate checksum over *data to *(data+nrOfBytes-1) area
\r
157 static ChecksumType calcChecksum(void *data, uint16 nrOfBytes)
\r
160 uint8 *ptr = (uint8*)data;
\r
161 ChecksumType sum = 0;
\r
163 for (i = 0; i < nrOfBytes; i++)
\r
171 * Procedure: checkDtcKind
\r
172 * Description: Return TRUE if "dtcKind" match the events DTCKind or "dtcKind"
\r
173 * is "DEM_DTC_KIND_ALL_DTCS" otherwise FALSE.
\r
175 static boolean checkDtcKind(Dem_DTCKindType dtcKind, const Dem_EventParameterType *eventParam)
\r
177 boolean result = FALSE;
\r
179 if (dtcKind == DEM_DTC_KIND_ALL_DTCS) {
\r
183 if (eventParam->DTCClassRef != NULL) {
\r
184 if (eventParam->DTCClassRef->DTCKind == dtcKind) {
\r
194 * Procedure: checkDtcGroup
\r
195 * Description: Return TRUE if "dtc" match the events DTC or "dtc" is
\r
196 * "DEM_DTC_GROUP_ALL_DTCS" otherwise FALSE.
\r
198 static boolean checkDtcGroup(uint32 dtc, const Dem_EventParameterType *eventParam)
\r
200 boolean result = FALSE;
\r
202 if (dtc == DEM_DTC_GROUP_ALL_DTCS) {
\r
206 if (eventParam->DTCClassRef != NULL) {
\r
207 if (eventParam->DTCClassRef->DTC == dtc) {
\r
217 * Procedure: checkDtcOrigin
\r
218 * Description: Return TRUE if "dtcOrigin" match any of the events DTCOrigin otherwise FALSE.
\r
220 static boolean checkDtcOrigin(Dem_DTCOriginType dtcOrigin, const Dem_EventParameterType *eventParam)
\r
222 boolean result = FALSE;
\r
225 for (i = 0; (eventParam->EventClass->EventDestination[i] != dtcOrigin) && (i < DEM_MAX_NR_OF_EVENT_DESTINATION); i++);
\r
227 if (i < DEM_MAX_NR_OF_EVENT_DESTINATION) {
\r
236 * Procedure: checkDtcSeverityMask
\r
237 * Description: Return TRUE if "dtcSeverityMask" match any of the events DTC severity otherwise FALSE.
\r
239 static boolean checkDtcSeverityMask(Dem_DTCSeverityType dtcSeverityMask, const Dem_EventParameterType *eventParam)
\r
241 boolean result = TRUE;
\r
243 // TODO: This function is optional, may be implemented here.
\r
250 * Procedure: checkDtcFaultDetectionCounterMask
\r
251 * Description: TBD.
\r
253 static boolean checkDtcFaultDetectionCounter(const Dem_EventParameterType *eventParam)
\r
255 boolean result = TRUE;
\r
257 // TODO: Not implemented yet.
\r
264 * Procedure: lookupEventStatusRec
\r
265 * Description: Returns the pointer to event id parameters of "eventId" in "*eventStatusBuffer",
\r
266 * if not found NULL is returned.
\r
268 static void lookupEventStatusRec(Dem_EventIdType eventId, EventStatusRecType **const eventStatusRec)
\r
270 EventStatusRecType *eventStatusRecPtr = eventStatusBuffer;
\r
272 while ((eventStatusRecPtr->eventId != eventId) && (eventStatusRecPtr < &eventStatusBuffer[DEM_MAX_NUMBER_EVENT])) {
\r
273 eventStatusRecPtr++;
\r
276 if (eventStatusRecPtr < &eventStatusBuffer[DEM_MAX_NUMBER_EVENT]) {
\r
277 *eventStatusRec = eventStatusRecPtr;
\r
279 *eventStatusRec = NULL;
\r
285 * Procedure: lookupEventIdParameter
\r
286 * Description: Returns the pointer to event id parameters of "eventId" in "*eventIdParam",
\r
287 * if not found NULL is returned.
\r
289 static void lookupEventIdParameter(Dem_EventIdType eventId, const Dem_EventParameterType **const eventIdParam)
\r
291 const Dem_EventParameterType *EventIdParamPtr = configSet->EventParameter;
\r
293 // Lookup the correct event id parameters
\r
294 while ((EventIdParamPtr->EventID != eventId) && !EventIdParamPtr->Arc_EOL) {
\r
298 if (!EventIdParamPtr->Arc_EOL) {
\r
299 *eventIdParam = EventIdParamPtr;
\r
301 *eventIdParam = NULL;
\r
307 * Procedure: preDebounceNone
\r
308 * Description: Returns the result of the debouncing.
\r
310 static Dem_EventStatusType preDebounceNone(Dem_EventStatusType reportedStatus, EventStatusRecType* statusRecord) {
\r
311 Dem_EventStatusType returnCode;
\r
313 switch (reportedStatus) {
\r
314 case DEM_EVENT_STATUS_FAILED:
\r
315 case DEM_EVENT_STATUS_PASSED:
\r
316 // Already debounced, do nothing.
\r
320 // TODO: What to do with PREFAIL and PREPASSED on no debouncing?
\r
321 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
322 Det_ReportError(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_NONE_ID, DEM_E_PARAM_DATA);
\r
327 returnCode = reportedStatus;
\r
333 * Procedure: preDebounceCounterBased
\r
334 * Description: Returns the result of the debouncing.
\r
336 static Dem_EventStatusType preDebounceCounterBased(Dem_EventStatusType reportedStatus, EventStatusRecType* statusRecord) {
\r
337 Dem_EventStatusType returnCode;
\r
338 const Dem_PreDebounceCounterBasedType* pdVars = statusRecord->eventParamRef->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceCounterBased;
\r
340 switch (reportedStatus) {
\r
341 case DEM_EVENT_STATUS_PREFAILED:
\r
342 if (statusRecord->faultDetectionCounter < DEBOUNCE_FDC_TEST_FAILED) {
\r
343 if (pdVars->JumpUp && (statusRecord->faultDetectionCounter < 0)) {
\r
344 statusRecord->faultDetectionCounter = 0;
\r
346 if (((sint16)statusRecord->faultDetectionCounter + pdVars->CountInStepSize) < DEBOUNCE_FDC_TEST_FAILED) {
\r
347 statusRecord->faultDetectionCounter += pdVars->CountInStepSize;
\r
349 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED;
\r
355 case DEM_EVENT_STATUS_PREPASSED:
\r
356 if (statusRecord->faultDetectionCounter > DEBOUNCE_FDC_TEST_PASSED) {
\r
357 if (pdVars->JumpDown && (statusRecord->faultDetectionCounter > 0)) {
\r
358 statusRecord->faultDetectionCounter = 0;
\r
360 if (((sint16)statusRecord->faultDetectionCounter - pdVars->CountOutStepSize) > DEBOUNCE_FDC_TEST_PASSED) {
\r
361 statusRecord->faultDetectionCounter -= pdVars->CountOutStepSize;
\r
363 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED;
\r
369 case DEM_EVENT_STATUS_FAILED:
\r
370 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED;
\r
373 case DEM_EVENT_STATUS_PASSED:
\r
374 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED;
\r
378 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
379 Det_ReportError(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_COUNTER_BASED_ID, DEM_E_PARAM_DATA);
\r
385 switch (statusRecord->faultDetectionCounter) {
\r
386 case DEBOUNCE_FDC_TEST_FAILED:
\r
387 returnCode = DEM_EVENT_STATUS_FAILED;
\r
390 case DEBOUNCE_FDC_TEST_PASSED:
\r
391 returnCode = DEM_EVENT_STATUS_PASSED;
\r
395 returnCode = reportedStatus;
\r
404 * Procedure: updateEventStatusRec
\r
405 * Description: Update the status of "eventId", if not exist and "createIfNotExist" is
\r
406 * true a new record is created
\r
408 static void updateEventStatusRec(const Dem_EventParameterType *eventParam, Dem_EventStatusType eventStatus, boolean createIfNotExist, EventStatusRecType *eventStatusRec)
\r
410 EventStatusRecType *eventStatusRecPtr;
\r
411 imask_t state = McuE_EnterCriticalSection();
\r
414 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
416 if ((eventStatusRecPtr == NULL) && (createIfNotExist)) {
\r
417 // Search for free position
\r
418 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
420 if (eventStatusRecPtr != NULL) {
\r
421 // Create new event record
\r
422 eventStatusRecPtr->eventId = eventParam->EventID;
\r
423 eventStatusRecPtr->eventParamRef = eventParam;
\r
424 eventStatusRecPtr->faultDetectionCounter = 0;
\r
425 eventStatusRecPtr->occurrence = 0;
\r
426 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
427 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
430 // Error: Event status buffer full
\r
431 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
432 Det_ReportError(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
438 if (eventStatusRecPtr != NULL) {
\r
439 // Handle debouncing
\r
440 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName) {
\r
441 case DEM_NO_PRE_DEBOUNCE:
\r
442 eventStatus = preDebounceNone(eventStatus, eventStatusRecPtr);
\r
445 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
446 eventStatus = preDebounceCounterBased(eventStatus, eventStatusRecPtr);
\r
450 // Don't know how to handle this.
\r
451 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
452 Det_ReportError(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
458 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
460 // Check test failed
\r
461 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
462 if (!(eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED)) {
\r
463 eventStatusRecPtr->occurrence++;
\r
464 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
466 eventStatusRecPtr->eventStatusExtended |= (DEM_TEST_FAILED | DEM_TEST_FAILED_THIS_OPERATION_CYCLE | DEM_TEST_FAILED_SINCE_LAST_CLEAR | DEM_PENDING_DTC);
\r
467 eventStatusRecPtr->eventStatusExtended &= ~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
470 // Check test passed
\r
471 if (eventStatus == DEM_EVENT_STATUS_PASSED) {
\r
472 if (eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED) {
\r
473 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
475 eventStatusRecPtr->eventStatusExtended &= ~DEM_TEST_FAILED;
\r
476 eventStatusRecPtr->eventStatusExtended &= ~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
480 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
483 // Copy an empty record to return data
\r
484 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
485 eventStatusRecPtr->faultDetectionCounter = 0;
\r
486 eventStatusRec->occurrence = 0;
\r
487 eventStatusRec->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
488 eventStatusRec->errorStatusChanged = FALSE;
\r
491 McuE_ExitCriticalSection(state);
\r
496 * Procedure: mergeEventStatusRec
\r
497 * Description: Update the occurrence counter of status, if not exist a new record is created
\r
499 static void mergeEventStatusRec(EventRecType *eventRec)
\r
501 EventStatusRecType *eventStatusRecPtr;
\r
502 imask_t state = McuE_EnterCriticalSection();
\r
505 lookupEventStatusRec(eventRec->eventId, &eventStatusRecPtr);
\r
507 if (eventStatusRecPtr != NULL) {
\r
508 // Update occurrence counter, rest of pre init state is kept.
\r
509 eventStatusRecPtr->occurrence += eventRec->occurrence;
\r
513 // Search for free position
\r
514 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
516 if (eventStatusRecPtr != NULL) {
\r
517 // Create new event, from stored event
\r
518 eventStatusRecPtr->eventId = eventRec->eventId;
\r
519 lookupEventIdParameter(eventRec->eventId, &eventStatusRecPtr->eventParamRef);
\r
520 eventStatusRecPtr->faultDetectionCounter = 0;
\r
521 eventStatusRecPtr->occurrence = eventRec->occurrence;
\r
522 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
523 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
526 // Error: Event status buffer full
\r
527 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
528 Det_ReportError(MODULE_ID_DEM, 0, DEM_MERGE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
533 McuE_ExitCriticalSection(state);
\r
538 * Procedure: deleteEventStatusRec
\r
539 * Description: Delete the status record of "eventParam->eventId" from "eventStatusBuffer".
\r
541 static void deleteEventStatusRec(const Dem_EventParameterType *eventParam)
\r
543 EventStatusRecType *eventStatusRecPtr;
\r
544 imask_t state = McuE_EnterCriticalSection();
\r
547 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
549 if (eventStatusRecPtr != NULL) {
\r
550 // Delete event record
\r
551 memset(eventStatusRecPtr, 0, sizeof(EventStatusRecType));
\r
554 McuE_ExitCriticalSection(state);
\r
559 * Procedure: getEventStatusRec
\r
560 * Description: Returns the status record of "eventId" in "eventStatusRec"
\r
562 static void getEventStatusRec(Dem_EventIdType eventId, EventStatusRecType *eventStatusRec)
\r
564 EventStatusRecType *eventStatusRecPtr;
\r
567 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
569 if (eventStatusRecPtr != NULL) {
\r
571 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
574 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
580 * Procedure: lookupDtcEvent
\r
581 * Description: Returns TRUE if the DTC was found and "eventStatusRec" points
\r
582 * to the event record found.
\r
584 static boolean lookupDtcEvent(uint32 dtc, EventStatusRecType **eventStatusRec)
\r
586 boolean dtcFound = FALSE;
\r
589 *eventStatusRec = NULL;
\r
591 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && !dtcFound; i++) {
\r
592 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
593 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
596 if (eventStatusBuffer[i].eventParamRef->DTCClassRef->DTC == dtc) {
\r
597 *eventStatusRec = &eventStatusBuffer[i];
\r
609 * Procedure: matchEventWithDtcFilter
\r
610 * Description: Returns TRUE if the event pointed by "event" fulfill
\r
611 * the "dtcFilter" global filter settings.
\r
613 static boolean matchEventWithDtcFilter(const EventStatusRecType *eventRec)
\r
615 boolean dtcMatch = FALSE;
\r
618 if ((dtcFilter.dtcStatusMask == DEM_DTC_STATUS_MASK_ALL) || (eventRec->eventStatusExtended & dtcFilter.dtcStatusMask)) {
\r
619 if (eventRec->eventParamRef != NULL) {
\r
622 if (checkDtcKind(dtcFilter.dtcKind, eventRec->eventParamRef)) {
\r
625 if (checkDtcOrigin(dtcFilter.dtcOrigin, eventRec->eventParamRef)) {
\r
628 if ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
629 || ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES) && checkDtcSeverityMask(dtcFilter.dtcSeverityMask, eventRec->eventParamRef))) {
\r
631 // Check fault detection counter
\r
632 if ((dtcFilter.filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO)
\r
633 || ((dtcFilter.filterWithSeverity == DEM_FILTER_FOR_FDC_YES) && checkDtcFaultDetectionCounter(eventRec->eventParamRef))) {
\r
646 static void getFreezeFrameData(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
649 freezeFrame->eventId = DEM_EVENT_ID_NULL; // Not supported yet
\r
653 static void storeFreezeFrameDataPreInit(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
659 static void updateFreezeFrameOccurrencePreInit(EventRecType *EventBuffer)
\r
666 * Procedure: getExtendedData
\r
667 * Description: Collects the extended data according to "eventParam" and return it in "extData",
\r
668 * if not found eventId is set to DEM_EVENT_ID_NULL.
\r
670 static void getExtendedData(const Dem_EventParameterType *eventParam, ExtDataRecType *extData)
\r
672 Std_ReturnType callbackReturnCode;
\r
674 uint16 storeIndex = 0;
\r
677 // Clear ext data record
\r
678 memset(extData, 0, sizeof(ExtDataRecType));
\r
680 // Check if any pointer to extended data class
\r
681 if (eventParam->ExtendedDataClassRef != NULL) {
\r
682 // Request extended data and copy it to the buffer
\r
683 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL); i++) {
\r
684 recordSize = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
685 if ((storeIndex + recordSize) <= DEM_MAX_SIZE_EXT_DATA) {
\r
686 callbackReturnCode = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->CallbackGetExtDataRecord(&extData->data[storeIndex]);
\r
687 if (callbackReturnCode != E_OK) {
\r
688 // Callback data currently not available, clear space.
\r
689 memset(&extData->data[storeIndex], 0xFF, recordSize);
\r
691 storeIndex += recordSize;
\r
694 // Error: Size of extended data record is bigger than reserved space.
\r
695 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
696 Det_ReportError(MODULE_ID_DEM, 0, DEM_GET_EXTENDED_DATA_ID, DEM_E_EXT_DATA_TOO_BIG);
\r
698 break; // Break the loop
\r
703 // Check if any data has been stored
\r
704 if (storeIndex != 0) {
\r
705 extData->eventId = eventParam->EventID;
\r
706 extData->dataSize = storeIndex;
\r
707 extData->checksum = calcChecksum(extData, sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
710 extData->eventId = DEM_EVENT_ID_NULL;
\r
711 extData->dataSize = storeIndex;
\r
712 extData->checksum = 0;
\r
718 * Procedure: storeExtendedDataPreInit
\r
719 * Description: Store the extended data pointed by "extendedData" to the "preInitExtDataBuffer",
\r
720 * if non existent a new entry is created.
\r
722 static void storeExtendedDataPreInit(const Dem_EventParameterType *eventParam, ExtDataRecType *extendedData)
\r
725 imask_t state = McuE_EnterCriticalSection();
\r
727 // Check if already stored
\r
728 for (i = 0; (preInitExtDataBuffer[i].eventId != eventParam->EventID) && (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT); i++);
\r
730 if (i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) {
\r
731 // Yes, overwrite existing
\r
732 memcpy(&preInitExtDataBuffer[i], extendedData, sizeof(ExtDataRecType));
\r
735 // No, lookup first free position
\r
736 for (i = 0; (preInitExtDataBuffer[i].eventId !=0) && (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT); i++);
\r
738 if (i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) {
\r
739 memcpy(&preInitExtDataBuffer[i], extendedData, sizeof(ExtDataRecType));
\r
742 // Error: Pre init extended data buffer full
\r
743 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
744 Det_ReportError(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRE_INIT_ID, DEM_E_PRE_INIT_EXT_DATA_BUFF_FULL);
\r
749 McuE_ExitCriticalSection(state);
\r
754 * Procedure: storeEventPriMem
\r
755 * Description: Store the event data of "eventStatus->eventId" in "priMemEventBuffer",
\r
756 * if non existent a new entry is created.
\r
758 static void storeEventPriMem(const Dem_EventParameterType *eventParam, EventStatusRecType *eventStatus)
\r
761 imask_t state = McuE_EnterCriticalSection();
\r
765 for (i = 0; (priMemEventBuffer[i].eventId != eventStatus->eventId) && (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI); i++);
\r
767 if (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) {
\r
768 // Update event found
\r
769 priMemEventBuffer[i].occurrence = eventStatus->occurrence;
\r
770 priMemEventBuffer[i].checksum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
773 // Search for free position
\r
774 for (i=0; (priMemEventBuffer[i].eventId != DEM_EVENT_ID_NULL) && (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI); i++);
\r
776 if (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) {
\r
777 priMemEventBuffer[i].eventId = eventStatus->eventId;
\r
778 priMemEventBuffer[i].occurrence = eventStatus->occurrence;
\r
779 priMemEventBuffer[i].checksum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
782 // Error: Pri mem event buffer full
\r
783 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
784 Det_ReportError(MODULE_ID_DEM, 0, DEM_STORE_EVENT_PRI_MEM_ID, DEM_E_PRI_MEM_EVENT_BUFF_FULL);
\r
789 McuE_ExitCriticalSection(state);
\r
794 * Procedure: deleteEventPriMem
\r
795 * Description: Delete the event data of "eventParam->eventId" from "priMemEventBuffer".
\r
797 static void deleteEventPriMem(const Dem_EventParameterType *eventParam)
\r
800 imask_t state = McuE_EnterCriticalSection();
\r
804 for (i = 0; (priMemEventBuffer[i].eventId != eventParam->EventID) && (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI); i++);
\r
806 if (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) {
\r
807 // Delete event found
\r
808 memset(&priMemEventBuffer[i], 0, sizeof(EventRecType));
\r
811 McuE_ExitCriticalSection(state);
\r
816 * Procedure: storeEventEvtMem
\r
817 * Description: Store the event data of "eventStatus->eventId" in event memory according to
\r
818 * "eventParam" destination option.
\r
820 static void storeEventEvtMem(const Dem_EventParameterType *eventParam, EventStatusRecType *eventStatus)
\r
824 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != NULL); i++) {
\r
825 switch (eventParam->EventClass->EventDestination[i])
\r
827 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
828 storeEventPriMem(eventParam, eventStatus);
\r
831 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
832 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
833 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
834 // Not yet supported
\r
835 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
836 Det_ReportError(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
847 * Procedure: storeExtendedDataPriMem
\r
848 * Description: Store the extended data pointed by "extendedData" to the "priMemExtDataBuffer",
\r
849 * if non existent a new entry is created.
\r
851 static void storeExtendedDataPriMem(const Dem_EventParameterType *eventParam, ExtDataRecType *extendedData)
\r
854 imask_t state = McuE_EnterCriticalSection();
\r
856 // Check if already stored
\r
857 for (i = 0; (priMemExtDataBuffer[i].eventId != eventParam->EventID) && (i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM); i++);
\r
859 if (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) {
\r
860 // Yes, overwrite existing
\r
861 memcpy(&priMemExtDataBuffer[i], extendedData, sizeof(ExtDataRecType));
\r
864 // No, lookup first free position
\r
865 for (i = 0; (priMemExtDataBuffer[i].eventId != DEM_EVENT_ID_NULL) && (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM); i++);
\r
866 if (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) {
\r
867 memcpy(&priMemExtDataBuffer[i], extendedData, sizeof(ExtDataRecType));
\r
870 // Error: Pri mem extended data buffer full
\r
871 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
872 Det_ReportError(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRI_MEM_ID, DEM_E_PRI_MEM_EXT_DATA_BUFF_FULL);
\r
877 McuE_ExitCriticalSection(state);
\r
882 * Procedure: deleteExtendedDataPriMem
\r
883 * Description: Delete the extended data of "eventParam->eventId" from "priMemExtDataBuffer".
\r
885 static void deleteExtendedDataPriMem(const Dem_EventParameterType *eventParam)
\r
888 imask_t state = McuE_EnterCriticalSection();
\r
890 // Check if already stored
\r
891 for (i = 0; (priMemExtDataBuffer[i].eventId != eventParam->EventID) && (i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM); i++);
\r
893 if (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) {
\r
894 // Yes, clear record
\r
895 memset(&priMemExtDataBuffer[i], 0, sizeof(ExtDataRecType));
\r
898 McuE_ExitCriticalSection(state);
\r
903 * Procedure: storeExtendedDataEvtMem
\r
904 * Description: Store the extended data in event memory according to
\r
905 * "eventParam" destination option
\r
907 static void storeExtendedDataEvtMem(const Dem_EventParameterType *eventParam, ExtDataRecType *extendedData)
\r
911 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != NULL); i++) {
\r
912 switch (eventParam->EventClass->EventDestination[i])
\r
914 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
915 storeExtendedDataPriMem(eventParam, extendedData);
\r
918 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
919 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
920 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
921 // Not yet supported
\r
922 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
923 Det_ReportError(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
935 * Procedure: lookupExtendedDataRecNumParam
\r
936 * Description: Returns TRUE if the requested extended data number was found among the configured records for the event.
\r
937 * "extDataRecClassPtr" returns a pointer to the record class, "posInExtData" returns the position in stored extended data.
\r
939 static boolean lookupExtendedDataRecNumParam(uint8 extendedDataNumber, const Dem_EventParameterType *eventParam, Dem_ExtendedDataRecordClassType const **extDataRecClassPtr, uint8 *posInExtData)
\r
941 boolean recNumFound = FALSE;
\r
943 if (eventParam->ExtendedDataClassRef != NULL) {
\r
944 Dem_ExtendedDataRecordClassType const* const* extDataRecClassRefList = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef;
\r
945 uint16 byteCnt = 0;
\r
948 // Request extended data and copy it to the buffer
\r
949 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (extDataRecClassRefList[i] != NULL) && !recNumFound; i++) {
\r
950 if (extDataRecClassRefList[i]->RecordNumber == extendedDataNumber) {
\r
951 *extDataRecClassPtr = extDataRecClassRefList[i];
\r
952 *posInExtData = byteCnt;
\r
953 recNumFound = TRUE;
\r
955 byteCnt += extDataRecClassRefList[i]->DataSize;
\r
959 return recNumFound;
\r
964 * Procedure: lookupExtendedDataPriMem
\r
965 * Description: Returns TRUE if the requested event id is found, "extData" points to the found data.
\r
967 static boolean lookupExtendedDataPriMem(Dem_EventIdType eventId, ExtDataRecType **extData)
\r
969 boolean eventIdFound = FALSE;
\r
972 // Lookup corresponding extended data
\r
973 for (i = 0; (priMemExtDataBuffer[i].eventId != eventId) && (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM); i++);
\r
975 if (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) {
\r
976 // Yes, return pointer
\r
977 *extData = &priMemExtDataBuffer[i];
\r
978 eventIdFound = TRUE;
\r
981 return eventIdFound;
\r
985 static void storeFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
991 static void deleteFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam)
\r
998 * Procedure: storeFreezeFrameDataEvtMem
\r
999 * Description: Store the freeze frame data in event memory according to
\r
1000 * "eventParam" destination option
\r
1002 static void storeFreezeFrameDataEvtMem(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
1006 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != NULL); i++) {
\r
1007 switch (eventParam->EventClass->EventDestination[i])
\r
1009 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1010 storeFreezeFrameDataPriMem(eventParam, freezeFrame);
\r
1013 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1014 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1015 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1016 // Not yet supported
\r
1017 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1018 Det_ReportError(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1029 * Procedure: handlePreInitEvent
\r
1030 * Description: Handle the updating of event status and storing of
\r
1031 * event related data in preInit buffers.
\r
1033 static void handlePreInitEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1035 const Dem_EventParameterType *eventParam;
\r
1036 EventStatusRecType eventStatusLocal;
\r
1037 FreezeFrameRecType freezeFrameLocal;
\r
1038 ExtDataRecType extendedDataLocal;
\r
1040 // Find configuration for this event
\r
1041 lookupEventIdParameter(eventId, &eventParam);
\r
1042 if (eventParam != NULL) {
\r
1043 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1044 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1045 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
1046 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1049 updateEventStatusRec(eventParam, eventStatus, FALSE, &eventStatusLocal);
\r
1052 if (eventStatusLocal.errorStatusChanged) {
\r
1054 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1055 // Collect freeze frame data
\r
1056 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1057 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1058 storeFreezeFrameDataPreInit(eventParam, &freezeFrameLocal);
\r
1061 // Collect extended data
\r
1062 getExtendedData(eventParam, &extendedDataLocal);
\r
1063 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1064 storeExtendedDataPreInit(eventParam, &extendedDataLocal);
\r
1070 // Operation cycle not started
\r
1071 // TODO: Report error?
\r
1075 // Operation cycle not set
\r
1076 // TODO: Report error?
\r
1080 // Event ID not configured
\r
1081 // TODO: Report error?
\r
1087 * Procedure: handleEvent
\r
1088 * Description: Handle the updating of event status and storing of
\r
1089 * event related data in event memory.
\r
1091 static Std_ReturnType handleEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1093 Std_ReturnType returnCode = E_OK;
\r
1094 const Dem_EventParameterType *eventParam;
\r
1095 EventStatusRecType eventStatusLocal;
\r
1096 FreezeFrameRecType freezeFrameLocal;
\r
1097 ExtDataRecType extendedDataLocal;
\r
1099 // Find configuration for this event
\r
1100 lookupEventIdParameter(eventId, &eventParam);
\r
1101 if (eventParam != NULL) {
\r
1102 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1103 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1104 if (!(disableDtcStorage.storageDisabled && checkDtcGroup(disableDtcStorage.dtcGroup, eventParam) && checkDtcKind(disableDtcStorage.dtcKind, eventParam))) {
\r
1105 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1106 if (eventStatusLocal.errorStatusChanged) {
\r
1107 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1108 storeEventEvtMem(eventParam, &eventStatusLocal);
\r
1109 // Collect freeze frame data
\r
1110 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1111 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1112 storeFreezeFrameDataEvtMem(eventParam, &freezeFrameLocal);
\r
1115 // Collect extended data
\r
1116 getExtendedData(eventParam, &extendedDataLocal);
\r
1117 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL)
\r
1119 storeExtendedDataEvtMem(eventParam, &extendedDataLocal);
\r
1126 // Operation cycle not started
\r
1127 returnCode = E_NOT_OK;
\r
1131 // Operation cycle not set
\r
1132 returnCode = E_NOT_OK;
\r
1136 // Event ID not configured
\r
1137 returnCode = E_NOT_OK;
\r
1140 return returnCode;
\r
1145 * Procedure: resetEventStatus
\r
1146 * Description: Resets the events status of eventId.
\r
1148 static void resetEventStatus(Dem_EventIdType eventId)
\r
1150 imask_t state = McuE_EnterCriticalSection();
\r
1151 EventStatusRecType *eventStatusRecPtr;
\r
1153 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
1154 if (eventStatusRecPtr != NULL) {
\r
1155 eventStatusRecPtr->eventStatusExtended &= ~DEM_TEST_FAILED;
\r
1158 McuE_ExitCriticalSection(state);
\r
1163 * Procedure: getEventStatus
\r
1164 * Description: Returns the extended event status bitmask of eventId in "eventStatusExtended".
\r
1166 static void getEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended)
\r
1168 EventStatusRecType eventStatusLocal;
\r
1170 // Get recorded status
\r
1171 getEventStatusRec(eventId, &eventStatusLocal);
\r
1172 if (eventStatusLocal.eventId == eventId) {
\r
1173 *eventStatusExtended = eventStatusLocal.eventStatusExtended;
\r
1176 // Event Id not found, no report received.
\r
1177 *eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1183 * Procedure: getEventFailed
\r
1184 * Description: Returns the TRUE or FALSE of "eventId" in "eventFailed" depending on current status.
\r
1186 static void getEventFailed(Dem_EventIdType eventId, boolean *eventFailed)
\r
1188 EventStatusRecType eventStatusLocal;
\r
1190 // Get recorded status
\r
1191 getEventStatusRec(eventId, &eventStatusLocal);
\r
1192 if (eventStatusLocal.eventId == eventId) {
\r
1193 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1194 *eventFailed = TRUE;
\r
1197 *eventFailed = FALSE;
\r
1201 // Event Id not found, assume ok.
\r
1202 *eventFailed = FALSE;
\r
1208 * Procedure: getEventTested
\r
1209 * Description: Returns the TRUE or FALSE of "eventId" in "eventTested" depending on
\r
1210 * current status the "test not completed this operation cycle" bit.
\r
1212 static void getEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1214 EventStatusRecType eventStatusLocal;
\r
1216 // Get recorded status
\r
1217 getEventStatusRec(eventId, &eventStatusLocal);
\r
1218 if (eventStatusLocal.eventId == eventId) {
\r
1219 if ( !(eventStatusLocal.eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE)) {
\r
1220 *eventTested = TRUE;
\r
1223 *eventTested = FALSE;
\r
1227 // Event Id not found, not tested.
\r
1228 *eventTested = FALSE;
\r
1234 * Procedure: getFaultDetectionCounter
\r
1235 * Description: Returns pre debounce counter of "eventId" in "counter" and return value E_OK if
\r
1236 * the counter was available else E_NOT_OK.
\r
1238 static Std_ReturnType getFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1240 Std_ReturnType returnCode = E_NOT_OK;
\r
1241 const Dem_EventParameterType *eventParam;
\r
1243 lookupEventIdParameter(eventId, &eventParam);
\r
1244 if (eventParam != NULL) {
\r
1245 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
1246 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName)
\r
1248 case DEM_NO_PRE_DEBOUNCE:
\r
1249 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal != NULL) {
\r
1250 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc != NULL) {
\r
1251 returnCode = eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc(counter);
\r
1256 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
1258 EventStatusRecType *eventStatusRec;
\r
1260 lookupEventStatusRec(eventId, &eventStatusRec);
\r
1261 if (eventStatusRec != NULL) {
\r
1262 *counter = eventStatusRec->faultDetectionCounter;
\r
1266 returnCode = E_OK;
\r
1270 case DEM_PRE_DEBOUNCE_FREQUENCY_BASED:
\r
1271 case DEM_PRE_DEBOUNCE_TIME_BASED:
\r
1272 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1273 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1278 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1279 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_PARAM_DATA);
\r
1286 return returnCode;
\r
1291 * Procedure: setOperationCycleState
\r
1292 * Description: Change the operation state of "operationCycleId" to "cycleState" and updates stored
\r
1293 * event connected to this cycle id.
\r
1294 * Returns E_OK if operation was successful else E_NOT_OK.
\r
1296 static Std_ReturnType setOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState)
\r
1299 Std_ReturnType returnCode = E_OK;
\r
1301 if (operationCycleId < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1302 switch (cycleState)
\r
1304 case DEM_CYCLE_STATE_START:
\r
1305 operationCycleStateList[operationCycleId] = cycleState;
\r
1306 // Lookup event ID
\r
1307 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1308 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1309 eventStatusBuffer[i].eventStatusExtended &= ~DEM_TEST_FAILED_THIS_OPERATION_CYCLE;
\r
1310 eventStatusBuffer[i].eventStatusExtended |= DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
1315 case DEM_CYCLE_STATE_END:
\r
1316 operationCycleStateList[operationCycleId] = cycleState;
\r
1317 // Lookup event ID
\r
1318 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1319 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1320 if (!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_FAILED_THIS_OPERATION_CYCLE) && !(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE)) {
\r
1321 eventStatusBuffer[i].eventStatusExtended &= ~DEM_PENDING_DTC; // Clear pendingDTC bit
\r
1327 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1328 Det_ReportError(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
1330 returnCode = E_NOT_OK;
\r
1335 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1336 Det_ReportError(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
1338 returnCode = E_NOT_OK;
\r
1341 return returnCode;
\r
1345 //==============================================================================//
\r
1347 // E X T E R N A L F U N C T I O N S //
\r
1349 //==============================================================================//
\r
1351 /*********************************************
\r
1352 * Interface for upper layer modules (8.3.1) *
\r
1353 *********************************************/
\r
1356 * Procedure: Dem_GetVersionInfo
\r
1359 // Defined in Dem.h
\r
1362 /***********************************************
\r
1363 * Interface ECU State Manager <-> DEM (8.3.2) *
\r
1364 ***********************************************/
\r
1367 * Procedure: Dem_PreInit
\r
1370 void Dem_PreInit(void)
\r
1374 if (DEM_Config.ConfigSet == NULL) {
\r
1375 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1376 Det_ReportError(MODULE_ID_DEM, 0, DEM_PREINIT_ID, DEM_E_CONFIG_PTR_INVALID);
\r
1380 configSet = DEM_Config.ConfigSet;
\r
1383 // Initializion of operation cycle states.
\r
1384 for (i = 0; i < DEM_OPERATION_CYCLE_ID_ENDMARK; i++) {
\r
1385 operationCycleStateList[i] = DEM_CYCLE_STATE_END;
\r
1388 // Initialize the event status buffer
\r
1389 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1390 eventStatusBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1391 eventStatusBuffer[i].eventParamRef = NULL;
\r
1392 eventStatusBuffer[i].faultDetectionCounter = 0;
\r
1393 eventStatusBuffer[i].occurrence = 0;
\r
1394 eventStatusBuffer[i].eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1395 eventStatusBuffer[i].errorStatusChanged = FALSE;
\r
1398 // Initialize the pre init buffers
\r
1399 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1400 preInitFreezeFrameBuffer[i].checksum = 0;
\r
1401 preInitFreezeFrameBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1402 preInitFreezeFrameBuffer[i].occurrence = 0;
\r
1403 preInitFreezeFrameBuffer[i].dataSize = 0;
\r
1404 for (j = 0; j < DEM_MAX_SIZE_FF_DATA;j++)
\r
1405 preInitFreezeFrameBuffer[i].data[j] = 0;
\r
1408 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1409 preInitExtDataBuffer[i].checksum = 0;
\r
1410 preInitExtDataBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1411 preInitExtDataBuffer[i].dataSize = 0;
\r
1412 for (j = 0; j < DEM_MAX_SIZE_EXT_DATA;j++)
\r
1413 preInitExtDataBuffer[i].data[j] = 0;
\r
1416 disableDtcStorage.storageDisabled = FALSE;
\r
1418 setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_START);
\r
1420 demState = DEM_PREINITIALIZED;
\r
1425 * Procedure: Dem_Init
\r
1428 void Dem_Init(void)
\r
1431 ChecksumType cSum;
\r
1432 const Dem_EventParameterType *eventParam;
\r
1435 * Validate and read out saved error log from non volatile memory
\r
1438 // Validate event records stored in primary memory
\r
1439 for (i = 0; i < DEM_MAX_NUMBER_EVENT_PRI_MEM; i++) {
\r
1440 cSum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
1441 if ((cSum != priMemEventBuffer[i].checksum) || priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL) {
\r
1442 // Unlegal record, clear the record
\r
1443 memset(&priMemEventBuffer[i], 0, sizeof(EventRecType));
\r
1446 // Valid, update current status
\r
1447 mergeEventStatusRec(&priMemEventBuffer[i]);
\r
1449 // Update occurrence counter on pre init stored freeze frames
\r
1450 updateFreezeFrameOccurrencePreInit(&priMemEventBuffer[i]);
\r
1454 // Validate extended data records stored in primary memory
\r
1455 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM; i++) {
\r
1456 cSum = calcChecksum(&priMemExtDataBuffer[i], sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
1457 if ((cSum != priMemExtDataBuffer[i].checksum) || priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL) {
\r
1458 // Unlegal record, clear the record
\r
1459 memset(&priMemExtDataBuffer[i], 0, sizeof(ExtDataRecType));
\r
1463 // Validate freeze frame records stored in primary memory
\r
1464 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++) {
\r
1465 cSum = calcChecksum(&priMemFreezeFrameBuffer[i], sizeof(FreezeFrameRecType)-sizeof(ChecksumType));
\r
1466 if ((cSum != priMemFreezeFrameBuffer[i].checksum) || (priMemFreezeFrameBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1467 // Unlegal record, clear the record
\r
1468 memset(&priMemFreezeFrameBuffer[i], 0, sizeof(FreezeFrameRecType));
\r
1473 * Handle errors stored in temporary buffer (if any)
\r
1476 // Transfer updated event data to event memory
\r
1477 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1478 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1479 // Update the event memory
\r
1480 lookupEventIdParameter(eventStatusBuffer[i].eventId, &eventParam);
\r
1481 storeEventEvtMem(eventParam, &eventStatusBuffer[i]);
\r
1485 // Transfer extended data to event memory if necessary
\r
1486 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1487 if (preInitExtDataBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1488 lookupEventIdParameter(preInitExtDataBuffer[i].eventId, &eventParam);
\r
1489 storeExtendedDataEvtMem(eventParam, &preInitExtDataBuffer[i]);
\r
1493 // Transfer freeze frames to event memory
\r
1494 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1495 if (preInitFreezeFrameBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1496 lookupEventIdParameter(preInitFreezeFrameBuffer[i].eventId, &eventParam);
\r
1497 storeFreezeFrameDataEvtMem(eventParam, &preInitFreezeFrameBuffer[i]);
\r
1501 // Init the dtc filter
\r
1502 dtcFilter.dtcStatusMask = DEM_DTC_STATUS_MASK_ALL; // All allowed
\r
1503 dtcFilter.dtcKind = DEM_DTC_KIND_ALL_DTCS; // All kinds of DTCs
\r
1504 dtcFilter.dtcOrigin = DEM_DTC_ORIGIN_PRIMARY_MEMORY; // Primary memory
\r
1505 dtcFilter.filterWithSeverity = DEM_FILTER_WITH_SEVERITY_NO; // No Severity filtering
\r
1506 dtcFilter.dtcSeverityMask = DEM_SEVERITY_NO_SEVERITY; // Not used when filterWithSeverity is FALSE
\r
1507 dtcFilter.filterForFaultDetectionCounter = DEM_FILTER_FOR_FDC_NO; // No fault detection counter filtering
\r
1509 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1511 disableDtcStorage.storageDisabled = FALSE;
\r
1513 demState = DEM_INITIALIZED;
\r
1518 * Procedure: Dem_shutdown
\r
1521 void Dem_Shutdown(void)
\r
1523 setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_END);
\r
1525 demState = DEM_UNINITIALIZED;
\r
1530 * Interface for basic software scheduler
\r
1532 void Dem_MainFunction(void)
\r
1538 /***************************************************
\r
1539 * Interface SW-Components via RTE <-> DEM (8.3.3) *
\r
1540 ***************************************************/
\r
1543 * Procedure: Dem_SetEventStatus
\r
1546 Std_ReturnType Dem_SetEventStatus(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1548 Std_ReturnType returnCode = E_OK;
\r
1550 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1552 returnCode = handleEvent(eventId, eventStatus);
\r
1556 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1557 Det_ReportError(MODULE_ID_DEM, 0, DEM_SETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1559 returnCode = E_NOT_OK;
\r
1562 return returnCode;
\r
1567 * Procedure: Dem_ResetEventStatus
\r
1570 Std_ReturnType Dem_ResetEventStatus(Dem_EventIdType eventId)
\r
1572 Std_ReturnType returnCode = E_OK;
\r
1574 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1576 resetEventStatus(eventId);
\r
1580 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1581 Det_ReportError(MODULE_ID_DEM, 0, DEM_RESETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1583 returnCode = E_NOT_OK;
\r
1586 return returnCode;
\r
1591 * Procedure: Dem_GetEventStatus
\r
1594 Std_ReturnType Dem_GetEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended)
\r
1596 Std_ReturnType returnCode = E_OK;
\r
1598 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1600 getEventStatus(eventId, eventStatusExtended);
\r
1604 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1605 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1607 returnCode = E_NOT_OK;
\r
1610 return returnCode;
\r
1615 * Procedure: Dem_GetEventFailed
\r
1618 Std_ReturnType Dem_GetEventFailed(Dem_EventIdType eventId, boolean *eventFailed)
\r
1620 Std_ReturnType returnCode = E_OK;
\r
1622 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1624 getEventFailed(eventId, eventFailed);
\r
1628 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1629 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETEVENTFAILED_ID, DEM_E_UNINIT);
\r
1631 returnCode = E_NOT_OK;
\r
1634 return returnCode;
\r
1639 * Procedure: Dem_GetEventTested
\r
1642 Std_ReturnType Dem_GetEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1644 Std_ReturnType returnCode = E_OK;
\r
1646 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1648 getEventTested(eventId, eventTested);
\r
1652 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1653 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETEVENTTESTED_ID, DEM_E_UNINIT);
\r
1655 returnCode = E_NOT_OK;
\r
1658 return returnCode;
\r
1663 * Procedure: Dem_GetFaultDetectionCounter
\r
1666 Std_ReturnType Dem_GetFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\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 returnCode = getFaultDetectionCounter(eventId, counter);
\r
1676 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1677 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_UNINIT);
\r
1679 returnCode = E_NOT_OK;
\r
1682 return returnCode;
\r
1687 * Procedure: Dem_SetOperationCycleState
\r
1690 Std_ReturnType Dem_SetOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState)
\r
1692 Std_ReturnType returnCode = E_OK;
\r
1694 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1696 returnCode = setOperationCycleState(operationCycleId, cycleState);
\r
1701 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1702 Det_ReportError(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_UNINIT);
\r
1704 returnCode = E_NOT_OK;
\r
1707 return returnCode;
\r
1712 * Procedure: Dem_GetDTCOfEvent
\r
1715 Std_ReturnType Dem_GetDTCOfEvent(Dem_EventIdType eventId, Dem_DTCKindType dtcKind, uint32* dtcOfEvent)
\r
1717 Std_ReturnType returnCode = E_NO_DTC_AVAILABLE;
\r
1718 const Dem_EventParameterType *eventParam;
\r
1720 lookupEventIdParameter(eventId, &eventParam);
\r
1722 if (eventParam != NULL) {
\r
1723 if (checkDtcKind(dtcKind, eventParam)) {
\r
1724 if (eventParam->DTCClassRef != NULL) {
\r
1725 *dtcOfEvent = eventParam->DTCClassRef->DTC;
\r
1726 returnCode = E_OK;
\r
1731 // Event Id not found
\r
1732 returnCode = E_NOT_OK;
\r
1735 return returnCode;
\r
1739 /********************************************
\r
1740 * Interface BSW-Components <-> DEM (8.3.4) *
\r
1741 ********************************************/
\r
1744 * Procedure: Dem_ReportErrorStatus
\r
1747 void Dem_ReportErrorStatus( Dem_EventIdType eventId, Dem_EventStatusType eventStatus )
\r
1750 switch (demState) {
\r
1751 case DEM_PREINITIALIZED:
\r
1752 // Update status and check if is to be stored
\r
1753 if ((eventStatus == DEM_EVENT_STATUS_PASSED) || (eventStatus == DEM_EVENT_STATUS_FAILED)) {
\r
1754 handlePreInitEvent(eventId, eventStatus);
\r
1758 case DEM_INITIALIZED:
\r
1759 (void)handleEvent(eventId, eventStatus);
\r
1762 case DEM_UNINITIALIZED:
\r
1764 // Uninitialized can not do anything
\r
1765 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1766 Det_ReportError(MODULE_ID_DEM, 0, DEM_REPORTERRORSTATUS_ID, DEM_E_UNINIT);
\r
1770 } // switch (demState)
\r
1773 /*********************************
\r
1774 * Interface DCM <-> DEM (8.3.5) *
\r
1775 *********************************/
\r
1777 * Procedure: Dem_GetDTCStatusAvailabilityMask
\r
1780 Std_ReturnType Dem_GetDTCStatusAvailabilityMask(uint8 *dtcStatusMask)
\r
1782 *dtcStatusMask = DEM_DTC_STATUS_AVAILABILITY_MASK; // User configuration mask
\r
1783 *dtcStatusMask &= DEM_TEST_FAILED // Mask with supported bits
\r
1784 | DEM_TEST_FAILED_THIS_OPERATION_CYCLE
\r
1786 // | DEM_CONFIRMED_DTC TODO: Add support for this bit
\r
1787 | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR
\r
1788 | DEM_TEST_FAILED_SINCE_LAST_CLEAR
\r
1789 | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE
\r
1790 // | DEM_WARNING_INDICATOR_REQUESTED TODO: Add support for this bit
\r
1798 * Procedure: Dem_SetDTCFilter
\r
1801 Dem_ReturnSetDTCFilterType Dem_SetDTCFilter(uint8 dtcStatusMask,
\r
1802 Dem_DTCKindType dtcKind,
\r
1803 Dem_DTCOriginType dtcOrigin,
\r
1804 Dem_FilterWithSeverityType filterWithSeverity,
\r
1805 Dem_DTCSeverityType dtcSeverityMask,
\r
1806 Dem_FilterForFDCType filterForFaultDetectionCounter) {
\r
1808 Dem_ReturnSetDTCFilterType returnCode = DEM_WRONG_FILTER;
\r
1810 // Check dtcKind parameter
\r
1811 if ((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS)) {
\r
1813 // Check dtcOrigin parameter
\r
1814 if ((dtcOrigin == DEM_DTC_ORIGIN_SECONDARY_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_PRIMARY_MEMORY)
\r
1815 || (dtcOrigin == DEM_DTC_ORIGIN_PERMANENT_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_MIRROR_MEMORY)) {
\r
1817 // Check filterWithSeverity and dtcSeverityMask parameter
\r
1818 if ((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
1819 || ((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES) && !(dtcSeverityMask & ~(DEM_SEVERITY_MAINTENANCE_ONLY | DEM_SEVERITY_CHECK_AT_NEXT_FALT | DEM_SEVERITY_CHECK_IMMEDIATELY)))){
\r
1821 // Check filterForFaultDetectionCounter parameter
\r
1822 if ((filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_YES) || (filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO)) {
\r
1823 // Yes all parameters correct, set the new filters.
\r
1824 dtcFilter.dtcStatusMask = dtcStatusMask;
\r
1825 dtcFilter.dtcKind = dtcKind;
\r
1826 dtcFilter.dtcOrigin = dtcOrigin;
\r
1827 dtcFilter.filterWithSeverity = filterWithSeverity;
\r
1828 dtcFilter.dtcSeverityMask = dtcSeverityMask;
\r
1829 dtcFilter.filterForFaultDetectionCounter = filterForFaultDetectionCounter;
\r
1830 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1831 returnCode = DEM_FILTER_ACCEPTED;
\r
1837 return returnCode;
\r
1842 * Procedure: Dem_GetStatusOfDTC
\r
1845 Dem_ReturnGetStatusOfDTCType Dem_GetStatusOfDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, Dem_EventStatusExtendedType* status) {
\r
1846 Dem_ReturnGetStatusOfDTCType returnCode = DEM_STATUS_FAILED;
\r
1847 EventStatusRecType *eventRec;
\r
1849 if (lookupDtcEvent(dtc, &eventRec)) {
\r
1850 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
1851 if (checkDtcOrigin(dtcOrigin,eventRec->eventParamRef)) {
\r
1852 *status = eventRec->eventStatusExtended;
\r
1853 returnCode = DEM_STATUS_OK;
\r
1856 returnCode = DEM_STATUS_WRONG_DTCORIGIN;
\r
1860 returnCode = DEM_STATUS_WRONG_DTCKIND;
\r
1864 returnCode = DEM_STATUS_WRONG_DTC;
\r
1867 return returnCode;
\r
1872 * Procedure: Dem_GetNumberOfFilteredDtc
\r
1875 Dem_ReturnGetNumberOfFilteredDTCType Dem_GetNumberOfFilteredDtc(uint16 *numberOfFilteredDTC) {
\r
1877 uint16 numberOfFaults = 0;
\r
1879 //Dem_DisableEventStatusUpdate();
\r
1881 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1882 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1883 if (matchEventWithDtcFilter(&eventStatusBuffer[i])) {
\r
1884 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
1891 //Dem_EnableEventStatusUpdate();
\r
1893 *numberOfFilteredDTC = numberOfFaults;
\r
1895 return DEM_NUMBER_OK;
\r
1900 * Procedure: Dem_GetNextFilteredDTC
\r
1903 Dem_ReturnGetNextFilteredDTCType Dem_GetNextFilteredDTC(uint32 *dtc, Dem_EventStatusExtendedType *dtcStatus)
\r
1905 Dem_ReturnGetNextFilteredDTCType returnCode = DEM_FILTERED_OK;
\r
1906 boolean dtcFound = FALSE;
\r
1908 // TODO: This job should be done in an more advanced way according to Dem288
\r
1909 while (!dtcFound && (dtcFilter.faultIndex != 0)) {
\r
1910 dtcFilter.faultIndex--;
\r
1911 if (eventStatusBuffer[dtcFilter.faultIndex].eventId != DEM_EVENT_ID_NULL) {
\r
1912 if (matchEventWithDtcFilter(&eventStatusBuffer[dtcFilter.faultIndex])) {
\r
1913 if (eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef != NULL) {
\r
1914 *dtc = eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef->DTC;
\r
1915 *dtcStatus = eventStatusBuffer[dtcFilter.faultIndex].eventStatusExtended;
\r
1923 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1924 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
1927 return returnCode;
\r
1932 * Procedure: Dem_GetTranslationType
\r
1935 Dem_ReturnTypeOfDtcSupportedType Dem_GetTranslationType(void)
\r
1937 return DEM_TYPE_OF_DTC_SUPPORTED;
\r
1942 * Procedure: Dem_ClearDTC
\r
1945 Dem_ReturnClearDTCType Dem_ClearDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin)
\r
1947 Dem_ReturnClearDTCType returnCode = DEM_CLEAR_OK;
\r
1948 Dem_EventIdType eventId;
\r
1949 const Dem_EventParameterType *eventParam;
\r
1952 // Loop through the event buffer
\r
1953 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1954 eventId = eventStatusBuffer[i].eventId;
\r
1955 if (eventId != DEM_EVENT_ID_NULL) {
\r
1956 eventParam = eventStatusBuffer[i].eventParamRef;
\r
1957 if (eventParam != NULL) {
\r
1958 if (DEM_CLEAR_ALL_EVENTS | (eventParam->DTCClassRef != NULL)) {
\r
1959 if (checkDtcKind(dtcKind, eventParam)) {
\r
1960 if (checkDtcGroup(dtc, eventParam)) {
\r
1961 for (j = 0; (j < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[j] != dtcOrigin); j++);
\r
1962 if (j < DEM_MAX_NR_OF_EVENT_DESTINATION) {
\r
1963 // Yes! All conditions met.
\r
1964 switch (dtcOrigin)
\r
1966 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1967 deleteEventPriMem(eventParam);
\r
1968 deleteFreezeFrameDataPriMem(eventParam);
\r
1969 deleteExtendedDataPriMem(eventParam);
\r
1970 deleteEventStatusRec(eventParam); // TODO: Shall this be done or just resetting the status?
\r
1973 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1974 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1975 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1976 // Not yet supported
\r
1977 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
1978 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1979 Det_ReportError(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1983 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
1992 // Fatal error, no event parameters found for the stored event!
\r
1993 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1994 Det_ReportError(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNEXPECTED_EXECUTION);
\r
2000 return returnCode;
\r
2005 * Procedure: Dem_DisableDTCStorage
\r
2008 Dem_ReturnControlDTCStorageType Dem_DisableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind)
\r
2010 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2012 // Check dtcGroup parameter
\r
2013 if (dtcGroup == DEM_DTC_GROUP_ALL_DTCS) {
\r
2014 // Check dtcKind parameter
\r
2015 if ((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS)) {
\r
2016 disableDtcStorage.dtcGroup = dtcGroup;
\r
2017 disableDtcStorage.dtcKind = dtcKind;
\r
2018 disableDtcStorage.storageDisabled = TRUE;
\r
2020 returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2024 returnCode = DEM_CONTROL_DTC_WRONG_DTCGROUP;
\r
2027 return returnCode;
\r
2032 * Procedure: Dem_EnableDTCStorage
\r
2035 Dem_ReturnControlDTCStorageType Dem_EnableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind)
\r
2037 // TODO: Behavior is not defined if group or kind do not match active settings, therefore the filter is just switched off.
\r
2038 disableDtcStorage.storageDisabled = FALSE;
\r
2040 return DEM_CONTROL_DTC_STORAGE_OK;
\r
2044 * Procedure: Dem_GetExtendedDataRecordByDTC
\r
2047 Dem_ReturnGetExtendedDataRecordByDTCType Dem_GetExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint8 *destBuffer, uint8 *bufSize)
\r
2049 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_RECORD_WRONG_DTC;
\r
2050 EventStatusRecType *eventRec;
\r
2051 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2052 ExtDataRecType *extData;
\r
2053 uint8 posInExtData = 0;
\r
2055 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2056 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2057 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2058 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2059 if (*bufSize >= extendedDataRecordClass->DataSize) {
\r
2060 switch (dtcOrigin)
\r
2062 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2063 if (lookupExtendedDataPriMem(eventRec->eventId, &extData)) {
\r
2064 // Yes all conditions met, copy the extended data record to destination buffer.
\r
2065 memcpy(destBuffer, &extData->data[posInExtData], extendedDataRecordClass->DataSize);
\r
2066 *bufSize = extendedDataRecordClass->DataSize;
\r
2067 returnCode = DEM_RECORD_OK;
\r
2070 // The record number is legal but no record was found for the DTC
\r
2072 returnCode = DEM_RECORD_OK;
\r
2076 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2077 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2078 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2079 // Not yet supported
\r
2080 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2081 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
2082 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2086 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2091 returnCode = DEM_RECORD_BUFFERSIZE;
\r
2095 returnCode = DEM_RECORD_NUMBER;
\r
2099 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2103 returnCode = DEM_RECORD_DTCKIND;
\r
2107 return returnCode;
\r
2112 * Procedure: Dem_GetSizeOfExtendedDataRecordByDTC
\r
2115 Dem_ReturnGetSizeOfExtendedDataRecordByDTCType Dem_GetSizeOfExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint16 *sizeOfExtendedDataRecord)
\r
2117 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2118 EventStatusRecType *eventRec;
\r
2119 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2120 uint8 posInExtData;
\r
2122 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2123 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2124 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2125 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2126 *sizeOfExtendedDataRecord = extendedDataRecordClass->DataSize;
\r
2127 returnCode = DEM_GET_SIZEOFEDRBYDTC_OK;
\r
2130 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_RNUM;
\r
2134 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCOR;
\r
2138 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCKI;
\r
2142 return returnCode;
\r
2145 /***********************************
\r
2146 * OBD-specific Interfaces (8.3.6) *
\r
2147 ***********************************/
\r