博主最近参与一个BOOTLAODER的项目(MPC5634),需要用到DCM模块(基于UDS)的烧写流程。
由于采用Autosar架构,将配置函数和执行函数分开;本文主要说一下DCM的配置。
1 DCM_Cfg
DCM协议的配置
const Dcm_ServiceTableType Dcm_ServiceTable[DCM_SERVICE_NUM] =
{
{ 0x10u, DCM_PHYSICAL_ADDRESSING|DCM_FUNCTIONAL_ADDRESSING,
DCM_SESSION_DEFAULT|DCM_SESSION_PROGRAMMING|DCM_SESSION_EXTEND ,
&Dcm_RecvMsg10, NULL_PTR
},
#if(DCM_SERVICE_11_ENABLE == STD_ON)
{ 0x11u, DCM_PHYSICAL_ADDRESSING|DCM_FUNCTIONAL_ADDRESSING,
DCM_SESSION_DEFAULT|DCM_SESSION_PROGRAMMING|DCM_SESSION_EXTEND ,
&Dcm_RecvMsg11, NULL_PTR
},
#endif
#if(DCM_SERVICE_22_ENABLE == STD_ON)
{ 0x22u, DCM_PHYSICAL_ADDRESSING,
DCM_SESSION_DEFAULT|DCM_SESSION_PROGRAMMING|DCM_SESSION_EXTEND ,
&Dcm_RecvMsg22, NULL_PTR
},
#endif
{ 0x27u, DCM_PHYSICAL_ADDRESSING,
DCM_SESSION_PROGRAMMING ,
&Dcm_RecvMsg27, NULL_PTR
},
{ 0x28u, DCM_FUNCTIONAL_ADDRESSING|DCM_PHYSICAL_ADDRESSING,
DCM_SESSION_EXTEND ,
&Dcm_RecvMsg28, NULL_PTR
},
{ 0x2Eu, DCM_PHYSICAL_ADDRESSING,
DCM_SESSION_PROGRAMMING ,
&Dcm_RecvMsg2E, &Dcm_Pending2E
},
{ 0x31u, DCM_PHYSICAL_ADDRESSING,
DCM_SESSION_PROGRAMMING|DCM_SESSION_EXTEND ,
&Dcm_RecvMsg31, &Dcm_Pending31
},
{ 0x34u, DCM_PHYSICAL_ADDRESSING,
DCM_SESSION_PROGRAMMING ,
&Dcm_RecvMsg34, NULL_PTR
},
{ 0x36u, DCM_PHYSICAL_ADDRESSING,
DCM_SESSION_PROGRAMMING ,
&Dcm_RecvMsg36, &Dcm_Pending36
},
{ 0x37u, DCM_PHYSICAL_ADDRESSING,
DCM_SESSION_PROGRAMMING ,
&Dcm_RecvMsg37, NULL_PTR
},
{ 0x3Eu, DCM_PHYSICAL_ADDRESSING|DCM_FUNCTIONAL_ADDRESSING,
DCM_SESSION_DEFAULT|DCM_SESSION_PROGRAMMING|DCM_SESSION_EXTEND ,
&Dcm_RecvMsg3E, NULL_PTR
},
{ 0x85u, DCM_FUNCTIONAL_ADDRESSING|DCM_PHYSICAL_ADDRESSING,
DCM_SESSION_EXTEND ,
&Dcm_RecvMsg85, NULL_PTR
},
};
const Dcm_SessionRowType Dcm_SessionRow[DCM_SESSION_NUM] =
{
{
DCM_SESSION_DEFAULT,
DCM_SESSION_DEFAULT|DCM_SESSION_EXTEND,
DCM_SECURITY_LOCKED|DCM_SECURITY_LEV1
},
{
DCM_SESSION_PROGRAMMING,
DCM_SESSION_EXTEND,
DCM_SECURITY_LOCKED|DCM_SECURITY_LEV1
},
{
DCM_SESSION_EXTEND,
DCM_SESSION_DEFAULT|DCM_SESSION_PROGRAMMING|DCM_SESSION_EXTEND,
DCM_SECURITY_LOCKED|DCM_SECURITY_LEV1
},
};
#if(DCM_SERVICE_11_ENABLE == STD_ON)
const Dcm_ResetRowType Dcm_ResetRow[DCM_RESET_NUM] =
{
{ 0x01u,
DCM_SESSION_DEFAULT|DCM_SESSION_PROGRAMMING|DCM_SESSION_EXTEND,
DCM_SECURITY_LOCKED|DCM_SECURITY_LEV1
},
};
#endif
#if((DCM_READDID_NUM > 0) && (DCM_SERVICE_22_ENABLE == STD_ON))
const Dcm_ReadDidRowType Dcm_ReadDidRow[DCM_READDID_NUM] =
{
{
0xF15Bu,
DCM_SECURITY_LOCKED|DCM_SECURITY_LEV1,
&FL_ReadDid
},
};
#endif
const Dcm_SecurityRowType Dcm_SecurityRow[DCM_SECURITY_NUM] =
{
{
0x11u, 0x12u, DCM_SECURITY_LEV1,
DCM_SESSION_PROGRAMMING,
DCM_SECURITY_LOCKED|DCM_SECURITY_LEV1,
&SecM_GenerateSeed, &SecM_CompareKey
},
};
#if (DCM_COM_CONTROL_NUM > 0)
const Dcm_ComControlRowType Dcm_ComControlRow[DCM_COM_CONTROL_NUM] =
{
{
0x00u,
DCM_SESSION_EXTEND ,
DCM_SECURITY_LOCKED|DCM_SECURITY_LEV1
} ,
{
0x01u,
DCM_SESSION_EXTEND ,
DCM_SECURITY_LOCKED|DCM_SECURITY_LEV1
} ,
};
#endif
const Dcm_WriteDidRowType Dcm_WriteDidRow[DCM_WRITEDID_NUM] =
{
{
0xF199u, 0x11u,
DCM_SECURITY_LEV1,
&FL_WriteFingerPrint
},
};
const Dcm_RoutineControlRowType Dcm_RoutineControlRow[DCM_ROUTINE_CONTROL_NUM] =
{
{
0x0203u, 0x00u, DCM_PHYSICAL_ADDRESSING,
DCM_SESSION_DEFAULT|DCM_SESSION_PROGRAMMING|DCM_SESSION_EXTEND,
DCM_SECURITY_LOCKED|DCM_SECURITY_LEV1,
&Dcm_CheckProgPreCondition
},
{
0xFF00u, 0x02u, DCM_PHYSICAL_ADDRESSING,
DCM_SESSION_PROGRAMMING,
DCM_SECURITY_LEV1,
&Dcm_EraseMemory
},
{
0x0202u, 0x04u, DCM_PHYSICAL_ADDRESSING,
DCM_SESSION_PROGRAMMING,
DCM_SECURITY_LEV1,
&Dcm_CheckMemory
},
{
0xFF01u, 0x00u, DCM_PHYSICAL_ADDRESSING,
DCM_SESSION_PROGRAMMING,
DCM_SECURITY_LEV1,
&Dcm_CheckProgDependencies
},
};
const Dcm_DownloadRowType Dcm_DownloadRow =
{
{
DCM_SECURITY_LEV1
},
};
#if (DCM_DTC_SET_NUM > 0)
const Dcm_DTCSettingRowType Dcm_DTCSettingRow[DCM_DTC_SET_NUM] =
{
{
0x01u,
DCM_SESSION_EXTEND,
DCM_SECURITY_LOCKED|DCM_SECURITY_LEV1
},
{
0x02u,
DCM_SESSION_EXTEND,
DCM_SECURITY_LOCKED|DCM_SECURITY_LEV1
},
};
#endif
上面是服务的ID,下面是子服务。
由于要做基于UDS的BOOT,所以协议很重要,本文根据UDS协议,将用到的服务配置出来,在CAN通信过程中调用,至于如何和调用配合,请关注博主啊!