初始版本
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
#ifndef __ADS1231__
|
||||
#define __ADS1231__
|
||||
|
||||
#include "bsp.h"
|
||||
|
||||
void ADS1231_Open(void);
|
||||
void ADS1231_SpeedSet(void);
|
||||
bool ADS1231_Read(uint32_t *r_data, uint8_t channel);
|
||||
void ADS1231_HighSpeedSet(void);
|
||||
void ADS1231_LowSpeedSet(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
#ifndef __CAT_ONE_TASK_H
|
||||
#define __CAT_ONE_TASK_H
|
||||
#include "main.h"
|
||||
#include "Public.h"
|
||||
|
||||
#define CAT_ONE_REV_TIMEOUT_MAX (10 * 60 * 1000)
|
||||
#define CAT_ONE_REV_LEN_MAX 512
|
||||
|
||||
#define CAT_ONE_POW_ON() CAT1_POW_ON()
|
||||
#define CAT_ONE_POW_OFF() CAT1_POW_OFF()
|
||||
|
||||
#define CAT_ONE_LINKA_GET() CAT1_LINKA_GET()
|
||||
#define CAT_ONE_LINKB_GET() CAT1_LINKB_GET()
|
||||
|
||||
#define CAT_ONE_DELAY_1MS(X)
|
||||
|
||||
typedef enum {
|
||||
CAT_ONE_AT_NULL,
|
||||
CAT_ONE_AT, //开机检测
|
||||
CAT_ONE_ATE0, //关回显
|
||||
CAT_ONE_CPIN, //识卡
|
||||
CAT_ONE_IMEI,
|
||||
CAT_ONE_LCCID, //读卡
|
||||
CAT_ONE_CEREG, //查询注册状态
|
||||
CAT_ONE_CGPADDR, //查询IP地址
|
||||
CAT_ONE_CSQ, //查询信号强度
|
||||
CAT_ONE_LDNSGIP, //域名解析
|
||||
CAT_ONE_LBS, //获取基站定位信息
|
||||
CAT_ONE_LIPOPEN, //设置TCP服务器地址和端口
|
||||
CAT_ONE_LIPSEND, //发送数据
|
||||
CAT_ONE_LTPCLOSE, //断开连接
|
||||
CAT_ONE_LBSPARA,
|
||||
CAT_ONE_CCLK, //获取时间
|
||||
CAT_ONE_AT_CMD_END,
|
||||
}CatOneATCMD_m;
|
||||
|
||||
typedef enum {
|
||||
CAT_ONE_IDEL,
|
||||
CAT_ONE_INIT,
|
||||
CAT_ONE_TCP_CONN,
|
||||
CAT_ONE_WAIT_CONN,
|
||||
CAT_ONE_SEND_DATA,
|
||||
CAT_ONE_WAIT_SEND,
|
||||
CAT_ONE_REV_DATA,
|
||||
CAT_ONE_REG_SVR,
|
||||
CAT_ONE_WAIT_REV,
|
||||
CAT_ONE_RESET,
|
||||
CAT_ONE_OFF,
|
||||
CAT_ONE_CLOSE_TCP,
|
||||
}CatOneStatus_m;
|
||||
|
||||
typedef enum {
|
||||
CAT_ONE_RET_NULL,
|
||||
CAT_ONE_RET_OK,
|
||||
CAT_ONE_RET_ERR,
|
||||
CAT_ONE_RET_TIMEOUT,
|
||||
}CatOneRetStatus_m;
|
||||
|
||||
typedef enum {
|
||||
CAT_ONE_CMD_MODE,
|
||||
CAT_ONE_PT_MODE,
|
||||
}CatOneMode_m;
|
||||
|
||||
typedef enum {
|
||||
CAT_ONE_2G,
|
||||
CAT_ONE_ATE,
|
||||
}CatOneNetType_m;
|
||||
|
||||
typedef struct {
|
||||
CatOneStatus_m Status;
|
||||
CatOneStatus_m NextStatus;
|
||||
CatOneRetStatus_m ATCmdRet;
|
||||
uint32_t CatOne1mSDelayCnt;
|
||||
uint32_t ResetDelayCnt;
|
||||
uint32_t RegisterDelayCnt;
|
||||
uint8_t AtCmdResendCnt;
|
||||
uint8_t AtCmdIdx;
|
||||
CatOneATCMD_m AtCmd;
|
||||
bool RxFlag;
|
||||
uint16_t CSQ;
|
||||
char IMEI[20];
|
||||
char SIM[32];
|
||||
CatOneNetType_m NetType;
|
||||
bool TcpConnFlag;
|
||||
|
||||
bool LBSFlag;
|
||||
int Longitude;
|
||||
int Latitude;
|
||||
char CatOneSendBuff[1024];
|
||||
|
||||
GateWayPara GateWay;
|
||||
DataRevCallBack CatOneRevCallBack;
|
||||
}CatOne_t, *pCatOne_t;
|
||||
|
||||
CatOneRetStatus_m CatOneSend(uint8_t *sData, uint16_t sLen);
|
||||
void CatOneStart(void);
|
||||
void CatOneStop(void);
|
||||
void CatOneReset(void);
|
||||
void Cat1DBGOnOff(bool OnOff);
|
||||
void CatOneGetLocationInfo(int *Longitude, int *Latitude);
|
||||
void CatOneGetIMEIAndSIM(char *Imei, char *Sim);
|
||||
bool CatOneGetStatus(void);
|
||||
bool CatOneEthSendQueue(uint8_t *sData, uint16_t sLen);
|
||||
void CatOne_Eth_Thread_Entry(void *parameter);
|
||||
void EthRxOverhandler(void);
|
||||
void CatReadImeiOrSim(char *Imei, char *Sim);
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef __DEBUG_CMD_H
|
||||
#define __DEBUG_CMD_H
|
||||
|
||||
void Debug_Thread_Entry(void *parameter);
|
||||
void DebugRxOverhandler(void);
|
||||
void Debug_Printf(char *format, ...);
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef __EPT__
|
||||
#define __EPT__
|
||||
|
||||
void Encrypt_Code(unsigned char *data, unsigned char *EPT_data);
|
||||
void Decrypt_Code(unsigned char *EPT_data,unsigned char *DPT_data);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef __LORA_TASK_H
|
||||
#define __LORA_TASK_H
|
||||
|
||||
#include "bsp.h"
|
||||
#include "sx127x.h"
|
||||
|
||||
void Lora_Thread_Entry(void *parameter);
|
||||
int LoraRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen);
|
||||
void LoraInit(void);
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
#ifndef __PUBLIC_H
|
||||
#define __PUBLIC_H
|
||||
|
||||
#include "bsp.h"
|
||||
|
||||
#define LORA_LOWPOWER //LORA低功耗设备,采用主动上报方式
|
||||
|
||||
#define SENSOR_DATA_LEN_MAX 50
|
||||
#define SENSOR_NUM_MAX 16
|
||||
#define COMMUNIT_NUM_MAX 32
|
||||
|
||||
#define REGISTER_INTERVAL_MAX (2 * 60)
|
||||
#define COMMUNIT_READ_SENSOR_INTERVAL_MAX (1 * 60)
|
||||
|
||||
#define LORA_ERR_RESET_DLY_MAX (10 * 60) //LORA接收超时复位延时,单位秒
|
||||
#define CAT1_ERR_RESET_DLY_MAX (60 * 60) //CAT1接收超时复位延时,单位秒
|
||||
|
||||
typedef struct GateWay_t GateWayPara_t, *GateWayPara;
|
||||
|
||||
typedef void (*SendData)(uint8_t *sData, uint16_t sLen);
|
||||
typedef int (*DataRevCallBack)(GateWayPara GateWay, uint8_t *rData, uint16_t rLen);
|
||||
typedef int (*DataRevResCallBack)(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData Response);
|
||||
typedef int (*SendDataOrg)(uint8_t *sData);
|
||||
|
||||
typedef enum {
|
||||
DEBUG_CH_DBG,
|
||||
DEBUG_CH_RS485_1,
|
||||
DEBUG_CH_RS485_2,
|
||||
}DebugChannel_m;
|
||||
|
||||
|
||||
typedef enum {
|
||||
DEV_TYPE_BROADCAST,
|
||||
DEV_TYPE_INC_COMMUNIT = 0x8001,
|
||||
DEV_TYPE_EXT_COMMUNIT,
|
||||
DEV_TYPE_ICE_SENSOR,
|
||||
DEV_TYPE_CRACK_SENSOR,
|
||||
DEV_TYPE_PRESSURE_SENSOR,
|
||||
DEV_TYPE_RAIN_SENSOR,
|
||||
}DevType_m;
|
||||
|
||||
typedef enum {
|
||||
CATONE_COMM,
|
||||
ETH_COMM,
|
||||
}CommType_m;
|
||||
|
||||
typedef enum {
|
||||
LORA_COMM,
|
||||
RS485CH1_COMM,
|
||||
RS485CH2_COMM
|
||||
}SensorComm_m;
|
||||
|
||||
typedef enum {
|
||||
COMM_UNIT_CMD_REG,
|
||||
COMM_UNIT_CMD_CAIL,
|
||||
COMM_UNIT_CMD_READ,
|
||||
COMM_UNIT_CMD_SET_SENSOR_COLL_TIME = 5,
|
||||
COMM_UNIT_CMD_TIME_SYNC,
|
||||
COMM_UNIT_CMD_CONT_LASER = 8,//激光独有指令
|
||||
COMM_UNIT_CMD_END,
|
||||
}CommUnitCmd_m;
|
||||
|
||||
typedef enum {
|
||||
NET_COMM_CMD_REG,
|
||||
NET_COMM_CMD_CAIL,
|
||||
NET_COMM_CMD_UPDATE,
|
||||
NET_COMM_CMD_READ_GW_INFO,
|
||||
//NET_COMM_CMD_READ_UNIT_INFO,
|
||||
NET_COMM_CMD_GW_PARA_CONFIG,
|
||||
NET_COMM_CMD_HIS_DATA,
|
||||
NET_COMM_CMD_ADD_UNIT,
|
||||
NET_COMM_CMD_LP_DEV_CONFIG,
|
||||
NET_COMM_CMD_ALARM,
|
||||
NET_COMM_CMD_CONT_LASER,//激光独有指令
|
||||
NET_COMM_CMD_END,
|
||||
}NetCommCmd_m;
|
||||
|
||||
typedef enum {
|
||||
SENSOR_TYPE_NULL, //0x0000 空设备
|
||||
FORCE_6D, //0x0001 六维应力
|
||||
OSMOTIC_PRESSURE, //0x0002 渗透压
|
||||
ELASTIC_WAVEGUIDE, //0x0003 弹性波导
|
||||
DIELECTRIC_MASS, //0x0004 介电质普
|
||||
VIBRATE_SENSOR, //0x0005 微振动传感器
|
||||
CONT_DEFOR_3D, //0x0006 三维连续变形
|
||||
COMM_UNIT, //0x0007 通讯单元
|
||||
FORCE_3D, //0x0008 三维应力
|
||||
LASER_TRACING, //0x0009 激光示踪
|
||||
WATER_LEVEL, //0x000A 水位计
|
||||
_0x000B, //0x000B 保留
|
||||
_0x000C, //0x000C 保留
|
||||
MULTI_PARAMETER_FUSION, //0x000D 多参数融合
|
||||
CRACK_DETECTION, //0x000E 裂缝仪
|
||||
_0x000F, //0x000F 保留
|
||||
ATTITUDE_MONITOR, //0x0010 姿态检测
|
||||
LASER_DISPLACE, //0x0011 激光位移
|
||||
REBAR_STRESS, //0x0012 钢筋应力
|
||||
ANCHOR_ROD_STRESS, //0x0013 锚杆轴力
|
||||
SURFACE_STRESS, //0x0014 表面应力
|
||||
PRESSURE, //0x0015 压力
|
||||
MICROWAVE_DISPLACE, //0x0016 微波位移
|
||||
}SensorType_m;
|
||||
|
||||
typedef struct {//主设备固定包头
|
||||
uint8_t BatLevel; //电池电量
|
||||
int8_t RSSI; //信号强度
|
||||
int8_t Nsr; //信噪比
|
||||
}__attribute__ ((packed))MasterDev_T,*MasterDevDp;
|
||||
|
||||
typedef struct {
|
||||
int16_t AccX;
|
||||
int16_t AccY;
|
||||
int16_t AccZ;
|
||||
int32_t Strain1;
|
||||
int32_t Strain2;
|
||||
int32_t Strain3;
|
||||
int32_t Strain4;
|
||||
int32_t Strain5;
|
||||
int32_t Strain6;
|
||||
}__attribute__((packed))Force6D_T;
|
||||
|
||||
typedef struct {
|
||||
MasterDev_T MasterDev;
|
||||
int16_t PitchAngle; //俯仰角偏斜 (范围±900)单位0.1°
|
||||
int16_t RollAngle; //横滚角偏斜 (范围±900)单位0.1°
|
||||
int16_t YawAngle; //偏航角偏斜 (范围0~3600)单位0.1°
|
||||
}__attribute__((packed))LaserTracingType_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t CommDevAddr[6]; //通讯单元地址
|
||||
uint16_t CollectInterval; //采集时间间隔
|
||||
uint16_t ReportInterval; //上报时间间隔
|
||||
uint8_t ERInterval; //紧急上报时间间隔
|
||||
uint8_t ERTime; //紧急上报时长
|
||||
}__attribute__((packed))SvrDownLPDevConfigPara_t;
|
||||
|
||||
typedef struct {
|
||||
int Distance;
|
||||
}__attribute__((packed))LaserDistanceSensorType_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t AlarmType;
|
||||
uint8_t AlarmState;
|
||||
uint8_t AlarmPara;
|
||||
}__attribute__((packed))GateWayAlarmType_t;
|
||||
|
||||
#define LW_DEV_COLLECT_INTERVAL_MAX 300//默认300秒
|
||||
#define LW_DEV_REPORT_INTERVAL_MAX 20//20分钟
|
||||
#define LW_DEV_ER_INTERVAL_MAX 2//2分钟
|
||||
#define LW_DEV_ER_TIME_MAX 20//20分钟
|
||||
|
||||
typedef struct {
|
||||
uint16_t CollectInterval; //采集时间间隔
|
||||
uint16_t ReportInterval; //上报时间间隔
|
||||
uint8_t ERInterval; //紧急上报时间间隔
|
||||
uint8_t ERTime; //紧急上报时长
|
||||
uint32_t TimeStamp; //时间戳
|
||||
}__attribute__((packed))LPDevConfigPara_t;
|
||||
|
||||
typedef struct {
|
||||
bool RegFlag;
|
||||
bool RevNewDataFlag;
|
||||
bool CommStatus; //通讯状态,1-在线,0-离线
|
||||
bool CailFlag; //校准标志(低功耗)
|
||||
bool TimeSyncFlag; //时间同步标志(低功耗)
|
||||
bool ContLaser; //激光控制标志(低功耗)
|
||||
bool LaserOnOff; //激光状态(低功耗)
|
||||
uint32_t CommErrCnt;
|
||||
uint8_t MasterMac[6];
|
||||
uint8_t Mac[SENSOR_NUM_MAX][6];//第一位是主设备,后面全是子设备
|
||||
uint8_t BatLevel;
|
||||
int8_t RSSI; //信号强度
|
||||
int8_t Nsr; //信噪比
|
||||
uint16_t CUType;
|
||||
uint8_t SensorN;
|
||||
uint16_t SensorType[SENSOR_NUM_MAX];
|
||||
//低功耗设备配置信息
|
||||
bool ConfigFlag; //配置标志,为1表示有新配置,应答低功耗设备时需要附带发送
|
||||
uint16_t CollectInterval; //采集时间间隔
|
||||
uint16_t ReportInterval; //上报时间间隔
|
||||
uint8_t ERInterval; //紧急上报时间间隔
|
||||
uint8_t ERTime; //紧急上报时长
|
||||
}CommUnitPara_t, *CommUnitPara;
|
||||
|
||||
typedef struct {
|
||||
uint8_t Data[SENSOR_NUM_MAX][SENSOR_DATA_LEN_MAX];
|
||||
}CommUnitData_t, *CommUnitData;
|
||||
|
||||
typedef struct {
|
||||
CommUnitPara_t Para;
|
||||
}CommUnit_t, *CommUnit;
|
||||
|
||||
typedef struct {
|
||||
bool Enable; //串口使能
|
||||
bool CommUnitEnable; //通讯单元使能,开启(使用内部通讯单元功能,直接和传感器通讯),关闭(直接和RS485类型的通讯单元通讯)
|
||||
bool QuerySensorFlag; //查询传感器标志
|
||||
bool UpgradeEnable;//升级功能使能
|
||||
uint8_t Power;
|
||||
uint32_t BaudRate;
|
||||
SendData RS485Send;
|
||||
CommUnit_t CUData;
|
||||
}RS485Para_t, *RS485Para;
|
||||
|
||||
typedef struct {
|
||||
uint8_t Header;
|
||||
uint8_t GWMac[6];
|
||||
uint8_t DevMac[6];
|
||||
uint8_t Cmd;
|
||||
//uint16_t DevType;
|
||||
uint16_t PayloadLen;
|
||||
}__attribute__((packed))CommUnitFrameHeader_t, *CommUnitFrameHeader;
|
||||
|
||||
typedef struct {
|
||||
uint8_t Header;
|
||||
uint8_t GWMac[6];
|
||||
//uint8_t SvrMac[6];
|
||||
uint8_t Cmd;
|
||||
uint8_t BatLevel;
|
||||
uint32_t Timestamp;
|
||||
uint8_t PacketNum;
|
||||
uint8_t PacketIdx;
|
||||
uint16_t PayloadLen;
|
||||
}__attribute__((packed))NetCommFrameHeader_t, *NetCommFrameHeader;
|
||||
|
||||
typedef struct {
|
||||
bool OnOff;
|
||||
SendData LoraSend;
|
||||
uint8_t ucChannel;
|
||||
int8_t ucPower;
|
||||
uint8_t SignalBw;
|
||||
uint8_t SpreadFactor;
|
||||
uint8_t ErrorCoding;
|
||||
uint8_t RegPreamble;
|
||||
uint32_t FreqCent;
|
||||
}LoraPara_t, *pLoraPara;
|
||||
|
||||
typedef struct {
|
||||
uint32_t SavFlag; //存储标志
|
||||
CommType_m Comm; //网关通讯方式
|
||||
uint8_t GwMac[6]; //网关mac
|
||||
char SvrAddr[4]; //服务器地址
|
||||
uint32_t SvrPort; //服务器端口
|
||||
uint32_t CommUnitReadInterval; //通讯单元读取时间间隔,单位S
|
||||
CommUnitPara_t CommUnitArray[COMMUNIT_NUM_MAX]; //注册的通讯单元信息
|
||||
RS485Para_t Rs485Ch1; //RS485通道1配置
|
||||
RS485Para_t Rs485Ch2; //RS485通道2配置
|
||||
uint8_t DebugChannel; //调试通道
|
||||
LoraPara_t Lora; //Lora配置
|
||||
bool OutageFlag; //断电报警标志
|
||||
uint16_t crc16;
|
||||
}__attribute__((packed))GWConfigPara_t, *GWConfigPara;
|
||||
|
||||
struct GateWay_t{
|
||||
bool TimeSyncFlag; //时间同步标志
|
||||
bool SvrRegFlag; //服务器注册标志
|
||||
uint8_t SvrMac[6]; //服务器mac
|
||||
GWConfigPara_t ConfigPara; //配置参数
|
||||
CommUnitData_t CUDataArray[COMMUNIT_NUM_MAX];
|
||||
uint8_t Battery; //电池电量
|
||||
uint16_t UploadInterval; //上传间隔
|
||||
uint32_t HistoryNum; //历史数据数量
|
||||
DataRevCallBack SvrRevCallBack; //接收到服务器回调
|
||||
DataRevResCallBack CommUnitRevCallBack; //通讯单元接收回调
|
||||
rt_mq_t NetSendData_MQ; //网络发送数据队列,第一个字节用于存储消息长度, 第二字节存储命令字,后为数据
|
||||
rt_mq_t LoraRev_MQ; //Lora接收消息队列,第一个字节用于存储消息长度,后为数据
|
||||
rt_mutex_t UartRevMutex;
|
||||
|
||||
uint8_t BatteryReadDlyCnt; //读取电压延时,单位秒,防止4G发送拉低电池电压,造成断电误报
|
||||
};
|
||||
|
||||
int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen);
|
||||
uint16_t CRC_Modbus(uint16_t wBase, __IO uint8_t *para, uint16_t length);
|
||||
uint8_t AsciiToHex(char *ASCData, uint8_t *HexData, uint8_t sLen);
|
||||
void HexToAscii(uint8_t *HexData, char *ASCData, uint8_t sLen);
|
||||
int NetCommOrgData(GateWayPara GateWay, uint8_t *MegData, uint8_t *OutData);
|
||||
int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData Response);
|
||||
void DebugAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen);
|
||||
void CommUnitCmdSend(GateWayPara GateWay, uint8_t *CommUnitMac, CommUnitCmd_m Cmd, uint8_t *Payload, uint16_t PayloadLen, SendData Send);
|
||||
int CheckCommUnitReg(GateWayPara GateWay, uint8_t *CommUnitMac);
|
||||
int CommUintOrgData(GateWayPara GateWay, CommUnitPara CUPara, CommUnitData CUData, uint8_t *sData);
|
||||
void DebugDisplaySensorData(int SensorIdx, uint16_t SensorType, uint8_t *SensorData);
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef __PUBLIC_TYPES_H
|
||||
#define __PUBLIC_TYPES_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef void (*ReadPara)(pSFBTPara rPara);
|
||||
typedef void (*SavPara)(pSFBTPara wPara);
|
||||
typedef void (*UartSend)(uint8_t *sData, int sLen);
|
||||
typedef void (*DataRevCallBack)(uint8_t *rData, uint8_t rLen);
|
||||
typedef int (*SendDataOrg)(uint8_t *sData);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
#ifndef __RS485_TASK_H
|
||||
#define __RS485_TASK_H
|
||||
|
||||
#include "bsp.h"
|
||||
#include "Public.h"
|
||||
|
||||
#define RS485_RX_BUFF_LEN_MAX 64
|
||||
|
||||
typedef struct {
|
||||
SensorComm_m Com;
|
||||
uint16_t SensorType;
|
||||
}SensorTypes_t;
|
||||
|
||||
typedef enum {
|
||||
RS485_OUT_VOLTAGE_OV,
|
||||
RS485_OUT_VOLTAGE_5V,
|
||||
RS485_OUT_VOLTAGE_12V,
|
||||
}RS485Vol_m;
|
||||
|
||||
typedef struct {
|
||||
uint8_t Header;
|
||||
uint8_t SlvAddr;
|
||||
uint8_t Cmd;
|
||||
//uint16_t DevType;
|
||||
uint8_t PayloadLen;
|
||||
}__attribute__((packed))FrameHeader_t, *FrameHeader;
|
||||
|
||||
typedef enum {
|
||||
RS485_SENSOR_CMD_NULL,
|
||||
RS485_SENSOR_CMD_CAIL,
|
||||
RS485_SENSOR_CMD_READ,
|
||||
RS485_SENSOR_CMD_QUERY,
|
||||
RS485_SENSOR_CMD_SET_ADDR,
|
||||
RS485_SENSOR_CMD_SET_INV_TIME,
|
||||
RS485_SENSOR_CMD_TIME_SYNC,
|
||||
RS485_SENSOR_CMD_END,
|
||||
}RS485SensorCmd_m;
|
||||
|
||||
//´«¸ÐÆ÷Êý¾Ý·¢ËͽṹÌå
|
||||
typedef struct {
|
||||
bool SendFlag;
|
||||
uint8_t SensorCnt;
|
||||
uint8_t SensorErrCnt[SENSOR_NUM_MAX];
|
||||
uint8_t ReadSensorCnt;
|
||||
int32_t ReadSensorInterval;
|
||||
RS485SensorCmd_m Cmd;
|
||||
uint8_t SensorAddr;
|
||||
uint16_t SensorType;
|
||||
uint8_t CmdParaLen;
|
||||
uint8_t *CmdPara;
|
||||
uint8_t RS485RxBuff[RS485_RX_BUFF_LEN_MAX];
|
||||
uint8_t RS485RxLen;
|
||||
uint8_t RS485TimeOutCnt;
|
||||
uint32_t RS485CommUnitReadTimeDelay;
|
||||
uint8_t SendUnitCommIdx;
|
||||
rt_sem_t RS485Rev_Sem;
|
||||
bool InitOverFlag;
|
||||
CommUnitData_t SensorData;
|
||||
}SensorCommPara_t, *SensorCommPara;
|
||||
|
||||
void RS485CmdSend(GateWayPara GateWay, uint8_t CommUintAddr, SensorCommPara SensorComm);
|
||||
void RS485Ch1_Thread_Entry(void *parameter);
|
||||
void RS485Ch2_Thread_Entry(void *parameter);
|
||||
void RS485RxOverhandler(void);
|
||||
|
||||
extern SensorCommPara_t SComm1Para;
|
||||
extern SensorCommPara_t SComm2Para;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef _APP_COMM_H_
|
||||
#define _APP_COMM_H_
|
||||
|
||||
#include "rtthread.h"
|
||||
|
||||
#define BSP_LOG(format,...) do { \
|
||||
rt_kprintf(format, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,414 @@
|
||||
#ifndef __BSP_H
|
||||
#define __BSP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "hc32_ddl.h"
|
||||
#include "rtthread.h"
|
||||
#include "ff.h"
|
||||
|
||||
//#define USE_BOOTLOADER
|
||||
|
||||
//#define FLASH_SECTOR_SIZE 0x2000ul
|
||||
//#define FLASH_BASE ((uint32_t)0x00000000)
|
||||
//#define FLASH_SIZE (64u * FLASH_SECTOR_SIZE)
|
||||
|
||||
|
||||
//#define SRAM_BASE ((uint32_t)0x1FFF8000)
|
||||
//#define RAM_SIZE 0x2F000ul
|
||||
|
||||
|
||||
//#define BOOT_SIZE (4 * FLASH_SECTOR_SIZE)
|
||||
//#define APP_ADDRESS (FLASH_BASE + BOOT_SIZE)
|
||||
|
||||
//#define BOOT_PARA_ADDRESS (FLASH_SIZE - FLASH_SECTOR_SIZE)
|
||||
//#define BOOT_PARA_SIZE (FLASH_SECTOR_SIZE)
|
||||
|
||||
/* flash rom map 存储分区*/
|
||||
//boot 16k
|
||||
#define FLASH_BASE ((uint32_t)0x00000000)
|
||||
#define FLASH_SECTOR_SIZE 0x2000ul
|
||||
|
||||
#define FLASH_BOOT_BASE (FLASH_BASE)
|
||||
#define FLASH_BOOT_SIZE (4*FLASH_SECTOR_SIZE)
|
||||
//app
|
||||
#define FLASH_APP_BASE (FLASH_BOOT_BASE+ FLASH_BOOT_SIZE)
|
||||
#define FLASH_APP_SIZE (58*FLASH_SECTOR_SIZE)
|
||||
|
||||
//boot info
|
||||
#define FLASH_BINFO_BASE (FLASH_APP_BASE + FLASH_APP_SIZE)
|
||||
#define FLASH_BINFO_SIZE (1*FLASH_SECTOR_SIZE)
|
||||
|
||||
//user config
|
||||
#define FLASH_CFG_BASE (FLASH_BINFO_BASE + FLASH_BINFO_SIZE)
|
||||
#define FLASH_CFG_SIZE (1*FLASH_SECTOR_SIZE)
|
||||
|
||||
#define FLASH_CFG_MAGIC (0xa5)
|
||||
|
||||
#define APP_START_FLAG 0x55AA5A5A
|
||||
#define APP_UPDATE_FLAG 0xA5A5AA55
|
||||
|
||||
|
||||
#define WATCH_DOG 1
|
||||
|
||||
#define DEBUG 1
|
||||
#define USE_SD_CARD 0
|
||||
|
||||
#define RTC_IRQn Int001_IRQn
|
||||
|
||||
#define LORA_DIO0_IRQn Int005_IRQn
|
||||
|
||||
#define DBGUART_IRQn Int006_IRQn
|
||||
#define DBGUART_EI_IRQn Int007_IRQn
|
||||
|
||||
#define RS485CH1_UART_IRQn Int008_IRQn
|
||||
#define RS485CH1_UART_EI_IRQn Int009_IRQn
|
||||
|
||||
#define RS485CH2_UART_IRQn Int010_IRQn
|
||||
#define RS485CH2_UART_EI_IRQn Int011_IRQn
|
||||
|
||||
#define ETH_OR_CAT1_UART_IRQn Int012_IRQn
|
||||
#define ETH_OR_CAT1_UART_EI_IRQn Int013_IRQn
|
||||
|
||||
#define DBG_RXPIN_IRQn Int002_IRQn
|
||||
|
||||
|
||||
//DEBUG
|
||||
#define DBG_USART_CH (M4_USART1)
|
||||
#define DBG_USART_RX_PORT (PortA)
|
||||
#define DBG_USART_RX_PIN (Pin11)
|
||||
#define DBG_USART_TX_PORT (PortA)
|
||||
#define DBG_USART_TX_PIN (Pin12)
|
||||
#define DBG_USART_RX_FUNC (Func_Usart1_Rx)
|
||||
#define DBG_USART_TX_FUNC (Func_Usart1_Tx)
|
||||
#define DBG_USART_RI_NUM (INT_USART1_RI)
|
||||
#define DBG_USART_EI_NUM (INT_USART1_EI)
|
||||
#define DBG_USART_TI_NUM (INT_USART1_TI)
|
||||
#define DBG_USART_TCI_NUM (INT_USART1_TCI)
|
||||
#define DBG_FCG1_PERIPH (PWC_FCG1_PERIPH_USART1)
|
||||
|
||||
//RS485 Ch1
|
||||
#define RS485_CH1_USART_CH (M4_USART2)
|
||||
#define RS485_CH1_USART_RX_PORT (PortA)
|
||||
#define RS485_CH1_USART_RX_PIN (Pin10)
|
||||
#define RS485_CH1_USART_TX_PORT (PortA)
|
||||
#define RS485_CH1_USART_TX_PIN (Pin08)
|
||||
#define RS485_CH1_USART_RX_FUNC (Func_Usart2_Rx)
|
||||
#define RS485_CH1_USART_TX_FUNC (Func_Usart2_Tx)
|
||||
#define RS485_CH1_USART_RI_NUM (INT_USART2_RI)
|
||||
#define RS485_CH1_USART_EI_NUM (INT_USART2_EI)
|
||||
#define RS485_CH1_USART_TI_NUM (INT_USART2_TI)
|
||||
#define RS485_CH1_USART_TCI_NUM (INT_USART2_TCI)
|
||||
#define RS485_CH1_FCG1_PERIPH (PWC_FCG1_PERIPH_USART2)
|
||||
|
||||
#define RS485_CH1_CTRL_PORT (PortC)
|
||||
#define RS485_CH1_CTRL_PIN (Pin07)
|
||||
#define RS485_CH1_TX() PORT_SetBits(RS485_CH1_CTRL_PORT, RS485_CH1_CTRL_PIN)
|
||||
#define RS485_CH1_RX() PORT_ResetBits(RS485_CH1_CTRL_PORT, RS485_CH1_CTRL_PIN)
|
||||
|
||||
#define RS485_CH1_POW_PORT (PortC)
|
||||
#define RS485_CH1_POW_PIN (Pin10)
|
||||
#define RS485_CH1_POW_ON() PORT_SetBits(RS485_CH1_POW_PORT, RS485_CH1_POW_PIN)
|
||||
#define RS485_CH1_POW_OFF() PORT_ResetBits(RS485_CH1_POW_PORT, RS485_CH1_POW_PIN)
|
||||
|
||||
//#define RS485_CH1_VOL_CTRL_PORT (PortA)
|
||||
//#define RS485_CH1_VOL_CTRL_PIN (Pin15)
|
||||
//#define RS485_CH1_VOL_5V() PORT_SetBits(RS485_CH1_VOL_CTRL_PORT, RS485_CH1_VOL_CTRL_PIN)
|
||||
//#define RS485_CH1_VOL_12V() PORT_ResetBits(RS485_CH1_VOL_CTRL_PORT, RS485_CH1_VOL_CTRL_PIN)
|
||||
|
||||
//RS485 Ch2
|
||||
#define RS485_CH2_USART_CH (M4_USART3)
|
||||
#define RS485_CH2_USART_RX_PORT (PortB)
|
||||
#define RS485_CH2_USART_RX_PIN (Pin14)
|
||||
#define RS485_CH2_USART_TX_PORT (PortB)
|
||||
#define RS485_CH2_USART_TX_PIN (Pin12)
|
||||
#define RS485_CH2_USART_RX_FUNC (Func_Usart3_Rx)
|
||||
#define RS485_CH2_USART_TX_FUNC (Func_Usart3_Tx)
|
||||
#define RS485_CH2_USART_RI_NUM (INT_USART3_RI)
|
||||
#define RS485_CH2_USART_EI_NUM (INT_USART3_EI)
|
||||
#define RS485_CH2_USART_TI_NUM (INT_USART3_TI)
|
||||
#define RS485_CH2_USART_TCI_NUM (INT_USART3_TCI)
|
||||
#define RS485_CH2_FCG1_PERIPH (PWC_FCG1_PERIPH_USART3)
|
||||
|
||||
#define RS485_CH2_CTRL_PORT (PortB)
|
||||
#define RS485_CH2_CTRL_PIN (Pin13)
|
||||
#define RS485_CH2_TX() PORT_SetBits(RS485_CH2_CTRL_PORT, RS485_CH2_CTRL_PIN)
|
||||
#define RS485_CH2_RX() PORT_ResetBits(RS485_CH2_CTRL_PORT, RS485_CH2_CTRL_PIN)
|
||||
|
||||
#define RS485_CH2_POW_PORT (PortB)
|
||||
#define RS485_CH2_POW_PIN (Pin02)
|
||||
#define RS485_CH2_POW_ON() PORT_SetBits(RS485_CH2_POW_PORT, RS485_CH2_POW_PIN)
|
||||
#define RS485_CH2_POW_OFF() PORT_ResetBits(RS485_CH2_POW_PORT, RS485_CH2_POW_PIN)
|
||||
|
||||
//#define RS485_CH2_VOL_CTRL_PORT (PortB)
|
||||
//#define RS485_CH2_VOL_CTRL_PIN (Pin10)
|
||||
//#define RS485_CH2_VOL_5V() PORT_SetBits(RS485_CH2_VOL_CTRL_PORT, RS485_CH2_VOL_CTRL_PIN)
|
||||
//#define RS485_CH2_VOL_12V() PORT_ResetBits(RS485_CH2_VOL_CTRL_PORT, RS485_CH2_VOL_CTRL_PIN)
|
||||
|
||||
//ETH OR CAT1
|
||||
#define ETH_OR_CAT1_USART_CH (M4_USART4)
|
||||
#define ETH_OR_CAT1_USART_RX_PORT (PortB)
|
||||
#define ETH_OR_CAT1_USART_RX_PIN (Pin09)
|
||||
#define ETH_OR_CAT1_USART_TX_PORT (PortC)
|
||||
#define ETH_OR_CAT1_USART_TX_PIN (Pin13)
|
||||
#define ETH_OR_CAT1_USART_RX_FUNC (Func_Usart4_Rx)
|
||||
#define ETH_OR_CAT1_USART_TX_FUNC (Func_Usart4_Tx)
|
||||
#define ETH_OR_CAT1_USART_RI_NUM (INT_USART4_RI)
|
||||
#define ETH_OR_CAT1_USART_EI_NUM (INT_USART4_EI)
|
||||
#define ETH_OR_CAT1_USART_TI_NUM (INT_USART4_TI)
|
||||
#define ETH_OR_CAT1_USART_TCI_NUM (INT_USART4_TCI)
|
||||
#define ETH_OR_CAT1_FCG1_PERIPH (PWC_FCG1_PERIPH_USART4)
|
||||
|
||||
#define ETH_OR_CAT1_CTRL_PORT (PortB)
|
||||
#define ETH_OR_CAT1_CTRL_PIN (Pin08)
|
||||
#define ETH_ON() PORT_SetBits(ETH_OR_CAT1_CTRL_PORT, ETH_OR_CAT1_CTRL_PIN)
|
||||
#define CAT1_ON() PORT_ResetBits(ETH_OR_CAT1_CTRL_PORT, ETH_OR_CAT1_CTRL_PIN)
|
||||
|
||||
//#define ETH_OR_CAT1_TX_CTRL_PORT (PortH)
|
||||
//#define ETH_OR_CAT1_TX_CTRL_PIN (Pin02)
|
||||
//#define ETH_ON() { PORT_SetBits(ETH_OR_CAT1_CTRL_PORT, ETH_OR_CAT1_CTRL_PIN); PORT_SetBits(ETH_OR_CAT1_TX_CTRL_PORT, ETH_OR_CAT1_TX_CTRL_PIN); }
|
||||
//#define CAT1_ON() { PORT_ResetBits(ETH_OR_CAT1_CTRL_PORT, ETH_OR_CAT1_CTRL_PIN); PORT_ResetBits(ETH_OR_CAT1_TX_CTRL_PORT, ETH_OR_CAT1_TX_CTRL_PIN);}
|
||||
|
||||
#define CAT1_PWR_KEY_PORT (PortA)
|
||||
#define CAT1_PWR_KEY_PIN (Pin03)
|
||||
#define CAT1_PWR_KEY_CLR() PORT_SetBits(CAT1_PWR_KEY_PORT, CAT1_PWR_KEY_PIN)
|
||||
#define CAT1_PWR_KEY_SET() PORT_ResetBits(CAT1_PWR_KEY_PORT, CAT1_PWR_KEY_PIN)
|
||||
|
||||
#define CAT1_RESET_PORT (PortA)
|
||||
#define CAT1_RESET_PIN (Pin00)
|
||||
#define CAT1_RESET_CLR() PORT_SetBits(CAT1_RESET_PORT, CAT1_RESET_PIN)
|
||||
#define CAT1_RESET_SET() PORT_ResetBits(CAT1_RESET_PORT, CAT1_RESET_PIN)
|
||||
|
||||
//#define CAT1_POW_PORT (PortA)
|
||||
//#define CAT1_POW_PIN (Pin00)
|
||||
//#define CAT1_POW_ON() PORT_SetBits(CAT1_POW_PORT, CAT1_POW_PIN)
|
||||
//#define CAT1_POW_OFF() PORT_ResetBits(CAT1_POW_PORT, CAT1_POW_PIN)
|
||||
|
||||
#define ETH_RESET_PORT (PortB)
|
||||
#define ETH_RESET_PIN (Pin05)
|
||||
#define ETH_RESET_SET() PORT_SetBits(ETH_RESET_PORT, ETH_RESET_PIN)
|
||||
#define ETH_RESET_CLR() PORT_ResetBits(ETH_RESET_PORT, ETH_RESET_PIN)
|
||||
|
||||
#define ETH_DEF_PORT (PortB)
|
||||
#define ETH_DEF_PIN (Pin07)
|
||||
#define ETH_DEF_SET() PORT_SetBits(ETH_DEF_PORT, ETH_DEF_PIN)
|
||||
#define ETH_DEF_CLR() PORT_ResetBits(ETH_DEF_PORT, ETH_DEF_PIN)
|
||||
|
||||
#define ETH_LINK_PORT (PortB)
|
||||
#define ETH_LINK_PIN (Pin06)
|
||||
#define ETH_LINK_GET() PORT_GetBit(ETH_LINK_PORT, ETH_LINK_PIN)
|
||||
|
||||
/* SPI_MOSI Port/Pin definition */
|
||||
#define SPI_NSS_PORT (PortC)
|
||||
#define SPI_NSS_PIN (Pin00)
|
||||
#define SPI_NSS_FUNC (Func_Spi1_Nss0)
|
||||
#define SPI_NSS_SET() PORT_SetBits(SPI_NSS_PORT, SPI_NSS_PIN)
|
||||
#define SPI_NSS_CLR() PORT_ResetBits(SPI_NSS_PORT, SPI_NSS_PIN)
|
||||
|
||||
/* SPI_SCK Port/Pin definition */
|
||||
#define SPI_SCK_PORT (PortC)
|
||||
#define SPI_SCK_PIN (Pin02)
|
||||
#define SPI_SCK_FUNC (Func_Spi1_Sck)
|
||||
|
||||
/* SPI_MOSI Port/Pin definition */
|
||||
#define SPI_MOSI_PORT (PortC)
|
||||
#define SPI_MOSI_PIN (Pin03)
|
||||
#define SPI_MOSI_FUNC (Func_Spi1_Mosi)
|
||||
|
||||
/* SPI_MISO Port/Pin definition */
|
||||
#define SPI_MISO_PORT (PortC)
|
||||
#define SPI_MISO_PIN (Pin01)
|
||||
#define SPI_MISO_FUNC (Func_Spi1_Miso)
|
||||
|
||||
/* SPI unit and clock definition */
|
||||
#define SPI_UNIT (M4_SPI1)
|
||||
#define SPI_UNIT_CLOCK (PWC_FCG1_PERIPH_SPI1)
|
||||
|
||||
|
||||
//LORA IO
|
||||
/* SPI_SCK Port/Pin definition */
|
||||
#define SPI2_SCK_PORT (PortC)
|
||||
#define SPI2_SCK_PIN (Pin04)
|
||||
#define SPI2_SCK_FUNC (Func_Spi2_Sck)
|
||||
|
||||
/* SPI_MOSI Port/Pin definition */
|
||||
#define SPI2_MOSI_PORT (PortA)
|
||||
#define SPI2_MOSI_PIN (Pin07)
|
||||
#define SPI2_MOSI_FUNC (Func_Spi2_Mosi)
|
||||
|
||||
/* SPI_MISO Port/Pin definition */
|
||||
#define SPI2_MISO_PORT (PortA)
|
||||
#define SPI2_MISO_PIN (Pin06)
|
||||
#define SPI2_MISO_FUNC (Func_Spi2_Miso)
|
||||
|
||||
/* SPI_MOSI Port/Pin definition */
|
||||
#define SPI2_NSS_PORT (PortC)
|
||||
#define SPI2_NSS_PIN (Pin05)
|
||||
#define SPI2_NSS_FUNC (Func_Spi2_Nss0)
|
||||
#define SPI2_NSS_SET() PORT_SetBits(SPI2_NSS_PORT, SPI2_NSS_PIN)
|
||||
#define SPI2_NSS_CLR() PORT_ResetBits(SPI2_NSS_PORT, SPI2_NSS_PIN)
|
||||
|
||||
/* SPI unit and clock definition */
|
||||
#define SPI2_UNIT (M4_SPI2)
|
||||
#define SPI2_UNIT_CLOCK (PWC_FCG1_PERIPH_SPI2)
|
||||
|
||||
#define LORA_DIO_PORT (PortA)
|
||||
#define LORA_DIO_PIN (Pin04)
|
||||
#define LORA_DIO_GET() PORT_GetBit(LORA_DIO_PORT, LORA_DIO_PIN)
|
||||
#define LORA_DIO_EXIT_CH (ExtiCh04)
|
||||
#define LORA_DIO_EXIT_SRC (INT_PORT_EIRQ4)
|
||||
|
||||
#define LORA_RESET_PORT (PortA)
|
||||
#define LORA_RESET_PIN (Pin05)
|
||||
#define LORA_RESET_SET() PORT_SetBits(LORA_RESET_PORT, LORA_RESET_PIN)
|
||||
#define LORA_RESET_CLR() PORT_ResetBits(LORA_RESET_PORT, LORA_RESET_PIN)
|
||||
|
||||
#define LORA_RXEN_PORT (PortB)
|
||||
#define LORA_RXEN_PIN (Pin00)
|
||||
#define LORA_RXEN_SET() PORT_SetBits(LORA_RXEN_PORT, LORA_RXEN_PIN)
|
||||
#define LORA_RXEN_CLR() PORT_ResetBits(LORA_RXEN_PORT, LORA_RXEN_PIN)
|
||||
|
||||
#define LORA_TXEN_PORT (PortB)
|
||||
#define LORA_TXEN_PIN (Pin01)
|
||||
#define LORA_TXEN_SET() PORT_SetBits(LORA_TXEN_PORT, LORA_TXEN_PIN)
|
||||
#define LORA_TXEN_CLR() PORT_ResetBits(LORA_TXEN_PORT, LORA_TXEN_PIN)
|
||||
|
||||
#define LORA_RX_LED_PORT (PortB)
|
||||
#define LORA_RX_LED_PIN (Pin03)
|
||||
#define LORA_RX_LED_SET() PORT_SetBits(LORA_RX_LED_PORT, LORA_RX_LED_PIN)
|
||||
#define LORA_RX_LED_CLR() PORT_ResetBits(LORA_RX_LED_PORT, LORA_RX_LED_PIN)
|
||||
#define LORA_RX_TOGGLE() PORT_Toggle(LORA_RX_LED_PORT, LORA_RX_LED_PIN)
|
||||
|
||||
#define LORA_POW_PORT (PortC)
|
||||
#define LORA_POW_PIN (Pin06)
|
||||
#define LORA_POW_ON() PORT_SetBits(LORA_POW_PORT, LORA_POW_PIN)
|
||||
#define LORA_POW_OFF() PORT_ResetBits(LORA_POW_PORT, LORA_POW_PIN)
|
||||
|
||||
#define POWER_LED_PORT (PortB)
|
||||
#define POWER_LED_PIN (Pin04)
|
||||
#define POWER_LED_ON() PORT_SetBits(POWER_LED_PORT, POWER_LED_PIN)
|
||||
#define POWER_LED_OFF() PORT_ResetBits(POWER_LED_PORT, POWER_LED_PIN)
|
||||
#define POWER_TOGGLE() PORT_Toggle(POWER_LED_PORT, POWER_LED_PIN)
|
||||
|
||||
#if USE_SD_CARD
|
||||
#include "sd_card.h"
|
||||
/* SDIOC Port/Pin definition */
|
||||
#define SDIOC_CD_PORT (PortA)
|
||||
#define SDIOC_CD_PIN (Pin10)
|
||||
|
||||
#define SDIOC_CK_PORT (PortC)
|
||||
#define SDIOC_CK_PIN (Pin12)
|
||||
|
||||
#define SDIOC_CMD_PORT (PortD)
|
||||
#define SDIOC_CMD_PIN (Pin02)
|
||||
|
||||
#define SDIOC_D0_PORT (PortC)
|
||||
#define SDIOC_D0_PIN (Pin08)
|
||||
|
||||
#define SDIOC_D1_PORT (PortC)
|
||||
#define SDIOC_D1_PIN (Pin09)
|
||||
|
||||
#define SDIOC_D2_PORT (PortA)
|
||||
#define SDIOC_D2_PIN (Pin09)
|
||||
|
||||
#define SDIOC_D3_PORT (PortC)
|
||||
#define SDIOC_D3_PIN (Pin11)
|
||||
|
||||
/* SD sector && count */
|
||||
#define SD_SECTOR_START (0u)
|
||||
#define SD_SECTOR_COUNT (4u)
|
||||
|
||||
/* SDIOC unit */
|
||||
#define SDIOC_UNIT (M4_SDIOC1)
|
||||
|
||||
en_result_t SdioInit(void);
|
||||
bool SDCardErase(uint32_t u32BlkStartAddr, uint32_t u32BlkEndAddr);
|
||||
bool SDCardReadBlocks(uint32_t u32BlkStartAddr, uint32_t u32BlkEndAddr, uint8_t *ReadBuff);
|
||||
bool SDCardWriteBlocks(uint32_t u32BlkStartAddr, uint32_t u32BlkEndAddr, uint8_t *WriteBuff);
|
||||
#endif
|
||||
|
||||
#define BAT_COLL_ADC_CH (ADC1_CH1)
|
||||
|
||||
//帧头结构体
|
||||
typedef struct {
|
||||
uint8_t Header;
|
||||
uint8_t SlvAddr;
|
||||
uint8_t Cmd;
|
||||
uint8_t PayloadLen;
|
||||
}update_protocol_hd_t;
|
||||
|
||||
//主机下发升级请求载荷结构体
|
||||
typedef struct {
|
||||
uint16_t PackageNum;
|
||||
uint32_t AppSize;
|
||||
uint32_t AppCrc32;
|
||||
}__attribute__ ((packed))update_protocol_req_t;
|
||||
|
||||
//从机请求下发结构体
|
||||
typedef struct {
|
||||
uint16_t PackageIndex;
|
||||
uint32_t PackageNum;
|
||||
}__attribute__ ((packed))update_protocol_get_t;
|
||||
|
||||
//主机应答下发数据结构体
|
||||
typedef struct {
|
||||
uint16_t PackageIndex;
|
||||
uint16_t PackageNum;
|
||||
uint8_t DataLen;
|
||||
}__attribute__ ((packed))update_protocol_rsp_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t AppFlag;
|
||||
uint32_t DevType;
|
||||
uint32_t DevAddr;
|
||||
uint32_t UpdateFlag;
|
||||
uint32_t PackageNum;
|
||||
uint32_t AppSize;
|
||||
uint32_t Crc32Check;
|
||||
}boot_para_t;
|
||||
|
||||
void BSP_Init(void);
|
||||
|
||||
void DbgUart_Config(uint32_t BaudRate);
|
||||
void DebugUartSend(uint8_t *sData, uint16_t sLen);
|
||||
void DbgRxIrqCallback(uint8_t rData);
|
||||
|
||||
void RS485Ch1_Config(uint32_t BaudRate);
|
||||
void RS485Ch1UartSend(uint8_t *sData, uint16_t sLen);
|
||||
void RS485Ch1RxIrqCallback(uint8_t rData);
|
||||
|
||||
void RS485Ch2_Config(uint32_t BaudRate);
|
||||
void RS485Ch2UartSend(uint8_t *sData, uint16_t sLen);
|
||||
void RS485Ch2RxIrqCallback(uint8_t rData);
|
||||
|
||||
void EthOrCat1UartSend(uint8_t *sData, uint16_t sLen);
|
||||
void EthOrCat1RxIrqCallback(uint8_t rData);
|
||||
|
||||
void LoraTxRxIrqCallback(void);
|
||||
|
||||
uint16_t Spi1SendReceive(uint16_t sData);
|
||||
uint16_t Spi2SendReceive(uint16_t sData);
|
||||
|
||||
//void ReadAdcValue(uint16_t *ADValue);
|
||||
uint16_t GetADCBuffPoint(void);
|
||||
void ADC_Start(void) ;
|
||||
|
||||
void FeedDog(void);
|
||||
void Error_Handler(void);
|
||||
|
||||
int TimeTs(void);
|
||||
void TimeShow(uint32_t dwStamp);
|
||||
void TimeSync(time_t ts) ;
|
||||
void TimeGet(struct tm *cTime);
|
||||
void TimeSync2(uint8_t Year, uint8_t Month, uint8_t Day, uint8_t Hour, uint8_t Min, uint8_t Sec);
|
||||
|
||||
void FlashWrite(uint32_t Addr, uint32_t *wData, uint8_t wLen);
|
||||
void FlashRead(uint32_t Addr,uint32_t *rData, uint8_t rLen);
|
||||
void dev_boot_read_param(boot_para_t *pParam);
|
||||
int dev_boot_write_param(boot_para_t Param);
|
||||
//extern stc_sd_handle_t stcSdhandle;
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
|
||||
*
|
||||
* This software component is licensed by HDSC under BSD 3-Clause license
|
||||
* (the "License"); You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/** \file ddl_config.h
|
||||
**
|
||||
** A detailed description is available at
|
||||
** @link DdlConfigGroup Ddl Config description @endlink
|
||||
**
|
||||
** - 2021-04-16 CDT First version for Device Driver Library config.
|
||||
**
|
||||
******************************************************************************/
|
||||
#ifndef __DDL_CONFIG_H__
|
||||
#define __DDL_CONFIG_H__
|
||||
|
||||
/*******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
|
||||
/* C binding of definitions if building with C++ compiler */
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \defgroup DdlConfigGroup Device Driver Library config(DDLCONFIG)
|
||||
**
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/*******************************************************************************
|
||||
* Global type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Global pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
/*! Chip module on-off define */
|
||||
#define DDL_ON (1u)
|
||||
#define DDL_OFF (0u)
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief This is the list of modules to be used in the device driver library
|
||||
** Select the modules you need to use to DDL_ON.
|
||||
**
|
||||
** \note DDL_ICG_ENABLE must be turned on(DDL_ON) to ensure that the chip works
|
||||
** properly.
|
||||
**
|
||||
** \note DDL_UTILITY_ENABLE must be turned on(DDL_ON) if using Device Driver
|
||||
** Library.
|
||||
**
|
||||
** \note DDL_PRINT_ENABLE must be turned on(DDL_ON) if using printf function.
|
||||
******************************************************************************/
|
||||
#ifndef BOOT_ENABLE
|
||||
#define DDL_ICG_ENABLE (DDL_ON)
|
||||
#endif
|
||||
|
||||
//#define DDL_ICG_ENABLE (DDL_ON)
|
||||
#define DDL_UTILITY_ENABLE (DDL_ON)
|
||||
#define DDL_PRINT_ENABLE (DDL_OFF)
|
||||
|
||||
#define DDL_ADC_ENABLE (DDL_ON)
|
||||
#define DDL_AES_ENABLE (DDL_OFF)
|
||||
#define DDL_CAN_ENABLE (DDL_OFF)
|
||||
#define DDL_CLK_ENABLE (DDL_ON)
|
||||
#define DDL_CMP_ENABLE (DDL_OFF)
|
||||
#define DDL_CRC_ENABLE (DDL_OFF)
|
||||
#define DDL_DCU_ENABLE (DDL_OFF)
|
||||
#define DDL_DMAC_ENABLE (DDL_ON)
|
||||
#define DDL_EFM_ENABLE (DDL_ON)
|
||||
#define DDL_EMB_ENABLE (DDL_OFF)
|
||||
#define DDL_EVENT_PORT_ENABLE (DDL_OFF)
|
||||
#define DDL_EXINT_NMI_SWI_ENABLE (DDL_ON)
|
||||
#define DDL_GPIO_ENABLE (DDL_ON)
|
||||
#define DDL_HASH_ENABLE (DDL_OFF)
|
||||
#define DDL_I2C_ENABLE (DDL_OFF)
|
||||
#define DDL_I2S_ENABLE (DDL_OFF)
|
||||
#define DDL_INTERRUPTS_ENABLE (DDL_ON)
|
||||
#define DDL_INTERRUPTS_SHARE_ENABLE (DDL_OFF)
|
||||
#define DDL_KEYSCAN_ENABLE (DDL_OFF)
|
||||
#define DDL_MPU_ENABLE (DDL_OFF)
|
||||
#define DDL_OTS_ENABLE (DDL_OFF)
|
||||
#define DDL_PWC_ENABLE (DDL_ON)
|
||||
#define DDL_QSPI_ENABLE (DDL_OFF)
|
||||
#define DDL_RMU_ENABLE (DDL_OFF)
|
||||
#define DDL_RTC_ENABLE (DDL_ON)
|
||||
#define DDL_SDIOC_ENABLE (DDL_ON)
|
||||
#define DDL_SPI_ENABLE (DDL_ON)
|
||||
#define DDL_SRAM_ENABLE (DDL_ON)
|
||||
#define DDL_SWDT_ENABLE (DDL_ON)
|
||||
#define DDL_TIMER0_ENABLE (DDL_OFF)
|
||||
#define DDL_TIMER4_CNT_ENABLE (DDL_OFF)
|
||||
#define DDL_TIMER4_EMB_ENABLE (DDL_OFF)
|
||||
#define DDL_TIMER4_OCO_ENABLE (DDL_OFF)
|
||||
#define DDL_TIMER4_PWM_ENABLE (DDL_OFF)
|
||||
#define DDL_TIMER4_SEVT_ENABLE (DDL_OFF)
|
||||
#define DDL_TIMER6_ENABLE (DDL_OFF)
|
||||
#define DDL_TIMERA_ENABLE (DDL_OFF)
|
||||
#define DDL_TRNG_ENABLE (DDL_OFF)
|
||||
#define DDL_USART_ENABLE (DDL_ON)
|
||||
#define DDL_USBFS_ENABLE (DDL_OFF)
|
||||
#define DDL_WDT_ENABLE (DDL_OFF)
|
||||
|
||||
|
||||
/*! Midware module on-off define */
|
||||
#define MW_ON (1u)
|
||||
#define MW_OFF (0u)
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief This is the list of Midware modules to use
|
||||
** Select the modules you need to use to MW_ON.
|
||||
******************************************************************************/
|
||||
#define MW_FS_ENABLE (MW_OFF)
|
||||
#define MW_SD_CARD_ENABLE (MW_OFF)
|
||||
#define MW_W25QXX_ENABLE (MW_OFF)
|
||||
#define MW_WM8731_ENABLE (MW_OFF)
|
||||
|
||||
/* BSP on-off define */
|
||||
#define BSP_ON (1u)
|
||||
#define BSP_OFF (0u)
|
||||
|
||||
/**
|
||||
* @brief The following is a list of currently supported BSP boards.
|
||||
*/
|
||||
#define BSP_EV_HC32F460_LQFP100_V1 (1u)
|
||||
#define BSP_EV_HC32F460_LQFP100_V2 (2u)
|
||||
|
||||
/**
|
||||
* @brief The macro BSP_EV_HC32F460 is used to specify the BSP board currently
|
||||
* in use.
|
||||
* The value should be set to one of the list of currently supported BSP boards.
|
||||
* @note If there is no supported BSP board or the BSP function is not used,
|
||||
* the value needs to be set to BSP_EV_HC32F460.
|
||||
*/
|
||||
#define BSP_EV_HC32F460 (BSP_EV_HC32F460_LQFP100_V2)
|
||||
|
||||
/*******************************************************************************
|
||||
* Global variable definitions ('extern')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Global function prototypes (definition in C source)
|
||||
******************************************************************************/
|
||||
|
||||
//@} // DdlConfigGroup
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __DDL_CONFIG_H__ */
|
||||
|
||||
/*******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef __MAIN__H
|
||||
#define __MAIN__H
|
||||
#include "bsp.h"
|
||||
#include "Public.h"
|
||||
#include "DebugCmd.h"
|
||||
|
||||
#define SOFTWARE_VERSION 12
|
||||
#define HARDWARE_VERSION 12
|
||||
|
||||
#define MAC_ADDR_TYPE 1//0为测试服务器
|
||||
|
||||
extern bool MainDispEn;
|
||||
#define MAIN_DBG_LOG(...) { if(MainDispEn) Debug_Printf(__VA_ARGS__);}
|
||||
|
||||
void MainDBGOnOff(bool OnOff);
|
||||
#endif
|
||||
@@ -0,0 +1,96 @@
|
||||
#ifndef _PROTOCOL_H_
|
||||
#define _PROTOCOL_H_
|
||||
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
#define PROTOCOL_BUF_MAX (512)
|
||||
|
||||
#define PROTOCOL_HEAD (0x527A)
|
||||
|
||||
#define PROTOCOL_FRAME_HEAD_SIZE (7) // 最小帧长:头(2) + 地址(2) + 命令(1) + 长度(2) + CRC(2)
|
||||
|
||||
#define PROTOCOL_FRAME_MIN_SIZE (9) // 最小帧长:头(2) + 地址(2) + 命令(1) + 长度(2) + CRC(2)
|
||||
// 错误码定义
|
||||
typedef enum {
|
||||
PROTOCOL_SUCCESS = 0,
|
||||
PROTOCOL_ERR_INVALID_PARAM,
|
||||
PROTOCOL_ERR_BUFFER_OVERFLOW,
|
||||
PROTOCOL_ERR_CRC
|
||||
}protocol_err_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PROTOCOL_CMD_GET_AD =0x81,
|
||||
PROTOCOL_CMD_GET_TP =0x82,
|
||||
|
||||
PROTOCOL_CMD_SET_ID =0x83,
|
||||
PROTOCOL_CMD_GET_ID =0x84,
|
||||
|
||||
PROTOCOL_CMD_SET_TP_OFFSET =0x8A,
|
||||
PROTOCOL_CMD_GET_TP_OFFSET =0x8B,
|
||||
|
||||
PROTOCOL_CMD_RESET_CHANNEL =0x8F,
|
||||
|
||||
}protocol_cmd_t;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t status;
|
||||
float value;
|
||||
} ch_data_t;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t dev_status;
|
||||
ch_data_t channels[8];
|
||||
uint8_t reserved[7];
|
||||
} ad_datas_t;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t dev_status;
|
||||
ch_data_t channels[8];
|
||||
uint8_t reserved[7];
|
||||
} tp_datas_t;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t id;
|
||||
uint8_t reserved[3];
|
||||
} id_data_t;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t id;
|
||||
union{
|
||||
uint8_t bytes[4];
|
||||
float value;
|
||||
}prams;
|
||||
|
||||
} offset_set_data_t,offset_get_data_t;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t id;
|
||||
}offset_get_param_t;
|
||||
|
||||
extern int protocol_pack_frame(
|
||||
uint16_t slave_addr,
|
||||
uint8_t command,const
|
||||
uint8_t *payload,
|
||||
uint16_t payload_len,
|
||||
uint8_t *buffer,uint16_t buffer_size,
|
||||
uint16_t *packed_len
|
||||
);
|
||||
|
||||
extern int protocol_unpack_frame(
|
||||
const uint8_t *frame,
|
||||
uint16_t frame_len,
|
||||
uint16_t *slave_addr,
|
||||
uint8_t *command,
|
||||
uint8_t *payload,
|
||||
uint16_t *payload_len);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/******************************************************************************
|
||||
* @brief 环形缓冲区管理(参考linux/kfifo)
|
||||
*
|
||||
* Copyright (c) 2016~2020, <morro_luo@163.com>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2016-05-30 Morro 初版完成
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _RING_BUF_H_
|
||||
#define _RING_BUF_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*环形缓冲区管理器*/
|
||||
typedef struct {
|
||||
unsigned char *buf; /*环形缓冲区 */
|
||||
unsigned int size; /*环形缓冲区 */
|
||||
unsigned int front; /*头指针 */
|
||||
unsigned int rear; /*尾指针 */
|
||||
}ring_buf_t;
|
||||
|
||||
bool ring_buf_init(ring_buf_t *r,unsigned char *buf,unsigned int size);
|
||||
|
||||
void ring_buf_clr(ring_buf_t *r);
|
||||
|
||||
int ring_buf_len(ring_buf_t *r);
|
||||
|
||||
int ring_buf_put(ring_buf_t *r,unsigned char *buf,unsigned int len);
|
||||
|
||||
int ring_buf_get(ring_buf_t *r,unsigned char *buf,unsigned int len);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,76 @@
|
||||
#ifndef __SPI_FLASH_H
|
||||
#define __SPI_FLASH_H
|
||||
|
||||
#include "bsp.h"
|
||||
|
||||
#define LOG_SAV_FLAG (0xAA5555AA)
|
||||
#define LOG_INFO_SAV_FLAG (0xA55A)
|
||||
|
||||
#define SpiFlashClrNss() SPI_NSS_CLR()
|
||||
#define SpiFlashSetNss() SPI_NSS_SET()
|
||||
|
||||
#define SPIFLASH_CMD_WRITE 0x02 /* Write to Memory instruction */
|
||||
#define SPIFLASH_CMD_WRSR 0x01 /* Write Status Register instruction */
|
||||
#define SPIFLASH_CMD_WREN 0x06 /* Write enable instruction */
|
||||
#define SPIFLASH_CMD_READ 0x03 /* Read from Memory instruction */
|
||||
#define SPIFLASH_CMD_RDSR 0x05 /* Read Status Register instruction */
|
||||
#define SPIFLASH_CMD_RDID 0x9F /* Read identification */
|
||||
#define SPIFLASH_CMD_SE 0x20 /* 4KSector Erase instruction */
|
||||
#define SPIFLASH_CMD_BE 0xC7 /* Bulk Erase instruction */
|
||||
#define SPIFLASH_WIP_FLAG 0x01 /* Write In Progress (WIP) flag */
|
||||
#define SPIFLASH_DUMMY_BYTE 0xA5
|
||||
#define SPIFLASH_PAGESIZE 0x100
|
||||
#define SPIFLASH_SECTORSIZE 4096
|
||||
#define SPIFLASH_M25P128_ID 0x202018
|
||||
#define SPIFLASH_M25P64_ID 0x202017
|
||||
|
||||
void SpiFlashEraseChip(void);
|
||||
void SpiFlashEraseSector(uint32_t SectorAddr);
|
||||
void SpiFlashWriteAnyLengthData(uint8_t* wData, uint32_t wAddr, uint16_t wLen);
|
||||
void SpiFlashReadAnyLengthData(uint8_t* rData, uint32_t rAddr, uint16_t rLen);
|
||||
uint32_t SpiFlashReadId(void);
|
||||
|
||||
/* USER CODE BEGIN */
|
||||
#define SPIFLASH_SIZE 16777216
|
||||
#define SPIFLASH_SECTOR_NUM 4096
|
||||
|
||||
#define GATEWEY_PARA_SAV_ADDR 0x00
|
||||
#define GATEWEY_PARA_SAV_SECTOR 0x00
|
||||
|
||||
#define LOG_INFO_START_SECTOR 0x01
|
||||
#define LOG_SAV_START_SECTOR 0x02
|
||||
|
||||
//#if (LORA_MODULE == WH_LR36_L)
|
||||
//#define LOG_SAV_SIZE 78
|
||||
//#define LOG_SAV_NUM_SECTOR 52 //每扇区存储数量
|
||||
//#else
|
||||
//#define LOG_SAV_SIZE 78 //150
|
||||
//#define LOG_SAV_NUM_SECTOR 52 //27 //每扇区存储数量
|
||||
//#endif
|
||||
|
||||
#define LOG_SAV_SIZE_MAX 256
|
||||
#define LOG_SAV_NUM_MAX ((SPIFLASH_SECTOR_NUM - LOG_SAV_START_SECTOR) * LOG_SAV_NUM_SECTOR)
|
||||
|
||||
typedef struct {
|
||||
uint32_t LogSavFlag; //日志存储标志
|
||||
uint32_t LogIdx; //日志序号
|
||||
uint32_t LogEndAddr; //日志结束地址
|
||||
uint32_t TimeStamp; //存储时间
|
||||
}LogHeader_t, *LogHeader;
|
||||
|
||||
void SavMMC5983Calib(uint8_t *wData, uint32_t wLen);
|
||||
void ReadMMC5983Calib(uint8_t *rData, uint32_t rLen);
|
||||
|
||||
void LogInit(void);
|
||||
uint32_t ReadLogNum(void);
|
||||
uint32_t ReadLastLogEndAddr(void);
|
||||
uint32_t ReadFirstLogStartAddr(void);
|
||||
void SavLogNum(uint32_t LogNum);
|
||||
void AddLog(uint8_t *wData, uint32_t wLen);
|
||||
int ReadLog(LogHeader Header, uint8_t **wData, uint32_t LogIdx);
|
||||
int ReadPara(uint8_t *Para, uint32_t ParaLen);
|
||||
int WritePara(uint8_t *Para, uint32_t ParaLen);
|
||||
|
||||
/* USER CODE END */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef _UPDATE_PROTOCOL_H_
|
||||
#define _UPDATE_PROTOCOL_H_
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
#define CRC16_BASE 0xA001
|
||||
|
||||
typedef void (*update_send_t)(uint8_t *pBuf,uint16_t len);
|
||||
|
||||
void update_init(update_send_t pCbs);
|
||||
|
||||
int update_unpack(uint8_t* rxData, int rLen,uint8_t *cmd, uint8_t* dev_addr, void *pUser, int *pLen);
|
||||
|
||||
void update_send_cmd(uint8_t Cmd, uint16_t Indx, int PageNum);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef _UTILS_H_
|
||||
#define _UTILS_H_
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
extern uint16_t modbus_crc16(uint8_t *buf, int len);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user