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
24 /** @req DEM151.partially */
\r
26 /** @req DEM013.14229-1 */
\r
29 /** @req DEM113 */ /** @req DEM174 */
\r
39 //#include "SchM_Dem.h"
\r
41 #include "McuExtensions.h"
\r
46 #define DEBOUNCE_FDC_TEST_FAILED 127
\r
47 #define DEBOUNCE_FDC_TEST_PASSED -128
\r
53 typedef uint16 ChecksumType;
\r
57 Dem_EventStatusExtendedType dtcStatusMask;
\r
58 Dem_DTCKindType dtcKind;
\r
59 Dem_DTCOriginType dtcOrigin;
\r
60 Dem_FilterWithSeverityType filterWithSeverity;
\r
61 Dem_DTCSeverityType dtcSeverityMask;
\r
62 Dem_FilterForFDCType filterForFaultDetectionCounter;
\r
66 // DisableDtcStorageType
\r
68 boolean storageDisabled;
\r
69 Dem_DTCGroupType dtcGroup;
\r
70 Dem_DTCKindType dtcKind;
\r
71 } DisableDtcStorageType;
\r
73 // For keeping track of the events status
\r
75 Dem_EventIdType eventId;
\r
76 const Dem_EventParameterType *eventParamRef;
\r
77 sint8 faultDetectionCounter;
\r
78 uint16 occurrence; /** @req DEM011 */
\r
79 Dem_EventStatusExtendedType eventStatusExtended; /** @req DEM006 */
\r
80 boolean errorStatusChanged;
\r
81 } EventStatusRecType;
\r
84 // Types for storing different event data on event memory
\r
86 Dem_EventIdType eventId;
\r
88 ChecksumType checksum;
\r
92 Dem_EventIdType eventId;
\r
95 sint8 data[DEM_MAX_SIZE_FF_DATA];
\r
96 ChecksumType checksum;
\r
97 } FreezeFrameRecType;
\r
100 Dem_EventIdType eventId;
\r
102 uint8 data[DEM_MAX_SIZE_EXT_DATA];
\r
103 ChecksumType checksum;
\r
110 DEM_UNINITIALIZED = 0,
\r
111 DEM_PREINITIALIZED,
\r
113 } Dem_StateType; /** @req DEM169 */
\r
116 static Dem_StateType demState = DEM_UNINITIALIZED;
\r
118 // Help pointer to configuration set
\r
119 static const Dem_ConfigSetType *configSet;
\r
122 * Allocation of DTC filter parameters
\r
124 static DtcFilterType dtcFilter;
\r
127 * Allocation of Disable/Enable DTC storage parameters
\r
129 static DisableDtcStorageType disableDtcStorage;
\r
132 * Allocation of operation cycle state list
\r
134 static Dem_OperationCycleStateType operationCycleStateList[DEM_OPERATION_CYCLE_ID_ENDMARK];
\r
137 * Allocation of local event status buffer
\r
139 static EventStatusRecType eventStatusBuffer[DEM_MAX_NUMBER_EVENT];
\r
142 * Allocation of pre-init event memory (used between pre-init and init)
\r
145 static FreezeFrameRecType preInitFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRE_INIT];
\r
146 static ExtDataRecType preInitExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRE_INIT];
\r
149 * Allocation of primary event memory ramlog (after init) in uninitialized memory
\r
152 static EventRecType priMemEventBuffer[DEM_MAX_NUMBER_EVENT_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
153 static FreezeFrameRecType priMemFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
154 static ExtDataRecType priMemExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
158 * Procedure: zeroPriMemBuffers
\r
159 * Description: Fill the primary buffers with zeroes
\r
161 void demZeroPriMemBuffers(void)
\r
163 memset(priMemEventBuffer, 0, sizeof(priMemEventBuffer));
\r
164 memset(priMemFreezeFrameBuffer, 0, sizeof(priMemFreezeFrameBuffer));
\r
165 memset(priMemExtDataBuffer, 0, sizeof(priMemExtDataBuffer));
\r
170 * Procedure: calcChecksum
\r
171 * Description: Calculate checksum over *data to *(data+nrOfBytes-1) area
\r
173 static ChecksumType calcChecksum(void *data, uint16 nrOfBytes)
\r
176 uint8 *ptr = (uint8*)data;
\r
177 ChecksumType sum = 0;
\r
179 for (i = 0; i < nrOfBytes; i++)
\r
187 * Procedure: checkDtcKind
\r
188 * Description: Return TRUE if "dtcKind" match the events DTCKind or "dtcKind"
\r
189 * is "DEM_DTC_KIND_ALL_DTCS" otherwise FALSE.
\r
191 static boolean checkDtcKind(Dem_DTCKindType dtcKind, const Dem_EventParameterType *eventParam)
\r
193 boolean result = FALSE;
\r
195 if (dtcKind == DEM_DTC_KIND_ALL_DTCS) {
\r
199 if (eventParam->DTCClassRef != NULL) {
\r
200 if (eventParam->DTCClassRef->DTCKind == dtcKind) {
\r
210 * Procedure: checkDtcGroup
\r
211 * Description: Return TRUE if "dtc" match the events DTC or "dtc" is
\r
212 * "DEM_DTC_GROUP_ALL_DTCS" otherwise FALSE.
\r
214 static boolean checkDtcGroup(uint32 dtc, const Dem_EventParameterType *eventParam)
\r
216 boolean result = FALSE;
\r
218 if (dtc == DEM_DTC_GROUP_ALL_DTCS) {
\r
222 if (eventParam->DTCClassRef != NULL) {
\r
223 if (eventParam->DTCClassRef->DTC == dtc) {
\r
233 * Procedure: checkDtcOrigin
\r
234 * Description: Return TRUE if "dtcOrigin" match any of the events DTCOrigin otherwise FALSE.
\r
236 static boolean checkDtcOrigin(Dem_DTCOriginType dtcOrigin, const Dem_EventParameterType *eventParam)
\r
238 boolean result = FALSE;
\r
241 for (i = 0; (eventParam->EventClass->EventDestination[i] != dtcOrigin) && (i < DEM_MAX_NR_OF_EVENT_DESTINATION); i++);
\r
243 if (i < DEM_MAX_NR_OF_EVENT_DESTINATION) {
\r
252 * Procedure: checkDtcSeverityMask
\r
253 * Description: Return TRUE if "dtcSeverityMask" match any of the events DTC severity otherwise FALSE.
\r
255 static boolean checkDtcSeverityMask(Dem_DTCSeverityType dtcSeverityMask, const Dem_EventParameterType *eventParam)
\r
257 boolean result = TRUE;
\r
259 // TODO: This function is optional, may be implemented here.
\r
266 * Procedure: checkDtcFaultDetectionCounterMask
\r
267 * Description: TBD.
\r
269 static boolean checkDtcFaultDetectionCounter(const Dem_EventParameterType *eventParam)
\r
271 boolean result = TRUE;
\r
273 // TODO: Not implemented yet.
\r
280 * Procedure: lookupEventStatusRec
\r
281 * Description: Returns the pointer to event id parameters of "eventId" in "*eventStatusBuffer",
\r
282 * if not found NULL is returned.
\r
284 static void lookupEventStatusRec(Dem_EventIdType eventId, EventStatusRecType **const eventStatusRec)
\r
286 EventStatusRecType *eventStatusRecPtr = eventStatusBuffer;
\r
288 while ((eventStatusRecPtr->eventId != eventId) && (eventStatusRecPtr < &eventStatusBuffer[DEM_MAX_NUMBER_EVENT])) {
\r
289 eventStatusRecPtr++;
\r
292 if (eventStatusRecPtr < &eventStatusBuffer[DEM_MAX_NUMBER_EVENT]) {
\r
293 *eventStatusRec = eventStatusRecPtr;
\r
295 *eventStatusRec = NULL;
\r
301 * Procedure: lookupEventIdParameter
\r
302 * Description: Returns the pointer to event id parameters of "eventId" in "*eventIdParam",
\r
303 * if not found NULL is returned.
\r
305 static void lookupEventIdParameter(Dem_EventIdType eventId, const Dem_EventParameterType **const eventIdParam)
\r
307 const Dem_EventParameterType *EventIdParamPtr = configSet->EventParameter;
\r
309 // Lookup the correct event id parameters
\r
310 while ((EventIdParamPtr->EventID != eventId) && !EventIdParamPtr->Arc_EOL) {
\r
314 if (!EventIdParamPtr->Arc_EOL) {
\r
315 *eventIdParam = EventIdParamPtr;
\r
317 *eventIdParam = NULL;
\r
323 * Procedure: preDebounceNone
\r
324 * Description: Returns the result of the debouncing.
\r
326 static Dem_EventStatusType preDebounceNone(Dem_EventStatusType reportedStatus, EventStatusRecType* statusRecord) {
\r
327 Dem_EventStatusType returnCode;
\r
329 switch (reportedStatus) {
\r
330 case DEM_EVENT_STATUS_FAILED: /** @req DEM091.NoneFailed */
\r
331 case DEM_EVENT_STATUS_PASSED: /** @req DEM091.NonePassed */
\r
332 // Already debounced, do nothing.
\r
336 // TODO: What to do with PREFAIL and PREPASSED on no debouncing?
\r
337 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
338 Det_ReportError(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_NONE_ID, DEM_E_PARAM_DATA); /** @req DEM117 */
\r
343 returnCode = reportedStatus;
\r
349 * Procedure: preDebounceCounterBased
\r
350 * Description: Returns the result of the debouncing.
\r
352 static Dem_EventStatusType preDebounceCounterBased(Dem_EventStatusType reportedStatus, EventStatusRecType* statusRecord) {
\r
353 Dem_EventStatusType returnCode;
\r
354 const Dem_PreDebounceCounterBasedType* pdVars = statusRecord->eventParamRef->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceCounterBased;
\r
356 switch (reportedStatus) {
\r
357 case DEM_EVENT_STATUS_PREFAILED:
\r
358 if (statusRecord->faultDetectionCounter < DEBOUNCE_FDC_TEST_FAILED) {
\r
359 if (pdVars->JumpUp && (statusRecord->faultDetectionCounter < 0)) {
\r
360 statusRecord->faultDetectionCounter = 0;
\r
362 if (((sint16)statusRecord->faultDetectionCounter + pdVars->CountInStepSize) < DEBOUNCE_FDC_TEST_FAILED) {
\r
363 statusRecord->faultDetectionCounter += pdVars->CountInStepSize;
\r
365 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED;
\r
371 case DEM_EVENT_STATUS_PREPASSED:
\r
372 if (statusRecord->faultDetectionCounter > DEBOUNCE_FDC_TEST_PASSED) {
\r
373 if (pdVars->JumpDown && (statusRecord->faultDetectionCounter > 0)) {
\r
374 statusRecord->faultDetectionCounter = 0;
\r
376 if (((sint16)statusRecord->faultDetectionCounter - pdVars->CountOutStepSize) > DEBOUNCE_FDC_TEST_PASSED) {
\r
377 statusRecord->faultDetectionCounter -= pdVars->CountOutStepSize;
\r
379 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED;
\r
385 case DEM_EVENT_STATUS_FAILED:
\r
386 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED; /** @req DEM091.CounterFailed */
\r
389 case DEM_EVENT_STATUS_PASSED:
\r
390 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED; /** @req DEM091.CounterPassed */
\r
394 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
395 Det_ReportError(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_COUNTER_BASED_ID, DEM_E_PARAM_DATA); /** @req DEM117 */
\r
401 switch (statusRecord->faultDetectionCounter) {
\r
402 case DEBOUNCE_FDC_TEST_FAILED:
\r
403 returnCode = DEM_EVENT_STATUS_FAILED;
\r
406 case DEBOUNCE_FDC_TEST_PASSED:
\r
407 returnCode = DEM_EVENT_STATUS_PASSED;
\r
411 returnCode = reportedStatus;
\r
420 * Procedure: updateEventStatusRec
\r
421 * Description: Update the status of "eventId", if not exist and "createIfNotExist" is
\r
422 * true a new record is created
\r
424 static void updateEventStatusRec(const Dem_EventParameterType *eventParam, Dem_EventStatusType eventStatus, boolean createIfNotExist, EventStatusRecType *eventStatusRec)
\r
426 EventStatusRecType *eventStatusRecPtr;
\r
427 imask_t state = McuE_EnterCriticalSection();
\r
430 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
432 if ((eventStatusRecPtr == NULL) && (createIfNotExist)) {
\r
433 // Search for free position
\r
434 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
436 if (eventStatusRecPtr != NULL) {
\r
437 // Create new event record
\r
438 eventStatusRecPtr->eventId = eventParam->EventID;
\r
439 eventStatusRecPtr->eventParamRef = eventParam;
\r
440 eventStatusRecPtr->faultDetectionCounter = 0;
\r
441 eventStatusRecPtr->occurrence = 0;
\r
442 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
443 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
446 // Error: Event status buffer full
\r
447 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
448 Det_ReportError(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL); /** @req DEM117 */
\r
454 if (eventStatusRecPtr != NULL) {
\r
455 // Handle debouncing
\r
456 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
457 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName) { /** @req DEM004 */ /** @req DEM342 */
\r
458 case DEM_NO_PRE_DEBOUNCE:
\r
459 eventStatus = preDebounceNone(eventStatus, eventStatusRecPtr);
\r
462 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
463 eventStatus = preDebounceCounterBased(eventStatus, eventStatusRecPtr);
\r
467 // Don't know how to handle this.
\r
468 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
469 Det_ReportError(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
475 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
477 // Check test failed
\r
478 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
479 if (!(eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED)) {
\r
480 eventStatusRecPtr->occurrence++;
\r
481 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
483 /** @req DEM036 */ /** @req DEM379.PendingSet */
\r
484 eventStatusRecPtr->eventStatusExtended |= (DEM_TEST_FAILED | DEM_TEST_FAILED_THIS_OPERATION_CYCLE | DEM_TEST_FAILED_SINCE_LAST_CLEAR | DEM_PENDING_DTC);
\r
485 eventStatusRecPtr->eventStatusExtended &= ~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
488 // Check test passed
\r
489 if (eventStatus == DEM_EVENT_STATUS_PASSED) {
\r
490 if (eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED) {
\r
491 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
494 eventStatusRecPtr->eventStatusExtended &= ~DEM_TEST_FAILED;
\r
495 eventStatusRecPtr->eventStatusExtended &= ~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
499 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
502 // Copy an empty record to return data
\r
503 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
504 eventStatusRecPtr->faultDetectionCounter = 0;
\r
505 eventStatusRec->occurrence = 0;
\r
506 eventStatusRec->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
507 eventStatusRec->errorStatusChanged = FALSE;
\r
510 McuE_ExitCriticalSection(state);
\r
515 * Procedure: mergeEventStatusRec
\r
516 * Description: Update the occurrence counter of status, if not exist a new record is created
\r
518 static void mergeEventStatusRec(EventRecType *eventRec)
\r
520 EventStatusRecType *eventStatusRecPtr;
\r
521 imask_t state = McuE_EnterCriticalSection();
\r
524 lookupEventStatusRec(eventRec->eventId, &eventStatusRecPtr);
\r
526 if (eventStatusRecPtr != NULL) {
\r
527 // Update occurrence counter, rest of pre init state is kept.
\r
528 eventStatusRecPtr->occurrence += eventRec->occurrence;
\r
532 // Search for free position
\r
533 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
535 if (eventStatusRecPtr != NULL) {
\r
536 // Create new event, from stored event
\r
537 eventStatusRecPtr->eventId = eventRec->eventId;
\r
538 lookupEventIdParameter(eventRec->eventId, &eventStatusRecPtr->eventParamRef);
\r
539 eventStatusRecPtr->faultDetectionCounter = 0;
\r
540 eventStatusRecPtr->occurrence = eventRec->occurrence;
\r
541 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
542 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
545 // Error: Event status buffer full
\r
546 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
547 Det_ReportError(MODULE_ID_DEM, 0, DEM_MERGE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL); /** @req DEM117 */
\r
552 McuE_ExitCriticalSection(state);
\r
557 * Procedure: deleteEventStatusRec
\r
558 * Description: Delete the status record of "eventParam->eventId" from "eventStatusBuffer".
\r
560 static void deleteEventStatusRec(const Dem_EventParameterType *eventParam)
\r
562 EventStatusRecType *eventStatusRecPtr;
\r
563 imask_t state = McuE_EnterCriticalSection();
\r
566 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
568 if (eventStatusRecPtr != NULL) {
\r
569 // Delete event record
\r
570 memset(eventStatusRecPtr, 0, sizeof(EventStatusRecType));
\r
573 McuE_ExitCriticalSection(state);
\r
578 * Procedure: getEventStatusRec
\r
579 * Description: Returns the status record of "eventId" in "eventStatusRec"
\r
581 static void getEventStatusRec(Dem_EventIdType eventId, EventStatusRecType *eventStatusRec)
\r
583 EventStatusRecType *eventStatusRecPtr;
\r
586 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
588 if (eventStatusRecPtr != NULL) {
\r
590 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
593 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
599 * Procedure: lookupDtcEvent
\r
600 * Description: Returns TRUE if the DTC was found and "eventStatusRec" points
\r
601 * to the event record found.
\r
603 static boolean lookupDtcEvent(uint32 dtc, EventStatusRecType **eventStatusRec)
\r
605 boolean dtcFound = FALSE;
\r
608 *eventStatusRec = NULL;
\r
610 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && !dtcFound; i++) {
\r
611 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
612 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
615 if (eventStatusBuffer[i].eventParamRef->DTCClassRef->DTC == dtc) {
\r
616 *eventStatusRec = &eventStatusBuffer[i];
\r
628 * Procedure: matchEventWithDtcFilter
\r
629 * Description: Returns TRUE if the event pointed by "event" fulfill
\r
630 * the "dtcFilter" global filter settings.
\r
632 static boolean matchEventWithDtcFilter(const EventStatusRecType *eventRec)
\r
634 boolean dtcMatch = FALSE;
\r
637 if ((dtcFilter.dtcStatusMask == DEM_DTC_STATUS_MASK_ALL) || (eventRec->eventStatusExtended & dtcFilter.dtcStatusMask)) {
\r
638 if (eventRec->eventParamRef != NULL) {
\r
641 if (checkDtcKind(dtcFilter.dtcKind, eventRec->eventParamRef)) {
\r
644 if (checkDtcOrigin(dtcFilter.dtcOrigin, eventRec->eventParamRef)) {
\r
647 if ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
648 || ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES) && checkDtcSeverityMask(dtcFilter.dtcSeverityMask, eventRec->eventParamRef))) {
\r
650 // Check fault detection counter
\r
651 if ((dtcFilter.filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO)
\r
652 || ((dtcFilter.filterWithSeverity == DEM_FILTER_FOR_FDC_YES) && checkDtcFaultDetectionCounter(eventRec->eventParamRef))) {
\r
665 static void getFreezeFrameData(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
668 freezeFrame->eventId = DEM_EVENT_ID_NULL; // Not supported yet
\r
672 static void storeFreezeFrameDataPreInit(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
678 static void updateFreezeFrameOccurrencePreInit(EventRecType *EventBuffer)
\r
685 * Procedure: getExtendedData
\r
686 * Description: Collects the extended data according to "eventParam" and return it in "extData",
\r
687 * if not found eventId is set to DEM_EVENT_ID_NULL.
\r
689 static void getExtendedData(const Dem_EventParameterType *eventParam, ExtDataRecType *extData)
\r
691 Std_ReturnType callbackReturnCode;
\r
693 uint16 storeIndex = 0;
\r
696 // Clear ext data record
\r
697 memset(extData, 0, sizeof(ExtDataRecType));
\r
699 // Check if any pointer to extended data class
\r
700 if (eventParam->ExtendedDataClassRef != NULL) {
\r
701 // Request extended data and copy it to the buffer
\r
702 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL); i++) {
\r
703 recordSize = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
704 if ((storeIndex + recordSize) <= DEM_MAX_SIZE_EXT_DATA) {
\r
705 callbackReturnCode = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->CallbackGetExtDataRecord(&extData->data[storeIndex]); /** @req DEM282 */
\r
706 if (callbackReturnCode != E_OK) {
\r
707 // Callback data currently not available, clear space.
\r
708 memset(&extData->data[storeIndex], 0xFF, recordSize);
\r
710 storeIndex += recordSize;
\r
713 // Error: Size of extended data record is bigger than reserved space.
\r
714 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
715 Det_ReportError(MODULE_ID_DEM, 0, DEM_GET_EXTENDED_DATA_ID, DEM_E_EXT_DATA_TOO_BIG); /** @req DEM117 */
\r
717 break; // Break the loop
\r
722 // Check if any data has been stored
\r
723 if (storeIndex != 0) {
\r
724 extData->eventId = eventParam->EventID;
\r
725 extData->dataSize = storeIndex;
\r
726 extData->checksum = calcChecksum(extData, sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
729 extData->eventId = DEM_EVENT_ID_NULL;
\r
730 extData->dataSize = storeIndex;
\r
731 extData->checksum = 0;
\r
737 * Procedure: storeExtendedDataPreInit
\r
738 * Description: Store the extended data pointed by "extendedData" to the "preInitExtDataBuffer",
\r
739 * if non existent a new entry is created.
\r
741 static void storeExtendedDataPreInit(const Dem_EventParameterType *eventParam, ExtDataRecType *extendedData)
\r
744 imask_t state = McuE_EnterCriticalSection();
\r
746 // Check if already stored
\r
747 for (i = 0; (preInitExtDataBuffer[i].eventId != eventParam->EventID) && (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT); i++);
\r
749 if (i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) {
\r
750 // Yes, overwrite existing
\r
751 memcpy(&preInitExtDataBuffer[i], extendedData, sizeof(ExtDataRecType));
\r
754 // No, lookup first free position
\r
755 for (i = 0; (preInitExtDataBuffer[i].eventId !=0) && (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT); i++);
\r
757 if (i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) {
\r
758 memcpy(&preInitExtDataBuffer[i], extendedData, sizeof(ExtDataRecType));
\r
761 // Error: Pre init extended data buffer full
\r
762 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
763 Det_ReportError(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRE_INIT_ID, DEM_E_PRE_INIT_EXT_DATA_BUFF_FULL); /** @req DEM117 */
\r
768 McuE_ExitCriticalSection(state);
\r
773 * Procedure: storeEventPriMem
\r
774 * Description: Store the event data of "eventStatus->eventId" in "priMemEventBuffer",
\r
775 * if non existent a new entry is created.
\r
777 static void storeEventPriMem(const Dem_EventParameterType *eventParam, EventStatusRecType *eventStatus)
\r
780 imask_t state = McuE_EnterCriticalSection();
\r
784 for (i = 0; (priMemEventBuffer[i].eventId != eventStatus->eventId) && (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI); i++);
\r
786 if (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) {
\r
787 // Update event found
\r
788 priMemEventBuffer[i].occurrence = eventStatus->occurrence;
\r
789 priMemEventBuffer[i].checksum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
792 // Search for free position
\r
793 for (i=0; (priMemEventBuffer[i].eventId != DEM_EVENT_ID_NULL) && (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI); i++);
\r
795 if (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) {
\r
796 priMemEventBuffer[i].eventId = eventStatus->eventId;
\r
797 priMemEventBuffer[i].occurrence = eventStatus->occurrence;
\r
798 priMemEventBuffer[i].checksum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
801 // Error: Pri mem event buffer full
\r
802 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
803 Det_ReportError(MODULE_ID_DEM, 0, DEM_STORE_EVENT_PRI_MEM_ID, DEM_E_PRI_MEM_EVENT_BUFF_FULL); /** @req DEM117 */
\r
808 McuE_ExitCriticalSection(state);
\r
813 * Procedure: deleteEventPriMem
\r
814 * Description: Delete the event data of "eventParam->eventId" from "priMemEventBuffer".
\r
816 static void deleteEventPriMem(const Dem_EventParameterType *eventParam)
\r
819 imask_t state = McuE_EnterCriticalSection();
\r
823 for (i = 0; (priMemEventBuffer[i].eventId != eventParam->EventID) && (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI); i++);
\r
825 if (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) {
\r
826 // Delete event found
\r
827 memset(&priMemEventBuffer[i], 0, sizeof(EventRecType));
\r
830 McuE_ExitCriticalSection(state);
\r
835 * Procedure: storeEventEvtMem
\r
836 * Description: Store the event data of "eventStatus->eventId" in event memory according to
\r
837 * "eventParam" destination option.
\r
839 static void storeEventEvtMem(const Dem_EventParameterType *eventParam, EventStatusRecType *eventStatus)
\r
843 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION)
\r
844 && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
845 switch (eventParam->EventClass->EventDestination[i])
\r
847 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
848 storeEventPriMem(eventParam, eventStatus); /** @req DEM010 */
\r
851 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
852 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
853 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
854 // Not yet supported
\r
855 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
856 Det_ReportError(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
867 * Procedure: storeExtendedDataPriMem
\r
868 * Description: Store the extended data pointed by "extendedData" to the "priMemExtDataBuffer",
\r
869 * if non existent a new entry is created.
\r
871 static void storeExtendedDataPriMem(const Dem_EventParameterType *eventParam, ExtDataRecType *extendedData) /** @req DEM041 */
\r
874 imask_t state = McuE_EnterCriticalSection();
\r
876 // Check if already stored
\r
877 for (i = 0; (priMemExtDataBuffer[i].eventId != eventParam->EventID) && (i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM); i++);
\r
879 if (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) {
\r
880 // Yes, overwrite existing
\r
881 memcpy(&priMemExtDataBuffer[i], extendedData, sizeof(ExtDataRecType));
\r
884 // No, lookup first free position
\r
885 for (i = 0; (priMemExtDataBuffer[i].eventId != DEM_EVENT_ID_NULL) && (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM); i++);
\r
886 if (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) {
\r
887 memcpy(&priMemExtDataBuffer[i], extendedData, sizeof(ExtDataRecType));
\r
890 // Error: Pri mem extended data buffer full
\r
891 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
892 Det_ReportError(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRI_MEM_ID, DEM_E_PRI_MEM_EXT_DATA_BUFF_FULL); /** @req DEM117 */
\r
897 McuE_ExitCriticalSection(state);
\r
902 * Procedure: deleteExtendedDataPriMem
\r
903 * Description: Delete the extended data of "eventParam->eventId" from "priMemExtDataBuffer".
\r
905 static void deleteExtendedDataPriMem(const Dem_EventParameterType *eventParam)
\r
908 imask_t state = McuE_EnterCriticalSection();
\r
910 // Check if already stored
\r
911 for (i = 0; (priMemExtDataBuffer[i].eventId != eventParam->EventID) && (i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM); i++);
\r
913 if (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) {
\r
914 // Yes, clear record
\r
915 memset(&priMemExtDataBuffer[i], 0, sizeof(ExtDataRecType));
\r
918 McuE_ExitCriticalSection(state);
\r
923 * Procedure: storeExtendedDataEvtMem
\r
924 * Description: Store the extended data in event memory according to
\r
925 * "eventParam" destination option
\r
927 static void storeExtendedDataEvtMem(const Dem_EventParameterType *eventParam, ExtDataRecType *extendedData)
\r
931 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
932 switch (eventParam->EventClass->EventDestination[i])
\r
934 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
935 storeExtendedDataPriMem(eventParam, extendedData);
\r
938 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
939 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
940 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
941 // Not yet supported
\r
942 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
943 Det_ReportError(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
955 * Procedure: lookupExtendedDataRecNumParam
\r
956 * Description: Returns TRUE if the requested extended data number was found among the configured records for the event.
\r
957 * "extDataRecClassPtr" returns a pointer to the record class, "posInExtData" returns the position in stored extended data.
\r
959 static boolean lookupExtendedDataRecNumParam(uint8 extendedDataNumber, const Dem_EventParameterType *eventParam, Dem_ExtendedDataRecordClassType const **extDataRecClassPtr, uint8 *posInExtData)
\r
961 boolean recNumFound = FALSE;
\r
963 if (eventParam->ExtendedDataClassRef != NULL) {
\r
964 Dem_ExtendedDataRecordClassType const* const* extDataRecClassRefList = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef;
\r
965 uint16 byteCnt = 0;
\r
968 // Request extended data and copy it to the buffer
\r
969 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (extDataRecClassRefList[i] != NULL) && !recNumFound; i++) {
\r
970 if (extDataRecClassRefList[i]->RecordNumber == extendedDataNumber) {
\r
971 *extDataRecClassPtr = extDataRecClassRefList[i];
\r
972 *posInExtData = byteCnt;
\r
973 recNumFound = TRUE;
\r
975 byteCnt += extDataRecClassRefList[i]->DataSize;
\r
979 return recNumFound;
\r
984 * Procedure: lookupExtendedDataPriMem
\r
985 * Description: Returns TRUE if the requested event id is found, "extData" points to the found data.
\r
987 static boolean lookupExtendedDataPriMem(Dem_EventIdType eventId, ExtDataRecType **extData)
\r
989 boolean eventIdFound = FALSE;
\r
992 // Lookup corresponding extended data
\r
993 for (i = 0; (priMemExtDataBuffer[i].eventId != eventId) && (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM); i++);
\r
995 if (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) {
\r
996 // Yes, return pointer
\r
997 *extData = &priMemExtDataBuffer[i];
\r
998 eventIdFound = TRUE;
\r
1001 return eventIdFound;
\r
1005 static void storeFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
1011 static void deleteFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam)
\r
1018 * Procedure: storeFreezeFrameDataEvtMem
\r
1019 * Description: Store the freeze frame data in event memory according to
\r
1020 * "eventParam" destination option
\r
1022 static void storeFreezeFrameDataEvtMem(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
1026 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
1027 switch (eventParam->EventClass->EventDestination[i])
\r
1029 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1030 storeFreezeFrameDataPriMem(eventParam, freezeFrame);
\r
1033 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1034 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1035 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1036 // Not yet supported
\r
1037 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1038 Det_ReportError(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
1049 * Procedure: handlePreInitEvent
\r
1050 * Description: Handle the updating of event status and storing of
\r
1051 * event related data in preInit buffers.
\r
1053 static void handlePreInitEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1055 const Dem_EventParameterType *eventParam;
\r
1056 EventStatusRecType eventStatusLocal;
\r
1057 FreezeFrameRecType freezeFrameLocal;
\r
1058 ExtDataRecType extendedDataLocal;
\r
1060 // Find configuration for this event
\r
1061 lookupEventIdParameter(eventId, &eventParam);
\r
1062 if (eventParam != NULL) {
\r
1063 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1064 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1065 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
1066 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1069 updateEventStatusRec(eventParam, eventStatus, FALSE, &eventStatusLocal);
\r
1072 if (eventStatusLocal.errorStatusChanged) {
\r
1074 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1075 // Collect freeze frame data
\r
1076 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1077 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1078 storeFreezeFrameDataPreInit(eventParam, &freezeFrameLocal);
\r
1081 // Collect extended data
\r
1082 getExtendedData(eventParam, &extendedDataLocal);
\r
1083 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1084 storeExtendedDataPreInit(eventParam, &extendedDataLocal);
\r
1090 // Operation cycle not started
\r
1091 // TODO: Report error?
\r
1095 // Operation cycle not set
\r
1096 // TODO: Report error?
\r
1100 // Event ID not configured
\r
1101 // TODO: Report error?
\r
1107 * Procedure: handleEvent
\r
1108 * Description: Handle the updating of event status and storing of
\r
1109 * event related data in event memory.
\r
1111 static Std_ReturnType handleEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1113 Std_ReturnType returnCode = E_OK;
\r
1114 const Dem_EventParameterType *eventParam;
\r
1115 EventStatusRecType eventStatusLocal;
\r
1116 FreezeFrameRecType freezeFrameLocal;
\r
1117 ExtDataRecType extendedDataLocal;
\r
1119 // Find configuration for this event
\r
1120 lookupEventIdParameter(eventId, &eventParam);
\r
1121 if (eventParam != NULL) {
\r
1122 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1123 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1124 if (!(disableDtcStorage.storageDisabled && checkDtcGroup(disableDtcStorage.dtcGroup, eventParam) && checkDtcKind(disableDtcStorage.dtcKind, eventParam))) {
\r
1125 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1126 if (eventStatusLocal.errorStatusChanged) {
\r
1127 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1128 storeEventEvtMem(eventParam, &eventStatusLocal); /** @req DEM184 */
\r
1129 // Collect freeze frame data
\r
1130 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1131 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1132 storeFreezeFrameDataEvtMem(eventParam, &freezeFrameLocal); /** @req DEM190 */
\r
1135 // Collect extended data
\r
1136 getExtendedData(eventParam, &extendedDataLocal);
\r
1137 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL)
\r
1139 storeExtendedDataEvtMem(eventParam, &extendedDataLocal);
\r
1146 // Operation cycle not started
\r
1147 returnCode = E_NOT_OK;
\r
1151 // Operation cycle not set
\r
1152 returnCode = E_NOT_OK;
\r
1156 // Event ID not configured
\r
1157 returnCode = E_NOT_OK;
\r
1160 return returnCode;
\r
1165 * Procedure: resetEventStatus
\r
1166 * Description: Resets the events status of eventId.
\r
1168 static void resetEventStatus(Dem_EventIdType eventId)
\r
1170 imask_t state = McuE_EnterCriticalSection();
\r
1171 EventStatusRecType *eventStatusRecPtr;
\r
1173 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
1174 if (eventStatusRecPtr != NULL) {
\r
1175 eventStatusRecPtr->eventStatusExtended &= ~DEM_TEST_FAILED; /** @req DEM187 */
\r
1178 McuE_ExitCriticalSection(state);
\r
1183 * Procedure: getEventStatus
\r
1184 * Description: Returns the extended event status bitmask of eventId in "eventStatusExtended".
\r
1186 static void getEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended)
\r
1188 EventStatusRecType eventStatusLocal;
\r
1190 // Get recorded status
\r
1191 getEventStatusRec(eventId, &eventStatusLocal);
\r
1192 if (eventStatusLocal.eventId == eventId) {
\r
1193 *eventStatusExtended = eventStatusLocal.eventStatusExtended; /** @req DEM051 */
\r
1196 // Event Id not found, no report received.
\r
1197 *eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1203 * Procedure: getEventFailed
\r
1204 * Description: Returns the TRUE or FALSE of "eventId" in "eventFailed" depending on current status.
\r
1206 static void getEventFailed(Dem_EventIdType eventId, boolean *eventFailed)
\r
1208 EventStatusRecType eventStatusLocal;
\r
1210 // Get recorded status
\r
1211 getEventStatusRec(eventId, &eventStatusLocal);
\r
1212 if (eventStatusLocal.eventId == eventId) {
\r
1213 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) { /** @req DEM052 */
\r
1214 *eventFailed = TRUE;
\r
1217 *eventFailed = FALSE;
\r
1221 // Event Id not found, assume ok.
\r
1222 *eventFailed = FALSE;
\r
1228 * Procedure: getEventTested
\r
1229 * Description: Returns the TRUE or FALSE of "eventId" in "eventTested" depending on
\r
1230 * current status the "test not completed this operation cycle" bit.
\r
1232 static void getEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1234 EventStatusRecType eventStatusLocal;
\r
1236 // Get recorded status
\r
1237 getEventStatusRec(eventId, &eventStatusLocal);
\r
1238 if (eventStatusLocal.eventId == eventId) {
\r
1239 if ( !(eventStatusLocal.eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE)) { /** @req DEM053 */
\r
1240 *eventTested = TRUE;
\r
1243 *eventTested = FALSE;
\r
1247 // Event Id not found, not tested.
\r
1248 *eventTested = FALSE;
\r
1254 * Procedure: getFaultDetectionCounter
\r
1255 * Description: Returns pre debounce counter of "eventId" in "counter" and return value E_OK if
\r
1256 * the counter was available else E_NOT_OK.
\r
1258 static Std_ReturnType getFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1260 Std_ReturnType returnCode = E_NOT_OK;
\r
1261 const Dem_EventParameterType *eventParam;
\r
1263 lookupEventIdParameter(eventId, &eventParam);
\r
1264 if (eventParam != NULL) {
\r
1265 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
1266 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName)
\r
1268 case DEM_NO_PRE_DEBOUNCE:
\r
1269 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal != NULL) {
\r
1270 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc != NULL) {
\r
1271 returnCode = eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc(counter); /** @req DEM204.None */ /** @req DEM264 */ /** @req DEM265 */
\r
1276 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
1278 EventStatusRecType *eventStatusRec;
\r
1280 lookupEventStatusRec(eventId, &eventStatusRec);
\r
1281 if (eventStatusRec != NULL) {
\r
1282 *counter = eventStatusRec->faultDetectionCounter; /** @req DEM204.Counter */
\r
1286 returnCode = E_OK;
\r
1290 case DEM_PRE_DEBOUNCE_FREQUENCY_BASED:
\r
1291 case DEM_PRE_DEBOUNCE_TIME_BASED:
\r
1292 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1293 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
1298 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1299 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_PARAM_DATA); /** @req DEM117 */
\r
1306 return returnCode;
\r
1311 * Procedure: setOperationCycleState
\r
1312 * Description: Change the operation state of "operationCycleId" to "cycleState" and updates stored
\r
1313 * event connected to this cycle id.
\r
1314 * Returns E_OK if operation was successful else E_NOT_OK.
\r
1316 static Std_ReturnType setOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState) /** @req DEM338 */
\r
1319 Std_ReturnType returnCode = E_OK;
\r
1321 if (operationCycleId < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1322 switch (cycleState)
\r
1324 case DEM_CYCLE_STATE_START:
\r
1325 operationCycleStateList[operationCycleId] = cycleState;
\r
1326 // Lookup event ID
\r
1327 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1328 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1329 eventStatusBuffer[i].eventStatusExtended &= ~DEM_TEST_FAILED_THIS_OPERATION_CYCLE;
\r
1330 eventStatusBuffer[i].eventStatusExtended |= DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
1335 case DEM_CYCLE_STATE_END:
\r
1336 operationCycleStateList[operationCycleId] = cycleState;
\r
1337 // Lookup event ID
\r
1338 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1339 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1340 if (!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_FAILED_THIS_OPERATION_CYCLE) && !(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE)) {
\r
1341 eventStatusBuffer[i].eventStatusExtended &= ~DEM_PENDING_DTC; // Clear pendingDTC bit /** @req DEM379.PendingClear
\r
1347 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1348 Det_ReportError(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA); /** @req DEM117 */
\r
1350 returnCode = E_NOT_OK;
\r
1355 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1356 Det_ReportError(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA); /** @req DEM117 */
\r
1358 returnCode = E_NOT_OK;
\r
1361 return returnCode;
\r
1365 //==============================================================================//
\r
1367 // E X T E R N A L F U N C T I O N S //
\r
1369 //==============================================================================//
\r
1371 /*********************************************
\r
1372 * Interface for upper layer modules (8.3.1) *
\r
1373 *********************************************/
\r
1376 * Procedure: Dem_GetVersionInfo
\r
1379 // Defined in Dem.h
\r
1382 /***********************************************
\r
1383 * Interface ECU State Manager <-> DEM (8.3.2) *
\r
1384 ***********************************************/
\r
1387 * Procedure: Dem_PreInit
\r
1390 void Dem_PreInit(void)
\r
1392 /** @req DEM180 */
\r
1395 if (DEM_Config.ConfigSet == NULL) {
\r
1396 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1397 Det_ReportError(MODULE_ID_DEM, 0, DEM_PREINIT_ID, DEM_E_CONFIG_PTR_INVALID); /** @req DEM117 */
\r
1401 configSet = DEM_Config.ConfigSet;
\r
1404 // Initializion of operation cycle states.
\r
1405 for (i = 0; i < DEM_OPERATION_CYCLE_ID_ENDMARK; i++) {
\r
1406 operationCycleStateList[i] = DEM_CYCLE_STATE_END;
\r
1409 // Initialize the event status buffer
\r
1410 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1411 eventStatusBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1412 eventStatusBuffer[i].eventParamRef = NULL;
\r
1413 eventStatusBuffer[i].faultDetectionCounter = 0;
\r
1414 eventStatusBuffer[i].occurrence = 0;
\r
1415 eventStatusBuffer[i].eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1416 eventStatusBuffer[i].errorStatusChanged = FALSE;
\r
1419 // Initialize the pre init buffers
\r
1420 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1421 preInitFreezeFrameBuffer[i].checksum = 0;
\r
1422 preInitFreezeFrameBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1423 preInitFreezeFrameBuffer[i].occurrence = 0;
\r
1424 preInitFreezeFrameBuffer[i].dataSize = 0;
\r
1425 for (j = 0; j < DEM_MAX_SIZE_FF_DATA;j++)
\r
1426 preInitFreezeFrameBuffer[i].data[j] = 0;
\r
1429 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1430 preInitExtDataBuffer[i].checksum = 0;
\r
1431 preInitExtDataBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1432 preInitExtDataBuffer[i].dataSize = 0;
\r
1433 for (j = 0; j < DEM_MAX_SIZE_EXT_DATA;j++)
\r
1434 preInitExtDataBuffer[i].data[j] = 0;
\r
1437 disableDtcStorage.storageDisabled = FALSE;
\r
1439 setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_START); /** @req DEM047 */
\r
1441 demState = DEM_PREINITIALIZED;
\r
1446 * Procedure: Dem_Init
\r
1449 void Dem_Init(void)
\r
1452 ChecksumType cSum;
\r
1453 const Dem_EventParameterType *eventParam;
\r
1456 * Validate and read out saved error log from non volatile memory
\r
1459 // Validate event records stored in primary memory
\r
1460 for (i = 0; i < DEM_MAX_NUMBER_EVENT_PRI_MEM; i++) {
\r
1461 cSum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
1462 if ((cSum != priMemEventBuffer[i].checksum) || priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL) {
\r
1463 // Unlegal record, clear the record
\r
1464 memset(&priMemEventBuffer[i], 0, sizeof(EventRecType));
\r
1467 // Valid, update current status
\r
1468 mergeEventStatusRec(&priMemEventBuffer[i]);
\r
1470 // Update occurrence counter on pre init stored freeze frames
\r
1471 updateFreezeFrameOccurrencePreInit(&priMemEventBuffer[i]);
\r
1475 // Validate extended data records stored in primary memory
\r
1476 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM; i++) {
\r
1477 cSum = calcChecksum(&priMemExtDataBuffer[i], sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
1478 if ((cSum != priMemExtDataBuffer[i].checksum) || priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL) {
\r
1479 // Unlegal record, clear the record
\r
1480 memset(&priMemExtDataBuffer[i], 0, sizeof(ExtDataRecType));
\r
1484 // Validate freeze frame records stored in primary memory
\r
1485 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++) {
\r
1486 cSum = calcChecksum(&priMemFreezeFrameBuffer[i], sizeof(FreezeFrameRecType)-sizeof(ChecksumType));
\r
1487 if ((cSum != priMemFreezeFrameBuffer[i].checksum) || (priMemFreezeFrameBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1488 // Unlegal record, clear the record
\r
1489 memset(&priMemFreezeFrameBuffer[i], 0, sizeof(FreezeFrameRecType));
\r
1494 * Handle errors stored in temporary buffer (if any)
\r
1497 // Transfer updated event data to event memory
\r
1498 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1499 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1500 // Update the event memory
\r
1501 lookupEventIdParameter(eventStatusBuffer[i].eventId, &eventParam);
\r
1502 storeEventEvtMem(eventParam, &eventStatusBuffer[i]);
\r
1506 // Transfer extended data to event memory if necessary
\r
1507 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1508 if (preInitExtDataBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1509 lookupEventIdParameter(preInitExtDataBuffer[i].eventId, &eventParam);
\r
1510 storeExtendedDataEvtMem(eventParam, &preInitExtDataBuffer[i]);
\r
1514 // Transfer freeze frames to event memory
\r
1515 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1516 if (preInitFreezeFrameBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1517 lookupEventIdParameter(preInitFreezeFrameBuffer[i].eventId, &eventParam);
\r
1518 storeFreezeFrameDataEvtMem(eventParam, &preInitFreezeFrameBuffer[i]);
\r
1522 // Init the dtc filter
\r
1523 dtcFilter.dtcStatusMask = DEM_DTC_STATUS_MASK_ALL; // All allowed
\r
1524 dtcFilter.dtcKind = DEM_DTC_KIND_ALL_DTCS; // All kinds of DTCs
\r
1525 dtcFilter.dtcOrigin = DEM_DTC_ORIGIN_PRIMARY_MEMORY; // Primary memory
\r
1526 dtcFilter.filterWithSeverity = DEM_FILTER_WITH_SEVERITY_NO; // No Severity filtering
\r
1527 dtcFilter.dtcSeverityMask = DEM_SEVERITY_NO_SEVERITY; // Not used when filterWithSeverity is FALSE
\r
1528 dtcFilter.filterForFaultDetectionCounter = DEM_FILTER_FOR_FDC_NO; // No fault detection counter filtering
\r
1530 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1532 disableDtcStorage.storageDisabled = FALSE;
\r
1534 demState = DEM_INITIALIZED;
\r
1539 * Procedure: Dem_shutdown
\r
1542 void Dem_Shutdown(void)
\r
1544 setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_END); /** @req DEM047 */
\r
1546 demState = DEM_UNINITIALIZED; /** @req DEM368 */
\r
1551 * Interface for basic software scheduler
\r
1553 void Dem_MainFunction(void)
\r
1555 /** @req DEM125 */
\r
1560 /***************************************************
\r
1561 * Interface SW-Components via RTE <-> DEM (8.3.3) *
\r
1562 ***************************************************/
\r
1565 * Procedure: Dem_SetEventStatus
\r
1568 Std_ReturnType Dem_SetEventStatus(Dem_EventIdType eventId, Dem_EventStatusType eventStatus) /** @req DEM330 */
\r
1570 Std_ReturnType returnCode = E_OK;
\r
1572 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1574 returnCode = handleEvent(eventId, eventStatus);
\r
1578 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1579 Det_ReportError(MODULE_ID_DEM, 0, DEM_SETEVENTSTATUS_ID, DEM_E_UNINIT); /** @req DEM124.SetEventStatus */ /** @req DEM117 */
\r
1581 returnCode = E_NOT_OK; /** @req DEM370.SetEventStatus */
\r
1584 return returnCode;
\r
1589 * Procedure: Dem_ResetEventStatus
\r
1592 Std_ReturnType Dem_ResetEventStatus(Dem_EventIdType eventId) /** @req DEM331 */
\r
1594 Std_ReturnType returnCode = E_OK;
\r
1596 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1598 resetEventStatus(eventId); /** @req DEM186 */
\r
1602 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1603 Det_ReportError(MODULE_ID_DEM, 0, DEM_RESETEVENTSTATUS_ID, DEM_E_UNINIT); /** @req DEM124.ResetEventStatus */ /** @req DEM117 */
\r
1605 returnCode = E_NOT_OK; /** @req DEM370.ResetEventStatus */
\r
1608 return returnCode;
\r
1613 * Procedure: Dem_GetEventStatus
\r
1616 Std_ReturnType Dem_GetEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended) /** @req DEM332 */
\r
1618 Std_ReturnType returnCode = E_OK;
\r
1620 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1622 getEventStatus(eventId, eventStatusExtended);
\r
1626 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1627 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETEVENTSTATUS_ID, DEM_E_UNINIT); /** @req DEM124.GetEventStatus */ /** @req DEM117 */
\r
1629 returnCode = E_NOT_OK; /** @req DEM370.GetEventStatus */
\r
1632 return returnCode;
\r
1637 * Procedure: Dem_GetEventFailed
\r
1640 Std_ReturnType Dem_GetEventFailed(Dem_EventIdType eventId, boolean *eventFailed) /** @req DEM333 */
\r
1642 Std_ReturnType returnCode = E_OK;
\r
1644 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1646 getEventFailed(eventId, eventFailed);
\r
1650 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1651 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETEVENTFAILED_ID, DEM_E_UNINIT); /** @req DEM124.GetEventFailed */ /** @req DEM117 */
\r
1653 returnCode = E_NOT_OK; /** @req DEM370.GetEventFailed */
\r
1656 return returnCode;
\r
1661 * Procedure: Dem_GetEventTested
\r
1664 Std_ReturnType Dem_GetEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1666 Std_ReturnType returnCode = E_OK;
\r
1668 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1670 getEventTested(eventId, eventTested);
\r
1674 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1675 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETEVENTTESTED_ID, DEM_E_UNINIT); /** @req DEM124.GetEventTested */ /** @req DEM117 */
\r
1677 returnCode = E_NOT_OK; /** @req DEM370.GetEventTested */
\r
1680 return returnCode;
\r
1685 * Procedure: Dem_GetFaultDetectionCounter
\r
1688 Std_ReturnType Dem_GetFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1690 Std_ReturnType returnCode = E_OK;
\r
1692 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1694 returnCode = getFaultDetectionCounter(eventId, counter);
\r
1698 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1699 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_UNINIT); /** @req DEM124.GetFaultDetectionCounter */ /** @req DEM117 */
\r
1701 returnCode = E_NOT_OK; /** @req DEM370.GetFaultDetectionCounter */
\r
1704 return returnCode;
\r
1709 * Procedure: Dem_SetOperationCycleState
\r
1712 Std_ReturnType Dem_SetOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState)
\r
1714 Std_ReturnType returnCode = E_OK;
\r
1716 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1718 returnCode = setOperationCycleState(operationCycleId, cycleState);
\r
1723 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1724 Det_ReportError(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_UNINIT); /** @req DEM124.SetOperationCycleState */ /** @req DEM117 */
\r
1726 returnCode = E_NOT_OK; /** @req DEM370.SetOperationCycleState */
\r
1729 return returnCode;
\r
1734 * Procedure: Dem_GetDTCOfEvent
\r
1737 Std_ReturnType Dem_GetDTCOfEvent(Dem_EventIdType eventId, Dem_DTCKindType dtcKind, uint32* dtcOfEvent)
\r
1739 Std_ReturnType returnCode = E_NO_DTC_AVAILABLE;
\r
1740 const Dem_EventParameterType *eventParam;
\r
1742 lookupEventIdParameter(eventId, &eventParam);
\r
1744 if (eventParam != NULL) {
\r
1745 if (checkDtcKind(dtcKind, eventParam)) {
\r
1746 if (eventParam->DTCClassRef != NULL) {
\r
1747 *dtcOfEvent = eventParam->DTCClassRef->DTC; /** @req DEM269 */
\r
1748 returnCode = E_OK;
\r
1753 // Event Id not found
\r
1754 returnCode = E_NOT_OK;
\r
1757 return returnCode;
\r
1761 /********************************************
\r
1762 * Interface BSW-Components <-> DEM (8.3.4) *
\r
1763 ********************************************/
\r
1766 * Procedure: Dem_ReportErrorStatus
\r
1769 void Dem_ReportErrorStatus( Dem_EventIdType eventId, Dem_EventStatusType eventStatus ) /** @req DEM107 */
\r
1772 switch (demState) {
\r
1773 case DEM_PREINITIALIZED:
\r
1774 // Update status and check if is to be stored
\r
1775 if ((eventStatus == DEM_EVENT_STATUS_PASSED) || (eventStatus == DEM_EVENT_STATUS_FAILED)) {
\r
1776 handlePreInitEvent(eventId, eventStatus); /** @req DEM168 */
\r
1780 case DEM_INITIALIZED:
\r
1781 (void)handleEvent(eventId, eventStatus); /** @req DEM167 */
\r
1784 case DEM_UNINITIALIZED:
\r
1786 // Uninitialized can not do anything
\r
1787 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1788 Det_ReportError(MODULE_ID_DEM, 0, DEM_REPORTERRORSTATUS_ID, DEM_E_UNINIT); /** @req DEM124.ReportErrorStatus */ /** @req DEM364 */ /** @req DEM117 */
\r
1792 } // switch (demState)
\r
1795 /*********************************
\r
1796 * Interface DCM <-> DEM (8.3.5) *
\r
1797 *********************************/
\r
1799 * Procedure: Dem_GetDTCStatusAvailabilityMask
\r
1802 Std_ReturnType Dem_GetDTCStatusAvailabilityMask(uint8 *dtcStatusMask) /** @req DEM014 */
\r
1804 *dtcStatusMask = DEM_DTC_STATUS_AVAILABILITY_MASK; // User configuration mask
\r
1805 *dtcStatusMask &= DEM_TEST_FAILED // Mask with supported bits /** @req DEM060 */
\r
1806 | DEM_TEST_FAILED_THIS_OPERATION_CYCLE
\r
1808 // | DEM_CONFIRMED_DTC TODO: Add support for this bit
\r
1809 | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR
\r
1810 | DEM_TEST_FAILED_SINCE_LAST_CLEAR
\r
1811 | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE
\r
1812 // | DEM_WARNING_INDICATOR_REQUESTED TODO: Add support for this bit
\r
1820 * Procedure: Dem_SetDTCFilter
\r
1823 Dem_ReturnSetDTCFilterType Dem_SetDTCFilter(uint8 dtcStatusMask,
\r
1824 Dem_DTCKindType dtcKind,
\r
1825 Dem_DTCOriginType dtcOrigin,
\r
1826 Dem_FilterWithSeverityType filterWithSeverity,
\r
1827 Dem_DTCSeverityType dtcSeverityMask,
\r
1828 Dem_FilterForFDCType filterForFaultDetectionCounter) {
\r
1830 Dem_ReturnSetDTCFilterType returnCode = DEM_WRONG_FILTER;
\r
1832 // Check dtcKind parameter
\r
1833 if ((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS)) {
\r
1835 // Check dtcOrigin parameter
\r
1836 if ((dtcOrigin == DEM_DTC_ORIGIN_SECONDARY_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_PRIMARY_MEMORY)
\r
1837 || (dtcOrigin == DEM_DTC_ORIGIN_PERMANENT_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_MIRROR_MEMORY)) {
\r
1839 // Check filterWithSeverity and dtcSeverityMask parameter
\r
1840 if ((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
1841 || ((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES) && !(dtcSeverityMask & ~(DEM_SEVERITY_MAINTENANCE_ONLY | DEM_SEVERITY_CHECK_AT_NEXT_FALT | DEM_SEVERITY_CHECK_IMMEDIATELY)))){
\r
1843 // Check filterForFaultDetectionCounter parameter
\r
1844 if ((filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_YES) || (filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO)) {
\r
1845 // Yes all parameters correct, set the new filters. /** @req DEM057 */
\r
1846 dtcFilter.dtcStatusMask = dtcStatusMask;
\r
1847 dtcFilter.dtcKind = dtcKind;
\r
1848 dtcFilter.dtcOrigin = dtcOrigin;
\r
1849 dtcFilter.filterWithSeverity = filterWithSeverity;
\r
1850 dtcFilter.dtcSeverityMask = dtcSeverityMask;
\r
1851 dtcFilter.filterForFaultDetectionCounter = filterForFaultDetectionCounter;
\r
1852 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1853 returnCode = DEM_FILTER_ACCEPTED;
\r
1859 return returnCode;
\r
1864 * Procedure: Dem_GetStatusOfDTC
\r
1867 Dem_ReturnGetStatusOfDTCType Dem_GetStatusOfDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, Dem_EventStatusExtendedType* status) {
\r
1868 Dem_ReturnGetStatusOfDTCType returnCode = DEM_STATUS_FAILED;
\r
1869 EventStatusRecType *eventRec;
\r
1871 if (lookupDtcEvent(dtc, &eventRec)) {
\r
1872 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
1873 if (checkDtcOrigin(dtcOrigin,eventRec->eventParamRef)) {
\r
1874 *status = eventRec->eventStatusExtended; /** @req DEM059 */
\r
1875 returnCode = DEM_STATUS_OK;
\r
1878 returnCode = DEM_STATUS_WRONG_DTCORIGIN; /** @req DEM171 */
\r
1882 returnCode = DEM_STATUS_WRONG_DTCKIND;
\r
1886 returnCode = DEM_STATUS_WRONG_DTC; /** @req DEM172 */
\r
1889 return returnCode;
\r
1894 * Procedure: Dem_GetNumberOfFilteredDtc
\r
1897 Dem_ReturnGetNumberOfFilteredDTCType Dem_GetNumberOfFilteredDtc(uint16 *numberOfFilteredDTC) {
\r
1899 uint16 numberOfFaults = 0;
\r
1901 //Dem_DisableEventStatusUpdate();
\r
1903 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1904 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1905 if (matchEventWithDtcFilter(&eventStatusBuffer[i])) {
\r
1906 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
1913 //Dem_EnableEventStatusUpdate();
\r
1915 *numberOfFilteredDTC = numberOfFaults; /** @req DEM061 */
\r
1917 return DEM_NUMBER_OK;
\r
1922 * Procedure: Dem_GetNextFilteredDTC
\r
1925 Dem_ReturnGetNextFilteredDTCType Dem_GetNextFilteredDTC(uint32 *dtc, Dem_EventStatusExtendedType *dtcStatus)
\r
1927 Dem_ReturnGetNextFilteredDTCType returnCode = DEM_FILTERED_OK;
\r
1928 boolean dtcFound = FALSE;
\r
1930 // TODO: This job should be done in an more advanced way according to Dem217
\r
1931 while (!dtcFound && (dtcFilter.faultIndex != 0)) {
\r
1932 dtcFilter.faultIndex--;
\r
1933 if (eventStatusBuffer[dtcFilter.faultIndex].eventId != DEM_EVENT_ID_NULL) {
\r
1934 if (matchEventWithDtcFilter(&eventStatusBuffer[dtcFilter.faultIndex])) {
\r
1935 if (eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef != NULL) {
\r
1936 *dtc = eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef->DTC; /** @req DEM216 */
\r
1937 *dtcStatus = eventStatusBuffer[dtcFilter.faultIndex].eventStatusExtended;
\r
1945 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1946 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
1949 return returnCode;
\r
1954 * Procedure: Dem_GetTranslationType
\r
1957 Dem_ReturnTypeOfDtcSupportedType Dem_GetTranslationType(void)
\r
1959 return DEM_TYPE_OF_DTC_SUPPORTED; /** @req DEM231 */
\r
1964 * Procedure: Dem_ClearDTC
\r
1967 Dem_ReturnClearDTCType Dem_ClearDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin) /** @req DEM009 */
\r
1969 Dem_ReturnClearDTCType returnCode = DEM_CLEAR_OK;
\r
1970 Dem_EventIdType eventId;
\r
1971 const Dem_EventParameterType *eventParam;
\r
1974 // Loop through the event buffer
\r
1975 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1976 eventId = eventStatusBuffer[i].eventId;
\r
1977 if (eventId != DEM_EVENT_ID_NULL) {
\r
1978 eventParam = eventStatusBuffer[i].eventParamRef;
\r
1979 if (eventParam != NULL) {
\r
1980 if (DEM_CLEAR_ALL_EVENTS | (eventParam->DTCClassRef != NULL)) {
\r
1981 if (checkDtcKind(dtcKind, eventParam)) {
\r
1982 if (checkDtcGroup(dtc, eventParam)) {
\r
1983 for (j = 0; (j < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[j] != dtcOrigin); j++);
\r
1984 if (j < DEM_MAX_NR_OF_EVENT_DESTINATION) {
\r
1985 // Yes! All conditions met.
\r
1986 switch (dtcOrigin)
\r
1988 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1989 /** @req DEM077 */
\r
1990 deleteEventPriMem(eventParam);
\r
1991 deleteFreezeFrameDataPriMem(eventParam);
\r
1992 deleteExtendedDataPriMem(eventParam);
\r
1993 deleteEventStatusRec(eventParam); // TODO: Shall this be done or just resetting the status?
\r
1996 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1997 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1998 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1999 // Not yet supported
\r
2000 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2001 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
2002 Det_ReportError(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
2006 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2015 // Fatal error, no event parameters found for the stored event!
\r
2016 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
2017 Det_ReportError(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNEXPECTED_EXECUTION); /** @req DEM117 */
\r
2023 return returnCode;
\r
2028 * Procedure: Dem_DisableDTCStorage
\r
2031 Dem_ReturnControlDTCStorageType Dem_DisableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind) /** @req DEM035 */
\r
2033 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2035 // Check dtcGroup parameter
\r
2036 if (dtcGroup == DEM_DTC_GROUP_ALL_DTCS) {
\r
2037 // Check dtcKind parameter
\r
2038 if ((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS)) {
\r
2039 /** @req DEM079 */
\r
2040 disableDtcStorage.dtcGroup = dtcGroup;
\r
2041 disableDtcStorage.dtcKind = dtcKind;
\r
2042 disableDtcStorage.storageDisabled = TRUE;
\r
2044 returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2048 returnCode = DEM_CONTROL_DTC_WRONG_DTCGROUP;
\r
2051 return returnCode;
\r
2056 * Procedure: Dem_EnableDTCStorage
\r
2059 Dem_ReturnControlDTCStorageType Dem_EnableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind)
\r
2061 // TODO: Behavior is not defined if group or kind do not match active settings, therefore the filter is just switched off.
\r
2062 disableDtcStorage.storageDisabled = FALSE; /** @req DEM080 */
\r
2064 return DEM_CONTROL_DTC_STORAGE_OK;
\r
2068 * Procedure: Dem_GetExtendedDataRecordByDTC
\r
2071 Dem_ReturnGetExtendedDataRecordByDTCType Dem_GetExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint8 *destBuffer, uint8 *bufSize)
\r
2073 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_RECORD_WRONG_DTC;
\r
2074 EventStatusRecType *eventRec;
\r
2075 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2076 ExtDataRecType *extData;
\r
2077 uint8 posInExtData = 0;
\r
2079 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2080 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2081 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2082 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2083 if (*bufSize >= extendedDataRecordClass->DataSize) {
\r
2084 switch (dtcOrigin)
\r
2086 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2087 if (lookupExtendedDataPriMem(eventRec->eventId, &extData)) {
\r
2088 // Yes all conditions met, copy the extended data record to destination buffer.
\r
2089 memcpy(destBuffer, &extData->data[posInExtData], extendedDataRecordClass->DataSize); /** @req DEM075 */
\r
2090 *bufSize = extendedDataRecordClass->DataSize;
\r
2091 returnCode = DEM_RECORD_OK;
\r
2094 // The record number is legal but no record was found for the DTC
\r
2096 returnCode = DEM_RECORD_OK;
\r
2100 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2101 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2102 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2103 // Not yet supported
\r
2104 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2105 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
2106 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
2110 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2115 returnCode = DEM_RECORD_BUFFERSIZE;
\r
2119 returnCode = DEM_RECORD_NUMBER;
\r
2123 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2127 returnCode = DEM_RECORD_DTCKIND;
\r
2131 return returnCode;
\r
2136 * Procedure: Dem_GetSizeOfExtendedDataRecordByDTC
\r
2139 Dem_ReturnGetSizeOfExtendedDataRecordByDTCType Dem_GetSizeOfExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint16 *sizeOfExtendedDataRecord)
\r
2141 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2142 EventStatusRecType *eventRec;
\r
2143 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2144 uint8 posInExtData;
\r
2146 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2147 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2148 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2149 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2150 *sizeOfExtendedDataRecord = extendedDataRecordClass->DataSize; /** @req DEM076 */
\r
2151 returnCode = DEM_GET_SIZEOFEDRBYDTC_OK;
\r
2154 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_RNUM;
\r
2158 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCOR;
\r
2162 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCKI;
\r
2166 return returnCode;
\r
2169 /***********************************
\r
2170 * OBD-specific Interfaces (8.3.6) *
\r
2171 ***********************************/
\r