Commit 1cb64f87 authored by 张金硕's avatar 张金硕

Merge branch 'LYK' into 'dev'

诊断增加DID,可读可写,修改22/2E/27服务,11服务复位前增加延时,QAC问题修改

See merge request !83
parents c99dcdd1 345a423c
......@@ -68,6 +68,7 @@ static void Power_KL30_Init(void)
g_stRTCInformation.u8RTCYear = 20;
RTE_RTC_Init(g_stRTCInformation);
Menu_User_Init();
UDS_Startup_Init();
Can_Init();
Protocol_KL30_Wakeup_Init();
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, 500);
......
......@@ -2,7 +2,7 @@
#define __FLASH_H__
#include <stdint.h>
#include "common.h"
#define SECTOR_SIZE 512
#define SECTOR_SIZE 1024
#define WORD_SIZE 4
//#define FLASH_PROTCET
#define PROTECT_VALUE ((uint32_t)0x1234ABCD)
......
......@@ -61,40 +61,46 @@ int EraseChip (uint32_t adr)
* @param adr - sector address of user code flash
* @return status: 0 - OK, 1 - Failed
***********************************************************************************************************************/
int EraseSector (uint32_t adr)
int EraseSector(uint32_t adr)
{
#ifdef FLASH_PROTCET
if(flash_protect_flag != PROTECT_VALUE)
{
return(1);
}
flash_protect_flag = 0;
if (flash_protect_flag != PROTECT_VALUE)
{
return (1);
}
flash_protect_flag = 0;
#endif
__DI;
__DI;
FMC->FLERMD = 0x10;
FMC->FLPROT = 0xF1;
FMC->FLOPMD1 = 0x55;
FMC->FLOPMD2 = 0xAA;
FMC->FLOPMD2 = 0xAA;
// Write data to start address of sector to trigger Erase Operation
*(uint32_t *) adr = 0xFFFFFFFF;
*(uint32_t *)adr = 0xFFFFFFFF;
// polling Erase Over Flag
while((FMC->FLSTS & FMC_FLSTS_OVF_Msk) == 0);
while ((FMC->FLSTS & FMC_FLSTS_OVF_Msk) == 0)
{
;
}
FMC->FLSTS = FMC_FLSTS_OVF_Msk;
FMC->FLERMD = 0x00;
FMC->FLPROT = 0xF0;
if(FMC->FLSTS & FMC_FLSTS_EVF_Msk)
/* if(FMC->FLSTS & FMC_FLSTS_EVF_Msk)
{
FMC->FLSTS = FMC_FLSTS_EVF_Msk;
__EI;
return(1); /* verify ng */
return(1);
}
else
{
__EI;
return(0); /* verify ok */
}
return(0);
} */
__EI;
return 0;
}
/***********************************************************************************************************************
......
......@@ -203,11 +203,13 @@ void UDS_S_Data_Indication(uint16_t S_TAtype, uint8_t *S_Data, uint16_t S_Length
返回值:无 SYSC0_RUNPLL2CNTR
******************************************************************************/
extern uint8_t S3_Server_refresh;
extern uint8_t S3_ServerEN;
extern uint8_t SessionType;
void UDS_Process_Service_Request(void)
{
if (UDS_APP_RX.A_PDU.New)
{
S3_Server_refresh = 1;
S3_ServerEN = 0; // 收到消息时,暂停S3Timer
switch (UDS_APP_RX.A_PDU.A_PCI.SI)
{
case 0x10: UDS_Service_10_Indication(UDS_APP_RX.A_PDU.TA_type, UDS_APP_RX.A_PDU.Length, UDS_APP_RX.A_PDU.Data);
......@@ -218,11 +220,11 @@ void UDS_Process_Service_Request(void)
UDS_Service_22_Indication(UDS_APP_RX.A_PDU.TA_type, UDS_APP_RX.A_PDU.Length, UDS_APP_RX.A_PDU.Data);
}
break;
/* case 0x2E: UDS_Service_2E_Indication(UDS_APP_RX.A_PDU.TA_type, UDS_APP_RX.A_PDU.Length, UDS_APP_RX.A_PDU.Data);
break;
case 0x27: UDS_Service_27_Indication(UDS_APP_RX.A_PDU.TA_type, UDS_APP_RX.A_PDU.Length, UDS_APP_RX.A_PDU.Data);
break;
case 0x28: UDS_Service_28_Indication(UDS_APP_RX.A_PDU.TA_type, UDS_APP_RX.A_PDU.Length, UDS_APP_RX.A_PDU.Data);
case 0x2E: UDS_Service_2E_Indication(UDS_APP_RX.A_PDU.TA_type, UDS_APP_RX.A_PDU.Length, UDS_APP_RX.A_PDU.Data);
break;
/* case 0x28: UDS_Service_28_Indication(UDS_APP_RX.A_PDU.TA_type, UDS_APP_RX.A_PDU.Length, UDS_APP_RX.A_PDU.Data);
break;
case 0x85: UDS_Service_85_Indication(UDS_APP_RX.A_PDU.TA_type, UDS_APP_RX.A_PDU.Length, UDS_APP_RX.A_PDU.Data);
break; */
......@@ -239,6 +241,12 @@ void UDS_Process_Service_Request(void)
break;
}
UDS_APP_RX.A_PDU.New = 0;
if(SessionType > DefaultSession) // 非默认会话时执行
{
S3_Server_refresh = 1; // 诊断请求处理完成, 刷新S3Timer
S3_ServerEN = 1; // 消息处理完成,恢复S3Timer计时
}
}
}
......
......@@ -34,12 +34,22 @@ DiagSendDataNeg NegRes;
uint8_t UDS_ISO14229_Transfer[250];
DiagFlag DiagDataForFlag;
uint8_t Service27_DelayTimer_Enable;
uint8_t Service27_DelayTimer;
uint8_t Services27_Seed_Requested;
uint8_t DiagLockFlag;
uint32_t Ser27_SeedRandomNumber;
uint32_t GenerateKey;
uint8_t Attemptcnt;
/****************S3Timer********************/
uint8_t S3_ServerEN = 0;
uint8_t S3_ServerCnt = 0;
uint8_t S3_Server_refresh = 0;
/****************DiagnosticSession*****************/
uint8_t SessionType = 0x01;
uint8_t SessionType;
Diag_Write_Data_t Diag_Write_Data;
/******************************************************************************
The service access point of the diagnostics application layer provides a number
of services that all have the same general structure. For each service, three
......@@ -68,7 +78,7 @@ uint8_t MCU_HWversion[6] = {'H', 'V', (uint8_t)((HWV >> 8u) & 0x0Fu) + 0x30u, '.
uint8_t MCU_FBLversion[6] = {'B', 'V', (uint8_t)((BTV >> 8u) & 0x0Fu) + 0x30u, '.', (uint8_t)((BTV >> 4u) & 0x0Fu) + 0x30u, (uint8_t)(BTV & 0x0Fu) + 0x30u};
//零件号信息 F187
uint8_t MCU_PartNumber[16] = {'K', 'E', 'E', 'W', 'A', 'Y', '_', 'T', '0', '6', '_', 'M', 'E', 'T', 'E', 'R'};
uint8_t MCU_PartNumber[12] = {'H', 'J', 'Y', 'B', '-', '7', '5', '0', '0', 'T', 'F', 'T'};
/* internal program info */
const uint8_t DID_1024[13] =
......@@ -110,13 +120,36 @@ void S3_ServerCNTT(void)
if ( S3_ServerCnt >= S3_SERVER )
{
DIAG_InitParameter( );
UDS_Normal_Init( );
SessionType = DefaultSession;
}
else
{
++S3_ServerCnt;
}
}
if(Service27_DelayTimer_Enable == 1U)
{
if(Service27_DelayTimer >= 100U)
{
Service27_DelayTimer_Enable = 0U;
Attemptcnt -= AttemptMaxCnt - 1U;
Service27_DelayTimer = 0U;
}
else
{
++Service27_DelayTimer;
}
}
}
void Ser27_CreateRandomSeed(void)
{
do
{
Ser27_SeedRandomNumber = Ser27_SeedRandomNumber * 1103515245ul + 12345u;
} while ((Ser27_SeedRandomNumber == 0U) || (Ser27_SeedRandomNumber == 0xFFFFFFFFU));
}
uint8_t SerXXNRC12Filter(uint8_t insub, const uint8_t *supportsub, uint8_t size, uint8_t *index)
......@@ -311,7 +344,7 @@ void UDS_Service_10_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A
NrcCode = SerXXNRC12Filter(SubFunction, Ser10Sub, sizeof(Ser10Sub), &Index);
}
if ((0 == NrcCode) && (DIAG_ID_Rx_FUN == FunorPhy) && (ProgrammingSession == Ser10Sub[Index]))
if ((0 == NrcCode) && (DIAG_ID_Rx_FUN == FunorPhy) && (ProgrammingSession == SubFunction))
{
NrcCode = subFunctionNotSupported;
}
......@@ -339,12 +372,8 @@ void UDS_Service_10_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A
UDS_ISO14229_Transfer[4] = 200;
if (DefaultSession == SubFunction)
{
S3_ServerEN = 0;
UDS_Normal_Init();
SessionType = DefaultSession;
DIAG_InitParameter();
CAN_RX_SetEnable(&CAN_CH0_CanMsgOp, CAN_N_RX_Enable);
CAN_TX_SetEnable(&CAN_CH0_CanMsgTxOp, CAN_N_TX_Enable);//切会话解除
if (AbleResponseType == Ser10BanResponse)
{
......@@ -360,10 +389,6 @@ void UDS_Service_10_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A
}
else if (ProgrammingSession == SubFunction)
{
S3_ServerEN = 1;
S3_Server_refresh = 1;
SessionType = ProgrammingSession;
if (AbleResponseType == Ser10BanResponse)
{
if (bit_is_clear(UDS_ISO14229_Transfer[0], 7))
......@@ -372,22 +397,17 @@ void UDS_Service_10_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A
UDS_Service_Response(si, NEGATIVE_RSP, DIAG_ID_Tx, 1, (uint8_t *)(&NegRes.code));
Write_App_InValid(Jump_To_Boot_Need_Answer);
for (i = 0; i < 250; ++i)
{
__NOP();
}
__NVIC_SystemReset();
}
else
{
Write_App_InValid(Jump_To_Boot_No_Answer);
for (i = 0; i < 250; ++i)
{
__NOP();
}
__NVIC_SystemReset();
}
for (i = 0; i < 250; ++i)
{
__NOP();
}
__NVIC_SystemReset();
}
else
{
......@@ -403,8 +423,7 @@ void UDS_Service_10_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A
}
else if (ExtendedDiagnosticSession == SubFunction)
{
S3_ServerEN = 1;
S3_Server_refresh = 1;
UDS_Normal_Init();
SessionType = ExtendedDiagnosticSession;
if (AbleResponseType == Ser10BanResponse)
......@@ -428,14 +447,12 @@ void UDS_Service_10_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A
{
NegRes.code = NrcCode;
UDS_Service_Response(si, NEGATIVE_RSP, DIAG_ID_Tx, 1, (uint8_t *)(&NegRes.code));
return;
}
}
else
{
NegRes.code = NrcCode;
UDS_Service_Response(si, NEGATIVE_RSP, DIAG_ID_Tx, 1, (uint8_t *)(&NegRes.code));
return;
}
}
}
......@@ -522,10 +539,11 @@ void UDS_Service_11_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A
{
UDS_Service_Response(si, POSITIVE_RSP, DIAG_ID_Tx, 1, UDS_ISO14229_Transfer);
}
i = 900;
i = 6400;
while (--i)
{
__NOP();
RTE_WDT_Clear();
}
__NVIC_SystemReset();
}
......@@ -557,7 +575,7 @@ static const uint8_t Ser22BanResponse = DisableResponseType;
static const uint8_t Ser22Sub [] = {0xFF};
static const uint8_t Ser22MinLen [] = {2};
static const uint8_t Ser22SubLen [] = {2};
static const uint16_t Ser22DIDList [] = {0xF195, 0xF193, 0xF180, 0xF187, 0x1024, 0x1028, 0xF184,/*0x2024*/ };
static const uint16_t Ser22DIDList [] = {0xF195, 0xF193, 0xF180, 0xF187, 0x1024, 0x1028, 0xF184, 0x5000 };
static const uint8_t Ser22SupportSession = DefaultMode | ProgrammingMode | ExtendedDiagnosticMode;
static const uint8_t Ser22SubSupportSession [] = {DefaultMode | ProgrammingMode | ExtendedDiagnosticMode};
void UDS_Service_22_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A_Data)
......@@ -622,7 +640,7 @@ void UDS_Service_22_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A
if (0 == NrcCode)
{
DID = ((uint16_t)UDS_ISO14229_Transfer[0] << 8) | UDS_ISO14229_Transfer[1];
NrcCode = SerXXNRC31DIDFilter(DID, Ser22DIDList, (sizeof(Ser22DIDList) / 2), &Index);
NrcCode = SerXXNRC31DIDFilter(DID, Ser22DIDList, (uint8_t)(sizeof(Ser22DIDList) / 2), &Index);
}
if (0 == NrcCode)
......@@ -653,11 +671,16 @@ void UDS_Service_22_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A
break;
case 0xF187: // 读零件号
for (i = 0; i < 16; i++)
for (i = 0; i < 12; i++)
{
UDS_ISO14229_Transfer[i + 2] = MCU_PartNumber[i];
}
UDS_Service_Response(si, POSITIVE_RSP, DIAG_ID_Tx, 2 + 16, UDS_ISO14229_Transfer);
UDS_Service_Response(si, POSITIVE_RSP, DIAG_ID_Tx, 2 + 12, UDS_ISO14229_Transfer);
break;
case 0x5000U: // 读UUID
(void)memcpy(&UDS_ISO14229_Transfer[2], Diag_Write_Data.DID_5000, sizeof(Diag_Write_Data.DID_5000));
UDS_Service_Response(si, POSITIVE_RSP, DIAG_ID_Tx, 2 + sizeof(Diag_Write_Data.DID_5000), UDS_ISO14229_Transfer);
break;
case 0x1024: // 读内部版本号
......@@ -700,6 +723,284 @@ void UDS_Service_22_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A
}
}
void UDS_Service_27_Indication(uint32_t A_TA_type, uint16_t A_Length, uint8_t *A_Data)
{
uint16_t i;
uint8_t NRC;
uint32_t KeyReceive;
uint8_t Seed_Array[4];
uint8_t SID = SecurityAccess;
uint8_t SubFunction = 0U;
uint16_t Data_Length = A_Length;
uint32_t Rx_ID = A_TA_type;
/* do not support functional address */
if (Rx_ID == DIAG_ID_Rx_FUN)
{
NRC = serviceNotSupported;
}
else
{
NRC = POSITIVE_RSP;
}
/* NRC7F */
if (0U == NRC)
{
if (SessionType != ExtendedDiagnosticSession)
{
NRC = serviceNotSupportedInActiveSession;
}
}
/* NRC13 */
if (0U == NRC)
{
if (Data_Length < 1U)
{
NRC = incorrectMessageLength;
}
}
/* NRC12 */
if (0U == NRC)
{
for (i = 0; i < Data_Length; i++)
{
UDS_ISO14229_Transfer[i] = *(A_Data + i);
}
SubFunction = UDS_ISO14229_Transfer[0];
if ((SubFunction != requestSeed_LV1) && (SubFunction != sendKey_LV1))
{
NRC = subFunctionNotSupported;
}
}
/* NRC13 */
if (0U == NRC)
{
if (SubFunction == requestSeed_LV1)
{
if (Data_Length != 1U)
{
NRC = incorrectMessageLength;
}
}
else
{
if (Data_Length != 5U)
{
NRC = incorrectMessageLength;
}
}
}
/* NRC24 */
if (0U == NRC)
{
if (SubFunction == sendKey_LV1)
{
if (Services27_Seed_Requested != 1U)
{
NRC = requestSequenceError;
}
}
}
/* NRC37 */
if (0U == NRC)
{
if (SubFunction == requestSeed_LV1)
{
if (Service27_DelayTimer_Enable == 1)
{
NRC = requiredTimeDelayNotExpired;
}
}
}
if (0U == NRC)
{
switch (SubFunction)
{
case requestSeed_LV1:
if (DiagLockFlag == NormalKeyUnlock)
{
UDS_ISO14229_Transfer[0] = requestSeed_LV1;
UDS_ISO14229_Transfer[1] = 0;
UDS_ISO14229_Transfer[2] = 0;
UDS_ISO14229_Transfer[3] = 0;
UDS_ISO14229_Transfer[4] = 0;
}
else
{
Ser27_CreateRandomSeed();
UDS_ISO14229_Transfer[1] = (uint8_t)(Ser27_SeedRandomNumber >> 24U);
UDS_ISO14229_Transfer[2] = (uint8_t)(Ser27_SeedRandomNumber >> 16U);
UDS_ISO14229_Transfer[3] = (uint8_t)(Ser27_SeedRandomNumber >> 8U);
UDS_ISO14229_Transfer[4] = (uint8_t)Ser27_SeedRandomNumber;
Services27_Seed_Requested = 1;
}
UDS_Service_Response(SID, POSITIVE_RSP, DIAG_ID_Tx, 5, UDS_ISO14229_Transfer);
Seed_Array[0] = UDS_ISO14229_Transfer[1];
Seed_Array[1] = UDS_ISO14229_Transfer[2];
Seed_Array[2] = UDS_ISO14229_Transfer[3];
Seed_Array[3] = UDS_ISO14229_Transfer[4];
GenerateKey = CalculateKey(Seed_Array);
break;
case sendKey_LV1:
Services27_Seed_Requested = 0U;
KeyReceive = Combine_U8_Into_U32(&UDS_ISO14229_Transfer[1]);
if (KeyReceive == GenerateKey)
{
DiagLockFlag = NormalKeyUnlock;
UDS_Service_Response(SID, POSITIVE_RSP, DIAG_ID_Tx, 1, UDS_ISO14229_Transfer);
}
else
{
Attemptcnt++;
if (Attemptcnt >= 3)
{
Service27_DelayTimer_Enable = 1U;
NRC = exceedNumberOfAttempts;
UDS_Service_Response(SID, NEGATIVE_RSP, DIAG_ID_Tx, 1, (uint8_t *)(&NRC));
}
else
{
NRC = invalidKey;
UDS_Service_Response(SID, NEGATIVE_RSP, DIAG_ID_Tx, 1, (uint8_t *)(&NRC));
}
}
break;
default:
NRC = subFunctionNotSupported;
UDS_Service_Response(SID, NEGATIVE_RSP, DIAG_ID_Tx, 1, (uint8_t *)(&NRC));
break;
}
}
else
{
if(Rx_ID == DIAG_ID_Rx_PHY)
{
UDS_Service_Response(SID, NEGATIVE_RSP, DIAG_ID_Tx, 1, (uint8_t *)(&NRC));
}
}
}
void UDS_Service_2E_Indication(uint32_t A_TA_type, uint16_t A_Length, uint8_t *A_Data)
{
uint16_t i = 0U;
uint8_t ret = 0U;
uint8_t NRC;
uint8_t SID = WriteDataByIdentifier;
uint16_t Data_Length = A_Length;
uint32_t Rx_ID = A_TA_type;
uint16_t DID = 0U;
/* do not support functional address */
if (Rx_ID == DIAG_ID_Rx_FUN)
{
NRC = serviceNotSupported;
}
else
{
NRC = POSITIVE_RSP;
}
/* NRC7F */
if (0U == NRC)
{
if (SessionType != ExtendedDiagnosticSession)
{
NRC = serviceNotSupportedInActiveSession;
}
}
/* NRC33 */
if (0U == NRC)
{
if (DiagLockFlag == NormalKeyLock)
{
NRC = securityAccessDenied;
}
}
/* NRC13 */
if (0U == NRC)
{
if (Data_Length < 3U)
{
NRC = incorrectMessageLength;
}
}
/* NRC31 */
if (0U == NRC)
{
for (i = 0; i < Data_Length; i++)
{
UDS_ISO14229_Transfer[i] = *(A_Data + i);
}
DID = ((uint16_t)UDS_ISO14229_Transfer[0] << 8) | (uint16_t)UDS_ISO14229_Transfer[1];
}
if (0U == NRC)
{
if(DID == 0x5000)
{
if(Data_Length != 34U)
{
NRC = incorrectMessageLength;
}
}
}
if (0U == NRC)
{
switch (DID)
{
case 0x5000U:
Diag_Write_Data.Flag = FLAG_APP_FLAG;
(void)memcpy(Diag_Write_Data.DID_5000, &UDS_ISO14229_Transfer[2], sizeof(Diag_Write_Data.DID_5000));
ret = Write_Data_Flash(FLASH_APP_RWDATA_INFO, sizeof(Diag_Write_Data), (uint8_t *)&Diag_Write_Data.Flag);
break;
default:
NRC = requestOutOfRange;
break;
}
if (0U == NRC)
{
if (ret == 0U)
{
UDS_Service_Response(SID, POSITIVE_RSP, DIAG_ID_Tx, 2U, UDS_ISO14229_Transfer);
}
else
{
NRC = generalProgrammingFailure;
UDS_Service_Response(SID, NEGATIVE_RSP, DIAG_ID_Tx, 1, &NRC);
}
}
else
{
UDS_Service_Response(SID, NEGATIVE_RSP, DIAG_ID_Tx, 1, &NRC);
}
}
else
{
if (Rx_ID == DIAG_ID_Rx_PHY)
{
UDS_Service_Response(SID, NEGATIVE_RSP, DIAG_ID_Tx, 1, &NRC);
}
}
}
/******************************************************************************
3E# - TesterPresent
******************************************************************************/
......@@ -800,12 +1101,34 @@ void UDS_Service_3E_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A
}
}
void UDS_Normal_Init(void)
{
Services27_Seed_Requested = 0U;
DiagLockFlag = NormalKeyLock;
GenerateKey = 0U;
}
/*************IGN on,S3 Timeout****************/
void DIAG_InitParameter(void)
void UDS_Startup_Init(void)
{
S3_ServerCnt = 0;
S3_ServerEN = 0;
S3_Server_refresh = 0;
SessionType = DefaultSession;
Ser27_SeedRandomNumber = 20240728U;
Services27_Seed_Requested = 0U;
DiagLockFlag = NormalKeyLock;
GenerateKey = 0U;
Attemptcnt = 0U;
Service27_DelayTimer = 0U;
Service27_DelayTimer_Enable = 0U;
flash_read(FLASH_APP_RWDATA_INFO, sizeof(Diag_Write_Data), (uint8_t *)&Diag_Write_Data.Flag);
if(Diag_Write_Data.Flag != FLAG_APP_FLAG)
{
memset((uint8_t *)&Diag_Write_Data.Flag, 0xFFU, sizeof(Diag_Write_Data));
}
}
void Get_Into_630H_Update_MCU_Mode(void)
......@@ -818,3 +1141,60 @@ void Get_Into_630H_Update_MCU_Mode(void)
}
__NVIC_SystemReset();
}
uint32_t CalculateKey(uint8_t seed_array[])
{
uint8_t key_array[4];
uint32_t key_value;
key_array[0] = seed_array[0] | seed_array[3];
key_array[1] = (seed_array[1] >> 1) | (seed_array[2] << 1);
key_array[2] = (seed_array[2] >> 2) | (seed_array[1] << 2);
key_array[3] = (seed_array[3] >> 3) | (seed_array[0] << 3);
key_value = ((uint32_t)key_array[0] << 24U);
key_value = key_value | ((uint32_t)key_array[1] << 16U);
key_value = key_value | ((uint32_t)key_array[2] << 8U);
key_value = key_value | (uint32_t)key_array[3];
return (key_value);
}
/**
* @brief 按照传入的8bit数据的指针,向后查找4个8bit数据,按照顺序组合成一个32bit数据
*/
uint32_t Combine_U8_Into_U32(uint8_t *U8)
{
uint32_t ret = 0U;
uint32_t d_temp;
d_temp = (uint32_t)U8[0];
ret = (d_temp << 24) & 0xFF000000UL;
d_temp = (uint32_t)U8[1];
ret = ret | ((d_temp << 16) & 0x00FF0000UL);
d_temp = (uint32_t)U8[2];
ret = ret | ((d_temp << 8) & 0x0000FF00UL);
d_temp = (uint32_t)U8[3];
ret = ret | (d_temp & 0x000000FFUL);
return (ret);
}
uint8_t Write_Data_Flash(uint32_t addr, uint32_t size, uint8_t *data)
{
uint8_t ret;
erase_memory(FLASH_APP_RWDATA_INFO, (FLASH_APP_RWDATA_INFO + size));
ret = flash_write(FLASH_APP_RWDATA_INFO, size, data);
return (ret);
}
void erase_memory(uint32_t start_addr, uint32_t end_addr)
{
uint32_t i;
for (i = start_addr; i < end_addr; i += FLASH_PAGE_SIZE)
{
(void)EraseSector(i);
if((i % (FLASH_PAGE_SIZE * 16U)) == 0U) /* feed watch dog after erase 16 block */
{
RTE_WDT_Clear();
}
}
}
......@@ -47,6 +47,8 @@
#define FLASH_APP_RODATA_INFO (0x00501C00UL) /* 存储只读DID信息 */
#define FLASH_APP_RWDATA_INFO (0x00502000UL) /* 存储可写的DID信息 */
#define FLASH_PAGE_SIZE (0x400UL) /* FLASH 页面大小 */
#define Data_Flash_Addr_BootValid_OFFSET 0x00000000
#define Data_Flash_Addr_DiagReceive_OFFSET 0x00002000
#define Data_Flash_Addr_Diag2E_OFFSET 0x00004000
......@@ -56,6 +58,8 @@
#define Jump_To_Boot_No_Answer 0xA77A8AA8
#define Flag_App_OTAStatus 0x3663B88B // ����Boot��ԭ������ΪOTA
#define FLAG_APP_FLAG (0xA77A5AA5U) /* 表示APP标识已写入 */
#define EnableInterrupts \
{ \
__asm CLI; \
......@@ -176,8 +180,6 @@
// #define sendKey_LV11 0x12
#define NormalKeyUnlock 0x01
#define NormalKeyLock 0x00
#define BootKeyUnlock 0x02
#define BootKeyLock 0x00
#define RequestSeedMaxCnt 0x04
#define AttemptMaxCnt 0x03
......@@ -338,26 +340,45 @@ typedef struct
uint8_t OpCode;
} DiagSendDataNeg;
void UDS_Service_10_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A_Data);
void UDS_Service_11_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A_Data);
void UDS_Service_22_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A_Data);
void UDS_Service_3E_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A_Data);
void S3_ServerCNTT(void);
extern void DIAG_InitParameter(void);
typedef struct
{
uint32_t Flag;
uint8_t DID_5000[32]; /* programming date */
// uint8_t fill_data[17]; /* 用于保证该结构体长度是4的倍数 */
} Diag_Write_Data_t;
extern void UDS_Service_10_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A_Data);
extern void UDS_Service_11_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A_Data);
extern void UDS_Service_22_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A_Data);
extern void UDS_Service_27_Indication(uint32_t A_TA_type, uint16_t A_Length, uint8_t *A_Data);
extern void UDS_Service_2E_Indication(uint32_t A_TA_type, uint16_t A_Length, uint8_t *A_Data);
extern void UDS_Service_3E_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A_Data);
extern void S3_ServerCNTT(void);
extern void UDS_Normal_Init(void);
extern void UDS_Startup_Init(void);
typedef void (*InitFunction)(void);
/***********Local Functin*************/
uint8_t GetCurrentSession(void);
uint8_t SerXXNRC12Filter(uint8_t insub, const uint8_t *supportsub, uint8_t size, uint8_t *index);
uint8_t SerXXNRC13Filter(uint8_t type, uint8_t serlength, const uint8_t *length, uint8_t index);
uint8_t SerXXNRC22Filter(void);
uint8_t SerXXNRC31DIDFilter(uint16_t inDID, const uint16_t *DIDList, uint8_t size, uint8_t *index);
uint8_t SerXXNRC7EFilter(const uint8_t *SubSupportSession, uint8_t index);
uint8_t SerXXNRC7FFilter(uint8_t SupportSession);
void Write_App_InValid(uint32_t m32);
extern uint8_t GetCurrentSession(void);
extern uint8_t SerXXNRC12Filter(uint8_t insub, const uint8_t *supportsub, uint8_t size, uint8_t *index);
extern uint8_t SerXXNRC13Filter(uint8_t type, uint8_t serlength, const uint8_t *length, uint8_t index);
extern uint8_t SerXXNRC22Filter(void);
extern uint8_t SerXXNRC31DIDFilter(uint16_t inDID, const uint16_t *DIDList, uint8_t size, uint8_t *index);
extern uint8_t SerXXNRC7EFilter(const uint8_t *SubSupportSession, uint8_t index);
extern uint8_t SerXXNRC7FFilter(uint8_t SupportSession);
extern void Write_App_InValid(uint32_t m32);
extern void Get_Into_630H_Update_MCU_Mode(void);
extern void Check_MCU_Info_in_630H(void);
extern void Ser27_CreateRandomSeed(void);
extern uint32_t CalculateKey(uint8_t seed_array[]);
extern uint32_t Combine_U8_Into_U32(uint8_t *U8);
extern uint8_t Write_Data_Flash(uint32_t addr, uint32_t size, uint8_t *data);
extern void erase_memory(uint32_t start_addr, uint32_t end_addr);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment