增加所有文件
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
#include "app_config.h"
|
||||
|
||||
//定义并初始化
|
||||
BrakeSystem brake_system = {
|
||||
.brake_timer = {0, 0, 0, 0, 0}, // 初始化 Timer 结构体
|
||||
.brake_command = 0,
|
||||
.brake_motor_state = 0,
|
||||
.brake_command_in_progress = 0,
|
||||
.emergency_stop_switch = 0,
|
||||
.remote_emergency_stop = 0,
|
||||
.remote_fault = 0,
|
||||
.can_bus_fault = 0,
|
||||
.ethernet_fault = 0,
|
||||
.mode_signal = 0
|
||||
};
|
||||
|
||||
|
||||
// 处理所有输入信号的函数
|
||||
static void processInputSignals(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // 标记变量为已使用,避免编译器警告
|
||||
|
||||
// 如果当前有刹车命令在执行,忽略新的输入信号
|
||||
if (brake_system.brake_command_in_progress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (brake_system.emergency_stop_switch || brake_system.remote_emergency_stop ||
|
||||
(brake_system.mode_signal == 0 && brake_system.remote_fault) || // 手动模式下的遥控器故障
|
||||
(brake_system.mode_signal == 1 && (brake_system.can_bus_fault || brake_system.ethernet_fault))) // 自动模式下的CAN总线或以太网通信故障
|
||||
{
|
||||
brake_system.brake_command = 1; // 发送刹车指令
|
||||
publishMessage(&brake_system.brake_command, 1);
|
||||
brake_system.brake_command_in_progress = 1; // 标记刹车命令正在执行
|
||||
}
|
||||
else
|
||||
{
|
||||
brake_system.brake_command = 2; // 发送释放刹车指令
|
||||
publishMessage(&brake_system.brake_command, 1);
|
||||
brake_system.brake_command_in_progress = 1; // 标记释放命令正在执行
|
||||
}
|
||||
}
|
||||
|
||||
// 刹车信号处理函数
|
||||
static void brakeProcess(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // 标记变量为已使用,避免编译器警告
|
||||
int signal = *(int *)signal_id;
|
||||
|
||||
if (signal == 1) // 刹车
|
||||
{
|
||||
brake_system.brake_motor_state = 1;
|
||||
publishMessage(&brake_system.brake_motor_state, 1); // 状态改变时发送刹车电机状态信号
|
||||
timerInit(&brake_system.brake_timer, 1500); // 控制刹车电机前进,保持1.5秒
|
||||
}
|
||||
else if (signal == 2) // 释放刹车
|
||||
{
|
||||
brake_system.brake_motor_state = 2;
|
||||
publishMessage(&brake_system.brake_motor_state, 1); // 状态改变时发送刹车电机状态信号
|
||||
timerInit(&brake_system.brake_timer, 800); // 控制刹车电机后退,保持0.8秒
|
||||
}
|
||||
|
||||
timerStart(&brake_system.brake_timer);
|
||||
}
|
||||
|
||||
// 定时器信号处理函数
|
||||
static void brakeTimerProcess(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // 标记变量为已使用,避免编译器警告
|
||||
|
||||
brake_system.brake_motor_state = 0;
|
||||
brake_system.brake_command_in_progress = 0; // 刹车命令执行完成,重置状态
|
||||
publishMessage(&brake_system.brake_motor_state, 1); // 状态改变时发送刹车电机状态信号
|
||||
}
|
||||
|
||||
// 输出处理函数
|
||||
static void outputProcess(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // 标记变量为已使用,避免编译器警告
|
||||
//根据电机状态,填充发送数据结构,发送信号
|
||||
switch (brake_system.brake_motor_state) {
|
||||
case 1: // 电机前进状态
|
||||
UnHBridgeOutput.brake_motor1 = 0;
|
||||
UnHBridgeOutput.brake_motor2 = 1;
|
||||
UnHBridgeOutput.sleep_01 = 0;
|
||||
break;
|
||||
|
||||
case 2: // 电机后退状态
|
||||
UnHBridgeOutput.brake_motor1 = 1;
|
||||
UnHBridgeOutput.brake_motor2 = 0;
|
||||
UnHBridgeOutput.sleep_01 = 0;
|
||||
break;
|
||||
default:
|
||||
UnHBridgeOutput.brake_motor1 = 0;
|
||||
UnHBridgeOutput.brake_motor2 = 0;
|
||||
UnHBridgeOutput.sleep_01 = 0;
|
||||
break;
|
||||
}
|
||||
publishMessage(&UnHBridgeOutput, 1);
|
||||
}
|
||||
|
||||
// APP模块的初始化
|
||||
void brakeAppInit(void)
|
||||
{
|
||||
// 初始化定时器,使用 brake_timer 的地址作为信号ID
|
||||
timerInit(&brake_system.brake_timer, 0);
|
||||
|
||||
// 订阅刹车命令
|
||||
subscribe(&brake_system.brake_command, brakeProcess);
|
||||
|
||||
// 订阅定时器信号,用于停止电机
|
||||
subscribe(&brake_system.brake_timer, brakeTimerProcess);
|
||||
|
||||
// 订阅电机状态
|
||||
subscribe(&brake_system.brake_motor_state, outputProcess);
|
||||
|
||||
// 订阅输入信号,处理刹车逻辑
|
||||
subscribe(&UnSwSample, processInputSignals);
|
||||
subscribe(&UnRemoteControlInput, processInputSignals);
|
||||
subscribe(&brake_system.remote_fault, processInputSignals);
|
||||
subscribe(&brake_system.can_bus_fault, processInputSignals);
|
||||
subscribe(&brake_system.ethernet_fault, processInputSignals);
|
||||
subscribe(&brake_system.mode_signal, processInputSignals);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef APP_BRAKE_H
|
||||
#define APP_BRAKE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "app_config.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
Timer brake_timer; // 定时器结构体
|
||||
int brake_command; // 刹车命令变量:1表示刹车,2表示释放
|
||||
int brake_motor_state; // 刹车电机状态变量:0停止,1前进,2后退
|
||||
int brake_command_in_progress; // 刹车命令执行状态:0表示空闲,1表示正在执行
|
||||
//输入
|
||||
int emergency_stop_switch; // 急停开关
|
||||
int remote_emergency_stop; // 遥控器急停开关
|
||||
int remote_fault; // 遥控器故障
|
||||
int can_bus_fault; // CAN总线故障
|
||||
int ethernet_fault; // 以太网通信故障
|
||||
int mode_signal; // 模式信号:0表示手动模式,1表示自动模式
|
||||
} BrakeSystem;
|
||||
|
||||
// 在头文件中声明外部变量
|
||||
extern BrakeSystem brake_system;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // APP_BRAKE_H
|
||||
@@ -0,0 +1,51 @@
|
||||
#ifndef _CRC16_H_
|
||||
#define _CRC16_H_
|
||||
|
||||
static 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
|
||||
};
|
||||
|
||||
__inline unsigned short crc16_ccitt(const unsigned char *buf, unsigned int len)
|
||||
{
|
||||
register unsigned int counter;
|
||||
register unsigned short crc = 0;
|
||||
for( counter = 0; counter < len; counter++)
|
||||
crc = (crc<<8) ^ crc16tab[((crc>>8) ^ *(unsigned char *)buf++)&0x00FF];
|
||||
return crc;
|
||||
}
|
||||
extern __inline unsigned short crc16_ccitt(const unsigned char *buf, unsigned int len);
|
||||
|
||||
#endif /* _CRC16_H_ */
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
|
||||
|
||||
#include "interface_config.h"
|
||||
|
||||
UnMotorInput un_motor_input1 ;//电机控制器1 左前侧
|
||||
UnMotorInput un_motor_input2 ;//电机控制器2 右前侧
|
||||
UnMotorInput un_motor_input3 ;//电机控制器1 左后侧
|
||||
UnMotorInput un_motor_input4 ;//电机控制器2 右后侧
|
||||
|
||||
UnBmsInput un_bms_input ;//BMS接收数据
|
||||
UnTempModuleInput un_temp_module_input ;//温度采集模块
|
||||
|
||||
UnMotorOutput un_motor_output1 ;//电机输出
|
||||
UnMotorOutput un_motor_output2 ;//电机输出
|
||||
UnMotorOutput un_motor_output3 ;//电机输出
|
||||
UnMotorOutput un_motor_output4 ;//电机输出
|
||||
|
||||
UnInfCanKGFOutput un_inf_can_kgf_output1 ;//kgf输出
|
||||
UnInfCanKGFOutput un_inf_can_kgf_output2 ;
|
||||
UnHBridgeOutput un_h_bridge_output ;//H桥输出
|
||||
UnWheelSpeedOutput un_wheel_wpeed_output ;//轮速输出
|
||||
|
||||
UnRemoteControlInput un_remote_control_input ;//遥控器输入
|
||||
|
||||
UnHBridgeOutput un_h_bridge_output ;//H桥输出
|
||||
|
||||
UnHBridgeOutput un_h_bridge_output1 ;//左太阳能板电机
|
||||
UnHBridgeOutput un_h_bridge_output2 ;//右太阳能板电机
|
||||
|
||||
UnLifterOutput un_lifter_output ;//基站升降杆输出
|
||||
|
||||
|
||||
|
||||
UnSdoOutput un_sdo_output1 ;//设定转向电机位置
|
||||
UnSdoOutput un_sdo_output2 ;//设定转向电机速度
|
||||
UnSdoOutput un_sdo_output3 ;//使能向下一个点
|
||||
UnSdoOutput un_sdo_output4 ;//设定电机使能
|
||||
UnSdoOutput un_sdo_output5 ;//设置电机模式
|
||||
UnSdoOutput un_sdo_output6 ;//接收数据
|
||||
UnSdoOutput un_sdo_output7 ;//发送使能数据
|
||||
|
||||
|
||||
//IO口
|
||||
UnSwSample un_sw_sample ;//采集
|
||||
|
||||
|
||||
//以太网
|
||||
UnAutoComputerInput un_auto_computer_input ;//自主计算机自动数据
|
||||
UnManualComputerInput un_manual_computer_input ;//自主计算机手动数据
|
||||
UnRequestFrame un_request_frame ;//请求帧
|
||||
|
||||
UnComputerOutput un_computer_output ;//输出给自主计算机
|
||||
|
||||
//输出给上位机
|
||||
UnVehicleInfoOutput un_vehicle_Info_output ;// 车辆信息,输出给上位机
|
||||
UnMotorStatusOutput un_motor_status_output ;// 电机状态信息,输出给上位机
|
||||
UnPIDOutput un_pid_output ;// PID参数输出,输出给上位机
|
||||
UnAnalogSignalOutput un_analog_signal_output ;// 模拟信号输出,输出给上位机
|
||||
UnRemoteControlOutput un_remote_control_output ;// 遥控器数据输出,给上位机
|
||||
UnManualControlOutput un_manual_control_output ;// 手动控制数据,返回给请求者
|
||||
UnAutoControlOutput un_auto_control_output ;// 自动控制数据输出,返回给请求者
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,890 @@
|
||||
#ifndef _INTERFACE_H_
|
||||
#define _INTERFACE_H_
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
#include "app/app_config.h" // 假设包含基础配置和宏定义
|
||||
#include "irq.h"
|
||||
#include "interface_config.h"
|
||||
#include <udelay/udelay.h>
|
||||
|
||||
|
||||
|
||||
#pragma pack(1)//数据结构一个字节对齐
|
||||
|
||||
|
||||
#define request_read_id un_request_frame.bit_data.request_id//读取ID
|
||||
#define request_header_id un_request_frame.bit_data.frame_header//帧头
|
||||
|
||||
|
||||
#define FAULT 0
|
||||
#define NORMAL 1
|
||||
|
||||
|
||||
//-----CAN----------------------------------------------------------------
|
||||
// 接收电机控制器输入
|
||||
typedef struct _StrMotorInput
|
||||
{
|
||||
//-----接收数据0x10F90708----------------------------------------------
|
||||
unsigned int control_data3 : 16; // 读取的控制数据
|
||||
unsigned int torque : 16; // 当前扭矩
|
||||
unsigned int phase_current : 16; // 当前相电流
|
||||
unsigned int speed : 16; // 当前转速
|
||||
|
||||
unsigned int gear : 2; // 反馈档位
|
||||
unsigned int speed_gear : 3; // 当前扭矩
|
||||
unsigned int reserve1 : 1; // 保留
|
||||
unsigned int reserve2 : 1; // 保留
|
||||
unsigned int reserve3 : 1; // 保留
|
||||
|
||||
unsigned int reserve4 : 8; // 保留
|
||||
unsigned int reserve5 : 16; // 保留
|
||||
unsigned int reserve6 : 16; // 保留
|
||||
unsigned int reserve7 : 16; // 保留
|
||||
} StrMotorInput;
|
||||
|
||||
typedef union _UnMotorInput
|
||||
{
|
||||
StrMotorInput bit_data; // 使用定义的结构体变量名
|
||||
uint8_t arr[sizeof(StrMotorInput)]; // 通过结构体类型确定大小
|
||||
} UnMotorInput;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 接收BMS输入
|
||||
typedef struct _StrBmsInput
|
||||
{
|
||||
//----接收0x100----------------------------------
|
||||
// 多字节数据,高位在前,低位在后
|
||||
unsigned int bus_voltage : 16; // 母线电压 单位为10mV
|
||||
unsigned int bus_current : 16; // 母线电流 单位为10mA
|
||||
unsigned int remainder_capacity : 16; // 剩余容量 单位为10mAh 充电为正,放电为负
|
||||
unsigned int crc1 : 16; //crc
|
||||
//----接收0x101----------------------------------
|
||||
// 多字节数据,高位在前,低位在后
|
||||
unsigned int full_capacity : 16; // 充满容量 单位为10mAh
|
||||
unsigned int Discharge_times : 16; // 放电循环次数 单位为1次
|
||||
unsigned int soc : 16; // soc 1%
|
||||
unsigned int crc2 : 16; //crc
|
||||
} StrBmsInput;
|
||||
|
||||
typedef union _UnBmsInput
|
||||
{
|
||||
StrBmsInput bit_data; // 使用定义的结构体变量名
|
||||
uint8_t arr[sizeof(StrBmsInput)]; // 通过结构体类型确定大小
|
||||
} UnBmsInput;
|
||||
|
||||
|
||||
// 接收温度模块输入
|
||||
typedef struct _StrTempModuleInput
|
||||
{
|
||||
//-----接收数据0x301,302----------------------------------------------
|
||||
// 多字节数据,高位在前,低位在后
|
||||
unsigned int channel_1 : 16; // 通道1 温度传感器 系数为0.1 有符号 正数表示正温度,负数表示负温度
|
||||
unsigned int channel_2 : 16; // 通道2
|
||||
unsigned int channel_3 : 16; // 通道3
|
||||
unsigned int channel_4 : 16; // 通道4
|
||||
unsigned int channel_5 : 16; // 通道5
|
||||
unsigned int channel_6 : 16; // 通道6
|
||||
unsigned int channel_7 : 16; // 通道7
|
||||
unsigned int channel_8 : 16; // 通道8
|
||||
} StrTempModuleInput;
|
||||
|
||||
typedef union _UnTempModuleInput
|
||||
{
|
||||
StrTempModuleInput bit_data; // 使用定义的结构体变量名
|
||||
uint8_t arr[sizeof(StrTempModuleInput)]; // 通过结构体类型确定大小
|
||||
} UnTempModuleInput;
|
||||
|
||||
|
||||
|
||||
|
||||
//-----以太网-------------------------------------------------------------
|
||||
// 接收自主计算机自动输入
|
||||
typedef struct _StrAutoComputerInput
|
||||
{
|
||||
// 多字节数据,高位在前,低位在后
|
||||
unsigned int frame_header : 16; // 帧头 固定值0xFFCC
|
||||
unsigned int frame_type : 16; // 帧类型 固定值0x0001
|
||||
unsigned int frame_length : 8; // 帧长 固定值0x19
|
||||
unsigned int heartbeat : 8; // 心跳 按帧累加
|
||||
unsigned int set_speed : 16; // 设定速度 系数0.01,正为前进,负为后退 单位m/s
|
||||
unsigned int set_curvature : 16; // 设定曲率 系数0.0001,正为左转,负为右转
|
||||
unsigned int latitude : 32; // 纬度 系数10^-7,431234567表示43.1234567度
|
||||
unsigned int longitude : 32; // 经度 系数10^-7,431234567表示43.1234567度
|
||||
unsigned int altitude : 32; // 高度 单位mm
|
||||
unsigned int heading : 16; // 航向 车辆航向,35999表示359.99度
|
||||
unsigned int crc : 8; // CRC 按字节累加之和,溢出取低8位
|
||||
} StrAutoComputerInput;
|
||||
|
||||
typedef union _UnAutoComputerInput
|
||||
{
|
||||
StrAutoComputerInput bit_data; // 使用定义的结构体变量名
|
||||
uint8_t arr[sizeof(StrAutoComputerInput)]; // 通过结构体类型确定大小
|
||||
} UnAutoComputerInput;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 接收自主计算机手动输入
|
||||
|
||||
typedef struct _StrManualComputerInput
|
||||
{
|
||||
// 手动控制数据 高位在前,低位在后
|
||||
unsigned int frame_header : 16; // 帧头 固定值0xFFBB
|
||||
unsigned int frame_type : 16; // 帧类型 固定值0x0011
|
||||
unsigned int frame_length : 8; // 帧长 固定值0x0B
|
||||
unsigned int accumulated : 8; // 累加值 按帧累加
|
||||
unsigned int set_speed : 16; // 期望速度 系数0.01,正为前进,负为后退 单位m/s
|
||||
unsigned int set_curvature : 16; // 期望曲率 系数0.0001,正为左转,负为右转
|
||||
unsigned int reserved : 8; // 保留 同时按下LB+Y时发0xFF,松开发0,同时按下LT+Y时发0x10,松开发0
|
||||
unsigned int crc : 8; // CRC 按字节累加之和,溢出取低8位
|
||||
} StrManualComputerInput;
|
||||
|
||||
typedef union _UnManualComputerInput
|
||||
{
|
||||
StrManualComputerInput bit_data; // 使用定义的结构体变量名
|
||||
unsigned int arr[sizeof(StrManualComputerInput) / sizeof(unsigned int)]; // 通过结构体类型确定大小
|
||||
} UnManualComputerInput;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 接收请求帧
|
||||
typedef struct _StrRequestFrame
|
||||
{
|
||||
//--------------------------------------------------
|
||||
unsigned int frame_header : 16; // 帧头 固定值0x0080
|
||||
unsigned int frame_type : 16; // 帧类型 固定值0x0029
|
||||
unsigned int frame_length : 16; // 帧长 固定值10
|
||||
unsigned int accumulated : 8; // 累加值 按帧累加
|
||||
unsigned int request_id : 16; // 请求帧ID 请求ID 0-FFFF,FFFF表示全部帧
|
||||
unsigned int crc : 8; // CRC 按字节累加之和 取低8位
|
||||
} StrRequestFrame;
|
||||
|
||||
typedef union _UnRequestFrame
|
||||
{
|
||||
StrRequestFrame bit_data; // 使用定义的结构体变量名
|
||||
unsigned char arr[sizeof(StrRequestFrame)]; // 通过结构体类型确定大小
|
||||
} UnRequestFrame;
|
||||
|
||||
|
||||
// 接收遥控器输入
|
||||
typedef struct _StrRemoteControlInput
|
||||
{
|
||||
//-----接收数据0x12000013----------------------------------------------
|
||||
unsigned int speed : 16; // 速度
|
||||
unsigned int curvature : 16; // 曲率
|
||||
unsigned int reserve1 : 16; // 遥控轴
|
||||
|
||||
unsigned int switch_a : 1; // SwA
|
||||
unsigned int switch_b : 2; // SwB 急停开关 1释放 0/2是急停
|
||||
unsigned int switch_c : 2; // SwC 模式开关 1自动 0/2是手动
|
||||
unsigned int switch_d : 1; // SwD 上电开关 先短按再长按
|
||||
unsigned int reserve2 : 1; // 保留
|
||||
unsigned int reserve3 : 1; // 保留
|
||||
|
||||
unsigned int enable : 8; // 使能
|
||||
} StrRemoteControlInput;
|
||||
|
||||
typedef union _UnRemoteControlInput
|
||||
{
|
||||
StrRemoteControlInput bit_data; // 使用定义的结构体变量名
|
||||
uint8_t arr[sizeof(StrRemoteControlInput)]; // 通过结构体类型确定大小
|
||||
} UnRemoteControlInput;
|
||||
|
||||
|
||||
//-----IO口---------------------------------------------------------------
|
||||
// 从IO口输入
|
||||
|
||||
typedef struct _StrSwSample
|
||||
{
|
||||
unsigned int emergency_stop_switch : 1; // 通道1,急停开关
|
||||
unsigned int High_voltage_switch : 1; // 通道2,高压开关
|
||||
unsigned int Left_switch : 1; // 通道3 左限位开关
|
||||
unsigned int right_switch : 1; // 通道4 右限位开关
|
||||
unsigned int CH05 : 1; // 通道5
|
||||
unsigned int CH06 : 1; // 通道6
|
||||
unsigned int CH07 : 1; // 通道7
|
||||
unsigned int CH08 : 1; // 通道8
|
||||
unsigned int CH09 : 1; // 通道9
|
||||
unsigned int CH10 : 1; // 通道10
|
||||
unsigned int CH11 : 1; // 通道11
|
||||
unsigned int CH12 : 1; // 通道12
|
||||
unsigned int CH13 : 1; // 通道13
|
||||
unsigned int CH14 : 1; // 通道14
|
||||
unsigned int CH15 : 1; // 通道15
|
||||
unsigned int CH16 : 1; // 通道16
|
||||
unsigned int CH17 : 1; // 通道17
|
||||
unsigned int CH18 : 1; // 通道18
|
||||
unsigned int CH19 : 1; // 通道19
|
||||
unsigned int CH20 : 1; // 通道20
|
||||
unsigned int CH21 : 1; // 通道21
|
||||
unsigned int CH22 : 1; // 通道22
|
||||
unsigned int CH23 : 1; // 通道23
|
||||
unsigned int CH24 : 1; // 通道24
|
||||
unsigned int CH25 : 1; // 通道25
|
||||
unsigned int CH26 : 1; // 通道26
|
||||
unsigned int CH27 : 1; // 通道27
|
||||
unsigned int CH28 : 1; // 通道28
|
||||
unsigned int CH29 : 1; // 通道29
|
||||
unsigned int CH30 : 1; // 通道30
|
||||
unsigned int CH31 : 1; // 通道31
|
||||
unsigned int CH32 : 1; // 通道32
|
||||
unsigned int CH33 : 1; // 通道33
|
||||
unsigned int CH34 : 1; // 通道34
|
||||
unsigned int CH35 : 1; // 通道35
|
||||
unsigned int CH36 : 1; // 通道36
|
||||
unsigned int CH37 : 1; // 通道37
|
||||
unsigned int CH38 : 1; // 通道38
|
||||
unsigned int CH39 : 1; // 通道39
|
||||
unsigned int CH40 : 1; // 通道40
|
||||
unsigned int CH41 : 1; // 通道41
|
||||
unsigned int CH42 : 1; // 通道42
|
||||
unsigned int CH43 : 1; // 通道43
|
||||
unsigned int CH44 : 1; // 通道44
|
||||
unsigned int reserve : 4;
|
||||
} StrSwSample;
|
||||
|
||||
typedef union _UnSwSample
|
||||
{
|
||||
StrSwSample bit_data; // 使用定义的结构体变量名
|
||||
uint8_t arr[sizeof(StrSwSample)]; // 通过结构体类型确定大小
|
||||
} UnSwSample;
|
||||
|
||||
|
||||
//-----输出数据结构---------------------------------------------------------------
|
||||
//-----CAN----------------------------------------------------------------
|
||||
// 输出到电机控制器
|
||||
//typedef struct _StrMotorOutput
|
||||
//{
|
||||
////-----发送数据0x201或者0x202----------------------------------------------
|
||||
// unsigned int mode : 8; // 模式 0x1恒速模式,0x2恒扭模式,其他无效
|
||||
// unsigned int gear : 8; // 档位 0x0空挡模式,0x1前进挡,0x2倒退档,其他无效
|
||||
// unsigned int set_torque : 16; // 给定扭矩 系数 0.01 偏移量 -300 实际物理量=数据×系数+偏移量
|
||||
// unsigned int set_rotation_speed : 16; // 给定转速 偏移量 -30000
|
||||
// unsigned int fault_code : 8; // 故障码
|
||||
// unsigned int heartbeat : 8; // 心跳
|
||||
////-----发送数据0x401或者0x402----------------------------------------------
|
||||
// unsigned int feed_power : 16; // 馈电功率 单位为 W 最大为10KW
|
||||
// unsigned int discharge_power : 16; // 放电功率 单位为 W 最大为15kW
|
||||
// unsigned int reserve1 : 16; // 保留
|
||||
// unsigned int reserve2 : 16; // 保留
|
||||
//} StrMotorOutput;
|
||||
//
|
||||
//typedef union _UnMotorOutput
|
||||
//{
|
||||
// StrMotorOutput bit_data; // 使用定义的结构体变量名
|
||||
// uint8_t arr[sizeof(StrMotorOutput)]; // 通过结构体类型确定大小
|
||||
//} UnMotorOutput;
|
||||
|
||||
|
||||
|
||||
// canoe协议输出
|
||||
typedef struct _StrSdoOutput
|
||||
{
|
||||
//-----发送数据0x601----------------------------------------------
|
||||
unsigned int cmd : 8; // 命令
|
||||
unsigned int object_index : 16; // 索引
|
||||
unsigned int sub_index : 8; // 从索引
|
||||
unsigned int data : 32; // 数据
|
||||
} StrSdoOutput;
|
||||
|
||||
typedef union _UnSdoOutput
|
||||
{
|
||||
StrSdoOutput bit_data; // 使用定义的结构体变量名
|
||||
uint8_t arr[sizeof(StrSdoOutput)]; // 通过结构体类型确定大小
|
||||
} UnSdoOutput;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct _StrMotorOutput
|
||||
{
|
||||
//-----发送数据0x10F80807----------------------------------------------
|
||||
unsigned int gear : 2; // 0 表示空挡,1 表示前进,2 表示后退
|
||||
unsigned int can_gear : 1; // 0-无效 1-有效。无效时 BIT10 的挡位无效,以线路控制挡位为准
|
||||
unsigned int can_break : 1; // 0:不刹车,1-刹车(刹车时才能启动电子刹车)
|
||||
unsigned int reserve1 : 1; // 0-只有高速档 1-可以通过接线切换 123 档。
|
||||
unsigned int reserve2 : 1; // 0-无效 1-有效:线控防盗使能
|
||||
unsigned int reserve3 : 1; // 0-无效 1-有效:线控巡航使能
|
||||
unsigned int reserve4 : 1; // 0-无效 1-有效:线控座桶使能
|
||||
|
||||
unsigned int reserve5 : 1; // 0-无效 1-有效:线控边撑使能
|
||||
unsigned int reserve6 : 1; // 0-无效 1-有效:线控防盗使能
|
||||
unsigned int reserve7 : 1; // 0-无效 1-有效:线控巡航使能
|
||||
unsigned int reserve8 : 1; // 0-无效 1-有效:线控座桶使能
|
||||
unsigned int reserve9 : 1; // 0-无效 1-有效:线控巡航使能
|
||||
unsigned int reserve10 : 1; // 0-无效 1-有效:线控座桶使能
|
||||
unsigned int reserve11 : 1; // 0-无效 1-有效:线控巡航使能
|
||||
unsigned int reserve12 : 1; // 0-无效 1-有效:线控座桶使能
|
||||
|
||||
unsigned int reserve13 : 1; // 0-无效 1-有效:线控边撑使能
|
||||
unsigned int reserve14 : 1; // 0-无效 1-有效:线控防盗使能
|
||||
unsigned int reserve15 : 1; // 0-无效 1-有效:线控巡航使能
|
||||
unsigned int reserve16 : 1; // 0-无效 1-有效:线控座桶使能
|
||||
unsigned int reserve17 : 1; // 0-无效 1-有效:线控巡航使能
|
||||
unsigned int reserve18 : 1; // 0-无效 1-有效:线控座桶使能
|
||||
unsigned int motor_direction : 1; // 0 和 1 (静止空闲状态设置有效,在油门、 转矩、转速模式下允许设置,否则使用控制器 内部保存的参数控制电机方向)
|
||||
unsigned int Contactor : 1; // 0-断开 1-闭合,(部分控制器支持)
|
||||
|
||||
unsigned int reserve19 : 1; // 0-无效 1-有效:线控边撑使能
|
||||
unsigned int reserve20 : 1; // 0-无效 1-有效:线控防盗使能
|
||||
unsigned int reserve21 : 1; // 0-无效 1-有效:线控巡航使能
|
||||
unsigned int reserve22 : 1; // 0-无效 1-有效:线控座桶使能
|
||||
unsigned int mode : 4; //0x0:转把控制,0x5:油门模式,0xA:转矩模式, 0xC:转速模式,其它无效停机。在这三种模式下,电机方向设置有效。只允许在停机状态下设置控制模式。
|
||||
|
||||
unsigned int control_data1 : 16; // 油门-256~+256:(0~+256 表示最大油门,-256 表 示最大电子刹车力度。转矩 -256~10000,(正数 驱 动 扭 矩 0~1000.0Nm,负数表示刹车,-256 表示最大电子刹车力度)转速-256~12000,(正数表示转速 0~12000rpm, 负数表示刹车,-256 最大刹车力度)
|
||||
unsigned int control_data2 : 16; // 控制数据和上一个一样
|
||||
} StrMotorOutput;
|
||||
|
||||
typedef union _UnMotorOutput
|
||||
{
|
||||
StrMotorOutput bit_data; // 使用定义的结构体变量名
|
||||
uint8_t arr[sizeof(StrMotorOutput)]; // 通过结构体类型确定大小
|
||||
} UnMotorOutput;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//电机控制器风扇左
|
||||
//kgf1
|
||||
//电机控制器风扇右
|
||||
//kgf3
|
||||
//预充
|
||||
//kgf4
|
||||
//高压压继电器
|
||||
//kgf7,8
|
||||
//低压继电器
|
||||
//kgf11-12
|
||||
//左前红灯
|
||||
//kgf6
|
||||
//左前黄灯
|
||||
//kgf9
|
||||
//左风扇
|
||||
//kgf14
|
||||
//右风扇
|
||||
//kgf19
|
||||
//电脑
|
||||
//kgf 17-18
|
||||
//交换机
|
||||
//kgf 21-22
|
||||
//右前红灯
|
||||
//kgf24
|
||||
//右前黄灯
|
||||
//kgf25
|
||||
//左后红灯
|
||||
//kgf26
|
||||
//左后黄灯
|
||||
//kgf27
|
||||
//右后红灯
|
||||
//kgf29
|
||||
//右后黄灯
|
||||
//kgf30
|
||||
|
||||
|
||||
// 输出到开关阀模块
|
||||
typedef struct _StrInfCanKGFOutput
|
||||
{
|
||||
//----------主机发送命令字0x11000002 --------------------------------------------
|
||||
unsigned int KGF01 : 1; // 通道1
|
||||
unsigned int KGF02 : 1; // 通道2
|
||||
unsigned int KGF03 : 1; // 通道3
|
||||
unsigned int KGF04 : 1; // 通道4
|
||||
unsigned int KGF05 : 1; // 通道5
|
||||
unsigned int KGF06 : 1; // 通道6
|
||||
unsigned int KGF07 : 1; // 通道7
|
||||
unsigned int KGF08 : 1; // 通道8
|
||||
unsigned int KGF09 : 1; // 通道9
|
||||
unsigned int KGF10 : 1; // 通道10
|
||||
unsigned int KGF11 : 1; // 通道11
|
||||
unsigned int KGF12 : 1; // 通道12
|
||||
unsigned int KGF13 : 1; // 通道13
|
||||
unsigned int KGF14 : 1; // 通道14
|
||||
unsigned int KGF15 : 1; // 通道15
|
||||
unsigned int KGF16 : 1; // 通道16
|
||||
|
||||
unsigned int can_rx2 : 8; // 保留
|
||||
unsigned int can_rx3 : 8; // 保留
|
||||
unsigned int can_rx4 : 8; // 保留
|
||||
unsigned int can_rx5 : 8; // 保留
|
||||
unsigned int can_period_h : 8; // 发送周期高位
|
||||
unsigned int can_period_l : 8; // 发送周期低位
|
||||
|
||||
//----------发送0x11000003 ---------------------------------------------------
|
||||
unsigned int pwm_01 : 4; // PWM通道1
|
||||
unsigned int pwm_02 : 4; // PWM通道2
|
||||
unsigned int pwm_03 : 4; // PWM通道3
|
||||
unsigned int pwm_04 : 4; // PWM通道4
|
||||
unsigned int pwm_05 : 4; // PWM通道5
|
||||
unsigned int pwm_06 : 4; // PWM通道6
|
||||
unsigned int pwm_07 : 4; // PWM通道7
|
||||
unsigned int pwm_08 : 4; // PWM通道8
|
||||
unsigned int pwm_09 : 4; // PWM通道9
|
||||
unsigned int pwm_10 : 4; // PWM通道10
|
||||
unsigned int pwm_11 : 4; // PWM通道11
|
||||
unsigned int pwm_12 : 4; // PWM通道12
|
||||
unsigned int pwm_13 : 4; // PWM通道13
|
||||
unsigned int pwm_14 : 4; // PWM通道14
|
||||
unsigned int pwm_15 : 4; // PWM通道15
|
||||
unsigned int pwm_16 : 4; // PWM通道16
|
||||
} StrInfCanKGFOutput;
|
||||
|
||||
typedef union _UnInfCanKGFOutput
|
||||
{
|
||||
StrInfCanKGFOutput bit_data; // 使用定义的结构体变量名
|
||||
uint8_t arr[sizeof(StrInfCanKGFOutput)]; // 通过结构体类型确定大小
|
||||
} UnInfCanKGFOutput;
|
||||
|
||||
|
||||
|
||||
// 输出到H桥模块
|
||||
typedef struct _StrHBridgeOutput
|
||||
{
|
||||
//----------主机发送命令字0x7F2 --------------------------------------------
|
||||
unsigned int channel_01 : 1; // 通道1
|
||||
unsigned int channel_02 : 1; // 通道2
|
||||
unsigned int channel_03 : 1; // 通道3
|
||||
unsigned int channel_04 : 1; // 通道4
|
||||
unsigned int channel_05 : 1; // 通道5
|
||||
unsigned int channel_06 : 1; // 通道6
|
||||
unsigned int channel_07 : 1; // 通道7
|
||||
unsigned int channel_08 : 1; // 通道8
|
||||
unsigned int sleep_01 : 1; // 休眠1
|
||||
unsigned int sleep_02 : 1; // 休眠2
|
||||
unsigned int sleep_03 : 1; // 休眠3
|
||||
unsigned int sleep_04 : 1; // 休眠4
|
||||
unsigned int reserve_01 : 1; // 保留1
|
||||
unsigned int reserve_02 : 1; // 保留2
|
||||
unsigned int reserve_03 : 1; // 保留3
|
||||
unsigned int reserve_04 : 1; // 保留4
|
||||
|
||||
unsigned int reserve_05 : 8; // 保留5
|
||||
unsigned int reserve_06 : 8; // 保留6
|
||||
unsigned int reserve_07 : 8; // 保留7
|
||||
unsigned int reserve_08 : 8; // 保留8
|
||||
unsigned int can_period_h : 8; // 发送周期高位
|
||||
unsigned int can_period_l : 8; // 发送周期低位
|
||||
|
||||
//----------发送0x7F3 ---------------------------------------------------
|
||||
unsigned int pwm_channel_01 : 4; // PWM通道1
|
||||
unsigned int pwm_channel_02 : 4; // PWM通道2
|
||||
unsigned int pwm_channel_03 : 4; // PWM通道3
|
||||
unsigned int pwm_channel_04 : 4; // PWM通道4
|
||||
unsigned int pwm_channel_05 : 4; // PWM通道5
|
||||
unsigned int pwm_channel_06 : 4; // PWM通道6
|
||||
unsigned int pwm_channel_07 : 4; // PWM通道7
|
||||
unsigned int pwm_channel_08 : 4; // PWM通道8
|
||||
unsigned int pwm_reserve_01 : 4; // 保留pwm1
|
||||
unsigned int pwm_reserve_02 : 4; // 保留pwm2
|
||||
unsigned int pwm_reserve_03 : 4; // 保留pwm3
|
||||
unsigned int pwm_reserve_04 : 4; // 保留pwm4
|
||||
unsigned int pwm_reserve_05 : 4; // 保留pwm5
|
||||
unsigned int pwm_reserve_06 : 4; // 保留pwm6
|
||||
unsigned int pwm_reserve_07 : 4; // 保留pwm7
|
||||
unsigned int pwm_reserve_08 : 4; // 保留pwm8
|
||||
} StrHBridgeOutput;
|
||||
|
||||
typedef union _UnHBridgeOutput
|
||||
{
|
||||
StrHBridgeOutput bit_data; // 使用定义的结构体变量名
|
||||
uint8_t arr[sizeof(StrHBridgeOutput)]; // 通过结构体类型确定大小
|
||||
} UnHBridgeOutput;
|
||||
|
||||
|
||||
// 输出给导航仪
|
||||
typedef struct _StrWheelSpeedOutput
|
||||
{
|
||||
//-----发送数据0x98----------------------------------------------
|
||||
unsigned int left_front : 16; // 左前轮速
|
||||
unsigned int right_front : 16; // 右前轮速
|
||||
unsigned int left_rear : 16; // 左后轮速
|
||||
unsigned int right_rear : 16; // 右后轮速
|
||||
} StrWheelSpeedOutput;
|
||||
|
||||
typedef union _UnWheelSpeedOutput
|
||||
{
|
||||
StrWheelSpeedOutput bit_data; // 使用定义的结构体变量名
|
||||
uint8_t arr[sizeof(StrWheelSpeedOutput)]; // 通过结构体类型确定大小
|
||||
} UnWheelSpeedOutput;
|
||||
|
||||
|
||||
// 输出给基站升降杆
|
||||
typedef struct _StrLifterOutput
|
||||
{
|
||||
//-----发送数据0x6F2----------------------------------------------
|
||||
unsigned int cmd : 8 ; // 上升命令
|
||||
unsigned int reserve1 : 8 ; // 保留
|
||||
unsigned int reserve2 : 16; // 保留
|
||||
unsigned int reserve3 : 16; // 保留
|
||||
unsigned int reserve4 : 16; // 保留
|
||||
} StrLifterOutput;
|
||||
|
||||
typedef union _UnrLifterOutput
|
||||
{
|
||||
StrLifterOutput bit_data; // 使用定义的结构体变量名
|
||||
uint8_t arr[sizeof(StrLifterOutput)]; // 通过结构体类型确定大小
|
||||
} UnLifterOutput;
|
||||
|
||||
|
||||
//-----以太网-------------------------------------------------------------
|
||||
// 输出给自主计算机
|
||||
typedef struct _StrComputerOutput
|
||||
{
|
||||
//--------------------------------------------------
|
||||
unsigned int frame_header : 16; // 帧头 0xFFCC
|
||||
unsigned int frame_type : 16; // 帧类型 0x0011
|
||||
unsigned int frame_length : 8; // 帧长 0x000b,11
|
||||
unsigned int accumulated : 8; // 累加值
|
||||
unsigned int speed : 16; // 左侧轮速
|
||||
unsigned int curvature : 16; // 右侧轮速
|
||||
unsigned int crc : 8; // CRC
|
||||
} StrComputerOutput;
|
||||
|
||||
typedef union _UnComputerOutput
|
||||
{
|
||||
StrComputerOutput bit_data; // 使用定义的结构体变量名
|
||||
uint8_t arr[sizeof(StrComputerOutput)]; // 通过结构体类型确定大小
|
||||
} UnComputerOutput;
|
||||
|
||||
|
||||
|
||||
|
||||
// 车辆信息,输出给上位机
|
||||
typedef struct _StrVehicleInfoOutput
|
||||
{
|
||||
//--------------------------------------------------
|
||||
unsigned int frame_header : 16; // 帧头
|
||||
unsigned int frame_type : 16; // 帧类型
|
||||
unsigned int frame_length : 16; // 帧长
|
||||
unsigned int accumulated : 8; // 累加值
|
||||
unsigned int desired_speed : 16; // 期望速度
|
||||
unsigned int desired_curvature : 16; // 期望曲率
|
||||
unsigned int set_left_speed : 16; // 设定左转速度
|
||||
unsigned int set_right_speed : 16; // 设定右转速度
|
||||
unsigned int longitude : 32; // 经度
|
||||
unsigned int latitude : 32; // 纬度
|
||||
unsigned int altitude : 32; // 高度
|
||||
unsigned int heading_angle : 16; // 航向角
|
||||
unsigned int speed : 16; // 当前车速
|
||||
unsigned int curvature : 16; // 当前曲率
|
||||
unsigned int battery_voltage : 16; // 电池电压
|
||||
unsigned int battery_soc : 16; // 电池SOC
|
||||
unsigned int battery_current : 16; // 电池电流
|
||||
unsigned int vehicle_fault_state : 8; // 整车故障状态
|
||||
unsigned int crc : 8; // CRC
|
||||
} StrVehicleInfoOutput;
|
||||
|
||||
typedef union _UnVehicleInfoOutput
|
||||
{
|
||||
StrVehicleInfoOutput bit_data; // 使用定义的结构体变量名
|
||||
unsigned char arr[sizeof(StrVehicleInfoOutput)]; // 通过结构体类型确定大小
|
||||
} UnVehicleInfoOutput;
|
||||
|
||||
|
||||
|
||||
|
||||
// 电机状态信息,输出给上位机
|
||||
typedef struct _StrMotorStatusOutput
|
||||
{
|
||||
//--------------------------------------------------
|
||||
unsigned int frame_header : 16; // 帧头 固定值0xAACC
|
||||
unsigned int frame_type : 16; // 帧类型 固定值0x0021
|
||||
unsigned int frame_length : 16; // 帧长 固定值30
|
||||
unsigned int accumulated : 8; // 累加值 按帧累加
|
||||
unsigned int left_wheel_speed : 16; // 当前左侧轮速 系数 1 偏移量 -30000 单位rad/min
|
||||
unsigned int right_wheel_speed : 16; // 当前右侧轮速 系数 1 偏移量 -30000 单位rad/min
|
||||
unsigned int left_torque : 16; // 左侧电机扭矩 系数 0.01 偏移量 -300 单位N/s
|
||||
unsigned int right_torque : 16; // 右侧电机扭矩 系数 0.01 偏移量 -300 单位N/s
|
||||
unsigned int left_fault_code : 8; // 左侧电机故障码
|
||||
unsigned int right_fault_code : 8; // 右侧电机故障码
|
||||
unsigned int left_torque_limit : 16; // 左侧电机扭矩限制
|
||||
unsigned int right_torque_limit : 16; // 右侧电机扭矩限制
|
||||
unsigned int left_power_in : 16; // 左侧电机馈电功率
|
||||
unsigned int right_power_in : 16; // 右侧电机馈电功率
|
||||
unsigned int left_power_out : 16; // 左侧电机放电功率
|
||||
unsigned int right_power_out : 16; // 右侧电机放电功率
|
||||
unsigned int left_voltage : 16; // 左侧电机电压
|
||||
unsigned int right_voltage : 16; // 右侧电机电压
|
||||
unsigned int checksum : 8; // 校验和 按字节累加之和 取低8位
|
||||
} StrMotorStatusOutput;
|
||||
|
||||
typedef union _UnMotorStatusOutput
|
||||
{
|
||||
StrMotorStatusOutput bit_data; // 使用定义的结构体变量名
|
||||
unsigned char arr[sizeof(StrMotorStatusOutput)]; // 通过结构体类型确定大小
|
||||
} UnMotorStatusOutput;
|
||||
|
||||
|
||||
|
||||
|
||||
// PID参数输出,输出给上位机
|
||||
typedef struct _StrPIDOutput
|
||||
{
|
||||
//--------------------------------------------------
|
||||
unsigned int frame_header : 16; // 帧头
|
||||
unsigned int frame_type : 16; // 帧类型
|
||||
unsigned int frame_length : 16; // 帧长
|
||||
unsigned int accumulated : 8; // 累加值
|
||||
unsigned int rc_straight_p : 32; // 遥控直行P参数
|
||||
unsigned int rc_straight_i : 32; // 遥控直行I参数
|
||||
unsigned int rc_straight_d : 32; // 遥控直行D参数
|
||||
unsigned int auto_straight_p : 32; // 自主直行P参数
|
||||
unsigned int auto_straight_i : 32; // 自主直行I参数
|
||||
unsigned int auto_straight_d : 32; // 自主直行D参数
|
||||
unsigned int rc_turn_p : 32; // 遥控转弯P参数
|
||||
unsigned int rc_turn_i : 32; // 遥控转弯I参数
|
||||
unsigned int rc_turn_d : 32; // 遥控转弯D参数
|
||||
unsigned int auto_turn_p : 32; // 自主转弯P参数
|
||||
unsigned int auto_turn_i : 32; // 自主转弯I参数
|
||||
unsigned int auto_turn_d : 32; // 自主转弯D参数
|
||||
unsigned int checksum : 8; // 校验和
|
||||
} StrPIDOutput;
|
||||
|
||||
typedef union _UnPIDOutput
|
||||
{
|
||||
StrPIDOutput bit_data; // 使用定义的结构体变量名
|
||||
unsigned char arr[sizeof(StrPIDOutput)]; // 通过结构体类型确定大小
|
||||
} UnPIDOutput;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 模拟信号输出,输出给上位机
|
||||
typedef struct _StrAnalogSignalOutput
|
||||
{
|
||||
//--------------------------------------------------
|
||||
unsigned int frame_header : 16; // 帧头 固定值0xAACC
|
||||
unsigned int frame_type : 16; // 帧类型 固定值0x0023
|
||||
unsigned int frame_length : 16; // 帧长 固定值24
|
||||
unsigned int accumulated : 8; // 累加值 按帧累加
|
||||
unsigned int channel_1 : 16; // 通道1 温度传感器 系数为0.1 有符号 正数表示正温度,负数标表示负温度
|
||||
unsigned int channel_2 : 16; // 通道2
|
||||
unsigned int channel_3 : 16; // 通道3
|
||||
unsigned int channel_4 : 16; // 通道4
|
||||
unsigned int channel_5 : 16; // 通道5 温度传感器 系数为0.1 有符号 正数表示正温度,负数标表示负温度
|
||||
unsigned int channel_6 : 16; // 通道6
|
||||
unsigned int channel_7 : 16; // 通道7
|
||||
unsigned int channel_8 : 16; // 通道8
|
||||
unsigned int crc : 8 ; // 校验和 按字节累加之和 取低8位
|
||||
|
||||
} StrAnalogSignalOutput;
|
||||
|
||||
typedef union _UnAnalogSignalOutput
|
||||
{
|
||||
StrAnalogSignalOutput bit_data; // 使用定义的结构体变量名
|
||||
unsigned char arr[sizeof(StrAnalogSignalOutput)]; // 通过结构体类型确定大小
|
||||
} UnAnalogSignalOutput;
|
||||
|
||||
|
||||
|
||||
// 遥控器数据输出,给上位机
|
||||
typedef struct _StrRemoteControlOutput
|
||||
{
|
||||
//--------------------------------------------------
|
||||
unsigned int frame_header : 16; // 帧头 固定值0xAACC
|
||||
unsigned int frame_type : 16; // 帧类型 固定值0x0024
|
||||
unsigned int frame_length : 16; // 帧长 固定值20
|
||||
unsigned int accumulated : 8; // 累加值 按帧累加
|
||||
|
||||
// RC6GS遥控原始数据
|
||||
unsigned int speed : 16; // 速度 系数0.01,正为前进,负为后退 单位m/s
|
||||
unsigned int curvature : 16; // 曲率 系数0.0001,正为左转,负为右转
|
||||
unsigned int reserve_1 : 16; // 备用1
|
||||
|
||||
unsigned int switch_a : 1; // SwA
|
||||
unsigned int switch_b : 2; // SwB 0和2刹车状态 1正常状态
|
||||
unsigned int switch_c : 2; // SwC 0和2自主状态 1手动状态
|
||||
unsigned int switch_d : 1; // SwD
|
||||
unsigned int hv_relay_state : 1; // 高压继电机状态 0 断开, 1开启
|
||||
unsigned int reserve_2 : 1; // 备用
|
||||
unsigned int enable : 8; // 使能 1遥控数据有效,0无效
|
||||
unsigned int accumulated_value : 16; // 接收累加值
|
||||
unsigned int crc : 8; // 校验和 按字节累加之和 取低8位
|
||||
} StrRemoteControlOutput;
|
||||
|
||||
typedef union _UnRemoteControlOutput
|
||||
{
|
||||
StrRemoteControlOutput bit_data; // 使用定义的结构体变量名
|
||||
unsigned char arr[sizeof(StrRemoteControlOutput)]; // 通过结构体类型确定大小
|
||||
} UnRemoteControlOutput;
|
||||
|
||||
|
||||
|
||||
// 手动控制数据,返回给请求者
|
||||
typedef struct _StrManualControlOutput
|
||||
{
|
||||
//--------------------------------------------------
|
||||
// 手动控制数据 高位在前,低位在后
|
||||
unsigned int frame_header : 16; // 帧头 固定值0xFFBB
|
||||
unsigned int frame_type : 16; // 帧类型 固定值0x0025
|
||||
unsigned int frame_length : 8; // 帧长 固定值0x0C
|
||||
unsigned int accumulated : 8; // 累加值 按帧累加
|
||||
unsigned int set_speed : 16; // 设定速度 系数0.01,正为前进,负为后退 单位m/s
|
||||
unsigned int set_curvature : 16; // 设定曲率 系数0.0001,正为左转,负为右转
|
||||
unsigned int reserved : 8; // 保留
|
||||
unsigned int crc_1 : 8 ; // CRC 按字节累加之和,溢出取低8位
|
||||
unsigned int accumulated_value : 16; // 接收累加值
|
||||
unsigned int crc_2 : 8 ; // CRC 按字节累加之和,溢出取低8位
|
||||
} StrManualControlOutput;
|
||||
|
||||
typedef union _UnManualControlOutput
|
||||
{
|
||||
StrManualControlOutput bit_data; // 使用定义的结构体变量名
|
||||
unsigned char arr[sizeof(StrManualControlOutput)]; // 通过结构体类型确定大小
|
||||
} UnManualControlOutput;
|
||||
|
||||
|
||||
|
||||
|
||||
// 自动控制数据输出,返回给请求者
|
||||
typedef struct _StrAutoControlOutput
|
||||
{
|
||||
//--------------------------------------------------
|
||||
// 自主计算机自动数据 高位在前,低位在后
|
||||
unsigned int frame_header : 16; // 帧头 固定值0xFFCC
|
||||
unsigned int frame_type : 16; // 帧类型 固定值0x0026
|
||||
unsigned int frame_length : 8; // 帧长 固定值0x19
|
||||
unsigned int accumulated : 8; // 累加值 按帧累加
|
||||
unsigned int set_speed : 16; // 设定速度 系数0.01,正为前进,负为后退 单位m/s
|
||||
unsigned int set_curvature : 16; // 设定曲率 系数0.0001,正为左转,负为右转
|
||||
unsigned int latitude : 32; // 纬度 系数10^-7,431234567表示43.1234567度
|
||||
unsigned int longitude : 32; // 经度 系数10^-7,431234567表示43.1234567度
|
||||
unsigned int altitude : 32; // 高度 单位mm
|
||||
unsigned int heading : 16; // 航向 车辆航向,35999表示359.99度。
|
||||
unsigned int accumulated_value : 16; // 累加值 按帧累加
|
||||
unsigned int crc : 8 ; // CRC 总体累加CRC
|
||||
} StrAutoControlOutput;
|
||||
|
||||
typedef union _UnAutoControlOutput
|
||||
{
|
||||
StrAutoControlOutput bit_data; // 使用定义的结构体变量名
|
||||
unsigned char arr[sizeof(StrAutoControlOutput)]; // 通过结构体类型确定大小
|
||||
} UnAutoControlOutput;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//-----IO口---------------------------------------------------------------
|
||||
// 电压信号输出,到遥控器
|
||||
typedef struct _StrVoltageSignalOutput
|
||||
{
|
||||
unsigned int pwm_value : 16; // PWM值
|
||||
} StrVoltageSignalOutput;
|
||||
|
||||
typedef union _UnVoltageSignalOutput
|
||||
{
|
||||
StrVoltageSignalOutput bit_data; // 使用定义的结构体变量名
|
||||
uint8_t arr[sizeof(StrVoltageSignalOutput)]; // 通过结构体类型确定大小
|
||||
} UnVoltageSignalOutput;
|
||||
|
||||
|
||||
|
||||
//外部数据结构声明
|
||||
extern UnMotorInput un_motor_input1 ;//电机控制器1 左侧
|
||||
extern UnMotorInput un_motor_input2 ;//电机控制器2 右侧
|
||||
extern UnMotorInput un_motor_input3 ;//电机控制器1 左后侧
|
||||
extern UnMotorInput un_motor_input4 ;//电机控制器2 右后侧
|
||||
extern UnBmsInput un_bms_input ;//BMS接收数据
|
||||
extern UnTempModuleInput un_temp_module_input;//温度采集模块
|
||||
extern UnAutoComputerInput un_auto_computer_input;//自主计算机自动数据
|
||||
extern UnManualComputerInput un_manual_computer_input;//自主计算机手动数据
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
extern UnMotorOutput un_motor_output1; //电机输出
|
||||
extern UnMotorOutput un_motor_output2; //电机输出
|
||||
extern UnMotorOutput un_motor_output3; //电机输出
|
||||
extern UnMotorOutput un_motor_output4; //电机输出
|
||||
extern UnInfCanKGFOutput un_inf_can_kgf_output1;
|
||||
extern UnInfCanKGFOutput un_inf_can_kgf_output2;
|
||||
extern UnHBridgeOutput un_h_bridge_output;
|
||||
extern UnHBridgeOutput un_h_bridge_output1;
|
||||
extern UnHBridgeOutput un_h_bridge_output2;
|
||||
extern UnWheelSpeedOutput un_wheel_wpeed_output;
|
||||
extern UnLifterOutput un_lifter_output;//基站升降杆输出
|
||||
|
||||
extern UnSdoOutput un_sdo_output1 ;//设定转向电机位置
|
||||
extern UnSdoOutput un_sdo_output2 ;//设定转向电机速度
|
||||
extern UnSdoOutput un_sdo_output3 ;//使能向下一个点
|
||||
extern UnSdoOutput un_sdo_output4 ;//设定电机使能
|
||||
extern UnSdoOutput un_sdo_output5 ;//设置电机模式
|
||||
extern UnSdoOutput un_sdo_output6 ;//接收数据
|
||||
extern UnSdoOutput un_sdo_output7 ;//发送使能数据
|
||||
//串口
|
||||
extern UnRemoteControlInput un_remote_control_input; //遥控器输入
|
||||
|
||||
//IO口
|
||||
extern UnSwSample un_sw_sample;
|
||||
|
||||
//以太网
|
||||
extern UnRequestFrame un_request_frame; //请求帧
|
||||
|
||||
extern UnComputerOutput un_computer_output; //输出给自主计算机
|
||||
|
||||
//输出给上位机
|
||||
extern UnVehicleInfoOutput un_vehicle_Info_output; // 车辆信息,输出给上位机
|
||||
extern UnMotorStatusOutput un_motor_status_output; // 电机状态信息,输出给上位机
|
||||
extern UnPIDOutput un_pid_output; // PID参数输出,输出给上位机
|
||||
extern UnAnalogSignalOutput un_analog_signal_output; // 模拟信号输出,输出给上位机
|
||||
extern UnRemoteControlOutput un_remote_control_output;// 遥控器数据输出,给上位机
|
||||
extern UnManualControlOutput un_manual_control_output;// 手动控制数据,返回给请求者
|
||||
extern UnAutoControlOutput un_auto_control_output; // 自动控制数据输出,返回给请求者
|
||||
extern UnSdoOutput un_sdo_output ;//转向电机输出
|
||||
|
||||
|
||||
//变量
|
||||
extern uint8_t test_app[26];
|
||||
|
||||
|
||||
|
||||
|
||||
//函数
|
||||
void canSendAll(void *signal_id);
|
||||
void ethernetSendAll(void *signal_id);
|
||||
|
||||
#pragma pack()
|
||||
|
||||
#endif /* _INTERFACE_H_ */
|
||||
@@ -0,0 +1,428 @@
|
||||
|
||||
|
||||
#include <sdrv_gpio.h>
|
||||
#include <udelay/udelay.h>
|
||||
#include <debug.h>
|
||||
#include "sdrv_spi.h"
|
||||
#include "irq_num.h"
|
||||
#include "clock_ip.h"
|
||||
|
||||
|
||||
|
||||
#include "interface_config.h"
|
||||
|
||||
|
||||
#define _nop_() udelay(1);
|
||||
#define somenop {_nop_();_nop_();_nop_();_nop_();_nop_();}
|
||||
#define bit bool
|
||||
|
||||
#define MASTER_TEST_LEN 100//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E0B7A2>100<30><30><EFBFBD>ֽڵ<D6BD><DAB5><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
static uint8_t m_rx_buf_u8[MASTER_TEST_LEN] __attribute__((__aligned__(32)));
|
||||
static uint8_t m_tx_buf_u8[MASTER_TEST_LEN] __attribute__((__aligned__(32)));
|
||||
|
||||
static struct sdrv_spi g_master;
|
||||
|
||||
void iic_start(void);
|
||||
void iic_stop(void);
|
||||
void iic_ack(bit ackbit);
|
||||
void iic_sendbyte(unsigned char byt);
|
||||
//void wrbyte_24c02(unsigned int add,unsigned char dat);
|
||||
void delay(unsigned char t);
|
||||
|
||||
bit iic_waitack(void);
|
||||
unsigned char i2c_recbyte(void);
|
||||
unsigned char rdbyte_24c02(unsigned int add);
|
||||
unsigned char wrEE_CRC_Bak(unsigned char add,unsigned char *eeData,unsigned char len,unsigned char addbak);
|
||||
unsigned char rdEE_CRC_Bak(unsigned char add,unsigned char *eeData,unsigned char len,unsigned char addbak);
|
||||
|
||||
|
||||
////FM25CL64ָ<34><EFBFBD><EEB6A8>
|
||||
#define FM25CL64_WREN 0x06 //ʹ<><CAB9>
|
||||
#define FM25CL64_WRDI 0x04 //ʧ<><CAA7>
|
||||
#define FM25CL64_RDSR 0x05 //<2F><>״̬
|
||||
#define FM25CL64_WRSR 0x01 //д״̬
|
||||
#define FM25CL64_READ 0x03 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define FM25CL64_WRITE 0x02 //д<><D0B4><EFBFBD><EFBFBD>
|
||||
|
||||
|
||||
|
||||
#define MAX_FM25CL64_LEN 8192//8k<38>ֽ<EFBFBD>
|
||||
|
||||
static const struct spi_device_config device_mode0_8bits_ss0 = {
|
||||
.sclk_freq = 1000000,
|
||||
.cpol = SCK_IDLE_LOW,
|
||||
.cpha = DATA_CPT_ON_FIRST_SCK_EDGE,
|
||||
.cs_pol = CS_ACTIVE_LOW,
|
||||
.cs_sel = CS_SEL_SS0,
|
||||
.width = SPI_DATA_WIDTH_BYTE,
|
||||
.fream_delay = 0,
|
||||
.clk2cs_delay = 0,
|
||||
.clk2cs_end_delay = 0,
|
||||
.is_lsb_mode = false,
|
||||
|
||||
};
|
||||
|
||||
static struct spi_common_config spi_master = {
|
||||
.is_spi_mode = true,
|
||||
.is_half_mode = false,
|
||||
.is_master = true,
|
||||
.base = APB_SPI6_BASE,
|
||||
.irq = SPI6_SPI_INTR_NUM,
|
||||
#if CONFIG_E3
|
||||
.clk = &g_ckgen_ip_spi_sf_1_to_4,
|
||||
#else
|
||||
.clk = &g_ckgen_ip_spi_sf_1_to_3,
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void initSpi()
|
||||
{
|
||||
/* Init Spi Instance */
|
||||
sdrv_spi_init(&g_master, &spi_master);
|
||||
sdrv_spi_config_device(&g_master, &device_mode0_8bits_ss0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void SDAOut(bit c)
|
||||
{
|
||||
// sdrv_pinctrl_set_input_select(GPIO_Y3, PIN_IS_CMOS);
|
||||
// sdrv_gpio_set_pin_direction(GPIO_Y3, GPIO_DIR_OUT);
|
||||
sdrv_gpio_set_pin_output_level(GPIO_Y3, c);
|
||||
}
|
||||
|
||||
void SCLOut(bit c)
|
||||
{
|
||||
sdrv_gpio_set_pin_output_level(GPIO_Y2, c);
|
||||
}
|
||||
|
||||
void iic_start(void)
|
||||
{
|
||||
SDAOut(1);
|
||||
_nop_();
|
||||
SCLOut(1);
|
||||
somenop;
|
||||
SDAOut(0);
|
||||
somenop;
|
||||
SCLOut(0);
|
||||
}
|
||||
|
||||
void iic_stop(void)
|
||||
{
|
||||
SDAOut(0);
|
||||
_nop_();
|
||||
SCLOut(1);
|
||||
somenop;
|
||||
SDAOut(1);
|
||||
}
|
||||
|
||||
void iic_ack(bit ackbit)
|
||||
{
|
||||
if(ackbit)
|
||||
SDAOut(0);
|
||||
else
|
||||
SDAOut(1);
|
||||
somenop;
|
||||
SCLOut(1);
|
||||
somenop;
|
||||
SCLOut(0);
|
||||
SDAOut(1);
|
||||
somenop;
|
||||
}
|
||||
|
||||
bit iic_waitack(void)
|
||||
{
|
||||
SDAOut(1);
|
||||
somenop;
|
||||
SCLOut(1);
|
||||
// sdrv_pinctrl_set_input_select(GPIO_Y3, PIN_IS_CMOS_SCHMITT);
|
||||
// sdrv_gpio_set_pin_direction(GPIO_Y3, GPIO_DIR_IN);
|
||||
somenop;
|
||||
if(sdrv_gpio_read_pin_input_level(GPIO_Y3))
|
||||
{
|
||||
SCLOut(0);
|
||||
iic_stop();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
SCLOut(0);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void iic_sendbyte(unsigned char byt)
|
||||
{
|
||||
unsigned char i;
|
||||
for(i=0;i<8;i++)
|
||||
{
|
||||
if(byt&0x80)
|
||||
SDAOut(1);
|
||||
else
|
||||
SDAOut(0);
|
||||
somenop;
|
||||
SCLOut(1);
|
||||
byt <<= 1;
|
||||
somenop;
|
||||
SCLOut(0);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char iic_recbyte(void)
|
||||
{
|
||||
unsigned char da;
|
||||
unsigned char i;
|
||||
for(i=0;i<8;i++)
|
||||
{
|
||||
SCLOut(1);
|
||||
// sdrv_pinctrl_set_input_select(GPIO_Y3, PIN_IS_CMOS_SCHMITT);
|
||||
// sdrv_gpio_set_pin_direction(GPIO_Y3, GPIO_DIR_IN);
|
||||
somenop;
|
||||
da <<= 1;
|
||||
|
||||
// P1_IOCR01 = 0x0020; // load port control register 1
|
||||
if(sdrv_gpio_read_pin_input_level(GPIO_Y3))
|
||||
da |= 0x01;
|
||||
SCLOut(0);
|
||||
somenop;
|
||||
}
|
||||
return da;
|
||||
}
|
||||
|
||||
unsigned char wrbyte_24c02(unsigned int add,unsigned char dat)
|
||||
{
|
||||
#if EN_24C02
|
||||
unsigned char eeprom_page = 0;
|
||||
unsigned char eeprom_add = 0;
|
||||
unsigned char device_add = 0;
|
||||
//-------------------------------------------------
|
||||
|
||||
eeprom_page = add/256;//ҳ
|
||||
eeprom_add = add%256;
|
||||
if(eeprom_page >= 3)//ĿǰE2һ<32><D2BB>4ҳ<34><D2B3>1k
|
||||
{
|
||||
eeprom_page = 3;
|
||||
}
|
||||
// Device Address 1100 0 p1 p0 R/W
|
||||
device_add = (0xa0 | (eeprom_page << 1));//
|
||||
|
||||
// ssdk_printf(SSDK_CRIT, "eeprom_page:0x%x\r\n", eeprom_page);
|
||||
// ssdk_printf(SSDK_CRIT, "eeprom_add:0x%x\r\n", eeprom_add);
|
||||
// ssdk_printf(SSDK_CRIT, "device_add:0x%x\r\n", device_add);
|
||||
|
||||
iic_start();
|
||||
iic_sendbyte(device_add);
|
||||
iic_waitack();
|
||||
iic_sendbyte(eeprom_add);
|
||||
iic_waitack();
|
||||
iic_sendbyte(dat);
|
||||
iic_waitack();
|
||||
iic_stop();
|
||||
#else
|
||||
if(add >= MAX_FM25CL64_LEN)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>
|
||||
{
|
||||
printf("E2 len error!\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_tx_buf_u8[0] = FM25CL64_WREN;//дʹ<D0B4><CAB9>
|
||||
if (sdrv_spi_sync_transmit(&g_master, m_tx_buf_u8, m_rx_buf_u8,1,1))
|
||||
{
|
||||
printf("E2 write Failed!\r\n");
|
||||
}
|
||||
|
||||
m_tx_buf_u8[0] = FM25CL64_WRITE;//д<><D0B4><EFBFBD><EFBFBD>
|
||||
m_tx_buf_u8[1] = (uint8_t)( add >> 8);// <20><>8λ<38><CEBB>ַ
|
||||
m_tx_buf_u8[2] = (uint8_t)( add );//
|
||||
m_tx_buf_u8[3] = dat;//
|
||||
|
||||
if (sdrv_spi_sync_transmit(&g_master, m_tx_buf_u8, m_rx_buf_u8,4,4))
|
||||
{
|
||||
printf("E2 write Failed!\r\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned char rdbyte_24c02(unsigned int add)
|
||||
{
|
||||
#if EN_24C02
|
||||
unsigned char eeprom_page = 0;
|
||||
unsigned char eeprom_add = 0;
|
||||
unsigned char device_add = 0;
|
||||
unsigned char da;
|
||||
//-------------------------------------------------
|
||||
|
||||
eeprom_page = add/256;//ҳ
|
||||
eeprom_add = add%256;
|
||||
if(eeprom_page >= 3)//ĿǰE2һ<32><D2BB>4ҳ<34><D2B3>1k
|
||||
{
|
||||
eeprom_page = 3;
|
||||
}
|
||||
|
||||
// Device Address 1100 000 R/W
|
||||
iic_start();
|
||||
device_add = (0xa0 | (eeprom_page << 1));// αд<CEB1><D0B4><EFBFBD><EFBFBD>
|
||||
iic_sendbyte(device_add);
|
||||
iic_waitack();
|
||||
iic_sendbyte(eeprom_add);
|
||||
iic_waitack();
|
||||
iic_start();
|
||||
|
||||
device_add = (0xa1 | (eeprom_page << 1));//
|
||||
|
||||
ssdk_printf(SSDK_CRIT, "device_add:0x%x\r\n", device_add);
|
||||
|
||||
iic_sendbyte(device_add);
|
||||
iic_waitack();
|
||||
da = iic_recbyte();
|
||||
iic_ack(0);
|
||||
iic_stop();
|
||||
//CAN_sendAck(add, da);
|
||||
return da;
|
||||
#else
|
||||
if(add >= MAX_FM25CL64_LEN)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>
|
||||
{
|
||||
printf("E2 len error!\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_tx_buf_u8[0] = FM25CL64_READ;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
m_tx_buf_u8[1] = (uint8_t)( add >> 8);// <20><>8λ<38><CEBB>ַ
|
||||
m_tx_buf_u8[2] = (uint8_t)( add );//
|
||||
m_tx_buf_u8[3] = 0xFF;//
|
||||
|
||||
if (sdrv_spi_sync_transmit(&g_master, m_tx_buf_u8, m_rx_buf_u8,4,4))
|
||||
{
|
||||
printf("E2 write Failed!\r\n");
|
||||
}
|
||||
|
||||
return m_rx_buf_u8[3];
|
||||
}
|
||||
#endif
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
|
||||
#ifdef _EEROM_CRC_
|
||||
#define POLY 0x1021
|
||||
/**
|
||||
* Calculating CRC-16 in 'C'
|
||||
* @para addr, start of data
|
||||
* @para num, length of data
|
||||
* @para crc, incoming CRC
|
||||
*/
|
||||
unsigned int crc16(unsigned char *addr, int num, unsigned int crc)
|
||||
{
|
||||
int i;
|
||||
for (; num > 0; num--) /* Step through bytes in memory */
|
||||
{
|
||||
crc = crc ^ ((*addr) << 8); /* Fetch byte from memory, XOR into CRC top byte*/
|
||||
addr++;
|
||||
for (i = 0; i < 8; i++) /* Prepare to rotate 8 bits */
|
||||
{
|
||||
if (crc & 0x8000) /* b15 is set... */
|
||||
crc = (crc << 1) ^ POLY; /* rotate and XOR with polynomic */
|
||||
else /* b15 is clear... */
|
||||
crc <<= 1; /* just rotate */
|
||||
} /* Loop for 8 bits */
|
||||
crc &= 0xFFFF; /* Ensure CRC remains 16-bit value */
|
||||
} /* Loop until num=0 */
|
||||
return(crc); /* Return updated CRC */
|
||||
}
|
||||
|
||||
//д<><D0B4><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD>Զ<EFBFBD>дһ<D0B4><D2BB><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD><CDB2><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
||||
unsigned char wrEE_CRC_Bak(unsigned char add,unsigned char *eeData,unsigned char len,unsigned char addbak)
|
||||
{
|
||||
uword crc_Res;
|
||||
unsigned char index;
|
||||
unsigned char flagEEwrOK;
|
||||
|
||||
crc_Res = crc16(eeData, len-2, 0xffff); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>У<EFBFBD><D0A3>
|
||||
eeData[len-2] = (ubyte)(crc_Res );
|
||||
eeData[len-1] = (ubyte)(crc_Res >> 8);
|
||||
|
||||
for(index=0;index<len;index++) //д<><D0B4><EFBFBD><EFBFBD>
|
||||
{WDT_vServiceWDT();
|
||||
wrbyte_24c02( add + index, eeData[index]);
|
||||
}
|
||||
flagEEwrOK = 1;
|
||||
|
||||
for(index=0;index<len;index++) //У<><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{WDT_vServiceWDT();
|
||||
if(rdbyte_24c02( add + index) != eeData[index])
|
||||
{
|
||||
flagEEwrOK = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(1 == flagEEwrOK) //
|
||||
{
|
||||
for(index=0;index<len;index++) //д<><D0B4><EFBFBD>ݺ<EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{WDT_vServiceWDT();
|
||||
wrbyte_24c02( addbak + index, eeData[index]);
|
||||
}
|
||||
flagEEwrOK = 2;
|
||||
for(index=0;index<len;index++)
|
||||
{WDT_vServiceWDT();
|
||||
if(rdbyte_24c02( addbak + index) != eeData[index])
|
||||
{ flagEEwrOK = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
flagEEwrOK = 0;
|
||||
//.........
|
||||
}
|
||||
return flagEEwrOK;
|
||||
}
|
||||
unsigned char rdEE_CRC_Bak(unsigned char add,unsigned char *eeData,unsigned char len,unsigned char addbak)
|
||||
{
|
||||
uword crc_Res;
|
||||
unsigned char index;
|
||||
unsigned char reEEok = 0;
|
||||
|
||||
for(index=0;index<len;index++) //<2F><><EFBFBD><EFBFBD><EFBFBD>ݺ<EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{WDT_vServiceWDT();
|
||||
eeData[index] = rdbyte_24c02(add + index);
|
||||
}
|
||||
crc_Res = crc16(eeData, len-2, 0xffff); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>У<EFBFBD><D0A3>
|
||||
if( crc_Res == ((uword)eeData[len-1] << 8) + (uword)eeData[len-2]) //<2F>Աȶ<D4B1>ȡ<EFBFBD><C8A1>У<EFBFBD><D0A3>ֵ <20><>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>EEֵ<45><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ...
|
||||
{
|
||||
reEEok = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(index=0;index<len;index++) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݺ<EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{WDT_vServiceWDT();
|
||||
eeData[index] = rdbyte_24c02(addbak + index);
|
||||
}
|
||||
crc_Res = crc16(eeData, len-2, 0xffff); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>У<EFBFBD><D0A3>
|
||||
if( crc_Res == ((uword)eeData[len-1] << 8) + (uword)eeData[len-2]) //<2F>Աȶ<D4B1>ȡ<EFBFBD><C8A1>У<EFBFBD><D0A3>ֵ <20><>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>EEֵ<45><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ...
|
||||
{
|
||||
reEEok = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
reEEok = 0;
|
||||
}
|
||||
}
|
||||
return reEEok;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef _INTERFACE_24C02_H_
|
||||
#define _INTERFACE_24C02_H_
|
||||
|
||||
#define _nop_() udelay(1);
|
||||
#define somenop {_nop_();_nop_();_nop_();_nop_();_nop_();}
|
||||
#define bit bool
|
||||
|
||||
|
||||
//#define EN_24C02 1
|
||||
|
||||
|
||||
void iic_start(void);
|
||||
void iic_stop(void);
|
||||
void iic_ack(bit ackbit);
|
||||
void iic_sendbyte(unsigned char byt);
|
||||
unsigned char wrbyte_24c02(unsigned int add,unsigned char dat);
|
||||
void delay(unsigned char t);
|
||||
|
||||
bit iic_waitack(void);
|
||||
unsigned char i2c_recbyte(void);
|
||||
unsigned char rdbyte_24c02(unsigned int add);
|
||||
unsigned char wrEE_CRC_Bak(unsigned char add,unsigned char *eeData,unsigned char len,unsigned char addbak);
|
||||
unsigned char rdEE_CRC_Bak(unsigned char add,unsigned char *eeData,unsigned char len,unsigned char addbak);
|
||||
|
||||
|
||||
void initSpi();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* _INTERFACE_24C02_H_ */
|
||||
@@ -0,0 +1,127 @@
|
||||
|
||||
#include <udelay/udelay.h>
|
||||
#include <reset_ip.h>
|
||||
#include <debug.h>
|
||||
#include <sdrv_gpio.h>
|
||||
#include <armv7-r/cache.h>
|
||||
#include "sdrv_rstgen.h"
|
||||
#include "interface_config.h"
|
||||
|
||||
|
||||
|
||||
uint16_t FrameHeader = 0;//֡ͷ
|
||||
bool boot_can_flag = false;//֡ͷ
|
||||
|
||||
SystemDataRecord g_systemDataRecord = {0,0,0,0};
|
||||
|
||||
bool WDTReFresh_flag = false;//
|
||||
|
||||
Timer boot_timer_interface;
|
||||
|
||||
|
||||
|
||||
void bootmian(void *signal_id)
|
||||
{
|
||||
static uint16_t bootmianSTT = 0;
|
||||
// uint32_t time_boot = getCurrentTime();//<2F><>¼<EFBFBD><C2BC>ǰʱ<C7B0><CAB1>
|
||||
//------------------------------------------------------------------------------
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
if(true == boot_can_flag)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD><D6BE><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>н<EFBFBD><D0BD>պ<EFBFBD><D5BA><EFBFBD>1
|
||||
{
|
||||
boot_can_flag = false;
|
||||
if(EXCUTE_APP == FrameHeader)//д<><D0B4>־0<D6BE><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>APP
|
||||
{
|
||||
printf("go to app!\r\n");
|
||||
wrbyte_24c02(Update_Flg_E2adr,NORMAL_ON); //д<><D0B4>־λΪ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>γ<EFBFBD><CEB3><EFBFBD>ֱ<EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD>app
|
||||
// udelay(3000);//<2F><>ʱ3ms
|
||||
g_systemDataRecord.canBootloaderUpgrade = rdbyte_24c02(Update_Flg_E2adr); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD>ι<EFBFBD><CEB9>
|
||||
|
||||
// sdrv_rstgen_global_reset(&rstctl_glb);
|
||||
for(;;)
|
||||
{
|
||||
printf("Restart!\r\n");
|
||||
}
|
||||
}
|
||||
else if(ENTER_UPDATE_MODE == FrameHeader)//д<><D0B4>־1<D6BE><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>boot
|
||||
{
|
||||
ssdk_printf(SSDK_INFO, "go to boot!\r\n");
|
||||
wrbyte_24c02(Update_Flg_E2adr,CAN_BOOTLOADER_UPGRADE); //д<><D0B4>־<EFBFBD><D6BE><EFBFBD><EFBFBD>
|
||||
// udelay(3000);//<2F><>ʱ3ms
|
||||
|
||||
// sdrv_rstgen_global_reset(&rstctl_glb);
|
||||
for(;;)
|
||||
{
|
||||
printf("Restart!\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//<2F>жϴ<D0B6>e2<65><32>ȡboot<6F><74>־<EFBFBD><EFBFBD><F3A3ACBE><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>APP<50><50>ʱι<CAB1><CEB9>
|
||||
if( CAN_BOOTLOADER_UPGRADE == (g_systemDataRecord.canBootloaderUpgrade) )//boot<6F><74>־
|
||||
{
|
||||
//boot<6F><74>־Ϊ1<CEAA><31><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD>boot<6F><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>ι<EFBFBD><CEB9>
|
||||
if(true == WDTReFresh_flag)//<2F><><EFBFBD>յ<EFBFBD>ID<49>Ÿ<EFBFBD><C5B8><EFBFBD>WDT <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>־<EFBFBD><D6BE>ι<EFBFBD><CEB9>
|
||||
{
|
||||
feedWatchdog();//ι<><CEB9>
|
||||
WDTReFresh_flag = false;
|
||||
}
|
||||
}
|
||||
else//APP<50>Լ<EFBFBD>ι<EFBFBD><CEB9>
|
||||
{
|
||||
bootmianSTT ++;
|
||||
if(bootmianSTT >= 5)//5*1000*100us = 500ms
|
||||
{
|
||||
bootmianSTT = 0;
|
||||
feedWatchdog();//ι<><CEB9>
|
||||
}
|
||||
}
|
||||
|
||||
timerStart(&boot_timer_interface, 100,0);
|
||||
|
||||
// printf("bootAPP spend time:%d\n",getCurrentTime() - time_boot);//<2F><><EFBFBD><EFBFBD>app<70><70><EFBFBD>˶ʱ<E0B3A4><CAB1>
|
||||
}
|
||||
|
||||
|
||||
|
||||
static uint32_t time_wdt = 0;
|
||||
// ι<><CEB9>
|
||||
void feedWatchdog(void)
|
||||
{
|
||||
sdrv_gpio_toggle_pin_output_level(WDTGPIO); //<2F>ⲿwdtι<74><CEB9>
|
||||
printf("WDT:%d \n",getCurrentTime() - time_wdt);
|
||||
time_wdt = getCurrentTime();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// APPģ<50><C4A3><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC>
|
||||
void bootInterfaceInit(void)
|
||||
{
|
||||
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
timerInit(&boot_timer_interface);
|
||||
// <20><><EFBFBD>Ķ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>źţ<C5BA><C5A3><EFBFBD><EFBFBD>ڶ<EFBFBD>ʱ<EFBFBD>ɼ<EFBFBD>
|
||||
subscribe(&boot_timer_interface, bootmian);
|
||||
|
||||
timerStart(&boot_timer_interface, 100,0); //100ms
|
||||
|
||||
feedWatchdog();//ι<><CEB9>,<2C><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ιһ<CEB9><D2BB>
|
||||
|
||||
printf("bootInterface: initial OK %d\n",getCurrentTime());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
|
||||
#ifndef __INTERFACE_BOOT_H_
|
||||
#define __INTERFACE_BOOT_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include "stdint.h"
|
||||
#include <rom_ctrl/rom_ctrl.h>
|
||||
|
||||
|
||||
|
||||
|
||||
//#define WDTGPIO GPIO_H13
|
||||
#define WDTGPIO GPIO_F5
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
volatile uint8_t canBootloaderUpgrade; //CAN<41><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ
|
||||
uint8_t test1;
|
||||
uint8_t test2;
|
||||
uint8_t test3;
|
||||
} SystemDataRecord;//<2F><><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>APPͬ<50><CDAC>
|
||||
|
||||
typedef enum{
|
||||
NORMAL_ON = 0,
|
||||
CAN_BOOTLOADER_UPGRADE,
|
||||
}UpgradeFlag;
|
||||
|
||||
|
||||
#define Update_Flg_E2adr 0x0 //ռ<><D5BC>1<EFBFBD><31><EFBFBD>ֽ<EFBFBD>
|
||||
#define BOOT0_VERSION_E2adr 0x1 //ռ<><D5BC>5<EFBFBD><35><EFBFBD>ֽ<EFBFBD> <20><><EFBFBD><EFBFBD>+ʱ<><CAB1>+<2B>汾<EFBFBD><E6B1BE> 20 24 08 08 01
|
||||
#define BOOT1_VERSION_E2adr 0x6 //ռ<><D5BC>5<EFBFBD><35><EFBFBD>ֽ<EFBFBD> <20><><EFBFBD><EFBFBD>+ʱ<><CAB1>+<2B>汾<EFBFBD><E6B1BE> 20 24 08 08 01
|
||||
#define APP_VERSION_E2adr 0xB //ռ<><D5BC>5<EFBFBD><35><EFBFBD>ֽ<EFBFBD> <20><><EFBFBD><EFBFBD>+ʱ<><CAB1>+<2B>汾<EFBFBD><E6B1BE> 20 24 08 08 01
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define ENTER_UPDATE_MODE 0x1
|
||||
#define READ_VERSION 0x100
|
||||
#define CRC_UPDATE 0x101
|
||||
#define Write_VERSION 0x103
|
||||
#define ENTER_APP 0x102
|
||||
#define EXCUTE_APP 0x02
|
||||
#define FEEDDOG_HEADER 0x200 //<2F><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>ι<EFBFBD><CEB9>can֡֡ͷ
|
||||
|
||||
//<2F>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD>
|
||||
void bootmian(void *signal_id);
|
||||
void reboot_global(sdrv_rom_ctrl_boot_mode_e boot_mode);
|
||||
void bootInterfaceInit(void);
|
||||
|
||||
|
||||
//<2F>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD>
|
||||
extern uint32_t OTA_CANTxID;//Ĭ<>Ϸ<EFBFBD><CFB7><EFBFBD>IDΪ0x02
|
||||
extern uint32_t OTA_CANRxID;//Ĭ<>Ͻ<EFBFBD><CFBD><EFBFBD>IDΪ0x01
|
||||
extern uint32_t WDT_CANRxID;//Ĭ<>Ͻ<EFBFBD><CFBD><EFBFBD>IDΪ0x03
|
||||
|
||||
extern SystemDataRecord g_systemDataRecord ;
|
||||
extern uint16_t FrameHeader;//֡ͷ
|
||||
extern bool boot_can_flag;//֡ͷ
|
||||
//ι<><CEB9>
|
||||
extern void feedWatchdog(void);
|
||||
|
||||
|
||||
#endif /*__INTERFACE_BOOT_H_*/
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
#include "regs_base.h"
|
||||
#include "irq_num.h"
|
||||
#include "sdrv_btm.h"
|
||||
|
||||
#include "interface_config.h"
|
||||
|
||||
//app<70><70><EFBFBD><EFBFBD>
|
||||
#include "app/app_config.h"
|
||||
|
||||
static sdrv_btm_t gstsdrv_btm_timer0;
|
||||
static sdrv_btm_t gstsdrv_btm_timer1;
|
||||
|
||||
volatile uint8_t Btm10ms = 0;
|
||||
|
||||
|
||||
#define DEVICE_BASE(dev) _DEVICE_BASE(dev)
|
||||
#define _DEVICE_BASE(dev) APB_##dev##_BASE
|
||||
|
||||
#define DEVICE_INTR(dev) _DEVICE_INTR(dev)
|
||||
#define _DEVICE_INTR(dev) dev##_INTR_NUM
|
||||
|
||||
|
||||
/*SDRV_BTM_G0ʱ<30><CAB1><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>APB clock, APB clock<63><6B><EFBFBD><EFBFBD>150MHz*/
|
||||
/*SDRV_BTM_G0<47><30>Ƶ֮<C6B5><D6AE><EFBFBD><EFBFBD>clock<63><6B><EFBFBD><EFBFBD>1M*/
|
||||
static sdrv_btm_cfg_t timer0_config = {
|
||||
.base = DEVICE_BASE(BTM2),
|
||||
.irq = DEVICE_INTR(BTM2_O_BTM),
|
||||
.tmr_id = SDRV_BTM_G0,
|
||||
.tmr_cfg = {
|
||||
.si_val = 74, /*<2A><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ÿ(si_val + 1)cycle, G0<47><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>inc_val<61><6C>*/
|
||||
.inc_val = 1,
|
||||
.frc_rld_rst_cnt_en = true, /*Ĭ<><C4AC><EFBFBD><EFBFBD>true<75><65><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ʼ<EFBFBD><CABC>ʱ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>counter<65><72><EFBFBD>㡣*/
|
||||
.term_use_mode = SDRV_BTM_DIRECT, /*<2A><><EFBFBD><EFBFBD>overflowֵ<77><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǵȵ<C7B5><C8B5><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>*/
|
||||
.cmp_use_mode = SDRV_BTM_DIRECT, /*<2A><><EFBFBD><EFBFBD>compareֵ<65><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǵȵ<C7B5><C8B5><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>*/
|
||||
.cnt_dir = SDRV_BTM_CNT_UP, /*<2A><><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
.cnt_mode = SDRV_BTM_CONTINOUS_MODE, /*<2A><><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ*/
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*SDRV_BTM_G1ʱ<31><CAB1><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD><F1A3ACB5><EFBFBD>24MHz*/
|
||||
/*SDRV_BTM_G1<47><31>Ƶ֮<C6B5><D6AE><EFBFBD><EFBFBD>clock<63><6B><EFBFBD><EFBFBD>1M*/
|
||||
static sdrv_btm_cfg_t timer1_config = {
|
||||
.base = DEVICE_BASE(BTM2),
|
||||
.irq = DEVICE_INTR(BTM2_O_BTM),
|
||||
.tmr_id = SDRV_BTM_G1,
|
||||
.tmr_cfg = {
|
||||
.si_val = 23,
|
||||
.inc_val = 1,
|
||||
.frc_rld_rst_cnt_en = true,
|
||||
.term_use_mode = SDRV_BTM_DIRECT,
|
||||
.cmp_use_mode = SDRV_BTM_DIRECT,
|
||||
.cnt_dir = SDRV_BTM_CNT_UP,
|
||||
.cnt_mode = SDRV_BTM_CONTINOUS_MODE,
|
||||
}
|
||||
};
|
||||
|
||||
//<2F>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>10ms<6D><73>ʱ<EFBFBD><CAB1>־
|
||||
static void timer1_handle(void *arg)
|
||||
{
|
||||
static int timer1_count = 0;
|
||||
timer1_count++;
|
||||
|
||||
if(timer1_count >= 100)
|
||||
{
|
||||
timer1_count = 0;
|
||||
Btm10ms = 1;
|
||||
}
|
||||
|
||||
//app
|
||||
timerUpdateAll(); // <20><><EFBFBD>ö<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>º<EFBFBD><C2BA><EFBFBD>
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD>g1<67><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
int btm_init(void)
|
||||
{
|
||||
sdrv_btm_init(&gstsdrv_btm_timer1, &timer0_config);//<2F><>ʱ<EFBFBD><CAB1>1<EFBFBD><31>ʼ<EFBFBD><CABC>
|
||||
sdrv_btm_set_callback(&gstsdrv_btm_timer1, timer1_handle, &gstsdrv_btm_timer1);//<2F>趨<EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
sdrv_btm_start(&gstsdrv_btm_timer1, BTM_TYPE_PERIOD, BTM_TIME_US, 1000);//<2F>趨1000us<75><73>ʱ
|
||||
|
||||
sdrv_btm_init(&gstsdrv_btm_timer0, &timer1_config);//<2F><>ʱ<EFBFBD><CAB1>0<EFBFBD><30>ʼ<EFBFBD><CABC>
|
||||
sdrv_btm_start(&gstsdrv_btm_timer0, BTM_TYPE_PERIOD, BTM_TIME_MS, ~0);//<2F>趨1ms<6D><73>ʱ
|
||||
return 0;
|
||||
}
|
||||
|
||||
//<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>,lwip<69><70>
|
||||
uint32_t current_time(void)
|
||||
{
|
||||
return sdrv_btm_get_current_time(&gstsdrv_btm_timer0) / 1000;
|
||||
}
|
||||
|
||||
//<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>us
|
||||
uint32_t getCurrentTime(void)
|
||||
{
|
||||
return sdrv_btm_get_current_time(&gstsdrv_btm_timer0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef __INTERFACE_BTM_H__
|
||||
#define __INTERFACE_BTM_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include "sdrv_btm.h"
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
extern volatile uint8_t Btm10ms;
|
||||
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int btm_init(void);
|
||||
extern uint32_t current_time(void);
|
||||
extern uint32_t getCurrentTime(void);
|
||||
|
||||
|
||||
#endif /* __BTM_INIT_H__ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,170 @@
|
||||
|
||||
#ifndef _INTERFACE_CAN_H_
|
||||
#define _INTERFACE_CAN_H_
|
||||
|
||||
#include "regs_base.h"
|
||||
#include "irq_num.h"
|
||||
#include <sdrv_flexcan.h>
|
||||
|
||||
|
||||
#define CAN_INDEX_0 FLEXCAN7
|
||||
#define CAN_INDEX_1 FLEXCAN21
|
||||
#define CAN_INDEX_2 FLEXCAN16
|
||||
#define CAN_INDEX_3 FLEXCAN3
|
||||
#define CAN_INDEX_4 FLEXCAN23
|
||||
#define CAN_INDEX_5 FLEXCAN5
|
||||
#define CAN_INDEX_6 FLEXCAN6
|
||||
#define CAN_INDEX_7 FLEXCAN4
|
||||
|
||||
|
||||
|
||||
#define TX_MB_INDEX (USED_MB_FOR_FIFO)
|
||||
|
||||
|
||||
//#define MOTOR_INPUT_ID_1 0x101
|
||||
//#define MOTOR_INPUT_ID_2 0x102
|
||||
|
||||
#define MOTOR_INPUT_ID_1 0x10F91708//<2F><>ǰ ת<><D7AA>
|
||||
#define MOTOR_INPUT_ID_2 0x10F92708//<2F><>ǰ
|
||||
#define MOTOR_INPUT_ID_3 0x10F93708//<2F><><EFBFBD><EFBFBD>
|
||||
#define MOTOR_INPUT_ID_4 0x10F94708//<2F>Һ<EFBFBD>
|
||||
|
||||
|
||||
#define MOTOR_INPUT_ID_5 0x10F81708//<2F><>ǰ <20><>λ
|
||||
#define MOTOR_INPUT_ID_6 0x10F82708//<2F><>ǰ
|
||||
#define MOTOR_INPUT_ID_7 0x10F83708//<2F><><EFBFBD><EFBFBD>
|
||||
#define MOTOR_INPUT_ID_8 0x10F84708//<2F>Һ<EFBFBD>
|
||||
|
||||
|
||||
|
||||
#define BMS_INPUT_ID1 0x100
|
||||
#define BMS_INPUT_ID2 0x101
|
||||
#define REMOTE_ID 0x12000023
|
||||
#define TEMP_MODULE_INPUT_ID_1 0x301
|
||||
#define TEMP_MODULE_INPUT_ID_2 0x302
|
||||
|
||||
|
||||
#define CAN_FIFO_SIZE 8
|
||||
|
||||
//#define TEMP_MODULE_INPUT_ID_2 0x302
|
||||
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
typedef struct _StrCanFault
|
||||
{
|
||||
uint8_t navigator_count; //<2F><><EFBFBD><EFBFBD><EFBFBD>Ǽ<EFBFBD><C7BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t motor1_count; //<2F>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t motor2_count; //<2F>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t bms_count; //bms<6D><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t temperature_count; //<2F>¶ȼ<C2B6><C8BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t remote_count; //ң<>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
uint8_t navigator_state; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
||||
uint8_t motor1_state; //<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD>״̬
|
||||
uint8_t motor2_state; //<2F><><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD>״̬
|
||||
uint8_t bms_state; //bms״̬
|
||||
uint8_t temperature_state; //<2F>¶ȼ<C2B6><C8BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t remote_state; //ң<><D2A3>״̬
|
||||
} StrCanFault;
|
||||
|
||||
typedef union _UnCanFault
|
||||
{
|
||||
StrCanFault bit_data; // ʹ<>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>Ľṹ<C4BD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t arr[sizeof(StrCanFault)]; // ͨ<><CDA8><EFBFBD>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>С
|
||||
} UnCanFault;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// can<61><6E><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>
|
||||
typedef struct _StrCanBuffer
|
||||
{
|
||||
uint32_t id; //**< CAN Frame Identifier. */
|
||||
uint8_t dataBuffer[8]; //<2F><><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD>
|
||||
unsigned int length : 7; //**< CAN frame payload length in bytes(Range: 0~8). */
|
||||
unsigned int type : 1; //**< CAN Frame Type(DATA or REMOTE). */
|
||||
unsigned int format : 1; //**< CAN Frame Identifier(STD or EXT format). */
|
||||
|
||||
}StrCanBuffer;
|
||||
|
||||
|
||||
|
||||
typedef struct Fifo_Queue_Tag
|
||||
{
|
||||
StrCanBuffer Data[CAN_FIFO_SIZE];//<2F><><EFBFBD><EFBFBD>
|
||||
uint8_t front;//ͷָ<CDB7><D6B8>
|
||||
uint8_t rear;//βָ<CEB2><D6B8>
|
||||
}StrCanFifoQueue;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define ON 1
|
||||
#define OFF 0
|
||||
|
||||
#define left_motor_fan(Value) un_inf_can_kgf_output1.bit_data.KGF01 = Value;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define right_motor_fan(Value) un_inf_can_kgf_output1.bit_data.KGF03 = Value;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define pre_charge_relay(Value) un_inf_can_kgf_output1.bit_data.KGF04 = Value;//Ԥ<><D4A4>
|
||||
#define high_voltage_relay(Value) un_inf_can_kgf_output1.bit_data.KGF07 = Value;un_inf_can_kgf_output1.bit_data.KGF08 = Value//<2F><>ѹ<EFBFBD>̵<EFBFBD><CCB5><EFBFBD>
|
||||
#define low_voltage_relay(Value) un_inf_can_kgf_output1.bit_data.KGF11 = Value;un_inf_can_kgf_output1.bit_data.KGF12 = Value//<2F><>ѹ<EFBFBD>̵<EFBFBD><CCB5><EFBFBD>
|
||||
#define yellow_light(Value) un_inf_can_kgf_output1.bit_data.KGF06 = Value;//<2F>Ƶ<EFBFBD>
|
||||
#define red_light(Value) un_inf_can_kgf_output1.bit_data.KGF09 = Value;//<2F><><EFBFBD><EFBFBD>
|
||||
#define left_vehicle_fan(Value) un_inf_can_kgf_output1.bit_data.KGF14 = Value;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define right_vehicle_fan(Value) un_inf_can_kgf_output2.bit_data.KGF03 = Value;//<2F><><EFBFBD>ҷ<EFBFBD><D2B7><EFBFBD>
|
||||
#define computer(Value) un_inf_can_kgf_output2.bit_data.KGF01 = Value;un_inf_can_kgf_output2.bit_data.KGF02 = Value//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define network_switch(Value) un_inf_can_kgf_output2.bit_data.KGF05 = Value;un_inf_can_kgf_output2.bit_data.KGF06 = Value//<2F><><EFBFBD>罻<EFBFBD><E7BDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD>
|
||||
|
||||
//H<><48>
|
||||
#define brake_motor_forward un_h_bridge_output.bit_data.channel_01 = ON ;un_h_bridge_output.bit_data.channel_04 = ON ;un_h_bridge_output.bit_data.channel_02 = OFF;un_h_bridge_output.bit_data.channel_03 = OFF;un_h_bridge_output.bit_data.sleep_01 = ON ;un_h_bridge_output.bit_data.sleep_02 = ON//<2F><>ת
|
||||
#define brake_motor_reversal un_h_bridge_output.bit_data.channel_01 = OFF;un_h_bridge_output.bit_data.channel_04 = OFF;un_h_bridge_output.bit_data.channel_02 = ON ;un_h_bridge_output.bit_data.channel_03 = ON ;un_h_bridge_output.bit_data.sleep_01 = ON ;un_h_bridge_output.bit_data.sleep_02 = ON//<2F><>ת
|
||||
#define brake_motor_off un_h_bridge_output.bit_data.channel_01 = OFF;un_h_bridge_output.bit_data.channel_04 = OFF;un_h_bridge_output.bit_data.channel_02 = OFF;un_h_bridge_output.bit_data.channel_03 = OFF;un_h_bridge_output.bit_data.sleep_01 = OFF;un_h_bridge_output.bit_data.sleep_02 = OFF//<2F>ر<EFBFBD>
|
||||
|
||||
|
||||
|
||||
|
||||
//<2F>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD>
|
||||
void flexcan_transfer_callback(flexcan_handle_t *handle,flexcan_status_e status, uint32_t result,void *userData);
|
||||
uint8_t flexcan_config_rx_fifo(flexcan_handle_t *handle,flexcan_rx_fifo_config_t *config);
|
||||
uint8_t CAN_Send_Msg( flexcan_handle_t *handle, uint32_t ID, flexcan_frame_format_e ide, flexcan_frame_type_e rtr, uint8_t *msg, uint8_t len, uint8_t tx_index);
|
||||
void flexcan_Busoff_Recovery(void);
|
||||
void initialization_All_Flexcan(void);
|
||||
|
||||
|
||||
|
||||
|
||||
//<2F>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD>
|
||||
extern flexcan_handle_t g_flexcan_handle;
|
||||
extern bool busoff_occur_flag;//<2F><>־<EFBFBD><D6BE>
|
||||
extern bool WDTReFresh_flag;//<2F><><EFBFBD>±<EFBFBD>־
|
||||
extern flexcan_handle_t g_flexcan_handle;
|
||||
extern uint16_t FrameHeader;//֡ͷ
|
||||
extern flexcan_handle_t can_handle_0;//can<61><6E>ʼ<EFBFBD><CABC><EFBFBD>ṹ<EFBFBD><E1B9B9>
|
||||
extern flexcan_handle_t can_handle_1;
|
||||
extern flexcan_handle_t can_handle_2;
|
||||
extern flexcan_handle_t can_handle_3;
|
||||
extern flexcan_handle_t can_handle_4;
|
||||
extern flexcan_handle_t can_handle_5;
|
||||
extern flexcan_handle_t can_handle_6;
|
||||
extern flexcan_handle_t can_handle_7;
|
||||
extern UnCanFault can_fault_info;
|
||||
|
||||
extern uint32_t time_elapsed;
|
||||
extern uint32_t time_elapsed1;
|
||||
|
||||
//<2F>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD>
|
||||
void canInterfaceInit(void);
|
||||
|
||||
|
||||
#endif /* INTERFACE_CAN_H */
|
||||
@@ -0,0 +1,70 @@
|
||||
#ifndef _INTERFACE_CONFIG_H_
|
||||
#define _INTERFACE_CONFIG_H_
|
||||
|
||||
//ͷ<>ļ<EFBFBD>
|
||||
#include "interface.h"
|
||||
#include "interface_can.h"
|
||||
#include "interface_gpio.h"
|
||||
#include "interface_ethernet.h"
|
||||
#include "interface_btm.h"
|
||||
#include "interface_boot.h"
|
||||
#include "interface_wdt.h"
|
||||
#include "interface_24c02.h"
|
||||
|
||||
#include "app/app_frm_monitor.h"
|
||||
#include "app/app_frm_signal.h"
|
||||
#include "app/app_frm_timer.h"
|
||||
|
||||
|
||||
|
||||
#include "irq.h"
|
||||
#include <sdrv_gpio.h>
|
||||
#include <rom_ctrl/rom_ctrl.h>
|
||||
#include "lwip/udp.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include "debug.h"
|
||||
#include <clock_ip.h>
|
||||
#include "board.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* _INTERFACE_CONFIG_H_ */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,820 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include "debug.h"
|
||||
#include <string.h>
|
||||
#include <udelay/udelay.h>
|
||||
#include "interface_ethernet.h"
|
||||
#include "eth_cfg.h"
|
||||
#include "lwip/timeouts.h"
|
||||
#include "sdrv_eth.h"
|
||||
#include "app/app_param_manage.h"
|
||||
#include "app/app_differential_drive.h"
|
||||
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define MAX_BUFFER_SIZE (sizeof(((RequestContext *)0)->param_request->arr))
|
||||
#define MAX_PACKET_SIZE 1024 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>СΪ1K
|
||||
|
||||
Timer ethernet_timer_interface;
|
||||
Timer ethernet_timer_interface1;
|
||||
|
||||
struct udp_pcb *udpcb_1;
|
||||
struct udp_pcb *udpcb_2;
|
||||
struct udp_pcb *udpcb_3;
|
||||
|
||||
bool eth_pool_rx = false;
|
||||
|
||||
|
||||
UnEthernetFault ethernet_fault_Info = {
|
||||
.bit_data.auto_count = 0,
|
||||
.bit_data.manual_count = 0,
|
||||
.bit_data.auto_state = 0,
|
||||
.bit_data.manual_state = 0,
|
||||
};
|
||||
|
||||
|
||||
|
||||
StrEthernetParameter ethernet_parameter = {
|
||||
.local_ip = {192,168,17,20},
|
||||
.mask = {255,255,255,0},
|
||||
.computer_ip = {192,168,17,3},
|
||||
.local_communication_port = 8011,
|
||||
.Local_upper_port = 8000,
|
||||
.Local_download_port = 7811,
|
||||
.upper_ip = {192,168,17,3},
|
||||
.download_ip = {192,168,17,183},
|
||||
.target_upper_port = 8000,
|
||||
.target_download_port = 7811,
|
||||
.target_communication_port = 8011,
|
||||
};
|
||||
|
||||
|
||||
|
||||
static bool g_eth1_rx_pkt;
|
||||
|
||||
|
||||
|
||||
static void eth_dma_rx_int_cb(struct net_driver_s *dev)
|
||||
{
|
||||
if (dev == &g_eth1_dev)
|
||||
g_eth1_rx_pkt = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void lwip_Ethernet(void *signal_id)
|
||||
{
|
||||
// uint32_t time_boot = getCurrentTime();//<2F><>¼<EFBFBD><C2BC>ǰʱ<C7B0><CAB1>
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD>ETH֡<48><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD>LWIPЭ<50><D0AD>ջ
|
||||
// <20><><EFBFBD><EFBFBD>ʹ<EFBFBD>ܽ<EFBFBD><DCBD><EFBFBD><EFBFBD>жϣ<D0B6><CFA3><EFBFBD>ΪISR<53><52><EFBFBD><EFBFBD>disable<6C><65><EFBFBD><EFBFBD><EFBFBD>жϣ<D0B6><CFA3><EFBFBD><EFBFBD>ˣ<EFBFBD><CBA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// <20>жϽ<D0B6><CFBD>ձ<EFBFBD>־(g_eth1_rx_pkt)<29>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD>
|
||||
// <20>µĽ<C2B5><C4BD><EFBFBD><EFBFBD>жϱ<D0B6><CFB1><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD>ﲻ<EFBFBD><EFB2BB><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⡣
|
||||
if ((!eth_pool_rx && g_eth1_rx_pkt) || eth_pool_rx)
|
||||
{
|
||||
g_eth1_rx_pkt = false;
|
||||
dwc_eth_rx(&g_eth1_dev, eth_pool_rx);
|
||||
}
|
||||
|
||||
// LWIPЭ<50><D0AD>ջ<EFBFBD>ӿڣ<D3BF><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>LWIP<49><50>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||||
sys_check_timeouts();
|
||||
|
||||
timerStart(ðernet_timer_interface1, 10,1); //10ms<6D><73><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
|
||||
// printf("lwipInterface spend time:%d\n",getCurrentTime() - time_boot);//<2F><><EFBFBD><EFBFBD>app<70><70><EFBFBD>˶ʱ<E0B3A4><CAB1>
|
||||
}
|
||||
|
||||
|
||||
//err_t
|
||||
//udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
|
||||
|
||||
void UdpSendToData(uint8_t udpcbID, uint8_t *buf, uint16_t len, uint8_t *sip, uint16_t port)
|
||||
{
|
||||
struct pbuf *DesPuff = NULL;
|
||||
ip4_addr_t Desaddr;
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
IP4_ADDR(&Desaddr,sip[0],sip[1],sip[2],sip[3]);//<2F><>ֵַת<D6B5><D7AA>
|
||||
|
||||
DesPuff = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_POOL); /* <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD> */
|
||||
|
||||
pbuf_take(DesPuff, buf, len); /* <20><>g_lwip_demo_sendbuf<75>е<EFBFBD><D0B5><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD>pbuf<75>ṹ<EFBFBD><E1B9B9> */
|
||||
|
||||
if(UDPCB_1 == udpcbID)
|
||||
{
|
||||
udp_sendto(udpcb_1, DesPuff, &Desaddr, port);
|
||||
}
|
||||
else if(UDPCB_2 == udpcbID)
|
||||
{
|
||||
udp_sendto(udpcb_2, DesPuff, &Desaddr, port);
|
||||
}
|
||||
else if(UDPCB_3 == udpcbID)
|
||||
{
|
||||
udp_sendto(udpcb_3, DesPuff, &Desaddr, port);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
pbuf_free(DesPuff); /* <20>ͷ<EFBFBD><CDB7>ڴ<EFBFBD> */
|
||||
}
|
||||
|
||||
// udpcbID UDP<44><50><EFBFBD><EFBFBD>
|
||||
//recv <20>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
//port <20>˿<F3B6A8B6>
|
||||
void UDP_Echo_Init(uint8_t udpcbID, udp_recv_fn recv, uint16_t port)
|
||||
{
|
||||
//------------------------------------------
|
||||
if(UDPCB_1 == udpcbID)
|
||||
{
|
||||
/* <20>½<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ƿ<EFBFBD>*/
|
||||
udpcb_1 = udp_new();
|
||||
ASSERT(udpcb_1);
|
||||
/* <20>˿ں<CBBF> */
|
||||
udp_bind(udpcb_1, IP_ADDR_ANY, port);
|
||||
/* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻص<DDBB><D8B5><EFBFBD><EFBFBD><EFBFBD> */
|
||||
udp_recv(udpcb_1, recv, (void *)udpcbID);
|
||||
}
|
||||
else if(UDPCB_2 == udpcbID)
|
||||
{
|
||||
/* <20>½<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ƿ<EFBFBD>*/
|
||||
udpcb_2 = udp_new();
|
||||
ASSERT(udpcb_2);
|
||||
/* <20>˿ں<CBBF> */
|
||||
udp_bind(udpcb_2, IP_ADDR_ANY, port);
|
||||
/* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻص<DDBB><D8B5><EFBFBD><EFBFBD><EFBFBD> */
|
||||
udp_recv(udpcb_2, recv, (void *)udpcbID);
|
||||
}
|
||||
else if(UDPCB_3 == udpcbID)
|
||||
{
|
||||
/* <20>½<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ƿ<EFBFBD>*/
|
||||
udpcb_3 = udp_new();
|
||||
ASSERT(udpcb_3);
|
||||
/* <20>˿ں<CBBF> */
|
||||
udp_bind(udpcb_3, IP_ADDR_ANY, port);
|
||||
/* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻص<DDBB><D8B5><EFBFBD><EFBFBD><EFBFBD> */
|
||||
udp_recv(udpcb_3, recv, (void *)udpcbID);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void udp_Callback_1(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
|
||||
{
|
||||
uint8_t *buf = (uint8_t *)(p->payload);
|
||||
uint16_t i = 0;
|
||||
uint16_t len = 0;
|
||||
uint16_t udp_temp = 0;
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
if( (0xFF == buf[0] ) && ( 0xBB == buf[1] ) )//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>ң<EFBFBD><D2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>ң<EFBFBD><D2A3><EFBFBD><EFBFBD>
|
||||
{
|
||||
ethernet_fault_Info.bit_data.manual_count ++;
|
||||
|
||||
if( (p->len) >= sizeof(UnManualComputerInput) )//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ȳ<EFBFBD><C8B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
||||
{
|
||||
len = sizeof(UnManualComputerInput);
|
||||
}
|
||||
else
|
||||
{
|
||||
len = p->len;
|
||||
}
|
||||
|
||||
for(i = 0; i < len; i++)
|
||||
{
|
||||
un_manual_computer_input.arr[i] = buf[i];
|
||||
}
|
||||
publishMessage(&un_manual_computer_input, 1);
|
||||
|
||||
// p->len = len;
|
||||
printf("Manualrecive len:%d\n",len);
|
||||
// udp_sendto(upcb, p, addr, port);
|
||||
}
|
||||
else if( (0xFF == buf[0] ) && (0xCC == buf[1] ) )//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Զ<EFBFBD>
|
||||
{
|
||||
ethernet_fault_Info.bit_data.auto_count ++;
|
||||
|
||||
if( (p->len) >= sizeof(UnAutoComputerInput) )//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ȳ<EFBFBD><C8B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
||||
{
|
||||
len = sizeof(UnAutoComputerInput);
|
||||
}
|
||||
else
|
||||
{
|
||||
len = p->len;
|
||||
}
|
||||
|
||||
|
||||
// unsigned int frame_header : 16; // ֡ͷ <20>̶<EFBFBD>ֵ0xFFCC
|
||||
// unsigned int frame_type : 16; // ֡<><D6A1><EFBFBD><EFBFBD> <20>̶<EFBFBD>ֵ0x0001
|
||||
// unsigned int frame_length : 8; // ֡<><D6A1> <20>̶<EFBFBD>ֵ0x19
|
||||
// unsigned int heartbeat : 8; // <20><><EFBFBD><EFBFBD> <20><>֡<EFBFBD>ۼ<EFBFBD>
|
||||
// unsigned int set_speed : 16; // <20>趨<EFBFBD>ٶ<EFBFBD> ϵ<><CFB5>0.01<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>λm/s
|
||||
// unsigned int set_curvature : 16; // <20>趨<EFBFBD><E8B6A8><EFBFBD><EFBFBD> ϵ<><CFB5>0.0001<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>ת
|
||||
// unsigned int latitude : 32; // γ<><CEB3> ϵ<><CFB5>10^-7<><37>431234567<36><37>ʾ43.1234567<EFBFBD><EFBFBD>
|
||||
// unsigned int longitude : 32; // <20><><EFBFBD><EFBFBD> ϵ<><CFB5>10^-7<><37>431234567<36><37>ʾ43.1234567<EFBFBD><EFBFBD>
|
||||
// unsigned int altitude : 32; // <20>߶<EFBFBD> <20><>λmm
|
||||
// unsigned int heading : 16; // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>35999<39><39>ʾ359.99<EFBFBD><EFBFBD>
|
||||
// unsigned int crc : 8; // CRC <20><><EFBFBD>ֽ<EFBFBD><D6BD>ۼ<EFBFBD>֮<EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>8λ
|
||||
for(i = 0; i < len; i++)
|
||||
{
|
||||
un_auto_computer_input.arr[i] = buf[i];
|
||||
}
|
||||
|
||||
udp_temp = ((un_auto_computer_input.bit_data.set_speed << 8) | (un_auto_computer_input.bit_data.set_speed >> 8));//<2F>趨<EFBFBD>ٶ<EFBFBD> 20240928 <20>ĸߵ<C4B8>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>
|
||||
un_auto_computer_input.bit_data.set_speed = udp_temp;
|
||||
|
||||
udp_temp = ((un_auto_computer_input.bit_data.set_curvature << 8) | (un_auto_computer_input.bit_data.set_curvature >> 8));//<2F>趨<EFBFBD><E8B6A8><EFBFBD><EFBFBD>
|
||||
un_auto_computer_input.bit_data.set_curvature = udp_temp;
|
||||
publishMessage(&un_auto_computer_input, 1);
|
||||
|
||||
// p->len = len;
|
||||
printf("Autorecive len:%d\n",len);
|
||||
// udp_sendto(upcb, p, addr, port);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void udp_Callback_2(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
|
||||
{
|
||||
uint8_t ip_addr[4] = {0,0,0,0};
|
||||
uint8_t *buf = (uint8_t *)(p->payload);
|
||||
//------------------------------------------------------------------------------------------------
|
||||
|
||||
ip_addr[0] = addr->addr & 0xff; /* IADDR4 */
|
||||
ip_addr[1] = (addr->addr >> 8) & 0xff; /* IADDR3 */
|
||||
ip_addr[2] = (addr->addr >> 16) & 0xff; /* IADDR2 */
|
||||
ip_addr[3] = (addr->addr >> 24) & 0xff; /* IADDR1 */
|
||||
|
||||
ethernet_parameter.target_upper_port = port;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5>Ķ˿ں<CBBF>IP<49><50><EFBFBD>´η<C2B4><CEB7>Ͷ<EFBFBD>Ӧ<EFBFBD><D3A6>IP<49>Ͷ˿<CDB6>
|
||||
|
||||
ethernet_parameter.upper_ip[0] = ip_addr[0];
|
||||
ethernet_parameter.upper_ip[1] = ip_addr[1];
|
||||
ethernet_parameter.upper_ip[2] = ip_addr[2];
|
||||
ethernet_parameter.upper_ip[3] = ip_addr[3];
|
||||
|
||||
if( (0x80 == buf[0]) && (0x00 == buf[1]) )
|
||||
{
|
||||
memcpy((uint8_t *)&(un_request_frame.arr[0]),buf, sizeof(UnRequestFrame));
|
||||
publishMessage(&un_request_frame, 1);
|
||||
printf("request_read_id:%d\n",request_read_id);
|
||||
}
|
||||
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Timer ethernet_timer_interface;
|
||||
|
||||
//100ms <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
void ethernetTimerProcess(void)
|
||||
{
|
||||
static uint8_t ethernet_timer = 0;
|
||||
static uint8_t ethernet_temp[4] = {0,0,0,0};//<2F>м<EFBFBD><D0BC>ж<EFBFBD>ֵ
|
||||
uint8_t temp = 0;
|
||||
|
||||
ethernet_timer ++;
|
||||
if(ethernet_timer >= 5)//500ms<6D>ж<EFBFBD>һ<EFBFBD><D2BB>
|
||||
{
|
||||
ethernet_timer = 0;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>------------------------------------------------------------
|
||||
if(ethernet_fault_Info.bit_data.auto_count == ethernet_temp[0])//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
||||
{
|
||||
ethernet_fault_Info.bit_data.auto_state = FAULT;
|
||||
}
|
||||
else
|
||||
{
|
||||
ethernet_fault_Info.bit_data.auto_state = NORMAL;
|
||||
ethernet_temp[0] = ethernet_fault_Info.bit_data.auto_count;//<2F><><EFBFBD>ݸ<EFBFBD><DDB8><EFBFBD>
|
||||
}
|
||||
|
||||
if(ethernet_fault_Info.bit_data.auto_state != ethernet_temp[1])
|
||||
{
|
||||
ethernet_temp[1] = ethernet_fault_Info.bit_data.auto_state;
|
||||
temp ++;
|
||||
}
|
||||
|
||||
|
||||
//<2F>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>------------------------------------------------------------
|
||||
if(ethernet_fault_Info.bit_data.manual_count == ethernet_temp[2])//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
||||
{
|
||||
ethernet_fault_Info.bit_data.manual_state = FAULT;
|
||||
}
|
||||
else
|
||||
{
|
||||
ethernet_fault_Info.bit_data.manual_state = NORMAL;
|
||||
ethernet_temp[2] = ethernet_fault_Info.bit_data.manual_count;//<2F><><EFBFBD>ݸ<EFBFBD><DDB8><EFBFBD>
|
||||
}
|
||||
|
||||
if(ethernet_fault_Info.bit_data.manual_state != ethernet_temp[3])
|
||||
{
|
||||
|
||||
ethernet_temp[3] = ethernet_fault_Info.bit_data.manual_state;
|
||||
temp ++;
|
||||
}
|
||||
}
|
||||
|
||||
publishMessage(ðernet_fault_Info, 1);// ״̬<D7B4>仯 <20><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
|
||||
}
|
||||
|
||||
|
||||
//<2F><>̫<EFBFBD><CCAB> <20><><EFBFBD><EFBFBD>
|
||||
void ethernetSendAll(void *signal_id)
|
||||
{
|
||||
static uint8_t computer_output_cnt = 0;
|
||||
uint32_t crc_temp = 0;
|
||||
uint8_t i = 0;
|
||||
uint16_t Rg_Tmp = 0;
|
||||
float Rg_FloatTmp = 0;
|
||||
static uint8_t eth_cnt = 0;
|
||||
//-------------------------------------------------------------------------
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̫<EFBFBD><CCAB>50ms<6D><73><EFBFBD><EFBFBD> 20210811<31><EFBFBD>Ϊ100ms<6D><73><EFBFBD><EFBFBD>
|
||||
//20210827<32><EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB>ǰ<EFBFBD><C7B0>λ<EFBFBD>ٺ<EFBFBD><D9BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
computer_output_cnt ++;
|
||||
if(computer_output_cnt >= 1)
|
||||
{
|
||||
computer_output_cnt = 0;
|
||||
//<2F><><EFBFBD>ֽ<EFBFBD><D6BD>ۼӺͣ<D3BA>ע<EFBFBD>ⲻ<EFBFBD><E2B2BB><EFBFBD>ź<EFBFBD> 20210826<32>İ<DEB8><C4B0><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD>ۼ<EFBFBD>
|
||||
|
||||
// printf("left_motor_speed = %f\n",diff_data.left_motor_speed);
|
||||
// printf("right_motor_speed = %f\n",diff_data.right_motor_speed);
|
||||
|
||||
un_computer_output.bit_data.frame_header = 0xCCFF;
|
||||
un_computer_output.bit_data.frame_type = 0x1100;
|
||||
un_computer_output.bit_data.frame_length = 0x0B;
|
||||
un_computer_output.bit_data.accumulated = eth_cnt ++;
|
||||
|
||||
Rg_FloatTmp = (diff_data.left_motor_speed*(float)getParam("whl_dia") * M_PI*60)/1000.0/(float)getParam("gRatio");// ת/<2F><><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD>km/h һȦ1.8<EFBFBD><EFBFBD>
|
||||
Rg_FloatTmp = Rg_FloatTmp*100;//,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>100<30><30> ,ϵ<><CFB5>0.01
|
||||
Rg_Tmp = (uint16_t)((int16_t)(Rg_FloatTmp));//<2F><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD>); //20231012<31><EFBFBD><DEB8><EFBFBD><EFBFBD>ٷ<EFBFBD><D9B7><EFBFBD> 20231226-3<>ų<EFBFBD><C5B3>ķ<DEB8><C4B7><EFBFBD>
|
||||
un_computer_output.bit_data.speed = ((Rg_Tmp << 8) | (Rg_Tmp >> 8));//<2F><>λ<EFBFBD><CEBB>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>λ<EFBFBD>ֺ<EFBFBD>
|
||||
|
||||
Rg_FloatTmp = (diff_data.right_motor_speed*(float)getParam("whl_dia") * M_PI*60)/1000.0/(float)getParam("gRatio");// ת/<2F><><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD>km/h һȦ1.8<EFBFBD><EFBFBD>
|
||||
Rg_FloatTmp = Rg_FloatTmp*100;//,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>100<30><30> ,ϵ<><CFB5>0.01
|
||||
Rg_Tmp = (uint16_t)((int16_t)(Rg_FloatTmp));//<2F><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD>); //20231012<31><EFBFBD><DEB8><EFBFBD><EFBFBD>ٷ<EFBFBD><D9B7><EFBFBD> 20231226-3<>ų<EFBFBD><C5B3>ķ<DEB8><C4B7><EFBFBD>
|
||||
un_computer_output.bit_data.curvature = ((Rg_Tmp << 8) | (Rg_Tmp >> 8));//<2F><>λ<EFBFBD><CEBB>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>λ<EFBFBD>ֺ<EFBFBD>
|
||||
|
||||
crc_temp = 0;
|
||||
for(i = 0; i<10 ;i++)//<2F><><EFBFBD>ȹ̶<C8B9>
|
||||
{
|
||||
crc_temp = crc_temp + (un_computer_output.arr[i]);
|
||||
}
|
||||
un_computer_output.bit_data.crc = (uint8_t)crc_temp;
|
||||
|
||||
UdpSendToData(UDPCB_1,(uint8_t *)(&un_computer_output.arr[0]), 11, (uint8_t *)ðernet_parameter.computer_ip[0], COMMUNICATION_PORT);
|
||||
}
|
||||
}
|
||||
|
||||
// <20><>̫<EFBFBD><CCAB><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>źŴ<C5BA><C5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
static void ethernetInterfaceTimerProcess(void *signal_id)
|
||||
{
|
||||
uint32_t time_boot = getCurrentTime();//<2F><>¼<EFBFBD><C2BC>ǰʱ<C7B0><CAB1>
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
ethernetSendAll(signal_id);
|
||||
|
||||
ethernetTimerProcess();//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
|
||||
timerStart(ðernet_timer_interface, 100,1); //100ms<6D><73><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
|
||||
// printf("ethernetInterface spend time:%d\n",getCurrentTime() - time_boot);//<2F><><EFBFBD><EFBFBD>app<70><70><EFBFBD>˶ʱ<E0B3A4><CAB1>
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void processRequestframe(void *signal_id)
|
||||
{
|
||||
uint32_t TempAcc = 0;
|
||||
uint8_t i = 0;
|
||||
static uint8_t VehicleStaACC0 = 0;
|
||||
static uint8_t VehicleStaACC1 = 0;
|
||||
static uint8_t VehicleStaACC2 = 0;
|
||||
static uint8_t VehicleStaACC3 = 0;
|
||||
|
||||
uint16_t RgExchangeTemp = 0;
|
||||
uint32_t TxLen = 0;
|
||||
uint32_t Rg32ExchangeTemp = 0;
|
||||
//-----------------------------------------------------------
|
||||
switch (request_read_id)//ע<><D7A2><EFBFBD>Ǹ<EFBFBD>λ<EFBFBD><CEBB>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>λ<EFBFBD>ں<EFBFBD>
|
||||
{
|
||||
case 0x2000://״̬֡
|
||||
un_vehicle_Info_output.bit_data.frame_header = 0xCCAA;//֡ͷ
|
||||
un_vehicle_Info_output.bit_data.frame_type = 0x2000;//֡<><D6A1><EFBFBD><EFBFBD>
|
||||
un_vehicle_Info_output.bit_data.frame_length = 0x2900;//֡<><D6A1>
|
||||
un_vehicle_Info_output.bit_data.accumulated = VehicleStaACC0++;//<2F>ۼ<EFBFBD>ֵ
|
||||
|
||||
RgExchangeTemp = (uint16_t)(int16_t)(diff_data.desired_speed * 100.0);
|
||||
un_vehicle_Info_output.bit_data.desired_speed = ((RgExchangeTemp << 8) | (RgExchangeTemp >> 8));//<2F><>ǰ<EFBFBD>ٶ<EFBFBD>
|
||||
|
||||
RgExchangeTemp = (uint16_t)(int16_t)(diff_data.desired_curvature * 10000.0);
|
||||
un_vehicle_Info_output.bit_data.desired_curvature = ((RgExchangeTemp << 8) | (RgExchangeTemp >> 8));//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
||||
|
||||
un_vehicle_Info_output.bit_data.longitude = un_auto_computer_input.bit_data.longitude;//<2F><><EFBFBD><EFBFBD>
|
||||
|
||||
un_vehicle_Info_output.bit_data.latitude = un_auto_computer_input.bit_data.latitude;
|
||||
|
||||
un_vehicle_Info_output.bit_data.altitude = un_auto_computer_input.bit_data.altitude;
|
||||
|
||||
un_vehicle_Info_output.bit_data.heading_angle = un_auto_computer_input.bit_data.heading;//<2F><><EFBFBD><EFBFBD>
|
||||
|
||||
RgExchangeTemp = (uint16_t)(int16_t)(diff_data.speed * 100.0);
|
||||
un_vehicle_Info_output.bit_data.speed = ((RgExchangeTemp << 8) | (RgExchangeTemp >> 8));//<2F><>ǰ<EFBFBD>ٶ<EFBFBD>
|
||||
|
||||
RgExchangeTemp = (uint16_t)(int16_t)(diff_data.curvature * 10000.0);
|
||||
un_vehicle_Info_output.bit_data.curvature = ((RgExchangeTemp << 8) | (RgExchangeTemp >> 8));//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
||||
|
||||
un_vehicle_Info_output.bit_data.battery_voltage = un_bms_input.bit_data.bus_voltage/10;//<2F><><EFBFBD>ص<EFBFBD>ѹ<EFBFBD><D1B9>ȡ<EFBFBD>õ<EFBFBD>10mV<6D><56><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>100mV<6D><56>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С10<31><30>
|
||||
|
||||
un_vehicle_Info_output.bit_data.battery_soc = un_bms_input.bit_data.soc;//SOC
|
||||
un_vehicle_Info_output.bit_data.battery_current = un_bms_input.bit_data.bus_current;//<2F><><EFBFBD>ص<EFBFBD><D8B5><EFBFBD>
|
||||
|
||||
TempAcc = 0;
|
||||
for (i = 0; i < 40; i++)//<2F>ۼ<EFBFBD>ǰ40<34><30><EFBFBD>ֽ<EFBFBD>
|
||||
{
|
||||
TempAcc = TempAcc + (uint32_t)(un_vehicle_Info_output.arr[i]);
|
||||
}
|
||||
un_vehicle_Info_output.bit_data.crc = (uint8_t)TempAcc;//<2F>ۼ<EFBFBD>ֵ
|
||||
|
||||
TxLen = 41;
|
||||
UdpSendToData(UDPCB_2,(uint8_t *)(&un_vehicle_Info_output), TxLen, (uint8_t *)ðernet_parameter.upper_ip[0], ethernet_parameter.target_upper_port);
|
||||
break;
|
||||
|
||||
case 0x2100://<2F><><EFBFBD><EFBFBD>֡
|
||||
un_motor_status_output.bit_data.frame_header = 0xCCAA;//֡ͷ
|
||||
un_motor_status_output.bit_data.frame_type = 0x2100;//֡<><D6A1><EFBFBD><EFBFBD>
|
||||
un_motor_status_output.bit_data.frame_length = 0x1E00;//֡<><D6A1>
|
||||
un_motor_status_output.bit_data.accumulated = VehicleStaACC1++;//<2F>ۼ<EFBFBD>ֵ
|
||||
un_motor_status_output.bit_data.left_wheel_speed = ((un_motor_input1.bit_data.speed << 8) | (un_motor_input1.bit_data.speed >> 8));//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
un_motor_status_output.bit_data.right_wheel_speed = ((un_motor_input2.bit_data.speed << 8) | (un_motor_input2.bit_data.speed >> 8));//<2F>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD>
|
||||
un_motor_status_output.bit_data.left_torque = ((un_motor_input1.bit_data.torque << 8) | (un_motor_input1.bit_data.torque >> 8));//<2F><><EFBFBD><EFBFBD>Ť<EFBFBD><C5A4>
|
||||
un_motor_status_output.bit_data.right_torque = ((un_motor_input2.bit_data.torque << 8) | (un_motor_input2.bit_data.torque >> 8));//<2F>Ҳ<EFBFBD>Ť<EFBFBD><C5A4>
|
||||
// un_motor_status_output.bit_data.left_fault_code = un_motor_input1.bit_data.fault_code;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// un_motor_status_output.bit_data.right_fault_code = un_motor_input2.bit_data.fault_code;//<2F>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
RgExchangeTemp = ( (uint16_t)getParam("maxTorq") + 300 ) *100;
|
||||
un_motor_status_output.bit_data.left_torque_limit = ((RgExchangeTemp << 8) | (RgExchangeTemp >> 8));//<2F><><EFBFBD><EFBFBD>Ť<EFBFBD><C5A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
un_motor_status_output.bit_data.right_torque_limit = ((RgExchangeTemp << 8) | (RgExchangeTemp >> 8));//<2F>Ҳ<EFBFBD>Ť<EFBFBD><C5A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
un_motor_status_output.bit_data.left_power_in = (((uint16_t)getParam("feedPwr") << 8) | ((uint16_t)getParam("feedPwr") >> 8));//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>繦<EFBFBD><E7B9A6>
|
||||
un_motor_status_output.bit_data.right_power_in = (((uint16_t)getParam("feedPwr") << 8) | ((uint16_t)getParam("feedPwr") >> 8));//<2F>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD>繦<EFBFBD><E7B9A6>
|
||||
un_motor_status_output.bit_data.left_power_out = (((uint16_t)getParam("dispPwr") << 8) | ((uint16_t)getParam("dispPwr") >> 8));//<2F><><EFBFBD><EFBFBD><EFBFBD>ŵ繦<C5B5><E7B9A6>
|
||||
un_motor_status_output.bit_data.right_power_out = (((uint16_t)getParam("dispPwr") << 8) | ((uint16_t)getParam("dispPwr") >> 8));//<2F>Ҳ<EFBFBD><D2B2>ŵ繦<C5B5><E7B9A6>
|
||||
// un_motor_status_output.bit_data.left_voltage = ((un_motor_input1.bit_data.bus_voltage << 8) | (un_motor_input1.bit_data.bus_voltage >> 8));//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ
|
||||
// un_motor_status_output.bit_data.right_voltage = ((un_motor_input2.bit_data.bus_voltage << 8) | (un_motor_input2.bit_data.bus_voltage >> 8));//<2F>Ҳ<EFBFBD><D2B2><EFBFBD>ѹ
|
||||
|
||||
TempAcc = 0;
|
||||
for (i = 0; i < 31; i++)//<2F>ۼ<EFBFBD>ǰ31<33><31><EFBFBD>ֽ<EFBFBD>
|
||||
{
|
||||
TempAcc = TempAcc + (uint32_t)(un_motor_status_output.arr[i]);
|
||||
un_motor_status_output.bit_data.checksum = (uint8_t)TempAcc;//<2F>ۼ<EFBFBD>ֵ
|
||||
}
|
||||
TxLen = 34;
|
||||
UdpSendToData(UDPCB_2,(uint8_t *)(&un_motor_status_output), 34, (uint8_t *)ðernet_parameter.upper_ip[0], ethernet_parameter.target_upper_port);
|
||||
break;
|
||||
|
||||
case 0x2200:
|
||||
un_pid_output.bit_data.frame_header = 0xCCAA;//֡ͷ
|
||||
un_pid_output.bit_data.frame_type = 0x2200;//֡<><D6A1><EFBFBD><EFBFBD>
|
||||
un_pid_output.bit_data.frame_length = 0x3800;//֡<><D6A1>
|
||||
un_pid_output.bit_data.accumulated = VehicleStaACC2++;//<2F>ۼ<EFBFBD>ֵ
|
||||
|
||||
|
||||
|
||||
// getParam("spd_kp"),
|
||||
// getParam("spd_ki"),
|
||||
// getParam("spd_kd"),
|
||||
|
||||
// unsigned int rc_straight_p : 32; // ң<><D2A3>ֱ<EFBFBD><D6B1>P<EFBFBD><50><EFBFBD><EFBFBD>
|
||||
// unsigned int rc_straight_i : 32; // ң<><D2A3>ֱ<EFBFBD><D6B1>I<EFBFBD><49><EFBFBD><EFBFBD>
|
||||
// unsigned int rc_straight_d : 32; // ң<><D2A3>ֱ<EFBFBD><D6B1>D<EFBFBD><44><EFBFBD><EFBFBD>
|
||||
// unsigned int auto_straight_p : 32; // <20><><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>P<EFBFBD><50><EFBFBD><EFBFBD>
|
||||
// unsigned int auto_straight_i : 32; // <20><><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>I<EFBFBD><49><EFBFBD><EFBFBD>
|
||||
// unsigned int auto_straight_d : 32; // <20><><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>D<EFBFBD><44><EFBFBD><EFBFBD>
|
||||
// unsigned int rc_turn_p : 32; // ң<><D2A3>ת<EFBFBD><D7AA>P<EFBFBD><50><EFBFBD><EFBFBD>
|
||||
// unsigned int rc_turn_i : 32; // ң<><D2A3>ת<EFBFBD><D7AA>I<EFBFBD><49><EFBFBD><EFBFBD>
|
||||
// unsigned int rc_turn_d : 32; // ң<><D2A3>ת<EFBFBD><D7AA>D<EFBFBD><44><EFBFBD><EFBFBD>
|
||||
// unsigned int auto_turn_p : 32; // <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>P<EFBFBD><50><EFBFBD><EFBFBD>
|
||||
// unsigned int auto_turn_i : 32; // <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>I<EFBFBD><49><EFBFBD><EFBFBD>
|
||||
// unsigned int auto_turn_d : 32; // <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>D<EFBFBD><44><EFBFBD><EFBFBD>
|
||||
|
||||
|
||||
Rg32ExchangeTemp = (uint32_t)(int32_t)(getParam("spd_kp")*1000);
|
||||
Rg32ExchangeTemp = ( ((Rg32ExchangeTemp >> 24) &0xff ) | ((Rg32ExchangeTemp >> 8) & 0xFF00) | ((Rg32ExchangeTemp << 8) & 0xFF0000) | ((Rg32ExchangeTemp << 24)) );
|
||||
un_pid_output.bit_data.rc_straight_p = Rg32ExchangeTemp;//ң<><D2A3>ֱ<EFBFBD><D6B1>P<EFBFBD><50><EFBFBD><EFBFBD>
|
||||
|
||||
Rg32ExchangeTemp = (uint32_t)(int32_t)(getParam("spd_ki")*1000);
|
||||
Rg32ExchangeTemp = ( ((Rg32ExchangeTemp >> 24) &0xff ) | ((Rg32ExchangeTemp >> 8) & 0xFF00) | ((Rg32ExchangeTemp << 8) & 0xFF0000) | ((Rg32ExchangeTemp << 24)) );
|
||||
un_pid_output.bit_data.rc_straight_i = Rg32ExchangeTemp;//ң<><D2A3>ֱ<EFBFBD><D6B1>I<EFBFBD><49><EFBFBD><EFBFBD>
|
||||
|
||||
Rg32ExchangeTemp = (uint32_t)(int32_t)(getParam("spd_kd")*1000);
|
||||
Rg32ExchangeTemp = ( ((Rg32ExchangeTemp >> 24) &0xff ) | ((Rg32ExchangeTemp >> 8) & 0xFF00) | ((Rg32ExchangeTemp << 8) & 0xFF0000) | ((Rg32ExchangeTemp << 24)) );
|
||||
un_pid_output.bit_data.rc_straight_d = Rg32ExchangeTemp;//ң<><D2A3>ֱ<EFBFBD><D6B1>D<EFBFBD><44><EFBFBD><EFBFBD>
|
||||
|
||||
Rg32ExchangeTemp = (uint32_t)(int32_t)(getParam("spd_kp")*1000);
|
||||
Rg32ExchangeTemp = ( ((Rg32ExchangeTemp >> 24) &0xff ) | ((Rg32ExchangeTemp >> 8) & 0xFF00) | ((Rg32ExchangeTemp << 8) & 0xFF0000) | ((Rg32ExchangeTemp << 24)) );
|
||||
un_pid_output.bit_data.auto_straight_p = Rg32ExchangeTemp;//<2F><><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>P<EFBFBD><50><EFBFBD><EFBFBD>
|
||||
|
||||
Rg32ExchangeTemp = (uint32_t)(int32_t)(getParam("spd_ki")*1000);
|
||||
Rg32ExchangeTemp = ( ((Rg32ExchangeTemp >> 24) &0xff ) | ((Rg32ExchangeTemp >> 8) & 0xFF00) | ((Rg32ExchangeTemp << 8) & 0xFF0000) | ((Rg32ExchangeTemp << 24)) );
|
||||
un_pid_output.bit_data.auto_straight_i = Rg32ExchangeTemp;//<2F><><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>I<EFBFBD><49><EFBFBD><EFBFBD>
|
||||
|
||||
Rg32ExchangeTemp = (uint32_t)(int32_t)(getParam("spd_kd")*1000);
|
||||
Rg32ExchangeTemp = ( ((Rg32ExchangeTemp >> 24) &0xff ) | ((Rg32ExchangeTemp >> 8) & 0xFF00) | ((Rg32ExchangeTemp << 8) & 0xFF0000) | ((Rg32ExchangeTemp << 24)) );
|
||||
un_pid_output.bit_data.auto_straight_d = Rg32ExchangeTemp;//<2F><><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>D<EFBFBD><44><EFBFBD><EFBFBD>
|
||||
|
||||
Rg32ExchangeTemp = (uint32_t)(int32_t)(getParam("spd_kp")*1000);
|
||||
Rg32ExchangeTemp = ( ((Rg32ExchangeTemp >> 24) &0xff ) | ((Rg32ExchangeTemp >> 8) & 0xFF00) | ((Rg32ExchangeTemp << 8) & 0xFF0000) | ((Rg32ExchangeTemp << 24)) );
|
||||
un_pid_output.bit_data.rc_turn_p = Rg32ExchangeTemp;//ң<><D2A3>ת<EFBFBD><D7AA>P<EFBFBD><50><EFBFBD><EFBFBD>
|
||||
|
||||
Rg32ExchangeTemp = (uint32_t)(int32_t)(getParam("spd_ki")*1000);
|
||||
Rg32ExchangeTemp = ( ((Rg32ExchangeTemp >> 24) &0xff ) | ((Rg32ExchangeTemp >> 8) & 0xFF00) | ((Rg32ExchangeTemp << 8) & 0xFF0000) | ((Rg32ExchangeTemp << 24)) );
|
||||
un_pid_output.bit_data.rc_turn_i = Rg32ExchangeTemp;//ң<><D2A3>ת<EFBFBD><D7AA>I<EFBFBD><49><EFBFBD><EFBFBD>
|
||||
|
||||
Rg32ExchangeTemp = (uint32_t)(int32_t)(getParam("spd_kd")*1000);
|
||||
Rg32ExchangeTemp = ( ((Rg32ExchangeTemp >> 24) &0xff ) | ((Rg32ExchangeTemp >> 8) & 0xFF00) | ((Rg32ExchangeTemp << 8) & 0xFF0000) | ((Rg32ExchangeTemp << 24)) );
|
||||
un_pid_output.bit_data.rc_turn_d = Rg32ExchangeTemp;//ң<><D2A3>ת<EFBFBD><D7AA>D<EFBFBD><44><EFBFBD><EFBFBD>
|
||||
|
||||
Rg32ExchangeTemp = (uint32_t)(int32_t)(getParam("spd_kp")*1000);
|
||||
Rg32ExchangeTemp = ( ((Rg32ExchangeTemp >> 24) &0xff ) | ((Rg32ExchangeTemp >> 8) & 0xFF00) | ((Rg32ExchangeTemp << 8) & 0xFF0000) | ((Rg32ExchangeTemp << 24)) );
|
||||
un_pid_output.bit_data.auto_turn_p = Rg32ExchangeTemp;//<2F><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>P<EFBFBD><50><EFBFBD><EFBFBD>
|
||||
|
||||
Rg32ExchangeTemp = (uint32_t)(int32_t)(getParam("spd_ki")*1000);
|
||||
Rg32ExchangeTemp = ( ((Rg32ExchangeTemp >> 24) &0xff ) | ((Rg32ExchangeTemp >> 8) & 0xFF00) | ((Rg32ExchangeTemp << 8) & 0xFF0000) | ((Rg32ExchangeTemp << 24)) );
|
||||
un_pid_output.bit_data.auto_turn_i = Rg32ExchangeTemp;//<2F><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>I<EFBFBD><49><EFBFBD><EFBFBD>
|
||||
|
||||
Rg32ExchangeTemp = (uint32_t)(int32_t)(getParam("spd_kd")*1000);
|
||||
Rg32ExchangeTemp = ( ((Rg32ExchangeTemp >> 24) &0xff ) | ((Rg32ExchangeTemp >> 8) & 0xFF00) | ((Rg32ExchangeTemp << 8) & 0xFF0000) | ((Rg32ExchangeTemp << 24)) );
|
||||
un_pid_output.bit_data.auto_turn_d = Rg32ExchangeTemp;//<2F><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>I<EFBFBD><49><EFBFBD><EFBFBD>
|
||||
|
||||
TempAcc = 0;
|
||||
for (i = 0; i < 55; i++)//<2F>ۼ<EFBFBD>ǰ40<34><30><EFBFBD>ֽ<EFBFBD>
|
||||
{
|
||||
TempAcc = TempAcc + (uint32_t)(un_pid_output.arr[i]);
|
||||
}
|
||||
un_pid_output.bit_data.checksum = (uint8_t)TempAcc;//<2F>ۼ<EFBFBD>ֵ
|
||||
TxLen = 56;
|
||||
UdpSendToData(UDPCB_2,(uint8_t *)(&un_pid_output), 56, (uint8_t *)ðernet_parameter.upper_ip[0], ethernet_parameter.target_upper_port);
|
||||
break;
|
||||
|
||||
case 0x2300:
|
||||
// ETHTxtempArr[0] = 0xAA;
|
||||
// ETHTxtempArr[1] = 0xCC;
|
||||
// ETHTxtempArr[2] = 0x00;
|
||||
// ETHTxtempArr[3] = 0x23;
|
||||
// ETHTxtempArr[4] = 0;
|
||||
// ETHTxtempArr[5] = 27;
|
||||
// ETHTxtempArr[6] = VehicleStaACC3++;
|
||||
// //AIAO
|
||||
// memcpy(ÐTxtempArr[7],(uint8_t *)&(UnAIAOSignal_1.ArrData.ArrRx[0]),17);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD>
|
||||
// ETHTxtempArr[24] = (u8)(RgCanToAiAOCnt>>8);
|
||||
// ETHTxtempArr[25] = (u8)RgCanToAiAOCnt;//<2F>ۼ<EFBFBD>ֵ
|
||||
//
|
||||
// TempAcc = 0;
|
||||
// for (i = 0; i < 26; i++)//<2F>ۼ<EFBFBD>ǰ40<34><30><EFBFBD>ֽ<EFBFBD>
|
||||
// {
|
||||
// TempAcc = TempAcc + (u32)(ETHTxtempArr[i]);
|
||||
// }
|
||||
// ETHTxtempArr[26] = (uint8_t)TempAcc;//<2F>ۼ<EFBFBD>ֵ
|
||||
//
|
||||
// TxLen = 27;
|
||||
// UdpSendToData(UDPCB_2,(uint8_t *)(&un_analog_signal_output), 27, (uint8_t *)ðernet_parameter.upper_ip[0], ethernet_parameter.target_upper_port);
|
||||
break;
|
||||
|
||||
case 0x2400:
|
||||
un_remote_control_output.bit_data.frame_header = 0xCCAA;//֡ͷ
|
||||
un_remote_control_output.bit_data.frame_type = 0x2400;//֡<><D6A1><EFBFBD><EFBFBD>
|
||||
un_remote_control_output.bit_data.frame_length = 0x1400;//֡<><D6A1>
|
||||
un_remote_control_output.bit_data.accumulated = VehicleStaACC3++;//<2F>ۼ<EFBFBD>ֵ
|
||||
//RCH_3
|
||||
un_remote_control_output.bit_data.speed = ((un_remote_control_input.bit_data.speed << 8) | (un_remote_control_input.bit_data.speed >> 8));//ң<><D2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
||||
un_remote_control_output.bit_data.curvature = ((un_remote_control_input.bit_data.curvature << 8) | (un_remote_control_input.bit_data.curvature >> 8));//ң<><D2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
memcpy(&un_remote_control_output.arr[11],&un_remote_control_input.arr[4],4);//ң<><D2A3><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD>
|
||||
un_remote_control_output.arr[15] = (uint8_t)(can_fault_info.bit_data.remote_count>>8);
|
||||
un_remote_control_output.arr[16] = (uint8_t)(can_fault_info.bit_data.remote_count);//<2F>ۼ<EFBFBD>ֵ
|
||||
|
||||
TempAcc = 0;
|
||||
for (i = 0; i < 17; i++)//<2F>ۼ<EFBFBD>ǰ40<34><30><EFBFBD>ֽ<EFBFBD>
|
||||
{
|
||||
TempAcc = TempAcc + (uint32_t)(un_remote_control_output.arr[i]);
|
||||
}
|
||||
un_remote_control_output.bit_data.crc = (uint8_t)TempAcc;//<2F>ۼ<EFBFBD>ֵ
|
||||
UdpSendToData(UDPCB_2,(uint8_t *)(&un_remote_control_output), 18, (uint8_t *)ðernet_parameter.upper_ip[0], ethernet_parameter.target_upper_port);
|
||||
break;
|
||||
|
||||
case 0x2500:
|
||||
memcpy(&un_manual_control_output.arr[0],&(un_manual_computer_input.arr[0]),12);//<2F>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD>
|
||||
un_manual_control_output.bit_data.frame_type = 0x2500;
|
||||
|
||||
un_manual_control_output.arr[12] = (uint8_t)(ethernet_fault_Info.bit_data.manual_count>>8);
|
||||
un_manual_control_output.arr[13] = (uint8_t)(ethernet_fault_Info.bit_data.manual_count);//<2F>ۼ<EFBFBD>ֵ
|
||||
TempAcc = 0;
|
||||
for (i = 0; i < 14; i++)//<2F>ۼ<EFBFBD>ǰ40<34><30><EFBFBD>ֽ<EFBFBD>
|
||||
{
|
||||
TempAcc = TempAcc + (uint32_t)(un_manual_control_output.arr[i]);
|
||||
}
|
||||
un_manual_control_output.bit_data.crc_2 = (uint8_t)TempAcc;//<2F>ۼ<EFBFBD>ֵ
|
||||
UdpSendToData(UDPCB_2,(uint8_t *)(&un_manual_control_output), 15, (uint8_t *)ðernet_parameter.upper_ip[0], ethernet_parameter.target_upper_port);
|
||||
break;
|
||||
|
||||
case 0x2600:
|
||||
memcpy(&un_auto_control_output.arr[0],&(un_auto_computer_input.arr[0]),25);//<2F>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD>
|
||||
un_auto_control_output.bit_data.frame_type = 0x2600;
|
||||
un_auto_control_output.arr[25] = (uint8_t)(ethernet_fault_Info.bit_data.auto_count>>8);
|
||||
un_auto_control_output.arr[26] = (uint8_t)(ethernet_fault_Info.bit_data.auto_count);//<2F>ۼ<EFBFBD>ֵ
|
||||
|
||||
TempAcc = 0;
|
||||
for (i = 0; i < 27; i++)//<2F>ۼ<EFBFBD>ǰ40<34><30><EFBFBD>ֽ<EFBFBD>
|
||||
{
|
||||
TempAcc = TempAcc + (uint32_t)(un_auto_control_output.arr[i]);
|
||||
}
|
||||
un_auto_control_output.bit_data.crc = (uint8_t)TempAcc;//<2F>ۼ<EFBFBD>ֵ
|
||||
|
||||
UdpSendToData(UDPCB_2,(uint8_t *)(&un_auto_control_output), 28, (uint8_t *)ðernet_parameter.upper_ip[0], ethernet_parameter.target_upper_port);
|
||||
|
||||
break;
|
||||
|
||||
// case 0x2700:
|
||||
// memcpy(ÐTxtempArr[0],(uint8_t *)&RemoteControlRoomToVcuBuf,11);//<2F>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD>
|
||||
// ETHTxtempArr[2] = 0;//<2F><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>Ϊ0x0025
|
||||
// ETHTxtempArr[3] = 0x27;
|
||||
// ETHTxtempArr[11] = (u8)(RgETHToRemoteControlCnt>>8);
|
||||
// ETHTxtempArr[12] = (u8)RgETHToRemoteControlCnt;//<2F>ۼ<EFBFBD>ֵ
|
||||
// TempAcc = 0;
|
||||
// for (i = 0; i < 13; i++)//<2F>ۼ<EFBFBD>ǰ40<34><30><EFBFBD>ֽ<EFBFBD>
|
||||
// {
|
||||
// TempAcc = TempAcc + (u32)(ETHTxtempArr[i]);
|
||||
// }
|
||||
// ETHTxtempArr[13] = (uint8_t)TempAcc;//<2F>ۼ<EFBFBD>ֵ
|
||||
//
|
||||
// TxLen = 14;
|
||||
// UdpSendToData(SocketId2,ETHTxtempArr,&TxLen,ip_addr,port);//<2F><><EFBFBD><EFBFBD>
|
||||
// break;
|
||||
|
||||
// case 0xFFFF:
|
||||
// memcpy(ÐTxtempArr[0],(uint8_t *)&RemoteControlRoomToVcuBuf,11);//<2F>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD>
|
||||
// ETHTxtempArr[2] = 0x27;//<2F><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>Ϊ0x0025
|
||||
// ETHTxtempArr[3] = 0;
|
||||
// ETHTxtempArr[11] = (u8)RgETHToRemoteControlCnt;
|
||||
// ETHTxtempArr[12] = (u8)(RgETHToRemoteControlCnt>>8);//<2F>ۼ<EFBFBD>ֵ
|
||||
// TempAcc = 0;
|
||||
// for (i = 0; i < 13; i++)//<2F>ۼ<EFBFBD>ǰ40<34><30><EFBFBD>ֽ<EFBFBD>
|
||||
// {
|
||||
// TempAcc = TempAcc + (u32)(ETHTxtempArr[i]);
|
||||
// }
|
||||
// ETHTxtempArr[13] = (uint8_t)TempAcc;//<2F>ۼ<EFBFBD>ֵ
|
||||
//
|
||||
// TxLen = 14;
|
||||
// UdpSendToData(SocketId2,ETHTxtempArr,&TxLen,ip_addr,port);//<2F><><EFBFBD><EFBFBD>
|
||||
// break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static unsigned char receive_buffer[MAX_BUFFER_SIZE];
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>
|
||||
void udp_Callback_3(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
|
||||
{
|
||||
static unsigned int received_size = 0;
|
||||
uint8_t *buf = (uint8_t *)(p->payload);
|
||||
|
||||
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>µ<EFBFBD>֡ͷ
|
||||
if ((0x80 == buf[1]) && (0xFF == buf[0]))
|
||||
{
|
||||
// <20><><EFBFBD>ý<EFBFBD><C3BD>չ<EFBFBD><D5B9><EFBFBD>
|
||||
received_size = 0;
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>֡ͷ,<2C><><EFBFBD>ý<EFBFBD><C3BD>չ<EFBFBD><D5B9><EFBFBD>\n");
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>㹻<EFBFBD>Ŀռ<C4BF><D5BC><EFBFBD><EFBFBD>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (received_size + p->len <= MAX_BUFFER_SIZE)
|
||||
{
|
||||
printf("p->len %d :\n" , p->len);
|
||||
|
||||
memcpy(receive_buffer + received_size, buf, p->len);
|
||||
received_size += p->len;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (received_size >= sizeof(request_context.param_request->arr))
|
||||
{
|
||||
printf("received_size : %d :\n" , received_size);
|
||||
|
||||
for(u16_t i = 0; i< sizeof(request_context.param_request->arr); i++)
|
||||
{
|
||||
request_context.param_request->arr[i] = receive_buffer[i];
|
||||
}
|
||||
|
||||
memcpy(request_context.param_request->arr, receive_buffer, sizeof(request_context.param_request->arr));
|
||||
request_context.sender_ip = (unsigned int)addr->addr;
|
||||
request_context.sender_port = port;
|
||||
|
||||
// <20><>ӡ request_context.param_request->arr <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// printf("<22><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD> param_request->arr <20><><EFBFBD><EFBFBD>:\n");
|
||||
// for (size_t i = 0; i < sizeof(request_context.param_request->arr); ++i)
|
||||
// {
|
||||
// printf("%02X ", request_context.param_request->arr[i]);
|
||||
// if ((i + 1) % 1024 == 0 || i == sizeof(request_context.param_request->arr) - 1)
|
||||
// {
|
||||
// printf("\n");
|
||||
// feedWatchdog();
|
||||
// }
|
||||
// }
|
||||
|
||||
publishMessage(&request_context, 1);
|
||||
|
||||
printf("received_size<EFBFBD><EFBFBD>%d \n" , received_size);
|
||||
// <20><><EFBFBD>ý<EFBFBD><C3BD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
received_size = 0;
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD>ý<EFBFBD><C3BD><EFBFBD>
|
||||
received_size = 0;
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD>ջ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>\n");
|
||||
}
|
||||
|
||||
unsigned int tmp_count = pbuf_free(p);
|
||||
printf("pbuf_free<EFBFBD>Ѿ<EFBFBD><EFBFBD>ͷţ<EFBFBD>tmp_count :%d \n" , tmp_count);
|
||||
p = NULL;
|
||||
}
|
||||
|
||||
void OnParamSend(void *data)
|
||||
{
|
||||
uint8_t ip_addr[4] = {0,0,0,0};
|
||||
RequestContext *signal = (RequestContext *)(data);
|
||||
|
||||
ip_addr[0] = signal->sender_ip & 0xff; /* IADDR4 */
|
||||
ip_addr[1] = (signal->sender_ip >> 8) & 0xff; /* IADDR3 */
|
||||
ip_addr[2] = (signal->sender_ip >> 16) & 0xff; /* IADDR2 */
|
||||
ip_addr[3] = (signal->sender_ip >> 24) & 0xff; /* IADDR1 */
|
||||
|
||||
uint32_t total_size = sizeof(signal->param_request->arr);
|
||||
uint32_t sent_size = 0;
|
||||
|
||||
|
||||
while (sent_size < total_size)
|
||||
{
|
||||
uint32_t remaining = total_size - sent_size;
|
||||
uint32_t packet_size = (remaining > MAX_PACKET_SIZE) ? MAX_PACKET_SIZE : remaining;
|
||||
|
||||
UdpSendToData(UDPCB_3,
|
||||
(uint8_t *)(signal->param_request->arr) + sent_size,
|
||||
packet_size,
|
||||
ip_addr,
|
||||
signal->sender_port);
|
||||
|
||||
sent_size += packet_size;
|
||||
// <20><><EFBFBD><EFBFBD>С<EFBFBD>ӳ<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ
|
||||
udelay(1000);
|
||||
}
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD>%d \n", sent_size);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// APPģ<50><C4A3><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC>
|
||||
void ethernetInterfaceInit(void)
|
||||
{
|
||||
//-----------------------------------
|
||||
if (!eth_pool_rx) {
|
||||
// ʹ<><CAB9>DMA Rx<52>жϡ<D0B6>Txδʹ<CEB4><CAB9><EFBFBD>жϣ<D0B6><CFA3><EFBFBD>ΪETH<54><48><EFBFBD>ʺܸߣ<DCB8>
|
||||
// Tx<54>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶȡ<D9B6>
|
||||
dwc_eth_enable_dma_rx_int(&g_eth1_dev, eth_dma_rx_int_cb);
|
||||
}
|
||||
|
||||
timerInit(ðernet_timer_interface1);
|
||||
timerInit(ðernet_timer_interface);
|
||||
|
||||
// <20><><EFBFBD>Ķ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>źţ<C5BA><C5A3><EFBFBD><EFBFBD>ڶ<EFBFBD>ʱ<EFBFBD>ɼ<EFBFBD>
|
||||
subscribe(ðernet_timer_interface, ethernetInterfaceTimerProcess);
|
||||
subscribe(ðernet_timer_interface1, lwip_Ethernet);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ʹ<EFBFBD>þ<EFBFBD>̬<EFBFBD><CCAC>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ص<EFBFBD>
|
||||
subscribe(&request_send, OnParamSend);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ʹ<EFBFBD>þ<EFBFBD>̬<EFBFBD><CCAC>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ص<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
subscribe(&un_request_frame, processRequestframe);
|
||||
|
||||
timerStart(ðernet_timer_interface, 100,1); //100ms<6D><73><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
timerStart(ðernet_timer_interface1, 10,1); //10ms<6D><73><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
|
||||
printf( "ethernetInterface: initial OK %d\n",getCurrentTime());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
#ifndef _INTERFACE_ETHERNET_H_
|
||||
#define _INTERFACE_ETHERNET_H_
|
||||
|
||||
#include "interface_config.h"
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/inet.h"
|
||||
#include "lwip/tcp.h"
|
||||
#include "lwip/udp.h"
|
||||
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/ip.h"
|
||||
#include "lwip/init.h"
|
||||
#include "netif/etharp.h"
|
||||
#include "lwip/pbuf.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//<2F><>̫<EFBFBD><CCAB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
typedef struct _StrEthernetFault
|
||||
{
|
||||
uint8_t auto_count; //<2F>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t manual_count; //<2F>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t auto_state; // <20>Զ<EFBFBD>״̬ | 0<><30><EFBFBD><EFBFBD> 1<><31><EFBFBD><EFBFBD>
|
||||
uint8_t manual_state; // <20>ֶ<EFBFBD>״̬ | 0<><30><EFBFBD><EFBFBD> 1<><31><EFBFBD><EFBFBD>
|
||||
} StrEthernetFault;
|
||||
|
||||
typedef union _UnEthernetFault
|
||||
{
|
||||
StrEthernetFault bit_data; // ʹ<>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>Ľṹ<C4BD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t arr[sizeof(StrEthernetFault)]; // ͨ<><CDA8><EFBFBD>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>С
|
||||
} UnEthernetFault;
|
||||
|
||||
|
||||
extern UnEthernetFault ethernet_fault_Info;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t local_ip[4];
|
||||
uint8_t mask[4];
|
||||
uint16_t Local_upper_port;
|
||||
uint16_t Local_download_port;
|
||||
uint16_t local_communication_port;
|
||||
uint8_t computer_ip[4];
|
||||
uint8_t upper_ip[4];
|
||||
uint8_t download_ip[4];
|
||||
uint16_t target_upper_port;
|
||||
uint16_t target_download_port;
|
||||
uint16_t target_communication_port;
|
||||
|
||||
} StrEthernetParameter;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define UDPCB_1 1//ͨѶ<CDA8>˿<EFBFBD>
|
||||
#define UDPCB_2 2//<2F><>λ<EFBFBD><CEBB><EFBFBD>˿<EFBFBD>
|
||||
#define UDPCB_3 3//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD>˿<EFBFBD>
|
||||
|
||||
|
||||
#define COMMUNICATION_PORT 8011
|
||||
#define UPPER_PORT 8000
|
||||
#define DOWNLOAR_PORT 7811
|
||||
#define PARAM_PORT 8080
|
||||
|
||||
|
||||
//<2F>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD>
|
||||
void UDP_Echo_Init(uint8_t udpcbID, udp_recv_fn recv, uint16_t port);
|
||||
void UdpSendToData(uint8_t udpcbID, uint8_t *buf, uint16_t len, uint8_t *sip, uint16_t port);
|
||||
|
||||
void udp_Callback_1(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port);
|
||||
void udp_Callback_2(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port);
|
||||
void udp_Callback_3(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port);
|
||||
void ethernetTimerProcess(void);
|
||||
void ethernetInterfaceInit(void);
|
||||
//<2F>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD>
|
||||
extern struct udp_pcb *udpcb_1;
|
||||
extern StrEthernetParameter ethernet_parameter;
|
||||
|
||||
#endif /*ETH_DEMO_H */
|
||||
@@ -0,0 +1,145 @@
|
||||
#include "interface_gpio.h"
|
||||
|
||||
|
||||
Timer gpio_timer_interface;
|
||||
|
||||
void gpioTimerProcess(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // 标记变量为已使用,避免编译器警告
|
||||
// uint32_t time_boot = getCurrentTime();//记录当前时间
|
||||
//--------------------------------------------
|
||||
un_sw_sample.bit_data.emergency_stop_switch = sdrv_gpio_read_pin_input_level(GPIO_A4);
|
||||
un_sw_sample.bit_data.High_voltage_switch = sdrv_gpio_read_pin_input_level(GPIO_C7);
|
||||
|
||||
publishMessage(&un_sw_sample, 1);//发射信号
|
||||
|
||||
timerStart(&gpio_timer_interface, 100,1);
|
||||
printf("sw state %d\n",un_sw_sample.arr[0]);
|
||||
}
|
||||
|
||||
|
||||
// APP模块的初始化
|
||||
void gpioInterfaceInit(void)
|
||||
{
|
||||
// 初始化定时器
|
||||
timerInit(&gpio_timer_interface);
|
||||
// 订阅定时器信号,用于定时采集
|
||||
subscribe(&gpio_timer_interface, gpioTimerProcess);
|
||||
|
||||
timerStart(&gpio_timer_interface, 100,1);
|
||||
|
||||
printf("gpioInterface: initial OK %d\n",getCurrentTime());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef _INTERFACE_GPIO_H_
|
||||
#define _INTERFACE_GPIO_H_
|
||||
|
||||
|
||||
#include "interface_config.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//#deifne emergency_stop_switch sdrv_gpio_read_pin_input_level(GPIO_A6)
|
||||
//
|
||||
//#deifne high_voltage_switch sdrv_gpio_read_pin_input_level(GPIO_A7)
|
||||
|
||||
|
||||
void gpioTimerProcess(void *signal_id);
|
||||
|
||||
void gpioInterfaceInit(void);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* _INTERFACE_GPIO_H_ */
|
||||
@@ -0,0 +1,139 @@
|
||||
|
||||
|
||||
#include "interface_power.h"
|
||||
#include "app/app_config.h"
|
||||
|
||||
Timer ppwer_timer;
|
||||
|
||||
|
||||
// 100ms
|
||||
void powerOn(void)
|
||||
{
|
||||
static uint8_t power_state = 0;
|
||||
static uint8_t power_count = 0;
|
||||
//---------------------------------------
|
||||
switch(power_state)
|
||||
{
|
||||
case 0:
|
||||
left_motor_fan(ON);
|
||||
right_motor_fan(ON);
|
||||
pre_charge_relay(ON);
|
||||
high_voltage_relay(OFF);
|
||||
low_voltage_relay(ON);
|
||||
yellow_light(ON);
|
||||
red_light(ON);
|
||||
left_vehicle_fan(ON);
|
||||
right_vehicle_fan(ON);
|
||||
computer(ON);
|
||||
network_switch(ON);
|
||||
power_state = 10;
|
||||
power_count = 0;
|
||||
break;
|
||||
case 10:
|
||||
if (power_count >= 100)//10s
|
||||
{
|
||||
left_motor_fan(ON);
|
||||
right_motor_fan(ON);
|
||||
pre_charge_relay(OFF);
|
||||
high_voltage_relay(ON);
|
||||
low_voltage_relay(ON);
|
||||
yellow_light(ON);
|
||||
red_light(ON);
|
||||
left_vehicle_fan(ON);
|
||||
right_vehicle_fan(ON);
|
||||
computer(ON);
|
||||
network_switch(ON);
|
||||
power_state = 11;
|
||||
power_count = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
left_motor_fan(ON);
|
||||
right_motor_fan(ON);
|
||||
pre_charge_relay(ON);
|
||||
high_voltage_relay(OFF);
|
||||
low_voltage_relay(ON);
|
||||
yellow_light(ON);
|
||||
red_light(ON);
|
||||
left_vehicle_fan(ON);
|
||||
right_vehicle_fan(ON);
|
||||
computer(ON);
|
||||
network_switch(ON);
|
||||
power_state = 10;
|
||||
power_count ++;
|
||||
}
|
||||
break;
|
||||
case 11:
|
||||
power_state = 11;
|
||||
// left_motor_fan(ON);
|
||||
// left_motor_fan(ON);
|
||||
// right_motor_fan(ON);
|
||||
// pre_charge_relay(OFF);
|
||||
// high_voltage_relay(ON);
|
||||
// low_voltage_relay(ON);
|
||||
// yellow_light(ON);
|
||||
// red_light(ON);
|
||||
// left_vehicle_fan(ON);
|
||||
// right_vehicle_fan(ON);
|
||||
// computer(ON);
|
||||
// network_switch(ON);
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
|
||||
canSendAll();
|
||||
// ethernetSendAll(&power_state);
|
||||
}
|
||||
|
||||
//<2F>ϵ紦<CFB5><E7B4A6>
|
||||
//void powerOnSignal(void *data)
|
||||
//{
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
||||
|
||||
// APPģ<50><C4A3><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC>
|
||||
void powerAppInit(void)
|
||||
{
|
||||
|
||||
// <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
|
||||
// subscribe(&un_remote_control_input, powerOnSignal);
|
||||
// timerStart(&test_timer, 5000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
|
||||
#ifndef _INTERFACE_POWER_H_
|
||||
#define _INTERFACE_POWER_H_
|
||||
|
||||
|
||||
#include "interface_config.h"
|
||||
|
||||
#define ON 1
|
||||
#define OFF 0
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//kgf1
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//kgf3
|
||||
|
||||
//Ԥ<><D4A4>
|
||||
//kgf4
|
||||
|
||||
//<2F><>ѹѹ<D1B9>̵<EFBFBD><CCB5><EFBFBD>
|
||||
//kgf7<66><37>8
|
||||
|
||||
//<2F><>ѹ<EFBFBD>̵<EFBFBD><CCB5><EFBFBD>
|
||||
//kgf11-12
|
||||
|
||||
//<2F><>1
|
||||
//kgf6
|
||||
|
||||
//<2F><>2
|
||||
//kgf9
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//kgf14
|
||||
|
||||
//<2F>ҷ<EFBFBD><D2B7><EFBFBD>
|
||||
//kgf19
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
//kgf 17-18
|
||||
|
||||
#define left_motor_fan(Value) un_inf_can_kgf_output1.bit_data.KGF01 = Value;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define right_motor_fan(Value) un_inf_can_kgf_output1.bit_data.KGF03 = Value;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define pre_charge_relay(Value) un_inf_can_kgf_output1.bit_data.KGF04 = Value;//Ԥ<><D4A4>
|
||||
#define high_voltage_relay(Value) un_inf_can_kgf_output1.bit_data.KGF07 = Value;un_inf_can_kgf_output1.bit_data.KGF08 = Value//<2F><>ѹ<EFBFBD>̵<EFBFBD><CCB5><EFBFBD>
|
||||
#define low_voltage_relay(Value) un_inf_can_kgf_output1.bit_data.KGF11 = Value;un_inf_can_kgf_output1.bit_data.KGF12 = Value//<2F><>ѹ<EFBFBD>̵<EFBFBD><CCB5><EFBFBD>
|
||||
#define yellow_light(Value) un_inf_can_kgf_output1.bit_data.KGF06 = Value;//<2F>Ƶ<EFBFBD>
|
||||
#define red_light(Value) un_inf_can_kgf_output1.bit_data.KGF09 = Value;//<2F><><EFBFBD><EFBFBD>
|
||||
#define left_vehicle_fan(Value) un_inf_can_kgf_output1.bit_data.KGF14 = Value;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define right_vehicle_fan(Value) un_inf_can_kgf_output2.bit_data.KGF03 = Value;//<2F><><EFBFBD>ҷ<EFBFBD><D2B7><EFBFBD>
|
||||
#define computer(Value) un_inf_can_kgf_output2.bit_data.KGF01 = Value;un_inf_can_kgf_output2.bit_data.KGF02 = Value//<2F><>ѹ<EFBFBD>̵<EFBFBD><CCB5><EFBFBD>
|
||||
#define network_switch(Value) un_inf_can_kgf_output2.bit_data.KGF05 = Value;un_inf_can_kgf_output2.bit_data.KGF06 = Value//<2F><><EFBFBD>罻<EFBFBD><E7BDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD>
|
||||
|
||||
//H<><48>
|
||||
#define brake_motor_forward un_h_bridge_output.bit_data.channel_01 = ON ;un_h_bridge_output.bit_data.channel_04 = ON ;un_h_bridge_output.bit_data.channel_02 = OFF;un_h_bridge_output.bit_data.channel_03 = OFF;un_h_bridge_output.bit_data.sleep_01 = ON ;un_h_bridge_output.bit_data.sleep_02 = ON//<2F><>ת
|
||||
#define brake_motor_reversal un_h_bridge_output.bit_data.channel_01 = OFF;un_h_bridge_output.bit_data.channel_04 = OFF;un_h_bridge_output.bit_data.channel_02 = ON ;un_h_bridge_output.bit_data.channel_03 = ON ;un_h_bridge_output.bit_data.sleep_01 = ON ;un_h_bridge_output.bit_data.sleep_02 = ON//<2F><>ת
|
||||
#define brake_motor_off un_h_bridge_output.bit_data.channel_01 = OFF;un_h_bridge_output.bit_data.channel_04 = OFF;un_h_bridge_output.bit_data.channel_02 = OFF;un_h_bridge_output.bit_data.channel_03 = OFF;un_h_bridge_output.bit_data.sleep_01 = OFF;un_h_bridge_output.bit_data.sleep_02 = OFF//<2F>ر<EFBFBD>
|
||||
|
||||
|
||||
|
||||
//#define OutputL01_13(Value) UnInfCanKGF_2.bit_data.KGF03 = Value;UnBCM_1Signal_1.bit_data.BCM_1SignalW9 = Value//<2F><>ת 20200106<30><36>ת<EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD>ΪK19 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵƲ<CFB5><C6B2>ܹ<EFBFBD><DCB9><EFBFBD>ͬһ<CDAC><D2BB>ͨ<EFBFBD><CDA8><EFBFBD>ϡ<EFBFBD>
|
||||
//#define OutputL01_14(Value) UnInfCanKGF_1.bit_data.KGF13 = Value;UnBCM_1Signal_1.bit_data.BCM_1SignalW7 = Value//<2F><>ת
|
||||
//#define OutputL01_19(Value) UnInfCanKGF_1.bit_data.KGF05 = Value;UnInfCanKGF_1.bit_data.KGF06 = Value; UnBCM_1Signal_1.bit_data.BCM_1SignalW22 = Value //Զ<><D4B6>
|
||||
//#define OutputL01_18(Value) UnInfCanKGF_1.bit_data.KGF03 = Value;UnInfCanKGF_1.bit_data.KGF04 = Value; UnBCM_1Signal_1.bit_data.BCM_1SignalW23 = Value //<2F><><EFBFBD><EFBFBD>
|
||||
//#define OutputL01_22(Value) UnInfCanKGF_1.bit_data.KGF11 = Value;UnInfCanKGF_1.bit_data.KGF12 = Value //<2F><><EFBFBD><EFBFBD>
|
||||
//#define OutputL01_06(Value) UnInfCanKGF_1.bit_data.KGF01 = Value;UnInfCanKGF_1.bit_data.KGF02 = Value; UnBCM_1Signal_1.bit_data.BCM_1SignalW2 = Value//λ<><CEBB>
|
||||
//#define OutputL01_04(Value) UnInfCanKGF_2.bit_data.KGF05 = Value//<2F><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD> 20200106<30><36><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD>ΪK21
|
||||
//#define OutputL01_02(Value) UnInfCanKGF_1.bit_data.KGF16 = Value//<2F><><EFBFBD><EFBFBD>ǰ<EFBFBD>յ<EFBFBD>
|
||||
//#define OutputL01_20(Value) UnInfCanKGF_1.bit_data.KGF09 = Value;UnInfCanKGF_1.bit_data.KGF10 = Value //<2F>ƶ<EFBFBD>
|
||||
//#define OutputL01_21(Value) UnInfCanKGF_1.bit_data.KGF07 = Value;UnInfCanKGF_1.bit_data.KGF08 = Value;UnBCM_1Signal_1.bit_data.BCM_1SignalW28 = Value//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//
|
||||
//#define OutputL01_05(Value) UnInfCanKGF_2.bit_data.KGF01 = Value//<2F><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD> ҲΪ<D2B2>ƶ<EFBFBD><C6B6><EFBFBD>
|
||||
//#define OutputL01_11(Value) UnInfCanKGF_2.bit_data.KGF02 = Value//<2F><><EFBFBD>յ<EFBFBD>1<EFBFBD><31>LED
|
||||
//#define OutputL01_12(Value) UnInfCanKGF_1.bit_data.KGF14 = Value//<2F><><EFBFBD>յ<EFBFBD>2<EFBFBD><32>LED
|
||||
//#define OutputL01_10(Value) UnInfCanKGF_2.bit_data.KGF04 = Value;UnBCM_1Signal_1.bit_data.BCM_1SignalW21 = Value//Σ<><CEA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Led
|
||||
//#define OutputL01_16(Value) UnInfCanKGF_1.bit_data.KGF15 = Value//<2F><><EFBFBD>ε<EFBFBD><CEB5><EFBFBD>1 20200106<30><36><EFBFBD><EFBFBD>1<EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD>ΪK15
|
||||
//#define OutputL01_17(Value) UnInfCanKGF_2.bit_data.KGF06 = Value//<2F><><EFBFBD>ε<EFBFBD><CEB5><EFBFBD>2
|
||||
//#define OutputL01_07(Value) UnInfCanKGF_2.bit_data.KGF07 = Value;UnBCM_2Signal_1.bit_data.BCM_2SignalW12 = Value//<2F><><EFBFBD><EFBFBD>
|
||||
//#define OutputL01_08(Value) UnInfCanKGF_2.bit_data.KGF08 = Value;UnBCM_2Signal_1.bit_data.BCM_2SignalW10 = Value//<2F><><EFBFBD><EFBFBD><EFBFBD>սŵ<D5BD>
|
||||
//#define OutputL01_09(Value) UnInfCanKGF_2.bit_data.KGF09 = Value//ǰ<><C7B0>˪LED
|
||||
//#define OutputL01_01(Value) UnInfCanKGF_2.bit_data.KGF11 = Value;UnInfCanKGF_2.bit_data.KGF12 = Value;UnBCM_2Signal_1.bit_data.BCM_2SignalW8 = Value//ǰ<><C7B0>ϴ
|
||||
//#define OutputL01_03(Value) UnInfCanKGF_2.bit_data.KGF10 = Value//<2F><><EFBFBD>ε<EFBFBD><CEB5><EFBFBD>1<EFBFBD>ٶȿ<D9B6><C8BF><EFBFBD>
|
||||
//#define OutputL01_15(Value) UnInfCanKGF_2.bit_data.KGF13 = Value//<2F><><EFBFBD><EFBFBD>20190202
|
||||
//#define OutputL01_23(Value) UnInfCanKGF_2.bit_data.KGF14 = Value//<2F><><EFBFBD>ε<EFBFBD><CEB5><EFBFBD>2<EFBFBD>ٶȿ<D9B6><C8BF><EFBFBD>
|
||||
//#define OutputL01_24(Value) UnInfCanKGF_2.bit_data.KGF15 = Value//ǰ<><C7B0>˪<EFBFBD>¿<EFBFBD><C2BF><EFBFBD>
|
||||
//#define OutputL01_25(Value) UnInfCanKGF_2.bit_data.KGF16 = Value//220V<30>Ӵ<EFBFBD><D3B4><EFBFBD>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//w<>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD>
|
||||
|
||||
void powerOn(void);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* _APP_POWER_H_ */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,471 @@
|
||||
|
||||
|
||||
|
||||
#include "interface_uart.h"
|
||||
|
||||
|
||||
#define BUFFER_SIZE 256
|
||||
|
||||
#define SBUS_UART UART3
|
||||
|
||||
|
||||
UartFaultInfo uart_fault_info = {
|
||||
.remote_count = 0,
|
||||
.remote_state = 0,
|
||||
};
|
||||
|
||||
|
||||
|
||||
// <20><><EFBFBD>岢<EFBFBD><E5B2A2>ʼ<EFBFBD><CABC> SBus <20><><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD><E1B9B9>
|
||||
typedef struct {
|
||||
uint16_t channels[16]; // <20>洢16<31><36>ͨ<EFBFBD><CDA8><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t flags; // <20><>־<EFBFBD>ֽ<EFBFBD>
|
||||
} SBusData;
|
||||
|
||||
|
||||
SBusData sbus_data = {
|
||||
.channels = {0},
|
||||
.flags = 0
|
||||
};
|
||||
|
||||
///* Buffer used to receive data from the console */
|
||||
typedef struct user_data {
|
||||
uint8_t user_buffer[BUFFER_SIZE];
|
||||
uint8_t *buff_ptr;
|
||||
uint32_t buff_remain;
|
||||
} user_data_t;
|
||||
static user_data_t user_data;
|
||||
///* Buffer used to transmit welcome message */
|
||||
|
||||
|
||||
sdrv_uart_t uart_ctrl_ptr;
|
||||
|
||||
/* uart config structures */
|
||||
//sbus Ĭ<><C4AC>Ϊ100k
|
||||
static sdrv_uart_config_t g_uart_config = {
|
||||
.base = DEVICE_BASE(SBUS_UART),
|
||||
.irq = DEVICE_INTR(SBUS_UART),
|
||||
.baud = 100000,
|
||||
.data_bits = SDRV_UART_CHAR_8_BITS,
|
||||
.stop_bits = SDRV_UART_STOP_2_BIT,
|
||||
.parity = SDRV_UART_EVEN_PARITY,
|
||||
};
|
||||
|
||||
|
||||
// SBus <20><><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
SBusData* parseSBusData(const uint8_t *input_data)
|
||||
{
|
||||
|
||||
for(uint8_t i = 0; i < 25; i++)
|
||||
{
|
||||
test_app[i] = input_data[i];
|
||||
}
|
||||
test_app[25] = 0x44;
|
||||
|
||||
float sbus_temp = 0.0;
|
||||
// <20><><EFBFBD><EFBFBD>16<31><36>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>ÿ<EFBFBD><C3BF>ͨ<EFBFBD><CDA8>Ϊ11λ 0xFΪ֡ͷ<D6A1><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
sbus_data.channels[0] = (input_data[1] | input_data[2] << 8) & 0x07FF;
|
||||
sbus_data.channels[1] = (input_data[2] >> 3 | input_data[3] << 5) & 0x07FF;
|
||||
sbus_data.channels[2] = (input_data[3] >> 6 | input_data[4] << 2 | input_data[5] << 10) & 0x07FF;
|
||||
sbus_data.channels[3] = (input_data[5] >> 1 | input_data[6] << 7) & 0x07FF;
|
||||
sbus_data.channels[4] = (input_data[6] >> 4 | input_data[7] << 4) & 0x07FF;
|
||||
sbus_data.channels[5] = (input_data[7] >> 7 | input_data[8] << 1 | input_data[9] << 9) & 0x07FF;
|
||||
sbus_data.channels[6] = (input_data[9] >> 2 | input_data[10] << 6) & 0x07FF;
|
||||
sbus_data.channels[7] = (input_data[10] >> 5 | input_data[11] << 3) & 0x07FF;
|
||||
sbus_data.channels[8] = (input_data[12] | input_data[13] << 8) & 0x07FF;
|
||||
sbus_data.channels[9] = (input_data[13] >> 3 | input_data[14] << 5) & 0x07FF;
|
||||
sbus_data.channels[10] = (input_data[14] >> 6 | input_data[15] << 2 | input_data[16] << 10) & 0x07FF;
|
||||
sbus_data.channels[11] = (input_data[16] >> 1 | input_data[17] << 7) & 0x07FF;
|
||||
sbus_data.channels[12] = (input_data[17] >> 4 | input_data[18] << 4) & 0x07FF;
|
||||
sbus_data.channels[13] = (input_data[18] >> 7 | input_data[19] << 1 | input_data[20] << 9) & 0x07FF;
|
||||
sbus_data.channels[14] = (input_data[20] >> 2 | input_data[21] << 6) & 0x07FF;
|
||||
sbus_data.channels[15] = (input_data[21] >> 5 | input_data[22] << 3) & 0x07FF;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD>ֽ<EFBFBD>
|
||||
sbus_data.flags = input_data[23];
|
||||
|
||||
//ת<><D7AA>
|
||||
sbus_temp = (float)(sbus_data.channels[0]);
|
||||
sbus_temp = (ZERO_VALUE - sbus_temp)*23;//<2F><>Ҫ<EFBFBD>任һ<E4BBBB>·<EFBFBD><C2B7>ţ<EFBFBD><C5A3><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
remote_curvature = (uint16_t)((int16_t)sbus_temp);//<2F><><EFBFBD><EFBFBD>
|
||||
|
||||
//ת<><D7AA>
|
||||
sbus_temp = (float)(sbus_data.channels[1]);
|
||||
sbus_temp = (ZERO_VALUE - sbus_temp)*2.3;//<2F><>Ҫ<EFBFBD>任һ<E4BBBB>·<EFBFBD><C2B7>ţ<EFBFBD><C5A3><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
remote_speed = (uint16_t)((int16_t)sbus_temp);//ת<><D7AA>
|
||||
|
||||
remote_Reserve = sbus_data.channels[7];
|
||||
|
||||
//SwA
|
||||
if(sbus_data.channels[3] >= 1700)//<2F><><EFBFBD><EFBFBD>
|
||||
{
|
||||
emergency_stop = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
emergency_stop = 0;
|
||||
}
|
||||
|
||||
//SwB
|
||||
if(sbus_data.channels[4] >= 1700)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
remote_switch_b = 2;
|
||||
}
|
||||
else if(sbus_data.channels[6] <= 250)//<2F>ڶ<EFBFBD><DAB6><EFBFBD>
|
||||
{
|
||||
remote_switch_b = 0;
|
||||
}
|
||||
else//<2F><>һ<EFBFBD><D2BB>
|
||||
{
|
||||
remote_switch_b = 1;
|
||||
}
|
||||
|
||||
//SwC
|
||||
if(sbus_data.channels[5] >= 1700)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
remote_switch_c = 2;
|
||||
}
|
||||
else if(sbus_data.channels[4] <= 250)//<2F>ڶ<EFBFBD><DAB6><EFBFBD>
|
||||
{
|
||||
remote_switch_c = 0;
|
||||
}
|
||||
else//<2F><>һ<EFBFBD><D2BB>
|
||||
{
|
||||
remote_switch_c = 1;
|
||||
}
|
||||
|
||||
//SwD
|
||||
if(sbus_data.channels[6] >= 1700)//<2F><><EFBFBD><EFBFBD>
|
||||
{
|
||||
remote_switch_d = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
remote_switch_d = 0;
|
||||
}
|
||||
|
||||
if(0 == sbus_data.flags)//<2F>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD>߹<EFBFBD><DFB9><EFBFBD><EFBFBD>ж<EFBFBD> //ͨ<><CDA8><EFBFBD><EFBFBD>־<EFBFBD><D6BE><EFBFBD>жϣ<D0B6> Ϊ0<CEAA><30>ʾ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
remote_enable = 1;//<2F>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
else
|
||||
{
|
||||
remote_enable = 0;//<2F>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
ssdk_printf(SSDK_NOTICE, "sta\r\n");
|
||||
for(int i=0;i<16;i++)
|
||||
{
|
||||
ssdk_printf(SSDK_EMERG, "%04x\r\n",sbus_data.channels[i]);
|
||||
}
|
||||
ssdk_printf(SSDK_NOTICE, "end\r\n");
|
||||
return &sbus_data;
|
||||
}
|
||||
|
||||
|
||||
void callback(sdrv_uart_t *ctrl, sdrv_uart_callback_status_e status,
|
||||
void *userData)
|
||||
{
|
||||
uint8_t char_data[25] = {0};//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽڻ<D6BD><DABB><EFBFBD>
|
||||
static uint8_t cnt_sbus = 0;
|
||||
static uint8_t state = 0;
|
||||
static uint8_t receive = 0;
|
||||
static uint8_t sbus_buff[25];
|
||||
SBusData *tmp_sbus_data;
|
||||
|
||||
// user_data_t *user_data = (user_data_t *)userData;
|
||||
|
||||
// ssdk_printf(SSDK_NOTICE, "123456789\r\n");
|
||||
|
||||
/* Uart receive data. */
|
||||
if (SDRV_UART_RxFWF == status)
|
||||
{
|
||||
uart_fault_info.remote_count ++;
|
||||
|
||||
size_t size = sdrv_uart_get_rxfifodata(ctrl, char_data,1);
|
||||
|
||||
// for(uint8_t i = 0; i < 25; i++)
|
||||
// {
|
||||
// test_app[i] = char_data[i];
|
||||
//
|
||||
// }
|
||||
|
||||
// sdrv_uart_sync_transmit(&g_console_uart, char_data,
|
||||
// 25, NULL,
|
||||
// 0Xffff);
|
||||
|
||||
// for(uint8_t i=0;i<25;i++)
|
||||
// {
|
||||
// ssdk_printf(SSDK_INFO,"char_data: %x \r\n", char_data[i]);
|
||||
// }
|
||||
//
|
||||
|
||||
// for(int i=0;i<size;i++)
|
||||
// {
|
||||
switch(state)
|
||||
{
|
||||
case 0:
|
||||
if(0x0f == char_data[0])
|
||||
{
|
||||
receive = 0;
|
||||
cnt_sbus = 0;
|
||||
sbus_buff[cnt_sbus] = char_data[0];
|
||||
cnt_sbus++;
|
||||
state = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = 0;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if(cnt_sbus >= 24)
|
||||
{
|
||||
for(uint8_t i = 0; i < 25; i++)
|
||||
{
|
||||
test_app[i] = sbus_buff[i];
|
||||
}
|
||||
test_app[25] = 0x55;
|
||||
// ssdk_printf(SSDK_INFO,"char_data24: %x \r\n", char_data[0]);
|
||||
if(0x0 == char_data[0])
|
||||
{
|
||||
cnt_sbus = 0;
|
||||
receive = 0;
|
||||
sbus_buff[cnt_sbus] = char_data[0];
|
||||
state = 0;
|
||||
tmp_sbus_data = parseSBusData(sbus_buff);
|
||||
|
||||
// sdrv_uart_sync_transmit(ctrl, "AA\r\n", strlen("AA\r\n"), NULL, 0xFFFF);
|
||||
|
||||
// sdrv_uart_sync_transmit(ctrl, ( const uint8_t *)&tmp_sbus_data->channels[0],
|
||||
// 32, NULL,
|
||||
// 0Xffff);
|
||||
// ssdk_printf(SSDK_EMERG, "AAAr\n");
|
||||
}
|
||||
}
|
||||
else if(0x0f == char_data[0])
|
||||
{
|
||||
receive = 0;
|
||||
cnt_sbus = 0;
|
||||
sbus_buff[cnt_sbus] = char_data[0];
|
||||
cnt_sbus++;
|
||||
state = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
sbus_buff[cnt_sbus] = char_data[0];
|
||||
cnt_sbus ++;
|
||||
state = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// }
|
||||
}
|
||||
else if (SDRV_UART_RxFifoOverFlow == status)
|
||||
{
|
||||
// if (0 != user_data->buff_remain) {
|
||||
// size_t size = sdrv_uart_get_rxfifodata(ctrl, user_data->user_buffer,
|
||||
// user_data->buff_remain);
|
||||
// }
|
||||
// sdrv_uart_sync_transmit(ctrl, "\r\n", strlen("\r\n"), NULL, TIMES_OUT);
|
||||
// sdrv_uart_sync_transmit(ctrl, user_data->user_buffer,
|
||||
// BUFFER_SIZE - user_data->buff_remain, NULL,
|
||||
// TIMES_OUT);
|
||||
// sdrv_uart_sync_transmit(ctrl, "\r\n", strlen("\r\n"), NULL, TIMES_OUT);
|
||||
//
|
||||
// memset(user_data->user_buffer, '\0', BUFFER_SIZE);
|
||||
// user_data->buff_ptr = user_data->user_buffer;
|
||||
// user_data->buff_remain = BUFFER_SIZE;
|
||||
//
|
||||
// sdrv_uart_sync_transmit(
|
||||
// ctrl, "\r\ncallback: SDRV_UART_RxFifoOverFlow!\r\n",
|
||||
// strlen("\r\ncallback: SDRV_UART_RxFifoOverFlow!\r\n"), NULL,
|
||||
// TIMES_OUT);
|
||||
//
|
||||
// /* User can stop or reset realtime receive if you want, when transfer
|
||||
// * occur errors */
|
||||
// sdrv_uart_stop_realtime_receive(ctrl);
|
||||
// sdrv_uart_start_realtime_receive(ctrl);
|
||||
|
||||
}
|
||||
else if (SDRV_UART_ParityError == status)
|
||||
{
|
||||
// sdrv_uart_sync_transmit(
|
||||
// ctrl, "\r\ncallback: SDRV_UART_ParityError!\r\n",
|
||||
// strlen("\r\ncallback: SDRV_UART_ParityError!\r\n"), NULL,
|
||||
// TIMES_OUT);
|
||||
}
|
||||
else if (SDRV_UART_BaudrateError == status)
|
||||
{
|
||||
// sdrv_uart_sync_transmit(
|
||||
// ctrl, "\r\ncallback: SDRV_UART_BaudrateError!\r\n",
|
||||
// strlen("\r\ncallback: SDRV_UART_BaudrateError!\r\n"), NULL,
|
||||
// TIMES_OUT);
|
||||
}
|
||||
else if (SDRV_UART_NoiseError == status)
|
||||
{
|
||||
// sdrv_uart_sync_transmit(
|
||||
// ctrl, "\r\ncallback: SDRV_UART_NoiseError!\r\n",
|
||||
// strlen("\r\ncallback: SDRV_UART_NoiseError!\r\n"), NULL, TIMES_OUT);
|
||||
}
|
||||
else if (SDRV_UART_FramingError == status)
|
||||
{
|
||||
// sdrv_uart_sync_transmit(
|
||||
// ctrl, "\r\ncallback: SDRV_UART_FramingError!\r\n",
|
||||
// strlen("\r\ncallback: SDRV_UART_FramingError!\r\n"), NULL,
|
||||
// TIMES_OUT);
|
||||
}
|
||||
else
|
||||
{
|
||||
// ssdk_printf(SSDK_NOTICE, "234567891\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void uart_Initialize(void)
|
||||
{
|
||||
/* Get uart clk Config. */
|
||||
#if ((CONFIG_E3210) || (CONFIG_E3110))
|
||||
if (g_uart_config.irq <= UART8_INTR_NUM) {
|
||||
g_uart_config.clk_freq =
|
||||
sdrv_ckgen_get_rate(CLK_NODE(g_ckgen_ip_uart_sf_1_to_8));
|
||||
} else {
|
||||
g_uart_config.clk_freq =
|
||||
sdrv_ckgen_get_rate(CLK_NODE(g_ckgen_ip_uart_sf_9_to_16));
|
||||
}
|
||||
#else
|
||||
if (g_uart_config.irq <= UART6_INTR_NUM) {
|
||||
g_uart_config.clk_freq =
|
||||
sdrv_ckgen_get_rate(CLK_NODE(g_ckgen_ip_uart_sf_1_to_6));
|
||||
} else {
|
||||
g_uart_config.clk_freq =
|
||||
sdrv_ckgen_get_rate(CLK_NODE(g_ckgen_ip_uart_sf_7_to_12));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Initializes sdrv uart controller. */
|
||||
|
||||
user_data.buff_ptr = user_data.user_buffer;
|
||||
user_data.buff_remain = BUFFER_SIZE;
|
||||
|
||||
ssdk_printf(SSDK_NOTICE, "uart3 init\r\n");
|
||||
sdrv_uart_controller_init(&uart_ctrl_ptr, &g_uart_config, callback,
|
||||
&user_data);
|
||||
|
||||
sdrv_uart_start_realtime_receive(&uart_ctrl_ptr);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void uartTimerProcess(void)
|
||||
{
|
||||
static uint8_t uart_timer = 0;
|
||||
static uint8_t uart_temp[1] = {2};//<2F>м<EFBFBD><D0BC>ж<EFBFBD>ֵ
|
||||
//----------------------------------------------------------------------------
|
||||
uart_timer ++;
|
||||
if(uart_timer >= 1)//500ms<6D>ж<EFBFBD>һ<EFBFBD><D2BB>
|
||||
{
|
||||
uart_timer = 0;
|
||||
if(uart_fault_info.remote_count == uart_temp[0])//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
||||
{
|
||||
uart_fault_info.remote_state = FAULT;
|
||||
}
|
||||
else
|
||||
{
|
||||
uart_fault_info.remote_state = NORMAL;
|
||||
uart_temp[0] = uart_fault_info.remote_count;//<2F><><EFBFBD>ݸ<EFBFBD><DDB8><EFBFBD>
|
||||
}
|
||||
|
||||
if(uart_fault_info.remote_state != uart_temp[1])
|
||||
{
|
||||
// publishMessage(&uart_fault_info.remote_state, 1);// ״̬<D7B4>仯 <20><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
|
||||
uart_temp[1] = uart_fault_info.remote_state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//Timer uart_timer_interface;
|
||||
|
||||
// APPģ<50><C4A3><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC>
|
||||
void uartAppInit(void)
|
||||
{
|
||||
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9> brake_timer <20>ĵ<EFBFBD>ַ<EFBFBD><D6B7>Ϊ<EFBFBD>ź<EFBFBD>ID
|
||||
// timerInit(&uart_timer_interface, 100);
|
||||
// subscribe(&uart_timer_interface, uartTimerProcess);
|
||||
|
||||
// timerStart(&uart_timer_interface);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
#ifndef _INTERFACE_UART_H_
|
||||
#define _INTERFACE_UART_H_
|
||||
|
||||
#include "interface_config.h"
|
||||
#include <sdrv_uart.h>
|
||||
|
||||
|
||||
#define ZERO_VALUE 1022//<2F><><EFBFBD><EFBFBD>ң<EFBFBD><D2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ʱ<30><CAB1><EFBFBD><EFBFBD>Ϊ1022
|
||||
|
||||
#define remote_speed un_remote_control_input.bit_data.speed//<2F>ٶ<EFBFBD>
|
||||
#define remote_curvature un_remote_control_input.bit_data.curvature//ת<><D7AA>
|
||||
#define remote_Reserve un_remote_control_input.bit_data.reserve1//<2F><><EFBFBD><EFBFBD>
|
||||
#define emergency_stop un_remote_control_input.bit_data.switch_a//DF_SwA
|
||||
#define remote_switch_b un_remote_control_input.bit_data.switch_b//DF_SwB
|
||||
#define remote_switch_c un_remote_control_input.bit_data.switch_c//DF_SwC
|
||||
#define remote_switch_d un_remote_control_input.bit_data.switch_d//DF_SwD
|
||||
#define remote_enable un_remote_control_input.bit_data.enable//<2F>ֱ<EFBFBD>ʹ<EFBFBD><CAB9>״̬
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t remote_count; //ң<>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t remote_state; //ң<><D2A3>״̬
|
||||
}UartFaultInfo;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void uart_Initialize(void);
|
||||
|
||||
void callback(sdrv_uart_t *ctrl, sdrv_uart_callback_status_e status,
|
||||
void *userData);
|
||||
|
||||
#endif /* _INTERFACE_H_ */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#include <sdrv_btm.h>
|
||||
#include <regs_base.h>
|
||||
#include <irq_num.h>
|
||||
#include <debug.h>
|
||||
#include <sdrv_rstgen.h>
|
||||
#include "interface_config.h"
|
||||
|
||||
sdrv_wdt_t *wdt_type = (sdrv_wdt_t *)(uintptr_t)APB_WDT1_BASE;
|
||||
|
||||
static bool internal_reset_switch = true;
|
||||
static bool external_reset_switch = false;
|
||||
|
||||
//<2F><><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD>ʼ<EFBFBD><CABC>
|
||||
void wdt_init(uint32_t timeoutms)
|
||||
{
|
||||
static sdrv_wdt_config_t wdt_cfg;
|
||||
int ret = 0;
|
||||
//--------------------------------------------------
|
||||
sdrv_wdt_get_default_config(&wdt_cfg);
|
||||
|
||||
if (internal_reset_switch) {
|
||||
wdt_cfg.int_rst.reset_en = true;
|
||||
sdrv_rstgen_wdt_reset_enable(RESET_WDT1, true);
|
||||
}
|
||||
|
||||
if (external_reset_switch) {
|
||||
/* config GPIO_H12 as WDT1_RST_N function */
|
||||
wdt_cfg.ext_rst.reset_en = true;
|
||||
wdt_cfg.ext_rst.reset_mode = 0; /* low level active */
|
||||
}
|
||||
|
||||
ret = sdrv_wdt_init(wdt_type, &wdt_cfg);
|
||||
ASSERT(ret == 0);
|
||||
|
||||
// irq_attach(wdt_irq, wdt_irq_handler, NULL);
|
||||
// irq_enable(wdt_irq);
|
||||
|
||||
sdrv_wdt_set_timeout(wdt_type, timeoutms);
|
||||
|
||||
ret = sdrv_wdt_enable(wdt_type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
#ifndef _INTERFACE_WDT_H_
|
||||
#define _INTERFACE_WDT_H_
|
||||
|
||||
#include <sdrv_watchdog.h>
|
||||
|
||||
|
||||
|
||||
#define WDT_OUTms 1600
|
||||
|
||||
|
||||
|
||||
|
||||
//<2F>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD>
|
||||
void wdt_init(uint32_t timeoutms);
|
||||
|
||||
|
||||
|
||||
|
||||
void External_wdt_refresh(void);
|
||||
|
||||
//<2F>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD>
|
||||
extern sdrv_wdt_t *wdt_type;
|
||||
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* _INTERFACE_WDT_H_*/
|
||||
126
boards/e3_176_ref/app_demo/eth-xip/20241203可移动基站调试完成无原地转向/main.c
Normal file
126
boards/e3_176_ref/app_demo/eth-xip/20241203可移动基站调试完成无原地转向/main.c
Normal file
@@ -0,0 +1,126 @@
|
||||
#include <types.h>
|
||||
#include "board.h"
|
||||
#include "debug.h"
|
||||
#include "regs_base.h"
|
||||
#include "irq_num.h"
|
||||
|
||||
#include "clock_cfg.h"
|
||||
#include "reset_cfg.h"
|
||||
#include "pinmux_cfg.h"
|
||||
#include "eth_cfg.h"
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/inet.h"
|
||||
#include "lwip/tcp.h"
|
||||
#include "lwip/timeouts.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "lwip/udp.h"
|
||||
#include "flexcan_cfg.h"
|
||||
|
||||
#include "interface_config.h"
|
||||
#include "irq.h"
|
||||
//app包含
|
||||
#include "app/app_config.h"
|
||||
#include "app/app_param_manage.h"
|
||||
#include "app/app_power.h"
|
||||
#include "app/app_brake.h"
|
||||
#include "app/app_differential_drive.h"
|
||||
#include <app/app_test.h>
|
||||
#include <app/app_temp.h>
|
||||
#include <app/app_base.h>
|
||||
#include <app/app_turn.h>
|
||||
#include <app/app_light.h>
|
||||
|
||||
void testAppInit(void);
|
||||
|
||||
#define IP_ADDR0 10
|
||||
#define IP_ADDR1 18
|
||||
#define IP_ADDR2 252
|
||||
#define IP_ADDR3 34
|
||||
|
||||
|
||||
extern int btm_init(void);
|
||||
extern struct tcp_pcb *netdemo_connect_server(char *ip, int port);
|
||||
extern bool netdemo_tcp_connected(void);
|
||||
extern bool netdemo_tcp_send_done(void);
|
||||
extern void netdemo_clear_tcp_send_done(void);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
uint8_t mainCnt = 0;
|
||||
uint8_t mainCntarr[8] = {0x56,0x88,0x98,0x79,0x23};
|
||||
uint8_t desIp[4] = {192,168,17,3};
|
||||
|
||||
uint8_t test_app[26] = {0};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
initFramework();
|
||||
|
||||
uint8_t BOOT_Arr[2] = {0x01,0x02};//上电发送app帧给上位机用
|
||||
|
||||
// 释放MCU各模块reset信号
|
||||
board_reset_init();
|
||||
|
||||
// 配置时钟
|
||||
int ret = sdrv_ckgen_init(&g_clock_config);
|
||||
ASSERT(ret == 0);
|
||||
|
||||
// VIC初始化
|
||||
irq_initialize(VIC1_BASE, IRQ_MAX_INTR_NUM);
|
||||
|
||||
// 配置pinmux
|
||||
sdrv_pinctrl_init(NUM_OF_CONFIGURED_PINS, g_pin_init_config);
|
||||
|
||||
// Timer初始化,用于提供LWIP sys_now接口获取当前时间
|
||||
btm_init();
|
||||
|
||||
// 使能打印
|
||||
board_debug_console_init();
|
||||
printf("debug_console_init initial OK %d\n",getCurrentTime());
|
||||
//初始化所有can
|
||||
initialization_All_Flexcan();
|
||||
printf("initialization_All_Flexcan initial OK %d\n",getCurrentTime());
|
||||
// ETH初始化
|
||||
board_eth_init();
|
||||
|
||||
initSpi();//初始化SPI
|
||||
|
||||
//以太网端口初始化
|
||||
UDP_Echo_Init(UDPCB_1, udp_Callback_1, COMMUNICATION_PORT);
|
||||
UDP_Echo_Init(UDPCB_2, udp_Callback_2, UPPER_PORT);
|
||||
UDP_Echo_Init(UDPCB_3, udp_Callback_3, PARAM_PORT);
|
||||
printf("board_eth_init initial OK %d\n",getCurrentTime());
|
||||
//读取重启标志
|
||||
g_systemDataRecord.canBootloaderUpgrade = rdbyte_24c02(0x00);
|
||||
printf("rdbyte_24c02 OK %d\n",getCurrentTime());
|
||||
//发送重启后的第一帧给上位机
|
||||
CAN_Send_Msg(&can_handle_6,OTA_CANTxID, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, BOOT_Arr,2, TX_MB_INDEX);//app 帧
|
||||
printf("CAN_Send_Msg can_handle_6 OK %d\n",getCurrentTime());
|
||||
//打印版本号
|
||||
printf("version: V1.72 \n");
|
||||
// 初始化框架 放在最前面,解决电机can发送信号累积不处理的问题。
|
||||
|
||||
testAppInit();
|
||||
paramAppInit();
|
||||
diffAppInit();
|
||||
brakeAppInit();
|
||||
powerAppInit(); //电源管理
|
||||
turnAppInit(); //舵机转向
|
||||
tempAppInit(); //温度
|
||||
lightAppInit(); //灯光
|
||||
baseAppInit(); //基站
|
||||
gpioInterfaceInit();
|
||||
canInterfaceInit();
|
||||
ethernetInterfaceInit();
|
||||
bootInterfaceInit();
|
||||
|
||||
printf("All init OK ------ %d\n",getCurrentTime());
|
||||
for (;;)
|
||||
{
|
||||
// 处理信号
|
||||
processMessages();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user