/* -------------------------------- Arctic Core ------------------------------
* Arctic Core - the open source AUTOSAR platform http://arccore.com
*
* Copyright (C) 2009 ArcCore AB <contact@arccore.com>
*
* This source code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by the
* Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
* -------------------------------- Arctic Core ------------------------------*/
//lint -esym(754, SID) //Structure member SID not used in udsReadDtcInfoSub_0x01_0x07_0x11_0x12() and udsReadDtcInfoSub_0x02_0x0A_0x0F_0x13_0x15()
/*
* General requirements
*/
/** @req DCM273 */ /** @req DCM272 */
/** @req DCM039 */ /** @req DCM038 */ /** @req DCM269 */
/** @req DCM271 */ /** @req DCM274 */ /** @req DCM275 */ /** @req DCM424 */
/** @req DCM007 */
#include <string.h>
#include "Dcm.h"
#include "Dcm_Internal.h"
#if defined (DCM_USE_SERVICE_CLEARDIAGNOSTICINFORMATION)|| defined(DCM_USE_SERVICE_READDTCINFORMATION) || defined(DCM_USE_SERVICE_CONTROLDTCSETTING) \
|| defined (DCM_USE_SERVICE_REQUESTPOWERTRAINFREEZEFRAMEDATA) || defined(DCM_USE_SERVICE_CLEAREMISSIONRELATEDDIAGNOSTICDATA) \
|| defined(DCM_USE_SERVICE_REQUESTEMISSIONRELATEDDTCS) || defined(DCM_USE_SERVICE_REQUESTEMISSIONRELATEDDTCSDETECTEDDURINGCURRENTORLASCOMPLETEDDRIVINGCYCLE)
#if defined(USE_DEM)
#include "Dem.h"
#else
#warning Dcm: UDS services ClearDiagnosticInformation, ReadDTCInformation, ControlDTCSetting, RequestPowertrainFreezeFrameData, ClearEmissionRelatedDiagnosticData,\
RequestEmissionRelatedDTCs and/or RequestEmissionRelatedDTCsDetectedDuringCurrentOrLasCompletedDrivingCycle will not work without Dem.
#endif
#endif
#include "MemMap.h"
#if defined(USE_MCU)
#include "Mcu.h"
#endif
/*
* Macros
*/
#define ZERO_SUB_FUNCTION 0x00
#define DCM_FORMAT_LOW_MASK 0x0F
#define DCM_FORMAT_HIGH_MASK 0xF0
#define DCM_MEMORY_ADDRESS_MASK 0x00FFFFFF
#define DCM_DID_HIGH_MASK 0xFF00
#define DCM_DID_LOW_MASK 0xFF
#define DCM_PERODICDID_HIGH_MASK 0xF200
#define SID_AND_DDDID_LEN 0x4
#define SDI_AND_MS_LEN 0x4
#define SID_AND_SDI_LEN 0x6
#define SID_AND_PISDR_LEN 0x7
/* == Parser macros == */
/* General */
#define SID_INDEX 0
#define SID_LEN 1
#define SF_INDEX 1
#define SF_LEN 1
#define PID_BUFFER_SIZE 255 // OBD
#define DTC_LEN 3
#define FF_REC_NUM_LEN 1
/* Read/WriteMemeoryByAddress */
#define ALFID_INDEX 1
#define ALFID_LEN 1
#define ADDR_START_INDEX 2
/* DynamicallyDefineDataByIdentifier */
#define DDDDI_INDEX 2
#define DDDDI_LEN 2
#define DYNDEF_ALFID_INDEX 4
#define DYNDEF_ADDRESS_START_INDEX 5
/* InputOutputControlByIdentifier */
#define IOI_INDEX 1
#define IOI_LEN 2
#define IOCP_INDEX 3
#define IOCP_LEN 1
#define COR_INDEX 4
/* CommunicationControl */
#define CC_CTP_INDEX 2
#define COMM_CTRL_ISO_RES_SF_LOW 0x04
#define COMM_CTRL_ISO_RES_SF_HIGH 0x3F
#define COMM_CTRL_ISO_RES_SF 0x7F
#define IS_IN_ISO_RESERVED_RANGE(_x) ((_x >= COMM_CTRL_ISO_RES_SF_LOW) && (_x <= COMM_CTRL_ISO_RES_SF_HIGH))
#define IS_ISO_RESERVED(_x) (IS_IN_ISO_RESERVED_RANGE(_x) || (COMM_CTRL_ISO_RES_SF == _x))
/*OBD RequestCurrentPowertrainDiagnosticData*/
#define PIDZERO 0
#define DATAZERO 0
#define INFOTYPE_ZERO 0
#define PID_LEN 1
#define RECORD_NUM 0
#define HALF_BYTE 4
#define OFFSET_ONE_BYTE 8
#define OFFSET_TWO_BYTES 16
#define OFFSET_THREE_BYTES 24
#define SUPPRTED_PIDS_DATA_LEN 4
#define LEAST_BIT_MASK ((uint8)0x01u)
#define OBD_DATA_LSB_MASK ((uint32)0x000000FFu)
#define OBD_REQ_MESSAGE_LEN_ONE_MIN 2
#define OBD_REQ_MESSAGE_LEN_MAX 7
#define AVAIL_TO_SUPPORTED_PID_OFFSET_MIN 0x01
#define AVAIL_TO_SUPPORTED_PID_OFFSET_MAX 0x20
#define AVAIL_TO_SUPPORTED_INFOTYPE_OFFSET_MIN 0x01
#define AVAIL_TO_SUPPORTED_INFOTYPE_OFFSET_MAX 0x20
#define MAX_REQUEST_PID_NUM 6
#define LENGTH_OF_DTC 2
/*OBD RequestCurrentPowertrainDiagnosticData*/
#define FF_NUM_LEN 1
#define OBD_DTC_LEN 2
#define OBD_SERVICE_TWO ((uint8)0x02u)
#define MAX_PID_FFNUM_NUM 3
#define OBD_REQ_MESSAGE_LEN_TWO_MIN 3
#if defined(DEM_MAX_NR_OF_RECORDS_IN_FREEZEFRAME_DATA)
#define DCM_MAX_PID_NUM_IN_FF DEM_MAX_NR_OF_RECORDS_IN_FREEZEFRAME_DATA
#else
#define DCM_MAX_PID_NUM_IN_FF 0
#endif
/*OBD RequestEmissionRelatedDiagnosticTroubleCodes service03 07*/
#define EMISSION_DTCS_HIGH_BYTE(dtc) (((uint32)(dtc) >> 8) & 0xFFu)
#define EMISSION_DTCS_LOW_BYTE(dtc) ((uint32)(dtc) & 0xFFu)
#define OBD_RESPONSE_DTC_MAX_NUMS 126
/*OBD Requestvehicleinformation service09*/
#define OBD_TX_MAXLEN 0xFF
#define MAX_REQUEST_VEHINFO_NUM 6
#define OBD_SERVICE_FOUR 0x04
#define OBD_VIN_LENGTH 17
#define BYTES_TO_DTC(hb, mb, lb) (((uint32)(hb) << 16) | ((uint32)(mb) << 8) | (uint32)(lb))
#define DTC_HIGH_BYTE(dtc) (((uint32)(dtc) >> 16) & 0xFFu)
#define DTC_MID_BYTE(dtc) (((uint32)(dtc) >> 8) & 0xFFu)
#define DTC_LOW_BYTE(dtc) ((uint32)(dtc) & 0xFFu)
typedef enum {
DCM_READ_MEMORY = 0,
DCM_WRITE_MEMORY,
} DspMemoryServiceType;
typedef enum {
DCM_DSP_RESET_NO_RESET,
DCM_DSP_RESET_PENDING,
DCM_DSP_RESET_WAIT_TX_CONF,
} DcmDspResetStateType;
typedef struct {
DcmDspResetStateType resetPending;
PduIdType resetPduId;
PduInfoType *pduTxData;
Dcm_EcuResetType resetType;
} DspUdsEcuResetDataType;
typedef struct {
boolean sessionPending;
PduIdType sessionPduId;
Dcm_SesCtrlType session;
} DspUdsSessionControlDataType;
typedef enum {
DCM_DID_IDLE,
DCM_DID_PENDING,
} ReadDidPendingStateType;
typedef struct {
ReadDidPendingStateType state;
const PduInfoType* pduRxData;
PduInfoType* pduTxData;
} DspUdsDidPendingType;
static DspUdsEcuResetDataType dspUdsEcuResetData;
static DspUdsSessionControlDataType dspUdsSessionControlData;
static boolean dspWritePending;
static DspUdsDidPendingType dspUdsReadDidPending;
static DspUdsDidPendingType dspUdsWriteDidPending;
typedef struct {
boolean reqInProgress;
Dcm_SecLevelType reqSecLevel;
const Dcm_DspSecurityRowType *reqSecLevelRef;
} DspUdsSecurityAccessDataType;
static DspUdsSecurityAccessDataType dspUdsSecurityAccesData;
typedef enum{
DCM_MEMORY_UNUSED,
DCM_MEMORY_READ,
DCM_MEMORY_WRITE,
DCM_MEMORY_FAILED
}Dcm_DspMemoryStateType;
static Dcm_DspMemoryStateType dspMemoryState;
typedef enum{
DCM_DDD_SOURCE_DEFAULT,
DCM_DDD_SOURCE_DID,
DCM_DDD_SOURCE_ADDRESS
}Dcm_DspDDDSourceKindType;
typedef struct{
uint32 PDidTxCounter;
uint32 PDidTxCounterLimit;
uint8 PeriodicDid;
}Dcm_pDidType;/* a type to save the periodic DID and cycle */
typedef struct{
Dcm_pDidType dspPDid[DCM_LIMITNUMBER_PERIODDATA]; /*a buffer to save the periodic DID and cycle */
uint8 PDidNr; /* note the number of periodic DID is used */
}Dsp_pDidRefType;
static Dsp_pDidRefType dspPDidRef;
typedef struct{
uint8 formatOrPosition; /*note the formate of address and size*/
uint8 memoryIdentifier;
uint32 SourceAddressOrDid; /*note the memory address */
uint16 Size; /*note the memory size */
Dcm_DspDDDSourceKindType DDDTpyeID;
}Dcm_DspDDDSourceType;
typedef struct{
uint16 DynamicallyDid;
Dcm_DspDDDSourceType DDDSource[DCM_MAX_DDDSOURCE_NUMBER];
}
Dcm_DspDDDType;
static Dcm_DspDDDType dspDDD[DCM_MAX_DDD_NUMBER];
/*
* * static Function
*/
static boolean LookupDDD(uint16 didNr, const Dcm_DspDDDType **DDid);
static Dcm_NegativeResponseCodeType checkAddressRange(DspMemoryServiceType serviceType, uint8 memoryIdentifier, uint32 memoryAddress, uint32 length);
static const Dcm_DspMemoryRangeInfo* findRange(const Dcm_DspMemoryRangeInfo *memoryRangePtr, uint32 memoryAddress, uint32 length);
static Dcm_NegativeResp
- 1
- 2
前往页