1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\r
6 * This source code is free software; you can redistribute it and/or modify it
\r
7 * under the terms of the GNU General Public License version 2 as published by the
\r
8 * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
\r
10 * This program is distributed in the hope that it will be useful, but
\r
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\r
14 * -------------------------------- Arctic Core ------------------------------*/
\r
16 // 904 PC-Lint MISRA 14.7: OK. Allow VALIDATE, VALIDATE_RV and VALIDATE_NO_RV to return value.
\r
17 //lint -emacro(904,VALIDATE_RV,VALIDATE_NO_RV,VALIDATE)
\r
18 // 522 PC-Lint exception for empty functions
\r
19 //lint -esym(522,storeFreezeFrameDataEvtMem)
\r
20 //lint -esym(522,deleteFreezeFrameDataPriMem)
\r
21 //lint -esym(522,storeFreezeFrameDataPreInit)
\r
22 //lint -esym(522,storeFreezeFrameDataPriMem)
\r
23 //lint -esym(522,updateFreezeFrameOccurrencePreInit)
\r
29 * General requirements
\r
32 /** @req DEM151.partially */
\r
34 /** @req DEM013.14229-1 */
\r
37 /** @req DEM113 */ /** @req DEM174 */
\r
51 //#include "SchM_Dem.h"
\r
53 #include "McuExtensions.h"
\r
58 #define DEBOUNCE_FDC_TEST_FAILED 127
\r
59 #define DEBOUNCE_FDC_TEST_PASSED -128
\r
61 #if ( DEM_DEV_ERROR_DETECT == STD_ON )
\r
64 #define VALIDATE_RV(_exp,_api,_err,_rv ) \
\r
66 Det_ReportError(MODULE_ID_DEM, 0, _api, _err); \
\r
70 #define VALIDATE_NO_RV(_exp,_api,_err ) \
\r
72 Det_ReportError(MODULE_ID_DEM, 0, _api, _err); \
\r
75 #define DET_REPORTERROR(_x,_y,_z,_q) Det_ReportError(_x, _y, _z, _q)
\r
78 #define VALIDATE_RV(_exp,_api,_err,_rv )
\r
79 #define VALIDATE_NO_RV(_exp,_api,_err )
\r
80 #define DET_REPORTERROR(_x,_y,_z,_q)
\r
83 #if (DEM_OBD_SUPPORT == STD_ON)
\r
84 #error "DEM_OBD_SUPPORT is set to STD_ON, this is not supported by the code."
\r
87 #if (DEM_PTO_SUPPORT == STD_ON)
\r
88 #error "DEM_PTO_SUPPORT is set to STD_ON, this is not supported by the code."
\r
91 #if (DEM_TYPE_OF_DTC_SUPPORTED != 0x01)
\r
92 #error "DEM_TYPE_OF_DTC_SUPPORTED is not set to 1 (ISO14229-1), only ISO14229-1 is currently supported by the code."
\r
100 typedef uint16 ChecksumType;
\r
104 Dem_EventStatusExtendedType dtcStatusMask;
\r
105 Dem_DTCKindType dtcKind;
\r
106 Dem_DTCOriginType dtcOrigin;
\r
107 Dem_FilterWithSeverityType filterWithSeverity;
\r
108 Dem_DTCSeverityType dtcSeverityMask;
\r
109 Dem_FilterForFDCType filterForFaultDetectionCounter;
\r
113 // DisableDtcStorageType
\r
115 boolean storageDisabled;
\r
116 Dem_DTCGroupType dtcGroup;
\r
117 Dem_DTCKindType dtcKind;
\r
118 } DisableDtcStorageType;
\r
120 // For keeping track of the events status
\r
122 Dem_EventIdType eventId;
\r
123 const Dem_EventParameterType *eventParamRef;
\r
124 sint8 faultDetectionCounter;
\r
125 uint16 occurrence; /** @req DEM011 */
\r
126 Dem_EventStatusExtendedType eventStatusExtended; /** @req DEM006 */
\r
127 boolean errorStatusChanged;
\r
128 } EventStatusRecType;
\r
131 // Types for storing different event data on event memory
\r
133 Dem_EventIdType eventId;
\r
135 ChecksumType checksum;
\r
139 Dem_EventIdType eventId;
\r
142 sint8 data[DEM_MAX_SIZE_FF_DATA];
\r
143 ChecksumType checksum;
\r
144 } FreezeFrameRecType;
\r
147 Dem_EventIdType eventId;
\r
149 uint8 data[DEM_MAX_SIZE_EXT_DATA];
\r
150 ChecksumType checksum;
\r
157 DEM_UNINITIALIZED = 0,
\r
158 DEM_PREINITIALIZED,
\r
160 } Dem_StateType; /** @req DEM169 */
\r
163 static Dem_StateType demState = DEM_UNINITIALIZED;
\r
165 // Help pointer to configuration set
\r
166 static const Dem_ConfigSetType *configSet;
\r
169 * Allocation of DTC filter parameters
\r
171 static DtcFilterType dtcFilter;
\r
174 * Allocation of Disable/Enable DTC storage parameters
\r
176 static DisableDtcStorageType disableDtcStorage;
\r
179 * Allocation of operation cycle state list
\r
181 static Dem_OperationCycleStateType operationCycleStateList[DEM_OPERATION_CYCLE_ID_ENDMARK];
\r
184 * Allocation of local event status buffer
\r
186 static EventStatusRecType eventStatusBuffer[DEM_MAX_NUMBER_EVENT];
\r
189 * Allocation of pre-init event memory (used between pre-init and init)
\r
192 static FreezeFrameRecType preInitFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRE_INIT];
\r
193 static ExtDataRecType preInitExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRE_INIT];
\r
196 * Allocation of primary event memory ramlog (after init) in uninitialized memory
\r
199 static EventRecType priMemEventBuffer[DEM_MAX_NUMBER_EVENT_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
200 static FreezeFrameRecType priMemFreezeFrameBuffer[DEM_MAX_NUMBER_FF_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
201 static ExtDataRecType priMemExtDataBuffer[DEM_MAX_NUMBER_EXT_DATA_PRI_MEM] __attribute__ ((section (".dem_eventmemory_pri")));
\r
205 * Procedure: zeroPriMemBuffers
\r
206 * Description: Fill the primary buffers with zeroes
\r
208 //lint -e957 PC-Lint exception - Used only by DemTest
\r
209 void demZeroPriMemBuffers(void)
\r
211 memset(priMemEventBuffer, 0, sizeof(priMemEventBuffer));
\r
212 memset(priMemFreezeFrameBuffer, 0, sizeof(priMemFreezeFrameBuffer));
\r
213 memset(priMemExtDataBuffer, 0, sizeof(priMemExtDataBuffer));
\r
218 * Procedure: calcChecksum
\r
219 * Description: Calculate checksum over *data to *(data+nrOfBytes-1) area
\r
221 static ChecksumType calcChecksum(void *data, uint16 nrOfBytes)
\r
224 uint8 *byte = (uint8*)data;
\r
225 ChecksumType sum = 0;
\r
227 for (i = 0; i < nrOfBytes; i++) {
\r
236 * Procedure: checkDtcKind
\r
237 * Description: Return TRUE if "dtcKind" match the events DTCKind or "dtcKind"
\r
238 * is "DEM_DTC_KIND_ALL_DTCS" otherwise FALSE.
\r
240 static boolean checkDtcKind(Dem_DTCKindType dtcKind, const Dem_EventParameterType *eventParam)
\r
242 boolean result = FALSE;
\r
244 if (dtcKind == DEM_DTC_KIND_ALL_DTCS) {
\r
248 if (eventParam->DTCClassRef != NULL) {
\r
249 if (eventParam->DTCClassRef->DTCKind == dtcKind) {
\r
259 * Procedure: checkDtcGroup
\r
260 * Description: Return TRUE if "dtc" match the events DTC or "dtc" is
\r
261 * "DEM_DTC_GROUP_ALL_DTCS" otherwise FALSE.
\r
263 static boolean checkDtcGroup(uint32 dtc, const Dem_EventParameterType *eventParam)
\r
265 boolean result = FALSE;
\r
267 if (dtc == DEM_DTC_GROUP_ALL_DTCS) {
\r
271 if (eventParam->DTCClassRef != NULL) {
\r
272 if (eventParam->DTCClassRef->DTC == dtc) {
\r
282 * Procedure: checkDtcOrigin
\r
283 * Description: Return TRUE if "dtcOrigin" match any of the events DTCOrigin otherwise FALSE.
\r
285 static boolean checkDtcOrigin(Dem_DTCOriginType dtcOrigin, const Dem_EventParameterType *eventParam)
\r
287 boolean result = FALSE;
\r
288 boolean dtcOriginFound = FALSE;
\r
291 for (i = 0;(i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound); i++){
\r
292 dtcOriginFound = (eventParam->EventClass->EventDestination[i] == dtcOrigin);
\r
295 if (dtcOriginFound) {
\r
303 * Procedure: checkDtcSeverityMask
\r
304 * Description: Return TRUE if "dtcSeverityMask" match any of the events DTC severity otherwise FALSE.
\r
306 // PC-Lint (715 etc): Remove errors until function is filled.
\r
307 //lint -e{715} Symbol not referenced
\r
308 static boolean checkDtcSeverityMask(Dem_DTCSeverityType dtcSeverityMask, const Dem_EventParameterType *eventParam)
\r
310 boolean result = TRUE;
\r
312 // TODO: This function is optional, may be implemented here.
\r
319 * Procedure: checkDtcFaultDetectionCounterMask
\r
320 * Description: TBD.
\r
322 // PC-Lint (715 etc): Remove errors until function is filled.
\r
323 //lint -e{715} Symbol not referenced
\r
324 static boolean checkDtcFaultDetectionCounter(const Dem_EventParameterType *eventParam)
\r
326 boolean result = TRUE;
\r
328 // TODO: Not implemented yet.
\r
335 * Procedure: lookupEventStatusRec
\r
336 * Description: Returns the pointer to event id parameters of "eventId" in "*eventStatusBuffer",
\r
337 * if not found NULL is returned.
\r
339 static void lookupEventStatusRec(Dem_EventIdType eventId, EventStatusRecType **const eventStatusRec)
\r
342 boolean eventIdFound = FALSE;
\r
344 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!eventIdFound); i++) {
\r
345 eventIdFound = (eventStatusBuffer[i].eventId == eventId);
\r
348 if (eventIdFound) {
\r
349 *eventStatusRec = &eventStatusBuffer[i-1];
\r
351 *eventStatusRec = NULL;
\r
357 * Procedure: lookupEventIdParameter
\r
358 * Description: Returns the pointer to event id parameters of "eventId" in "*eventIdParam",
\r
359 * if not found NULL is returned.
\r
361 static void lookupEventIdParameter(Dem_EventIdType eventId, const Dem_EventParameterType **const eventIdParam)
\r
363 const Dem_EventParameterType *EventIdParamList = configSet->EventParameter;
\r
365 // Lookup the correct event id parameters
\r
367 while ((EventIdParamList[i].EventID != eventId) && (!EventIdParamList[i].Arc_EOL)) {
\r
371 if (!EventIdParamList[i].Arc_EOL) {
\r
372 *eventIdParam = &EventIdParamList[i];
\r
374 *eventIdParam = NULL;
\r
380 * Procedure: preDebounceNone
\r
381 * Description: Returns the result of the debouncing.
\r
383 static Dem_EventStatusType preDebounceNone(const Dem_EventStatusType reportedStatus, const EventStatusRecType* statusRecord) {
\r
384 Dem_EventStatusType returnCode;
\r
385 (void)statusRecord; // Just to get rid of PC-Lint warnings
\r
387 switch (reportedStatus) {
\r
388 case DEM_EVENT_STATUS_FAILED: /** @req DEM091.NoneFailed */
\r
389 case DEM_EVENT_STATUS_PASSED: /** @req DEM091.NonePassed */
\r
390 // Already debounced, do nothing.
\r
394 // TODO: What to do with PREFAIL and PREPASSED on no debouncing?
\r
395 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_NONE_ID, DEM_E_PARAM_DATA);
\r
399 returnCode = reportedStatus;
\r
405 * Procedure: preDebounceCounterBased
\r
406 * Description: Returns the result of the debouncing.
\r
408 static Dem_EventStatusType preDebounceCounterBased(Dem_EventStatusType reportedStatus, EventStatusRecType* statusRecord) {
\r
409 Dem_EventStatusType returnCode;
\r
410 const Dem_PreDebounceCounterBasedType* pdVars = statusRecord->eventParamRef->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceCounterBased;
\r
412 switch (reportedStatus) {
\r
413 case DEM_EVENT_STATUS_PREFAILED:
\r
414 if (statusRecord->faultDetectionCounter < DEBOUNCE_FDC_TEST_FAILED) {
\r
415 if ((pdVars->JumpUp) && (statusRecord->faultDetectionCounter < 0)) {
\r
416 statusRecord->faultDetectionCounter = 0;
\r
418 if (((sint16)statusRecord->faultDetectionCounter + (sint8)pdVars->CountInStepSize) < DEBOUNCE_FDC_TEST_FAILED) {
\r
419 statusRecord->faultDetectionCounter += (sint8)pdVars->CountInStepSize;
\r
421 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED;
\r
427 case DEM_EVENT_STATUS_PREPASSED:
\r
428 if (statusRecord->faultDetectionCounter > DEBOUNCE_FDC_TEST_PASSED) {
\r
429 if ((pdVars->JumpDown) && (statusRecord->faultDetectionCounter > 0)) {
\r
430 statusRecord->faultDetectionCounter = 0;
\r
432 if (((sint16)statusRecord->faultDetectionCounter - (sint8)pdVars->CountOutStepSize) > DEBOUNCE_FDC_TEST_PASSED) {
\r
433 statusRecord->faultDetectionCounter -= (sint8)pdVars->CountOutStepSize;
\r
435 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED;
\r
441 case DEM_EVENT_STATUS_FAILED:
\r
442 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_FAILED; /** @req DEM091.CounterFailed */
\r
445 case DEM_EVENT_STATUS_PASSED:
\r
446 statusRecord->faultDetectionCounter = DEBOUNCE_FDC_TEST_PASSED; /** @req DEM091.CounterPassed */
\r
450 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_PREDEBOUNCE_COUNTER_BASED_ID, DEM_E_PARAM_DATA);
\r
455 switch (statusRecord->faultDetectionCounter) {
\r
456 case DEBOUNCE_FDC_TEST_FAILED:
\r
457 returnCode = DEM_EVENT_STATUS_FAILED;
\r
460 case DEBOUNCE_FDC_TEST_PASSED:
\r
461 returnCode = DEM_EVENT_STATUS_PASSED;
\r
465 returnCode = reportedStatus;
\r
474 * Procedure: updateEventStatusRec
\r
475 * Description: Update the status of "eventId", if not exist and "createIfNotExist" is
\r
476 * true a new record is created
\r
478 static void updateEventStatusRec(const Dem_EventParameterType *eventParam, Dem_EventStatusType eventStatus, boolean createIfNotExist, EventStatusRecType *eventStatusRec)
\r
480 EventStatusRecType *eventStatusRecPtr;
\r
481 imask_t state = McuE_EnterCriticalSection();
\r
484 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
486 if ((eventStatusRecPtr == NULL) && (createIfNotExist)) {
\r
487 // Search for free position
\r
488 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
490 if (eventStatusRecPtr != NULL) {
\r
491 // Create new event record
\r
492 eventStatusRecPtr->eventId = eventParam->EventID;
\r
493 eventStatusRecPtr->eventParamRef = eventParam;
\r
494 eventStatusRecPtr->faultDetectionCounter = 0;
\r
495 eventStatusRecPtr->occurrence = 0;
\r
496 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
497 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
500 // Error: Event status buffer full
\r
501 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
506 if (eventStatusRecPtr != NULL) {
\r
507 // Handle debouncing
\r
508 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
509 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName) { /** @req DEM004 */ /** @req DEM342 */
\r
510 case DEM_NO_PRE_DEBOUNCE:
\r
511 eventStatus = preDebounceNone(eventStatus, eventStatusRecPtr);
\r
514 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
515 eventStatus = preDebounceCounterBased(eventStatus, eventStatusRecPtr);
\r
519 // Don't know how to handle this.
\r
520 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_UPDATE_EVENT_STATUS_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
525 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
527 // Check test failed
\r
528 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
529 if (!(eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED)) {
\r
530 eventStatusRecPtr->occurrence++;
\r
531 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
533 /** @req DEM036 */ /** @req DEM379.PendingSet */
\r
534 eventStatusRecPtr->eventStatusExtended |= (DEM_TEST_FAILED | DEM_TEST_FAILED_THIS_OPERATION_CYCLE | DEM_TEST_FAILED_SINCE_LAST_CLEAR | DEM_PENDING_DTC);
\r
535 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
538 // Check test passed
\r
539 if (eventStatus == DEM_EVENT_STATUS_PASSED) {
\r
540 if (eventStatusRecPtr->eventStatusExtended & DEM_TEST_FAILED) {
\r
541 eventStatusRecPtr->errorStatusChanged = TRUE;
\r
544 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED;
\r
545 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~(DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE);
\r
549 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
552 // Copy an empty record to return data
\r
553 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
554 eventStatusRec->faultDetectionCounter = 0;
\r
555 eventStatusRec->occurrence = 0;
\r
556 eventStatusRec->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
557 eventStatusRec->errorStatusChanged = FALSE;
\r
560 McuE_ExitCriticalSection(state);
\r
565 * Procedure: mergeEventStatusRec
\r
566 * Description: Update the occurrence counter of status, if not exist a new record is created
\r
568 static void mergeEventStatusRec(const EventRecType *eventRec)
\r
570 EventStatusRecType *eventStatusRecPtr;
\r
571 imask_t state = McuE_EnterCriticalSection();
\r
574 lookupEventStatusRec(eventRec->eventId, &eventStatusRecPtr);
\r
576 if (eventStatusRecPtr != NULL) {
\r
577 // Update occurrence counter, rest of pre init state is kept.
\r
578 eventStatusRecPtr->occurrence += eventRec->occurrence;
\r
582 // Search for free position
\r
583 lookupEventStatusRec(DEM_EVENT_ID_NULL, &eventStatusRecPtr);
\r
585 if (eventStatusRecPtr != NULL) {
\r
586 // Create new event, from stored event
\r
587 eventStatusRecPtr->eventId = eventRec->eventId;
\r
588 lookupEventIdParameter(eventRec->eventId, &eventStatusRecPtr->eventParamRef);
\r
589 eventStatusRecPtr->faultDetectionCounter = 0;
\r
590 eventStatusRecPtr->occurrence = eventRec->occurrence;
\r
591 eventStatusRecPtr->eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
592 eventStatusRecPtr->errorStatusChanged = FALSE;
\r
595 // Error: Event status buffer full
\r
596 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_MERGE_EVENT_STATUS_ID, DEM_E_EVENT_STATUS_BUFF_FULL);
\r
600 McuE_ExitCriticalSection(state);
\r
605 * Procedure: deleteEventStatusRec
\r
606 * Description: Delete the status record of "eventParam->eventId" from "eventStatusBuffer".
\r
608 static void deleteEventStatusRec(const Dem_EventParameterType *eventParam)
\r
610 EventStatusRecType *eventStatusRecPtr;
\r
611 imask_t state = McuE_EnterCriticalSection();
\r
614 lookupEventStatusRec(eventParam->EventID, &eventStatusRecPtr);
\r
616 if (eventStatusRecPtr != NULL) {
\r
617 // Delete event record
\r
618 memset(eventStatusRecPtr, 0, sizeof(EventStatusRecType));
\r
621 McuE_ExitCriticalSection(state);
\r
626 * Procedure: getEventStatusRec
\r
627 * Description: Returns the status record of "eventId" in "eventStatusRec"
\r
629 static void getEventStatusRec(Dem_EventIdType eventId, EventStatusRecType *eventStatusRec)
\r
631 EventStatusRecType *eventStatusRecPtr;
\r
634 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
636 if (eventStatusRecPtr != NULL) {
\r
638 memcpy(eventStatusRec, eventStatusRecPtr, sizeof(EventStatusRecType));
\r
641 eventStatusRec->eventId = DEM_EVENT_ID_NULL;
\r
647 * Procedure: lookupDtcEvent
\r
648 * Description: Returns TRUE if the DTC was found and "eventStatusRec" points
\r
649 * to the event record found.
\r
651 static boolean lookupDtcEvent(uint32 dtc, EventStatusRecType **eventStatusRec)
\r
653 boolean dtcFound = FALSE;
\r
656 *eventStatusRec = NULL;
\r
658 for (i = 0; (i < DEM_MAX_NUMBER_EVENT) && (!dtcFound); i++) {
\r
659 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
660 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
663 if (eventStatusBuffer[i].eventParamRef->DTCClassRef->DTC == dtc) {
\r
664 *eventStatusRec = &eventStatusBuffer[i];
\r
676 * Procedure: matchEventWithDtcFilter
\r
677 * Description: Returns TRUE if the event pointed by "event" fulfill
\r
678 * the "dtcFilter" global filter settings.
\r
680 static boolean matchEventWithDtcFilter(const EventStatusRecType *eventRec)
\r
682 boolean dtcMatch = FALSE;
\r
685 if ((dtcFilter.dtcStatusMask == DEM_DTC_STATUS_MASK_ALL) || (eventRec->eventStatusExtended & dtcFilter.dtcStatusMask)) {
\r
686 if (eventRec->eventParamRef != NULL) {
\r
689 if (checkDtcKind(dtcFilter.dtcKind, eventRec->eventParamRef)) {
\r
692 if (checkDtcOrigin(dtcFilter.dtcOrigin, eventRec->eventParamRef)) {
\r
695 if ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
696 || ((dtcFilter.filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES) && (checkDtcSeverityMask(dtcFilter.dtcSeverityMask, eventRec->eventParamRef)))) {
\r
698 // Check fault detection counter
\r
699 if ((dtcFilter.filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO)
\r
700 || ((dtcFilter.filterWithSeverity == DEM_FILTER_FOR_FDC_YES) && (checkDtcFaultDetectionCounter(eventRec->eventParamRef)))) {
\r
713 // PC-Lint (715 etc): Remove errors until function is filled.
\r
714 //lint -e{715} Symbol not referenced
\r
715 static void getFreezeFrameData(const Dem_EventParameterType *eventParam, FreezeFrameRecType *freezeFrame)
\r
718 freezeFrame->eventId = DEM_EVENT_ID_NULL; // Not supported yet
\r
722 // PC-Lint (715 etc): Remove errors until function is filled.
\r
723 //lint -e{715} Symbol not referenced
\r
724 static void storeFreezeFrameDataPreInit(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
730 // PC-Lint (715 etc): Remove errors until function is filled.
\r
731 //lint -e{715} Symbol not referenced
\r
732 static void updateFreezeFrameOccurrencePreInit(const EventRecType *EventBuffer)
\r
739 * Procedure: getExtendedData
\r
740 * Description: Collects the extended data according to "eventParam" and return it in "extData",
\r
741 * if not found eventId is set to DEM_EVENT_ID_NULL.
\r
743 static void getExtendedData(const Dem_EventParameterType *eventParam, ExtDataRecType *extData)
\r
745 Std_ReturnType callbackReturnCode;
\r
747 uint16 storeIndex = 0;
\r
750 // Clear ext data record
\r
751 memset(extData, 0, sizeof(ExtDataRecType));
\r
753 // Check if any pointer to extended data class
\r
754 if (eventParam->ExtendedDataClassRef != NULL) {
\r
755 // Request extended data and copy it to the buffer
\r
756 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL); i++) {
\r
757 recordSize = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
758 if ((storeIndex + recordSize) <= DEM_MAX_SIZE_EXT_DATA) {
\r
759 callbackReturnCode = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->CallbackGetExtDataRecord(&extData->data[storeIndex]); /** @req DEM282 */
\r
760 if (callbackReturnCode != E_OK) {
\r
761 // Callback data currently not available, clear space.
\r
762 memset(&extData->data[storeIndex], 0xFF, recordSize);
\r
764 storeIndex += recordSize;
\r
767 // Error: Size of extended data record is bigger than reserved space.
\r
768 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GET_EXTENDED_DATA_ID, DEM_E_EXT_DATA_TOO_BIG);
\r
769 break; // Break the loop
\r
774 // Check if any data has been stored
\r
775 if (storeIndex != 0) {
\r
776 extData->eventId = eventParam->EventID;
\r
777 extData->dataSize = storeIndex;
\r
778 extData->checksum = calcChecksum(extData, sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
781 extData->eventId = DEM_EVENT_ID_NULL;
\r
782 extData->dataSize = storeIndex;
\r
783 extData->checksum = 0;
\r
789 * Procedure: storeExtendedDataPreInit
\r
790 * Description: Store the extended data pointed by "extendedData" to the "preInitExtDataBuffer",
\r
791 * if non existent a new entry is created.
\r
793 static void storeExtendedDataPreInit(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
795 boolean eventIdFound = FALSE;
\r
796 boolean eventIdFreePositionFound=FALSE;
\r
798 imask_t state = McuE_EnterCriticalSection();
\r
800 // Check if already stored
\r
801 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) && (!eventIdFound); i++){
\r
802 eventIdFound = (preInitExtDataBuffer[i].eventId == eventParam->EventID);
\r
806 // Yes, overwrite existing
\r
807 memcpy(&preInitExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
810 // No, lookup first free position
\r
811 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRE_INIT) && (!eventIdFreePositionFound); i++){
\r
812 if(preInitExtDataBuffer[i].eventId ==0){
\r
813 eventIdFreePositionFound=TRUE;
\r
817 if (eventIdFreePositionFound) {
\r
818 memcpy(&preInitExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
821 // Error: Pre init extended data buffer full
\r
822 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRE_INIT_ID, DEM_E_PRE_INIT_EXT_DATA_BUFF_FULL);
\r
826 McuE_ExitCriticalSection(state);
\r
830 * Procedure: storeEventPriMem
\r
831 * Description: Store the event data of "eventStatus->eventId" in "priMemEventBuffer",
\r
832 * if non existent a new entry is created.
\r
834 static void storeEventPriMem(const Dem_EventParameterType *eventParam, const EventStatusRecType *eventStatus)
\r
836 boolean eventIdFound = FALSE;
\r
837 boolean eventIdFreePositionFound=FALSE;
\r
839 imask_t state = McuE_EnterCriticalSection();
\r
841 (void)*eventParam; // Currently not used, do this to avoid warning
\r
844 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
845 eventIdFound = (priMemEventBuffer[i].eventId == eventStatus->eventId);
\r
848 if (eventIdFound) {
\r
849 // Update event found
\r
850 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
851 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
854 // Search for free position
\r
855 for (i=0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFreePositionFound); i++){
\r
856 eventIdFreePositionFound = (priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
860 if (eventIdFreePositionFound) {
\r
861 priMemEventBuffer[i-1].eventId = eventStatus->eventId;
\r
862 priMemEventBuffer[i-1].occurrence = eventStatus->occurrence;
\r
863 priMemEventBuffer[i-1].checksum = calcChecksum(&priMemEventBuffer[i-1], sizeof(EventRecType)-sizeof(ChecksumType));
\r
866 // Error: Pri mem event buffer full
\r
867 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EVENT_PRI_MEM_ID, DEM_E_PRI_MEM_EVENT_BUFF_FULL);
\r
871 McuE_ExitCriticalSection(state);
\r
875 * Procedure: deleteEventPriMem
\r
876 * Description: Delete the event data of "eventParam->eventId" from "priMemEventBuffer".
\r
878 static void deleteEventPriMem(const Dem_EventParameterType *eventParam)
\r
880 boolean eventIdFound = FALSE;
\r
882 imask_t state = McuE_EnterCriticalSection();
\r
886 for (i = 0; (i < DEM_MAX_NUMBER_EVENT_ENTRY_PRI) && (!eventIdFound); i++){
\r
887 eventIdFound = (priMemEventBuffer[i].eventId == eventParam->EventID);
\r
890 if (eventIdFound) {
\r
891 // Delete event found
\r
892 memset(&priMemEventBuffer[i-1], 0, sizeof(EventRecType));
\r
895 McuE_ExitCriticalSection(state);
\r
899 * Procedure: storeEventEvtMem
\r
900 * Description: Store the event data of "eventStatus->eventId" in event memory according to
\r
901 * "eventParam" destination option.
\r
903 static void storeEventEvtMem(const Dem_EventParameterType *eventParam, const EventStatusRecType *eventStatus)
\r
907 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION)
\r
908 && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
909 switch (eventParam->EventClass->EventDestination[i])
\r
911 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
912 storeEventPriMem(eventParam, eventStatus); /** @req DEM010 */
\r
915 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
916 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
917 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
918 // Not yet supported
\r
919 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
929 * Procedure: storeExtendedDataPriMem
\r
930 * Description: Store the extended data pointed by "extendedData" to the "priMemExtDataBuffer",
\r
931 * if non existent a new entry is created.
\r
933 static void storeExtendedDataPriMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData) /** @req DEM041 */
\r
935 boolean eventIdFound = FALSE;
\r
936 boolean eventIdFreePositionFound=FALSE;
\r
938 imask_t state = McuE_EnterCriticalSection();
\r
940 // Check if already stored
\r
941 for (i = 0; (i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
942 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
945 if (eventIdFound) {
\r
946 // Yes, overwrite existing
\r
947 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
950 // No, lookup first free position
\r
951 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFreePositionFound); i++){
\r
952 eventIdFreePositionFound = (priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL);
\r
954 if (eventIdFreePositionFound) {
\r
955 memcpy(&priMemExtDataBuffer[i-1], extendedData, sizeof(ExtDataRecType));
\r
958 // Error: Pri mem extended data buffer full
\r
959 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_STORE_EXT_DATA_PRI_MEM_ID, DEM_E_PRI_MEM_EXT_DATA_BUFF_FULL);
\r
963 McuE_ExitCriticalSection(state);
\r
967 * Procedure: deleteExtendedDataPriMem
\r
968 * Description: Delete the extended data of "eventParam->eventId" from "priMemExtDataBuffer".
\r
970 static void deleteExtendedDataPriMem(const Dem_EventParameterType *eventParam)
\r
972 boolean eventIdFound = FALSE;
\r
974 imask_t state = McuE_EnterCriticalSection();
\r
976 // Check if already stored
\r
977 for (i = 0;(i<DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++){
\r
978 eventIdFound = (priMemExtDataBuffer[i].eventId == eventParam->EventID);
\r
981 if (eventIdFound) {
\r
982 // Yes, clear record
\r
983 memset(&priMemExtDataBuffer[i-1], 0, sizeof(ExtDataRecType));
\r
986 McuE_ExitCriticalSection(state);
\r
990 * Procedure: storeExtendedDataEvtMem
\r
991 * Description: Store the extended data in event memory according to
\r
992 * "eventParam" destination option
\r
994 static void storeExtendedDataEvtMem(const Dem_EventParameterType *eventParam, const ExtDataRecType *extendedData)
\r
998 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
999 switch (eventParam->EventClass->EventDestination[i])
\r
1001 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1002 storeExtendedDataPriMem(eventParam, extendedData);
\r
1005 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1006 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1007 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1008 // Not yet supported
\r
1009 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1020 * Procedure: lookupExtendedDataRecNumParam
\r
1021 * Description: Returns TRUE if the requested extended data number was found among the configured records for the event.
\r
1022 * "extDataRecClassPtr" returns a pointer to the record class, "posInExtData" returns the position in stored extended data.
\r
1024 static boolean lookupExtendedDataRecNumParam(uint8 extendedDataNumber, const Dem_EventParameterType *eventParam, Dem_ExtendedDataRecordClassType const **extDataRecClassPtr, uint16 *posInExtData)
\r
1026 boolean recNumFound = FALSE;
\r
1028 if (eventParam->ExtendedDataClassRef != NULL) {
\r
1029 uint16 byteCnt = 0;
\r
1032 // Request extended data and copy it to the buffer
\r
1033 for (i = 0; (i < DEM_MAX_NR_OF_RECORDS_IN_EXTENDED_DATA) && (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i] != NULL) && (!recNumFound); i++) {
\r
1034 if (eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->RecordNumber == extendedDataNumber) {
\r
1035 *extDataRecClassPtr = eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i];
\r
1036 *posInExtData = byteCnt;
\r
1037 recNumFound = TRUE;
\r
1039 byteCnt += eventParam->ExtendedDataClassRef->ExtendedDataRecordClassRef[i]->DataSize;
\r
1043 return recNumFound;
\r
1048 * Procedure: lookupExtendedDataPriMem
\r
1049 * Description: Returns TRUE if the requested event id is found, "extData" points to the found data.
\r
1051 static boolean lookupExtendedDataPriMem(Dem_EventIdType eventId, ExtDataRecType **extData)
\r
1053 boolean eventIdFound = FALSE;
\r
1056 // Lookup corresponding extended data
\r
1057 for (i = 0; (i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM) && (!eventIdFound); i++) {
\r
1058 eventIdFound = (priMemExtDataBuffer[i].eventId == eventId);
\r
1061 if (eventIdFound) {
\r
1062 // Yes, return pointer
\r
1063 *extData = &priMemExtDataBuffer[i-1];
\r
1066 return eventIdFound;
\r
1069 // PC-Lint (715 etc): Remove errors until function is filled.
\r
1070 //lint -e{715} Symbol not referenced
\r
1071 static void storeFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1077 // PC-Lint (715 etc): Remove errors until function is filled.
\r
1078 //lint -e{715} Symbol not referenced
\r
1079 static void deleteFreezeFrameDataPriMem(const Dem_EventParameterType *eventParam)
\r
1086 * Procedure: storeFreezeFrameDataEvtMem
\r
1087 * Description: Store the freeze frame data in event memory according to
\r
1088 * "eventParam" destination option
\r
1090 static void storeFreezeFrameDataEvtMem(const Dem_EventParameterType *eventParam, const FreezeFrameRecType *freezeFrame)
\r
1094 for (i = 0; (i < DEM_MAX_NR_OF_EVENT_DESTINATION) && (eventParam->EventClass->EventDestination[i] != DEM_EVENT_DESTINATION_END_OF_LIST); i++) {
\r
1095 switch (eventParam->EventClass->EventDestination[i])
\r
1097 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
1098 storeFreezeFrameDataPriMem(eventParam, freezeFrame);
\r
1101 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
1102 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
1103 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
1104 // Not yet supported
\r
1105 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GLOBAL_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1116 * Procedure: handlePreInitEvent
\r
1117 * Description: Handle the updating of event status and storing of
\r
1118 * event related data in preInit buffers.
\r
1120 static void handlePreInitEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1122 const Dem_EventParameterType *eventParam;
\r
1123 EventStatusRecType eventStatusLocal;
\r
1124 FreezeFrameRecType freezeFrameLocal;
\r
1125 ExtDataRecType extendedDataLocal;
\r
1127 // Find configuration for this event
\r
1128 lookupEventIdParameter(eventId, &eventParam);
\r
1129 if (eventParam != NULL) {
\r
1130 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1131 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1132 if (eventStatus == DEM_EVENT_STATUS_FAILED) {
\r
1133 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1136 updateEventStatusRec(eventParam, eventStatus, FALSE, &eventStatusLocal);
\r
1139 if (eventStatusLocal.errorStatusChanged) {
\r
1141 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1142 // Collect freeze frame data
\r
1143 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1144 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1145 storeFreezeFrameDataPreInit(eventParam, &freezeFrameLocal);
\r
1148 // Collect extended data
\r
1149 getExtendedData(eventParam, &extendedDataLocal);
\r
1150 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1151 storeExtendedDataPreInit(eventParam, &extendedDataLocal);
\r
1157 // Operation cycle not started
\r
1158 // TODO: Report error?
\r
1162 // Operation cycle not set
\r
1163 // TODO: Report error?
\r
1167 // Event ID not configured
\r
1168 // TODO: Report error?
\r
1174 * Procedure: handleEvent
\r
1175 * Description: Handle the updating of event status and storing of
\r
1176 * event related data in event memory.
\r
1178 static Std_ReturnType handleEvent(Dem_EventIdType eventId, Dem_EventStatusType eventStatus)
\r
1180 Std_ReturnType returnCode = E_OK;
\r
1181 const Dem_EventParameterType *eventParam;
\r
1182 EventStatusRecType eventStatusLocal;
\r
1183 FreezeFrameRecType freezeFrameLocal;
\r
1184 ExtDataRecType extendedDataLocal;
\r
1186 // Find configuration for this event
\r
1187 lookupEventIdParameter(eventId, &eventParam);
\r
1188 if (eventParam != NULL) {
\r
1189 if (eventParam->EventClass->OperationCycleRef < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1190 if (operationCycleStateList[eventParam->EventClass->OperationCycleRef] == DEM_CYCLE_STATE_START) {
\r
1191 if ((!((disableDtcStorage.storageDisabled) && (checkDtcGroup(disableDtcStorage.dtcGroup, eventParam)) && (checkDtcKind(disableDtcStorage.dtcKind, eventParam))))) {
\r
1192 updateEventStatusRec(eventParam, eventStatus, TRUE, &eventStatusLocal);
\r
1193 if (eventStatusLocal.errorStatusChanged) {
\r
1194 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) {
\r
1195 storeEventEvtMem(eventParam, &eventStatusLocal); /** @req DEM184 */
\r
1196 // Collect freeze frame data
\r
1197 getFreezeFrameData(eventParam, &freezeFrameLocal);
\r
1198 if (freezeFrameLocal.eventId != DEM_EVENT_ID_NULL) {
\r
1199 storeFreezeFrameDataEvtMem(eventParam, &freezeFrameLocal); /** @req DEM190 */
\r
1202 // Collect extended data
\r
1203 getExtendedData(eventParam, &extendedDataLocal);
\r
1204 if (extendedDataLocal.eventId != DEM_EVENT_ID_NULL)
\r
1206 storeExtendedDataEvtMem(eventParam, &extendedDataLocal);
\r
1213 // Operation cycle not started
\r
1214 returnCode = E_NOT_OK;
\r
1218 // Operation cycle not set
\r
1219 returnCode = E_NOT_OK;
\r
1223 // Event ID not configured
\r
1224 returnCode = E_NOT_OK;
\r
1227 return returnCode;
\r
1232 * Procedure: resetEventStatus
\r
1233 * Description: Resets the events status of eventId.
\r
1235 static void resetEventStatus(Dem_EventIdType eventId)
\r
1237 imask_t state = McuE_EnterCriticalSection();
\r
1238 EventStatusRecType *eventStatusRecPtr;
\r
1240 lookupEventStatusRec(eventId, &eventStatusRecPtr);
\r
1241 if (eventStatusRecPtr != NULL) {
\r
1242 eventStatusRecPtr->eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED; /** @req DEM187 */
\r
1245 McuE_ExitCriticalSection(state);
\r
1250 * Procedure: getEventStatus
\r
1251 * Description: Returns the extended event status bitmask of eventId in "eventStatusExtended".
\r
1253 static void getEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended)
\r
1255 EventStatusRecType eventStatusLocal;
\r
1257 // Get recorded status
\r
1258 getEventStatusRec(eventId, &eventStatusLocal);
\r
1259 if (eventStatusLocal.eventId == eventId) {
\r
1260 *eventStatusExtended = eventStatusLocal.eventStatusExtended; /** @req DEM051 */
\r
1263 // Event Id not found, no report received.
\r
1264 *eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1270 * Procedure: getEventFailed
\r
1271 * Description: Returns the TRUE or FALSE of "eventId" in "eventFailed" depending on current status.
\r
1273 static void getEventFailed(Dem_EventIdType eventId, boolean *eventFailed)
\r
1275 EventStatusRecType eventStatusLocal;
\r
1277 // Get recorded status
\r
1278 getEventStatusRec(eventId, &eventStatusLocal);
\r
1279 if (eventStatusLocal.eventId == eventId) {
\r
1280 if (eventStatusLocal.eventStatusExtended & DEM_TEST_FAILED) { /** @req DEM052 */
\r
1281 *eventFailed = TRUE;
\r
1284 *eventFailed = FALSE;
\r
1288 // Event Id not found, assume ok.
\r
1289 *eventFailed = FALSE;
\r
1295 * Procedure: getEventTested
\r
1296 * Description: Returns the TRUE or FALSE of "eventId" in "eventTested" depending on
\r
1297 * current status the "test not completed this operation cycle" bit.
\r
1299 static void getEventTested(Dem_EventIdType eventId, boolean *eventTested)
\r
1301 EventStatusRecType eventStatusLocal;
\r
1303 // Get recorded status
\r
1304 getEventStatusRec(eventId, &eventStatusLocal);
\r
1305 if (eventStatusLocal.eventId == eventId) {
\r
1306 if ( !(eventStatusLocal.eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE)) { /** @req DEM053 */
\r
1307 *eventTested = TRUE;
\r
1310 *eventTested = FALSE;
\r
1314 // Event Id not found, not tested.
\r
1315 *eventTested = FALSE;
\r
1321 * Procedure: getFaultDetectionCounter
\r
1322 * Description: Returns pre debounce counter of "eventId" in "counter" and return value E_OK if
\r
1323 * the counter was available else E_NOT_OK.
\r
1325 static Std_ReturnType getFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1327 Std_ReturnType returnCode = E_NOT_OK;
\r
1328 const Dem_EventParameterType *eventParam;
\r
1330 lookupEventIdParameter(eventId, &eventParam);
\r
1331 if (eventParam != NULL) {
\r
1332 if (eventParam->EventClass->PreDebounceAlgorithmClass != NULL) {
\r
1333 switch (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceName)
\r
1335 case DEM_NO_PRE_DEBOUNCE:
\r
1336 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal != NULL) {
\r
1337 if (eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc != NULL) {
\r
1338 returnCode = eventParam->EventClass->PreDebounceAlgorithmClass->PreDebounceAlgorithm.PreDebounceMonitorInternal->CallbackGetFDCntFnc(counter); /** @req DEM204.None */ /** @req DEM264 */ /** @req DEM265 */
\r
1343 case DEM_PRE_DEBOUNCE_COUNTER_BASED:
\r
1345 EventStatusRecType *eventStatusRec;
\r
1347 lookupEventStatusRec(eventId, &eventStatusRec);
\r
1348 if (eventStatusRec != NULL) {
\r
1349 *counter = eventStatusRec->faultDetectionCounter; /** @req DEM204.Counter */
\r
1353 returnCode = E_OK;
\r
1357 case DEM_PRE_DEBOUNCE_FREQUENCY_BASED:
\r
1358 case DEM_PRE_DEBOUNCE_TIME_BASED:
\r
1359 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
1363 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_PARAM_DATA);
\r
1369 return returnCode;
\r
1374 * Procedure: setOperationCycleState
\r
1375 * Description: Change the operation state of "operationCycleId" to "cycleState" and updates stored
\r
1376 * event connected to this cycle id.
\r
1377 * Returns E_OK if operation was successful else E_NOT_OK.
\r
1379 static Std_ReturnType setOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState) /** @req DEM338 */
\r
1382 Std_ReturnType returnCode = E_OK;
\r
1384 if (operationCycleId < DEM_OPERATION_CYCLE_ID_ENDMARK) {
\r
1385 switch (cycleState)
\r
1387 case DEM_CYCLE_STATE_START:
\r
1388 operationCycleStateList[operationCycleId] = cycleState;
\r
1389 // Lookup event ID
\r
1390 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1391 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1392 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_TEST_FAILED_THIS_OPERATION_CYCLE;
\r
1393 eventStatusBuffer[i].eventStatusExtended |= DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE;
\r
1398 case DEM_CYCLE_STATE_END:
\r
1399 operationCycleStateList[operationCycleId] = cycleState;
\r
1400 // Lookup event ID
\r
1401 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1402 if ((eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) && (eventStatusBuffer[i].eventParamRef->EventClass->OperationCycleRef == operationCycleId)) {
\r
1403 if ((!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_FAILED_THIS_OPERATION_CYCLE)) && (!(eventStatusBuffer[i].eventStatusExtended & DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE))) {
\r
1404 eventStatusBuffer[i].eventStatusExtended &= (Dem_EventStatusExtendedType)~DEM_PENDING_DTC; // Clear pendingDTC bit /** @req DEM379.PendingClear
\r
1410 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
1411 returnCode = E_NOT_OK;
\r
1416 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_PARAM_DATA);
\r
1417 returnCode = E_NOT_OK;
\r
1420 return returnCode;
\r
1424 //==============================================================================//
\r
1426 // E X T E R N A L F U N C T I O N S //
\r
1428 //==============================================================================//
\r
1430 /*********************************************
\r
1431 * Interface for upper layer modules (8.3.1) *
\r
1432 *********************************************/
\r
1435 * Procedure: Dem_GetVersionInfo
\r
1438 // Defined in Dem.h
\r
1441 /***********************************************
\r
1442 * Interface ECU State Manager <-> DEM (8.3.2) *
\r
1443 ***********************************************/
\r
1446 * Procedure: Dem_PreInit
\r
1449 void Dem_PreInit(void)
\r
1451 /** @req DEM180 */
\r
1454 VALIDATE_NO_RV(DEM_Config.ConfigSet != NULL, DEM_PREINIT_ID, DEM_E_CONFIG_PTR_INVALID);
\r
1456 configSet = DEM_Config.ConfigSet;
\r
1458 // Initializion of operation cycle states.
\r
1459 for (i = 0; i < DEM_OPERATION_CYCLE_ID_ENDMARK; i++) {
\r
1460 operationCycleStateList[i] = DEM_CYCLE_STATE_END;
\r
1463 // Initialize the event status buffer
\r
1464 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1465 eventStatusBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1466 eventStatusBuffer[i].eventParamRef = NULL;
\r
1467 eventStatusBuffer[i].faultDetectionCounter = 0;
\r
1468 eventStatusBuffer[i].occurrence = 0;
\r
1469 eventStatusBuffer[i].eventStatusExtended = DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR;
\r
1470 eventStatusBuffer[i].errorStatusChanged = FALSE;
\r
1473 // Initialize the pre init buffers
\r
1474 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1475 preInitFreezeFrameBuffer[i].checksum = 0;
\r
1476 preInitFreezeFrameBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1477 preInitFreezeFrameBuffer[i].occurrence = 0;
\r
1478 preInitFreezeFrameBuffer[i].dataSize = 0;
\r
1479 for (j = 0; j < DEM_MAX_SIZE_FF_DATA;j++){
\r
1480 preInitFreezeFrameBuffer[i].data[j] = 0;
\r
1484 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1485 preInitExtDataBuffer[i].checksum = 0;
\r
1486 preInitExtDataBuffer[i].eventId = DEM_EVENT_ID_NULL;
\r
1487 preInitExtDataBuffer[i].dataSize = 0;
\r
1488 for (j = 0; j < DEM_MAX_SIZE_EXT_DATA;j++){
\r
1489 preInitExtDataBuffer[i].data[j] = 0;
\r
1493 disableDtcStorage.storageDisabled = FALSE;
\r
1495 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_START); /** @req DEM047 */
\r
1497 demState = DEM_PREINITIALIZED;
\r
1502 * Procedure: Dem_Init
\r
1505 void Dem_Init(void)
\r
1508 ChecksumType cSum;
\r
1509 const Dem_EventParameterType *eventParam;
\r
1512 * Validate and read out saved error log from non volatile memory
\r
1515 // Validate event records stored in primary memory
\r
1516 for (i = 0; i < DEM_MAX_NUMBER_EVENT_PRI_MEM; i++) {
\r
1517 cSum = calcChecksum(&priMemEventBuffer[i], sizeof(EventRecType)-sizeof(ChecksumType));
\r
1518 if ((cSum != priMemEventBuffer[i].checksum) || (priMemEventBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1519 // Unlegal record, clear the record
\r
1520 memset(&priMemEventBuffer[i], 0, sizeof(EventRecType));
\r
1523 // Valid, update current status
\r
1524 mergeEventStatusRec(&priMemEventBuffer[i]);
\r
1526 // Update occurrence counter on pre init stored freeze frames
\r
1527 updateFreezeFrameOccurrencePreInit(&priMemEventBuffer[i]);
\r
1531 // Validate extended data records stored in primary memory
\r
1532 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRI_MEM; i++) {
\r
1533 cSum = calcChecksum(&priMemExtDataBuffer[i], sizeof(ExtDataRecType)-sizeof(ChecksumType));
\r
1534 if ((cSum != priMemExtDataBuffer[i].checksum) || (priMemExtDataBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1535 // Unlegal record, clear the record
\r
1536 memset(&priMemExtDataBuffer[i], 0, sizeof(ExtDataRecType));
\r
1540 // Validate freeze frame records stored in primary memory
\r
1541 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++) {
\r
1542 cSum = calcChecksum(&priMemFreezeFrameBuffer[i], sizeof(FreezeFrameRecType)-sizeof(ChecksumType));
\r
1543 if ((cSum != priMemFreezeFrameBuffer[i].checksum) || (priMemFreezeFrameBuffer[i].eventId == DEM_EVENT_ID_NULL)) {
\r
1544 // Unlegal record, clear the record
\r
1545 memset(&priMemFreezeFrameBuffer[i], 0, sizeof(FreezeFrameRecType));
\r
1550 * Handle errors stored in temporary buffer (if any)
\r
1553 // Transfer updated event data to event memory
\r
1554 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1555 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1556 // Update the event memory
\r
1557 lookupEventIdParameter(eventStatusBuffer[i].eventId, &eventParam);
\r
1558 storeEventEvtMem(eventParam, &eventStatusBuffer[i]);
\r
1562 // Transfer extended data to event memory if necessary
\r
1563 for (i = 0; i < DEM_MAX_NUMBER_EXT_DATA_PRE_INIT; i++) {
\r
1564 if (preInitExtDataBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1565 lookupEventIdParameter(preInitExtDataBuffer[i].eventId, &eventParam);
\r
1566 storeExtendedDataEvtMem(eventParam, &preInitExtDataBuffer[i]);
\r
1570 // Transfer freeze frames to event memory
\r
1571 for (i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRE_INIT; i++) {
\r
1572 if (preInitFreezeFrameBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1573 lookupEventIdParameter(preInitFreezeFrameBuffer[i].eventId, &eventParam);
\r
1574 storeFreezeFrameDataEvtMem(eventParam, &preInitFreezeFrameBuffer[i]);
\r
1578 // Init the dtc filter
\r
1579 dtcFilter.dtcStatusMask = DEM_DTC_STATUS_MASK_ALL; // All allowed
\r
1580 dtcFilter.dtcKind = DEM_DTC_KIND_ALL_DTCS; // All kinds of DTCs
\r
1581 dtcFilter.dtcOrigin = DEM_DTC_ORIGIN_PRIMARY_MEMORY; // Primary memory
\r
1582 dtcFilter.filterWithSeverity = DEM_FILTER_WITH_SEVERITY_NO; // No Severity filtering
\r
1583 dtcFilter.dtcSeverityMask = DEM_SEVERITY_NO_SEVERITY; // Not used when filterWithSeverity is FALSE
\r
1584 dtcFilter.filterForFaultDetectionCounter = DEM_FILTER_FOR_FDC_NO; // No fault detection counter filtering
\r
1586 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1588 disableDtcStorage.storageDisabled = FALSE;
\r
1590 demState = DEM_INITIALIZED;
\r
1595 * Procedure: Dem_shutdown
\r
1598 void Dem_Shutdown(void)
\r
1600 (void)setOperationCycleState(DEM_ACTIVE, DEM_CYCLE_STATE_END); /** @req DEM047 */
\r
1602 demState = DEM_UNINITIALIZED; /** @req DEM368 */
\r
1607 * Interface for basic software scheduler
\r
1609 void Dem_MainFunction(void)
\r
1611 /** @req DEM125 */
\r
1616 /***************************************************
\r
1617 * Interface SW-Components via RTE <-> DEM (8.3.3) *
\r
1618 ***************************************************/
\r
1621 * Procedure: Dem_SetEventStatus
\r
1624 Std_ReturnType Dem_SetEventStatus(Dem_EventIdType eventId, Dem_EventStatusType eventStatus) /** @req DEM330 */
\r
1626 Std_ReturnType returnCode = E_OK;
\r
1628 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1630 returnCode = handleEvent(eventId, eventStatus);
\r
1634 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1635 returnCode = E_NOT_OK;
\r
1638 return returnCode;
\r
1643 * Procedure: Dem_ResetEventStatus
\r
1646 Std_ReturnType Dem_ResetEventStatus(Dem_EventIdType eventId) /** @req DEM331 */
\r
1648 Std_ReturnType returnCode = E_OK;
\r
1650 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1652 resetEventStatus(eventId); /** @req DEM186 */
\r
1656 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_RESETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1657 returnCode = E_NOT_OK;
\r
1660 return returnCode;
\r
1665 * Procedure: Dem_GetEventStatus
\r
1668 Std_ReturnType Dem_GetEventStatus(Dem_EventIdType eventId, Dem_EventStatusExtendedType *eventStatusExtended) /** @req DEM332 */
\r
1670 Std_ReturnType returnCode = E_OK;
\r
1672 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1674 getEventStatus(eventId, eventStatusExtended);
\r
1678 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTSTATUS_ID, DEM_E_UNINIT);
\r
1679 returnCode = E_NOT_OK;
\r
1682 return returnCode;
\r
1687 * Procedure: Dem_GetEventFailed
\r
1690 Std_ReturnType Dem_GetEventFailed(Dem_EventIdType eventId, boolean *eventFailed) /** @req DEM333 */
\r
1692 Std_ReturnType returnCode = E_OK;
\r
1694 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1696 getEventFailed(eventId, eventFailed);
\r
1700 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTFAILED_ID, DEM_E_UNINIT);
\r
1701 returnCode = E_NOT_OK;
\r
1704 return returnCode;
\r
1709 * Procedure: Dem_GetEventTested
\r
1712 Std_ReturnType Dem_GetEventTested(Dem_EventIdType eventId, boolean *eventTested)
\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 getEventTested(eventId, eventTested);
\r
1722 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEVENTTESTED_ID, DEM_E_UNINIT);
\r
1723 returnCode = E_NOT_OK;
\r
1726 return returnCode;
\r
1731 * Procedure: Dem_GetFaultDetectionCounter
\r
1734 Std_ReturnType Dem_GetFaultDetectionCounter(Dem_EventIdType eventId, sint8 *counter)
\r
1736 Std_ReturnType returnCode = E_OK;
\r
1738 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1740 returnCode = getFaultDetectionCounter(eventId, counter);
\r
1744 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETFAULTDETECTIONCOUNTER_ID, DEM_E_UNINIT);
\r
1745 returnCode = E_NOT_OK;
\r
1748 return returnCode;
\r
1753 * Procedure: Dem_SetOperationCycleState
\r
1756 Std_ReturnType Dem_SetOperationCycleState(Dem_OperationCycleIdType operationCycleId, Dem_OperationCycleStateType cycleState)
\r
1758 Std_ReturnType returnCode = E_OK;
\r
1760 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1762 returnCode = setOperationCycleState(operationCycleId, cycleState);
\r
1767 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETOPERATIONCYCLESTATE_ID, DEM_E_UNINIT);
\r
1768 returnCode = E_NOT_OK;
\r
1771 return returnCode;
\r
1776 * Procedure: Dem_GetDTCOfEvent
\r
1779 Std_ReturnType Dem_GetDTCOfEvent(Dem_EventIdType eventId, Dem_DTCKindType dtcKind, uint32* dtcOfEvent)
\r
1781 Std_ReturnType returnCode = E_NO_DTC_AVAILABLE;
\r
1782 const Dem_EventParameterType *eventParam;
\r
1784 if (demState == DEM_INITIALIZED) // No action is taken if the module is not started
\r
1786 lookupEventIdParameter(eventId, &eventParam);
\r
1788 if (eventParam != NULL) {
\r
1789 if (checkDtcKind(dtcKind, eventParam)) {
\r
1790 if (eventParam->DTCClassRef != NULL) {
\r
1791 *dtcOfEvent = eventParam->DTCClassRef->DTC; /** @req DEM269 */
\r
1792 returnCode = E_OK;
\r
1797 // Event Id not found
\r
1798 returnCode = E_NOT_OK;
\r
1803 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETDTCOFEVENT_ID, DEM_UNINITIALIZED);
\r
1804 returnCode = E_NOT_OK;
\r
1807 return returnCode;
\r
1811 /********************************************
\r
1812 * Interface BSW-Components <-> DEM (8.3.4) *
\r
1813 ********************************************/
\r
1816 * Procedure: Dem_ReportErrorStatus
\r
1819 void Dem_ReportErrorStatus( Dem_EventIdType eventId, Dem_EventStatusType eventStatus ) /** @req DEM107 */
\r
1822 switch (demState) {
\r
1823 case DEM_PREINITIALIZED:
\r
1824 // Update status and check if is to be stored
\r
1825 if ((eventStatus == DEM_EVENT_STATUS_PASSED) || (eventStatus == DEM_EVENT_STATUS_FAILED)) {
\r
1826 handlePreInitEvent(eventId, eventStatus); /** @req DEM168 */
\r
1830 case DEM_INITIALIZED:
\r
1831 (void)handleEvent(eventId, eventStatus); /** @req DEM167 */
\r
1834 case DEM_UNINITIALIZED:
\r
1836 // Uninitialized can not do anything
\r
1837 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_REPORTERRORSTATUS_ID, DEM_E_UNINIT);
\r
1841 } // switch (demState)
\r
1844 /*********************************
\r
1845 * Interface DCM <-> DEM (8.3.5) *
\r
1846 *********************************/
\r
1848 * Procedure: Dem_GetDTCStatusAvailabilityMask
\r
1851 Std_ReturnType Dem_GetDTCStatusAvailabilityMask(uint8 *dtcStatusMask) /** @req DEM014 */
\r
1853 *dtcStatusMask = DEM_DTC_STATUS_AVAILABILITY_MASK; // User configuration mask
\r
1854 *dtcStatusMask &= DEM_TEST_FAILED // Mask with supported bits /** @req DEM060 */
\r
1855 | DEM_TEST_FAILED_THIS_OPERATION_CYCLE
\r
1857 // | DEM_CONFIRMED_DTC TODO: Add support for this bit
\r
1858 | DEM_TEST_NOT_COMPLETED_SINCE_LAST_CLEAR
\r
1859 | DEM_TEST_FAILED_SINCE_LAST_CLEAR
\r
1860 | DEM_TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE
\r
1861 // | DEM_WARNING_INDICATOR_REQUESTED TODO: Add support for this bit
\r
1869 * Procedure: Dem_SetDTCFilter
\r
1872 Dem_ReturnSetDTCFilterType Dem_SetDTCFilter(uint8 dtcStatusMask,
\r
1873 Dem_DTCKindType dtcKind,
\r
1874 Dem_DTCOriginType dtcOrigin,
\r
1875 Dem_FilterWithSeverityType filterWithSeverity,
\r
1876 Dem_DTCSeverityType dtcSeverityMask,
\r
1877 Dem_FilterForFDCType filterForFaultDetectionCounter)
\r
1879 Dem_ReturnSetDTCFilterType returnCode = DEM_FILTER_ACCEPTED;
\r
1881 if (demState == DEM_INITIALIZED) {
\r
1882 // Check dtcKind parameter
\r
1883 VALIDATE_RV((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS), DEM_SETDTCFILTER_ID, DEM_E_PARAM_DATA, DEM_WRONG_FILTER);
\r
1885 // Check dtcOrigin parameter
\r
1886 VALIDATE_RV((dtcOrigin == DEM_DTC_ORIGIN_SECONDARY_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_PRIMARY_MEMORY)
\r
1887 || (dtcOrigin == DEM_DTC_ORIGIN_PERMANENT_MEMORY) || (dtcOrigin == DEM_DTC_ORIGIN_MIRROR_MEMORY), DEM_SETDTCFILTER_ID, DEM_E_PARAM_DATA, DEM_WRONG_FILTER);
\r
1889 // Check filterWithSeverity and dtcSeverityMask parameter
\r
1890 VALIDATE_RV(((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_NO)
\r
1891 || ((filterWithSeverity == DEM_FILTER_WITH_SEVERITY_YES)
\r
1892 && (!(dtcSeverityMask & (Dem_DTCSeverityType)~(DEM_SEVERITY_MAINTENANCE_ONLY | DEM_SEVERITY_CHECK_AT_NEXT_FALT | DEM_SEVERITY_CHECK_IMMEDIATELY))))), DEM_SETDTCFILTER_ID, DEM_E_PARAM_DATA, DEM_WRONG_FILTER);
\r
1894 // Check filterForFaultDetectionCounter parameter
\r
1895 VALIDATE_RV((filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_YES) || (filterForFaultDetectionCounter == DEM_FILTER_FOR_FDC_NO), DEM_SETDTCFILTER_ID, DEM_E_PARAM_DATA, DEM_WRONG_FILTER);
\r
1897 // Yes all parameters correct, set the new filters. /** @req DEM057 */
\r
1898 dtcFilter.dtcStatusMask = dtcStatusMask;
\r
1899 dtcFilter.dtcKind = dtcKind;
\r
1900 dtcFilter.dtcOrigin = dtcOrigin;
\r
1901 dtcFilter.filterWithSeverity = filterWithSeverity;
\r
1902 dtcFilter.dtcSeverityMask = dtcSeverityMask;
\r
1903 dtcFilter.filterForFaultDetectionCounter = filterForFaultDetectionCounter;
\r
1904 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
1906 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETDTCFILTER_ID, DEM_E_UNINIT);
\r
1907 returnCode = DEM_WRONG_FILTER;
\r
1910 return returnCode;
\r
1915 * Procedure: Dem_GetStatusOfDTC
\r
1918 Dem_ReturnGetStatusOfDTCType Dem_GetStatusOfDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, Dem_EventStatusExtendedType* status) {
\r
1919 Dem_ReturnGetStatusOfDTCType returnCode = DEM_STATUS_FAILED;
\r
1920 EventStatusRecType *eventRec;
\r
1922 if (demState == DEM_INITIALIZED) {
\r
1923 if (lookupDtcEvent(dtc, &eventRec)) {
\r
1924 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
1925 if (checkDtcOrigin(dtcOrigin,eventRec->eventParamRef)) {
\r
1926 *status = eventRec->eventStatusExtended; /** @req DEM059 */
\r
1927 returnCode = DEM_STATUS_OK;
\r
1930 returnCode = DEM_STATUS_WRONG_DTCORIGIN; /** @req DEM171 */
\r
1934 returnCode = DEM_STATUS_WRONG_DTCKIND;
\r
1938 returnCode = DEM_STATUS_WRONG_DTC; /** @req DEM172 */
\r
1941 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETSTATUSOFDTC_ID, DEM_E_UNINIT);
\r
1942 returnCode = DEM_STATUS_FAILED;
\r
1945 return returnCode;
\r
1950 * Procedure: Dem_GetNumberOfFilteredDtc
\r
1953 Dem_ReturnGetNumberOfFilteredDTCType Dem_GetNumberOfFilteredDtc(uint16 *numberOfFilteredDTC) {
\r
1955 uint16 numberOfFaults = 0;
\r
1956 Dem_ReturnGetNumberOfFilteredDTCType returnCode = DEM_NUMBER_OK;
\r
1958 if (demState == DEM_INITIALIZED) {
\r
1959 //Dem_DisableEventStatusUpdate();
\r
1961 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
1962 if (eventStatusBuffer[i].eventId != DEM_EVENT_ID_NULL) {
\r
1963 if (matchEventWithDtcFilter(&eventStatusBuffer[i])) {
\r
1964 if (eventStatusBuffer[i].eventParamRef->DTCClassRef != NULL) {
\r
1971 //Dem_EnableEventStatusUpdate();
\r
1973 *numberOfFilteredDTC = numberOfFaults; /** @req DEM061 */
\r
1975 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETNUMBEROFFILTEREDDTC_ID, DEM_E_UNINIT);
\r
1976 returnCode = DEM_NUMBER_FAILED;
\r
1979 return returnCode;
\r
1984 * Procedure: Dem_GetNextFilteredDTC
\r
1987 Dem_ReturnGetNextFilteredDTCType Dem_GetNextFilteredDTC(uint32 *dtc, Dem_EventStatusExtendedType *dtcStatus)
\r
1989 Dem_ReturnGetNextFilteredDTCType returnCode = DEM_FILTERED_OK;
\r
1990 boolean dtcFound = FALSE;
\r
1992 if (demState == DEM_INITIALIZED) {
\r
1993 // TODO: This job should be done in an more advanced way according to Dem217
\r
1994 while ((!dtcFound) && (dtcFilter.faultIndex != 0)) {
\r
1995 dtcFilter.faultIndex--;
\r
1996 if (eventStatusBuffer[dtcFilter.faultIndex].eventId != DEM_EVENT_ID_NULL) {
\r
1997 if (matchEventWithDtcFilter(&eventStatusBuffer[dtcFilter.faultIndex])) {
\r
1998 if (eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef != NULL) {
\r
1999 *dtc = eventStatusBuffer[dtcFilter.faultIndex].eventParamRef->DTCClassRef->DTC; /** @req DEM216 */
\r
2000 *dtcStatus = eventStatusBuffer[dtcFilter.faultIndex].eventStatusExtended;
\r
2008 dtcFilter.faultIndex = DEM_MAX_NUMBER_EVENT;
\r
2009 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
2012 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETNEXTFILTEREDDTC_ID, DEM_E_UNINIT);
\r
2013 returnCode = DEM_FILTERED_NO_MATCHING_DTC;
\r
2016 return returnCode;
\r
2021 * Procedure: Dem_GetTranslationType
\r
2024 Dem_ReturnTypeOfDtcSupportedType Dem_GetTranslationType(void)
\r
2026 return DEM_TYPE_OF_DTC_SUPPORTED; /** @req DEM231 */
\r
2031 * Procedure: Dem_ClearDTC
\r
2034 Dem_ReturnClearDTCType Dem_ClearDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin) /** @req DEM009 */
\r
2036 Dem_ReturnClearDTCType returnCode = DEM_CLEAR_OK;
\r
2037 Dem_EventIdType eventId;
\r
2038 const Dem_EventParameterType *eventParam;
\r
2041 if (demState == DEM_INITIALIZED) {
\r
2042 // Loop through the event buffer
\r
2043 for (i = 0; i < DEM_MAX_NUMBER_EVENT; i++) {
\r
2044 eventId = eventStatusBuffer[i].eventId;
\r
2045 if (eventId != DEM_EVENT_ID_NULL) {
\r
2046 eventParam = eventStatusBuffer[i].eventParamRef;
\r
2047 if (eventParam != NULL) {
\r
2048 //lint --e(506) PC-Lint exception Misra 13.7, 14.1 Allow configuration variables in boolean expression
\r
2049 //lint --e(774) PC-Lint exception Related to MISRA 13.7
\r
2050 if ((DEM_CLEAR_ALL_EVENTS == STD_ON) || (eventParam->DTCClassRef != NULL)) {
\r
2051 if (checkDtcKind(dtcKind, eventParam)) {
\r
2052 if (checkDtcGroup(dtc, eventParam)) {
\r
2053 boolean dtcOriginFound = FALSE;
\r
2054 for (j = 0; (j < DEM_MAX_NR_OF_EVENT_DESTINATION) && (!dtcOriginFound) ; j++){
\r
2055 dtcOriginFound =(eventParam->EventClass->EventDestination[j] == dtcOrigin);
\r
2057 //if (j-1 < DEM_MAX_NR_OF_EVENT_DESTINATION) {
\r
2058 if (dtcOriginFound) {
\r
2059 // Yes! All conditions met.
\r
2060 switch (dtcOrigin)
\r
2062 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2063 /** @req DEM077 */
\r
2064 deleteEventPriMem(eventParam);
\r
2065 deleteFreezeFrameDataPriMem(eventParam);
\r
2066 deleteExtendedDataPriMem(eventParam);
\r
2067 deleteEventStatusRec(eventParam); // TODO: Shall this be done or just resetting the status?
\r
2070 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2071 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2072 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2073 // Not yet supported
\r
2074 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2075 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2078 returnCode = DEM_CLEAR_WRONG_DTCORIGIN;
\r
2087 // Fatal error, no event parameters found for the stored event!
\r
2088 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNEXPECTED_EXECUTION);
\r
2093 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_CLEARDTC_ID, DEM_E_UNINIT);
\r
2094 returnCode = DEM_CLEAR_FAILED;
\r
2097 return returnCode;
\r
2102 * Procedure: Dem_DisableDTCStorage
\r
2105 Dem_ReturnControlDTCStorageType Dem_DisableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind) /** @req DEM035 */
\r
2107 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2109 if (demState == DEM_INITIALIZED) {
\r
2110 // Check dtcGroup parameter
\r
2111 if (dtcGroup == DEM_DTC_GROUP_ALL_DTCS) {
\r
2112 // Check dtcKind parameter
\r
2113 if ((dtcKind == DEM_DTC_KIND_ALL_DTCS) || (dtcKind == DEM_DTC_KIND_EMISSION_REL_DTCS)) {
\r
2114 /** @req DEM079 */
\r
2115 disableDtcStorage.dtcGroup = dtcGroup;
\r
2116 disableDtcStorage.dtcKind = dtcKind;
\r
2117 disableDtcStorage.storageDisabled = TRUE;
\r
2119 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2122 returnCode = DEM_CONTROL_DTC_WRONG_DTCGROUP;
\r
2125 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_DISABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
2126 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2129 return returnCode;
\r
2134 * Procedure: Dem_EnableDTCStorage
\r
2137 Dem_ReturnControlDTCStorageType Dem_EnableDTCStorage(Dem_DTCGroupType dtcGroup, Dem_DTCKindType dtcKind)
\r
2139 Dem_ReturnControlDTCStorageType returnCode = DEM_CONTROL_DTC_STORAGE_OK;
\r
2141 if (demState == DEM_INITIALIZED) {
\r
2142 // TODO: Behavior is not defined if group or kind do not match active settings, therefore the filter is just switched off.
\r
2143 (void)dtcGroup; (void)dtcKind; // Just to make get rid of PC-Lint warnings
\r
2144 disableDtcStorage.storageDisabled = FALSE; /** @req DEM080 */
\r
2146 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_ENABLEDTCSTORAGE_ID, DEM_E_UNINIT);
\r
2147 returnCode = DEM_CONTROL_DTC_STORAGE_N_OK;
\r
2150 return returnCode;
\r
2154 * Procedure: Dem_GetExtendedDataRecordByDTC
\r
2157 Dem_ReturnGetExtendedDataRecordByDTCType Dem_GetExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint8 *destBuffer, uint16 *bufSize)
\r
2159 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_RECORD_WRONG_DTC;
\r
2160 EventStatusRecType *eventRec;
\r
2161 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2162 ExtDataRecType *extData;
\r
2163 uint16 posInExtData = 0;
\r
2165 if (demState == DEM_INITIALIZED) {
\r
2166 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2167 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2168 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2169 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2170 if (*bufSize >= extendedDataRecordClass->DataSize) {
\r
2171 switch (dtcOrigin)
\r
2173 case DEM_DTC_ORIGIN_PRIMARY_MEMORY:
\r
2174 if (lookupExtendedDataPriMem(eventRec->eventId, &extData)) {
\r
2175 // Yes all conditions met, copy the extended data record to destination buffer.
\r
2176 memcpy(destBuffer, &extData->data[posInExtData], extendedDataRecordClass->DataSize); /** @req DEM075 */
\r
2177 *bufSize = extendedDataRecordClass->DataSize;
\r
2178 returnCode = DEM_RECORD_OK;
\r
2181 // The record number is legal but no record was found for the DTC
\r
2183 returnCode = DEM_RECORD_OK;
\r
2187 case DEM_DTC_ORIGIN_SECONDARY_MEMORY:
\r
2188 case DEM_DTC_ORIGIN_PERMANENT_MEMORY:
\r
2189 case DEM_DTC_ORIGIN_MIRROR_MEMORY:
\r
2190 // Not yet supported
\r
2191 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2192 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_NOT_IMPLEMENTED_YET);
\r
2195 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2200 returnCode = DEM_RECORD_BUFFERSIZE;
\r
2204 returnCode = DEM_RECORD_NUMBER;
\r
2208 returnCode = DEM_RECORD_WRONG_DTCORIGIN;
\r
2212 returnCode = DEM_RECORD_DTCKIND;
\r
2216 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
2217 returnCode = DEM_RECORD_WRONG_DTC;
\r
2220 return returnCode;
\r
2225 * Procedure: Dem_GetSizeOfExtendedDataRecordByDTC
\r
2228 Dem_ReturnGetSizeOfExtendedDataRecordByDTCType Dem_GetSizeOfExtendedDataRecordByDTC(uint32 dtc, Dem_DTCKindType dtcKind, Dem_DTCOriginType dtcOrigin, uint8 extendedDataNumber, uint16 *sizeOfExtendedDataRecord)
\r
2230 Dem_ReturnGetExtendedDataRecordByDTCType returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2231 EventStatusRecType *eventRec;
\r
2232 Dem_ExtendedDataRecordClassType const *extendedDataRecordClass = NULL;
\r
2233 uint16 posInExtData;
\r
2235 if (demState == DEM_INITIALIZED) {
\r
2236 if (lookupDtcEvent(dtc, &eventRec)) {
\r
2237 if (checkDtcKind(dtcKind, eventRec->eventParamRef)) {
\r
2238 if (checkDtcOrigin(dtcOrigin, eventRec->eventParamRef)) {
\r
2239 if (lookupExtendedDataRecNumParam(extendedDataNumber, eventRec->eventParamRef, &extendedDataRecordClass, &posInExtData)) {
\r
2240 *sizeOfExtendedDataRecord = extendedDataRecordClass->DataSize; /** @req DEM076 */
\r
2241 returnCode = DEM_GET_SIZEOFEDRBYDTC_OK;
\r
2244 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_RNUM;
\r
2248 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCOR;
\r
2252 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTCKI;
\r
2256 DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETSIZEOFEXTENDEDDATARECORDBYDTC_ID, DEM_E_UNINIT);
\r
2257 returnCode = DEM_GET_SIZEOFEDRBYDTC_W_DTC;
\r
2260 return returnCode;
\r
2263 /***********************************
\r
2264 * OBD-specific Interfaces (8.3.6) *
\r
2265 ***********************************/
\r