Compare commits

...

44 Commits

Author SHA1 Message Date
LGM
032e019397 新增VHR功能 2024-05-13 11:20:37 +08:00
LGM
ebfe560101 新增继电器粘连紧急处理 2024-05-10 18:26:03 +08:00
LGM
73fbc98c82 增加OTA功能,交直流回检滤波时间延长 2024-05-07 14:41:24 +08:00
LGM
b707353a49 增加交直流继电器粘连处理 2024-04-12 17:24:26 +08:00
LGM
b9c77b12f8 解决假休眠唤醒,通讯丢失问题 2024-04-11 14:15:43 +08:00
LGM
08dba96cc3 强推 2024-03-28 14:16:08 +08:00
LGM
1643c2172b 彻底解决温度限制问题 2024-03-28 14:07:26 +08:00
lidun
5b71ad08b7
DOX内置bin转换工具
Signed-off-by: lidun <1084178170@qq.com>
2024-03-23 11:01:22 +08:00
LGM
18c51300b2 修复板载温度BUG 2024-03-21 17:25:17 +08:00
lidun
9995c72909
修改UDS提交的更新文件
Signed-off-by: lidun <1084178170@qq.com>
2024-03-21 09:35:33 +08:00
LGM
6c0826e20a 改个初始化 2024-03-15 20:27:05 +08:00
LGM
067521a322 解决UDS任务饿死问题 2024-03-10 16:13:13 +08:00
LGM
417c55798d A40U31 2024-03-08 16:20:32 +08:00
LGM
d8d782b8c7 增加314故障等级 2024-03-08 00:00:33 +08:00
LGM
00e77c1fa4 增加DTCList全部故障注入 2024-03-06 01:03:30 +08:00
LGM
1ea9e10071 新板子 2024-03-03 22:11:59 +08:00
LGM
d6437b3089 新增3E8发送DTCList 2024-02-29 17:18:12 +08:00
LGM
7882e98019 修复43f丢帧 2024-02-28 15:46:20 +08:00
LGM
39af92f420 完善充电流程 2024-02-26 10:57:42 +08:00
LGM
5939bce269 完成UDS部分数据填充 2024-02-24 16:41:23 +08:00
lidun
ab15b4d38d
完成UDS合并
Signed-off-by: lidun <1084178170@qq.com>
2024-02-23 18:41:16 +08:00
LGM
361b1e0bcb 进入假休眠,有插枪动作或者有0x427,退出假休眠状态 2024-02-23 16:43:20 +08:00
LGM
fc5334f13a 增加发送网络管理条件 2024-02-21 17:11:05 +08:00
LGM
7e8302c678 优化休眠功能 2024-02-20 18:27:12 +08:00
LGM
a00425327a 有CAN2报文,不进入休眠 2024-02-19 14:53:32 +08:00
LGM
bdb06cd674 增加充电电流检测,直流充电结束阶段低于5A才能断开DC继电器 2024-02-04 20:01:49 +08:00
LGM
825c1ef670 增加高压互作信号滤波 2024-02-04 10:20:07 +08:00
LGM
00771ec60f 软件年前冻结版本 2024-02-03 21:33:06 +08:00
LGM
f353608d95 CC2阻值改到3E8 2024-02-03 17:18:56 +08:00
LGM
569c8853fb 优化判断故障条件 2024-02-02 14:13:36 +08:00
LGM
3d88ee1152 修改UDS物理请求改为响应 2024-02-01 11:36:40 +08:00
LGM
83f3991e7d 修改BSM,转发BMS故障 2024-01-31 10:46:36 +08:00
lidun
7a7daad23a
完成UDS升级
Signed-off-by: lidun <1084178170@qq.com>
2024-01-30 11:31:27 +08:00
lidun
1e7070334c
增加UDS升级功能
Signed-off-by: lidun <1084178170@qq.com>
2024-01-28 22:06:01 +08:00
LGM
cac8424c19 修改打印输出故障码信息 2024-01-28 19:32:13 +08:00
LGM
592e145a36 增加亿点故障码,优化充电流程 2024-01-27 23:12:40 +08:00
lidun
2675f990ac
更改报文发送机制
Signed-off-by: lidun <1084178170@qq.com>
2024-01-25 22:24:30 +08:00
LGM
15303c378a 优化粘连检测功能 2024-01-25 02:41:21 +08:00
LGM
30562fad90 增加直流交流继电器粘连检测功能 2024-01-25 02:34:43 +08:00
LGM
c3c14cd11f 修改直流充电与充电桩交互参数 2024-01-23 00:06:06 +08:00
lidun
ff03fd2f75
更改AD采样驱动
Signed-off-by: lidun <1084178170@qq.com>
2024-01-20 19:42:08 +08:00
lidun
751343a361
更新CC2采样策略
Signed-off-by: lidun <1084178170@qq.com>
2024-01-20 07:07:44 +08:00
lidun
e7c746efd1
增加单板调试指令
Signed-off-by: lidun <1084178170@qq.com>
2024-01-20 04:01:37 +08:00
LGM
c41c88d80e 赛力斯V2.0 2024-01-18 00:04:28 +08:00
117 changed files with 25608 additions and 9479 deletions

View File

@ -1,18 +0,0 @@
{
"configurations": [
{
"name": "windows-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "windows-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}

24
.vscode/launch.json vendored
View File

@ -1,24 +0,0 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": "d:/git_lidun/42_SaLiSi/Celis_adapter_DC_To_AC/HARDWARE/CDZ",
"program": "d:/git_lidun/42_SaLiSi/Celis_adapter_DC_To_AC/HARDWARE/CDZ/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

59
.vscode/settings.json vendored
View File

@ -1,59 +0,0 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

1150
APPLICATION/MM/hashmap.c Normal file

File diff suppressed because it is too large Load Diff

53
APPLICATION/MM/hashmap.h Normal file
View File

@ -0,0 +1,53 @@
// Copyright 2020 Joshua J Baker. All rights reserved.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
#ifndef HASHMAP_H
#define HASHMAP_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
struct hashmap;
struct hashmap *hashmap_new(size_t elsize, size_t cap, uint64_t seed0,
uint64_t seed1,
uint64_t (*hash)(const void *item, uint64_t seed0, uint64_t seed1),
int (*compare)(const void *a, const void *b, void *udata),
void (*elfree)(void *item),
void *udata);
struct hashmap *hashmap_new_with_allocator(void *(*malloc)(size_t),
void *(*realloc)(void *, size_t), void (*free)(void*), size_t elsize,
size_t cap, uint64_t seed0, uint64_t seed1,
uint64_t (*hash)(const void *item, uint64_t seed0, uint64_t seed1),
int (*compare)(const void *a, const void *b, void *udata),
void (*elfree)(void *item),
void *udata);
void hashmap_free(struct hashmap *map);
void hashmap_clear(struct hashmap *map, bool update_cap);
size_t hashmap_count(struct hashmap *map);
bool hashmap_oom(struct hashmap *map);
const void *hashmap_get(struct hashmap *map, const void *item);
const void *hashmap_set(struct hashmap *map, const void *item);
const void *hashmap_delete(struct hashmap *map, const void *item);
const void *hashmap_probe(struct hashmap *map, uint64_t position);
bool hashmap_scan(struct hashmap *map, bool (*iter)(const void *item, void *udata), void *udata);
bool hashmap_iter(struct hashmap *map, size_t *i, void **item);
uint64_t hashmap_sip(const void *data, size_t len, uint64_t seed0, uint64_t seed1);
uint64_t hashmap_murmur(const void *data, size_t len, uint64_t seed0, uint64_t seed1);
uint64_t hashmap_xxhash3(const void *data, size_t len, uint64_t seed0, uint64_t seed1);
const void *hashmap_get_with_hash(struct hashmap *map, const void *key, uint64_t hash);
const void *hashmap_delete_with_hash(struct hashmap *map, const void *key, uint64_t hash);
const void *hashmap_set_with_hash(struct hashmap *map, const void *item, uint64_t hash);
void hashmap_set_grow_by_power(struct hashmap *map, size_t power);
// DEPRECATED: use `hashmap_new_with_allocator`
void hashmap_set_allocator(void *(*malloc)(size_t), void (*free)(void*));
#endif

View File

@ -453,9 +453,24 @@ void vPortGetHeapStats( HeapStats_t * pxHeapStats )
/*-----------------------------------------------------------*/
/*-----------------------------------------------------------*/
void* myRealloc(void* ptr, size_t newSize) {
void* newPtr = pvPortMalloc(newSize);
if (newPtr != NULL) {
// 复制旧内存的数据到新内存
size_t copySize = newSize; // 这里可以根据需要进行调整
memcpy(newPtr, ptr, copySize);
// 释放旧的内存
vPortFree(ptr);
}
return newPtr;
}
/*-----------------------------------------------------------*/

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Doc/A40U36.bin Normal file

Binary file not shown.

BIN
Doc/ChargeBuildBin.exe Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 KiB

BIN
Doc/报文发送机制.eddx Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
HARDWARE/CELIS/Task_1MS.c Normal file

Binary file not shown.

BIN
HARDWARE/CELIS/Task_1MS.h Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

2097
OBJ/LED.s19 Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

BIN
README.md

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,173 @@
#include "24cxx.h"
#include "bsp_i2c_gpio.h"
#include "led.h"
//初始化IIC
void ee_Init(void)
{
bsp_InitI2C();
}
//在AT24CXX指定地址读取一个数据
//ReadAddr :开始读数的地址
//返回值 :读取到的数据
u8 ee_ReadOneByte(u16 ReadAddr)
{
u8 temp = 0;
IIC_Start();
if (EE_TYPE > AT24C16) {
IIC_Send_Byte(EE_DEV_ADDR|EEPROM_I2C_WR);//发送写命令
IIC_Wait_Ack();
IIC_Send_Byte(ReadAddr / 256); //发送高地址
} else IIC_Send_Byte(EE_DEV_ADDR|EEPROM_I2C_WR + ((ReadAddr / 256) << 1)); //发送器件地址0xA0,写数据
IIC_Wait_Ack();
IIC_Send_Byte(ReadAddr % 256); //发送低地址
IIC_Wait_Ack();
IIC_Start();
if (1)IIC_Send_Byte(EE_DEV_ADDR|EEPROM_I2C_RD); //进入接收模式
else IIC_Send_Byte(EE_DEV_ADDR|EEPROM_I2C_RD + ((ReadAddr / 256) << 1)); //进入接收模式
IIC_Wait_Ack();
temp = IIC_Read_Byte(1);
IIC_Stop();//产生一个停止条件
return temp;
}
//在AT24CXX指定地址写一个数据
//WriteAddr:写入数据的目的地址
//data :要写入的数据
void ee_WriteOneByte(u16 WriteAddr, u8 data)
{
IIC_Start();
if (EE_TYPE > AT24C16) {
IIC_Send_Byte(EE_DEV_ADDR|EEPROM_I2C_WR);
IIC_Wait_Ack();
IIC_Send_Byte(WriteAddr / 256); //发送高地址
} else IIC_Send_Byte(EE_DEV_ADDR|EEPROM_I2C_WR + ((WriteAddr / 256) << 1));
IIC_Wait_Ack();
IIC_Send_Byte(WriteAddr % 256); //发送低地址
IIC_Wait_Ack();
IIC_Send_Byte(data);
IIC_Wait_Ack();
IIC_Stop();//产生一个停止条件
Delay_MS(6);
}
#if 1
//向EEPROM写入多个字节
uint8_t ee_WriteBytes(uint8_t *_pWriteBuf, uint16_t _usAddress, uint16_t _usSize)
{
uint16_t i, m;
uint16_t addr;
addr = _usAddress;
for (i = 0; i < _usSize; i++) {
//当第一次或者地址对齐到8就要重新发起起始信号和EEPROM地址
//为了解决8地址对齐问题
if (i == 0 || (addr % EE_PAGE_SIZE) == 0) {
if (i != 0) {
IIC_Stop();
Delay_MS(6);
}
//发送起始地址
IIC_Start();
//发送设备写地址
if (EE_TYPE > AT24C16) {
IIC_Send_Byte(EE_DEV_ADDR|EEPROM_I2C_WR);
if (IIC_Wait_Ack() != 0) {
goto cmd_fail;
}
IIC_Send_Byte(addr / 256); //发送高地址
} else IIC_Send_Byte((EE_DEV_ADDR + ((addr / 256) << 1)) | EEPROM_I2C_WR);
//等待从机应答
if (IIC_Wait_Ack() != 0) {
goto cmd_fail;
}
//EEPROM应答后发送EEPROM的内部存储器地址
IIC_Send_Byte((uint8_t)addr);
//等待从机应答
if (IIC_Wait_Ack() != 0) {
goto cmd_fail;
}
}
//发送数据
IIC_Send_Byte(_pWriteBuf[i]);
//等待应答
if (IIC_Wait_Ack() != 0) {
goto cmd_fail;
}
//写入地址加1
addr++;
}
IIC_Stop();
return 1;
cmd_fail:
IIC_Stop();
return 0;
}
uint8_t ee_ReadBytes(uint8_t *_pReadBuf, uint16_t _usAddress, uint16_t _usSize)
{
uint16_t i;
//发送起始地址
IIC_Start();
//发送设备写地址
if (EE_TYPE > AT24C16) {
IIC_Send_Byte(EE_DEV_ADDR);
if (IIC_Wait_Ack() != 0) {
goto cmd_fail;
}
IIC_Send_Byte(_usAddress / 256); //发送高地址
} else IIC_Send_Byte((EE_DEV_ADDR + ((_usAddress / 256) << 1)) | EEPROM_I2C_WR);
if (IIC_Wait_Ack() != 0) {
goto cmd_fail;
}
IIC_Send_Byte((uint8_t)_usAddress);
if (IIC_Wait_Ack() != 0) {
goto cmd_fail;
}
IIC_Start();
if (EE_TYPE > AT24C16) IIC_Send_Byte(EE_DEV_ADDR | EEPROM_I2C_RD);
else IIC_Send_Byte((EE_DEV_ADDR + ((_usAddress / 256) << 1)) | EEPROM_I2C_RD);
if (IIC_Wait_Ack() != 0) {
goto cmd_fail;
}
for (i = 0; i < _usSize; i++) {
/* 每读完1个字节后需要发送Ack 最后一个字节不需要Ack发Nack */
_pReadBuf[i] = IIC_Read_Byte(i != _usSize - 1?1:0);
}
IIC_Stop();
return 1;
cmd_fail:
IIC_Stop();
return 0;
}
#endif
#if 0
static void IIC1_Start(void); //发送起始信号
static void IIC1_Stop(void); //发送停止信号
static void IIC1_Write_Byte(u8 dat);//发送一个字节
@ -11,9 +178,9 @@ static void IIC1_NAck(void);//
void I2C_delay(uint16_t n)
{
u8 i = 5*n; //这里可以优化速度 经测试最低到5还能写入
while(i)
{
u8 i = 100 * n; //这里可以优化速度 经测试最低到5还能写入
while (i) {
i--;
}
}
@ -26,7 +193,7 @@ void AT24cxx_init(void)
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10|GPIO_Pin_11;//SDA,SCL
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;//GPIO_Mode_Out_OD;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
IIC_SDA1;
@ -41,13 +208,13 @@ u8 AT24cxx_ReadOneByte(u16 ReadAddr)
{
u8 temp=0;
IIC1_Start();
if(EE_TYPE>AT24C16)
{
if (EE_TYPE > AT24C16) {
IIC1_Write_Byte(0xa0);//发送写命令
IIC1_Wait_Ack();
IIC1_Write_Byte(ReadAddr/256);//发送高地址
}
else IIC1_Write_Byte(0xa0+((ReadAddr/256)<<1));//发送器件地址0xA0,写数据
} else IIC1_Write_Byte(0xa0 + ((ReadAddr / 256) << 1)); //发送器件地址0xA0,写数据
IIC1_Wait_Ack();
IIC1_Write_Byte(ReadAddr%256);//发送低地址
IIC1_Wait_Ack();
@ -65,13 +232,13 @@ u8 AT24cxx_ReadOneByte(u16 ReadAddr)
void AT24cxx_WriteOneByte(u16 WriteAddr,u8 data)
{
IIC1_Start();
if(EE_TYPE>AT24C16)
{
if (EE_TYPE > AT24C16) {
IIC1_Write_Byte(0xa0);
IIC1_Wait_Ack();
IIC1_Write_Byte(WriteAddr/256);//发送高地址
}
else IIC1_Write_Byte(0xa0+((WriteAddr/256)<<1));
} else IIC1_Write_Byte(0xa0 + ((WriteAddr / 256) << 1));
IIC1_Wait_Ack();
IIC1_Write_Byte(WriteAddr%256);//发送低地址
IIC1_Wait_Ack();
@ -88,8 +255,8 @@ void AT24cxx_WriteOneByte(u16 WriteAddr,u8 data)
void AT24cxx_WriteLenByte(u16 WriteAddr,u32 data,u8 len)
{
u8 i;
for(i=0;i<len;i++)
{
for (i = 0; i < len; i++) {
AT24cxx_WriteOneByte(WriteAddr+i,(data>>(8*i))&0xff);
}
}
@ -102,8 +269,8 @@ u32 AT24cxx_ReadLenByte(u16 ReadAddr,u8 len)
{
u8 i;
u32 temp=0;
for(i=0;i<len;i++)
{
for (i = 0; i < len; i++) {
temp<<=8;
temp+=AT24cxx_ReadOneByte(ReadAddr+len-i-1);
}
@ -118,8 +285,8 @@ u32 AT24cxx_ReadLenByte(u16 ReadAddr,u8 len)
void AT24cxx_Write(u16 WriteAddr,u8 *buf,u16 len)
{
u16 i;
for(i=0;i<len;i++)
{
for (i = 0; i < len; i++) {
IWDG_Feed();
AT24cxx_WriteOneByte(WriteAddr,*buf);
WriteAddr++;
@ -133,8 +300,7 @@ void AT24cxx_Write(u16 WriteAddr,u8 *buf,u16 len)
//buf :数据数组首地址
void AT24cxx_Read(u16 ReadAddr,u8 *buf,u16 len)
{
while(len--)
{
while (len--) {
IWDG_Feed();
*buf++=AT24cxx_ReadOneByte(ReadAddr++);
}
@ -150,8 +316,7 @@ u8 AT24cxx_Check(void)
temp1=AT24cxx_ReadOneByte(0x010);//避免每次开机都写AT24CXX
temp2=temp1;
if(temp2==0x55)return 0;
else
{
else {
AT24cxx_WriteOneByte(0x010,0x55);
temp1=AT24cxx_ReadOneByte(0x010);
temp2=temp1;
@ -194,11 +359,11 @@ static u8 IIC1_Wait_Ack(void)
I2C_delay(2);
IIC_SCL1;
I2C_delay(2);
while(Read_IIC_SDA())
{
while (Read_IIC_SDA()) {
i++;
if(i>250)
{
if (i > 250) {
IIC1_Stop();
return 1;
@ -239,15 +404,13 @@ void IIC1_Write_Byte(u8 dat)
u8 t;
SDA_OUT();
I2C_delay(2);
for(t=0;t<8;t++)
{
for (t = 0; t < 8; t++) {
IIC_SCL0;
if(dat&0x80)
{
if (dat & 0x80) {
IIC_SDA1;
}
else
{
} else {
IIC_SDA0;
}
I2C_delay(2);
@ -266,8 +429,8 @@ u8 IIC1_Read_Byte(unsigned char ack)
SDA_IN();//SDA设为输入
IIC_SDA0;
I2C_delay(2);
for(i=0;i<8;i++)
{
for (i = 0; i < 8; i++) {
IIC_SCL0;
I2C_delay(2);
IIC_SCL1;
@ -286,4 +449,4 @@ u8 IIC1_Read_Byte(unsigned char ack)
IIC1_NAck();
return receive;
}
#endif

View File

@ -13,17 +13,58 @@
#define AT24C128 16383
#define AT24C256 32767
#define EE_TYPE AT24C02 //使用的是AT24C16
#define EE_TYPE AT24C32 //使用的是AT24C16
#define EE_DEV_ADDR 0xA0
void AT24cxx_init(void);//初试化IIC
u8 AT24cxx_ReadOneByte(u16 ReadAddr);//指定地址读取一个字节
void AT24cxx_WriteOneByte(u16 WriteAddr,u8 data);//指定地址写一个数据
void AT24cxx_WriteLenByte(u16 WriteAddr,u32 data,u8 len);//在指定地址开始写入指定长度的数据
u32 AT24cxx_ReadLenByte(u16 ReadAddr,u8 len);//在指定地址开始读出指定长度的数据
void AT24cxx_Write(u16 WriteAddr,u8 *buf,u16 len);//在指定地址开始写入指定长度的数据
void AT24cxx_Read(u16 ReadAddr,u8 *buf,u16 len);//在指定地址开始读出指定长度的数据
u8 AT24cxx_Check(void);//检查器件
#if EE_TYPE == AT24C01
#define EE_PAGE_SIZE 8 //字节/页
#define EE_SIZE 0x007F //eeprom的总容量
#elif EE_TYPE == AT24C02
#define EE_PAGE_SIZE 16
#define EE_SIZE 0x00FF
#elif EE_TYPE == AT24C04
#define EE_PAGE_SIZE 16
#define EE_SIZE 0x01FF
#elif EE_TYPE == AT24C08
#define EE_PAGE_SIZE 16
#define EE_SIZE 0x03FF
#elif EE_TYPE == AT24C16
#define EE_PAGE_SIZE 16
#define EE_SIZE 0x07FF
#elif EE_TYPE == AT24C32
#define EE_PAGE_SIZE 32
#define EE_SIZE 0x0FFF
#elif EE_TYPE == AT24C64
#define EE_PAGE_SIZE 32
#define EE_SIZE 0x1FFF
#elif EE_TYPE == AT24C128
#define EE_PAGE_SIZE 64
#define EE_SIZE 0x3FFF
#elif EE_TYPE == AT24C256
#define EE_PAGE_SIZE 64
#define EE_SIZE 0x7FFF
#elif EE_TYPE == AT24C512
#define EE_PAGE_SIZE 128
#define EE_SIZE 0xFFFF
#endif
#define EEPROM_I2C_WR 0 /* 写控制bit */
#define EEPROM_I2C_RD 1 /* 读控制bit */
// void AT24cxx_init(void);//初试化IIC
// u8 AT24cxx_ReadOneByte(u16 ReadAddr);//指定地址读取一个字节
// void AT24cxx_WriteOneByte(u16 WriteAddr,u8 data);//指定地址写一个数据
// void AT24cxx_WriteLenByte(u16 WriteAddr,u32 data,u8 len);//在指定地址开始写入指定长度的数据
// u32 AT24cxx_ReadLenByte(u16 ReadAddr,u8 len);//在指定地址开始读出指定长度的数据
// void AT24cxx_Write(u16 WriteAddr,u8 *buf,u16 len);//在指定地址开始写入指定长度的数据
// void AT24cxx_Read(u16 ReadAddr,u8 *buf,u16 len);//在指定地址开始读出指定长度的数据
// u8 AT24cxx_Check(void);//检查器件
void ee_Init(void);
u8 ee_ReadOneByte(u16 ReadAddr);
void ee_WriteOneByte(u16 WriteAddr, u8 data);
uint8_t ee_WriteBytes(uint8_t *_pWriteBuf, uint16_t _usAddress, uint16_t _usSize);
uint8_t ee_ReadBytes(uint8_t *_pReadBuf, uint16_t _usAddress, uint16_t _usSize);
/* 定义I2C总线连接的GPIO端口, 用户只需要修改下面4行代码即可任意改变SCL和SDA的引脚 */
//IO方向设置
@ -32,17 +73,17 @@ u8 AT24cxx_Check(void);//
//IO操作设置
#define IIC_SDA0 GPIOB->BRR=GPIO_Pin_11;//sda=0
#define IIC_SDA1 GPIOB->BSRR=GPIO_Pin_11;//sda=1
#define IIC_SCL0 GPIOB->BRR=GPIO_Pin_10;
#define IIC_SCL1 GPIOB->BSRR=GPIO_Pin_10;
// #define IIC_SDA0 GPIOB->BRR=GPIO_Pin_11;//sda=0
// #define IIC_SDA1 GPIOB->BSRR=GPIO_Pin_11;//sda=1
// #define IIC_SCL0 GPIOB->BRR=GPIO_Pin_10;
// #define IIC_SCL1 GPIOB->BSRR=GPIO_Pin_10;
#define Read_IIC_SDA() ((GPIOB->IDR&GPIO_Pin_11)!=0)?1:0 //判断接收到的位
// #define Read_IIC_SDA() ((GPIOB->IDR&GPIO_Pin_11)!=0)?1:0 //判断接收到的位
//IIC所有操作函数
void IIC_Init(void);// 初始化iic的所有IO口
// void IIC_Init(void);// 初始化iic的所有IO口
//void IIC_Start(void); //发送起始信号
//void IIC_Stop(void); //发送停止信号
//void IIC_Write_Byte(u8 dat);//发送一个字节

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -34,13 +34,13 @@
#define RCC_I2C_PORT RCC_APB2Periph_GPIOB /* GPIO端口时钟 */
#define PORT_I2C_SCL GPIOB /* GPIO端口 */
#define PIN_I2C_SCL GPIO_Pin_6 /* GPIO引脚 */
#define PIN_I2C_SCL GPIO_Pin_10 /* GPIO引脚 */
#define PORT_I2C_SDA GPIOB /* GPIO端口 */
#define PIN_I2C_SDA GPIO_Pin_7 /* GPIO引脚 */
#define PIN_I2C_SDA GPIO_Pin_11 /* GPIO引脚 */
#define I2C_SCL_PIN GPIO_Pin_6 /* 连接到SCL时钟线的GPIO */
#define I2C_SDA_PIN GPIO_Pin_7 /* 连接到SDA数据线的GPIO */
#define I2C_SCL_PIN GPIO_Pin_10 /* 连接到SCL时钟线的GPIO */
#define I2C_SDA_PIN GPIO_Pin_11 /* 连接到SDA数据线的GPIO */
/* 定义读写SCL和SDA的宏 */
#define I2C_SCL_1() PORT_I2C_SCL->BSRR = I2C_SCL_PIN /* SCL = 1 */
@ -78,7 +78,16 @@ void bsp_InitI2C(void)
/* 给一个停止信号, 复位I2C总线上的所有设备到待机模式 */
// IIC_Stop();
GPIO_SetBits(GPIOB,GPIO_Pin_6|GPIO_Pin_7); //PB6,PB7 ???
GPIO_SetBits(PORT_I2C_SCL,PIN_I2C_SCL); //PB6,PB7 ???
GPIO_SetBits(PORT_I2C_SDA,PIN_I2C_SDA);
//???
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;//A SCL SDA
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
// GPIO_Init(GPIOB, &GPIO_InitStructure);
// GPIO_SetBits(GPIOB,GPIO_Pin_6|GPIO_Pin_7); //PB6,PB7 ???
}
/*

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

190
UDS/bootloader.c Normal file
View File

@ -0,0 +1,190 @@
#include "bootloader.h"
#if BOOTLOADER_CODE_FLAG
#include "stm32f10x_flash.h"
const uint8_t BootloaderSwVersion[] = BOOTLOADER_SOFTWARE_VERSION;
#endif
uint8_t updataflag = false;
uint8_t Checksum(uint32_t address, uint32_t length)
{
//uint32_t checksum = 0;
return 1;
}
typedef void (*pFunction)(void);
static pFunction Jump_To_Application;
static uint32_t JumpAddress = 0;
void BootloaderInit(void)
{
}
void JumpToApplicationSW(void)
{
#if BOOTLOADER_CODE_FLAG
__disable_irq();//关全局中断
if (IsExternProgrammingRequestValid()) {
updataflag = true;
ClearExternProgrammingRequest();
} else if (((*(__IO uint32_t *)APP_FlashBaseAddress) & 0x2FFE0000) == MCU_RAM_StartAddress) {
SetBootloaderSwVersionAddress();
JumpAddress = *(__IO uint32_t *)(APP_FlashBaseAddress + 4);
Jump_To_Application = (pFunction) JumpAddress;
__set_MSP(*(__IO uint32_t *) APP_FlashBaseAddress);
Jump_To_Application();
}
__enable_irq();
#endif
}
#if BOOTLOADER_CODE_FLAG
void RAMFLASHInit(void)
{
}
status_t EraseApplicationSoftwareCode(uint32_t address, uint32_t length)
{
status_t ret = STATUS_SUCCESS;
uint32_t page_address = 0;
if (address % FMC_PAGE_SIZE) {
return STATUS_ERROR;
}
FLASH_Unlock();
/* 清空所有标志位 */
FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
page_address = address;
while(page_address < address+length)
{
if(FLASH_COMPLETE != FLASH_ErasePage(page_address))
{
ret = STATUS_ERROR;
break;
}
page_address += FMC_PAGE_SIZE;
}
FLASH_Lock();
return ret;
}
status_t ProgramApplicationSoftware(uint32_t address, uint8_t *pdata, uint32_t length)
{
status_t ret = STATUS_SUCCESS;
uint32_t program_address = 0;
FLASH_Unlock();
/* 清空所有标志位 */
FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
/* Program Flash Bank1 */
program_address = address;
while(program_address < (address + length))
{
FLASH_ProgramWord(program_address, *(uint32_t *)pdata);
if (*(uint32_t*)program_address != *(uint32_t*)pdata)
{
ret = STATUS_ERROR; // 读出校验
break;
}
program_address += 4;
pdata += 4;
}
FLASH_Lock();
return ret;
}
#endif
uint8_t GetUdsUpdataFlag(void)
{
if (updataflag) {
updataflag = 0;
return 1;
}
return 0;
}
void ClearExternProgrammingRequest(void)
{
BKP->DR39 = 0x00;
BKP->DR40 = 0x00;
}
void SetExternProgrammingRequest(void)
{
BKP->DR39 = (uint16_t)(BOOTLOADER_PROGRAMMING_FLAG >> 0);
BKP->DR40 = (uint16_t)(BOOTLOADER_PROGRAMMING_FLAG >> 16);
}
bool IsExternProgrammingRequestValid(void)
{
bool status = false;
uint32_t flag;
flag = BKP->DR40;
flag = (flag << 16) | BKP->DR39;
if (flag == BOOTLOADER_PROGRAMMING_FLAG) {
status = true;
}
return status;
}
#if BOOTLOADER_CODE_FLAG
void SetBootloaderSwVersionAddress(void)
{
BKP->DR41 = (uint16_t)((uint32_t)BootloaderSwVersion >> 0);
BKP->DR42 = (uint16_t)((uint32_t)BootloaderSwVersion >> 16);
}
#endif
uint32_t GetBootloaderSwVersionAddress(void)
{
static uint32_t bl_sw_addr;
bl_sw_addr = BKP->DR42;
bl_sw_addr = (bl_sw_addr << 16) | BKP->DR41;
return bl_sw_addr;
}

39
UDS/bootloader.h Normal file
View File

@ -0,0 +1,39 @@
#ifndef __BOOTLOADER_H__
#define __BOOTLOADER_H__
#include "uds_config.h"
#define BOOTLOADER_PROGRAMMING_FLAG 0xAA55BA5C
#define BOOT_FlashBaseAddress 0x08000000 //FBL Й雄測鎢
#define APP_FlashBaseAddress 0x08008000 //APP お宎華硊
#define APP_FlagAddress (APP_FlashBaseAddress+0x4000) //APP梓祩弇華硊
typedef enum
{
/* Generic error codes */
STATUS_SUCCESS = 0x000U, /*!< Generic operation success status */
STATUS_ERROR = 0x001U, /*!< Generic operation failure status */
STATUS_BUSY = 0x002U, /*!< Generic operation busy status */
STATUS_TIMEOUT = 0x003U, /*!< Generic operation timeout status */
} status_t;
extern void JumpToApplicationSW(void);
extern status_t EraseApplicationSoftwareCode(uint32_t address, uint32_t length);
extern status_t ProgramApplicationSoftware(uint32_t address, uint8_t *pdata, uint32_t length);
extern void BootloaderInit(void);
extern uint8_t GetUdsUpdataFlag(void);
void ClearExternProgrammingRequest(void);
void SetExternProgrammingRequest(void);
void SetBootloaderSwVersionAddress(void);
uint32_t GetBootloaderSwVersionAddress(void);
bool IsExternProgrammingRequestValid(void);
#endif

97
UDS/crc.c Normal file
View File

@ -0,0 +1,97 @@
#include "crc.h"
const unsigned short crc16tab[256] = {
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
};
/* Calculate checksum */
void CalcCheckSum(uint32_t *sum, uint8_t *data, uint32_t size)
{
int i;
for(i=0;i<size;i++)
{
*sum = *sum + data[i];
}
}
void CRC16_CCITT_1021_Init(uint16_t *crc)
{
*crc = 0xffff; /* initial value */
}
//Polynomial 1021,CRC16_CCITT ²é±í
void CRC16_CCITT_1021_Update(uint16_t *crc, uint8_t *pData ,uint32_t len)
{
int tmp;
int i;
for(i=0;i<len;i++) {
tmp=(*crc>>8)^pData[i];
*crc=(*crc<<8)^crc16tab[tmp];
}
}
uint32_t CRC_Cal16_WithCfg( const uint8_t *pData, uint32_t size)
{
uint8_t cnt,temp;
uint16_t crc=0xFFFF;
uint16_t poly=0x8005;
while(size)
{
size--;
temp = * pData++;
crc ^=temp<<8;
for( cnt=0; cnt<8; cnt++ )
{
if(crc &0x8000){crc<<=1; crc^=poly;}
else crc<<=1;
}
}
return crc;
}
uint32_t CRC16_DataCheck( const u8 *pData, u32 size )
{
uint32_t CRCData;
uint32_t CRC16;
//polynome 0x8005
CRC16 = CRC_Cal16_WithCfg((u8*)pData, size);
CRCData = (u16)(pData[size+1]<<8)|pData[size];
return (CRCData^CRC16);
}

17
UDS/crc.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef _CRC_H
#define _CRC_H
#include "sys.h"
uint32_t crc32( uint8_t *buf, int len); //crc32 ʵÏÖº¯Êý
uint32_t crc32MultSegment( uint8_t *seg1, int len1, uint8_t *seg2, int len2);
void CalcCheckSum(uint32_t *sum, uint8_t *data, uint32_t size);
void CRC16_CCITT_1021_Init(uint16_t *crc);
void CRC16_CCITT_1021_Update(uint16_t *crc, uint8_t *pData ,uint32_t len);
uint32_t CRC16_DataCheck( const u8 *pData, u32 size );
uint32_t CRC_Cal16_WithCfg( const uint8_t *pData, uint32_t size);
#endif

1398
UDS/diagnosis_mid.c Normal file

File diff suppressed because it is too large Load Diff

142
UDS/diagnosis_mid.h Normal file
View File

@ -0,0 +1,142 @@
#ifndef __DIAGNOSIS_MID_H__
#define __DIAGNOSIS_MID_H__
#include "uds_config.h"
#pragma anon_unions
#define PROGRAMMING_PASS_TIMEOUT_TIME 500 //5s base:10ms
#define OTA_TIMEOUT_TIME (6) //30min base:5min
/*
INPUT_OVERVOLTAGE) \
INPUT_UNDERVOLTAGE) \
CHARGE_TEMP_DERATE) \
INTER_TEMP_DERATE) \
INTER_OVERTEMP) \
CHARGE_OVERTEMP) \
DC_POS_RELAY_ADH) \
DC_NEG_RELAY_ADH) \
AC_POS_RELAY_ADH) \
AC_NEG_RELAY_ADH) \
HV_INTERLOCK) \
CC_CC2_RELAY_CTRL_INV) \
CP_CC1_RELAY_CTRL_INV) \
DCU_VOL_ABN)
*/
//车身信息给到uds
typedef struct {
uint8_t IgnSts : 1; //ign状态 0:OFF 1:ON
uint8_t BattLow : 1; //电瓶低压
uint8_t BattHigh : 1; //电瓶高压
uint8_t Limphome : 1; //
uint8_t InOverVoltFault : 1; //输入过压故障 0:正常 1:故障
uint8_t InUnderVoltFault : 1; //输入欠压故障 0:正常 1:故障
uint8_t ChargeTempDerateFault : 1; //充电座温度降额故障 0:正常 1:故障
uint8_t InterTempDerateFault : 1; //内部温度降额故障 0:正常 1:故障
uint8_t InterOverTempFault : 1; //内部温度过温故障 0:正常 1:故障
uint8_t ChargeOverTempFault : 1; //充电座过温故障 0:正常 1:故障
uint8_t DcPosRelayAdhFault : 1; //直流正极继电器粘连 0:正常 1:故障
uint8_t DcNegRelayAdhFault : 1; //直流负极继电器粘连 0:正常 1:故障
uint8_t AcPosRelayAdhFault : 1; //交流正极继电器粘连 0:正常 1:故障
uint8_t AcNegRelayAdhFault : 1; //交流负极继电器粘连 0:正常 1:故障
uint8_t HvInterlockFault : 1; //高压互锁故障 0:正常 1:故障
uint8_t CcCc2RelayCtrlInv : 1; //CC/CC2控制继电器控制失效 0:正常 1:故障
uint8_t CpCc1RelayCtrlInv : 1; //CC/CC2控制继电器控制失效 0:正常 1:故障
uint16_t CurrDcVolt; //当前直流电压 0.1V
uint8_t ChargeTemp; //充电座温度值 °C
uint8_t BoardTemp; //板载温度值 °C
// uint8_t OtaModeSts; //OTA 模式状态 0:not in ota 1:in transition ota 2:in ota
uint8_t BusoffCnt; //busoff计数器进入busoff后每恢复一次就累加1。CAN总线正常后退出busoff就清零。
DTC_SnapshotType Snapshot;
}VehicleInfo2UdsType;
typedef struct {
uint8_t NcmRxEnable : 1;
uint8_t NcmTxEnable : 1;
uint8_t NmcmRxEnable : 1;
uint8_t NmcmTxEnable : 1;
uint8_t UdsOffLine : 1;
uint8_t EcuConfig;
uint8_t DCDCEnable; //0x00:ENABLE 0x01:DISABLE
uint8_t ChargeTempProtVal; //充电座温度保护值 °C 偏移-40
uint8_t BoardTempProtVal; //板载温度保护值 °C 偏移-40
uint16_t DCVoltProtVal; //直流电压保护值 0.1V
uint16_t InsulDetVoltVal; // 绝缘检测电压 0.1V
uint8_t DTCNum; //DTC个数
uint8_t DTCList[DTC_ID_NUM];
uint8_t OtaModeSts; //OTA 模式状态 0:not in ota 1:in transition ota 2:in ota
}UdsInfo2VehicleType;
extern VehicleInfo2UdsType vehicleInfo2uds;
extern UdsInfo2VehicleType udsInfo2Vehicle;
extern INT32U g_ulRand;
extern uint32_t g_ulCanStatus;
extern uint8_t UdsSelfCheckFlag;
extern uint8_t UdsCalibrationFlag;
extern uint8_t EraseFlashMemory(uint32_t addr,uint32_t length);
extern uint8_t EraseEepromMemory(uint32_t addr,uint32_t length);
extern void GenRand(void);
extern INT8U Get0x19SerDiagData(INT8U *pOut,INT8U Type,INT8U *pdata);
extern INT16U Get0x22SerDiagData(INT8U *pOut);
extern INT8U Set0x2EDidDiagData(INT8U *pIn,INT16U PLen);
extern void SaveDtcRecode(INT16U Addr,INT32U DtcCode,INT8U Status,INT8U Acccnt);
extern void CheckDtcHsCanError(void);
extern void UdsQueueCanOut(void);
extern uint8_t GenerateSID27SeedValue(uint8_t *seed);
extern uint8_t GenerateSID27KeyValue(uint8_t levelType,uint8_t *seed,uint8_t *key);
extern INT8U Set0x2FDiagData(INT8U *pIn,INT16U PLen,INT8U *pOut,INT16U *RLen);
extern INT8U Set0x31DiagData(INT8U *pIn,INT16U PLen,INT8U *pOut,INT16U *RLen);
extern INT8U Set0x36DiagData(INT8U *pIn,INT16U PLen,INT8U *pOut,INT16U *RLen);
extern uint8_t EE_Write(uint8_t *pImage, const uint8_t *pData, uint32_t Len, void (*pCbFn)(uint32_t));
extern uint8_t EE_Read(uint8_t *pImage, uint8_t **pData);
extern void SetUdsUpdataFlag(void);
extern void DTC_SignalRecover(void);
extern uint8_t ClearCurrentDTCData(uint8_t i);
extern void ClearDtc(void);
extern void IO_InputOutputRelease(void);
extern void Uds_SetMsgMonitorTimer(uint16_t msgid);
extern void SnapshotRecordNumberGet(DTC_RecordDataBufType *record_data, uint16_t *dataBuf, uint8_t *num);
extern void UdsEncryptDate_Crc32Cal_Init(void);
extern void UdsEncryptDate_Crc32Cal_Update(const u8 *pData, u32 size);
extern uint32_t UdsEncryptDate_Crc32Cal_Final(void);
extern uint16_t UdsEncryptDate_Decrypt(uint8_t *src,uint16_t size_src);
extern void UdsEncryptDate_Xor(uint8_t *src,uint16_t size_src);
bool CheckVechileStatus(void);
bool CheckIsBatteryLow(void);
bool CheckIsBatteryHigh(void);
bool CheckIsIgnON(void);
bool CheckIsIgnOff2ON(void);
bool CheckIsTurnLeft_Short2Gnd(void);
bool CheckIsTurnLeft_Openload(void);
bool CheckIsTurnLeft_Normal(void);
bool CheckIsTurnRight_Short2Gnd(void);
bool CheckIsTurnRight_Openload(void);
bool CheckIsTurnRight_Normal(void);
bool CheckIsDRL_Short2Gnd(void);
bool CheckIsDRL_Openload(void);
bool CheckIsDRL_Normal(void);
bool CheckIsPosition_Short2Gnd(void);
bool CheckIsPosition_Openload(void);
bool CheckIsPosition_Normal(void);
bool CheckIsCanBusoff(void);
bool CheckIsNM_Limphome(void);
bool CheckIsFobUnlearn(void);
bool CheckIsVinUnwrite(void);
#endif

127
UDS/tp_15765_2.h Normal file
View File

@ -0,0 +1,127 @@
#ifndef TP_15765_2_H
#define TP_15765_2_H
/*!
* @file tp_15765_2.h
* @brief TP layer file according to the 15765-2.
*
*/
#include "uds_types.h"
#define FRAME_TYPE_MASK 0xF0 /*!< FRAME TYPE MASK */
#define FLOW_STATUS_MASK 0x0F /*!< FLOW STATUS MASK */
#define SEQUENCE_NUMBER_MASK 0x0F /*!< SEQUENCE NUMBER MASK */
#define SINGLE_FRAME_DATA_LENGTH_MASK 0x0F /*!< SINGLE FRAME DATA LENGTH MASK */
#define FIRST_FRAME_DATA_LENGTH_MSB_NIBBLE_MASK 0x0F /*!< FIRST FRAME DATA LENGTH MSB NIBBLE MASK */
#define SEQUENCE_NUMBER_MAX 0x10 /*!< SEQUENCE NUMBER MAX */
#define CAN_FRAME_BYTES_UPPER_RANGE 7 /*!< CAN FRAME BYTES UPPER RANGEK */
#define ZERO_LOOP_COUNT 0 /*!< SEQUENCE NUMBER MASK */
#define ONE_LOOP_COUNT 1 /*!< SEQUENCE NUMBER MASK */
#define TWO_LOOP_COUNT 2 /*!< SEQUENCE NUMBER MASK */
#ifdef RX_MULTI_BUFFER_SUPPORT
#define RECEIVE_MULTI_BUFFER_SUPPORT TRUE
#else
#define RECEIVE_MULTI_BUFFER_SUPPORT FALSE
#endif
/*!
* Enum Type. TP Layer State
*/
typedef enum TPState_Tag
{
TP_Idle_State = 0, /*!< Idle State */
TP_Wait_For_SFORFF_TxConf_State, /*!< Wait for TXConf State */
TP_Wait_For_FCFrame_Rx_State, /*!< Wait for Flow Control State */
TP_Transmit_CF_State, /*!< Transmit CF State */
TP_Wait_For_CF_TxConf_State, /*!< Wait For CF TxConf State */
TP_Wait_For_STmin_State, /*!< Wait For STmin State */
TP_Wait_For_FC_TXconf_State, /*!< Wait For FC_TXconf State */
TP_Rx_CF_State, /*!< Receive CF State */
TP_Wait_For_DataRead_State /*!< Wait For DataRead State */
}TPState_T;
/*!
* Enum Type. Parameters
*/
typedef enum TPParameters_Tag
{
N_BLOCKSIZE = 0,
N_SEPERATIONTIME
}TPParameters_T;
/*!
* Enum Type. Result for change parameter
*/
typedef enum TPResultChangePara_Tag
{
N_OK_R = 0,
N_RX_ON,
N_WRONG_PARAMETER,
N_WRONG_VALUE
}TPResultChangePara_T;
/*!
* Enum Type. Transmit sub state
*/
typedef enum TPTransmitSubState_Tag
{
TP_TX_LOAD_CF_DATA = 0,
TP_TX_LOAD_REMAINING_BYTES_OF_CF,
TP_TX_LOAD_REMAINING_BYTES_OF_LAST_CF
}TPTransmitSubState_T;
/*!
* Enum Type. Receive sub state
*/
typedef enum TPReceiveSubState_Tag
{
TP_RX_UNLOAD_CF_DATA = 0,
TP_RX_UNLOAD_REMAINING_BYTES_OF_CF,
TP_RX_UNLOAD_REMAINING_BYTES_OF_LAST_CF
}TPReceiveSubState_T;
/*!
* Enum Type. Transmit Status
*/
typedef enum TPTransmitStatus_Tag
{
TP_TRANSMIT_IDLE = 0,
TP_TRANSMIT_START,
WAITINGFORFLOWCONTROL
}TPTransmitStatus_T;
/*!
* Enum Type. Receive Status
*/
typedef enum TPReceiveStatus_Tag
{
TP_RECEIVE_IDLE = 0,
TP_RECEIVE_START
}TPReceiveStatus_T;
/*!
* Enum Type. Timer control
*/
typedef enum TPTimerControl_Tag
{
TIMER_STOP = 0,
TIMER_RUN
}TPTimerControl_T;
/*!
* Enum Type. Flow control
*/
typedef enum TPFlowControlStatus_Tag
{
CLEAR_TO_SEND = 0,
WAIT,
OVERFLOW,
RESERVED
}TPFlowControlStatus_T;
/*!
* Enum Type. Buffer Status
*/
typedef enum TPBufferStatus_Tag
{
EMPTY = 0,
FILLED
}TPBufferStatus_T;
#endif

1781
UDS/tp_cca.c Normal file

File diff suppressed because it is too large Load Diff

235
UDS/tp_config.h Normal file
View File

@ -0,0 +1,235 @@
#ifndef TP_CONFIG_H
#define TP_CONFIG_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "uds_config.h"
#include "uds_did.h"
#include "uds_dtc.h"
#include "uds_can_interface.h"
#include "diagnosis_mid.h"
#include "tp_15765_2.h"
#include "tp_config.h"
#include "uds_interface.h"
#include "uds_manage.h"
#include "uds_services.h"
#include "uds_types.h"
/*!
* @file tp_config.h
* @brief TP layer file according to the 15765-2.
*
*/
#include "uds_types.h"
// lbin_20190117
#define CALL_RATE_TP 1 /*!< Call rate of the periodic task */
#define N_As_TIME_OUT 70 /*!< default value : max as per standard = 1000msec */
#define N_Ar_TIME_OUT 70 /*!< default value : max as per standard = 1000msec */
#define N_Bs_TIME_OUT 150 /*!< default value : max as per standard = 1000msec */
#define N_Cr_TIME_OUT 150 /*!< default value : max as per standard = 1000msec */
#define N_As_TIMER_COUNT N_As_TIME_OUT/CALL_RATE_TP /*!< As TIMER COUNT*/
#define N_Ar_TIMER_COUNT N_Ar_TIME_OUT/CALL_RATE_TP /*!< Ar TIMER COUNT */
#define N_Bs_TIMER_COUNT N_Bs_TIME_OUT/CALL_RATE_TP /*!< Bs TIMER COUNT */
#define N_Cr_TIMER_COUNT N_Cr_TIME_OUT/CALL_RATE_TP /*!< Cr TIMER COUNT */
#if (BOOTLOADER_CODE_FLAG == 0)
#define TP_RX_BLOCK_SIZE_MAX 0 /*!< default block size for receive. */
#define TP_RX_SEPARATION_TIME_MIN 20 /*!< default STmin for receive. lbin */
#else
#define TP_RX_BLOCK_SIZE_MAX 0 /*!< default block size for receive. */
#define TP_RX_SEPARATION_TIME_MIN 0 /*!< default STmin for receive. lbin */
#endif
#define TP_BUFFER_SIZE 2050//255 /*!< TP buffer(common for both Rx & RX) size */
#define FRAME_DATA_SIZE 8 /*!< Frame buffer size */
/*!
* Macro. Wait frame Transmit support: if 0 no wait frame tx supported
* otherwise configure max wait frame tx count
*/
#define N_WAIT_FRAME_TX_MAX 0
/*!
* Macro. If the Padding is required select as 'TRUE'. Otherwise 'FALSE'
*/
#define PADDING_OPERATION true
/*!
* Macro. Default selected as -xaa; change it to required value
*/
#define PADDING_BYTE 0xCC
/* maximum dlc value for one CAN frame */
/* #define RX_MULTI_BUFFER_SUPPORT */
#define STmin_ZERO CALL_RATE_TP
#define TP_DIAG_PHYSICAL_MSG_SUPPORT
#define TP_DIAG_FUNCTIONAL_MSG_SUPPORT
/*!
* Macro. Max number of bytes
*/
#define NW_DLC_MAX_BYTES 8
/*!
* Macro. number of bytes to represent N_PCI in a sinlge frame
*/
#define SINGLE_FRAME_N_PCI_BYTE 1
/*!
* Macro. maximum number of data bytes in a single frame
*/
#define MAXIMUM_SINGLE_FRAME_DATA_BYTE 7
/*!
* Macro. Two N_PCI + six data bytes in a first frame
*/
#define FIRST_FRAME_N_PCI_PLUS_DATA_BYTE 8
/*!
* Macro. maximum number of data bytes in a consecutive frame
*/
#define CONSECUTIVE_FRAME_N_PCI_BYTE 1
/*!
* Macro. data bytes in a consecutive frame
*/
#define CONSECUTIVE_FRAME_DATA_BYTE 7
/*!
* Macro. One N_PCI + seven data bytes in a consecutive frame
*/
#define CONSECUTIVE_FRAME_N_PCI_PLUS_DATA_BYTE 8
/*!
* Macro. Three N_PCI bytes in a flow control frame
*/
#define FLOW_CONTROL_N_PCI_PLUS_DATA_BYTE 3
/*!
* Enum Type. PCI Type
*/
typedef enum TPN_PCI_Type_Tag
{
SINGLE_FRAME = 0x00, /*!< N_PCI type for single frame */
FIRST_FRAME = 0x10, /*!< N_PCI type for first frame */
CONSECUTIVE_FRAME = 0x20, /*!< N_PCI type for consecutive frame */
FLOW_CONTROL_FRAME = 0x30 /*!< N_PCI type for flow control frame */
}TPN_PCI_Type_T;
/*!
* Enum Type. TP Request Tpye
*/
typedef enum TPRequestTpye_Tag
{
PHYSICAL_ADDRESS_TYPE = 0, /*!< PHYSICAL ADDRESS TYPE */
FUNCTIONAL_ADDRESS_TYPE /*!< FUNCTIONAL ADDRESS TYPE */
}TPRequestTpye_T;
/*!
* Enum Type. TP Result Tpye
*/
typedef enum TPResult_Tag
{
N_OK = 0, /*!< Result OK */
N_TIMEOUT_A, /*!< Timeout A */
N_TIMEOUTBs, /*!< Timeout Bs */
N_TIMEOUTCr, /*!< Timeout Cr */
N_WRONG_SN, /*!< Wrong SN */
N_INVALID_FS, /*!< Invaild FS */
N_UNEXP_PDU, /*!< Unexpected PDU */
N_WFT_OVRN, /*!< WFT Overrun */
N_BUFFER_OVFLW, /*!< Buffer Overflow */
N_WRONG_DLC, /*!< Wrong DLC */
N_ERROR, /*!< ERROR */
TP_BUFFER_OVER_FLOW, /*!< TP Buffer Overflow */
TP_BUFFER_NOT_FILLED, /*!< TP BUFFER not filled */
TP_RX_LENGTH_INVALID /*!< TP Invalid RX Length */
} TPResult_T;
extern bool TpRxFlg;
extern uint16_t TP_Rx_Message_Length; /*!< Receive Message Length */
extern uint16_t TP_Rx_Index;
extern uint8_t TP_Buffer[TP_BUFFER_SIZE]; /*!< TP Buffer */
extern void TP_Init( void );
extern void TP_Periodic_Task( void );
extern void TP_Transmit_Buffer_Filled(void);
extern void TP_Receive_Buffer_Read(void);
extern uint16_t TP_Get_Message_Buffer_Size(void);
extern uint8_t * TP_Get_Message_Buffer_Pointer(void);
extern uint8_t TP_Get_Request_Type(void);
extern void TP_N_USData_Request(uint16_t TPTransmitMessageLength);
extern void TP_N_Change_Parameters_Request(uint8_t Parameter,
uint16_t ParameterValue);
uint8_t *TP_Get_Tx_Message_Buffer_Pointer (void);
extern void TP_D_UUData_Confirm(void);
extern void TP_D_UUData_Indication_Physical(void);
extern void TP_D_UUData_Indication_Functional(void);
#define UCB_TP_Transmit_Buffer_Empty HAL_UDS_Transmit_Buffer_Empty
#ifdef RX_MULTI_BUFFER_SUPPORT
#define UCB_TP_Receive_Buffer_Filled DG_TP_Receive_Buffer_Filled
#endif
#define UCB_TP_N_USData_Confirm HAL_UDS_Response_Confirm
#define UCB_TP_N_USData_FF_Indication HAL_UDS_FF_Indication
#define UCB_TP_N_USData_Indication HAL_UDS_Indication
#define UCB_TP_N_Change_Parameter_Confirm HAL_UDS_Change_Parameter_Confirm
#define UCB_TP_N_USData_FF_Confirmation HAL_UDS_FF_Confirmation
extern void UCB_TP_Transmit_Buffer_Empty(void);
#ifdef RX_MULTI_BUFFER_SUPPORT
extern void UCB_TP_Receive_Buffer_Filled(void);
#endif
extern void UCB_TP_N_USData_Confirm(uint8_t N_Result);
extern void UCB_TP_N_USData_FF_Indication(uint16_t
TPReceivexMessageLength);
extern void UCB_TP_N_USData_Indication(uint16_t TPReceivexMessageLength,
uint8_t N_Result);
extern void UCB_TP_N_Change_Parameter_Confirm(uint8_t Parameter,
uint8_t ParameterChangeResult);
extern void UCB_TP_N_USData_FF_Confirmation(void);
void TP_Task(void);
#endif
/*============================================================================*/
/* CAN : Controller Area Network */
/* DLC : Data Length Code (number of data bytes in a CAN message) */
/* ID : Identifier */
/* BS : Block Size */
/* CF : Consecutive frame */
/* confirm : Confirmation service primitive */
/* ECU : Electronic Control Unit - generic term for any electronic control */
/* unit */
/* FC : Flow Control */
/* FF : First frame */
/* FF_DL : First frame data length */
/* FS : Flow Status */
/*indication : Indication service primitive */
/* Mtype : Message Type */
/*N : Network */
/* N_AE : Network Address Extension */
/* N_AI : Address Information */
/* N_Ar : Network layer timing parameter Ar */
/* N_As : Network layer timing parameter As */
/* N_Br : Network layer timing parameter Br */
/* N_Bs : Network layer timing parameter Bs */
/* N_ChangeParameter : Network layer service name */
/* N_Cr : Network layer timing parameter Cr */
/* N_Cs : Network layer timing parameter Cs */
/* N_Data : Network Data */
/* N_PCI : Network Protocol Control Information */
/* N_PCItype : Network Protocol Control Information Type */
/* N_PDU : Network Protocol Data Unit */
/* N_USData : Network layer Unacknowledged Segmented Data transfer service */
/* name */
/* NWL : Network Layer */
/* request : Request service primitive */
/* SF : Single frame */
/* SF_DL : Single frame data length */
/* SN : Sequence Number */
/* STmin : Separation Time min. */
/* N_As : Time for transmission of the CAN frame(anu N_PDU) on the sender side*/
/* N_Ar : Time for transmission of the CAN frame(anu N_PDU) on the receiver */
/*side */
/* N_Bs : Time until reception of the next flow control N_PDU */
/* N_Cr : Time until reception of the next consecutive frame N_PDU */
/*============================================================================*/

BIN
UDS/uds_api.c Normal file

Binary file not shown.

52
UDS/uds_api.h Normal file
View File

@ -0,0 +1,52 @@
#ifndef _UDS_API_H
#define _UDS_API_H
#include "sys.h"
#include "stdbool.h"
#include "uds_can_interface.h"
typedef enum
{
UNDER_VOLT=0,
LOW_VOLT=1,
NORM_VOLT=2,
HIGH_VOLT=3,
OVER_VOLT=4,
VOLT_STATE_NUM,
}PWR_BATT_VOLT_STATE_ENUM;
typedef struct
{
uint16_t VMin_Cfg;/*mv*/
uint16_t VMax_Cfg;
uint16_t MinTimeCfg;
uint16_t MaxTimeCfg;
}PWR_Volt_State_Config_Type;
void UdsApi_1ms_task(void);
void UdsApi_10ms_task(void);
void UdsApi_MsgQueueIn(CanRxMsg msg);
void UdsApi_MsgQueueOut(can_msg_t uds_msg);
void UdsApi_ParaInit(void);
uint32_t UdsApi_GetRandom(void);
void UdsApi_HardwareFault_ForceClear(void);
uint8_t UdsApi_EE_WriteBytes(uint8_t *_pWriteBuf, uint16_t _usAddress, uint16_t _usSize);
uint8_t UdsApi_EE_ReadBytes(uint8_t *_pReadBuf, uint16_t _usAddress, uint16_t _usSize);
void UdsApi_NVM_Init(void);
int8_t IsAppCanID(CanTxMsg *TxMessage);
bool UdsApi_Is_UdsEnableNCMTx(void);
bool UdsApi_Is_UdsEnableNWMCMTx(void);
bool UdsApi_Is_UdsEnableNCMRx(void);
bool UdsApi_Is_UdsEnableNWMCMRx(void);
bool UdsApi_Is_UdsOnline(void);
bool UdsApi_Is_UdsIdle(void);
bool UdsApi_Is_UdsResponeMsg(uint16_t msg_id);
void UdsApi_BootSwAddr_Get(void);
void Pwr_BatVoltRangeMonitor(void);
#endif

235
UDS/uds_can_interface.c Normal file
View File

@ -0,0 +1,235 @@
#include "uds_config.h"
#include "bsp_can.h"
#if BOOTLOADER_CODE_FLAG == 0
//#include "nm_can.h"
#endif
_QueueCan0Tx QueueCan0Tx;
_QueueCan0Rx UdsQueueData;
INT8U gAppCanTxErrFlg=0;
INT8U gUdsBusOffCanOutBak=0;
bool bCan0InitOkFlg;
extern void HAL_UDS_Tx_Callback(void);
extern xchrTime ign1;
extern xchrTime ign3;
INT32U TestCanRxCnt=0,TestCanRxCntBak=0;
INT32U ParseCanRxCnt=0;
void DealCanProc(void)
{
bCan0InitOkFlg=true;
return;
}
void DealCanProc_bussoff(void)
{
}
void ParseUdsCan(can_msg_t pCanMsg)
{
UdsService.IsUdsFlg=true;
UdsService.SessionTimer=0;
//Debug("Can Bus Off 00\r\n");
switch(pCanMsg.id)
{
case UDS_PHY_TX_ID://NAMS Request 0x787 Response 0x78F
UdsService.CanID = UDS_PHY_TX_ID;
HAL_UDS_PHY_Rx_Callback(pCanMsg.data,pCanMsg.dlc);
break;
case UDS_FUN_TX_ID:
UdsService.CanID = UDS_FUN_TX_ID;
HAL_UDS_FUN_Rx_Callback(pCanMsg.data,pCanMsg.dlc);
break;
default:
break;
}
}
INT8U checkPin(INT8U bcheck,xchrTime *pt,INT8U g)
{
if((bcheck==0)&&(pt->state!='L'))
{
pt->Time1++;
if(pt->Time1>=g) //
{
pt->state='L';
return('L');
}
}
else if((bcheck==1)&&(pt->state!='H'))
{
pt->Time2++;
if(pt->Time2>=g) //
{
pt->state='H';
return('H');
}
}
else
{
pt->Time1=pt->Time2=0;
}
return(0);
}
void UdsQueueCanIn(can_msg_t RxCanMsg)
{
#if BOOTLOADER_CODE_FLAG == 0
//if(CAN_Status == DisableTxAndRx) return;
#endif
if(RxCanMsg.id == UDS_FUN_TX_ID || RxCanMsg.id == UDS_PHY_TX_ID )
{
if(UdsQueueData.In>=CAN0_MAX_RX) UdsQueueData.In=0;
UdsQueueData.CanMsg[UdsQueueData.In].id = RxCanMsg.id;
UdsQueueData.CanMsg[UdsQueueData.In].dlc = RxCanMsg.dlc;
UdsQueueData.CanMsg[UdsQueueData.In].flag = RxCanMsg.flag;
memcpy((void *)&UdsQueueData.CanMsg[UdsQueueData.In].data[0],(void *)&RxCanMsg.data[0],8);
UdsQueueData.In++;
} else {
Uds_SetMsgMonitorTimer(RxCanMsg.id);
}
return;
}
void TxQueueCan0In(can_msg_t TxCanMsg)
{
//if(('L' == ign1.state)&&(acc_status == _ACC_NORMAL))
// if((('L' == ign3.state)||('L' == ign1.state)))
{
if(QueueCan0Tx.In>=CAN0_MAX_TX) QueueCan0Tx.In=0;
QueueCan0Tx.CanMsg[QueueCan0Tx.In].id = TxCanMsg.id;
QueueCan0Tx.CanMsg[QueueCan0Tx.In].dlc = TxCanMsg.dlc;
QueueCan0Tx.CanMsg[QueueCan0Tx.In].flag = TxCanMsg.flag;
memcpy((void *)&QueueCan0Tx.CanMsg[QueueCan0Tx.In].data[0],(void *)&TxCanMsg.data[0],8);
QueueCan0Tx.In++;
}
return;
}
can_msg_t TxCan0Bak;
void TxQueueCan0Out(void)
{
// can_msg_t canmsg = {0};
//if(UdsService.EnRxAndTx) return;
if(g_ulCanStatus) return;
if(TRUE != CanRxConStatus()) return;
while( QueueCan0Tx.In != QueueCan0Tx.Out )
{
if(QueueCan0Tx.Out >= CAN0_MAX_TX)
{
QueueCan0Tx.Out=0;
}
// canmsg.id = QueueCan0Tx.CanMsg[QueueCan0Tx.Out].id;
// canmsg.dlc = QueueCan0Tx.CanMsg[QueueCan0Tx.Out].dlc;
// memcpy(canmsg.data,QueueCan0Tx.CanMsg[QueueCan0Tx.Out].data,8);
UdsApi_MsgQueueOut(QueueCan0Tx.CanMsg[QueueCan0Tx.Out]);
UdsService.UdsTxCompFlg=true;
UdsService.TxUdsChann=0;
QueueCan0Tx.Out++;
break;
}
}
extern void DTC_SignalInit(void);
extern void DID_SignalInit(void);
extern void UDS_ServiceInit(void);
void UdsProcTask(void)
{
// static INT8U Timer10MsCnt = 0;
static INT16U Timer1000MsCnt = 0;
static INT16U Timer200MsCnt = 0;
static INT16U Timer20MsCnt = 0;
static INT8U InitFlag = 0;
if(InitFlag == 0)
{
UdsApi_ParaInit();
// DID_SignalInit();
// DTC_SignalInit();
UDS_ServiceInit();
InitFlag = 1;
}
//等待复位不处理UDS其他任务
if (UdsService.ResetMcuFlg) {
if(UdsService.RstTimer) {
UdsService.RstTimer--;
} else {
UdsService.ResetMcuFlg = false;
NVIC_SystemReset();
}
return;
}
if(++Timer1000MsCnt >= 2)
{
Timer1000MsCnt = 0;
UDS_Demo_Services_Start();
UdsService.StartFlg=true;
UdsService.FrameType=0;
UdsQueueCanOut();
Timer20MsCnt = 0;
}
if (++Timer200MsCnt >= CALL_RATE_TP)
{
Timer200MsCnt = 0;
UDS_Demo_Services_Sequence();
HAL_UDS_Periodic_Task();
// if((FIRST_FRAME == UdsService.FrameType)||((CONSECUTIVE_FRAME == UdsService.FrameType)))
// {
// if(++Timer20MsCnt>=CALL_RATE_TP)
// {
// Timer20MsCnt=0;
// UdsQueueCanOut();
// }
// }
}
TxQueueCan0Out();
GotoDefaultSession();
CheckDtcHsCanError();
UDS_Nrc78PostProcessing();
return;
}
//"${workspace_loc:/${ProjName}/SDK}"

105
UDS/uds_can_interface.h Normal file
View File

@ -0,0 +1,105 @@
#ifndef _UDS_CAN_Interface_
#define _UDS_CAN_Interface_
#include "uds_config.h"
#define Version_Test 0
#define Encrypt_Switch 1
typedef void(*JumpToPtr)(void);
typedef struct{
bool Flg;
bool HappErrFlg;
//bool CanErrSendFlg;
//bool RecoverFlg;
INT8U GenFlg;
INT8U status;
INT8U BusOffRecCnt;
INT8U BusOffErrTimer;
INT8U NoBusOffCnt;
INT16U BusOffCrtCnt;
INT16U StartTime;
INT16U BusOffTime;
INT16U BusOffRecTime;
INT16U RxCntTime;
}_HSCANERROR;
//extern _HSCANERROR HsCanError;
#if BOOTLOADER_CODE_FLAG
//#define CAN0_MAX_BUFF 10//500
#define CAN0_MAX_RX 500
#define CAN0_MAX_TX 10
#else
//#define CAN0_MAX_BUFF 10
#define CAN0_MAX_RX 50
#define CAN0_MAX_TX 10
#endif
typedef struct {
INT32U id; /*11/29bit*/
INT8U dlc; /*0~8*/
INT8U data[8];
INT8U flag;
} can_msg_t;
typedef struct {
INT16U In;
INT16U Out;
can_msg_t CanMsg[CAN0_MAX_RX];
}_QueueCan0Rx;
typedef struct {
//status_t Flg;
INT16U In;
INT16U Out;
can_msg_t CanMsg[CAN0_MAX_TX];
}_QueueCan0Tx;
typedef struct
{
INT16U Time1;
INT16U Time2;
INT8U state;
} xchrTime;
extern INT8U g_ucWARN_LEVEL;
extern INT32U g_ulCanStatus;
extern INT8U gUdsBusOffCanOutBak;
extern INT32U TestCanRxCnt,TestCanRxCntBak;
extern INT32U ParseCanRxCnt;
extern _QueueCan0Tx QueueCan0Tx;
extern _QueueCan0Rx UdsQueueData;
extern can_msg_t TxCan0Bak;
extern void DealCanProc(void);
extern void DealCanProc_bussoff(void);
extern void DealCan2Proc(void);
extern INT8U checkPin(INT8U bcheck,xchrTime *pt,INT8U g);
extern void UdsQueueCanOut(void);
extern void UdsQueueCanIn(can_msg_t RxCanMsg);
extern void TxQueueCan0In(can_msg_t TxCanMsg);
extern void TxQueueCan0Out(void);
extern void ParseUdsCan(can_msg_t pCanMsg);
extern void UdsProcTask(void);
extern INT8U gAppCanTxErrFlg;
extern bool bCan0InitOkFlg;
#endif

72
UDS/uds_config.h Normal file
View File

@ -0,0 +1,72 @@
#ifndef UDS_CONFIG_H
#define UDS_CONFIG_H
#include "sys.h"
#include <stdint.h>
#include <stddef.h> /* This header is included for bool type */
#include <stdbool.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "uds_types.h"
#include "bootloader.h"
// #include "config.h"
#include "uds_did.h"
#include "uds_dtc.h"
#include "uds_can_interface.h"
#include "diagnosis_mid.h"
#include "tp_15765_2.h"
#include "tp_config.h"
#include "uds_interface.h"
#include "uds_manage.h"
#include "uds_services.h"
#include "uds_api.h"
#include "crc.h"
#define ECU_APP_FLAG "DCBMSQiruiB30C42"
/*!
* @file uds_config.h
* @brief UDS configuration file.
*
* misra_violations MISRA-C:2012 violations
*/
#define CAN_STD ((S16)0) /*!< standard type ID */
#define CAN_XTD ((S16)1) /*!< extended type ID */
#define CAN_RX ((S16)0) /*!< receive type */
#define CAN_TX ((S16)1) /*!< transmit type */
/**********************************************************************
* UDS information configuration
**********************************************************************/
/*! @brief PHYSICAL TRANSMIT ID. */
//#define UDS_PHY_TX_ID 0x075C//0x18DAF100
#define UDS_PHY_TX_ID 0x0734
/*! @brief PHYSICAL TRANSMIT ID TYPE, CAN_STD or CAN_XTD */
#define UDS_PHY_TX_TYPE CAN_XTD
/*! @brief PHYSICAL TRANSMIT ID DIRECTION, CAN_TX or CAN_RX */
#define UDS_PHY_TX_DIR CAN_TX
/*! @brief PHYSICAL RECEIVE ID. */
#define UDS_PHY_RX_ID 0x07B4
/*! @brief PHYSICAL RECEIVE ID TYPE, CAN_STD or CAN_XTD */
#define UDS_PHY_RX_TYPE CAN_XTD
/*! @brief PHYSICAL RECEIVE ID DIRECTION, CAN_TX or CAN_RX */
#define UDS_PHY_RX_DIR CAN_RX
/*! @brief FUNCTIONAL TRANSMIT ID. */
#define UDS_FUN_TX_ID 0x07DF//0x18DB33F1
/*! @brief FUNCTIONAL TRANSMIT ID TYPE, CAN_STD or CAN_XTD */
#define UDS_FUN_TX_TYPE CAN_XTD
/*! @brief FUNCTIONAL TRANSMIT ID DIRECTION, CAN_TX or CAN_RX */
#define UDS_FUN_TX_DIR CAN_TX
#endif

68
UDS/uds_did.c Normal file
View File

@ -0,0 +1,68 @@
#include "uds_did.h"
#include <stddef.h>
const uint16_t DIDOffset[] = {
DID_FOREACH(GENERATE_DID_OFFSETS)
};
const uint8_t DIDSize[] = {
DID_FOREACH(GENERATE_DID_SIZE)
};
const uint16_t DIDId[] = {
DID_FOREACH(GENERATE_DID_ID)
};
const uint8_t DIDIsStoreInFlashTable[] = {
DID_FOREACH(GENERATE_DID_STORE_FLAG)
};
const uint16_t DIDStoreInFlashOffset[] = {
DID_FOREACH(GENERATE_DID_STORE_IN_FLASH_OFFSETS)
};
const uint16_t DIDStoreInFlashSize[] = {
DID_FOREACH(GENERATE_DID_STORE_IN_FLASH_SIZE)
};
const uint16_t DIDStoreInFlashId[] = {
DID_FOREACH(GENERATE_DID_STORE_IN_FLASH_ID)
};
uint8_t GetDIDIndexByID(uint16_t id)
{
uint8_t ret = 0xFF;
uint8_t i;
for( i = 0; i < sizeof(DIDId)/sizeof(uint16_t); i++)
{
if (DIDId[i] == id)
{
ret = i;
break;
}
}
return ret;
}
uint8_t GetDIDStoreInFlashIndexByID(uint16_t id)
{
uint8_t ret = 0xFF;
uint8_t i;
for( i = 0; i < sizeof(DIDStoreInFlashId)/sizeof(uint16_t); i++)
{
if (DIDStoreInFlashId[i] == id)
{
ret = i;
break;
}
}
return ret;
}

131
UDS/uds_did.h Normal file
View File

@ -0,0 +1,131 @@
/**
* @file yfve_did_tbl.h
* @author Yfve Team
* @date January 30, 2018
* @brief DID table
*
* - This file contains:
* - DID table
*
* @copyright Copyright 2018 Yanfeng Visteon Electronics Technology (Nanjing) Co., Ltd. All rights reserved.
*/
//#ifndef _YFVE_DID_TBL_H_
//#define _YFVE_DID_TBL_H_
#ifndef __UDS_DID_H__
#define __UDS_DID_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "uds_config.h"
#define DID_FOREACH(func)\
/*01*/ func(0xF187,ECUManufacturerSparePartNumber,12,STORE_IN_RAM)\
/*02*/ func(0xF18A,SystemSupplierIdentifierData,10,STORE_IN_RAM)\
/*03*/ func(0xF197,SystemName,10,STORE_IN_RAM)\
/*04*/ func(0xF189,VehicleManufacturerECUSoftwareNumber,24,STORE_IN_RAM) \
/*05*/ func(0xF089,VehicleManufacturerECUHardwareNumber,8,STORE_IN_RAM) \
/*06*/ func(0xF193,SystemSupplierECUHardwareNumber,8,STORE_IN_RAM) \
/*07*/ func(0xF195,SystemSupplierECUSoftwareNumber,21,STORE_IN_RAM) \
/*08*/ func(0xF180,BootSoftwareNumber,8,STORE_IN_RAM)\
/*09*/ func(0xF190,VehicleIdentificationNumber,17,STORE_IN_FLASH) \
/*10*/ func(0xF010,EOLData,64,STORE_IN_FLASH) \
/*11*/ func(0xF18C,ECUSerialNumber,8,STORE_IN_FLASH) \
/*12*/ func(0xF184,FingerPrint,10,STORE_IN_FLASH) \
/*13*/ func(0xA000,ProgramTryCounter,2,STORE_IN_FLASH) \
/*14*/ func(0xA001,ProgramPassCounter,2,STORE_IN_FLASH) \
/*15*/ func(0x2F80,CurrentDCVolt,2,STORE_IN_RAM) \
/*16*/ func(0x2F81,DCUVariousTempProtectVal,2,STORE_IN_FLASH) \
/*17*/ func(0x2F82,DCVoltProtectVal,2,STORE_IN_FLASH) \
/*18*/ func(0x2F83,InsulationDectVolt,2,STORE_IN_FLASH) \
/*19*/ func(0x2F84,DCUVariousCurrentTempVal,2,STORE_IN_RAM) \
#define GENERATE_DID_INDEX(id,name,len,store) name,
typedef enum _DID_INDEX {
DID_FOREACH(GENERATE_DID_INDEX)
DID_NUM,
}DID_INDEX;
/* this line below for yfve internal */
#define GENERATE_DID_ID(id,name,len,store) id ,
#define GENERATE_DID_LEN(id,name,len,store) eDID_LEN_##name = len,
#define GENERATE_ARRAY(id,name,len,store) uint8_t DID_##name [len + 2];
#define GENERATE_DID_OFFSETS(id,name,len,store) offsetof(DIDs,DID_##name) ,
#define GENERATE_DID_SIZE(id,name,len,store) len ,
#define GENERATE_DID_STORE_FLAG(id,name,len,store) store##_GEN_FLAG(id,name,len)
#define STORE_IN_FLASH_GEN_FLAG(id,name,len) 1,
#define STORE_IN_RAM_GEN_FLAG(id,name,len) 0,
typedef enum _DID_LEN {
DID_FOREACH(GENERATE_DID_LEN)
}eDID_LEN;
typedef struct _DIDs {
DID_FOREACH(GENERATE_ARRAY)
}DIDs;
//ÒÔÏÂÊǽöÐèÒª´æ´¢µÄdid
#define GENERATE_DID_STORE_IN_FLASH_ID(id,name,len,store) store##_GEN_ID(id,name,len)
#define GENERATE_DID_STORE_IN_FLASH_OFFSETS(id,name,len,store) store##_GEN_OFFSETS(id,name,len)
#define GENERATE_DID_STORE_IN_FLASH_SIZE(id,name,len,store) store##_GEN_SIZE(id,name,len)
#define GENERATE_DID_STORE_IN_FLASH_ARRAY(id,name,len,store) store##_GEN_ARRAY(id,name,len)
#define GENERATE_DID_STORE_IN_FLASH_LEN(id,name,len,store) store##_GEN_LEN(id,name,len)
#define GENERATE_DID_STORE_IN_FLASH_INDEX(id,name,len,store) store##_GEN_INDEX(id,name,len)
#define STORE_IN_FLASH_GEN_ID(id,name,len) id ,
#define STORE_IN_RAM_GEN_ID(id,name,len)
#define STORE_IN_FLASH_GEN_OFFSETS(id,name,len) offsetof(DIDS_NvmType,DID_##name) ,
#define STORE_IN_RAM_GEN_OFFSETS(id,name,len)
#define STORE_IN_FLASH_GEN_SIZE(id,name,len) len ,
#define STORE_IN_RAM_GEN_SIZE(id,name,len)
#define STORE_IN_FLASH_GEN_ARRAY(id,name,len) uint8_t DID_##name [len + 2];
#define STORE_IN_RAM_GEN_ARRAY(id,name,len)
#define STORE_IN_FLASH_GEN_LEN(id,name,len) eDID_LEN_##name##_StoreInFlash = len,
#define STORE_IN_RAM_GEN_LEN(id,name,len)
#define STORE_IN_FLASH_GEN_INDEX(id,name,len) name##_StoreInFlash,
#define STORE_IN_RAM_GEN_INDEX(id,name,len)
typedef enum _DID_STORE_IN_FLASH_INDEX {
DID_FOREACH(GENERATE_DID_STORE_IN_FLASH_INDEX)
DID_StoreInFlash_NUM,
}DID_STORE_IN_FLASH_INDEX;
typedef enum _DID_STORE_IN_FLASH_LEN {
DID_FOREACH(GENERATE_DID_STORE_IN_FLASH_LEN)
}DID_STORE_IN_FLASH_LEN;
typedef struct {
DID_FOREACH(GENERATE_DID_STORE_IN_FLASH_ARRAY)
}DIDS_NvmType;
extern const uint16_t DIDOffset[];
extern const uint8_t DIDSize[];
extern const uint16_t DIDId[];
extern const uint16_t DIDStoreInFlashOffset[];
extern const uint16_t DIDStoreInFlashSize[];
extern const uint16_t DIDStoreInFlashId[];
uint8_t GetDIDIndexByID(uint16_t id);
uint8_t GetDIDStoreInFlashIndexByID(uint16_t id);
#define GetDIDIdByName(name) name
#ifdef __cplusplus
}
#endif
#endif /* _YFVE_DID_TBL_H_ */

179
UDS/uds_dtc.h Normal file
View File

@ -0,0 +1,179 @@
#ifndef __UDS_DTC_H__
#define __UDS_DTC_H__
// #include "config.h"
#include "uds_config.h"
#define DTC_FOREACH(func)\
/*01*/ func(0xC11187,BMS_COMM_LOSE) \
/*02*/ func(0xC29387,VCU_COMM_LOSE) \
/*03*/ func(0x911716,ECU_VOLTAGE_LOW) \
/*04*/ func(0x911717,ECU_VOLTAGE_HIGH) \
/*05*/ func(0xC07388,ECU_ENTER_BUSOFF) \
/*06*/ func(0x1F400C,INPUT_OVERVOLTAGE) \
/*07*/ func(0x1F400D,INPUT_UNDERVOLTAGE) \
/*08*/ func(0x1F4000,CHARGE_TEMP_DERATE) \
/*09*/ func(0x1F4001,INTER_TEMP_DERATE) \
/*10*/ func(0x1F4002,INTER_OVERTEMP) \
/*11*/ func(0x1F4003,CHARGE_OVERTEMP) \
/*12*/ func(0x1F4004,DC_POS_RELAY_ADH) \
/*13*/ func(0x1F4005,DC_NEG_RELAY_ADH) \
/*14*/ func(0x1F4006,AC_POS_RELAY_ADH) \
/*15*/ func(0x1F4007,AC_NEG_RELAY_ADH) \
/*16*/ func(0x1F4008,HV_INTERLOCK) \
/*17*/ func(0x1F4009,CC_CC2_RELAY_CTRL_INV) \
/*18*/ func(0x1F400A,CP_CC1_RELAY_CTRL_INV)
/*19*/ /*func(0x1F400B,DCU_VOL_ABN) */
#define GENERATE_DTC_ID(value,name) id##name ,
#define GENERATE_DTC_VALUE_ARRAY(value,name) value,
#define GENERATE_DTC_FAULT_FLAG(value,name) uint32_t f##name: 1;
#define GENERATE_DTC_TIMER_ARRAY(value,name) uint16_t u##name;
#define GENERATE_DTC_OPTION(value,name) uint32_t op##name: 1;
//DTC 请求子功能
#define DTC_ReportNumberOfDTCByStatusMask 0x01
#define DTC_ReportDTCByStatusMask 0x02
#define DTC_ReportDTCSnapshotIdentification 0x03
#define DTC_ReportDTCSnapshotRecordByDTCNumber 0x04
#define DTC_ReportDTCExtendedDataRecordByDTCNumber 0x06
#define DTC_ReportSupportedDTCs 0x0A
//DTCStatusMask/statusOfDtc 参数相关信息
#define DTC_STATUS_Test_Failed 0//测试失效
#define DTC_STATUS_Test_Failed_This_Monitoring_Cycle 1//本检测周期测试失效
#define DTC_STATUS_Pending_DTC 2//等待DTC
#define DTC_STATUS_Confirmed_DTC 3//确认DTC"
#define DTC_STATUS_Test_Not_Completed_Since_Last_Clear 4//上次清零后测试未完成
#define DTC_STATUS_Test_Failed_Since_Last_Clear 5//上次清零后测试失效
#define DTC_STATUS_Test_Not_Completed_This_Monitoring_Cycle 6//本检测周期测试未完成
#define DTC_STATUS_Warning_Indicator_Requested 7//警告指示位请求
#define DTC_STATUS_Support_Bit_Status ((1<<DTC_STATUS_Test_Failed) | (1<<DTC_STATUS_Confirmed_DTC))
//诊断初始化时间
#define DIAG_START_TIME 0 //0 MS
#define DIAG_START_INIT_TIME (470 - DIAG_START_TIME) //5000 MS
#pragma anon_unions
typedef enum _DTC_ID {
DTC_FOREACH(GENERATE_DTC_ID)
DTC_ID_NUM,
}DTC_ID;
typedef union _DTC_Fault_Flag{
uint32_t w;
struct
{
DTC_FOREACH(GENERATE_DTC_FAULT_FLAG)
}b;
}DTC_Fault_Flags;
typedef struct _DTC_Msg_Timer{
DTC_FOREACH(GENERATE_DTC_TIMER_ARRAY)
}DTC_Msg_Timers;
typedef union _DTC_Options{
uint32_t w;
struct
{
DTC_FOREACH(GENERATE_DTC_OPTION)
}b;
}DTC_Options;
typedef enum
{
ISO15031_6_DTCformat,
ISO14229_1_DTCformat,
SAE1939_73_DTCformat,
} DTC_FORMAT_IDENTIFIE;
typedef union
{
uint16_t map;
struct//小端端模式
{
uint8_t DTCcountLowByte;
uint8_t DTCcountHighByte;
//uint8_t DTCcountLowByte;
} b;
} DTC_COUNT;
typedef union
{
struct {
uint8_t BatVolt; //蓄电池电压(最大25.4V) 精度0.1V
uint8_t SOCH; //SOC MSB 0.1%
uint8_t SOCL; //SOC LSB
uint8_t DCInVolH; //直流输入电压MSB 0.1V
uint8_t DCInVolL; //直流输入电压LSB 0.1V
uint8_t GunSts; //插枪状态 0x00 :未插枪 0x01: AC工作模式 0x02:DC工作模式
uint8_t DCRealySts; //直流继电器状态 0x00 :未吸合 0x01: 吸合 0x02:粘连
uint8_t ACRealySts; //交流继电器状态 0x00 :未吸合 0x01: 吸合 0x02:粘连
uint8_t CC2ResistorH; //CC2电阻MSB 0.1Ω
uint8_t CC2ResistorL; //CC2电阻LSB 0.1Ω
uint8_t CommSts; //当前通信状态 0x00 :正常 0x01: 与整车失去通信 0x02:与充电桩失去通信
};
uint8_t d8[11];
}DTC_SnapshotType;
typedef union
{
struct {
uint8_t FaultCounter;
// uint8_t FaultCounterOfAge;
// uint8_t FaultAgingCounter;
};
uint8_t d8[3];
}DTC_ExtendedType;
typedef struct
{
uint8_t status;
uint8_t snapNumber;
DTC_SnapshotType snapshot;
DTC_ExtendedType extended;
uint8_t crc16[2]; //校验
} DTC_RecordDataBufType;
typedef struct
{
DTC_RecordDataBufType recordData[DTC_ID_NUM];
}DTC_StatusType;
typedef union
{
struct {
uint8_t DTCLowByte;
uint8_t DTCMiddleByte;
uint8_t DTCHightByte;
uint8_t res;
};
uint32_t dtc;
}DTC_MaskRecordTpye;
typedef struct
{
uint8_t DTCReportSubFunction;
uint8_t DTCStatusMask;
DTC_MaskRecordTpye DTCMaskRecord;
uint8_t DTCRecordNumber;
DTC_FORMAT_IDENTIFIE DTCFormatIdentifie;
DTC_COUNT DTCcount;
DTC_StatusType DTCStatus;
} DTC_STRUCT;
#endif

562
UDS/uds_interface.c Normal file
View File

@ -0,0 +1,562 @@
/*!
* @file uds_interface.c
* @brief customized service sequence definition. Here is the demo sequence. Modify the file according to the requirements.
*
*/
#include "uds_config.h"
/*!
* Demo Macro. Services number in the sequence.
*/
#define SERVICE_SEQUENCE_NUM (UDS_SERVICE_NUM)
/*!
* Demo Type. Service Control type.
*/
_UdsUpData UdsUpData;
__UDSService UdsService;
UDS_ParameterType UdsParam;
const uint8_t UDSsid[] = {
UDS_SERVICE_FOREACH(GENERATE_UDS_SERVICE_ID)
};
/*!
* Demo Type. Service Function type.
*/
typedef void (*SERVICE_FUNC_T)(void);
//static uint8_t UDS_Routine_ID[2]; /*!< Demo Variable. Routine ID buffer for Service 31 */
uint8_t UDS_SeedKeyBuf[8]; /*!< Demo Variable. Seed key buffer for Service 27 */
//static uint8_t UDS_AddrBuf[4]; /*!< Demo Variable. Address buffer for Service 34 */
//static uint8_t UDS_LengthBuf[4]; /*!< Demo Variable. Length buffer for Service 34 */
//static uint8_t UDS_DataBuf[100]; /*!< Demo Variable. Data buffer for Service 36 */
UDS_Demo_Service_Ctrl_T Service_Ctrl; /*!< Demo Variable. Service Control flag */
static void UDS_10_Service_Session_Control(void);
static void UDS_11_Service_Ecu_Reset(void);
static void UDS_22_Service_Read_Data(void);
static void UDS_2E_Service_Write_Data(void);
static void UDS_3E_Service_Tester_Present(void);
static void UDS_27_Service_Security_Access(void);
static void UDS_31_Service_Routine_Ctrl(void);
static void UDS_28_Service_Communication_Control(void);
static void UDS_85_Service_Control_DTC(void);
#if (BOOTLOADER_CODE_FLAG == 1)
static void UDS_34_Service_Request_Download(void);
static void UDS_36_Service_Transfer_Data(void);
static void UDS_37_Service_Transfer_Exit(void);
#else
static void UDS_14_Service_Clear_DTC(void);
static void UDS_19_Service_Read_DTC(void);
static void UDS_2F_IO_OutputControl(void);
#endif
static void UDS_Service_NRC(void);
/*!
* Demo Variable. Service Sequence table.
*/
static SERVICE_FUNC_T UDS_Demo_Service_Table[SERVICE_SEQUENCE_NUM]= {
UDS_SERVICE_FOREACH(GENERATE_UDS_SERVICE_TABLE)
};
#ifdef PRINT_LOG_INFO
void print_rx_data(uint8_t code)
{
// uint8_t i;
// Sprintf("\r\n=======>Rx uds 0x%02x code data:",code);
// for(i = 0; i< UdsService.RxDlc; i++) {
// Sprintf("0x%02x,",UdsService.ReqCmdBuf[i]);
//
// }
// Sprintf("\r\n");
}
#endif
bool CanRxConStatus(void)
{
bool xbRst=false;
//if((gSystemStatus.EngineStatus)&&(ign1.state=='L'))
// if(( true == UdsUpData.UpModleFlg )||((!HsCanError.StartTime)&&(('L' == ign1.state)||('L' == ign3.state))))
{
xbRst = true;
}
return xbRst;
}
static void UDS_10_Service_Session_Control(void)
{
if((UdsService.RequestFlg)&&(0x10 == UdsService.Id)) {
UDS_Service_10_Response(UdsService.RxSessionDiagModel);
UdsService.RequestFlg=0;
memset(TP_Buffer,0x0,255);
}
}
static void UDS_11_Service_Ecu_Reset(void)
{
if((UdsService.RequestFlg)&&(0x11 == UdsService.Id)) {
UDS_Service_11(UdsService.ReqCmdBuf);
UdsService.RequestFlg=0;
}
}
#if (BOOTLOADER_CODE_FLAG == 0)
static void UDS_14_Service_Clear_DTC(void)
{
if((UdsService.RequestFlg)&&(0x14 == UdsService.Id)) {
UDS_Service_14(UdsService.ReqCmdBuf,3);
UdsService.RequestFlg=0;
memset(TP_Buffer,0x0,255);
}
return;
}
static void UDS_19_Service_Read_DTC(void)
{
if((UdsService.RequestFlg)&&(0x19 == UdsService.Id)) {
UDS_Service_0x19_Response();
//memset(TP_Buffer,0x0,255);
UdsService.RequestFlg=0;
}
}
static void UDS_2F_IO_OutputControl(void)
{
if((UdsService.RequestFlg)&&(0x2F == UdsService.Id)) {
UDS_Service_0x2F_Response();
UdsService.RequestFlg=0;
}
}
#endif
static void UDS_22_Service_Read_Data(void)
{
if((UdsService.RequestFlg)&&(0x22 == UdsService.Id)) {
UDS_Service_0x22_Response();
//memset(TP_Buffer,0x0,255);
UdsService.RequestFlg=0;
}
}
static void UDS_2E_Service_Write_Data(void)
{
if((UdsService.RequestFlg)&&(0x2E == UdsService.Id)) {
UDS_Service_0x2E_Response(&TP_Buffer[1],TP_Rx_Index-1);
UdsService.MultFrameComp=0;
UdsService.RequestFlg=0;
//memset(TP_Buffer,0x0,255);
}
}
static void UDS_3E_Service_Tester_Present(void)
{
if((UdsService.RequestFlg)&&(0x3E == UdsService.Id)) {
UDS_Service_0x3E_Response(&UdsService.ReqCmdBuf[0]);
UdsService.RequestFlg=0;
//memset(TP_Buffer,0x0,255);
}
}
static void UDS_27_Service_Security_Access(void)
{
if((UdsService.RequestFlg)&&(0x27 == UdsService.Id)) {
if (UDS_SERVICE_27_SEND_KEY != UdsService.ReqCmdBuf[0]) {
UDS_Service_27(UDS_SERVICE_27_REQUEST_SEED,UdsService.ReqCmdBuf, UDS_SeedKeyBuf);
UdsService.RequestFlg=0;
//memset(TP_Buffer,0x0,255);
} else if (UDS_SERVICE_27_SEND_KEY == UdsService.ReqCmdBuf[0]) {
UDS_Service_27(UDS_SERVICE_27_SEND_KEY,UdsService.ReqCmdBuf,UDS_SeedKeyBuf);
UdsService.RequestFlg=0;
UdsService.MultFrameComp=0;
memset(UDS_SeedKeyBuf,0x0,8);
//memset(TP_Buffer,0x0,255);
}
}
}
//static void UDS_Demo_Service_Request_Seed(void)
//{
// if((UdsService.RequestFlg)&&(0x27 == UdsService.Id)) {
// UDS_Service_27(UDS_SERVICE_27_REQUEST_SEED,UdsService.ReqCmdBuf, UDS_SeedKeyBuf);
// UdsService.RequestFlg=0;
// //memset(TP_Buffer,0x0,255);
// }
//}
//
//static void UDS_Demo_Service_Send_Key(void)
//{
// if((UdsService.RequestFlg)&&(0x27 == UdsService.Id)) {
// UDS_Service_27(UDS_SERVICE_27_SEND_KEY,UdsService.ReqCmdBuf,UDS_SeedKeyBuf);
// UdsService.RequestFlg=0;
// UdsService.MultFrameComp=0;
// memset(UDS_SeedKeyBuf,0x0,8);
// //memset(TP_Buffer,0x0,255);
// }
//}
static void UDS_31_Service_Routine_Ctrl(void)
{
if((UdsService.RequestFlg)&&(0x31 == UdsService.Id)) {
UDS_Service_31(UdsService.ReqCmdBuf,3);
UdsService.RequestFlg=0;
memset(TP_Buffer,0x0,255);
}
}
static void UDS_28_Service_Communication_Control(void)
{
if((UdsService.RequestFlg)&&(0x28 == UdsService.Id)) {
#ifdef PRINT_LOG_INFO
print_rx_data(0x28);
#endif
UDS_Service_28(UdsService.ReqCmdBuf,2);
UdsService.RequestFlg=0;
memset(TP_Buffer,0x0,255);
}
}
//static void UDS_0x29_Service_Diag_Session(void)
//{
// if((UdsService.RequestFlg)&&(0x29 == UdsService.Id)) {
// UDS_Service_29(UdsService.ReqCmdBuf,1);
// UdsService.RequestFlg=0;
// memset(TP_Buffer,0x0,255);
// }
//}
//static void UDS_20_Service_Diag_Session(void)
//{
// if((UdsService.RequestFlg)&&(0x20 == UdsService.Id)) {
// UDS_Service_20(UdsService.ReqCmdBuf,1);
// UdsService.RequestFlg=0;
// memset(TP_Buffer,0x0,255);
// }
//}
static void UDS_85_Service_Control_DTC(void)
{
if((UdsService.RequestFlg)&&(0x85 == UdsService.Id)) {
#ifdef PRINT_LOG_INFO
print_rx_data(0x85);
#endif
UDS_Service_85(UdsService.ReqCmdBuf,1);
UdsService.RequestFlg=0;
memset(TP_Buffer,0x0,255);
}
}
void GotoDefaultSession(void)
{
//INT8U Tmp[10];
static INT16U Timer1sCnt=0;
static INT16U Timer10msCnt=0;
// static INT16U Timer5minCnt=0;
//if(++Timer1sCnt >= 1000)
if(++Timer10msCnt >= 10) {
//Timer1sCnt=0;
Timer10msCnt = 0;
if (UdsService.SessionTimer < (UDS_S3Sever/10)) {
UdsService.SessionTimer++;
if (UdsService.SessionTimer == (UDS_S3Sever/10)) {
UdsService.IsUdsFlg = false;
if ((_UDS_EXT_SESSION == UdsService.SessionDiagModel)||(_UDS_PROGRAM_SESSION == UdsService.SessionDiagModel)) {
UdsService.RequestFlg=0;
UdsService.SessionDiagModel=_UDS_DEFAULT_SESSION;
UdsService.SeedKeyIsOK=0;
UdsService.AlreadSendSeed = false;
UdsService.GenerateSeedReq_Non = false;
UdsService.SessionTimer=0;
UdsService.NcmDisRxAndTx = 0;
UdsService.NmcmDisRxAndTx = 0;
UdsService.DisDTCRecord=0;
UdsService.ChkProgPreconditionFlg = false;
if(true == UdsUpData.UpModleFlg ) {
UdsUpData.CalcCrc=0;
UdsUpData.UpModleFlg = false;
//EEPROM_write(0,"APP2",4);
//Tmp[0]=0x00;
//Tmp[1]=0x00;
//EEPROM_write(UDS_UPDATE_ADD,Tmp,2);
}
#if BOOTLOADER_CODE_FLAG == 0
IO_InputOutputRelease();
#else
UdsService.ResetMcuFlg = true; //在扩展会话模式或编程会话模式下S3 定时器超时会导致 ECU 重启
#endif
}
}
}
if (UdsService.NcmDisRxAndTx) {
udsInfo2Vehicle.NcmRxEnable = false;
udsInfo2Vehicle.NcmTxEnable = false;
} else {
udsInfo2Vehicle.NcmRxEnable = true;
udsInfo2Vehicle.NcmTxEnable = true;
}
if (UdsService.NmcmDisRxAndTx) {
udsInfo2Vehicle.NmcmRxEnable = false;
udsInfo2Vehicle.NmcmTxEnable = false;
} else {
udsInfo2Vehicle.NmcmRxEnable = true;
udsInfo2Vehicle.NmcmTxEnable = true;
}
if (UdsService.ProgrammingPassTimer) {
UdsService.ProgrammingPassTimer--;
if (UdsService.ProgrammingPassTimer == 0) {
UdsService.ChkProgPreconditionFlg = false;
}
}
if (++Timer1sCnt < 100) return;
Timer1sCnt = 0;
if (UdsService.KeyErrLockTimer) {
UdsService.KeyErrLockTimer--;
if (UdsService.KeyErrLockTimer == 0) {
if(true == UdsService.KeyLockFlg ) {
UdsService.KeyLockFlg=false;
if (UdsService.KeyErrCnt > 0) {
UdsService.KeyErrCnt -= 1;
}
}
}
}
if (UdsService.IsUdsFlg) {
udsInfo2Vehicle.UdsOffLine = false;
} else {
udsInfo2Vehicle.UdsOffLine = true;
udsInfo2Vehicle.OtaModeSts = 0;
#if BOOTLOADER_CODE_FLAG == 0
IO_InputOutputRelease();
#endif
}
// if (++Timer5minCnt >= 300) {
// Timer5minCnt = 0;
// if (UdsService.OtaTimeoutTimer) {
// UdsService.OtaTimeoutTimer--;
// }
// if (UdsService.OtaTimeoutTimer == 0) {
// udsInfo2Vehicle.OtaModeSts = 0;
// }
// }
}
return;
}
#if (BOOTLOADER_CODE_FLAG == 1)
static void UDS_34_Service_Request_Download(void)
{
if((UdsService.RequestFlg)&&(0x34 == UdsService.Id)) {
//UDS_Service_34(0,0x44,UDS_AddrBuf,UDS_LengthBuf);
UDS_Service_34_Ack(&TP_Buffer[1],TP_Rx_Index-1);
UdsService.RequestFlg=0;
UdsService.Id=0;
memset(TP_Buffer,0x0,255);
}
}
/*!
* @brief Demo Service Function to transfer data
* This function is used to transfer data
*/
static void UDS_36_Service_Transfer_Data(void)
{
if((UdsService.RequestFlg)&&(0x36 == UdsService.Id)) {
UDS_Service_36_Ack(UdsService.ReqCmdBuf,TP_Rx_Index-1);
UdsService.RequestFlg=0;
UdsService.Id=0;
memset(TP_Buffer,0x0,TP_BUFFER_SIZE);
}
}
/*!
* @brief Demo Service Function to exit transfer
* This function is used to exit transfer
*/
static void UDS_37_Service_Transfer_Exit(void)
{
if((UdsService.RequestFlg)&&(0x37 == UdsService.Id)) {
UDS_Service_37(&TP_Buffer[1],TP_Rx_Index-1);
UdsService.RequestFlg=0;
UdsService.Id=0;
}
}
#endif
static void UDS_Service_NRC(void)
{
if(UdsService.RequestFlg) {
UDS_Service_NonSupport_Response(UdsService.Id);
UdsService.RequestFlg=0;
UdsService.Id=0;
memset(TP_Buffer,0x0,255);
}
}
/*!
* @brief Demo Service Function to start service sequencce
* This function is used to start service sequencce
*/
void UDS_Demo_Services_Start(void)
{
//Service_Ctrl.index = 0;
Service_Ctrl.start = true;
UDS_Service_Init();
}
/*!
* @brief Demo Service Function to call the services in sequencce
* This function is used to call the services in sequencce
*/
void UDS_Demo_Services_Sequence(void)
{
//the functioni will be called in 10ms task
if(Service_Ctrl.start == true) {
if(Service_Ctrl.index < SERVICE_SEQUENCE_NUM) {
SERVICE_FUNC_T service = UDS_Demo_Service_Table[Service_Ctrl.index];
service();
} else {
Service_Ctrl.start = false;
}
}
}
/*!
* @brief Demo service function to calculate key according to seed.
* The function is used to calculate key according to seed.
*
* @param rsp_buf Response buf pointer
*/
void UDS_Demo_Calculate_Key(uint8_t* rsp_buf)
{
//request seed, store seed
UDS_SeedKeyBuf[0] = rsp_buf[2];
UDS_SeedKeyBuf[1] = rsp_buf[3];
//calculate key
UDS_SeedKeyBuf[0] = UDS_SeedKeyBuf[0]+1;
UDS_SeedKeyBuf[1] = UDS_SeedKeyBuf[1]+2;
}
/*!
* @brief Demo Service Function for positive response callback
* This function is used for positive response callback
*/
void UDS_Pos_Response_Callback(void)
{
Service_Ctrl.index++;
}
/*!
* @brief Demo Service Function for negtive response callback
* This function is used for negtive response callback
*/
void UDS_Neg_Response_Callback(void)
{
//Service_Ctrl.index = 0;
Service_Ctrl.start = false;
UDS_Service_Init();
}
bool CheckIsBeyonSession(INT8U CurSession,INT8U SelfSession,INT8U Type)
{
bool bRst=false;
if(Type) {
if(CurSession!=SelfSession)
bRst = true;
else
bRst = false;
} else {
if(CurSession == SelfSession)
bRst = true;
else
bRst = false;
}
return bRst;
}
bool CheckUdsDlcIsOk(INT16U RxDlc,INT16U rDlc)
{
bool bRst=false;
if( RxDlc == rDlc)
bRst = true;
return bRst;
}
bool CheckSubSidNeedPosResp(INT8U SubSID)
{
bool bRst=false;
if(!(SubSID&0x80))
bRst = true;
return bRst;
}
bool CheckIsKeyOk(void)
{
bool bRst=false;
if(1==UdsService.SeedKeyIsOK)
bRst = true;
return bRst;
}
bool CheckIsSupportBootloaderRead_Sid22(uint16_t did)
{
bool cbRst=false;
if (did == DIDId[BootSoftwareNumber] \
|| did == DIDId[FingerPrint] \
|| did == DIDId[ProgramTryCounter] \
|| did == DIDId[ProgramPassCounter]) {
cbRst = true;
}
return cbRst;
}
bool CheckIsSupportBootloaderWrite_Sid2E(uint16_t did)
{
bool cbRst=false;
if (did == DIDId[FingerPrint]) {
cbRst = true;
}
return cbRst;
}
bool CheckIsSupportAppWrite_Sid2E(uint16_t did)
{
bool cbRst=false;
if (did == DIDId[EOLData] \
|| did == DIDId[DCUVariousTempProtectVal] \
|| did == DIDId[DCVoltProtectVal] \
|| did == DIDId[InsulationDectVolt] \
|| did == DIDId[VehicleIdentificationNumber]) {
cbRst = true;
}
return cbRst;
}
bool CheckIsSupportSubFunc_Sid19(uint8_t sub)
{
bool cbRst=false;
if (sub == 0x01 || sub == 0x02 /*|| sub == 0x03 */|| sub == 0x04 /*|| sub == 0x06 */|| sub == 0x0A) {
cbRst = true;
}
return cbRst;
}
bool CheckIsSupportSubFunc_Sid11(uint8_t sub)
{
bool cbRst=false;
if (sub == 0x01 || sub == 0x03) {
cbRst = true;
}
return cbRst;
}

Some files were not shown because too many files have changed in this diff Show More