/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/*
* General requirements
*/
/* Disable MISRA 2004 rule 16.2, MISRA 2012 rule 17.2.
* This because of recursive calls to readDidData.
* */
//lint -estring(974,*recursive*)
/* @req DCM273 */
/* @req DCM272 */
/* @req DCM696 */
/* @req DCM039 */
/* @req DCM269 */
/* @req DCM271 */
/* @req DCM275 */
/* !req DCM038 Paged buffer not supported */
/* !req DCM700 DTCStatusMask = 0 should be handled by Dcm, but how? */
/* !req DCM085 */
/* @req DCM531 A jump to bootloader is possible only with services DiagnosticSessionControl and LinkControl services */
/* @req DCM527 At first call of an operation using the Dcm_OpStatusType, OpStatus should be DCM_INITIAL */
/* !req DCM528 E_FORCE_RCRRP not supported return for all operations */
/* !req DCM530 E_PENDING not supported return for all operations */
/* @req DCM077 When calling DEM for OBD services, DCM shall use the following values for the parameter DTCOrigin: Service $0A uses DEM_DTC_ORIGIN_PERMANENT_MEMORY All other services use DEM_DTC_ORIGIN_PRIMARY_MEMORY */
#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_REQUESTEMISSIONRELATEDDIAGNOSTICTROUBLECODES) || defined(DCM_USE_SERVICE_REQUESTEMISSIONRELATEDDTCSDETECTEDDURINGCURRENTORLASTCOMPLETEDDRIVINGCYCLE)
#if defined(USE_DEM)
#include "Dem.h"/* @req DCM332 */
#else
#warning "Dcm: UDS services 0x14, 0x18 and/or 0x85 will not work without Dem."
#warning "Dcm: OBD services $02, $03, $04 and/or $07 will not work without Dem."
#endif
#endif
#include "MemMap.h"
#if defined(USE_MCU)
#include "Mcu.h"
#endif
#ifndef DCM_NOT_SERVICE_COMPONENT
#include "Rte_Dcm.h"
#endif
#if defined(DCM_USE_SERVICE_REQUESTTRANSFEREXIT) || defined(DCM_USE_SERVICE_TRANSFERDATA) || defined(DCM_USE_SERVICE_REQUESTDOWNLOAD)
#define DCM_USE_UPLOAD_DOWNLOAD
#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 1u
#define SF_INDEX 1
#define SF_LEN 1
#define DTC_LEN 3
#define FF_REC_NUM_LEN 1
#define HALF_BYTE 4
#define OFFSET_ONE_BYTE 8
#define OFFSET_TWO_BYTES 16
#define OFFSET_THREE_BYTES 24
/* 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
#define IS_VALID_IOCTRL_PARAM(_x) ((_x) <= DCM_SHORT_TERM_ADJUSTMENT)
#define TO_SIGNAL_BIT(_x) (uint8)(1u<<(7u-((_x)%8u)))
/*OBD RequestCurrentPowertrainDiagnosticData*/
#define PIDZERO 0
#define DATAZERO 0
#define INFOTYPE_ZERO 0
#define PID_LEN 1
#define RECORD_NUM_ZERO 0
#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
/* CommunicationControl */
#define CC_CTP_INDEX 2
#define IS_SUPPORTED_0x28_SUBFUNCTION(_x) ((_x) < 4u)
#define UDS_0x28_NOF_COM_TYPES 3u
#define UDS_0x28_NOF_SUB_FUNCTIONS 4u
#define IS_VALID_0x28_COM_TYPE(_x) (((_x) > 0u) && ((_x) < 4u))
/*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
#define DATA_ELEMENT_INDEX_OF_PID_NOT_SUPPORTED 0
#define OBD_SERVICE_2_PID_AND_FRAME_SIZE 2u
#define OBD_SERVICE_2_PID_INDEX 0u
#define OBD_SERVICE_2_FRAME_INDEX 1u
/*OBD RequestEmissionRelatedDiagnosticTroubleCodes service03 07*/
#define EMISSION_DTCS_HIGH_BYTE(dtc) (((uint32)(dtc) >> 16) & 0xFFu)
#define EMISSION_DTCS_LOW_BYTE(dtc) (((uint32)(dtc) >> 8) & 0xFFu)
#define OBD_RESPONSE_DTC_MAX_NUMS 126
/*OBD OnBoardMonitoringTestResultsSpecificMonitoredSystems service06*/
#define OBDMID_LEN 1u
#define OBDMID_DATA_START_INDEX 1u
#define OBDM_TID_LEN 1u
#define OBDM_UASID_LEN 1u
#define OBDM_TESTRESULT_LEN 6u
#define SUPPORTED_MAX_OBDMID_REQUEST_LEN 1u
#define SUPPORTED_OBDM_OUTPUT_LEN (OBDM_TID_LEN + OBDM_UASID_LEN + OBDM_TESTRESULT_LEN)
#define SUPPORTED_OBDMIDS_DATA_LEN 4u
#define AVAIL_TO_SUPPORTED_OBDMID_OFFSET_MIN 0x01
#define AVAIL_TO_SUPPORTED_OBDMID_OFFSET_MAX 0x20
#define MAX_REQUEST_OBDMID_NUM 6u
#define IS_AVAILABILITY_OBDMID(_x) ((0 == ((_x) % 0x20)) && ((_x) <= 0xE0))
#define OBDM_LSB_MASK 0xFFu
/*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 IS_AVAILABILITY_PID(_x) ( (0 == ((_x) % 0x20)) && ((_x) <= 0xE0))
#define IS_AVAILABILITY_INFO_TYPE(_x) IS_AVAILABILITY_PID(_x)
#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)
/* UDS ReadDataByPeriodicIdentifier */
#define TO_PERIODIC_DID(_x) (DCM_PERODICDID_HIGH_MASK + (uint16)(_x))
/* Maximum length for periodic Dids */
#define MAX_PDID_DATA_SIZE 7
/* CAN */
#define MAX_TYPE2_PERIODIC_DID_LEN_CAN 7
#define MAX_TYPE1_PERIODIC_DID_LEN_CAN 5
/* Flexray */
/* IMPROVEMENT: Maximum length for flexray? */
#define MAX_TYPE2_PERIODIC_DID_LEN_FLEXRAY 0
#define MAX_TYPE1_PERIODIC_DID_LEN_FLEXRAY 0
/* Ip */
/* IMPROVEMENT: Maximum length for ip? */
#define MAX_TYPE2_PERIODIC_DID_LEN_IP 0
#define MAX_TYPE1_PERIODIC_DID_LEN_IP 0
#define TIMER_DECREMENT(timer) \
if (timer >= DCM_MAIN_FUNCTION_PERIOD_TIME_MS) { \
timer = timer - DCM_MAIN_FUNCTION_PERIOD_TIME_MS; \
} \
/* UDS Linkcontrol */
#define LINKCONTROL_SUBFUNC_VERIFY_BAUDRATE_TRANS_WITH_FIXED_BAUDRATE 0x01
#define LINKCONTROL_SUBFUNC_VERIFY_BAUDRATE_TRANS_WITH_SPECIFIC_BAUDRATE 0x02
#define LINKCONTROL_
评论3