Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
haoJin750TFT
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
时昊
haoJin750TFT
Commits
41d55bd2
Commit
41d55bd2
authored
Sep 15, 2024
by
李延凯
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 增加诊断2E服务
parent
53981bdb
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
179 additions
and
38 deletions
+179
-38
flash.h
...Device/Cmsemicon/BAT32A279/Library/Driver/include/flash.h
+1
-1
flash.c
...rce/Device/Cmsemicon/BAT32A279/Library/Driver/src/flash.c
+21
-15
UDS_ISO14229_Server.c
Firmware/Source/UDS/UDS_ISO14229_Server.c
+2
-2
UDS_ISO14229_Services.c
Firmware/Source/UDS/UDS_ISO14229_Services.c
+125
-4
UDS_ISO14229_Services.h
Firmware/Source/UDS/UDS_ISO14229_Services.h
+30
-16
No files found.
Firmware/Source/Device/Cmsemicon/BAT32A279/Library/Driver/include/flash.h
View file @
41d55bd2
...
...
@@ -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)
...
...
Firmware/Source/Device/Cmsemicon/BAT32A279/Library/Driver/src/flash.c
View file @
41d55bd2
...
...
@@ -61,12 +61,12 @@ 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
)
if
(
flash_protect_flag
!=
PROTECT_VALUE
)
{
return
(
1
);
return
(
1
);
}
flash_protect_flag
=
0
;
#endif
...
...
@@ -76,25 +76,31 @@ int EraseSector (uint32_t adr)
FMC
->
FLOPMD1
=
0x55
;
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
;
}
/***********************************************************************************************************************
...
...
Firmware/Source/UDS/UDS_ISO14229_Server.c
View file @
41d55bd2
...
...
@@ -222,9 +222,9 @@ void UDS_Process_Service_Request(void)
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 0x2E: UDS_Service_2E_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);
/*
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; */
...
...
Firmware/Source/UDS/UDS_ISO14229_Services.c
View file @
41d55bd2
...
...
@@ -48,6 +48,8 @@ uint8_t S3_ServerCnt = 0;
uint8_t
S3_Server_refresh
=
0
;
/****************DiagnosticSession*****************/
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
...
...
@@ -817,7 +819,7 @@ void UDS_Service_27_Indication(uint32_t A_TA_type, uint16_t A_Length, uint8_t *A
switch
(
SubFunction
)
{
case
requestSeed_LV1
:
if
(
DiagLockFlag
==
Boot
KeyUnlock
)
if
(
DiagLockFlag
==
Normal
KeyUnlock
)
{
UDS_ISO14229_Transfer
[
0
]
=
requestSeed_LV1
;
UDS_ISO14229_Transfer
[
1
]
=
0
;
...
...
@@ -848,7 +850,7 @@ void UDS_Service_27_Indication(uint32_t A_TA_type, uint16_t A_Length, uint8_t *A
KeyReceive
=
Combine_U8_Into_U32
(
&
UDS_ISO14229_Transfer
[
1
]);
if
(
KeyReceive
==
GenerateKey
)
{
DiagLockFlag
=
Boot
KeyUnlock
;
DiagLockFlag
=
Normal
KeyUnlock
;
UDS_Service_Response
(
SID
,
POSITIVE_RSP
,
DIAG_ID_Tx
,
1
,
UDS_ISO14229_Transfer
);
}
else
...
...
@@ -883,6 +885,104 @@ void UDS_Service_27_Indication(uint32_t A_TA_type, uint16_t A_Length, uint8_t *A
}
}
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
)
{
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
******************************************************************************/
...
...
@@ -986,7 +1086,7 @@ 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
=
Boot
KeyLock
;
DiagLockFlag
=
Normal
KeyLock
;
GenerateKey
=
0U
;
}
...
...
@@ -1000,7 +1100,7 @@ void UDS_Startup_Init(void)
Ser27_SeedRandomNumber
=
20240728U
;
Services27_Seed_Requested
=
0U
;
DiagLockFlag
=
Boot
KeyLock
;
DiagLockFlag
=
Normal
KeyLock
;
GenerateKey
=
0U
;
Attemptcnt
=
0U
;
Service27_DelayTimer
=
0U
;
...
...
@@ -1053,3 +1153,24 @@ uint32_t Combine_U8_Into_U32(uint8_t *U8)
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
();
}
}
}
Firmware/Source/UDS/UDS_ISO14229_Services.h
View file @
41d55bd2
...
...
@@ -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,12 +340,22 @@ 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_27_Indication
(
uint32_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
);
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
);
...
...
@@ -351,14 +363,14 @@ 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
);
...
...
@@ -366,5 +378,7 @@ 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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment