Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jiancetai
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
陈家乐
jiancetai
Commits
af19864e
Commit
af19864e
authored
May 26, 2025
by
梁百峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🐞
fix:版本号波动问题
parent
ffa58caa
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
1079 additions
and
275 deletions
+1079
-275
Barcode_Scanner.c
YueJin_test_bench/source/Appliciation/Barcode_Scanner.c
+58
-17
Barcode_Scanner.h
YueJin_test_bench/source/Appliciation/Barcode_Scanner.h
+1
-0
Check_Ctrl.c
YueJin_test_bench/source/Appliciation/Check_Ctrl.c
+3
-3
DoCAN_ISO15765.c
YueJin_test_bench/source/Appliciation/DoCAN_ISO15765.c
+244
-244
Key_user.c
YueJin_test_bench/source/Appliciation/Key_user.c
+5
-4
Protocol_CRC16.c
YueJin_test_bench/source/Appliciation/Protocol_CRC16.c
+48
-0
Protocol_CRC16.h
YueJin_test_bench/source/Appliciation/Protocol_CRC16.h
+10
-0
Protocol_Lib.c
YueJin_test_bench/source/Appliciation/Protocol_Lib.c
+274
-0
Protocol_Lib.h
YueJin_test_bench/source/Appliciation/Protocol_Lib.h
+67
-0
Protocol_User.c
YueJin_test_bench/source/Appliciation/Protocol_User.c
+307
-0
Protocol_User.h
YueJin_test_bench/source/Appliciation/Protocol_User.h
+14
-0
Task.c
YueJin_test_bench/source/Appliciation/Task.c
+38
-6
api_RS485.c
YueJin_test_bench/source/Appliciation/api_RS485.c
+10
-1
No files found.
YueJin_test_bench/source/Appliciation/Barcode_Scanner.c
View file @
af19864e
...
@@ -48,6 +48,7 @@ uint8_t powerstdio = 0;
...
@@ -48,6 +48,7 @@ uint8_t powerstdio = 0;
uint8_t
get_num_buf
[
34
];
uint8_t
get_num_buf
[
34
];
uint8_t
comparestart
;
uint8_t
comparestart
;
uint8_t
blename
[
5
];
uint8_t
blename
[
5
];
uint8_t
btmac
[
6
];
uint8_t
firstpowerflag
=
0
;
uint8_t
firstpowerflag
=
0
;
uint16_t
lightnumber
=
0
;
uint16_t
lightnumber
=
0
;
void
get_key
(
void
)
void
get_key
(
void
)
...
@@ -62,11 +63,12 @@ void get_key(void)
...
@@ -62,11 +63,12 @@ void get_key(void)
key_value
=
key_value
|
(
uint32_t
)
key_array
[
3
];
key_value
=
key_value
|
(
uint32_t
)
key_array
[
3
];
}
}
uint8_t
recvflag111
=
0
;
uint8_t
recvflag111
=
0
;
uint8_t
xierucishu
=
0
;
void
datacheck
(
void
)
void
datacheck
(
void
)
{
{
RS485_send_time
=
0
;
//
RS485_send_time = 0;
RS485_TX_finish
=
0
;
//
RS485_TX_finish = 0;
uint16_t
checksum
=
0
;
uint16_t
checksum
=
0
;
uint8_t
arraynum
=
0
;
uint8_t
arraynum
=
0
;
if
(
zhenduanflag
==
0
)
if
(
zhenduanflag
==
0
)
...
@@ -121,6 +123,12 @@ void datacheck(void)
...
@@ -121,6 +123,12 @@ void datacheck(void)
break
;
break
;
case
0x81
:
case
0x81
:
{
{
btmac
[
0
]
=
RS485_data
[
0
];
btmac
[
1
]
=
RS485_data
[
1
];
btmac
[
2
]
=
RS485_data
[
2
];
btmac
[
3
]
=
RS485_data
[
3
];
btmac
[
4
]
=
RS485_data
[
4
];
btmac
[
5
]
=
RS485_data
[
5
];
blename
[
0
]
=
RS485_data
[
6
];
blename
[
0
]
=
RS485_data
[
6
];
blename
[
1
]
=
RS485_data
[
7
];
blename
[
1
]
=
RS485_data
[
7
];
blename
[
2
]
=
RS485_data
[
8
];
blename
[
2
]
=
RS485_data
[
8
];
...
@@ -195,11 +203,13 @@ void datacheck(void)
...
@@ -195,11 +203,13 @@ void datacheck(void)
default:
default:
break
;
break
;
}
}
break
;
}
}
default:
default:
break
;
break
;
}
}
memset
(
RS485_data
,
0
,
64
);
memset
(
RS485_data
,
0
,
64
);
memset
(
BarCode
,
0
,
sizeof
(
BarCode
));
RS485_TX_finish
=
0
;
RS485_TX_finish
=
0
;
}
}
...
@@ -211,7 +221,7 @@ void datacheck(void)
...
@@ -211,7 +221,7 @@ void datacheck(void)
}
}
else
else
{
{
RS485_TX_finish
=
0
;
//
RS485_TX_finish = 0;
}
}
}
}
else
if
(
zhenduanflag
==
1
)
else
if
(
zhenduanflag
==
1
)
...
@@ -277,9 +287,20 @@ void datacheck(void)
...
@@ -277,9 +287,20 @@ void datacheck(void)
case
3
:
case
3
:
if
(
BarCode
[
2
]
==
0x4F
)
if
(
BarCode
[
2
]
==
0x4F
)
{
{
if
((
BarCode
[
4
]
==
0x6E
)
&&
(
BarCode
[
5
]
==
0x50
)
&&
(
BarCode
[
6
]
==
0
))
if
((
BarCode
[
4
]
==
0x6E
)
&&
(
BarCode
[
5
]
==
0x50
)
&&
(
BarCode
[
6
]
==
0
))
{
{
zhenduansendStep
++
;
// if(xierucishu > 4)
// {
zhenduansendStep
++
;
xierucishu
=
0
;
// }
// else
// {
// xierucishu++;
// }
RS485_TX_finish
=
0
;
RS485_TX_finish
=
0
;
}
}
if
(
BarCode
[
4
]
==
0x7F
&&
BarCode
[
5
]
==
0x2E
&&
BarCode
[
6
]
==
0x78
)
if
(
BarCode
[
4
]
==
0x7F
&&
BarCode
[
5
]
==
0x2E
&&
BarCode
[
6
]
==
0x78
)
...
@@ -435,20 +456,21 @@ void UART_Put2(uint32_t Value)
...
@@ -435,20 +456,21 @@ void UART_Put2(uint32_t Value)
}
}
else
else
{
{
UARTRxBuf
.
Rx_Buffer
[
UARTRxBuf
.
write_pos
]
=
Value
;
//
UARTRxBuf.Rx_Buffer [ UARTRxBuf.write_pos ] = Value;
UARTRxBuf
.
write_pos
=
(
UARTRxBuf
.
write_pos
+
1
)
%
UART_RX_MAX_DEPTH
;
//
UARTRxBuf.write_pos = (UARTRxBuf.write_pos + 1) % UART_RX_MAX_DEPTH;
}
}
RS485_send_time
=
0
;
//
RS485_send_time = 0;
return
;
return
;
}
}
void
Recv_Byte
(
void
)
void
Recv_Byte
(
void
)
{
{
int
i
=
0
;
int
i
=
0
;
int
j
=
0
;
int
j
=
0
;
uint32_t
len
;
uint32_t
len
;
int
k
=
0
;
readNum
=
Protocol_UartRead
(
mDataBufPtr
+
mDataBufLen
,
102
4
-
mDataBufLen
);
readNum
=
Protocol_UartRead
(
mDataBufPtr
+
mDataBufLen
,
102
5
-
mDataBufLen
);
uint8_t
testflag
=
0
;
if
(
readNum
>
0
)
if
(
readNum
>
0
)
{
{
mDataBufLen
+=
readNum
;
mDataBufLen
+=
readNum
;
...
@@ -457,9 +479,16 @@ void Recv_Byte(void)
...
@@ -457,9 +479,16 @@ void Recv_Byte(void)
{
{
for
(
i
=
0
;
i
<
mDataBufLen
;
i
++
)
for
(
i
=
0
;
i
<
mDataBufLen
;
i
++
)
{
{
if
(
i
>
5
)
// if(i > 5)
{
// {
if
((
mDataBufPtr
[
i
]
==
0x4A
)
&&
(
mDataBufPtr
[
i
-
1
]
==
0x4B
))
if
(
mDataBufPtr
[
i
-
1
]
==
0x59
&&
mDataBufPtr
[
i
]
==
0x44
)
{
k
=
i
-
1
;
}
if
((
mDataBufPtr
[
k
]
==
0x59
&&
mDataBufPtr
[
k
+
1
]
==
0x44
)
&&
(
mDataBufPtr
[
i
]
==
0x4A
)
&&
(
mDataBufPtr
[
i
-
1
]
==
0x4B
))
{
{
if
(
i
<
1
)
if
(
i
<
1
)
{
{
...
@@ -470,20 +499,32 @@ void Recv_Byte(void)
...
@@ -470,20 +499,32 @@ void Recv_Byte(void)
{
{
BarCode
[
j
]
=
mDataBufPtr
[
j
];
BarCode
[
j
]
=
mDataBufPtr
[
j
];
}
}
testflag
=
0
;
break
;
break
;
}
}
}
else
{
testflag
=
1
;
// break;
}
// }
}
}
if
(
testflag
)
{
testflag
=
0
;
break
;
}
// 解析协议
// 解析协议
len
=
i
;
len
=
i
+
1
;
if
(
(
len
>
0
)
&&
(
len
<
mDataBufLen
)
)
if
(
(
len
>
0
)
&&
(
len
<
mDataBufLen
)
)
{
{
// 将未解析的数据移到头部
// 将未解析的数据移到头部
// Move unparsed data to the head
// Move unparsed data to the head
memcpy
(
mDataBuf
Len
,
mDataBufLen
+
len
,
mDataBufLen
-
len
);
memcpy
(
mDataBuf
Ptr
,
mDataBufPtr
+
len
,
mDataBufLen
-
len
);
// memcpy(nowdata,mDataBufPtr + len,len);
// memcpy(nowdata,mDataBufPtr + len,len);
// datacheck();
// datacheck();
...
...
YueJin_test_bench/source/Appliciation/Barcode_Scanner.h
View file @
af19864e
...
@@ -37,4 +37,5 @@ extern uint8_t blename[5];
...
@@ -37,4 +37,5 @@ extern uint8_t blename[5];
extern
uint8_t
recvflag111
;
extern
uint8_t
recvflag111
;
extern
uint8_t
firstpowerflag
;
extern
uint8_t
firstpowerflag
;
extern
uint16_t
lightnumber
;
extern
uint16_t
lightnumber
;
extern
uint8_t
btmac
[
6
];
#endif
#endif
\ No newline at end of file
YueJin_test_bench/source/Appliciation/Check_Ctrl.c
View file @
af19864e
...
@@ -673,7 +673,7 @@ void Function_Check_Ctrl(uint32_t cmd)
...
@@ -673,7 +673,7 @@ void Function_Check_Ctrl(uint32_t cmd)
POWER_CTRL_KL30_Current
=
0
;
POWER_CTRL_KL30_Current
=
0
;
LED4
=
0
;
LED4
=
0
;
POWER_CTRL_KL30
=
0
;
POWER_CTRL_KL30
=
0
;
queren
=
0
;
//
queren = 0 ;
// ABStime = 0;
// ABStime = 0;
break
;
break
;
}
}
...
@@ -692,7 +692,7 @@ void Function_Check_Ctrl(uint32_t cmd)
...
@@ -692,7 +692,7 @@ void Function_Check_Ctrl(uint32_t cmd)
}
}
else
else
{
{
queren
=
1
;
//
queren = 1;
ABStime
=
0
;
ABStime
=
0
;
}
}
...
@@ -707,7 +707,7 @@ void Function_Check_Ctrl(uint32_t cmd)
...
@@ -707,7 +707,7 @@ void Function_Check_Ctrl(uint32_t cmd)
POWER_CTRL_KL30_Current
=
0
;
POWER_CTRL_KL30_Current
=
0
;
LED4
=
0
;
LED4
=
0
;
POWER_CTRL_KL30
=
0
;
POWER_CTRL_KL30
=
0
;
queren
=
0
;
//
queren = 0;
// ABStime = 0;
// ABStime = 0;
break
;
break
;
}
}
...
...
YueJin_test_bench/source/Appliciation/DoCAN_ISO15765.c
View file @
af19864e
/******************************************************************************
/******************************************************************************
文 件 名:
DoCAN_ISO15765.c
文 件 名:D
oCAN_ISO15765.c
功能描述:ISO 15765 规范规定的诊断服务函数库文件
功能描述:ISO 15765 规范规定的诊断服务函数库文件
作 者:张暄
作 者:张暄
版 本:
V1.0
版 本:V
1.0
日 期:
2016.7.18
日 期:2
016.7.18
******************************************************************************/
******************************************************************************/
#include "DoCAN_ISO15765.h"
#include "DoCAN_ISO15765.h"
...
@@ -27,15 +27,15 @@ extern void UDS_N_USData_FF_Indication(uint32_t N_TAtype, uint16_t Length);
...
@@ -27,15 +27,15 @@ extern void UDS_N_USData_FF_Indication(uint32_t N_TAtype, uint16_t Length);
extern
void
UDS_N_USData_Indication
(
uint32_t
N_TAtype
,
uint8_t
*
MessageData
,
uint16_t
Length
,
N_ResultEnum
N_Result
);
extern
void
UDS_N_USData_Indication
(
uint32_t
N_TAtype
,
uint8_t
*
MessageData
,
uint16_t
Length
,
N_ResultEnum
N_Result
);
/******************************************************************************
/******************************************************************************
后台服务
后台服务
******************************************************************************/
******************************************************************************/
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_Communication_Service
函数名:Do
CAN_Communication_Service
功 能:基于CAN总线的诊断通信服务后台控制函数
功 能:基于CAN总线的诊断通信服务后台控制函数
参 数:无
参 数:无
返回值:无
返回值:无
*******************************************************************************
*******************************************************************************
注 意:该服务函数必须被实时调用
注 意:该服务函数必须被实时调用
******************************************************************************/
******************************************************************************/
void
DoCAN_Communication_Service
(
void
)
void
DoCAN_Communication_Service
(
void
)
{
{
...
@@ -62,12 +62,12 @@ void DoCAN_Communication_Service(void)
...
@@ -62,12 +62,12 @@ void DoCAN_Communication_Service(void)
}
}
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_Timer_Update
函数名:Do
CAN_Timer_Update
功 能:更新定时器数值,用于时序控制以及STmin计时
功 能:更新定时器数值,用于时序控制以及STmin计时
参 数:Interval:定时器两次更新的时间间隔,单位
us
参 数:Interval:定时器两次更新的时间间隔,单位us
返回值:无
返回值:无
*******************************************************************************
*******************************************************************************
注 意:该服务函数必须被嵌入到定时中断中
注 意:该服务函数必须被嵌入到定时中断中
******************************************************************************/
******************************************************************************/
void
DoCAN_Timer_Update
(
uint16_t
Interval
)
void
DoCAN_Timer_Update
(
uint16_t
Interval
)
{
{
...
@@ -78,14 +78,14 @@ void DoCAN_Timer_Update(uint16_t Interval)
...
@@ -78,14 +78,14 @@ void DoCAN_Timer_Update(uint16_t Interval)
Services provided by network layer to higher layers
Services provided by network layer to higher layers
******************************************************************************/
******************************************************************************/
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_N_USData_Request
函数名:Do
CAN_N_USData_Request
功 能:该服务函数用于请求传输数据
功 能:该服务函数用于请求传输数据
This service is used to request the transfer of data. If necessary, the
This service is used to request the transfer of data. If necessary, the
network layer segments the data.
network layer segments the data.
参 数:N_TAtype :目标地址类型,发送数据请使用
DIAG_ID_Tx
参 数:N_TAtype :目标地址类型,发送数据请使用 DIAG_I
D_Tx
MessageData
:请求传输的数据
MessageData
:请求传输的数据
Length
:数据长度
Length
:数据长度
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_N_USData_Request
(
uint32_t
N_TAtype
,
uint8_t
MessageData
[],
uint16_t
Length
)
void
DoCAN_N_USData_Request
(
uint32_t
N_TAtype
,
uint8_t
MessageData
[],
uint16_t
Length
)
{
{
...
@@ -94,20 +94,20 @@ void DoCAN_N_USData_Request(uint32_t N_TAtype, uint8_t MessageData [], uint16_t
...
@@ -94,20 +94,20 @@ void DoCAN_N_USData_Request(uint32_t N_TAtype, uint8_t MessageData [], uint16_t
uint8_t
dlc
;
uint8_t
dlc
;
uint8_t
data
[
8
];
uint8_t
data
[
8
];
/*
非空闲状态下不允许发送
*/
/*
非空闲状态下不允许发送*/
if
(
TpCtrl
.
Process
!=
TP_IDLE
)
if
(
TpCtrl
.
Process
!=
TP_IDLE
)
{
{
DoCAN_N_USData_Confirm
(
N_TAtype
,
N_ERROR
);
DoCAN_N_USData_Confirm
(
N_TAtype
,
N_ERROR
);
}
}
else
else
{
{
if
(
(
Length
==
0u
)
||
(
Length
>
N_USDATA_TX_BUFFER_SIZE
)
)
/*
非法的长度
*/
if
(
(
Length
==
0u
)
||
(
Length
>
N_USDATA_TX_BUFFER_SIZE
)
)
/*
非法的长度*/
{
{
DoCAN_N_USData_Confirm
(
N_TAtype
,
N_ERROR
);
DoCAN_N_USData_Confirm
(
N_TAtype
,
N_ERROR
);
}
}
else
else
{
{
/*
将数据缓存到发送Buffer中
*/
/*
将数据缓存到发送Buffer中*/
N_USDataTxBuffer
.
N_TAtype
=
N_TAtype
;
N_USDataTxBuffer
.
N_TAtype
=
N_TAtype
;
N_USDataTxBuffer
.
Length
=
Length
;
N_USDataTxBuffer
.
Length
=
Length
;
...
@@ -116,18 +116,18 @@ void DoCAN_N_USData_Request(uint32_t N_TAtype, uint8_t MessageData [], uint16_t
...
@@ -116,18 +116,18 @@ void DoCAN_N_USData_Request(uint32_t N_TAtype, uint8_t MessageData [], uint16_t
N_USDataTxBuffer
.
MsgData
[
i
]
=
MessageData
[
i
];
N_USDataTxBuffer
.
MsgData
[
i
]
=
MessageData
[
i
];
}
}
/*
更新传输层状态
*/
/*
更新传输层状态*/
TpCtrl
.
NonStopMode
=
0u
;
TpCtrl
.
NonStopMode
=
0u
;
TpCtrl
.
TotalLen
=
Length
;
/*
记录字节总数
*/
TpCtrl
.
TotalLen
=
Length
;
/*
记录字节总数*/
TpCtrl
.
BSMax
=
0xFFu
;
/*
初始化BSMax数值
*/
TpCtrl
.
BSMax
=
0xFFu
;
/*
初始化BSMax数值*
/
TpCtrl
.
STmin
=
0x7Fu
;
TpCtrl
.
STmin
=
0x7Fu
;
/*
拆分为N
_PDU*/
/*
拆分为N_
PDU*/
if
(
TpCtrl
.
TotalLen
<
8u
)
/*
数据总长度小于8,采用单帧发送
*/
if
(
TpCtrl
.
TotalLen
<
8u
)
/*
数据总长度小于8,采用单帧发送*/
{
{
TpCtrl
.
BlockSize
=
1u
;
/*
单帧,Block总数为1
*/
TpCtrl
.
BlockSize
=
1u
;
/*
单帧,Block总数为1*
/
TpCtrl
.
Len
=
TpCtrl
.
TotalLen
;
/*
单帧发出全部的数据
*/
TpCtrl
.
Len
=
TpCtrl
.
TotalLen
;
/*
单帧发出全部的数据*/
TpCtrl
.
BlockCnt
=
1u
;
/*
记录已发送Block数
*/
TpCtrl
.
BlockCnt
=
1u
;
/*
记录已发送Block数*/
TransportTxData
.
N_PDU_SF
.
N_TAtype
=
N_USDataTxBuffer
.
N_TAtype
;
TransportTxData
.
N_PDU_SF
.
N_TAtype
=
N_USDataTxBuffer
.
N_TAtype
;
TransportTxData
.
N_PDU_SF
.
N_PCI
.
Type
=
SINGLE_FRAME
;
TransportTxData
.
N_PDU_SF
.
N_PCI
.
Type
=
SINGLE_FRAME
;
...
@@ -139,18 +139,18 @@ void DoCAN_N_USData_Request(uint32_t N_TAtype, uint8_t MessageData [], uint16_t
...
@@ -139,18 +139,18 @@ void DoCAN_N_USData_Request(uint32_t N_TAtype, uint8_t MessageData [], uint16_t
TransportTxData
.
N_PDU_SF
.
N_Data
[
i
]
=
N_USDataTxBuffer
.
MsgData
[
i
];
TransportTxData
.
N_PDU_SF
.
N_Data
[
i
]
=
N_USDataTxBuffer
.
MsgData
[
i
];
}
}
}
}
else
/*
数据总长度大于等于8,采用多帧发送,首先发送首帧
*/
else
/*
数据总长度大于等于8,采用多帧发送,首先发送首帧*/
{
{
if
(
(
Length
+
1u
)
%
7u
)
/*
计算
BlockSize*/
if
(
(
Length
+
1u
)
%
7u
)
/*
计算B
lockSize*/
{
{
TpCtrl
.
BlockSize
=
(
Length
+
8u
)
/
7u
;
/*
等效于
(Length + 1) / 7 + 1*/
TpCtrl
.
BlockSize
=
(
Length
+
8u
)
/
7u
;
/*
等效于(
Length + 1) / 7 + 1*/
}
}
else
else
{
{
TpCtrl
.
BlockSize
=
(
Length
+
1u
)
/
7u
;
TpCtrl
.
BlockSize
=
(
Length
+
1u
)
/
7u
;
}
}
TpCtrl
.
Len
=
6u
;
/*
首帧发出数据长度为6
*/
TpCtrl
.
Len
=
6u
;
/*
首帧发出数据长度为6*/
TpCtrl
.
BlockCnt
=
1u
;
/*
记录已发送Block数
*/
TpCtrl
.
BlockCnt
=
1u
;
/*
记录已发送Block数*/
TransportTxData
.
N_PDU_FF
.
N_TAtype
=
N_USDataTxBuffer
.
N_TAtype
;
TransportTxData
.
N_PDU_FF
.
N_TAtype
=
N_USDataTxBuffer
.
N_TAtype
;
TransportTxData
.
N_PDU_FF
.
N_PCI
.
Type
=
FIRST_FRAME
;
TransportTxData
.
N_PDU_FF
.
N_PCI
.
Type
=
FIRST_FRAME
;
...
@@ -171,23 +171,23 @@ void DoCAN_N_USData_Request(uint32_t N_TAtype, uint8_t MessageData [], uint16_t
...
@@ -171,23 +171,23 @@ void DoCAN_N_USData_Request(uint32_t N_TAtype, uint8_t MessageData [], uint16_t
data
[
i
]
=
TransportTxData
.
Frame
.
Data
[
i
];
data
[
i
]
=
TransportTxData
.
Frame
.
Data
[
i
];
}
}
/*TpCtrl.TxReq = 1u;*/
/*TpCtrl.TxReq = 1u;*/
DoCAN_Start_Timer
(
TIMING_PARA_N_As
);
/*
启动N_As计时
*/
DoCAN_Start_Timer
(
TIMING_PARA_N_As
);
/*
启动N_As计时*/
TpCtrl
.
Process
=
TP_TX_INIT
;
/*
数据帧已发出,等待发送完成
*/
TpCtrl
.
Process
=
TP_TX_INIT
;
/*
数据帧已发出,等待发送完成*/
DoCAN_L_Data_Request
(
id
,
dlc
,
data
);
DoCAN_L_Data_Request
(
id
,
dlc
,
data
);
}
}
}
}
}
}
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_N_USData_Confirm
函数名:Do
CAN_N_USData_Confirm
功 能:该服务函数由网络层发起,用于确认前一次使用N_USData.request服务向
功 能:该服务函数由网络层发起,用于确认前一次使用N_USData.request服务向
N_TAtype
地址发送的数据是否发送完成
N_TAtype
地址发送的数据是否发送完成
The N_USData.confirm service is issued by the network layer. The service
The N_USData.confirm service is issued by the network layer. The service
primitive confirms the completion of an N_USData.request service
primitive confirms the completion of an N_USData.request service
identified by the address information in N_TAtype.
identified by the address information in N_TAtype.
参 数:N_TAtype :N_USData.confirm服务请求的发送地址
参 数:N_TAtype :N_USData.confirm服务请求的发送地址
N_Result
:N_USData.request服务的传输状态
N_Result
:N_USData.request服务的传输状态
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_N_USData_Confirm
(
uint32_t
N_TAtype
,
N_ResultEnum
N_Result
)
void
DoCAN_N_USData_Confirm
(
uint32_t
N_TAtype
,
N_ResultEnum
N_Result
)
{
{
...
@@ -195,16 +195,16 @@ void DoCAN_N_USData_Confirm(uint32_t N_TAtype, N_ResultEnum N_Result)
...
@@ -195,16 +195,16 @@ void DoCAN_N_USData_Confirm(uint32_t N_TAtype, N_ResultEnum N_Result)
}
}
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_N_USData_FF_Indication
函数名:Do
CAN_N_USData_FF_Indication
功 能:该服务函数由网络层发起,用于向上层指示地址为N_TAtype的一组多帧数据的首帧
功 能:该服务函数由网络层发起,用于向上层指示地址为N_TAtype的一组多帧数据的首帧
的到来
的到来
The N_USData_FF.indication service is issued by the network layer. The
The N_USData_FF.indication service is issued by the network layer. The
service primitive indicates to the adjacent upper layer the arrival of
service primitive indicates to the adjacent upper layer the arrival of
a FirstFrame (FF) of a segmented message received from a peer protocol
a FirstFrame (FF) of a segmented message received from a peer protocol
entity, identified by the address information N_TAtype.
entity, identified by the address information N_TAtype.
参 数:N_TAtype :新到的多帧数据首帧的地址信息
参 数:N_TAtype :新到的多帧数据首帧的地址信息
Length
:新到的多帧数据的总长度
Length
:新到的多帧数据的总长度
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_N_USData_FF_Indication
(
uint32_t
N_TAtype
,
uint16_t
Length
)
void
DoCAN_N_USData_FF_Indication
(
uint32_t
N_TAtype
,
uint16_t
Length
)
{
{
...
@@ -212,19 +212,19 @@ void DoCAN_N_USData_FF_Indication(uint32_t N_TAtype, uint16_t Length)
...
@@ -212,19 +212,19 @@ void DoCAN_N_USData_FF_Indication(uint32_t N_TAtype, uint16_t Length)
}
}
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_N_USData_Indication
函数名:Do
CAN_N_USData_Indication
功 能:该服务函数由网络层发起,用于向上层指出由N_TAtype地址发送来的长度为
Length
功 能:该服务函数由网络层发起,用于向上层指出由N_TAtype地址发送来的长度为Length
的MessageData数据的传送结果N_Result,并同时传递这一数据
的MessageData数据的传送结果N_Result,并同时传递这一数据
The N_USData.indication service is issued by the network layer. The
The N_USData.indication service is issued by the network layer. The
service primitive indicates <N_Result> events and delivers
service primitive indicates <N_Result> events and delivers
<MessageData> with <Length> bytes received from a peer protocol entity
<MessageData> with <Length> bytes received from a peer protocol entity
identified by the address information in N_TAtype to the adjacent upper
identified by the address information in N_TAtype to the adjacent upper
layer.
layer.
参 数:N_TAtype :接收到的数据地址信息
参 数:N_TAtype :接收到的数据地址信息
MessageData
:接收到的数据 (仅在N_Result为N_OK时有效
)
MessageData
:接收到的数据 (仅在N_Result为N_OK时有效)
Length
:接收到的数据长度 (仅在N_Result为N_OK时有效
)
Length
:接收到的数据长度 (仅在N_Result为N_OK时有效)
N_Result
:数据的接收结果
N_Result
:数据的接收结果
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_N_USData_Indication
(
uint32_t
N_TAtype
,
uint8_t
*
MessageData
,
uint16_t
Length
,
N_ResultEnum
N_Result
)
void
DoCAN_N_USData_Indication
(
uint32_t
N_TAtype
,
uint8_t
*
MessageData
,
uint16_t
Length
,
N_ResultEnum
N_Result
)
{
{
...
@@ -232,19 +232,19 @@ void DoCAN_N_USData_Indication(uint32_t N_TAtype, uint8_t *MessageData, uint16_t
...
@@ -232,19 +232,19 @@ void DoCAN_N_USData_Indication(uint32_t N_TAtype, uint8_t *MessageData, uint16_t
}
}
/******************************************************************************
/******************************************************************************
下层接口函数
下层接口函数
******************************************************************************/
******************************************************************************/
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_L_Data_Request
函数名:Do
CAN_L_Data_Request
功 能:该服务原语请求向<Identifier>传输特定格式的<Data>数据
功 能:该服务原语请求向<Identifier>传输特定格式的<Data>数据
The service primitive requests transmission of <Data> that shall be
The service primitive requests transmission of <Data> that shall be
mapped within specific attributes of the data link protocol data unit
mapped within specific attributes of the data link protocol data unit
selected by means of <Identifier>.
selected by means of <Identifier>.
参 数:Identifier :报文I
D
参 数:Identifier :报文ID
dlc
:数据长度
dlc
:数据长度
Data
:数据<Data>于数据链路层的存放地址
Data
:数据<Data>于数据链路层的存放地址
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_L_Data_Request
(
uint32_t
Identifier
,
uint8_t
dlc
,
uint8_t
Data
[])
void
DoCAN_L_Data_Request
(
uint32_t
Identifier
,
uint8_t
dlc
,
uint8_t
Data
[])
{
{
...
@@ -282,20 +282,20 @@ void DoCAN_L_Data_Request(uint32_t Identifier, uint8_t dlc, uint8_t Data [])
...
@@ -282,20 +282,20 @@ void DoCAN_L_Data_Request(uint32_t Identifier, uint8_t dlc, uint8_t Data [])
}
}
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_L_Data_Confirm
函数名:Do
CAN_L_Data_Confirm
功 能:该服务原语用于确认具有特定<Identifier>的报文是否发送完成。
功 能:该服务原语用于确认具有特定<Identifier>的报文是否发送完成。
<TransferStatus>
参数用于传递发送完成与否的状态。
<TransferStatus>
参数用于传递发送完成与否的状态。
The service primitive confirms the completion of an L_Data.request
The service primitive confirms the completion of an L_Data.request
service for a specific <Identifier>.The parameter <TransferStatus>
service for a specific <Identifier>.The parameter <TransferStatus>
provides the status of the service request.
provides the status of the service request.
参 数:Identifier :报文I
D
参 数:Identifier :报文ID
TransferStatus
:Not_Complete - 未完成
TransferStatus
:Not_Complete - 未完成
Complete -
已发送完成
Complete -
已发送完成
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_L_Data_Confirm
(
uint32_t
Identifier
,
uint8_t
TransferStatus
)
void
DoCAN_L_Data_Confirm
(
uint32_t
Identifier
,
uint8_t
TransferStatus
)
{
{
/*
如果数据发送成功,收发状态相应改变
*/
/*
如果数据发送成功,收发状态相应改变*/
if
(
LinkTxCtrl
.
Identifier
==
Identifier
)
if
(
LinkTxCtrl
.
Identifier
==
Identifier
)
{
{
if
(
TransferStatus
==
DIAG_COMPLETE
)
if
(
TransferStatus
==
DIAG_COMPLETE
)
...
@@ -303,32 +303,32 @@ void DoCAN_L_Data_Confirm(uint32_t Identifier, uint8_t TransferStatus)
...
@@ -303,32 +303,32 @@ void DoCAN_L_Data_Confirm(uint32_t Identifier, uint8_t TransferStatus)
switch
(
TpCtrl
.
Process
)
switch
(
TpCtrl
.
Process
)
{
{
case
TP_TX_INIT
:
case
TP_TX_INIT
:
if
(
TpCtrl
.
BlockSize
==
1u
)
/*BlockSize
为1,单帧发送成功
*/
if
(
TpCtrl
.
BlockSize
==
1u
)
/*BlockSize
为1,单帧发送成功*
/
{
{
TpCtrl
.
Process
=
TP_IDLE
;
/*
所有数据发送完毕,回到空闲状态
*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
所有数据发送完毕,回到空闲状态*/
DoCAN_Stop_Timer
(
);
/*
停止计时
*/
DoCAN_Stop_Timer
(
);
/*
停止计时*/
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_OK
);
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_OK
);
}
}
else
/*BlockSize
不为1,首帧发送成功
*/
else
/*BlockSize
不为1,首帧发送成功*/
{
{
DoCAN_Start_Timer
(
TIMING_PARA_N_Bs
);
/*
启动N_Bs计时
*/
DoCAN_Start_Timer
(
TIMING_PARA_N_Bs
);
/*
启动N_Bs计时*/
TpCtrl
.
Process
=
TP_TX_RTS
;
/*
等待接收机许可多帧发送
*/
TpCtrl
.
Process
=
TP_TX_RTS
;
/*
等待接收机许可多帧发送*/
}
}
break
;
break
;
case
TP_TX_CTS
:
case
TP_TX_CTS
:
TpCtrl
.
BlockCnt
++
;
TpCtrl
.
BlockCnt
++
;
if
(
TpCtrl
.
BlockCnt
==
TpCtrl
.
BlockSize
)
/*
最后一帧发送完成
*/
if
(
TpCtrl
.
BlockCnt
==
TpCtrl
.
BlockSize
)
/*
最后一帧发送完成*/
{
{
TpCtrl
.
Process
=
TP_IDLE
;
/*
所有数据发送完毕,回到空闲状态
*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
所有数据发送完毕,回到空闲状态*/
DoCAN_Stop_Timer
(
);
/*
停止计时
*/
DoCAN_Stop_Timer
(
);
/*
停止计时*/
/* DoCAN_Start_Timer(TIMING_PARA_N_Bs);*/
/* DoCAN_Start_Timer(TIMING_PARA_N_Bs);*/
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_OK
);
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_OK
);
}
}
else
else
{
{
/* DoCAN_Start_Timer ( TIMING_PARA_N_Bs ); //
启动/重启N_Bs计时
*/
/* DoCAN_Start_Timer ( TIMING_PARA_N_Bs ); //
启动/重启N_Bs计时*/
if
(
TpCtrl
.
BSMax
)
/*
还可以继续发送数据帧,则启动STmin计时
*/
if
(
TpCtrl
.
BSMax
)
/*
还可以继续发送数据帧,则启动STmin计时*/
{
{
DoCAN_Stop_Timer
(
);
DoCAN_Stop_Timer
(
);
DoCAN_Start_STmin_Timer
(
TpCtrl
.
STmin
);
DoCAN_Start_STmin_Timer
(
TpCtrl
.
STmin
);
...
@@ -341,18 +341,18 @@ void DoCAN_L_Data_Confirm(uint32_t Identifier, uint8_t TransferStatus)
...
@@ -341,18 +341,18 @@ void DoCAN_L_Data_Confirm(uint32_t Identifier, uint8_t TransferStatus)
break
;
break
;
case
TP_RX_RTS
:
case
TP_RX_RTS
:
DoCAN_Start_Timer
(
TIMING_PARA_N_Cr
);
/*
启动N_Cr计时
*/
DoCAN_Start_Timer
(
TIMING_PARA_N_Cr
);
/*
启动N_Cr计时*/
TpCtrl
.
Process
=
TP_RX_CTS
;
TpCtrl
.
Process
=
TP_RX_CTS
;
break
;
break
;
case
TP_RX_WAIT
:
case
TP_RX_WAIT
:
DoCAN_Start_Timer
(
TIMING_PARA_N_Cr
);
/*
启动N_Cr计时
*/
DoCAN_Start_Timer
(
TIMING_PARA_N_Cr
);
/*
启动N_Cr计时*/
TpCtrl
.
Process
=
TP_RX_CTS
;
TpCtrl
.
Process
=
TP_RX_CTS
;
break
;
break
;
case
TP_RX_OVFL
:
case
TP_RX_OVFL
:
TpCtrl
.
Process
=
TP_IDLE
;
/*
停止接收过程
*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
停止接收过程*/
DoCAN_Stop_Timer
(
);
/*
停止计时
*/
DoCAN_Stop_Timer
(
);
/*
停止计时*/
DoCAN_N_USData_Indication
(
N_USDataRxBuffer
.
N_TAtype
,
N_USDataRxBuffer
.
MsgData
,
DoCAN_N_USData_Indication
(
N_USDataRxBuffer
.
N_TAtype
,
N_USDataRxBuffer
.
MsgData
,
N_USDataRxBuffer
.
Length
,
N_ERROR
);
N_USDataRxBuffer
.
Length
,
N_ERROR
);
break
;
break
;
...
@@ -363,26 +363,26 @@ void DoCAN_L_Data_Confirm(uint32_t Identifier, uint8_t TransferStatus)
...
@@ -363,26 +363,26 @@ void DoCAN_L_Data_Confirm(uint32_t Identifier, uint8_t TransferStatus)
}
}
else
else
{
{
/* TpCtrl.TxReq = 1u;*/
/*
发送失败,重发
*/
/* TpCtrl.TxReq = 1u;*/
/*
发送失败,重发*/
}
}
}
}
}
}
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_L_Data_Indication
函数名:Do
CAN_L_Data_Indication
功 能:该服务原语标示一个数据链路层事件到相邻上层并根据<Identifier>传送
<Data>
功 能:该服务原语标示一个数据链路层事件到相邻上层并根据<Identifier>传送<Data>
The service primitive indicates a data link layer event to the adjacent
The service primitive indicates a data link layer event to the adjacent
upper layer and delivers <Data> identified by <Identifier>
upper layer and delivers <Data> identified by <Identifier>
参 数:Identifier :报文I
D
参 数:Identifier :报文ID
dlc
:数据长度
dlc
:数据长度
pData
:数据<Data>于数据链路层的存放地址
pData
:数据<Data>于数据链路层的存放地址
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_L_Data_Indication
(
uint32_t
Identifier
,
uint8_t
dlc
,
uint8_t
pData
[])
void
DoCAN_L_Data_Indication
(
uint32_t
Identifier
,
uint8_t
dlc
,
uint8_t
pData
[])
{
{
uint8_t
i
;
uint8_t
i
;
if
(
LinkRxFIFO
.
Depth
>=
LINK_RX_FIFO_MAX_DEPTH
)
/*FIFO
未满时装入报文,否则抛弃报文
*/
if
(
LinkRxFIFO
.
Depth
>=
LINK_RX_FIFO_MAX_DEPTH
)
/*FIFO
未满时装入报文,否则抛弃报文*/
{
{
/*#if DOCAN_DEBUG_EN
/*#if DOCAN_DEBUG_EN
LINK_RX_FIFO_OVERFLOW_INDICATOR();
LINK_RX_FIFO_OVERFLOW_INDICATOR();
...
@@ -390,15 +390,15 @@ void DoCAN_L_Data_Indication(uint32_t Identifier, uint8_t dlc, uint8_t pData [])
...
@@ -390,15 +390,15 @@ void DoCAN_L_Data_Indication(uint32_t Identifier, uint8_t dlc, uint8_t pData [])
}
}
else
else
{
{
LinkRxFIFO
.
LinkData
[
LinkRxFIFO
.
IPtr
].
Identifier
=
Identifier
;
/*
装入报文
ID*/
LinkRxFIFO
.
LinkData
[
LinkRxFIFO
.
IPtr
].
Identifier
=
Identifier
;
/*
装入报文ID
*/
for
(
i
=
0u
;
i
<
dlc
;
i
++
)
/*
拷贝报文
*/
for
(
i
=
0u
;
i
<
dlc
;
i
++
)
/*
拷贝报文*/
{
{
LinkRxFIFO
.
LinkData
[
LinkRxFIFO
.
IPtr
].
Data
[
i
]
=
pData
[
i
];
LinkRxFIFO
.
LinkData
[
LinkRxFIFO
.
IPtr
].
Data
[
i
]
=
pData
[
i
];
}
}
LinkRxFIFO
.
LinkData
[
LinkRxFIFO
.
IPtr
].
DLC
=
dlc
;
/*
保存报文长度
*/
LinkRxFIFO
.
LinkData
[
LinkRxFIFO
.
IPtr
].
DLC
=
dlc
;
/*
保存报文长度*/
LinkRxFIFO
.
Depth
++
;
/*
新报文装入,深度
+1*/
LinkRxFIFO
.
Depth
++
;
/*
新报文装入,深度+1*
/
LinkRxFIFO
.
IPtr
++
;
/*
输入指针
+1*/
LinkRxFIFO
.
IPtr
++
;
/*
输入指针+1
*/
if
(
LinkRxFIFO
.
IPtr
>=
LINK_RX_FIFO_MAX_DEPTH
)
if
(
LinkRxFIFO
.
IPtr
>=
LINK_RX_FIFO_MAX_DEPTH
)
{
{
LinkRxFIFO
.
IPtr
=
0u
;
LinkRxFIFO
.
IPtr
=
0u
;
...
@@ -407,14 +407,14 @@ void DoCAN_L_Data_Indication(uint32_t Identifier, uint8_t dlc, uint8_t pData [])
...
@@ -407,14 +407,14 @@ void DoCAN_L_Data_Indication(uint32_t Identifier, uint8_t dlc, uint8_t pData [])
}
}
/******************************************************************************
/******************************************************************************
传输层协议解析
传输层协议解析
******************************************************************************/
******************************************************************************/
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_Receive_And_Assemble_N_USData();
函数名:Do
CAN_Receive_And_Assemble_N_USData();
功 能:接收N_PDU并重组数据
功 能:接收N_PDU并重组数据
参 数:无
参 数:无
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_Receive_And_Assemble_N_USData
(
void
)
void
DoCAN_Receive_And_Assemble_N_USData
(
void
)
{
{
...
@@ -430,12 +430,12 @@ void DoCAN_Receive_And_Assemble_N_USData(void)
...
@@ -430,12 +430,12 @@ void DoCAN_Receive_And_Assemble_N_USData(void)
case
FIRST_FRAME
:
case
FIRST_FRAME
:
DoCAN_Receive_First_Frame_N_Data
(
);
DoCAN_Receive_First_Frame_N_Data
(
);
DoCAN_Transmit_Flow_Control
(
);
/*
首帧发送完毕后必须发送流控帧
*/
DoCAN_Transmit_Flow_Control
(
);
/*
首帧发送完毕后必须发送流控帧*/
break
;
break
;
case
CONSECUTIVE_FRAME
:
case
CONSECUTIVE_FRAME
:
DoCAN_Receive_Consecutive_Frame_N_Data
(
);
DoCAN_Receive_Consecutive_Frame_N_Data
(
);
DoCAN_Transmit_Flow_Control
(
);
/*
当接收满一个BlockSize时,需要发送流控帧
*/
DoCAN_Transmit_Flow_Control
(
);
/*
当接收满一个BlockSize时,需要发送流控帧*/
break
;
break
;
case
FLOW_CONTROL
:
case
FLOW_CONTROL
:
...
@@ -451,27 +451,27 @@ void DoCAN_Receive_And_Assemble_N_USData(void)
...
@@ -451,27 +451,27 @@ void DoCAN_Receive_And_Assemble_N_USData(void)
}
}
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_Get_N_PDU
函数名:Do
CAN_Get_N_PDU
功 能:从数据链路层获取
N_PDU(network protocol data unit)
功 能:从数据链路层获取N_PDU
(network protocol data unit)
参 数:无
参 数:无
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_Get_N_PDU
(
void
)
void
DoCAN_Get_N_PDU
(
void
)
{
{
uint8_t
i
;
uint8_t
i
;
if
(
LinkRxFIFO
.
Depth
)
/*FIFO
中有数据
*/
if
(
LinkRxFIFO
.
Depth
)
/*FIFO
中有数据*/
{
{
TransportRxData
.
Frame
.
Identifier
=
LinkRxFIFO
.
LinkData
[
LinkRxFIFO
.
OPtr
].
Identifier
;
/*
取出
ID*/
TransportRxData
.
Frame
.
Identifier
=
LinkRxFIFO
.
LinkData
[
LinkRxFIFO
.
OPtr
].
Identifier
;
/*
取出I
D*/
for
(
i
=
0u
;
i
<
8u
;
i
++
)
/*
拷贝报文
*/
for
(
i
=
0u
;
i
<
8u
;
i
++
)
/*
拷贝报文*/
{
{
TransportRxData
.
Frame
.
Data
[
i
]
=
LinkRxFIFO
.
LinkData
[
LinkRxFIFO
.
OPtr
].
Data
[
i
];
TransportRxData
.
Frame
.
Data
[
i
]
=
LinkRxFIFO
.
LinkData
[
LinkRxFIFO
.
OPtr
].
Data
[
i
];
}
}
TransportRxData
.
Frame
.
DLC
=
LinkRxFIFO
.
LinkData
[
LinkRxFIFO
.
OPtr
].
DLC
;
/*
取出报文长度
*/
TransportRxData
.
Frame
.
DLC
=
LinkRxFIFO
.
LinkData
[
LinkRxFIFO
.
OPtr
].
DLC
;
/*
取出报文长度*/
TransportRxData
.
Frame
.
New
=
1u
;
TransportRxData
.
Frame
.
New
=
1u
;
LinkRxFIFO
.
Depth
--
;
/*
报文已取出,深度
-1*/
LinkRxFIFO
.
Depth
--
;
/*
报文已取出,深度-1*
/
LinkRxFIFO
.
OPtr
++
;
/*
输出指针
+1*/
LinkRxFIFO
.
OPtr
++
;
/*
输出指针+1
*/
if
(
LinkRxFIFO
.
OPtr
>=
LINK_RX_FIFO_MAX_DEPTH
)
if
(
LinkRxFIFO
.
OPtr
>=
LINK_RX_FIFO_MAX_DEPTH
)
{
{
LinkRxFIFO
.
OPtr
=
0u
;
LinkRxFIFO
.
OPtr
=
0u
;
...
@@ -480,16 +480,16 @@ void DoCAN_Get_N_PDU(void)
...
@@ -480,16 +480,16 @@ void DoCAN_Get_N_PDU(void)
}
}
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_Receive_Single_Frame_N_Data
函数名:Do
CAN_Receive_Single_Frame_N_Data
功 能:单帧数据接收
功 能:单帧数据接收
参 数:无
参 数:无
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_Receive_Single_Frame_N_Data
(
void
)
void
DoCAN_Receive_Single_Frame_N_Data
(
void
)
{
{
uint8_t
i
;
uint8_t
i
;
uint32_t
temp
;
uint32_t
temp
;
if
(
(
TpCtrl
.
Process
&
TP_DIR_MASK
)
==
TP_TX
)
/*
发送中不接收
*/
if
(
(
TpCtrl
.
Process
&
TP_DIR_MASK
)
==
TP_TX
)
/*
发送中不接收*/
{
{
}
}
else
else
...
@@ -508,7 +508,7 @@ void DoCAN_Receive_Single_Frame_N_Data(void)
...
@@ -508,7 +508,7 @@ void DoCAN_Receive_Single_Frame_N_Data(void)
/*---------------------------------------------------------------------------
/*---------------------------------------------------------------------------
Tester sends a Single frame with a CAN-DLC shorter and equal to the transport
Tester sends a Single frame with a CAN-DLC shorter and equal to the transport
protocol data length field. ECU must not send a response.
protocol data length field. ECU must not send a response.
2018.11.28
添加长度还要等于
8
2018.11.28
添加长度还要等于8
---------------------------------------------------------------------------*/
---------------------------------------------------------------------------*/
i
=
TransportRxData
.
N_PDU_SF
.
N_PCI
.
SF_DL
;
i
=
TransportRxData
.
N_PDU_SF
.
N_PCI
.
SF_DL
;
if
(
TransportRxData
.
N_PDU_SF
.
DLC
<=
i
)
if
(
TransportRxData
.
N_PDU_SF
.
DLC
<=
i
)
...
@@ -537,7 +537,7 @@ void DoCAN_Receive_Single_Frame_N_Data(void)
...
@@ -537,7 +537,7 @@ void DoCAN_Receive_Single_Frame_N_Data(void)
N_USDataRxBuffer
.
MsgData
[
i
]
=
TransportRxData
.
N_PDU_SF
.
N_Data
[
i
];
N_USDataRxBuffer
.
MsgData
[
i
]
=
TransportRxData
.
N_PDU_SF
.
N_Data
[
i
];
}
}
TpCtrl
.
Process
=
TP_IDLE
;
/*
接收完成,回到IDLE状态
*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
接收完成,回到IDLE状态*/
DoCAN_Stop_Timer
(
);
DoCAN_Stop_Timer
(
);
DoCAN_N_USData_Indication
(
N_USDataRxBuffer
.
N_TAtype
,
N_USDataRxBuffer
.
MsgData
,
DoCAN_N_USData_Indication
(
N_USDataRxBuffer
.
N_TAtype
,
N_USDataRxBuffer
.
MsgData
,
N_USDataRxBuffer
.
Length
,
N_OK
);
N_USDataRxBuffer
.
Length
,
N_OK
);
...
@@ -548,17 +548,17 @@ void DoCAN_Receive_Single_Frame_N_Data(void)
...
@@ -548,17 +548,17 @@ void DoCAN_Receive_Single_Frame_N_Data(void)
}
}
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_Receive_First_Frame_N_Data
函数名:Do
CAN_Receive_First_Frame_N_Data
功 能:接收首帧数据并初始化多帧数据接收
功 能:接收首帧数据并初始化多帧数据接收
参 数:无
参 数:无
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_Receive_First_Frame_N_Data
(
void
)
void
DoCAN_Receive_First_Frame_N_Data
(
void
)
{
{
uint8_t
i
;
uint8_t
i
;
uint16_t
Len
;
uint16_t
Len
;
if
(
(
TpCtrl
.
Process
&
TP_DIR_MASK
)
==
TP_TX
)
/*
发送中不接收
*/
if
(
(
TpCtrl
.
Process
&
TP_DIR_MASK
)
==
TP_TX
)
/*
发送中不接收*/
{
{
}
}
else
else
...
@@ -575,7 +575,7 @@ void DoCAN_Receive_First_Frame_N_Data(void)
...
@@ -575,7 +575,7 @@ void DoCAN_Receive_First_Frame_N_Data(void)
(8.3) A FirstFrame protocol data unit (FF N_PDU), containing the first six
(8.3) A FirstFrame protocol data unit (FF N_PDU), containing the first six
data bytes
data bytes
---------------------------------------------------------------------------*/
---------------------------------------------------------------------------*/
if
(
TransportRxData
.
N_PDU_FF
.
DLC
!=
8u
)
/*
首帧总长(N_PCI + N_Data)应为
8*/
if
(
TransportRxData
.
N_PDU_FF
.
DLC
!=
8u
)
/*
首帧总长(N_PCI + N_Data)应为8*/
{
{
}
}
else
else
...
@@ -608,23 +608,23 @@ void DoCAN_Receive_First_Frame_N_Data(void)
...
@@ -608,23 +608,23 @@ void DoCAN_Receive_First_Frame_N_Data(void)
TpCtrl
.
NonStopMode
=
1u
;
TpCtrl
.
NonStopMode
=
1u
;
#endif
#endif
TpCtrl
.
Len
=
6u
;
/*
首帧接收6字节
*/
TpCtrl
.
Len
=
6u
;
/*
首帧接收6字节*/
TpCtrl
.
TotalLen
=
Len
;
/*
记录字节总数
*/
TpCtrl
.
TotalLen
=
Len
;
/*
记录字节总数*/
TpCtrl
.
BlockCnt
=
1u
;
/*
首帧接收1个b
lock*/
TpCtrl
.
BlockCnt
=
1u
;
/*
首帧接收1个blo
ck*/
TpCtrl
.
BSMax
=
N_MAX_BS
;
/*
装入最大的BS数
*/
TpCtrl
.
BSMax
=
N_MAX_BS
;
/*
装入最大的BS数*/
TpCtrl
.
WFTCnt
=
N_WFTmax
;
/*
装入最大等待次数
*/
TpCtrl
.
WFTCnt
=
N_WFTmax
;
/*
装入最大等待次数*/
/*
首帧含6字节数据,连续帧含7字节数据,根据字节数计算Block总数
*/
/*
首帧含6字节数据,连续帧含7字节数据,根据字节数计算Block总数*/
if
(
(
TpCtrl
.
TotalLen
+
1u
)
%
7u
)
if
(
(
TpCtrl
.
TotalLen
+
1u
)
%
7u
)
{
{
TpCtrl
.
BlockSize
=
(
TpCtrl
.
TotalLen
+
8u
)
/
7u
;
/*
等效于
(TpCtrl.TotalLen + 1) / 7 + 1*/
TpCtrl
.
BlockSize
=
(
TpCtrl
.
TotalLen
+
8u
)
/
7u
;
/*
等效于(
TpCtrl.TotalLen + 1) / 7 + 1*/
}
}
else
else
{
{
TpCtrl
.
BlockSize
=
(
TpCtrl
.
TotalLen
+
1u
)
/
7u
;
TpCtrl
.
BlockSize
=
(
TpCtrl
.
TotalLen
+
1u
)
/
7u
;
}
}
/*
开始接收首帧数据
*/
/*
开始接收首帧数据*/
N_USDataRxBuffer
.
N_TAtype
=
TransportRxData
.
N_PDU_FF
.
N_TAtype
;
N_USDataRxBuffer
.
N_TAtype
=
TransportRxData
.
N_PDU_FF
.
N_TAtype
;
N_USDataRxBuffer
.
Length
=
Len
;
N_USDataRxBuffer
.
Length
=
Len
;
for
(
i
=
0u
;
i
<
6u
;
i
++
)
for
(
i
=
0u
;
i
<
6u
;
i
++
)
...
@@ -632,7 +632,7 @@ void DoCAN_Receive_First_Frame_N_Data(void)
...
@@ -632,7 +632,7 @@ void DoCAN_Receive_First_Frame_N_Data(void)
N_USDataRxBuffer
.
MsgData
[
i
]
=
TransportRxData
.
N_PDU_FF
.
N_Data
[
i
];
N_USDataRxBuffer
.
MsgData
[
i
]
=
TransportRxData
.
N_PDU_FF
.
N_Data
[
i
];
}
}
DoCAN_Start_Timer
(
TIMING_PARA_N_Br
);
/*
启动N_Br计时
*/
DoCAN_Start_Timer
(
TIMING_PARA_N_Br
);
/*
启动N_Br计时*/
TpCtrl
.
Process
=
TP_RX_INIT
;
TpCtrl
.
Process
=
TP_RX_INIT
;
DoCAN_N_USData_FF_Indication
(
N_USDataRxBuffer
.
N_TAtype
,
N_USDataRxBuffer
.
Length
);
DoCAN_N_USData_FF_Indication
(
N_USDataRxBuffer
.
N_TAtype
,
N_USDataRxBuffer
.
Length
);
}
}
...
@@ -642,10 +642,10 @@ void DoCAN_Receive_First_Frame_N_Data(void)
...
@@ -642,10 +642,10 @@ void DoCAN_Receive_First_Frame_N_Data(void)
}
}
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_Receive_Consecutive_Frame_N_Data
函数名:Do
CAN_Receive_Consecutive_Frame_N_Data
功 能:接收连接帧数据
功 能:接收连接帧数据
参 数:无
参 数:无
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_Receive_Consecutive_Frame_N_Data
(
void
)
void
DoCAN_Receive_Consecutive_Frame_N_Data
(
void
)
{
{
...
@@ -678,19 +678,19 @@ void DoCAN_Receive_Consecutive_Frame_N_Data(void)
...
@@ -678,19 +678,19 @@ void DoCAN_Receive_Consecutive_Frame_N_Data(void)
---------------------------------------------------------------------------*/
---------------------------------------------------------------------------*/
if
(
TransportRxData
.
N_PDU_CF
.
N_PCI
.
SN
!=
(
uint8_t
)(
TpCtrl
.
BlockCnt
&
(
0x000Fu
))
)
if
(
TransportRxData
.
N_PDU_CF
.
N_PCI
.
SN
!=
(
uint8_t
)(
TpCtrl
.
BlockCnt
&
(
0x000Fu
))
)
{
{
TpCtrl
.
Process
=
TP_IDLE
;
/*
停止接收过程
*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
停止接收过程*/
DoCAN_Stop_Timer
(
);
/*
停止计时
*/
DoCAN_Stop_Timer
(
);
/*
停止计时*/
DoCAN_N_USData_Indication
(
N_USDataRxBuffer
.
N_TAtype
,
N_USDataRxBuffer
.
MsgData
,
DoCAN_N_USData_Indication
(
N_USDataRxBuffer
.
N_TAtype
,
N_USDataRxBuffer
.
MsgData
,
N_USDataRxBuffer
.
Length
,
N_WRONG_SN
);
N_USDataRxBuffer
.
Length
,
N_WRONG_SN
);
}
}
else
else
{
{
TpCtrl
.
BlockCnt
++
;
/*
接收到1个
Block*/
TpCtrl
.
BlockCnt
++
;
/*
接收到1个
Block*/
TpCtrl
.
BSMax
--
;
TpCtrl
.
BSMax
--
;
if
(
TpCtrl
.
BlockCnt
<
TpCtrl
.
BlockSize
)
/*
此次接收不是最后一帧
*/
if
(
TpCtrl
.
BlockCnt
<
TpCtrl
.
BlockSize
)
/*
此次接收不是最后一帧*/
{
{
/*if ( TransportRxData.N_PDU_CF.DLC != 8u )*/
/*
此时连续帧总长(N_PCI + N_Data)应为
8*/
/*if ( TransportRxData.N_PDU_CF.DLC != 8u )*/
/*
此时连续帧总长(N_PCI + N_Data)应为8*/
/*{}
/*{}
else
else
{*/
{*/
...
@@ -699,21 +699,21 @@ void DoCAN_Receive_Consecutive_Frame_N_Data(void)
...
@@ -699,21 +699,21 @@ void DoCAN_Receive_Consecutive_Frame_N_Data(void)
N_USDataRxBuffer
.
MsgData
[
TpCtrl
.
Len
]
=
TransportRxData
.
N_PDU_CF
.
N_Data
[
i
];
N_USDataRxBuffer
.
MsgData
[
TpCtrl
.
Len
]
=
TransportRxData
.
N_PDU_CF
.
N_Data
[
i
];
TpCtrl
.
Len
++
;
TpCtrl
.
Len
++
;
}
}
DoCAN_Start_Timer
(
TIMING_PARA_N_Cr
);
/*
重启N_Cr计时
*/
DoCAN_Start_Timer
(
TIMING_PARA_N_Cr
);
/*
重启N_Cr计时*/
/*}*/
/*}*/
}
}
else
/*
此次接收是最后一帧
*/
else
/*
此次接收是最后一帧*/
{
{
/*-------------------------------------------------------------------------
/*-------------------------------------------------------------------------
In a segmented request the Tester sends a Consecutive frame with a CAN-DLC
In a segmented request the Tester sends a Consecutive frame with a CAN-DLC
shorter or equal to transport protocol data length field. ECU must not send
shorter or equal to transport protocol data length field. ECU must not send
a response.
a response.
2018.11.28
添加长度应该等于
8
2018.11.28
添加长度应该等于8
-------------------------------------------------------------------------*/
-------------------------------------------------------------------------*/
if
(
TransportRxData
.
N_PDU_CF
.
DLC
<=
TpCtrl
.
TotalLen
-
TpCtrl
.
Len
)
if
(
TransportRxData
.
N_PDU_CF
.
DLC
<=
TpCtrl
.
TotalLen
-
TpCtrl
.
Len
)
{
{
}
}
else
if
(
TransportRxData
.
N_PDU_CF
.
DLC
!=
8u
)
/*
此时连续帧总长应不小于剩余数据长度
*/
else
if
(
TransportRxData
.
N_PDU_CF
.
DLC
!=
8u
)
/*
此时连续帧总长应不小于剩余数据长度*/
{
{
}
}
else
else
...
@@ -726,7 +726,7 @@ void DoCAN_Receive_Consecutive_Frame_N_Data(void)
...
@@ -726,7 +726,7 @@ void DoCAN_Receive_Consecutive_Frame_N_Data(void)
TpCtrl
.
Len
++
;
TpCtrl
.
Len
++
;
}
}
TpCtrl
.
Process
=
TP_IDLE
;
/*
接收完成,回到IDLE状态
*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
接收完成,回到IDLE状态*/
DoCAN_Stop_Timer
(
);
DoCAN_Stop_Timer
(
);
DoCAN_N_USData_Indication
(
N_USDataRxBuffer
.
N_TAtype
,
N_USDataRxBuffer
.
MsgData
,
DoCAN_N_USData_Indication
(
N_USDataRxBuffer
.
N_TAtype
,
N_USDataRxBuffer
.
MsgData
,
N_USDataRxBuffer
.
Length
,
N_OK
);
N_USDataRxBuffer
.
Length
,
N_OK
);
...
@@ -738,10 +738,10 @@ void DoCAN_Receive_Consecutive_Frame_N_Data(void)
...
@@ -738,10 +738,10 @@ void DoCAN_Receive_Consecutive_Frame_N_Data(void)
}
}
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_Receive_Flow_Control
函数名:Do
CAN_Receive_Flow_Control
功 能:接收流控帧数据
功 能:接收流控帧数据
参 数:无
参 数:无
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_Receive_Flow_Control
(
void
)
void
DoCAN_Receive_Flow_Control
(
void
)
{
{
...
@@ -765,8 +765,8 @@ void DoCAN_Receive_Flow_Control(void)
...
@@ -765,8 +765,8 @@ void DoCAN_Receive_Flow_Control(void)
if
(
TransportRxData
.
N_PDU_FC
.
N_TAtype
!=
DIAG_ID_Rx_PHY
)
if
(
TransportRxData
.
N_PDU_FC
.
N_TAtype
!=
DIAG_ID_Rx_PHY
)
{
{
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_ERROR
);
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_ERROR
);
DoCAN_Stop_Timer
(
);
/*
停止计时
*/
DoCAN_Stop_Timer
(
);
/*
停止计时*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据发送,回到空闲状态
*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据发送,回到空闲状态*/
}
}
else
else
{
{
...
@@ -778,8 +778,8 @@ void DoCAN_Receive_Flow_Control(void)
...
@@ -778,8 +778,8 @@ void DoCAN_Receive_Flow_Control(void)
if
(
TransportRxData
.
N_PDU_FC
.
DLC
<
3u
)
if
(
TransportRxData
.
N_PDU_FC
.
DLC
<
3u
)
{
{
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_ERROR
);
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_ERROR
);
DoCAN_Stop_Timer
(
);
/*
停止计时
*/
DoCAN_Stop_Timer
(
);
/*
停止计时*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据发送,回到空闲状态
*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据发送,回到空闲状态*/
}
}
else
else
{
{
...
@@ -825,7 +825,7 @@ void DoCAN_Receive_Flow_Control(void)
...
@@ -825,7 +825,7 @@ void DoCAN_Receive_Flow_Control(void)
Tester verifies that the time between the Consecutive
Tester verifies that the time between the Consecutive
Frames is not below STMin time. This is tested for STMin
Frames is not below STMin time. This is tested for STMin
values 1,10,20,30,40,50 and 60.
values 1,10,20,30,40,50 and 60.
2018.11.29
添加为了在发连续帧时忽略第二个流控的
stmin
2018.11.29
添加为了在发连续帧时忽略第二个流控的stmin
-------------------------------------------------------*/
-------------------------------------------------------*/
if
(
TpCtrl
.
Process
!=
TP_TX_CTS
)
if
(
TpCtrl
.
Process
!=
TP_TX_CTS
)
{
{
...
@@ -843,9 +843,9 @@ void DoCAN_Receive_Flow_Control(void)
...
@@ -843,9 +843,9 @@ void DoCAN_Receive_Flow_Control(void)
one response frame. Tester sends two Flow Controls (FC)
one response frame. Tester sends two Flow Controls (FC)
instead of one. A response from the ECU is expected.
instead of one. A response from the ECU is expected.
-------------------------------------------------------*/
-------------------------------------------------------*/
TpCtrl
.
Process
=
TP_TX_CTS
;
/*
发送机被许可发送
*/
TpCtrl
.
Process
=
TP_TX_CTS
;
/*
发送机被许可发送*/
DoCAN_Stop_Timer
(
);
DoCAN_Stop_Timer
(
);
DoCAN_Start_STmin_Timer
(
TpCtrl
.
STmin
);
/*
启动STmin计时
*/
DoCAN_Start_STmin_Timer
(
TpCtrl
.
STmin
);
/*
启动STmin计时*/
break
;
break
;
case
FC_FS_WAIT
:
case
FC_FS_WAIT
:
...
@@ -862,8 +862,8 @@ void DoCAN_Receive_Flow_Control(void)
...
@@ -862,8 +862,8 @@ void DoCAN_Receive_Flow_Control(void)
send (CTS). Then the tester sends a new request. ECU must
send (CTS). Then the tester sends a new request. ECU must
send a response for the last request.
send a response for the last request.
-------------------------------------------------------*/
-------------------------------------------------------*/
TpCtrl
.
Process
=
TP_TX_WAIT
;
/*
接收机请求发送机等待
*/
TpCtrl
.
Process
=
TP_TX_WAIT
;
/*
接收机请求发送机等待*/
DoCAN_Start_Timer
(
TIMING_PARA_N_Bs
);
/*
启动/重启N_Bs计时
*/
DoCAN_Start_Timer
(
TIMING_PARA_N_Bs
);
/*
启动/重启N_Bs计时*/
break
;
break
;
case
FC_FS_OVFL
:
case
FC_FS_OVFL
:
...
@@ -887,8 +887,8 @@ void DoCAN_Receive_Flow_Control(void)
...
@@ -887,8 +887,8 @@ void DoCAN_Receive_Flow_Control(void)
if
(
TpCtrl
.
Process
==
TP_TX_RTS
)
if
(
TpCtrl
.
Process
==
TP_TX_RTS
)
{
{
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_BUFFER_OVFLW
);
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_BUFFER_OVFLW
);
DoCAN_Stop_Timer
(
);
/*
停止计时
*/
DoCAN_Stop_Timer
(
);
/*
停止计时*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据发送,回到空闲状态
*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据发送,回到空闲状态*/
}
}
break
;
break
;
...
@@ -898,8 +898,8 @@ void DoCAN_Receive_Flow_Control(void)
...
@@ -898,8 +898,8 @@ void DoCAN_Receive_Flow_Control(void)
must not send a response.
must not send a response.
-------------------------------------------------------*/
-------------------------------------------------------*/
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_INVALID_FS
);
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_INVALID_FS
);
DoCAN_Stop_Timer
(
);
/*
停止计时
*/
DoCAN_Stop_Timer
(
);
/*
停止计时*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据发送,回到空闲状态
*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据发送,回到空闲状态*/
break
;
break
;
}
}
}
}
...
@@ -908,10 +908,10 @@ void DoCAN_Receive_Flow_Control(void)
...
@@ -908,10 +908,10 @@ void DoCAN_Receive_Flow_Control(void)
}
}
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_Transmit_Flow_Control
函数名:Do
CAN_Transmit_Flow_Control
功 能:根据当前的接收机状态发送流控帧
功 能:根据当前的接收机状态发送流控帧
参 数:无
参 数:无
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_Transmit_Flow_Control
(
void
)
void
DoCAN_Transmit_Flow_Control
(
void
)
{
{
...
@@ -957,23 +957,23 @@ void DoCAN_Transmit_Flow_Control(void)
...
@@ -957,23 +957,23 @@ void DoCAN_Transmit_Flow_Control(void)
{
{
data
[
i
]
=
TransportTxData
.
Frame
.
Data
[
i
];
data
[
i
]
=
TransportTxData
.
Frame
.
Data
[
i
];
}
}
DoCAN_Start_Timer
(
TIMING_PARA_N_Ar
);
/*
启动N_Ar计时
*/
DoCAN_Start_Timer
(
TIMING_PARA_N_Ar
);
/*
启动N_Ar计时*/
DoCAN_L_Data_Request
(
id
,
dlc
,
data
);
DoCAN_L_Data_Request
(
id
,
dlc
,
data
);
}
}
else
if
(
TpCtrl
.
Process
==
TP_RX_CTS
)
else
if
(
TpCtrl
.
Process
==
TP_RX_CTS
)
{
{
if
(
TpCtrl
.
BSMax
)
/*
仍然没有接收满一个BS的N
_PDU*/
if
(
TpCtrl
.
BSMax
)
/*
仍然没有接收满一个BS的N_PDU
*/
{
{
}
}
else
else
{
{
if
(
TpCtrl
.
NonStopMode
)
/*
如果是连续接收模式(BS本来就是
0)*/
if
(
TpCtrl
.
NonStopMode
)
/*
如果是连续接收模式(BS本来就是0)*/
{
{
}
}
else
else
{
{
/*
/*
if (0) //
如果满足等待条件,则发送等待FC帧
if (0) //
如果满足等待条件,则发送等待FC帧
{
{
if(TpCtrl.WFTCnt == 0)
if(TpCtrl.WFTCnt == 0)
{
{
...
@@ -988,9 +988,9 @@ void DoCAN_Transmit_Flow_Control(void)
...
@@ -988,9 +988,9 @@ void DoCAN_Transmit_Flow_Control(void)
TransportTxData.N_PDU_FC.N_PCI.FS = FC_FS_WAIT;
TransportTxData.N_PDU_FC.N_PCI.FS = FC_FS_WAIT;
}*/
}*/
TpCtrl
.
BSMax
=
N_MAX_BS
;
/*
重新装入最大的BS数
*/
TpCtrl
.
BSMax
=
N_MAX_BS
;
/*
重新装入最大的BS数*/
TransportTxData
.
N_PDU_FC
.
N_PCI
.
FS
=
FC_FS_CTS
;
TransportTxData
.
N_PDU_FC
.
N_PCI
.
FS
=
FC_FS_CTS
;
TpCtrl
.
Process
=
TP_RX_RTS
;
/*
等待RTS发送完成
*/
TpCtrl
.
Process
=
TP_RX_RTS
;
/*
等待RTS发送完成*/
TransportTxData
.
N_PDU_FC
.
N_TAtype
=
DIAG_ID_Tx
;
TransportTxData
.
N_PDU_FC
.
N_TAtype
=
DIAG_ID_Tx
;
TransportTxData
.
N_PDU_FC
.
N_PCI
.
Type
=
FLOW_CONTROL
;
TransportTxData
.
N_PDU_FC
.
N_PCI
.
Type
=
FLOW_CONTROL
;
...
@@ -1009,7 +1009,7 @@ void DoCAN_Transmit_Flow_Control(void)
...
@@ -1009,7 +1009,7 @@ void DoCAN_Transmit_Flow_Control(void)
{
{
data
[
i
]
=
TransportTxData
.
Frame
.
Data
[
i
];
data
[
i
]
=
TransportTxData
.
Frame
.
Data
[
i
];
}
}
DoCAN_Start_Timer
(
TIMING_PARA_N_Ar
);
/*
启动N_Ar计时
*/
DoCAN_Start_Timer
(
TIMING_PARA_N_Ar
);
/*
启动N_Ar计时*/
DoCAN_L_Data_Request
(
id
,
dlc
,
data
);
DoCAN_L_Data_Request
(
id
,
dlc
,
data
);
}
}
}
}
...
@@ -1020,20 +1020,20 @@ void DoCAN_Transmit_Flow_Control(void)
...
@@ -1020,20 +1020,20 @@ void DoCAN_Transmit_Flow_Control(void)
}
}
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_Handle_Unknown_N_PDU
函数名:Do
CAN_Handle_Unknown_N_PDU
功 能:处理接收到的未知类型的N
_PDU
功 能:处理接收到的未知类型的N_PDU
参 数:无
参 数:无
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_Handle_Unknown_N_PDU
(
void
)
void
DoCAN_Handle_Unknown_N_PDU
(
void
)
{
{
}
}
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_Disassemble_And_Transmit_N_USData
函数名:Do
CAN_Disassemble_And_Transmit_N_USData
功 能:将数据拆分为连续帧(CF)并发送出去
功 能:将数据拆分为连续帧(CF)并发送出去
参 数:无
参 数:无
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_Disassemble_And_Transmit_N_USData
(
void
)
void
DoCAN_Disassemble_And_Transmit_N_USData
(
void
)
{
{
...
@@ -1043,24 +1043,24 @@ void DoCAN_Disassemble_And_Transmit_N_USData(void)
...
@@ -1043,24 +1043,24 @@ void DoCAN_Disassemble_And_Transmit_N_USData(void)
uint8_t
data
[
8
];
uint8_t
data
[
8
];
uint8_t
Len
;
uint8_t
Len
;
if
(
TpCtrl
.
Process
!=
TP_TX_CTS
)
/*
未被许可时不可以发送连续帧
*/
if
(
TpCtrl
.
Process
!=
TP_TX_CTS
)
/*
未被许可时不可以发送连续帧*/
{
{
}
}
else
else
{
{
/*
仅在STmin计时时间到后发送一次
*/
/*
仅在STmin计时时间到后发送一次*/
if
(
DoCAN_Get_STmin_Timer_Status
(
)
==
STmin_TIME_UP
)
if
(
DoCAN_Get_STmin_Timer_Status
(
)
==
STmin_TIME_UP
)
{
{
TransportTxData
.
N_PDU_CF
.
N_TAtype
=
N_USDataTxBuffer
.
N_TAtype
;
TransportTxData
.
N_PDU_CF
.
N_TAtype
=
N_USDataTxBuffer
.
N_TAtype
;
TransportTxData
.
N_PDU_CF
.
N_PCI
.
Type
=
CONSECUTIVE_FRAME
;
TransportTxData
.
N_PDU_CF
.
N_PCI
.
Type
=
CONSECUTIVE_FRAME
;
TransportTxData
.
N_PDU_CF
.
N_PCI
.
SN
=
(
uint8_t
)(
TpCtrl
.
BlockCnt
&
0x000Fu
);
TransportTxData
.
N_PDU_CF
.
N_PCI
.
SN
=
(
uint8_t
)(
TpCtrl
.
BlockCnt
&
0x000Fu
);
/*
当BSMax减小到0时,链路层数据发送完毕后,将不会再启动STmin计数器(详情见DoCAN_L_Data_Confirm函数)
*/
/*
当BSMax减小到0时,链路层数据发送完毕后,将不会再启动STmin计数器(详情见DoCAN_L_Data_Confirm函数)*/
/*
因此STmin_TIME_UP状态将不会再出现,从而停止了连续帧的发送
*/
/*
因此STmin_TIME_UP状态将不会再出现,从而停止了连续帧的发送*/
/*
直到有新的CF帧到来给BSMax赋予新值,或N_Bs计时超时
*/
/*
直到有新的CF帧到来给BSMax赋予新值,或N_Bs计时超时*/
TpCtrl
.
BSMax
--
;
TpCtrl
.
BSMax
--
;
if
(
TpCtrl
.
BlockCnt
<
TpCtrl
.
BlockSize
-
1u
)
/*
将要发送的不是最后一帧
*/
if
(
TpCtrl
.
BlockCnt
<
TpCtrl
.
BlockSize
-
1u
)
/*
将要发送的不是最后一帧*/
{
{
TransportTxData
.
N_PDU_CF
.
DLC
=
8u
;
TransportTxData
.
N_PDU_CF
.
DLC
=
8u
;
for
(
i
=
0u
;
i
<
7u
;
i
++
)
for
(
i
=
0u
;
i
<
7u
;
i
++
)
...
@@ -1076,10 +1076,10 @@ void DoCAN_Disassemble_And_Transmit_N_USData(void)
...
@@ -1076,10 +1076,10 @@ void DoCAN_Disassemble_And_Transmit_N_USData(void)
{
{
data
[
i
]
=
TransportTxData
.
Frame
.
Data
[
i
];
data
[
i
]
=
TransportTxData
.
Frame
.
Data
[
i
];
}
}
DoCAN_Start_Timer
(
TIMING_PARA_N_As
);
/*
启动N_As计时
*/
DoCAN_Start_Timer
(
TIMING_PARA_N_As
);
/*
启动N_As计时*/
DoCAN_L_Data_Request
(
id
,
dlc
,
data
);
DoCAN_L_Data_Request
(
id
,
dlc
,
data
);
}
}
else
if
(
TpCtrl
.
BlockCnt
==
TpCtrl
.
BlockSize
-
1u
)
/*
将要发送最后一帧
*/
else
if
(
TpCtrl
.
BlockCnt
==
TpCtrl
.
BlockSize
-
1u
)
/*
将要发送最后一帧*/
{
{
Len
=
(
uint8_t
)(
TpCtrl
.
TotalLen
-
TpCtrl
.
Len
);
Len
=
(
uint8_t
)(
TpCtrl
.
TotalLen
-
TpCtrl
.
Len
);
...
@@ -1095,14 +1095,14 @@ void DoCAN_Disassemble_And_Transmit_N_USData(void)
...
@@ -1095,14 +1095,14 @@ void DoCAN_Disassemble_And_Transmit_N_USData(void)
{
{
data
[
i
]
=
TransportTxData
.
Frame
.
Data
[
i
];
data
[
i
]
=
TransportTxData
.
Frame
.
Data
[
i
];
}
}
DoCAN_Start_Timer
(
TIMING_PARA_N_As
);
/*
启动N_As计时
*/
DoCAN_Start_Timer
(
TIMING_PARA_N_As
);
/*
启动N_As计时*/
DoCAN_L_Data_Request
(
id
,
dlc
,
data
);
DoCAN_L_Data_Request
(
id
,
dlc
,
data
);
/* TpCtrl.TxReq = 1u;*/
/* TpCtrl.TxReq = 1u;*/
}
}
else
/*
已发送帧数不可能大于帧总数,除非有错误发生
*/
else
/*
已发送帧数不可能大于帧总数,除非有错误发生*/
{
{
DoCAN_Stop_Timer
(
);
/*
停止计时
*/
DoCAN_Stop_Timer
(
);
/*
停止计时*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据发送,回到空闲状态
*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据发送,回到空闲状态*/
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_ERROR
);
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_ERROR
);
}
}
}
}
...
@@ -1110,13 +1110,13 @@ void DoCAN_Disassemble_And_Transmit_N_USData(void)
...
@@ -1110,13 +1110,13 @@ void DoCAN_Disassemble_And_Transmit_N_USData(void)
}
}
/******************************************************************************
/******************************************************************************
传输层时序管理
传输层时序管理
******************************************************************************/
******************************************************************************/
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_Update_Timer
函数名:Do
CAN_Update_Timer
功 能:定时器更新函数
功 能:定时器更新函数
参 数:无
参 数:无
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_Update_Timer
(
void
)
void
DoCAN_Update_Timer
(
void
)
{
{
...
@@ -1124,7 +1124,7 @@ void DoCAN_Update_Timer(void)
...
@@ -1124,7 +1124,7 @@ void DoCAN_Update_Timer(void)
uint16_t
Dec
;
uint16_t
Dec
;
CurrentCnt
=
TpTimingCtrl
.
Cnt
;
CurrentCnt
=
TpTimingCtrl
.
Cnt
;
if
(
CurrentCnt
!=
TpTimingCtrl
.
LastCnt
)
/*
定时器计数值有更新
*/
if
(
CurrentCnt
!=
TpTimingCtrl
.
LastCnt
)
/*
定时器计数值有更新*/
{
{
if
(
CurrentCnt
>
TpTimingCtrl
.
LastCnt
)
if
(
CurrentCnt
>
TpTimingCtrl
.
LastCnt
)
{
{
...
@@ -1175,21 +1175,21 @@ void DoCAN_Update_Timer(void)
...
@@ -1175,21 +1175,21 @@ void DoCAN_Update_Timer(void)
}
}
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_Handle_Time_Out
函数名:Do
CAN_Handle_Time_Out
功 能:超时处理
功 能:超时处理
参 数:无
参 数:无
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_Handle_Time_Out
(
void
)
void
DoCAN_Handle_Time_Out
(
void
)
{
{
if
(
TpTimingCtrl
.
NTimer
==
0u
)
/*
计时超时
*/
if
(
TpTimingCtrl
.
NTimer
==
0u
)
/*
计时超时*/
{
{
switch
(
TpTimingCtrl
.
Type
)
switch
(
TpTimingCtrl
.
Type
)
{
{
case
TIMING_PARA_N_As
:
case
TIMING_PARA_N_As
:
if
(
TpCtrl
.
Process
!=
TP_IDLE
)
if
(
TpCtrl
.
Process
!=
TP_IDLE
)
{
{
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据收发,回到空闲状态
*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据收发,回到空闲状态*/
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_TIMEOUT_A
);
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_TIMEOUT_A
);
}
}
break
;
break
;
...
@@ -1197,7 +1197,7 @@ void DoCAN_Handle_Time_Out(void)
...
@@ -1197,7 +1197,7 @@ void DoCAN_Handle_Time_Out(void)
case
TIMING_PARA_N_Ar
:
case
TIMING_PARA_N_Ar
:
if
(
TpCtrl
.
Process
!=
TP_IDLE
)
if
(
TpCtrl
.
Process
!=
TP_IDLE
)
{
{
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据收发,回到空闲状态
*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据收发,回到空闲状态*/
DoCAN_N_USData_Indication
(
N_USDataRxBuffer
.
N_TAtype
,
N_USDataRxBuffer
.
MsgData
,
DoCAN_N_USData_Indication
(
N_USDataRxBuffer
.
N_TAtype
,
N_USDataRxBuffer
.
MsgData
,
N_USDataRxBuffer
.
Length
,
N_TIMEOUT_A
);
N_USDataRxBuffer
.
Length
,
N_TIMEOUT_A
);
}
}
...
@@ -1206,7 +1206,7 @@ void DoCAN_Handle_Time_Out(void)
...
@@ -1206,7 +1206,7 @@ void DoCAN_Handle_Time_Out(void)
case
TIMING_PARA_N_Bs
:
case
TIMING_PARA_N_Bs
:
if
(
TpCtrl
.
Process
!=
TP_IDLE
)
if
(
TpCtrl
.
Process
!=
TP_IDLE
)
{
{
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据发送,回到空闲状态
*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据发送,回到空闲状态*/
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_TIMEOUT_Bs
);
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_TIMEOUT_Bs
);
}
}
break
;
break
;
...
@@ -1214,7 +1214,7 @@ void DoCAN_Handle_Time_Out(void)
...
@@ -1214,7 +1214,7 @@ void DoCAN_Handle_Time_Out(void)
case
TIMING_PARA_N_Br
:
case
TIMING_PARA_N_Br
:
if
(
TpCtrl
.
Process
!=
TP_IDLE
)
if
(
TpCtrl
.
Process
!=
TP_IDLE
)
{
{
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据收发,回到空闲状态
*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据收发,回到空闲状态*/
DoCAN_N_USData_Indication
(
N_USDataRxBuffer
.
N_TAtype
,
N_USDataRxBuffer
.
MsgData
,
DoCAN_N_USData_Indication
(
N_USDataRxBuffer
.
N_TAtype
,
N_USDataRxBuffer
.
MsgData
,
N_USDataRxBuffer
.
Length
,
N_ERROR
);
N_USDataRxBuffer
.
Length
,
N_ERROR
);
}
}
...
@@ -1223,7 +1223,7 @@ void DoCAN_Handle_Time_Out(void)
...
@@ -1223,7 +1223,7 @@ void DoCAN_Handle_Time_Out(void)
case
TIMING_PARA_N_Cs
:
case
TIMING_PARA_N_Cs
:
if
(
TpCtrl
.
Process
!=
TP_IDLE
)
if
(
TpCtrl
.
Process
!=
TP_IDLE
)
{
{
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据收发,回到空闲状态
*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据收发,回到空闲状态*/
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_ERROR
);
DoCAN_N_USData_Confirm
(
N_USDataTxBuffer
.
N_TAtype
,
N_ERROR
);
}
}
break
;
break
;
...
@@ -1231,7 +1231,7 @@ void DoCAN_Handle_Time_Out(void)
...
@@ -1231,7 +1231,7 @@ void DoCAN_Handle_Time_Out(void)
case
TIMING_PARA_N_Cr
:
case
TIMING_PARA_N_Cr
:
if
(
TpCtrl
.
Process
!=
TP_IDLE
)
if
(
TpCtrl
.
Process
!=
TP_IDLE
)
{
{
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据接收,回到空闲状态
*/
TpCtrl
.
Process
=
TP_IDLE
;
/*
中止数据接收,回到空闲状态*/
DoCAN_N_USData_Indication
(
N_USDataRxBuffer
.
N_TAtype
,
N_USDataRxBuffer
.
MsgData
,
DoCAN_N_USData_Indication
(
N_USDataRxBuffer
.
N_TAtype
,
N_USDataRxBuffer
.
MsgData
,
N_USDataRxBuffer
.
Length
,
N_TIMEOUT_Cr
);
N_USDataRxBuffer
.
Length
,
N_TIMEOUT_Cr
);
}
}
...
@@ -1241,7 +1241,7 @@ void DoCAN_Handle_Time_Out(void)
...
@@ -1241,7 +1241,7 @@ void DoCAN_Handle_Time_Out(void)
break
;
break
;
}
}
DoCAN_Stop_Timer
(
);
/*
停止计时
*/
DoCAN_Stop_Timer
(
);
/*
停止计时*/
}
}
}
}
...
@@ -1252,16 +1252,16 @@ void UDS_TP_ArTimeOutHandle(void)
...
@@ -1252,16 +1252,16 @@ void UDS_TP_ArTimeOutHandle(void)
}
}
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_Start_Timer
函数名:Do
CAN_Start_Timer
功 能:启动时序定时器
功 能:启动时序定时器
参 数:TimingParameter :时序参数,可以是下列参数中的一种
参 数:TimingParameter :时序参数,可以是下列参数中的一种
TIMING_PARA_N_As
TIMING_PARA_N_As
TIMING_PARA_N_Ar
TIMING_PARA_N_Ar
TIMING_PARA_N_Bs
TIMING_PARA_N_Bs
TIMING_PARA_N_Br
TIMING_PARA_N_Br
TIMING_PARA_N_Cs
TIMING_PARA_N_Cs
TIMING_PARA_N_Cr
TIMING_PARA_N_Cr
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_Start_Timer
(
uint8_t
TimingParameter
)
void
DoCAN_Start_Timer
(
uint8_t
TimingParameter
)
{
{
...
@@ -1305,10 +1305,10 @@ void DoCAN_Start_Timer(uint8_t TimingParameter)
...
@@ -1305,10 +1305,10 @@ void DoCAN_Start_Timer(uint8_t TimingParameter)
}
}
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_Stop_Timer
函数名:Do
CAN_Stop_Timer
功 能:停止时序定时器
功 能:停止时序定时器
参 数:无
参 数:无
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_Stop_Timer
(
void
)
void
DoCAN_Stop_Timer
(
void
)
{
{
...
@@ -1316,39 +1316,39 @@ void DoCAN_Stop_Timer(void)
...
@@ -1316,39 +1316,39 @@ void DoCAN_Stop_Timer(void)
}
}
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_Start_STmin_Timer
函数名:Do
CAN_Start_STmin_Timer
功 能:启动STmin定时器
功 能:启动STmin定时器
参 数:STminTime:STmin时间
参 数:STminTime:STmin时间
返回值:无
返回值:无
******************************************************************************/
******************************************************************************/
void
DoCAN_Start_STmin_Timer
(
uint8_t
STminTime
)
void
DoCAN_Start_STmin_Timer
(
uint8_t
STminTime
)
{
{
if
(
STminTime
<=
0x7Fu
)
/*0x00 - 0x7F
:0
ms - 127ms*/
if
(
STminTime
<=
0x7Fu
)
/*0x00 - 0x7F
:
0ms - 127ms*/
{
{
STminTime
++
;
STminTime
++
;
TpTimingCtrl
.
STimer
=
((
uint32_t
)(
STminTime
)
*
(
uint32_t
)
1000
);
TpTimingCtrl
.
STimer
=
((
uint32_t
)(
STminTime
)
*
(
uint32_t
)
1000
);
}
}
else
if
(
(
STminTime
>=
0xF1u
)
&&
(
STminTime
<=
0xF9u
)
)
/*0xF1 - 0xF9
:1
00us - 900us*/
else
if
(
(
STminTime
>=
0xF1u
)
&&
(
STminTime
<=
0xF9u
)
)
/*0xF1 - 0xF9
:
100us - 900us*/
{
{
TpTimingCtrl
.
STimer
=
(((
uint32_t
)
STminTime
)
&
(
uint32_t
)
0x0000000F
)
*
(
uint32_t
)
100
;
TpTimingCtrl
.
STimer
=
(((
uint32_t
)
STminTime
)
&
(
uint32_t
)
0x0000000F
)
*
(
uint32_t
)
100
;
}
}
else
/*Reserved
:1
27ms*/
else
/*Reserved
:
127ms*/
{
{
TpTimingCtrl
.
STimer
=
(
uint32_t
)
128000
;
TpTimingCtrl
.
STimer
=
(
uint32_t
)
128000
;
}
}
TpTimingCtrl
.
STminStatus
=
STmin_TIMING
;
/*STmin
开始计时
*/
TpTimingCtrl
.
STminStatus
=
STmin_TIMING
;
/*STmin
开始计时*
/
}
}
/******************************************************************************
/******************************************************************************
函数名:
DoCAN_Get_STmin_Timer_Status
函数名:Do
CAN_Get_STmin_Timer_Status
功 能:获取当前STmin定时器的状态
功 能:获取当前STmin定时器的状态
参 数:无
参 数:无
返回值:STmin_TIMER_IDLE:STmin定时器空闲
返回值:STmin_TIMER_IDLE:STmin定时器空闲
STmin_TIME_UP
:STmin定时时间到
STmin_TIME_UP
:STmin定时时间到
STmin_TIMING
:STmin定时器计时中
STmin_TIMING
:STmin定时器计时中
******************************************************************************/
******************************************************************************/
uint8_t
DoCAN_Get_STmin_Timer_Status
(
void
)
uint8_t
DoCAN_Get_STmin_Timer_Status
(
void
)
{
{
...
...
YueJin_test_bench/source/Appliciation/Key_user.c
View file @
af19864e
...
@@ -206,10 +206,11 @@ void Key_Operation_SW3(Key_Event_en_t enKeyEvent)
...
@@ -206,10 +206,11 @@ void Key_Operation_SW3(Key_Event_en_t enKeyEvent)
clearOdoFlag
=
1
;
clearOdoFlag
=
1
;
}
}
else
RS485_TX_finish
=
0
;
{
// else
clearOdoFlag
=
0
;
// {
}
// clearOdoFlag = 0;
// }
queren
=
0
;
queren
=
0
;
}
}
}
}
...
...
YueJin_test_bench/source/Appliciation/Protocol_CRC16.c
0 → 100644
View file @
af19864e
/**
* @file Protocol_CRC16.c
* @brief CRC16计算
* @details CRC16计算
* @author myliu
* @date 2022.05.09
* @version V1.0
* @copyright myiu
*/
#include "Protocol_CRC16.h"
static
const
Protocol_uint8_t
CRC16_TAB_H
[
256
]
=
{
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x01u
,
0xC0u
,
0x80u
,
0x41u
,
0x00u
,
0xC1u
,
0x81u
,
0x40u
};
static
const
Protocol_uint8_t
CRC16_TAB_L
[
256
]
=
{
0x00u
,
0xC0u
,
0xC1u
,
0x01u
,
0xC3u
,
0x03u
,
0x02u
,
0xC2u
,
0xC6u
,
0x06u
,
0x07u
,
0xC7u
,
0x05u
,
0xC5u
,
0xC4u
,
0x04u
,
0xCCu
,
0x0Cu
,
0x0Du
,
0xCDu
,
0x0Fu
,
0xCFu
,
0xCEu
,
0x0Eu
,
0x0Au
,
0xCAu
,
0xCBu
,
0x0Bu
,
0xC9u
,
0x09u
,
0x08u
,
0xC8u
,
0xD8u
,
0x18u
,
0x19u
,
0xD9u
,
0x1Bu
,
0xDBu
,
0xDAu
,
0x1Au
,
0x1Eu
,
0xDEu
,
0xDFu
,
0x1Fu
,
0xDDu
,
0x1Du
,
0x1Cu
,
0xDCu
,
0x14u
,
0xD4u
,
0xD5u
,
0x15u
,
0xD7u
,
0x17u
,
0x16u
,
0xD6u
,
0xD2u
,
0x12u
,
0x13u
,
0xD3u
,
0x11u
,
0xD1u
,
0xD0u
,
0x10u
,
0xF0u
,
0x30u
,
0x31u
,
0xF1u
,
0x33u
,
0xF3u
,
0xF2u
,
0x32u
,
0x36u
,
0xF6u
,
0xF7u
,
0x37u
,
0xF5u
,
0x35u
,
0x34u
,
0xF4u
,
0x3Cu
,
0xFCu
,
0xFDu
,
0x3Du
,
0xFFu
,
0x3Fu
,
0x3Eu
,
0xFEu
,
0xFAu
,
0x3Au
,
0x3Bu
,
0xFBu
,
0x39u
,
0xF9u
,
0xF8u
,
0x38u
,
0x28u
,
0xE8u
,
0xE9u
,
0x29u
,
0xEBu
,
0x2Bu
,
0x2Au
,
0xEAu
,
0xEEu
,
0x2Eu
,
0x2Fu
,
0xEFu
,
0x2Du
,
0xEDu
,
0xECu
,
0x2Cu
,
0xE4u
,
0x24u
,
0x25u
,
0xE5u
,
0x27u
,
0xE7u
,
0xE6u
,
0x26u
,
0x22u
,
0xE2u
,
0xE3u
,
0x23u
,
0xE1u
,
0x21u
,
0x20u
,
0xE0u
,
0xA0u
,
0x60u
,
0x61u
,
0xA1u
,
0x63u
,
0xA3u
,
0xA2u
,
0x62u
,
0x66u
,
0xA6u
,
0xA7u
,
0x67u
,
0xA5u
,
0x65u
,
0x64u
,
0xA4u
,
0x6Cu
,
0xACu
,
0xADu
,
0x6Du
,
0xAFu
,
0x6Fu
,
0x6Eu
,
0xAEu
,
0xAAu
,
0x6Au
,
0x6Bu
,
0xABu
,
0x69u
,
0xA9u
,
0xA8u
,
0x68u
,
0x78u
,
0xB8u
,
0xB9u
,
0x79u
,
0xBBu
,
0x7Bu
,
0x7Au
,
0xBAu
,
0xBEu
,
0x7Eu
,
0x7Fu
,
0xBFu
,
0x7Du
,
0xBDu
,
0xBCu
,
0x7Cu
,
0xB4u
,
0x74u
,
0x75u
,
0xB5u
,
0x77u
,
0xB7u
,
0xB6u
,
0x76u
,
0x72u
,
0xB2u
,
0xB3u
,
0x73u
,
0xB1u
,
0x71u
,
0x70u
,
0xB0u
,
0x50u
,
0x90u
,
0x91u
,
0x51u
,
0x93u
,
0x53u
,
0x52u
,
0x92u
,
0x96u
,
0x56u
,
0x57u
,
0x97u
,
0x55u
,
0x95u
,
0x94u
,
0x54u
,
0x9Cu
,
0x5Cu
,
0x5Du
,
0x9Du
,
0x5Fu
,
0x9Fu
,
0x9Eu
,
0x5Eu
,
0x5Au
,
0x9Au
,
0x9Bu
,
0x5Bu
,
0x99u
,
0x59u
,
0x58u
,
0x98u
,
0x88u
,
0x48u
,
0x49u
,
0x89u
,
0x4Bu
,
0x8Bu
,
0x8Au
,
0x4Au
,
0x4Eu
,
0x8Eu
,
0x8Fu
,
0x4Fu
,
0x8Du
,
0x4Du
,
0x4Cu
,
0x8Cu
,
0x44u
,
0x84u
,
0x85u
,
0x45u
,
0x87u
,
0x47u
,
0x46u
,
0x86u
,
0x82u
,
0x42u
,
0x43u
,
0x83u
,
0x41u
,
0x81u
,
0x80u
,
0x40u
};
/**
* 获取CRC16校验和
*/
/**
* @brief 计算传入数据的CRC16
* @param[in] pData 计算的数据内容
* @param[in] len 计算的数据长度
*
* @return 校验和
*
* @since 1.0.0
*/
Protocol_uint16_t
getCheckSum
(
const
Protocol_uint8_t
*
getCheckSum_pData
,
int
len
)
{
Protocol_uint8_t
u8_crc_h
=
0xFFu
;
Protocol_uint8_t
u8_crc_l
=
0xFFu
;
Protocol_uint8_t
u8_index
=
0u
;
Protocol_uint8_t
i
=
0u
;
Protocol_uint16_t
re_value
;
int
length
=
len
;
while
(
length
--
)
{
u8_index
=
u8_crc_h
^
(
getCheckSum_pData
[
i
++
]);
u8_crc_h
=
u8_crc_l
^
CRC16_TAB_H
[
u8_index
];
u8_crc_l
=
CRC16_TAB_L
[
u8_index
];
}
re_value
=
(
Protocol_uint16_t
)
u8_crc_h
<<
8u
;
re_value
|=
u8_crc_l
;
return
re_value
;
}
YueJin_test_bench/source/Appliciation/Protocol_CRC16.h
0 → 100644
View file @
af19864e
#ifndef PROTOCOL_CRC16_H
#define PROTOCOL_CRC16_H
//#include "Application.h"
#include "Protocol_Lib.h"
#include <stdio.h>
#include <stdint.h>
Protocol_uint16_t
getCheckSum
(
const
Protocol_uint8_t
*
getCheckSum_pData
,
int
len
);
#endif
YueJin_test_bench/source/Appliciation/Protocol_Lib.c
0 → 100644
View file @
af19864e
/**
* @file Protocol_Lib.c
* @brief 串口协议解析
* @details 串口协议解析
* @author myliu
* @date 2022.05.09
* @version V1.0
* @copyright myiu
*/
#include <stdio.h>
#include <string.h>
#include "Protocol_CRC16.h"
#include "debugger.h"
static
UARTOpen
UARTOpen_Cbk
;
static
UARTSend
UARTSend_Cbk
;
static
UARTRead
UARTRead_Cbk
;
static
ProcParse
ProcParseCbk
;
static
UARTClose
UARTClose_Cbk
;
static
ProtocolSetData
ProtocolSetData_Cbk
;
static
Protocol_uint8_t
*
mDataBufPtr
=
Protocol_NULL
;
static
Protocol_uint16_t
mDataBufLen
=
0
;
static
Protocol_uint32_t
DataBufMaxLen
=
0
;
// #define DEBUG_PRO_DATA 0
/**
* @brief 初始化函数
* @param[in] pMemSpace 分配给协议库的内存空间,用来缓存串口数据
* @param[in] MemLen 分配的内存空间大小
* @param[in] pFunc 回调函数,包括串口打开、发送、读取、关闭,也包括解析后数据回传
* @param[in] ProcParseCbk 此回调函数,返回数据从FrameNo开始到CRC16之前,和ProtocolSetData_Cbk二选一
* @param[in] ProtocolSetData_Cbk 此回调函数,返回数据区分命令字、电源状态等,和ProcParseCbk二选一,详见结构体Protocol_Data_t
*
* @warning 此函数KL30和Wakeup都要调用,否则未分配内存,功能不好使,也有可能造成野指针复位
*
* @since 1.0.0
*/
void
Protocol_Init
(
Protocol_uint8_t
*
pMemSpace
,
Protocol_uint32_t
MemLen
,
Protocol_Func_t
*
pFunc
)
{
mDataBufPtr
=
pMemSpace
;
DataBufMaxLen
=
MemLen
;
UARTOpen_Cbk
=
pFunc
->
UARTOpen_Cbk
;
UARTSend_Cbk
=
pFunc
->
UARTSend_Cbk
;
UARTRead_Cbk
=
pFunc
->
UARTRead_Cbk
;
ProcParseCbk
=
pFunc
->
ProcParseCbk
;
UARTClose_Cbk
=
pFunc
->
UARTClose_Cbk
;
ProtocolSetData_Cbk
=
pFunc
->
ProtocolSetData_Cbk
;
if
(
UARTOpen_Cbk
!=
Protocol_NULL
)
{
UARTOpen_Cbk
(
);
}
return
;
}
/**
* @brief 串口协议服务函数,包括读取数据,解析数据,如在外部读取数据,可不调用此函数
*
* @warning 此函数可自定义周期调用,建议20ms周期调用,最大不可超过协议的最小发送周期
*
* @since 1.0.0
*/
void
Protocol_Service
(
void
)
{
int
len
;
Protocol_uint32_t
readNum
=
0
;
if
(
UARTRead_Cbk
!=
Protocol_NULL
)
{
readNum
=
UARTRead_Cbk
(
mDataBufPtr
+
mDataBufLen
,
256
-
mDataBufLen
);
if
(
readNum
>
0
)
{
mDataBufLen
+=
readNum
;
// 解析协议
len
=
Protocol_Parse
(
mDataBufPtr
,
mDataBufLen
);
if
(
(
len
>
0
)
&&
(
len
<
mDataBufLen
)
)
{
// 将未解析的数据移到头部
// Move unparsed data to the head
memcpy
(
mDataBufPtr
,
mDataBufPtr
+
len
,
mDataBufLen
-
len
);
}
mDataBufLen
-=
len
;
}
}
}
/**
* @brief 协议解析函数,如外部获取数据(例如中断),可直接调用此函数解析数据
* @param[in] pData 协议数据内容
* @param[in] len 需要处理的协议数据长度
*
* @return 剩余已处理的数据长度
*
* @since 1.0.0
*/
Protocol_uint32_t
Protocol_Parse
(
const
Protocol_uint8_t
*
pData
,
Protocol_uint32_t
len
)
{
Protocol_uint32_t
remainLen
=
len
;
// 剩余数据长度 Remaining data length
Protocol_uint32_t
dataLen
;
// 数据包长度 Packet length
Protocol_uint32_t
frameLen
;
// 帧长度 Frame length
Protocol_uint8_t
frameSum
;
// 校验和 Checksum
Protocol_uint8_t
calcSum
=
0
;
// 计算得到的校验和 Calculated Checksum
Protocol_Data_t
ProcData
;
int
i
=
0
;
int
dataBuf
[
256
];
/**
* 以下部分根据协议格式进行相应的修改,解析出每一帧的数据
*/
while
(
remainLen
>=
DATA_PACKAGE_MIN_LEN
)
{
// 找到一帧数据的数据头
// Find the data header of a frame of data
while
(
(
remainLen
>=
2
)
&&
((
pData
[
0
]
!=
CMD_HEAD1
)
||
(
pData
[
1
]
!=
CMD_HEAD2
))
)
{
pData
++
;
remainLen
--
;
continue
;
}
if
(
remainLen
<
DATA_PACKAGE_MIN_LEN
)
{
#ifdef DEBUG_PRO_DATA
d_printf
(
"too short!!!!!!
\n
"
);
#endif
break
;
}
// 获取数据长度
dataLen
=
pData
[
3
];
// 计算帧总长度 (起始字节2 + ID1 + Len1 + 数据内容dataLen + 校验和1 + 结束字节2)
frameLen
=
2
+
1
+
1
+
dataLen
+
1
+
2
;
if
(
frameLen
>
remainLen
)
{
// 数据内容不全
#ifdef DEBUG_PRO_DATA
d_printf
(
"Incomplete data packet!!!!!!
\n
"
);
#endif
break
;
}
// 检查结束字节
if
(
(
pData
[
frameLen
-
2
]
!=
CMD_END1
)
||
(
pData
[
frameLen
-
1
]
!=
CMD_END2
)
)
{
#ifdef DEBUG_PRO_DATA
d_printf
(
"End bytes error!!!!!!
\n
"
);
#endif
pData
++
;
remainLen
--
;
continue
;
}
// 打印一帧数据,需要时在CommDef.h文件中打开DEBUG_PRO_DATA宏
#ifdef DEBUG_PRO_DATA
for
(
i
=
0
;
i
<
frameLen
;
++
i
)
{
d_printf
(
"%x "
,
pData
[
i
]);
}
d_printf
(
"
\n
"
);
#endif
// 计算和校验 (ID + Len + 数据内容)
calcSum
=
0
;
for
(
i
=
2
;
i
<
frameLen
-
3
;
i
++
)
{
calcSum
+=
pData
[
i
];
}
// 获取接收到的校验和
frameSum
=
pData
[
frameLen
-
3
];
if
(
calcSum
==
frameSum
)
{
// 解析一帧数据
if
(
ProcParseCbk
!=
Protocol_NULL
)
{
// 传递从ID开始到校验和之前的数据
ProcParseCbk
(
pData
+
2
,
dataLen
+
2
);
}
if
(
ProtocolSetData_Cbk
!=
Protocol_NULL
)
{
// 填充协议数据结构
ProcData
.
ID
=
pData
[
2
];
ProcData
.
DataLen
=
dataLen
;
// 复制数据内容
memcpy
(
ProcData
.
Data
,
pData
+
4
,
dataLen
);
// 回调处理
ProtocolSetData_Cbk
(
&
ProcData
);
}
}
else
{
#ifdef DEBUG_PRO_DATA
d_printf
(
"CheckSum error: calc = %x, recv = %x!!!!!!
\n
"
,
calcSum
,
frameSum
);
#endif
}
pData
+=
frameLen
;
remainLen
-=
frameLen
;
}
return
len
-
remainLen
;
}
/**
* 根据协议格式进行拼接
*/
/**
* @brief 串口协议数据拼接,如初始化发送函数,调用此函数后,数据已通过串口发送
* @param[in] cmdID 命令字
* @param[in] pData 协议数据内容(不包括协议头、长度、帧序号、命令字、校验和,从数据域算起)
* @param[in] len 数据域长度
*
* @return 已发送的数据长度
*
* @since 1.0.0
*/
Protocol_uint32_t
Protocol_Send
(
const
Protocol_uint16_t
cmdID
,
const
Protocol_uint8_t
*
pData
,
Protocol_uint8_t
len
)
{
int
i
;
Protocol_uint8_t
checksum
=
0
;
Protocol_uint8_t
dataBuf
[
256
];
Protocol_uint32_t
frameLen
;
if
(
len
+
DATA_PACKAGE_MIN_LEN
>
256
)
{
// printf("sendProtocol data is too len !!!\n");
return
0
;
}
dataBuf
[
0
]
=
CMD_HEAD1
;
dataBuf
[
1
]
=
CMD_HEAD2
;
// 同步帧头 Sync frame header
dataBuf
[
2
]
=
(
Protocol_uint8_t
)
cmdID
;
// 报文ID
dataBuf
[
3
]
=
len
;
// 数据长度
frameLen
=
4
;
// 数据内容 Data
for
(
i
=
0
;
i
<
len
;
++
i
)
{
dataBuf
[
frameLen
]
=
pData
[
i
];
frameLen
++
;
}
// 计算校验和 (ID + Len + 数据内容)
checksum
=
0
;
for
(
i
=
2
;
i
<
frameLen
;
i
++
)
{
checksum
+=
dataBuf
[
i
];
}
// 添加校验和
dataBuf
[
frameLen
]
=
checksum
;
frameLen
++
;
// 添加结束字节
dataBuf
[
frameLen
]
=
CMD_END1
;
frameLen
++
;
dataBuf
[
frameLen
]
=
CMD_END2
;
frameLen
++
;
if
(
UARTSend_Cbk
!=
Protocol_NULL
)
{
return
UARTSend_Cbk
(
dataBuf
,
frameLen
);
}
else
{
return
0
;
}
}
YueJin_test_bench/source/Appliciation/Protocol_Lib.h
0 → 100644
View file @
af19864e
#ifndef PROTOCOL_LIB_H
#define PROTOCOL_LIB_H
/*
Platform_32Bit
Platform_16Bit
*/
#ifdef Platform_16Bit
#define Protocol_uint8_t unsigned char
#define Protocol_uint16_t unsigned int
#define Protocol_uint32_t unsigned long
#else
#define Protocol_uint8_t unsigned char
#define Protocol_uint16_t unsigned short
#define Protocol_uint32_t unsigned int
#define Protocol_uint64_t unsigned long long
#endif
#ifndef Protocol_NULL
#define Protocol_NULL ( void * )0u
#endif
/* NULL */
/**<0x59 0x44 ID Len DATA0-DATAN SUM 0x4B 0x4A*/
#define DATA_PACKAGE_MIN_LEN 7
/**< 0x59 0x44 + ID + Len + 至少一个数据字节 + SUM + 0x4B 0x4A */
#define DATA_PACKAGE_FIXED_LEN 6
/**< 未计算在长度内的数据 0x59 0x44 + ID + Len + SUM + 0x4B 0x4A */
#define CMD_HEAD1 0x59
#define CMD_HEAD2 0x44
#define CMD_END1 0x4B
#define CMD_END2 0x4A
/**@struct Protocol_Data_t
* @brief 解析后的协议数据
*/
typedef
struct
{
Protocol_uint8_t
ID
;
/**< 报文ID */
Protocol_uint8_t
DataLen
;
/**< 有效数据长度 DATA0-DATAN*/
Protocol_uint8_t
Data
[
256
];
/**< 有效数据内容 DATA0-DATAN*/
}
Protocol_Data_t
;
typedef
Protocol_uint8_t
(
*
UARTOpen
)(
void
);
typedef
Protocol_uint32_t
(
*
UARTSend
)(
const
Protocol_uint8_t
*
pData
,
Protocol_uint32_t
u32Len
);
typedef
Protocol_uint32_t
(
*
UARTRead
)(
Protocol_uint8_t
*
pData
,
Protocol_uint32_t
u32Len
);
typedef
void
(
*
ProtocolSetData
)(
const
Protocol_Data_t
*
pData
);
typedef
void
(
*
ProcParse
)(
const
Protocol_uint8_t
*
pData
,
Protocol_uint32_t
u32Len
);
typedef
void
(
*
UARTClose
)(
void
);
/**@struct Protocol_Func_t
* @brief 协议解析回调函数
*/
typedef
struct
{
UARTOpen
UARTOpen_Cbk
;
/**< 串口打开回调 */
UARTSend
UARTSend_Cbk
;
/**< 串口发送回调 */
UARTRead
UARTRead_Cbk
;
/**< 串口读取回调 */
UARTClose
UARTClose_Cbk
;
/**< 串口关闭回调 */
ProcParse
ProcParseCbk
;
/**< 解析后的数据, 不包含协议头尾和校验,和ProtocolSetData_Cbk二选一 */
ProtocolSetData
ProtocolSetData_Cbk
;
/**< 不包含 0x59 0x44 + ID + Len + SUM + 0x4B 0x4A,和ProcParse二选一 */
}
Protocol_Func_t
;
void
Protocol_Init
(
Protocol_uint8_t
*
pMemSpace
,
Protocol_uint32_t
MemLen
,
Protocol_Func_t
*
pFunc
);
void
Protocol_Service
(
void
);
Protocol_uint32_t
Protocol_Parse
(
const
Protocol_uint8_t
*
pData
,
Protocol_uint32_t
len
);
Protocol_uint32_t
Protocol_Send
(
const
Protocol_uint16_t
cmdID
,
const
Protocol_uint8_t
*
pData
,
Protocol_uint8_t
len
);
#endif
YueJin_test_bench/source/Appliciation/Protocol_User.c
0 → 100644
View file @
af19864e
#include "Protocol_User.h"
#include "RTE_GPIO.h"
#include "api_RS485.h"
#include "Barcode_Scanner.h"
#include "Protocol_Lib.h" // 添加Protocol_Data_t定义
#include <string.h> // 添加memcpy等函数声明
#define UART_TX_MAX_DEPTH 1024UL //(2 * 1024UL) // 4K
#define UART_RX_MAX_DEPTH (2 * 1024UL) // 4K
#define UART_DATA_BUF_LEN (2 * 1024UL) // 4K
uint32_t
u32ActiveCount
=
0
;
uint32_t
u32ActiveReset
=
0
;
typedef
struct
__attribute__
((
aligned
(
4
)))
{
Protocol_uint32_t
read_pos
;
Protocol_uint32_t
write_pos
;
Protocol_uint8_t
Rx_Buffer
[
UART_RX_MAX_DEPTH
];
}
UARTRxBuf_t
;
typedef
struct
__attribute__
((
aligned
(
4
)))
{
Protocol_uint32_t
read_pos
;
Protocol_uint32_t
write_pos
;
Protocol_uint8_t
Tx_Buffer
[
UART_TX_MAX_DEPTH
];
}
UARTTxBuf_t
;
static
UARTRxBuf_t
UARTRxBuf
;
static
UARTTxBuf_t
UARTTxBuf
;
static
Protocol_uint8_t
UsartDataBuf
[
256
];
static
Protocol_uint8_t
mDataBufPtr
[
UART_DATA_BUF_LEN
];
static
Protocol_uint8_t
Protocol_OpenUart
(
void
);
static
Protocol_uint32_t
Protocol_UartRead
(
Protocol_uint8_t
*
UartRea_pData
,
Protocol_uint32_t
len
);
static
Protocol_uint32_t
Protocol_UartSend
(
const
Protocol_uint8_t
*
UartSend_pData
,
Protocol_uint32_t
u32Len
);
static
void
Protocol_UartHandle
(
const
Protocol_Data_t
*
UartHandle_pData
);
void
Protocol_KL30_Wakeup_Init
(
void
)
{
Protocol_Func_t
pFunc
;
pFunc
.
UARTOpen_Cbk
=
Protocol_OpenUart
;
pFunc
.
UARTSend_Cbk
=
Protocol_UartSend
;
pFunc
.
UARTRead_Cbk
=
Protocol_UartRead
;
pFunc
.
UARTClose_Cbk
=
Protocol_NULL
;
pFunc
.
ProcParseCbk
=
Protocol_NULL
;
pFunc
.
ProtocolSetData_Cbk
=
Protocol_UartHandle
;
UARTTxBuf
.
read_pos
=
0
;
UARTTxBuf
.
write_pos
=
0
;
UARTRxBuf
.
read_pos
=
0
;
UARTRxBuf
.
write_pos
=
0
;
Protocol_Init
(
mDataBufPtr
,
UART_DATA_BUF_LEN
,
&
pFunc
);
}
void
Protocol_Send_Service
(
void
)
{
Protocol_uint32_t
i
=
0u
;
Protocol_uint32_t
DataLen
=
0u
;
Protocol_uint32_t
SendLen
=
0u
;
if
(
UARTTxBuf
.
write_pos
==
UARTTxBuf
.
read_pos
)
{
return
;
}
if
(
UARTTxBuf
.
write_pos
>
UARTTxBuf
.
read_pos
)
{
DataLen
=
UARTTxBuf
.
write_pos
-
UARTTxBuf
.
read_pos
;
}
else
{
DataLen
=
UART_TX_MAX_DEPTH
-
(
UARTTxBuf
.
read_pos
-
UARTTxBuf
.
write_pos
);
}
if
(
DataLen
>
255
)
{
SendLen
=
255
;
}
else
{
SendLen
=
DataLen
;
}
for
(
i
=
0u
;
i
<
SendLen
;
i
++
)
{
UsartDataBuf
[
i
]
=
UARTTxBuf
.
Tx_Buffer
[
UARTTxBuf
.
read_pos
];
UARTTxBuf
.
read_pos
=
(
UARTTxBuf
.
read_pos
+
1
)
%
UART_TX_MAX_DEPTH
;
}
Uart0_IntSend
(
UsartDataBuf
,
SendLen
);
}
static
Protocol_uint8_t
Protocol_OpenUart
(
void
)
{
#if 0
UART_Channel_Config_st_t loc_config;
loc_config.u32UARTChEn = 1;
loc_config.u32UARTbps = 115200;
loc_config.pfnUARTConfirmCallBack = Protocol_NULL;
loc_config.pfnUARTReadMsgCallBack = UART_Put;
UART_Init(UART_RLIN31, &loc_config);
#endif
return
1
;
}
static
Protocol_uint32_t
Protocol_UartRead
(
Protocol_uint8_t
*
UartRea_pData
,
Protocol_uint32_t
len
)
{
Protocol_uint32_t
i
=
0
;
Protocol_uint32_t
DataLen
=
0u
;
Protocol_uint32_t
ReadLen
=
0u
;
if
(
UARTRxBuf
.
write_pos
==
UARTRxBuf
.
read_pos
)
{
return
0
;
//队列空
}
if
(
UARTRxBuf
.
write_pos
>
UARTRxBuf
.
read_pos
)
{
DataLen
=
UARTRxBuf
.
write_pos
-
UARTRxBuf
.
read_pos
;
}
else
{
DataLen
=
UART_RX_MAX_DEPTH
-
(
UARTRxBuf
.
read_pos
-
UARTRxBuf
.
write_pos
);
}
if
(
len
>
DataLen
)
{
ReadLen
=
DataLen
;
}
else
{
ReadLen
=
len
;
}
for
(
i
=
0u
;
i
<
ReadLen
;
i
++
)
{
UartRea_pData
[
i
]
=
UARTRxBuf
.
Rx_Buffer
[
UARTRxBuf
.
read_pos
];
UARTRxBuf
.
read_pos
=
(
UARTRxBuf
.
read_pos
+
1
)
%
UART_RX_MAX_DEPTH
;
}
return
ReadLen
;
}
static
Protocol_uint32_t
Protocol_UartSend
(
const
Protocol_uint8_t
*
UartSend_pData
,
Protocol_uint32_t
u32Len
)
{
Protocol_uint8_t
dataBuf
[
256
];
Protocol_uint32_t
frameLen
=
0
;
// 构建协议帧(适配Protocol_Lib格式)
dataBuf
[
frameLen
++
]
=
CMD_HEAD1
;
// 帧头
dataBuf
[
frameLen
++
]
=
CMD_HEAD2
;
dataBuf
[
frameLen
++
]
=
u32Len
+
4
;
// 总长度(数据+4字节固定)
dataBuf
[
frameLen
++
]
=
0
;
// 帧序号
dataBuf
[
frameLen
++
]
=
BARCODE_CMD_ID
;
// 条码指令ID
// 拷贝有效数据
if
(
u32Len
>
0
&&
UartSend_pData
!=
Protocol_NULL
)
{
memcpy
(
&
dataBuf
[
frameLen
],
UartSend_pData
,
u32Len
);
frameLen
+=
u32Len
;
}
// 计算CRC16校验和
Protocol_uint16_t
checksum
=
getCheckSum
(
dataBuf
+
2
,
frameLen
-
2
);
dataBuf
[
frameLen
++
]
=
(
checksum
>>
8
)
&
0xFF
;
dataBuf
[
frameLen
++
]
=
checksum
&
0xFF
;
// 写入发送缓冲区
Protocol_uint32_t
RemainLen
=
0u
;
if
(
UARTTxBuf
.
write_pos
>=
UARTTxBuf
.
read_pos
)
{
RemainLen
=
UART_TX_MAX_DEPTH
-
(
UARTTxBuf
.
write_pos
-
UARTTxBuf
.
read_pos
);
}
else
{
RemainLen
=
UARTTxBuf
.
read_pos
-
UARTTxBuf
.
write_pos
;
}
if
(
frameLen
>
RemainLen
)
{
return
1
;
// 队列已满
}
for
(
Protocol_uint32_t
i
=
0
;
i
<
frameLen
;
i
++
)
{
UARTTxBuf
.
Tx_Buffer
[
UARTTxBuf
.
write_pos
]
=
dataBuf
[
i
];
UARTTxBuf
.
write_pos
=
(
UARTTxBuf
.
write_pos
+
1
)
%
UART_TX_MAX_DEPTH
;
}
return
0
;
}
static
void
Protocol_UartHandle
(
const
Protocol_Data_t
*
UartHandle_pData
)
{
uint8_t
ID04
[
1
]
=
{
0
};
u32ActiveCount
=
0
;
if
(
UartHandle_pData
->
CmdID
==
ESP32_MCU_0x10
)
{
BlueTooth
.
BlueTooth_St
=
UartHandle_pData
->
Data
[
0
];
if
(
BlueTooth
.
BlueTooth_St
==
BLUE_STATE_ON
)
{
Protocol_Send
(
MCU_ESP32_0x20
,
Protocol_NULL
,
0
);
}
}
else
if
(
UartHandle_pData
->
CmdID
==
ESP32_MCU_0x12
)
{
BlueTooth
.
BLE_St
=
UartHandle_pData
->
Data
[
0
];
}
else
if
(
UartHandle_pData
->
CmdID
==
ESP32_MCU_0x05
)
{
BlueTooth
.
ESP32_SWV
=
UartHandle_pData
->
Data
[
0
];
}
else
if
(
UartHandle_pData
->
CmdID
==
ESP32_MCU_0x02
)
{
BlueTooth
.
ESP32_Reset
=
UartHandle_pData
->
Data
[
0
];
if
(
BlueTooth
.
ESP32_Reset
==
1
)
{
ID04
[
0
]
=
1
;
Protocol_Send
(
MCU_ESP32_0x04
,
ID04
,
1
);
}
else
if
(
BlueTooth
.
ESP32_Reset
==
2
)
{
__NVIC_SystemReset
();
}
else
{
;
}
}
else
if
(
UartHandle_pData
->
CmdID
==
ESP32_MCU_0x01
)
{
if
(
UartHandle_pData
->
Data
[
0
]
==
0x33
)
{
BlueTooth
.
Navigation_St
=
EM_ESP32_NAVI_ST_NAVIGATING
;
}
else
if
(
UartHandle_pData
->
Data
[
0
]
==
0x35
)
{
BlueTooth
.
Navigation_St
=
EM_ESP32_NAVI_ST_STANDBY
;
}
else
{
;
}
BlueTooth
.
Navigation_Code
=
UartHandle_pData
->
Data
[
1
];
BlueTooth
.
Navigation_Mileage
=
((
UartHandle_pData
->
Data
[
5
]
<<
24
)
|
(
UartHandle_pData
->
Data
[
4
]
<<
16
)
|
(
UartHandle_pData
->
Data
[
3
]
<<
8
)
|
UartHandle_pData
->
Data
[
2
]);
}
else
if
(
UartHandle_pData
->
CmdID
==
BARCODE_CMD_ID
)
{
// 处理条码数据
memcpy
(
BarCode
,
UartHandle_pData
->
Data
,
UartHandle_pData
->
DataLen
);
BarCode
[
UartHandle_pData
->
DataLen
]
=
'\0'
;
// 添加字符串结束符
}
else
{
//非本协议数据,不处理
}
}
void
Protocol_ESP32_Active_Service
(
void
)
{
if
(
RTE_GPIO_Get_Level
(
L_BIASBITSW_POW
)
==
1
)
{
if
(
u32ActiveCount
>=
200
)
{
u32ActiveReset
=
0
;
RTE_GPIO_Set_Level
(
L_BIASBITSW_POW
,
RTE_GPIO_LEVEL_LOW
);
}
else
{
u32ActiveCount
++
;
}
}
else
{
if
(
u32ActiveReset
<=
2
)
{
u32ActiveReset
++
;
}
else
{
u32ActiveReset
=
0
;
u32ActiveCount
=
0
;
RTE_GPIO_Set_Level
(
L_BIASBITSW_POW
,
RTE_GPIO_LEVEL_HIGH
);
}
}
}
void
UART_Put
(
Protocol_uint16_t
Data
)
{
Protocol_uint32_t
nextPos
=
0u
;
nextPos
=
(
UARTRxBuf
.
write_pos
+
1
)
%
UART_RX_MAX_DEPTH
;
if
(
nextPos
==
UARTRxBuf
.
read_pos
)
{
//队列已满,无法插入队列
}
else
{
UARTRxBuf
.
Rx_Buffer
[
UARTRxBuf
.
write_pos
]
=
(
Protocol_uint8_t
)
Data
;
UARTRxBuf
.
write_pos
=
(
UARTRxBuf
.
write_pos
+
1
)
%
UART_RX_MAX_DEPTH
;
}
//return;
}
YueJin_test_bench/source/Appliciation/Protocol_User.h
0 → 100644
View file @
af19864e
#ifndef PROTOCOL_USER_H
#define PROTOCOL_USER_H
//#include "Application.h"
#include "Protocol_Lib.h"
#include <stdio.h>
#include <stdint.h>
void
Protocol_KL30_Wakeup_Init
(
void
);
void
Protocol_Send_Service
(
void
);
// 10ms任务调用
void
UART_Put
(
Protocol_uint16_t
Data
);
void
Protocol_ESP32_Active_Service
(
void
);
#endif
YueJin_test_bench/source/Appliciation/Task.c
View file @
af19864e
...
@@ -52,6 +52,7 @@ void Sys_Run_Mode_Pseudo_Real_Time_Tasks(void)
...
@@ -52,6 +52,7 @@ void Sys_Run_Mode_Pseudo_Real_Time_Tasks(void)
TFT_LCD_Display_Update_Service
(
);
TFT_LCD_Display_Update_Service
(
);
Fre_In_Service
(
FRE_VEHICLE
);
Fre_In_Service
(
FRE_VEHICLE
);
MENU_CHECK_STEP
=
11
;
//Fre_In_Service(FRE_ENGINE);
//Fre_In_Service(FRE_ENGINE);
}
}
/*============================================================================*/
/*============================================================================*/
...
@@ -258,14 +259,45 @@ void Sys_Run_Mode_10ms_Tasks_Group(void)
...
@@ -258,14 +259,45 @@ void Sys_Run_Mode_10ms_Tasks_Group(void)
{
{
MENU_CHECK_STEP
=
3
;
MENU_CHECK_STEP
=
3
;
backsend
();
backsend
();
RS485_User_Tx_Data
();
// RS485_TX_finish = 0;
// backsend();
if
(
RS485_TX_finish
==
0
)
{
LINE_OUT_NEG_09
=
1
;
if
(
1
==
LINE_OUT_NEG_09
)
{
RS485_User_Tx_Data
();
}
}
else
{
LINE_OUT_NEG_09
=
0
;
if
(
LINE_OUT_NEG_09
==
0
)
{
Recv_Byte
();
}
}
if
(
clearodotime
<
3000
)
if
(
clearodotime
<
3000
)
{
clearodotime
++
;
clearodotime
++
;
}
else
{
clearodotime
=
0
;
}
if
(
clearodotime
>=
1500
)
if
(
clearodotime
>=
1500
)
{
{
// Port_SetPortPinLevel(2,9,PortGpioHigh);
// Port_SetPortPinLevel(2,9,PortGpioHigh);
queren
=
1
;
queren
=
1
;
}
}
else
{
queren
=
0
;
}
}
}
}
}
...
@@ -572,7 +604,7 @@ void Sys_Exact_50us_Tasks(void)
...
@@ -572,7 +604,7 @@ void Sys_Exact_50us_Tasks(void)
/*==============================================================================
/*==============================================================================
��ȷ��100ms��ʱ���� ��ֹ�������б��е�����
��ȷ��100ms��ʱ���� ��ֹ�������б��е�����
------------------------------------------------------------------------------*/
------------------------------------------------------------------------------*/
uint32_t
clearodotime
=
0
;
uint32_t
clearodotime
flash
=
0
;
void
Sys_Exact_100ms_Tasks
(
void
)
void
Sys_Exact_100ms_Tasks
(
void
)
{
{
if
(
connectbleFlag
==
1
)
if
(
connectbleFlag
==
1
)
...
@@ -610,10 +642,10 @@ void Sys_Exact_100ms_Tasks(void)
...
@@ -610,10 +642,10 @@ void Sys_Exact_100ms_Tasks(void)
startIGONtime
=
0
;
startIGONtime
=
0
;
}
}
}
}
if
(
clearodotime
<
0xFFFFFFFF
)
if
(
clearodotime
flash
<
0xFFFFFFFF
)
{
{
clearodotime
++
;
clearodotime
flash
++
;
if
(
clearodotime
%
20
==
0
)
if
(
clearodotime
flash
%
20
==
0
)
{
{
if
(
R485_0x80_msg
[
11
]
<
5
)
if
(
R485_0x80_msg
[
11
]
<
5
)
{
{
...
@@ -630,7 +662,7 @@ void Sys_Exact_100ms_Tasks(void)
...
@@ -630,7 +662,7 @@ void Sys_Exact_100ms_Tasks(void)
}
}
else
else
{
{
clearodotime
=
0
;
clearodotime
flash
=
0
;
}
}
}
}
/*============================================================================*/
/*============================================================================*/
...
...
YueJin_test_bench/source/Appliciation/api_RS485.c
View file @
af19864e
...
@@ -499,9 +499,18 @@ void RS485_User_Tx_Data(void)
...
@@ -499,9 +499,18 @@ void RS485_User_Tx_Data(void)
#endif
#endif
}
}
uint8_t
backtime
=
0
;
void
backsend
(
void
)
void
backsend
(
void
)
{
{
if
(
RS485_send_time
>=
50
)
if
(
clearOdoFlag
==
0
)
{
backtime
=
20
;
}
else
{
backtime
=
10
;
}
if
(
RS485_send_time
>=
backtime
)
{
{
RS485_send_time
=
0
;
RS485_send_time
=
0
;
RS485_TX_finish
=
0
;
RS485_TX_finish
=
0
;
...
...
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