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
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 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName) { /** @req DEM004 */ /** @req DEM342 */
\r
457 case DEM_NO_PRE_DEBOUNCE:
\r
458 eventStatus = preDebounceNone(eventStatus, eventStatusRecPtr);
\r
461 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
462 eventStatus = preDebounceCounterBased(eventStatus, eventStatusRecPtr);
\r
466 // Don't know how to handle this.
\r
467 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
468 Det_ReportError(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
474 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
476 // Check test failed
\r
477 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
478 if (!(eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED)) {
\r
479 eventStatusRecPtr->occurrence++;
\r
480 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
482 /** @req DEM036 */ /** @req DEM379.PendingSet */
\r
483 eventStatusRecPtr->eventStatusExtended |= (DEM_TEST_FAILED | DEM_TEST_FAILED_THIS_OPERATION_CYCLE | DEM_TEST_FAILED_SINCE_LAST_CLEAR | DEM_PENDING_DTC);
\r
484 eventStatusRecPtr->eventStatusExtended &= ~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
487 // Check test passed
\r
488 if (eventStatus == DEM_EVENT_STATUS_PASSED) {
\r
489 if (eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED) {
\r
490 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
493 eventStatusRecPtr->eventStatusExtended &= ~DEM_TEST_FAILED;
\r
494 eventStatusRecPtr->eventStatusExtended &= ~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
498 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
501 // Copy an empty record to return data
\r
502 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
503 eventStatusRecPtr->faultDetectionCounter = 0;
\r
504 eventStatusRec->occurrence = 0;
\r
505 eventStatusRec->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
506 eventStatusRec->errorStatusChanged = FALSE;
\r
509 McuE_ExitCriticalSection(state);
\r
514 * Procedure: mergeEventStatusRec
\r
515 * Description: Update the occurrence counter of status, if not exist a new record is created
\r
517 static void mergeEventStatusRec(EventRecType *eventRec)
\r
519 EventStatusRecType *eventStatusRecPtr;
\r
520 imask_t state = McuE_EnterCriticalSection();
\r
523 lookupEventStatusRec(eventRec->eventId, &eventStatusRecPtr);
\r
525 if (eventStatusRecPtr != NULL) {
\r
526 // Update occurrence counter, rest of pre init state is kept.
\r
527 eventStatusRecPtr->occurrence += eventRec->occurrence;
\r
531 // Search for free position
\r
532 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
534 if (eventStatusRecPtr != NULL) {
\r
535 // Create new event, from stored event
\r
536 eventStatusRecPtr->eventId = eventRec->eventId;
\r
537 lookupEventIdParameter(eventRec->eventId, &eventStatusRecPtr->eventParamRef);
\r
538 eventStatusRecPtr->faultDetectionCounter = 0;
\r
539 eventStatusRecPtr->occurrence = eventRec->occurrence;
\r
540 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
541 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
544 // Error: Event status buffer full
\r
545 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
546 Det_ReportError(MODULE_ID_DEM, 0, DEM_MERGE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL); /** @req DEM117 */
\r
551 McuE_ExitCriticalSection(state);
\r
556 * Procedure: deleteEventStatusRec
\r
557 * Description: Delete the status record of "eventParam->eventId" from "eventStatusBuffer".
\r
559 static void deleteEventStatusRec(const Dem_EventParameterType *eventParam)
\r
561 EventStatusRecType *eventStatusRecPtr;
\r
562 imask_t state = McuE_EnterCriticalSection();
\r
565 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
567 if (eventStatusRecPtr != NULL) {
\r
568 // Delete event record
\r
569 memset(eventStatusRecPtr, 0, sizeof(EventStatusRecType));
\r
572 McuE_ExitCriticalSection(state);
\r
577 * Procedure: getEventStatusRec
\r
578 * Description: Returns the status record of "eventId" in "eventStatusRec"
\r
580 static void getEventStatusRec(Dem_EventIdType eventId, EventStatusRecType *eventStatusRec)
\r
582 EventStatusRecType *eventStatusRecPtr;
\r
585 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
587 if (eventStatusRecPtr != NULL) {
\r
589 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
592 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
598 * Procedure: lookupDtcEvent
\r
599 * Description: Returns TRUE if the DTC was found and "eventStatusRec" points
\r
600 * to the event record found.
\r
602 static boolean lookupDtcEvent(uint32 dtc, EventStatusRecType **eventStatusRec)
\r
604 boolean dtcFound = FALSE;
\r
607 *eventStatusRec = NULL;
\r
609 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && !dtcFound; i++) {
\r
610 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
611 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
614 if (eventStatusBuffer[i].eventParamRef->DTCClassRef->DTC == dtc) {
\r
615 *eventStatusRec = &eventStatusBuffer[i];
\r
627 * Procedure: matchEventWithDtcFilter
\r
628 * Description: Returns TRUE if the event pointed by "event" fulfill
\r
629 * the "dtcFilter" global filter settings.
\r
631 static boolean matchEventWithDtcFilter(const EventStatusRecType *eventRec)
\r
633 boolean dtcMatch = FALSE;
\r
636 if ((dtcFilter.dtcStatusMask == DEM_DTC_STATUS_MASK_ALL) || (eventRec->eventStatusExtended & dtcFilter.dtcStatusMask)) {
\r
637 if (eventRec->eventParamRef != NULL) {
\r
640 if (checkDtcKind(dtcFilter.dtcKind, eventRec->eventParamRef)) {
\r
643 if (checkDtcOrigin(dtcFilter.dtcOrigin, eventRec->eventParamRef)) {
\r
646 if ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
647 || ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES) && checkDtcSeverityMask(dtcFilter.dtcSeverityMask, eventRec->eventParamRef))) {
\r
649 // Check fault detection counter
\r
650 if ((dtcFilter.filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO)
\r
651 || ((dtcFilter.filterWithSeverity == DEM_FILTER_FOR_FDC_YES) && checkDtcFaultDetectionCounter(eventRec->eventParamRef))) {
\r
664 static void getFreezeFrameData(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
667 freezeFrame->eventId = DEM_EVENT_ID_NULL; // Not supported yet
\r
671 static void storeFreezeFrameDataPreInit(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
677 static void updateFreezeFrameOccurrencePreInit(EventRecType *EventBuffer)
\r
684 * Procedure: getExtendedData
\r
685 * Description: Collects the extended data according to "eventParam" and return it in "extData",
\r
686 * if not found eventId is set to DEM_EVENT_ID_NULL.
\r
688 static void getExtendedData(const Dem_EventParameterType *eventParam, ExtDataRecType *extData)
\r
690 Std_ReturnType callbackReturnCode;
\r
692 uint16 storeIndex = 0;
\r
695 // Clear ext data record
\r
696 memset(extData, 0, sizeof(ExtDataRecType));
\r
698 // Check if any pointer to extended data class
\r
699 if (eventParam->ExtendedDataClassRef != NULL) {
\r
700 // Request extended data and copy it to the buffer
\r
701 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL); i++) {
\r
702 recordSize = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
703 if ((storeIndex + recordSize) <= DEM_MAX_SIZE_EXT_DATA) {
\r
704 callbackReturnCode = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->CallbackGetExtDataRecord(&extData->data[storeIndex]); /** @req DEM282 */
\r
705 if (callbackReturnCode != E_OK) {
\r
706 // Callback data currently not available, clear space.
\r
707 memset(&extData->data[storeIndex], 0xFF, recordSize);
\r
709 storeIndex += recordSize;
\r
712 // Error: Size of extended data record is bigger than reserved space.
\r
713 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
714 Det_ReportError(MODULE_ID_DEM, 0, DEM_GET_EXTENDED_DATA_ID, DEM_E_EXT_DATA_TOO_BIG); /** @req DEM117 */
\r
716 break; // Break the loop
\r
721 // Check if any data has been stored
\r
722 if (storeIndex != 0) {
\r
723 extData->eventId = eventParam->EventID;
\r
724 extData->dataSize = storeIndex;
\r
725 extData->checksum = calcChecksum(extData, sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
728 extData->eventId = DEM_EVENT_ID_NULL;
\r
729 extData->dataSize = storeIndex;
\r
730 extData->checksum = 0;
\r
736 * Procedure: storeExtendedDataPreInit
\r
737 * Description: Store the extended data pointed by "extendedData" to the "preInitExtDataBuffer",
\r
738 * if non existent a new entry is created.
\r
740 static void storeExtendedDataPreInit(const Dem_EventParameterType *eventParam, ExtDataRecType *extendedData)
\r
743 imask_t state = McuE_EnterCriticalSection();
\r
745 // Check if already stored
\r
746 for (i = 0; (preInitExtDataBuffer[i].eventId != eventParam->EventID) && (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT); i++);
\r
748 if (i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) {
\r
749 // Yes, overwrite existing
\r
750 memcpy(&preInitExtDataBuffer[i], extendedData, sizeof(ExtDataRecType));
\r
753 // No, lookup first free position
\r
754 for (i = 0; (preInitExtDataBuffer[i].eventId !=0) && (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT); i++);
\r
756 if (i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) {
\r
757 memcpy(&preInitExtDataBuffer[i], extendedData, sizeof(ExtDataRecType));
\r
760 // Error: Pre init extended data buffer full
\r
761 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
762 Det_ReportError(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRE_INIT_ID, DEM_E_PRE_INIT_EXT_DATA_BUFF_FULL); /** @req DEM117 */
\r
767 McuE_ExitCriticalSection(state);
\r
772 * Procedure: storeEventPriMem
\r
773 * Description: Store the event data of "eventStatus->eventId" in "priMemEventBuffer",
\r
774 * if non existent a new entry is created.
\r
776 static void storeEventPriMem(const Dem_EventParameterType *eventParam, EventStatusRecType *eventStatus)
\r
779 imask_t state = McuE_EnterCriticalSection();
\r
783 for (i = 0; (priMemEventBuffer[i].eventId != eventStatus->eventId) && (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI); i++);
\r
785 if (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) {
\r
786 // Update event found
\r
787 priMemEventBuffer[i].occurrence = eventStatus->occurrence;
\r
788 priMemEventBuffer[i].checksum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
791 // Search for free position
\r
792 for (i=0; (priMemEventBuffer[i].eventId != DEM_EVENT_ID_NULL) && (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI); i++);
\r
794 if (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) {
\r
795 priMemEventBuffer[i].eventId = eventStatus->eventId;
\r
796 priMemEventBuffer[i].occurrence = eventStatus->occurrence;
\r
797 priMemEventBuffer[i].checksum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
800 // Error: Pri mem event buffer full
\r
801 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
802 Det_ReportError(MODULE_ID_DEM, 0, DEM_STORE_EVENT_PRI_MEM_ID, DEM_E_PRI_MEM_EVENT_BUFF_FULL); /** @req DEM117 */
\r
807 McuE_ExitCriticalSection(state);
\r
812 * Procedure: deleteEventPriMem
\r
813 * Description: Delete the event data of "eventParam->eventId" from "priMemEventBuffer".
\r
815 static void deleteEventPriMem(const Dem_EventParameterType *eventParam)
\r
818 imask_t state = McuE_EnterCriticalSection();
\r
822 for (i = 0; (priMemEventBuffer[i].eventId != eventParam->EventID) && (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI); i++);
\r
824 if (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) {
\r
825 // Delete event found
\r
826 memset(&priMemEventBuffer[i], 0, sizeof(EventRecType));
\r
829 McuE_ExitCriticalSection(state);
\r
834 * Procedure: storeEventEvtMem
\r
835 * Description: Store the event data of "eventStatus->eventId" in event memory according to
\r
836 * "eventParam" destination option.
\r
838 static void storeEventEvtMem(const Dem_EventParameterType *eventParam, EventStatusRecType *eventStatus)
\r
842 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != NULL); i++) {
\r
843 switch (eventParam->EventClass->EventDestination[i])
\r
845 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
846 storeEventPriMem(eventParam, eventStatus); /** @req DEM010 */
\r
849 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
850 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
851 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
852 // Not yet supported
\r
853 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
854 Det_ReportError(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
865 * Procedure: storeExtendedDataPriMem
\r
866 * Description: Store the extended data pointed by "extendedData" to the "priMemExtDataBuffer",
\r
867 * if non existent a new entry is created.
\r
869 static void storeExtendedDataPriMem(const Dem_EventParameterType *eventParam, ExtDataRecType *extendedData) /** @req DEM041 */
\r
872 imask_t state = McuE_EnterCriticalSection();
\r
874 // Check if already stored
\r
875 for (i = 0; (priMemExtDataBuffer[i].eventId != eventParam->EventID) && (i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM); i++);
\r
877 if (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) {
\r
878 // Yes, overwrite existing
\r
879 memcpy(&priMemExtDataBuffer[i], extendedData, sizeof(ExtDataRecType));
\r
882 // No, lookup first free position
\r
883 for (i = 0; (priMemExtDataBuffer[i].eventId != DEM_EVENT_ID_NULL) && (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM); i++);
\r
884 if (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) {
\r
885 memcpy(&priMemExtDataBuffer[i], extendedData, sizeof(ExtDataRecType));
\r
888 // Error: Pri mem extended data buffer full
\r
889 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
890 Det_ReportError(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRI_MEM_ID, DEM_E_PRI_MEM_EXT_DATA_BUFF_FULL); /** @req DEM117 */
\r
895 McuE_ExitCriticalSection(state);
\r
900 * Procedure: deleteExtendedDataPriMem
\r
901 * Description: Delete the extended data of "eventParam->eventId" from "priMemExtDataBuffer".
\r
903 static void deleteExtendedDataPriMem(const Dem_EventParameterType *eventParam)
\r
906 imask_t state = McuE_EnterCriticalSection();
\r
908 // Check if already stored
\r
909 for (i = 0; (priMemExtDataBuffer[i].eventId != eventParam->EventID) && (i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM); i++);
\r
911 if (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) {
\r
912 // Yes, clear record
\r
913 memset(&priMemExtDataBuffer[i], 0, sizeof(ExtDataRecType));
\r
916 McuE_ExitCriticalSection(state);
\r
921 * Procedure: storeExtendedDataEvtMem
\r
922 * Description: Store the extended data in event memory according to
\r
923 * "eventParam" destination option
\r
925 static void storeExtendedDataEvtMem(const Dem_EventParameterType *eventParam, ExtDataRecType *extendedData)
\r
929 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != NULL); i++) {
\r
930 switch (eventParam->EventClass->EventDestination[i])
\r
932 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
933 storeExtendedDataPriMem(eventParam, extendedData);
\r
936 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
937 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
938 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
939 // Not yet supported
\r
940 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
941 Det_ReportError(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
953 * Procedure: lookupExtendedDataRecNumParam
\r
954 * Description: Returns TRUE if the requested extended data number was found among the configured records for the event.
\r
955 * "extDataRecClassPtr" returns a pointer to the record class, "posInExtData" returns the position in stored extended data.
\r
957 static boolean lookupExtendedDataRecNumParam(uint8 extendedDataNumber, const Dem_EventParameterType *eventParam, Dem_ExtendedDataRecordClassType const **extDataRecClassPtr, uint8 *posInExtData)
\r
959 boolean recNumFound = FALSE;
\r
961 if (eventParam->ExtendedDataClassRef != NULL) {
\r
962 Dem_ExtendedDataRecordClassType const* const* extDataRecClassRefList = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef;
\r
963 uint16 byteCnt = 0;
\r
966 // Request extended data and copy it to the buffer
\r
967 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (extDataRecClassRefList[i] != NULL) && !recNumFound; i++) {
\r
968 if (extDataRecClassRefList[i]->RecordNumber == extendedDataNumber) {
\r
969 *extDataRecClassPtr = extDataRecClassRefList[i];
\r
970 *posInExtData = byteCnt;
\r
971 recNumFound = TRUE;
\r
973 byteCnt += extDataRecClassRefList[i]->DataSize;
\r
977 return recNumFound;
\r
982 * Procedure: lookupExtendedDataPriMem
\r
983 * Description: Returns TRUE if the requested event id is found, "extData" points to the found data.
\r
985 static boolean lookupExtendedDataPriMem(Dem_EventIdType eventId, ExtDataRecType **extData)
\r
987 boolean eventIdFound = FALSE;
\r
990 // Lookup corresponding extended data
\r
991 for (i = 0; (priMemExtDataBuffer[i].eventId != eventId) && (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM); i++);
\r
993 if (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) {
\r
994 // Yes, return pointer
\r
995 *extData = &priMemExtDataBuffer[i];
\r
996 eventIdFound = TRUE;
\r
999 return eventIdFound;
\r
1003 static void storeFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
1009 static void deleteFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam)
\r
1016 * Procedure: storeFreezeFrameDataEvtMem
\r
1017 * Description: Store the freeze frame data in event memory according to
\r
1018 * "eventParam" destination option
\r
1020 static void storeFreezeFrameDataEvtMem(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
1024 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != NULL); i++) {
\r
1025 switch (eventParam->EventClass->EventDestination[i])
\r
1027 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1028 storeFreezeFrameDataPriMem(eventParam, freezeFrame);
\r
1031 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1032 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1033 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1034 // Not yet supported
\r
1035 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1036 Det_ReportError(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
1047 * Procedure: handlePreInitEvent
\r
1048 * Description: Handle the updating of event status and storing of
\r
1049 * event related data in preInit buffers.
\r
1051 static void handlePreInitEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1053 const Dem_EventParameterType *eventParam;
\r
1054 EventStatusRecType eventStatusLocal;
\r
1055 FreezeFrameRecType freezeFrameLocal;
\r
1056 ExtDataRecType extendedDataLocal;
\r
1058 // Find configuration for this event
\r
1059 lookupEventIdParameter(eventId, &eventParam);
\r
1060 if (eventParam != NULL) {
\r
1061 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1062 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1063 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
1064 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1067 updateEventStatusRec(eventParam, eventStatus, FALSE, &eventStatusLocal);
\r
1070 if (eventStatusLocal.errorStatusChanged) {
\r
1072 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1073 // Collect freeze frame data
\r
1074 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1075 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1076 storeFreezeFrameDataPreInit(eventParam, &freezeFrameLocal);
\r
1079 // Collect extended data
\r
1080 getExtendedData(eventParam, &extendedDataLocal);
\r
1081 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1082 storeExtendedDataPreInit(eventParam, &extendedDataLocal);
\r
1088 // Operation cycle not started
\r
1089 // TODO: Report error?
\r
1093 // Operation cycle not set
\r
1094 // TODO: Report error?
\r
1098 // Event ID not configured
\r
1099 // TODO: Report error?
\r
1105 * Procedure: handleEvent
\r
1106 * Description: Handle the updating of event status and storing of
\r
1107 * event related data in event memory.
\r
1109 static Std_ReturnType handleEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1111 Std_ReturnType returnCode = E_OK;
\r
1112 const Dem_EventParameterType *eventParam;
\r
1113 EventStatusRecType eventStatusLocal;
\r
1114 FreezeFrameRecType freezeFrameLocal;
\r
1115 ExtDataRecType extendedDataLocal;
\r
1117 // Find configuration for this event
\r
1118 lookupEventIdParameter(eventId, &eventParam);
\r
1119 if (eventParam != NULL) {
\r
1120 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1121 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1122 if (!(disableDtcStorage.storageDisabled && checkDtcGroup(disableDtcStorage.dtcGroup, eventParam) && checkDtcKind(disableDtcStorage.dtcKind, eventParam))) {
\r
1123 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1124 if (eventStatusLocal.errorStatusChanged) {
\r
1125 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1126 storeEventEvtMem(eventParam, &eventStatusLocal); /** @req DEM184 */
\r
1127 // Collect freeze frame data
\r
1128 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1129 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1130 storeFreezeFrameDataEvtMem(eventParam, &freezeFrameLocal); /** @req DEM190 */
\r
1133 // Collect extended data
\r
1134 getExtendedData(eventParam, &extendedDataLocal);
\r
1135 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL)
\r
1137 storeExtendedDataEvtMem(eventParam, &extendedDataLocal);
\r
1144 // Operation cycle not started
\r
1145 returnCode = E_NOT_OK;
\r
1149 // Operation cycle not set
\r
1150 returnCode = E_NOT_OK;
\r
1154 // Event ID not configured
\r
1155 returnCode = E_NOT_OK;
\r
1158 return returnCode;
\r
1163 * Procedure: resetEventStatus
\r
1164 * Description: Resets the events status of eventId.
\r
1166 static void resetEventStatus(Dem_EventIdType eventId)
\r
1168 imask_t state = McuE_EnterCriticalSection();
\r
1169 EventStatusRecType *eventStatusRecPtr;
\r
1171 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
1172 if (eventStatusRecPtr != NULL) {
\r
1173 eventStatusRecPtr->eventStatusExtended &= ~DEM_TEST_FAILED; /** @req DEM187 */
\r
1176 McuE_ExitCriticalSection(state);
\r
1181 * Procedure: getEventStatus
\r
1182 * Description: Returns the extended event status bitmask of eventId in "eventStatusExtended".
\r
1184 static void getEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended)
\r
1186 EventStatusRecType eventStatusLocal;
\r
1188 // Get recorded status
\r
1189 getEventStatusRec(eventId, &eventStatusLocal);
\r
1190 if (eventStatusLocal.eventId == eventId) {
\r
1191 *eventStatusExtended = eventStatusLocal.eventStatusExtended; /** @req DEM051 */
\r
1194 // Event Id not found, no report received.
\r
1195 *eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1201 * Procedure: getEventFailed
\r
1202 * Description: Returns the TRUE or FALSE of "eventId" in "eventFailed" depending on current status.
\r
1204 static void getEventFailed(Dem_EventIdType eventId, boolean *eventFailed)
\r
1206 EventStatusRecType eventStatusLocal;
\r
1208 // Get recorded status
\r
1209 getEventStatusRec(eventId, &eventStatusLocal);
\r
1210 if (eventStatusLocal.eventId == eventId) {
\r
1211 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) { /** @req DEM052 */
\r
1212 *eventFailed = TRUE;
\r
1215 *eventFailed = FALSE;
\r
1219 // Event Id not found, assume ok.
\r
1220 *eventFailed = FALSE;
\r
1226 * Procedure: getEventTested
\r
1227 * Description: Returns the TRUE or FALSE of "eventId" in "eventTested" depending on
\r
1228 * current status the "test not completed this operation cycle" bit.
\r
1230 static void getEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1232 EventStatusRecType eventStatusLocal;
\r
1234 // Get recorded status
\r
1235 getEventStatusRec(eventId, &eventStatusLocal);
\r
1236 if (eventStatusLocal.eventId == eventId) {
\r
1237 if ( !(eventStatusLocal.eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE)) { /** @req DEM053 */
\r
1238 *eventTested = TRUE;
\r
1241 *eventTested = FALSE;
\r
1245 // Event Id not found, not tested.
\r
1246 *eventTested = FALSE;
\r
1252 * Procedure: getFaultDetectionCounter
\r
1253 * Description: Returns pre debounce counter of "eventId" in "counter" and return value E_OK if
\r
1254 * the counter was available else E_NOT_OK.
\r
1256 static Std_ReturnType getFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1258 Std_ReturnType returnCode = E_NOT_OK;
\r
1259 const Dem_EventParameterType *eventParam;
\r
1261 lookupEventIdParameter(eventId, &eventParam);
\r
1262 if (eventParam != NULL) {
\r
1263 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
1264 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName)
\r
1266 case DEM_NO_PRE_DEBOUNCE:
\r
1267 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal != NULL) {
\r
1268 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc != NULL) {
\r
1269 returnCode = eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc(counter); /** @req DEM204.None */ /** @req DEM264 */ /** @req DEM265 */
\r
1274 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
1276 EventStatusRecType *eventStatusRec;
\r
1278 lookupEventStatusRec(eventId, &eventStatusRec);
\r
1279 if (eventStatusRec != NULL) {
\r
1280 *counter = eventStatusRec->faultDetectionCounter; /** @req DEM204.Counter */
\r
1284 returnCode = E_OK;
\r
1288 case DEM_PRE_DEBOUNCE_FREQUENCY_BASED:
\r
1289 case DEM_PRE_DEBOUNCE_TIME_BASED:
\r
1290 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1291 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
1296 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1297 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_PARAM_DATA); /** @req DEM117 */
\r
1304 return returnCode;
\r
1309 * Procedure: setOperationCycleState
\r
1310 * Description: Change the operation state of "operationCycleId" to "cycleState" and updates stored
\r
1311 * event connected to this cycle id.
\r
1312 * Returns E_OK if operation was successful else E_NOT_OK.
\r
1314 static Std_ReturnType setOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState) /** @req DEM338 */
\r
1317 Std_ReturnType returnCode = E_OK;
\r
1319 if (operationCycleId < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1320 switch (cycleState)
\r
1322 case DEM_CYCLE_STATE_START:
\r
1323 operationCycleStateList[operationCycleId] = cycleState;
\r
1324 // Lookup event ID
\r
1325 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1326 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1327 eventStatusBuffer[i].eventStatusExtended &= ~DEM_TEST_FAILED_THIS_OPERATION_CYCLE;
\r
1328 eventStatusBuffer[i].eventStatusExtended |= DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
1333 case DEM_CYCLE_STATE_END:
\r
1334 operationCycleStateList[operationCycleId] = cycleState;
\r
1335 // Lookup event ID
\r
1336 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1337 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1338 if (!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_FAILED_THIS_OPERATION_CYCLE) && !(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE)) {
\r
1339 eventStatusBuffer[i].eventStatusExtended &= ~DEM_PENDING_DTC; // Clear pendingDTC bit /** @req DEM379.PendingClear
\r
1345 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1346 Det_ReportError(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA); /** @req DEM117 */
\r
1348 returnCode = E_NOT_OK;
\r
1353 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1354 Det_ReportError(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA); /** @req DEM117 */
\r
1356 returnCode = E_NOT_OK;
\r
1359 return returnCode;
\r
1363 //==============================================================================//
\r
1365 // E X T E R N A L F U N C T I O N S //
\r
1367 //==============================================================================//
\r
1369 /*********************************************
\r
1370 * Interface for upper layer modules (8.3.1) *
\r
1371 *********************************************/
\r
1374 * Procedure: Dem_GetVersionInfo
\r
1377 // Defined in Dem.h
\r
1380 /***********************************************
\r
1381 * Interface ECU State Manager <-> DEM (8.3.2) *
\r
1382 ***********************************************/
\r
1385 * Procedure: Dem_PreInit
\r
1388 void Dem_PreInit(void)
\r
1390 /** @req DEM180 */
\r
1393 if (DEM_Config.ConfigSet == NULL) {
\r
1394 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1395 Det_ReportError(MODULE_ID_DEM, 0, DEM_PREINIT_ID, DEM_E_CONFIG_PTR_INVALID); /** @req DEM117 */
\r
1399 configSet = DEM_Config.ConfigSet;
\r
1402 // Initializion of operation cycle states.
\r
1403 for (i = 0; i < DEM_OPERATION_CYCLE_ID_ENDMARK; i++) {
\r
1404 operationCycleStateList[i] = DEM_CYCLE_STATE_END;
\r
1407 // Initialize the event status buffer
\r
1408 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1409 eventStatusBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1410 eventStatusBuffer[i].eventParamRef = NULL;
\r
1411 eventStatusBuffer[i].faultDetectionCounter = 0;
\r
1412 eventStatusBuffer[i].occurrence = 0;
\r
1413 eventStatusBuffer[i].eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1414 eventStatusBuffer[i].errorStatusChanged = FALSE;
\r
1417 // Initialize the pre init buffers
\r
1418 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1419 preInitFreezeFrameBuffer[i].checksum = 0;
\r
1420 preInitFreezeFrameBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1421 preInitFreezeFrameBuffer[i].occurrence = 0;
\r
1422 preInitFreezeFrameBuffer[i].dataSize = 0;
\r
1423 for (j = 0; j < DEM_MAX_SIZE_FF_DATA;j++)
\r
1424 preInitFreezeFrameBuffer[i].data[j] = 0;
\r
1427 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1428 preInitExtDataBuffer[i].checksum = 0;
\r
1429 preInitExtDataBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1430 preInitExtDataBuffer[i].dataSize = 0;
\r
1431 for (j = 0; j < DEM_MAX_SIZE_EXT_DATA;j++)
\r
1432 preInitExtDataBuffer[i].data[j] = 0;
\r
1435 disableDtcStorage.storageDisabled = FALSE;
\r
1437 setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_START); /** @req DEM047 */
\r
1439 demState = DEM_PREINITIALIZED;
\r
1444 * Procedure: Dem_Init
\r
1447 void Dem_Init(void)
\r
1450 ChecksumType cSum;
\r
1451 const Dem_EventParameterType *eventParam;
\r
1454 * Validate and read out saved error log from non volatile memory
\r
1457 // Validate event records stored in primary memory
\r
1458 for (i = 0; i < DEM_MAX_NUMBER_EVENT_PRI_MEM; i++) {
\r
1459 cSum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
1460 if ((cSum != priMemEventBuffer[i].checksum) || priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL) {
\r
1461 // Unlegal record, clear the record
\r
1462 memset(&priMemEventBuffer[i], 0, sizeof(EventRecType));
\r
1465 // Valid, update current status
\r
1466 mergeEventStatusRec(&priMemEventBuffer[i]);
\r
1468 // Update occurrence counter on pre init stored freeze frames
\r
1469 updateFreezeFrameOccurrencePreInit(&priMemEventBuffer[i]);
\r
1473 // Validate extended data records stored in primary memory
\r
1474 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM; i++) {
\r
1475 cSum = calcChecksum(&priMemExtDataBuffer[i], sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
1476 if ((cSum != priMemExtDataBuffer[i].checksum) || priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL) {
\r
1477 // Unlegal record, clear the record
\r
1478 memset(&priMemExtDataBuffer[i], 0, sizeof(ExtDataRecType));
\r
1482 // Validate freeze frame records stored in primary memory
\r
1483 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++) {
\r
1484 cSum = calcChecksum(&priMemFreezeFrameBuffer[i], sizeof(FreezeFrameRecType)-sizeof(ChecksumType));
\r
1485 if ((cSum != priMemFreezeFrameBuffer[i].checksum) || (priMemFreezeFrameBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1486 // Unlegal record, clear the record
\r
1487 memset(&priMemFreezeFrameBuffer[i], 0, sizeof(FreezeFrameRecType));
\r
1492 * Handle errors stored in temporary buffer (if any)
\r
1495 // Transfer updated event data to event memory
\r
1496 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1497 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1498 // Update the event memory
\r
1499 lookupEventIdParameter(eventStatusBuffer[i].eventId, &eventParam);
\r
1500 storeEventEvtMem(eventParam, &eventStatusBuffer[i]);
\r
1504 // Transfer extended data to event memory if necessary
\r
1505 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1506 if (preInitExtDataBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1507 lookupEventIdParameter(preInitExtDataBuffer[i].eventId, &eventParam);
\r
1508 storeExtendedDataEvtMem(eventParam, &preInitExtDataBuffer[i]);
\r
1512 // Transfer freeze frames to event memory
\r
1513 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1514 if (preInitFreezeFrameBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1515 lookupEventIdParameter(preInitFreezeFrameBuffer[i].eventId, &eventParam);
\r
1516 storeFreezeFrameDataEvtMem(eventParam, &preInitFreezeFrameBuffer[i]);
\r
1520 // Init the dtc filter
\r
1521 dtcFilter.dtcStatusMask = DEM_DTC_STATUS_MASK_ALL; // All allowed
\r
1522 dtcFilter.dtcKind = DEM_DTC_KIND_ALL_DTCS; // All kinds of DTCs
\r
1523 dtcFilter.dtcOrigin = DEM_DTC_ORIGIN_PRIMARY_MEMORY; // Primary memory
\r
1524 dtcFilter.filterWithSeverity = DEM_FILTER_WITH_SEVERITY_NO; // No Severity filtering
\r
1525 dtcFilter.dtcSeverityMask = DEM_SEVERITY_NO_SEVERITY; // Not used when filterWithSeverity is FALSE
\r
1526 dtcFilter.filterForFaultDetectionCounter = DEM_FILTER_FOR_FDC_NO; // No fault detection counter filtering
\r
1528 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1530 disableDtcStorage.storageDisabled = FALSE;
\r
1532 demState = DEM_INITIALIZED;
\r
1537 * Procedure: Dem_shutdown
\r
1540 void Dem_Shutdown(void)
\r
1542 setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_END); /** @req DEM047 */
\r
1544 demState = DEM_UNINITIALIZED; /** @req DEM368 */
\r
1549 * Interface for basic software scheduler
\r
1551 void Dem_MainFunction(void)
\r
1553 /** @req DEM125 */
\r
1558 /***************************************************
\r
1559 * Interface SW-Components via RTE <-> DEM (8.3.3) *
\r
1560 ***************************************************/
\r
1563 * Procedure: Dem_SetEventStatus
\r
1566 Std_ReturnType Dem_SetEventStatus(Dem_EventIdType eventId, Dem_EventStatusType eventStatus) /** @req DEM330 */
\r
1568 Std_ReturnType returnCode = E_OK;
\r
1570 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1572 returnCode = handleEvent(eventId, eventStatus);
\r
1576 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1577 Det_ReportError(MODULE_ID_DEM, 0, DEM_SETEVENTSTATUS_ID, DEM_E_UNINIT); /** @req DEM124.SetEventStatus */ /** @req DEM117 */
\r
1579 returnCode = E_NOT_OK; /** @req DEM370.SetEventStatus */
\r
1582 return returnCode;
\r
1587 * Procedure: Dem_ResetEventStatus
\r
1590 Std_ReturnType Dem_ResetEventStatus(Dem_EventIdType eventId) /** @req DEM331 */
\r
1592 Std_ReturnType returnCode = E_OK;
\r
1594 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1596 resetEventStatus(eventId); /** @req DEM186 */
\r
1600 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1601 Det_ReportError(MODULE_ID_DEM, 0, DEM_RESETEVENTSTATUS_ID, DEM_E_UNINIT); /** @req DEM124.ResetEventStatus */ /** @req DEM117 */
\r
1603 returnCode = E_NOT_OK; /** @req DEM370.ResetEventStatus */
\r
1606 return returnCode;
\r
1611 * Procedure: Dem_GetEventStatus
\r
1614 Std_ReturnType Dem_GetEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended) /** @req DEM332 */
\r
1616 Std_ReturnType returnCode = E_OK;
\r
1618 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1620 getEventStatus(eventId, eventStatusExtended);
\r
1624 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1625 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETEVENTSTATUS_ID, DEM_E_UNINIT); /** @req DEM124.GetEventStatus */ /** @req DEM117 */
\r
1627 returnCode = E_NOT_OK; /** @req DEM370.GetEventStatus */
\r
1630 return returnCode;
\r
1635 * Procedure: Dem_GetEventFailed
\r
1638 Std_ReturnType Dem_GetEventFailed(Dem_EventIdType eventId, boolean *eventFailed) /** @req DEM333 */
\r
1640 Std_ReturnType returnCode = E_OK;
\r
1642 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1644 getEventFailed(eventId, eventFailed);
\r
1648 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1649 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETEVENTFAILED_ID, DEM_E_UNINIT); /** @req DEM124.GetEventFailed */ /** @req DEM117 */
\r
1651 returnCode = E_NOT_OK; /** @req DEM370.GetEventFailed */
\r
1654 return returnCode;
\r
1659 * Procedure: Dem_GetEventTested
\r
1662 Std_ReturnType Dem_GetEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1664 Std_ReturnType returnCode = E_OK;
\r
1666 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1668 getEventTested(eventId, eventTested);
\r
1672 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1673 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETEVENTTESTED_ID, DEM_E_UNINIT); /** @req DEM124.GetEventTested */ /** @req DEM117 */
\r
1675 returnCode = E_NOT_OK; /** @req DEM370.GetEventTested */
\r
1678 return returnCode;
\r
1683 * Procedure: Dem_GetFaultDetectionCounter
\r
1686 Std_ReturnType Dem_GetFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1688 Std_ReturnType returnCode = E_OK;
\r
1690 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1692 returnCode = getFaultDetectionCounter(eventId, counter);
\r
1696 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1697 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_UNINIT); /** @req DEM124.GetFaultDetectionCounter */ /** @req DEM117 */
\r
1699 returnCode = E_NOT_OK; /** @req DEM370.GetFaultDetectionCounter */
\r
1702 return returnCode;
\r
1707 * Procedure: Dem_SetOperationCycleState
\r
1710 Std_ReturnType Dem_SetOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState)
\r
1712 Std_ReturnType returnCode = E_OK;
\r
1714 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1716 returnCode = setOperationCycleState(operationCycleId, cycleState);
\r
1721 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1722 Det_ReportError(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_UNINIT); /** @req DEM124.SetOperationCycleState */ /** @req DEM117 */
\r
1724 returnCode = E_NOT_OK; /** @req DEM370.SetOperationCycleState */
\r
1727 return returnCode;
\r
1732 * Procedure: Dem_GetDTCOfEvent
\r
1735 Std_ReturnType Dem_GetDTCOfEvent(Dem_EventIdType eventId, Dem_DTCKindType dtcKind, uint32* dtcOfEvent)
\r
1737 Std_ReturnType returnCode = E_NO_DTC_AVAILABLE;
\r
1738 const Dem_EventParameterType *eventParam;
\r
1740 lookupEventIdParameter(eventId, &eventParam);
\r
1742 if (eventParam != NULL) {
\r
1743 if (checkDtcKind(dtcKind, eventParam)) {
\r
1744 if (eventParam->DTCClassRef != NULL) {
\r
1745 *dtcOfEvent = eventParam->DTCClassRef->DTC; /** @req DEM269 */
\r
1746 returnCode = E_OK;
\r
1751 // Event Id not found
\r
1752 returnCode = E_NOT_OK;
\r
1755 return returnCode;
\r
1759 /********************************************
\r
1760 * Interface BSW-Components <-> DEM (8.3.4) *
\r
1761 ********************************************/
\r
1764 * Procedure: Dem_ReportErrorStatus
\r
1767 void Dem_ReportErrorStatus( Dem_EventIdType eventId, Dem_EventStatusType eventStatus ) /** @req DEM107 */
\r
1770 switch (demState) {
\r
1771 case DEM_PREINITIALIZED:
\r
1772 // Update status and check if is to be stored
\r
1773 if ((eventStatus == DEM_EVENT_STATUS_PASSED) || (eventStatus == DEM_EVENT_STATUS_FAILED)) {
\r
1774 handlePreInitEvent(eventId, eventStatus); /** @req DEM168 */
\r
1778 case DEM_INITIALIZED:
\r
1779 (void)handleEvent(eventId, eventStatus); /** @req DEM167 */
\r
1782 case DEM_UNINITIALIZED:
\r
1784 // Uninitialized can not do anything
\r
1785 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
1786 Det_ReportError(MODULE_ID_DEM, 0, DEM_REPORTERRORSTATUS_ID, DEM_E_UNINIT); /** @req DEM124.ReportErrorStatus */ /** @req DEM364 */ /** @req DEM117 */
\r
1790 } // switch (demState)
\r
1793 /*********************************
\r
1794 * Interface DCM <-> DEM (8.3.5) *
\r
1795 *********************************/
\r
1797 * Procedure: Dem_GetDTCStatusAvailabilityMask
\r
1800 Std_ReturnType Dem_GetDTCStatusAvailabilityMask(uint8 *dtcStatusMask) /** @req DEM014 */
\r
1802 *dtcStatusMask = DEM_DTC_STATUS_AVAILABILITY_MASK; // User configuration mask
\r
1803 *dtcStatusMask &= DEM_TEST_FAILED // Mask with supported bits /** @req DEM060 */
\r
1804 | DEM_TEST_FAILED_THIS_OPERATION_CYCLE
\r
1806 // | DEM_CONFIRMED_DTC TODO: Add support for this bit
\r
1807 | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR
\r
1808 | DEM_TEST_FAILED_SINCE_LAST_CLEAR
\r
1809 | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE
\r
1810 // | DEM_WARNING_INDICATOR_REQUESTED TODO: Add support for this bit
\r
1818 * Procedure: Dem_SetDTCFilter
\r
1821 Dem_ReturnSetDTCFilterType Dem_SetDTCFilter(uint8 dtcStatusMask,
\r
1822 Dem_DTCKindType dtcKind,
\r
1823 Dem_DTCOriginType dtcOrigin,
\r
1824 Dem_FilterWithSeverityType filterWithSeverity,
\r
1825 Dem_DTCSeverityType dtcSeverityMask,
\r
1826 Dem_FilterForFDCType filterForFaultDetectionCounter) {
\r
1828 Dem_ReturnSetDTCFilterType returnCode = DEM_WRONG_FILTER;
\r
1830 // Check dtcKind parameter
\r
1831 if ((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS)) {
\r
1833 // Check dtcOrigin parameter
\r
1834 if ((dtcOrigin == DEM_DTC_ORIGIN_SECONDARY_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_PRIMARY_MEMORY)
\r
1835 || (dtcOrigin == DEM_DTC_ORIGIN_PERMANENT_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_MIRROR_MEMORY)) {
\r
1837 // Check filterWithSeverity and dtcSeverityMask parameter
\r
1838 if ((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
1839 || ((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES) && !(dtcSeverityMask & ~(DEM_SEVERITY_MAINTENANCE_ONLY | DEM_SEVERITY_CHECK_AT_NEXT_FALT | DEM_SEVERITY_CHECK_IMMEDIATELY)))){
\r
1841 // Check filterForFaultDetectionCounter parameter
\r
1842 if ((filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_YES) || (filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO)) {
\r
1843 // Yes all parameters correct, set the new filters. /** @req DEM057 */
\r
1844 dtcFilter.dtcStatusMask = dtcStatusMask;
\r
1845 dtcFilter.dtcKind = dtcKind;
\r
1846 dtcFilter.dtcOrigin = dtcOrigin;
\r
1847 dtcFilter.filterWithSeverity = filterWithSeverity;
\r
1848 dtcFilter.dtcSeverityMask = dtcSeverityMask;
\r
1849 dtcFilter.filterForFaultDetectionCounter = filterForFaultDetectionCounter;
\r
1850 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1851 returnCode = DEM_FILTER_ACCEPTED;
\r
1857 return returnCode;
\r
1862 * Procedure: Dem_GetStatusOfDTC
\r
1865 Dem_ReturnGetStatusOfDTCType Dem_GetStatusOfDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, Dem_EventStatusExtendedType* status) {
\r
1866 Dem_ReturnGetStatusOfDTCType returnCode = DEM_STATUS_FAILED;
\r
1867 EventStatusRecType *eventRec;
\r
1869 if (lookupDtcEvent(dtc, &eventRec)) {
\r
1870 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
1871 if (checkDtcOrigin(dtcOrigin,eventRec->eventParamRef)) {
\r
1872 *status = eventRec->eventStatusExtended; /** @req DEM059 */
\r
1873 returnCode = DEM_STATUS_OK;
\r
1876 returnCode = DEM_STATUS_WRONG_DTCORIGIN; /** @req DEM171 */
\r
1880 returnCode = DEM_STATUS_WRONG_DTCKIND;
\r
1884 returnCode = DEM_STATUS_WRONG_DTC; /** @req DEM172 */
\r
1887 return returnCode;
\r
1892 * Procedure: Dem_GetNumberOfFilteredDtc
\r
1895 Dem_ReturnGetNumberOfFilteredDTCType Dem_GetNumberOfFilteredDtc(uint16 *numberOfFilteredDTC) {
\r
1897 uint16 numberOfFaults = 0;
\r
1899 //Dem_DisableEventStatusUpdate();
\r
1901 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1902 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1903 if (matchEventWithDtcFilter(&eventStatusBuffer[i])) {
\r
1904 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
1911 //Dem_EnableEventStatusUpdate();
\r
1913 *numberOfFilteredDTC = numberOfFaults; /** @req DEM061 */
\r
1915 return DEM_NUMBER_OK;
\r
1920 * Procedure: Dem_GetNextFilteredDTC
\r
1923 Dem_ReturnGetNextFilteredDTCType Dem_GetNextFilteredDTC(uint32 *dtc, Dem_EventStatusExtendedType *dtcStatus)
\r
1925 Dem_ReturnGetNextFilteredDTCType returnCode = DEM_FILTERED_OK;
\r
1926 boolean dtcFound = FALSE;
\r
1928 /** @req DEM217.Partially */ // TODO: This job should be done in an more advanced way according to Dem217
\r
1929 while (!dtcFound && (dtcFilter.faultIndex != 0)) {
\r
1930 dtcFilter.faultIndex--;
\r
1931 if (eventStatusBuffer[dtcFilter.faultIndex].eventId != DEM_EVENT_ID_NULL) {
\r
1932 if (matchEventWithDtcFilter(&eventStatusBuffer[dtcFilter.faultIndex])) {
\r
1933 if (eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef != NULL) {
\r
1934 *dtc = eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef->DTC; /** @req DEM216 */
\r
1935 *dtcStatus = eventStatusBuffer[dtcFilter.faultIndex].eventStatusExtended;
\r
1943 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1944 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
1947 return returnCode;
\r
1952 * Procedure: Dem_GetTranslationType
\r
1955 Dem_ReturnTypeOfDtcSupportedType Dem_GetTranslationType(void)
\r
1957 return DEM_TYPE_OF_DTC_SUPPORTED; /** @req DEM231 */
\r
1962 * Procedure: Dem_ClearDTC
\r
1965 Dem_ReturnClearDTCType Dem_ClearDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin) /** @req DEM009 */
\r
1967 Dem_ReturnClearDTCType returnCode = DEM_CLEAR_OK;
\r
1968 Dem_EventIdType eventId;
\r
1969 const Dem_EventParameterType *eventParam;
\r
1972 // Loop through the event buffer
\r
1973 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1974 eventId = eventStatusBuffer[i].eventId;
\r
1975 if (eventId != DEM_EVENT_ID_NULL) {
\r
1976 eventParam = eventStatusBuffer[i].eventParamRef;
\r
1977 if (eventParam != NULL) {
\r
1978 if (DEM_CLEAR_ALL_EVENTS | (eventParam->DTCClassRef != NULL)) {
\r
1979 if (checkDtcKind(dtcKind, eventParam)) {
\r
1980 if (checkDtcGroup(dtc, eventParam)) {
\r
1981 for (j = 0; (j < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[j] != dtcOrigin); j++);
\r
1982 if (j < DEM_MAX_NR_OF_EVENT_DESTINATION) {
\r
1983 // Yes! All conditions met.
\r
1984 switch (dtcOrigin)
\r
1986 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1987 /** @req DEM077 */
\r
1988 deleteEventPriMem(eventParam);
\r
1989 deleteFreezeFrameDataPriMem(eventParam);
\r
1990 deleteExtendedDataPriMem(eventParam);
\r
1991 deleteEventStatusRec(eventParam); // TODO: Shall this be done or just resetting the status?
\r
1994 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1995 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1996 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1997 // Not yet supported
\r
1998 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
1999 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
2000 Det_ReportError(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
2004 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2013 // Fatal error, no event parameters found for the stored event!
\r
2014 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
2015 Det_ReportError(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNEXPECTED_EXECUTION); /** @req DEM117 */
\r
2021 return returnCode;
\r
2026 * Procedure: Dem_DisableDTCStorage
\r
2029 Dem_ReturnControlDTCStorageType Dem_DisableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind) /** @req DEM035 */
\r
2031 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2033 // Check dtcGroup parameter
\r
2034 if (dtcGroup == DEM_DTC_GROUP_ALL_DTCS) {
\r
2035 // Check dtcKind parameter
\r
2036 if ((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS)) {
\r
2037 /** @req DEM079 */
\r
2038 disableDtcStorage.dtcGroup = dtcGroup;
\r
2039 disableDtcStorage.dtcKind = dtcKind;
\r
2040 disableDtcStorage.storageDisabled = TRUE;
\r
2042 returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2046 returnCode = DEM_CONTROL_DTC_WRONG_DTCGROUP;
\r
2049 return returnCode;
\r
2054 * Procedure: Dem_EnableDTCStorage
\r
2057 Dem_ReturnControlDTCStorageType Dem_EnableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind)
\r
2059 // TODO: Behavior is not defined if group or kind do not match active settings, therefore the filter is just switched off.
\r
2060 disableDtcStorage.storageDisabled = FALSE; /** @req DEM080 */
\r
2062 return DEM_CONTROL_DTC_STORAGE_OK;
\r
2066 * Procedure: Dem_GetExtendedDataRecordByDTC
\r
2069 Dem_ReturnGetExtendedDataRecordByDTCType Dem_GetExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint8 *destBuffer, uint8 *bufSize)
\r
2071 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_RECORD_WRONG_DTC;
\r
2072 EventStatusRecType *eventRec;
\r
2073 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2074 ExtDataRecType *extData;
\r
2075 uint8 posInExtData = 0;
\r
2077 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2078 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2079 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2080 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2081 if (*bufSize >= extendedDataRecordClass->DataSize) {
\r
2082 switch (dtcOrigin)
\r
2084 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2085 if (lookupExtendedDataPriMem(eventRec->eventId, &extData)) {
\r
2086 // Yes all conditions met, copy the extended data record to destination buffer.
\r
2087 memcpy(destBuffer, &extData->data[posInExtData], extendedDataRecordClass->DataSize); /** @req DEM075 */
\r
2088 *bufSize = extendedDataRecordClass->DataSize;
\r
2089 returnCode = DEM_RECORD_OK;
\r
2092 // The record number is legal but no record was found for the DTC
\r
2094 returnCode = DEM_RECORD_OK;
\r
2098 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2099 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2100 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2101 // Not yet supported
\r
2102 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2103 #if (DEM_DEV_ERROR_DETECT == STD_ON)
\r
2104 Det_ReportError(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_NOT_IMPLEMENTED_YET); /** @req DEM117 */
\r
2108 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2113 returnCode = DEM_RECORD_BUFFERSIZE;
\r
2117 returnCode = DEM_RECORD_NUMBER;
\r
2121 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2125 returnCode = DEM_RECORD_DTCKIND;
\r
2129 return returnCode;
\r
2134 * Procedure: Dem_GetSizeOfExtendedDataRecordByDTC
\r
2137 Dem_ReturnGetSizeOfExtendedDataRecordByDTCType Dem_GetSizeOfExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint16 *sizeOfExtendedDataRecord)
\r
2139 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2140 EventStatusRecType *eventRec;
\r
2141 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2142 uint8 posInExtData;
\r
2144 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2145 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2146 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2147 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2148 *sizeOfExtendedDataRecord = extendedDataRecordClass->DataSize; /** @req DEM076 */
\r
2149 returnCode = DEM_GET_SIZEOFEDRBYDTC_OK;
\r
2152 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_RNUM;
\r
2156 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCOR;
\r
2160 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCKI;
\r
2164 return returnCode;
\r
2167 /***********************************
\r
2168 * OBD-specific Interfaces (8.3.6) *
\r
2169 ***********************************/
\r