#define SID_AND_ALFID_LEN6 0x6\r
#define SID_AND_ALFID_LEN7 0x7\r
\r
+/* == Parser macros == */\r
+/* General */\r
+#define SID_INDEX 0\r
+#define SID_LEN 1\r
+#define SF_INDEX 1\r
+#define SF_LEN 1\r
+/* Read/WriteMemeoryByAddress */\r
+#define ALFID_INDEX 1\r
+#define ALFID_LEN 1\r
+#define ADDR_START_INDEX 2\r
+/* DynamicallyDefineDataByIdentifier */\r
+#define DDDDI_INDEX 2\r
+#define DDDDI_LEN 2\r
+#define DYNDEF_ALFID_INDEX 4\r
+#define DYNDEF_ADDRESS_START_INDEX 5\r
+\r
#define BYTES_TO_DTC(hb, mb, lb) (((uint32)(hb) << 16) | ((uint32)(mb) << 8) | (uint32)(lb))\r
#define DTC_HIGH_BYTE(dtc) (((uint32)(dtc) >> 16) & 0xFFu)\r
#define DTC_MID_BYTE(dtc) (((uint32)(dtc) >> 8) & 0xFFu)\r
#define DTC_LOW_BYTE(dtc) ((uint32)(dtc) & 0xFFu)\r
\r
+typedef enum {\r
+ DCM_READ_MEMORY = 0,\r
+ DCM_WRITE_MEMORY,\r
+} DspMemoryServiceType;\r
\r
typedef struct {\r
boolean resetPending;\r
\r
typedef struct{\r
uint8 formatOrPosition; /*note the formate of address and size*/\r
+ uint8 memoryIdentifier;\r
uint32 SourceAddressOrDid; /*note the memory address */\r
uint16 Size; /*note the memory size */\r
Dcm_DspDDDTpyeID DDDTpyeID;\r
* * static Function\r
*/\r
\r
-static boolean lookupReadMemory(uint32 memoryAddress,\r
- uint8 memoryAddressFormat,\r
- uint32 memorySize,\r
- const Dcm_DspMemoryIdInfo **MemoryPtr);\r
-\r
static boolean LookupDDD(uint16 didNr, const Dcm_DspDDDType **DDid);\r
-\r
-static boolean checkWriteMemoryByAddress(boolean useId,\r
- uint32 memoryAddress,\r
- uint8 memoryAddressFormat,\r
- uint32 memorySize,\r
- const Dcm_DspMemoryIdInfo *dspMemory);\r
-\r
+static Dcm_NegativeResponseCodeType checkAddressRange(DspMemoryServiceType serviceType, uint8 memoryIdentifier, uint32 memoryAddress, uint32 length);\r
+static const Dcm_DspMemoryRangeInfo* findRange(const Dcm_DspMemoryRangeInfo *memoryRangePtr, uint32 memoryAddress, uint32 length);\r
+static Dcm_NegativeResponseCodeType writeMemoryData(Dcm_OpStatusType* OpStatus, uint8 memoryIdentifier, uint32 MemoryAddress, uint32 MemorySize, uint8 *SourceData);\r
\r
/*\r
* end \r
/* clear periodic send buffer */\r
memset(&dspPDidRef,0,sizeof(dspPDidRef));\r
/* clear dynamically Did buffer */\r
- memset(&dspDDD[0],0,sizeof(dspDDD)); \r
+ memset(&dspDDD[0],0,sizeof(dspDDD));\r
}\r
\r
void DspMemoryMainFunction(void)\r
for (index = 0; pEventParaTemp->FreezeFrameClassRef[index] != NULL; index++){\r
if (pEventParaTemp->FreezeFrameClassRef[index]->FFRecordNumber == RecordNumber) {\r
// Calculate the Number of Dids in FF\r
- for (FFIdNumber = 0; pEventParaTemp->FreezeFrameClassRef[index]->FFIdClassRef[FFIdNumber].Arc_EOL != FALSE; FFIdNumber++) {\r
+ for (FFIdNumber = 0; pEventParaTemp->FreezeFrameClassRef[index]->FFIdClassRef[FFIdNumber]->Arc_EOL != FALSE; FFIdNumber++) {\r
;\r
}\r
}\r
{\r
uint8 i;\r
uint8 dataCount;\r
- uint8 AddressFormat;\r
uint16 SourceDataLength = 0;\r
- const Dcm_DspMemoryIdInfo *SourceMemoryInfoptr = NULL;\r
const Dcm_DspDidType *SourceDidPtr = NULL;\r
Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;\r
*Length = 0;\r
{\r
if(PDidPtr->DDDSource[i].DDDTpyeID == DCM_DDD_SOURCE_ADDRESS)\r
{\r
-\r
- AddressFormat = PDidPtr->DDDSource[i].formatOrPosition&DCM_FORMAT_HIGH_MASK >> 4;\r
- if(TRUE == lookupReadMemory(PDidPtr->DDDSource[i].SourceAddressOrDid,AddressFormat,\r
- PDidPtr->DDDSource[i].Size, &SourceMemoryInfoptr))\r
- {\r
- if(DspCheckSecurityLevel(SourceMemoryInfoptr->pReadMemoryInfo->pSecurityLevel) != TRUE)\r
- {\r
- responseCode = DCM_E_SECUTITYACCESSDENIED;\r
- }\r
- }\r
- else\r
- {\r
- responseCode = DCM_E_REQUESTOUTOFRANGE;\r
- }\r
- if(responseCode == DCM_E_POSITIVERESPONSE)\r
- {\r
- Dcm_ReadMemory(DCM_INITIAL,SourceMemoryInfoptr->MemoryIdValue,\r
+ responseCode = checkAddressRange(DCM_READ_MEMORY, PDidPtr->DDDSource[i].memoryIdentifier, PDidPtr->DDDSource[i].SourceAddressOrDid, PDidPtr->DDDSource[i].Size);\r
+ if( responseCode == DCM_E_POSITIVERESPONSE ) {\r
+ Dcm_ReadMemory(DCM_INITIAL,PDidPtr->DDDSource[i].memoryIdentifier,\r
PDidPtr->DDDSource[i].SourceAddressOrDid,\r
PDidPtr->DDDSource[i].Size,\r
(Data + *Length));\r
}\r
}\r
\r
-\r
-static boolean CheckReadMemoryByAddress( boolean useId,uint32 memoryAddress,\r
- uint8 memoryAddressFormat,\r
- uint32 memorySize,\r
- const Dcm_DspMemoryIdInfo *dspMemory)\r
-{\r
- boolean ret = FALSE;\r
- uint8 MemoryId;\r
-\r
- if(useId == FALSE)\r
- {\r
- /*@req DCM493*/\r
- if((memoryAddress >= dspMemory->pReadMemoryInfo->MemoryAddressLow)\r
- && (memoryAddress <= dspMemory->pReadMemoryInfo->MemoryAddressHigh)\r
- && (memoryAddress + memorySize - 1 <= dspMemory->pReadMemoryInfo->MemoryAddressHigh))\r
- {\r
- ret = TRUE;\r
- }\r
- }\r
- else\r
- {\r
- MemoryId = (uint8)(memoryAddress >> ((memoryAddressFormat - 1)*8));\r
- memoryAddress = (uint32)(memoryAddress & DCM_MEMORY_ADDRESS_MASK);\r
-\r
- if((MemoryId == dspMemory->MemoryIdValue)&&\r
- (memoryAddress >= dspMemory->pReadMemoryInfo->MemoryAddressLow)\r
- && (memoryAddress <= dspMemory->pReadMemoryInfo->MemoryAddressHigh)\r
- && (memoryAddress + memorySize - 1 <= dspMemory->pReadMemoryInfo->MemoryAddressHigh))\r
- {\r
- ret = TRUE;\r
- }\r
- }\r
- \r
- return ret;\r
-}\r
-\r
-static boolean lookupReadMemory(uint32 memoryAddress,\r
- uint8 memoryAddressFormat,\r
- uint32 memorySize,\r
- const Dcm_DspMemoryIdInfo **MemoryInfoPtr)\r
-{\r
- uint8 i;\r
- boolean memoryFound = FALSE;\r
- const Dcm_DspMemoryIdInfo *dspMemoryInfo = DCM_Config.Dsp->DspMemory->DspMemoryIdInfo;\r
-\r
- for(i = 0; (dspMemoryInfo->Arc_EOL == FALSE) && (memoryFound == FALSE); i++)\r
- {\r
- if(TRUE == CheckReadMemoryByAddress(DCM_Config.Dsp->DspMemory->DcmDspUseMemoryId,memoryAddress,memoryAddressFormat,memorySize,dspMemoryInfo))\r
- {\r
- memoryFound = TRUE;\r
- }\r
- else\r
- {\r
- dspMemoryInfo++;\r
- }\r
- }\r
- if (memoryFound == TRUE)\r
- {\r
- *MemoryInfoPtr = dspMemoryInfo;\r
- }\r
- \r
- return memoryFound;\r
-}\r
-\r
static Dcm_NegativeResponseCodeType readMemoryData( Dcm_OpStatusType *OpStatus,\r
- const Dcm_DspMemoryIdInfo *MemoryPtr,\r
+ uint8 memoryIdentifier,\r
uint32 MemoryAddress,\r
uint32 MemorySize,\r
PduInfoType *pduTxData)\r
{\r
Dcm_ReturnReadMemoryType ReadRet;\r
Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;\r
- ReadRet = Dcm_ReadMemory(*OpStatus,MemoryPtr->MemoryIdValue,\r
+ ReadRet = Dcm_ReadMemory(*OpStatus,memoryIdentifier,\r
MemoryAddress,\r
MemorySize,\r
&pduTxData->SduDataPtr[1]);\r
return responseCode;\r
}\r
\r
-/*@req Dcm442,DCM492*/\r
-void DspUdsReadMemoryByAddress(const PduInfoType *pduRxData, PduInfoType *pduTxData)\r
-{\r
- typedef struct{\r
- uint32 MemoryAddressStart; /* low address of a memory block to read or write*/\r
- uint32 MemoryIdValue; /* memory ID to read or write uint used by parameter */\r
- const Dcm_DspMemoryIdInfo *MemoryIdConfigPtr; \r
- Dcm_NegativeResponseCodeType ResponseCode; \r
- uint8 MemorySizeFormat;\r
- uint8 MemoryAddressFormat;\r
- uint32 MemorySize;\r
- uint16 MessageLength;\r
- }DspUdsReadMemoryByAddressType; /*the typed used for SID read memory by address*/\r
- uint8 i;\r
- DspUdsReadMemoryByAddressType dspReadMemoryByAddress;\r
- Dcm_OpStatusType OpStatus = 0;\r
- dspReadMemoryByAddress.MemoryAddressStart = 0;\r
- dspReadMemoryByAddress.MemorySize = 0;\r
- dspReadMemoryByAddress.MemoryIdConfigPtr = NULL;\r
- dspReadMemoryByAddress.ResponseCode = DCM_E_POSITIVERESPONSE;\r
- dspReadMemoryByAddress.MemorySizeFormat = ((uint8)(pduRxData->SduDataPtr[1] & DCM_FORMAT_HIGH_MASK)) >> 4; /*@req UDS_REQ_0x23_1 & UDS_REQ_0x23_5*/\r
- dspReadMemoryByAddress.MemoryAddressFormat = ((uint8)(pduRxData->SduDataPtr[1])) & 0x0Fu; /*@req UDS_REQ_0x23_1 & UDS_REQ_0x23_5*/\r
-\r
- if((dspReadMemoryByAddress.MemoryAddressFormat == 0)||(dspReadMemoryByAddress.MemorySizeFormat == 0))\r
- {\r
- dspReadMemoryByAddress.ResponseCode = DCM_E_REQUESTOUTOFRANGE; /*UDS_REQ_0x23_10*/\r
- }\r
- else\r
+static Dcm_NegativeResponseCodeType checkAddressRange(DspMemoryServiceType serviceType, uint8 memoryIdentifier, uint32 memoryAddress, uint32 length) {\r
+ const Dcm_DspMemoryIdInfo *dspMemoryInfo = DCM_Config.Dsp->DspMemory->DspMemoryIdInfo;\r
+ const Dcm_DspMemoryRangeInfo *memoryRangeInfo = NULL;\r
+ Dcm_NegativeResponseCodeType diagResponseCode = DCM_E_REQUESTOUTOFRANGE;\r
+\r
+ for( ; (dspMemoryInfo->Arc_EOL == FALSE) && (memoryRangeInfo == NULL); dspMemoryInfo++ )\r
{\r
- dspReadMemoryByAddress.MessageLength = (uint16)(dspReadMemoryByAddress.MemoryAddressFormat + dspReadMemoryByAddress.MemorySizeFormat + SID_AND_ALFID_LEN2);\r
- if(dspReadMemoryByAddress.MessageLength == (uint16)(pduRxData->SduLength))\r
+ if( ((TRUE == DCM_Config.Dsp->DspMemory->DcmDspUseMemoryId) && (dspMemoryInfo->MemoryIdValue == memoryIdentifier))\r
+ || (FALSE == DCM_Config.Dsp->DspMemory->DcmDspUseMemoryId) )\r
{\r
- /*take start address out */\r
- for(i = 0; i < dspReadMemoryByAddress.MemoryAddressFormat; i++)\r
+ if( DCM_READ_MEMORY == serviceType )\r
+ {\r
+ memoryRangeInfo = findRange( dspMemoryInfo->pReadMemoryInfo, memoryAddress, length );\r
+ }\r
+ else\r
{\r
- dspReadMemoryByAddress.MemoryAddressStart <<= 8;\r
- dspReadMemoryByAddress.MemoryAddressStart += (uint32)(pduRxData->SduDataPtr[SID_AND_ALFID_LEN2 + i]);\r
+ memoryRangeInfo = findRange( dspMemoryInfo->pWriteMemoryInfo, memoryAddress, length );\r
}\r
\r
- /*take value of MemorySize out */\r
- for(i = 0; i < dspReadMemoryByAddress.MemorySizeFormat; i++)\r
+ if( NULL != memoryRangeInfo )\r
{\r
- dspReadMemoryByAddress.MemorySize <<= 8;\r
- dspReadMemoryByAddress.MemorySize += (uint32)(pduRxData->SduDataPtr[2 + i + dspReadMemoryByAddress.MemoryAddressFormat]);\r
+ if( DspCheckSecurityLevel(memoryRangeInfo->pSecurityLevel) )\r
+ {\r
+ /* Range is ok */\r
+ diagResponseCode = DCM_E_POSITIVERESPONSE;\r
+ }\r
+ else\r
+ {\r
+ diagResponseCode = DCM_E_SECUTITYACCESSDENIED;\r
+ }\r
+ }\r
+ else {\r
+ /* Range was not configured for read/write */\r
+ diagResponseCode = DCM_E_REQUESTOUTOFRANGE;\r
}\r
- if(dspReadMemoryByAddress.MemorySize < DCM_PROTOCAL_TP_MAX_LENGTH)\r
+ }\r
+ else {\r
+ /* No memory with this id found */\r
+ diagResponseCode = DCM_E_REQUESTOUTOFRANGE;\r
+ }\r
+ }\r
+ return diagResponseCode;\r
+}\r
+\r
+static const Dcm_DspMemoryRangeInfo* findRange(const Dcm_DspMemoryRangeInfo *memoryRangePtr, uint32 memoryAddress, uint32 length)\r
+{\r
+ const Dcm_DspMemoryRangeInfo *memoryRange = NULL;\r
+\r
+ for( ; (memoryRangePtr->Arc_EOL == FALSE) && (memoryRange == NULL); memoryRangePtr++ )\r
+ {\r
+ /*@req DCM493*/\r
+ if((memoryAddress >= memoryRangePtr->MemoryAddressLow)\r
+ && (memoryAddress <= memoryRangePtr->MemoryAddressHigh)\r
+ && (memoryAddress + length - 1 <= memoryRangePtr->MemoryAddressHigh))\r
+ {\r
+ memoryRange = memoryRangePtr;\r
+ }\r
+ }\r
+\r
+ return memoryRange;\r
+}\r
+\r
+void DspUdsWriteMemoryByAddress(const PduInfoType *pduRxData, PduInfoType *pduTxData)\r
+{\r
+ Dcm_NegativeResponseCodeType diagResponseCode;\r
+ uint8 sizeFormat;\r
+ uint8 addressFormat;\r
+ uint32 memoryAddress = 0;\r
+ uint32 length = 0;\r
+ uint8 i;\r
+ uint8 memoryIdentifier = 0; /* Should be 0 if DcmDspUseMemoryId == FALSE */\r
+ Dcm_OpStatusType OpStatus;\r
+ uint8 addressOffset;\r
+\r
+ if( pduRxData->SduLength > ALFID_INDEX )\r
+ {\r
+ sizeFormat = ((uint8)(pduRxData->SduDataPtr[ALFID_INDEX] & DCM_FORMAT_HIGH_MASK)) >> 4; /*@req UDS_REQ_0x23_1 & UDS_REQ_0x23_5*/;\r
+ addressFormat = ((uint8)(pduRxData->SduDataPtr[ALFID_INDEX])) & DCM_FORMAT_LOW_MASK; /*@req UDS_REQ_0x23_1 & UDS_REQ_0x23_5*/;\r
+ if((addressFormat != 0) && (sizeFormat != 0))\r
+ {\r
+ if(addressFormat + sizeFormat + SID_LEN + ALFID_LEN <= pduRxData->SduLength)\r
{\r
- if(TRUE == lookupReadMemory(dspReadMemoryByAddress.MemoryAddressStart,\r
- dspReadMemoryByAddress.MemoryAddressFormat,\r
- dspReadMemoryByAddress.MemorySize,\r
- &dspReadMemoryByAddress.MemoryIdConfigPtr))\r
+ if( TRUE == DCM_Config.Dsp->DspMemory->DcmDspUseMemoryId ) {\r
+ memoryIdentifier = pduRxData->SduDataPtr[ADDR_START_INDEX];\r
+ addressOffset = 1;\r
+ }\r
+ else {\r
+ addressOffset = 0;\r
+ }\r
+\r
+ /* Parse address */\r
+ for(i = addressOffset; i < addressFormat; i++)\r
{\r
- if (DspCheckSecurityLevel(dspReadMemoryByAddress.MemoryIdConfigPtr->pReadMemoryInfo->pSecurityLevel) == TRUE)\r
- {\r
- dspReadMemoryByAddress.ResponseCode = readMemoryData(&OpStatus,dspReadMemoryByAddress.MemoryIdConfigPtr,\r
- dspReadMemoryByAddress.MemoryAddressStart,\r
- dspReadMemoryByAddress.MemorySize,pduTxData);/*@req UDS_REQ_0x23_9*/\r
- \r
- }\r
- else\r
+ memoryAddress <<= 8;\r
+ memoryAddress += (uint32)(pduRxData->SduDataPtr[ADDR_START_INDEX + i]);\r
+ }\r
+\r
+ /* Parse size */\r
+ for(i = 0; i < sizeFormat; i++)\r
+ {\r
+ length <<= 8;\r
+ length += (uint32)(pduRxData->SduDataPtr[ADDR_START_INDEX + addressFormat + i]);\r
+ }\r
+\r
+ if( addressFormat + sizeFormat + SID_LEN + ALFID_LEN + length == pduRxData->SduLength )\r
+ {\r
+\r
+ diagResponseCode = checkAddressRange(DCM_WRITE_MEMORY, memoryIdentifier, memoryAddress, length);\r
+ if( DCM_E_POSITIVERESPONSE == diagResponseCode )\r
{\r
- dspReadMemoryByAddress.ResponseCode = DCM_E_SECUTITYACCESSDENIED;/*@req UDS_REQ_0x23_11,@req DCM494*/\r
+ diagResponseCode = writeMemoryData(&OpStatus, memoryIdentifier, memoryAddress, length,\r
+ &pduRxData->SduDataPtr[SID_LEN + ALFID_LEN + addressFormat + sizeFormat]);\r
}\r
+\r
}\r
else\r
{\r
- dspReadMemoryByAddress.ResponseCode = DCM_E_REQUESTOUTOFRANGE; /*@req UDS_REQ_0x23_7,UDS_REQ_0x23_8*/\r
+ diagResponseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;\r
}\r
}\r
else\r
{\r
- dspReadMemoryByAddress.ResponseCode = DCM_E_REQUESTOUTOFRANGE;\r
+ diagResponseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;\r
}\r
}\r
else\r
{\r
- dspReadMemoryByAddress.ResponseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT; /*@req UDS_REQ_0x23_6*/\r
+ diagResponseCode = DCM_E_REQUESTOUTOFRANGE; /*UDS_REQ_0x23_10*/\r
}\r
}\r
- if(DCM_E_POSITIVERESPONSE == dspReadMemoryByAddress.ResponseCode)\r
+ else\r
{\r
- pduTxData->SduLength = 1 + dspReadMemoryByAddress.MemorySize;\r
- if(OpStatus == DCM_READ_PENDING)\r
- {\r
- dspMemoryState = DCM_MEMORY_READ;\r
- }\r
- else\r
+ diagResponseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;\r
+ }\r
+\r
+ if(DCM_E_POSITIVERESPONSE == diagResponseCode)\r
+ {\r
+ pduTxData->SduLength = SID_LEN + ALFID_LEN + addressFormat + sizeFormat;\r
+ pduTxData->SduDataPtr[ALFID_INDEX] = pduRxData->SduDataPtr[ALFID_INDEX];\r
+ for(i = 0; i < addressFormat + sizeFormat; i++)\r
{\r
- DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);\r
+ pduTxData->SduDataPtr[ADDR_START_INDEX + i] = pduRxData->SduDataPtr[ADDR_START_INDEX + i];\r
+ if(OpStatus != DCM_WRITE_PENDING)\r
+ {\r
+ DsdDspProcessingDone(diagResponseCode);\r
+ }\r
+ else\r
+ {\r
+ dspMemoryState=DCM_MEMORY_WRITE;\r
+ }\r
}\r
}\r
else\r
{\r
- DsdDspProcessingDone(dspReadMemoryByAddress.ResponseCode);\r
+ DsdDspProcessingDone(diagResponseCode);\r
}\r
}\r
\r
-static boolean checkWriteMemoryByAddress(boolean useId,uint32 memoryAddress,\r
- uint8 memoryAddressFormat,\r
- uint32 memorySize,\r
- const Dcm_DspMemoryIdInfo *dspMemory)\r
+/*@req Dcm442,DCM492*/\r
+void DspUdsReadMemoryByAddress(const PduInfoType *pduRxData, PduInfoType *pduTxData)\r
{\r
- boolean ret = FALSE;\r
- uint8 MemoryId;\r
- \r
- if(useId == FALSE)\r
+ Dcm_NegativeResponseCodeType diagResponseCode;\r
+ uint8 sizeFormat;\r
+ uint8 addressFormat;\r
+ uint32 memoryAddress = 0;\r
+ uint32 length = 0;\r
+ uint8 i;\r
+ uint8 memoryIdentifier = 0; /* Should be 0 if DcmDspUseMemoryId == FALSE */\r
+ Dcm_OpStatusType OpStatus;\r
+ uint8 addressOffset;\r
+\r
+ if( pduRxData->SduLength > ALFID_INDEX )\r
{\r
- if((memoryAddress >= dspMemory->pWriteMemoryInfo->MemoryAddressLow)\r
- && (memoryAddress <= dspMemory->pWriteMemoryInfo->MemoryAddressHigh)\r
- && (memoryAddress + memorySize - 1 <= dspMemory->pWriteMemoryInfo->MemoryAddressHigh))\r
+ sizeFormat = ((uint8)(pduRxData->SduDataPtr[ALFID_INDEX] & DCM_FORMAT_HIGH_MASK)) >> 4; /*@req UDS_REQ_0x23_1 & UDS_REQ_0x23_5*/;\r
+ addressFormat = ((uint8)(pduRxData->SduDataPtr[ALFID_INDEX])) & DCM_FORMAT_LOW_MASK; /*@req UDS_REQ_0x23_1 & UDS_REQ_0x23_5*/;\r
+ if((addressFormat != 0) && (sizeFormat != 0))\r
{\r
- ret = TRUE;\r
+ if(addressFormat + sizeFormat + SID_LEN + ALFID_LEN == pduRxData->SduLength)\r
+ {\r
+ if( TRUE == DCM_Config.Dsp->DspMemory->DcmDspUseMemoryId ) {\r
+ memoryIdentifier = pduRxData->SduDataPtr[ADDR_START_INDEX];\r
+ addressOffset = 1;\r
+ }\r
+ else {\r
+ addressOffset = 0;\r
+ }\r
+\r
+ /* Parse address */\r
+ for(i = addressOffset; i < addressFormat; i++)\r
+ {\r
+ memoryAddress <<= 8;\r
+ memoryAddress += (uint32)(pduRxData->SduDataPtr[ADDR_START_INDEX + i]);\r
+ }\r
+\r
+ /* Parse size */\r
+ for(i = 0; i < sizeFormat; i++)\r
+ {\r
+ length <<= 8;\r
+ length += (uint32)(pduRxData->SduDataPtr[ADDR_START_INDEX + addressFormat + i]);\r
+ }\r
+\r
+ if(length <= (DCM_PROTOCAL_TP_MAX_LENGTH - SID_LEN) )\r
+ {\r
+ diagResponseCode = checkAddressRange(DCM_READ_MEMORY, memoryIdentifier, memoryAddress, length);\r
+ if( DCM_E_POSITIVERESPONSE == diagResponseCode )\r
+ {\r
+ diagResponseCode = readMemoryData(&OpStatus, memoryIdentifier, memoryAddress, length, pduTxData);\r
+ }\r
+ }\r
+ else {\r
+ diagResponseCode = DCM_E_REQUESTOUTOFRANGE;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ diagResponseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ diagResponseCode = DCM_E_REQUESTOUTOFRANGE; /*UDS_REQ_0x23_10*/\r
}\r
}\r
else\r
{\r
- MemoryId = (uint8)(memoryAddress >> ((memoryAddressFormat - 1)*8));\r
- memoryAddress = memoryAddress & DCM_MEMORY_ADDRESS_MASK;\r
-\r
- if((MemoryId == dspMemory->MemoryIdValue) &&\r
- (memoryAddress >= dspMemory->pWriteMemoryInfo->MemoryAddressLow)\r
- && (memoryAddress <= dspMemory->pWriteMemoryInfo->MemoryAddressHigh)\r
- && (memoryAddress + memorySize -1 <= dspMemory->pWriteMemoryInfo->MemoryAddressHigh))\r
- {\r
- ret = TRUE;\r
- }\r
-\r
+ diagResponseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;\r
}\r
- \r
- return ret;\r
-}\r
-\r
-static boolean lookupWriteMemory(uint32 memoryAddress,\r
- uint8 memoryAddressFormat,\r
- uint32 memorySize,\r
- const Dcm_DspMemoryIdInfo **MemoryIdConfigPtr)\r
-{\r
- uint8 i;\r
- const Dcm_DspMemoryIdInfo *dspMemoryInfo = DCM_Config.Dsp->DspMemory->DspMemoryIdInfo;\r
- boolean memoryFound = FALSE;\r
\r
- for(i = 0;(dspMemoryInfo->Arc_EOL == FALSE) && (memoryFound == FALSE);i++)\r
+ if(DCM_E_POSITIVERESPONSE == diagResponseCode)\r
{\r
- if(TRUE == checkWriteMemoryByAddress(DCM_Config.Dsp->DspMemory->DcmDspUseMemoryId, memoryAddress,memoryAddressFormat,memorySize,dspMemoryInfo))\r
+ pduTxData->SduLength = SID_LEN + length;\r
+ if(OpStatus == DCM_READ_PENDING)\r
{\r
- memoryFound = TRUE;\r
+ dspMemoryState = DCM_MEMORY_READ;\r
}\r
else\r
{\r
- dspMemoryInfo++;\r
+ DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);\r
}\r
}\r
- if (memoryFound == TRUE)\r
+ else\r
{\r
- *MemoryIdConfigPtr = dspMemoryInfo;\r
+ DsdDspProcessingDone(diagResponseCode);\r
}\r
- \r
- return memoryFound;\r
}\r
\r
static Dcm_NegativeResponseCodeType writeMemoryData(Dcm_OpStatusType* OpStatus,\r
- const Dcm_DspMemoryIdInfo *MemoryIdConfigPtr,\r
+ uint8 memoryIdentifier,\r
uint32 MemoryAddress,\r
uint32 MemorySize,\r
uint8 *SourceData)\r
Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;\r
Dcm_ReturnWriteMemoryType writeRet;\r
writeRet = Dcm_WriteMemory(*OpStatus,\r
- MemoryIdConfigPtr->MemoryIdValue,\r
+ memoryIdentifier,\r
MemoryAddress,\r
MemorySize,\r
SourceData);\r
return responseCode;\r
}\r
\r
-void DspUdsWriteMemoryByAddress(const PduInfoType* pduRxData, PduInfoType* pduTxData)\r
-{\r
- typedef struct{\r
- uint32 MemoryAddressStart;\r
- uint32 MemoryIdValue;\r
- const Dcm_DspMemoryIdInfo *MemoryIdConfigPtr;\r
- Dcm_NegativeResponseCodeType ResponseCode;\r
- uint8 MemorySizeFormat;\r
- uint8 MemoryAddressFormat;\r
- uint32 MemorySize ;\r
- uint16 MessageLength;\r
- }DspUdsWriteMemoryType;\r
- uint8 i;\r
- DspUdsWriteMemoryType dspUdsWriteMemory;\r
- Dcm_OpStatusType OpStatus = DCM_INITIAL;\r
- dspUdsWriteMemory.MemoryAddressStart = 0;\r
- dspUdsWriteMemory.MemoryIdConfigPtr = NULL;\r
- dspUdsWriteMemory.ResponseCode = DCM_E_POSITIVERESPONSE;\r
- dspUdsWriteMemory.MemorySizeFormat = ((uint8)(pduRxData->SduDataPtr[1] & DCM_FORMAT_HIGH_MASK)) >> 4; /*@req UDS_REQ_0x3D_3 & UDS_REQ_0x3D_5*/\r
- dspUdsWriteMemory.MemoryAddressFormat = ((uint8)pduRxData->SduDataPtr[1]) & DCM_FORMAT_LOW_MASK; /*@req UDS_REQ_0x3D_3& UDS_REQ_0x3D_4*/\r
- dspUdsWriteMemory.MemorySize = 0;\r
-\r
- if((dspUdsWriteMemory.MemoryAddressFormat == 0) || (dspUdsWriteMemory.MemorySizeFormat == 0)) /*@req UDS_REQ_0x3D_14*/\r
- {\r
- dspUdsWriteMemory.ResponseCode = DCM_E_REQUESTOUTOFRANGE;\r
- }\r
- else\r
- {\r
- /*take value of MemorySize out */\r
- for(i = 0; i < dspUdsWriteMemory.MemorySizeFormat; i++)\r
- {\r
- dspUdsWriteMemory.MemorySize <<= 8;\r
- dspUdsWriteMemory.MemorySize += (uint32)(pduRxData->SduDataPtr[2 + i +dspUdsWriteMemory.MemoryAddressFormat]);\r
- }\r
- dspUdsWriteMemory.MessageLength = (uint16)(2 + dspUdsWriteMemory.MemoryAddressFormat + dspUdsWriteMemory.MemorySizeFormat + dspUdsWriteMemory.MemorySize);\r
- if(dspUdsWriteMemory.MessageLength == pduRxData->SduLength)\r
- {\r
- /*take Start Address out */\r
- for(i = 0; i < dspUdsWriteMemory.MemoryAddressFormat; i++)\r
- {\r
- dspUdsWriteMemory.MemoryAddressStart <<= 8;\r
- dspUdsWriteMemory.MemoryAddressStart += (uint32)(pduRxData->SduDataPtr[2 + i]);\r
- }\r
- if(TRUE == lookupWriteMemory(dspUdsWriteMemory.MemoryAddressStart,\r
- dspUdsWriteMemory.MemoryAddressFormat,\r
- dspUdsWriteMemory.MemorySize,\r
- &dspUdsWriteMemory.MemoryIdConfigPtr))\r
- {\r
- if (DspCheckSecurityLevel(dspUdsWriteMemory.MemoryIdConfigPtr->pReadMemoryInfo->pSecurityLevel) == TRUE)\r
- {\r
- dspUdsWriteMemory.ResponseCode = writeMemoryData(&OpStatus,\r
- dspUdsWriteMemory.MemoryIdConfigPtr, \r
- dspUdsWriteMemory.MemoryAddressStart,\r
- dspUdsWriteMemory.MemorySize,\r
- &pduRxData->SduDataPtr[2 + dspUdsWriteMemory.MemoryAddressFormat + dspUdsWriteMemory.MemorySizeFormat]);\r
- }\r
- else\r
- {\r
- dspUdsWriteMemory.ResponseCode = DCM_E_SECUTITYACCESSDENIED; /*@req UDS_REQ_0X3D_15,Dcm490*/\r
- }\r
- }\r
- else\r
- {\r
- dspUdsWriteMemory.ResponseCode = DCM_E_REQUESTOUTOFRANGE; /*@req UDS_REQ_0x3D_11,UDS_REQ_0x3D_12,Dcm489*/\r
- }\r
- }\r
- else\r
- {\r
- dspUdsWriteMemory.ResponseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;/*@req UDS_REQ_0x3D_9*/\r
- } \r
- }\r
- if(DCM_E_POSITIVERESPONSE == dspUdsWriteMemory.ResponseCode)\r
- {\r
- pduTxData->SduLength = 2 + dspUdsWriteMemory.MemorySizeFormat + dspUdsWriteMemory.MemoryAddressFormat;\r
- pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];\r
- for(i = 0; i < dspUdsWriteMemory.MemorySizeFormat + dspUdsWriteMemory.MemoryAddressFormat; i++)\r
- {\r
- pduTxData->SduDataPtr[2 + i] = pduRxData->SduDataPtr[2 + i];\r
- if(OpStatus != DCM_PENDING)\r
- {\r
- DsdDspProcessingDone(dspUdsWriteMemory.ResponseCode);\r
- }\r
- else\r
- {\r
- dspMemoryState=DCM_MEMORY_WRITE;\r
- }\r
- }\r
- }\r
- else\r
- {\r
- DsdDspProcessingDone(dspUdsWriteMemory.ResponseCode);\r
- }\r
-}\r
-\r
static boolean checkPeriodicIdentifierBuffer(uint8 PeriodicDid,uint8 Length,uint8 *postion)\r
{\r
uint8 i;\r
\r
static Dcm_NegativeResponseCodeType dynamicallyDefineDataIdentifierbyAddress(uint16 DDIdentifier,const PduInfoType *pduRxData,PduInfoType *pduTxData)\r
{\r
- uint8 LengthCount;\r
- uint8 SourceCount;\r
- uint16 Length;\r
- uint8 AddressFormat;\r
- uint8 MemorySizeFormat;\r
- uint32 MemoryAddress = 0;\r
- uint16 MemorySize = 0;\r
- uint16 SourceLength = 0;\r
+ uint16 numNewDefinitions;\r
+ uint16 numEarlierDefinitions = 0;\r
Dcm_DspDDDType *DDid = NULL;\r
- const Dcm_DspMemoryIdInfo *SourceMemoryInfo = NULL;\r
uint8 Num = 0;\r
- Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;\r
+ uint8 definitionIndex;\r
+ Dcm_NegativeResponseCodeType diagResponseCode = DCM_E_POSITIVERESPONSE;\r
+ uint8 sizeFormat;\r
+ uint8 addressFormat;\r
+ uint32 memoryAddress = 0;\r
+ uint32 length = 0;\r
+ uint8 i;\r
+ uint8 memoryIdentifier = 0; /* Should be 0 if DcmDspUseMemoryId == FALSE */\r
+ uint8 addressOffset;\r
\r
if(FALSE == LookupDDD(DDIdentifier, (const Dcm_DspDDDType **)&DDid))\r
{\r
}\r
if(Num >= DCM_MAX_DDD_NUMBER)\r
{\r
- responseCode = DCM_E_REQUESTOUTOFRANGE;\r
+ diagResponseCode = DCM_E_REQUESTOUTOFRANGE;\r
}\r
else\r
{\r
}\r
else\r
{\r
- while((SourceLength < DCM_MAX_DDDSOURCE_NUMBER) && (DDid->DDDSource[SourceLength].formatOrPosition != 0 ))\r
+ while((numEarlierDefinitions < DCM_MAX_DDDSOURCE_NUMBER) && (DDid->DDDSource[numEarlierDefinitions].formatOrPosition != 0 ))\r
{\r
- SourceLength++;\r
+ numEarlierDefinitions++;\r
}\r
- if(SourceLength >= DCM_MAX_DDDSOURCE_NUMBER)\r
+ if(numEarlierDefinitions >= DCM_MAX_DDDSOURCE_NUMBER)\r
{\r
- responseCode = DCM_E_REQUESTOUTOFRANGE;\r
+ diagResponseCode = DCM_E_REQUESTOUTOFRANGE;\r
}\r
}\r
- if(responseCode == DCM_E_POSITIVERESPONSE)\r
+\r
+ if( diagResponseCode == DCM_E_POSITIVERESPONSE )\r
{\r
- AddressFormat = (uint8)pduRxData->SduDataPtr[4] & DCM_FORMAT_LOW_MASK;\r
- MemorySizeFormat = (uint8)(pduRxData->SduDataPtr[4] >> 4) & DCM_FORMAT_LOW_MASK;\r
- if((AddressFormat+MemorySizeFormat) != 0)\r
- {\r
- Length = (pduRxData->SduLength - SID_AND_ALFID_LEN5) / (AddressFormat + MemorySizeFormat);\r
- }\r
- if((AddressFormat != 0) && (MemorySizeFormat != 0) && ((SourceLength+Length) <= DCM_MAX_DDDSOURCE_NUMBER))\r
+ if( pduRxData->SduLength > DYNDEF_ALFID_INDEX )\r
{\r
- if((Length != 0)&&( Length * (AddressFormat + MemorySizeFormat) == (pduRxData->SduLength - 5) ))\r
+ sizeFormat = ((uint8)(pduRxData->SduDataPtr[DYNDEF_ALFID_INDEX] & DCM_FORMAT_HIGH_MASK)) >> 4; /*@req UDS_REQ_0x23_1 & UDS_REQ_0x23_5*/;\r
+ addressFormat = ((uint8)(pduRxData->SduDataPtr[DYNDEF_ALFID_INDEX])) & DCM_FORMAT_LOW_MASK; /*@req UDS_REQ_0x23_1 & UDS_REQ_0x23_5*/;\r
+ if((addressFormat != 0) && (sizeFormat != 0))\r
{\r
- for(LengthCount = 0; (LengthCount < Length) && (responseCode == DCM_E_POSITIVERESPONSE); LengthCount++)\r
+ numNewDefinitions = (pduRxData->SduLength - (SID_LEN + SF_LEN + DDDDI_LEN + ALFID_LEN) ) / (sizeFormat + addressFormat);\r
+ if( (numNewDefinitions != 0) &&\r
+ ((SID_LEN + SF_LEN + DDDDI_LEN + ALFID_LEN + numNewDefinitions * (sizeFormat + addressFormat)) == pduRxData->SduLength) )\r
{\r
- MemoryAddress = 0;\r
- for(SourceCount = 0; SourceCount < AddressFormat; SourceCount++)\r
+ if( (numEarlierDefinitions+numNewDefinitions) <= DCM_MAX_DDDSOURCE_NUMBER )\r
{\r
- MemoryAddress = MemoryAddress << 8;\r
- MemoryAddress += (uint32)(pduRxData->SduDataPtr[5 + SourceCount + LengthCount * (AddressFormat + MemorySizeFormat)]);\r
- }\r
+ for( definitionIndex = 0; (definitionIndex < numNewDefinitions) && (diagResponseCode == DCM_E_POSITIVERESPONSE); definitionIndex++ )\r
+ {\r
\r
- /*take value of MemorySize out */\r
- MemorySize = 0;\r
- for(SourceCount = 0; SourceCount < MemorySizeFormat; SourceCount++)\r
- {\r
- MemorySize = MemorySize << 8;\r
- MemorySize += (uint32)(pduRxData->SduDataPtr[5 + SourceCount + AddressFormat + LengthCount * (AddressFormat + MemorySizeFormat)]);\r
- }\r
- if(TRUE == lookupReadMemory(MemoryAddress, AddressFormat,MemorySize,&SourceMemoryInfo))\r
- {\r
- if(DspCheckSecurityLevel(SourceMemoryInfo->pReadMemoryInfo->pSecurityLevel) == TRUE)\r
+ if( TRUE == DCM_Config.Dsp->DspMemory->DcmDspUseMemoryId ) {\r
+ memoryIdentifier = pduRxData->SduDataPtr[DYNDEF_ADDRESS_START_INDEX + definitionIndex * (sizeFormat + addressFormat)];\r
+ addressOffset = 1;\r
+ }\r
+ else {\r
+ addressOffset = 0;\r
+ }\r
+\r
+ /* Parse address */\r
+ memoryAddress = 0;\r
+ for(i = addressOffset; i < addressFormat; i++)\r
+ {\r
+ memoryAddress <<= 8;\r
+ memoryAddress += (uint32)(pduRxData->SduDataPtr[DYNDEF_ADDRESS_START_INDEX + definitionIndex * (sizeFormat + addressFormat) + i]);\r
+ }\r
+\r
+ /* Parse size */\r
+ length = 0;\r
+ for(i = 0; i < sizeFormat; i++)\r
+ {\r
+ length <<= 8;\r
+ length += (uint32)(pduRxData->SduDataPtr[DYNDEF_ADDRESS_START_INDEX + definitionIndex * (sizeFormat + addressFormat) + addressFormat + i]);\r
+ }\r
+\r
+ diagResponseCode = checkAddressRange(DCM_READ_MEMORY, memoryIdentifier, memoryAddress, length);\r
+ if( DCM_E_POSITIVERESPONSE == diagResponseCode )\r
+ {\r
+ DDid->DDDSource[definitionIndex + numEarlierDefinitions].formatOrPosition = pduRxData->SduDataPtr[DYNDEF_ALFID_INDEX];\r
+ DDid->DDDSource[definitionIndex + numEarlierDefinitions].memoryIdentifier = memoryIdentifier;\r
+ DDid->DDDSource[definitionIndex + numEarlierDefinitions].SourceAddressOrDid = memoryAddress;\r
+ DDid->DDDSource[definitionIndex + numEarlierDefinitions].Size = length;\r
+ DDid->DDDSource[definitionIndex + numEarlierDefinitions].DDDTpyeID = DCM_DDD_SOURCE_ADDRESS;\r
+ }\r
+ }\r
+ if(diagResponseCode == DCM_E_POSITIVERESPONSE)\r
{\r
- DDid->DDDSource[LengthCount + SourceLength].formatOrPosition = pduRxData->SduDataPtr[4];\r
- DDid->DDDSource[LengthCount + SourceLength].SourceAddressOrDid = MemoryAddress;\r
- DDid->DDDSource[LengthCount + SourceLength].Size = MemorySize;\r
- DDid->DDDSource[LengthCount + SourceLength].DDDTpyeID = DCM_DDD_SOURCE_ADDRESS;\r
- /*UDS_REQ_0x2C_6*/\r
+ DDid->DynamicallyDid = DDIdentifier;\r
}\r
else\r
{\r
- /*UDS_REQ_0x2C_19,DCM726*/\r
- responseCode = DCM_E_SECUTITYACCESSDENIED;\r
+ for( definitionIndex = 0; (definitionIndex < numNewDefinitions); definitionIndex++ )\r
+ {\r
+ DDid->DDDSource[definitionIndex + numEarlierDefinitions].formatOrPosition = 0x00;\r
+ DDid->DDDSource[definitionIndex + numEarlierDefinitions].memoryIdentifier = 0x00;\r
+ DDid->DDDSource[definitionIndex + numEarlierDefinitions].SourceAddressOrDid = 0x00000000;\r
+ DDid->DDDSource[definitionIndex + numEarlierDefinitions].Size = 0x0000;\r
+ DDid->DDDSource[definitionIndex + numEarlierDefinitions].DDDTpyeID = DCM_DDD_SOURCE_DEFAULT;\r
+ }\r
}\r
}\r
else\r
{\r
- /*UDS_REQ_0x2C_15,UDS_REQ_0x2C_16*/\r
- responseCode = DCM_E_REQUESTOUTOFRANGE;\r
+ diagResponseCode = DCM_E_REQUESTOUTOFRANGE;\r
}\r
}\r
- if(responseCode == DCM_E_POSITIVERESPONSE)\r
+ else\r
{\r
- DDid->DynamicallyDid = DDIdentifier;\r
+ diagResponseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;\r
}\r
}\r
else\r
{\r
- /*UDS_REQ_0x2C_11*/\r
- responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;\r
+ diagResponseCode = DCM_E_REQUESTOUTOFRANGE; /*UDS_REQ_0x23_10*/\r
}\r
}\r
else\r
{\r
- /*UDS_REQ_0x2C_17, UDS_REQ_0x2C_18*/\r
- responseCode = DCM_E_REQUESTOUTOFRANGE;\r
+ diagResponseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;\r
}\r
-\r
}\r
- if(responseCode == DCM_E_POSITIVERESPONSE)\r
+\r
+\r
+ if(diagResponseCode == DCM_E_POSITIVERESPONSE)\r
{\r
- pduTxData->SduDataPtr[1] = DCM_DDD_SUBFUNCTION_DEFINEBYADDRESS;\r
+ pduTxData->SduDataPtr[SF_INDEX] = DCM_DDD_SUBFUNCTION_DEFINEBYADDRESS;\r
}\r
\r
- return responseCode;\r
+ return diagResponseCode;\r
}\r
\r
\r
{\r
/*UDS_REQ_0x2C_5*/\r
sint8 i, j;\r
- uint8 ClearCount;\r
uint8 position;\r
- uint8 ClearNum = 0;\r
Dcm_DspDDDType *DDid = NULL;\r
Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;\r
\r