初始版本
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,381 @@
|
||||
#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_MUM_MAX 32
|
||||
|
||||
#define REGISTER_INTERVAL_MAX (2 * 60)
|
||||
#define COMMUNIT_READ_SENSOR_INTERVAL_MAX (1 * 60)
|
||||
|
||||
#define LORA_CAT_ERR_RESET_DLY_MAX (20 * 60) //单位秒
|
||||
|
||||
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 {
|
||||
SENSOR_TYPE_NULL,
|
||||
STRAIN_SENSOR,
|
||||
PRESSURE_SENSOR,
|
||||
SONAR_SENSOR,
|
||||
CAP_SENSOR,
|
||||
VIBRATE_SENSOR,
|
||||
DEFM_3D_SENSOR,
|
||||
STRAIN_SENSOR_MAG = 8,
|
||||
PRESSURE_SENSOR_MAG,
|
||||
SONAR_SENSOR_MAG,
|
||||
CAP_SENSOR_MAG,
|
||||
DEFM_3D_SENSOR_MAG,
|
||||
STRAIN_2_SENSOR,
|
||||
CRACK_SENSOR,
|
||||
SIX_DIM_SENSOR,
|
||||
POSTURE_SENSOR,
|
||||
LASER_DISTANCE_SENSOR,
|
||||
CRACK_2_SENSOR, //裂缝别名
|
||||
}SensorType_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_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_HIS_DATA,
|
||||
NET_COMM_CMD_ADD_UNIT,
|
||||
NET_COMM_CMD_LP_DEV_CONFIG,
|
||||
NET_COMM_CMD_END,
|
||||
}NetCommCmd_m;
|
||||
|
||||
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;
|
||||
}__attribute__((packed))StrainSensorType_t;
|
||||
|
||||
typedef struct {
|
||||
int16_t AccX;
|
||||
int16_t AccY;
|
||||
int16_t AccZ;
|
||||
int16_t MegX;
|
||||
int16_t MegY;
|
||||
int16_t MegZ;
|
||||
int32_t Strain1;
|
||||
int32_t Strain2;
|
||||
int32_t Strain3;
|
||||
int32_t Strain4;
|
||||
int32_t Strain5;
|
||||
int32_t Strain6;
|
||||
}__attribute__((packed))StrainMegSensorType_t;
|
||||
|
||||
typedef struct {
|
||||
int16_t AccX;
|
||||
int16_t AccY;
|
||||
int16_t AccZ;
|
||||
uint32_t Pressure;
|
||||
}__attribute__((packed))PressureSensorType_t;
|
||||
|
||||
typedef struct {
|
||||
int16_t AccX;
|
||||
int16_t AccY;
|
||||
int16_t AccZ;
|
||||
uint16_t Sonar1;
|
||||
uint16_t Sonar2;
|
||||
uint16_t Sonar3;
|
||||
uint16_t Sonar4;
|
||||
}__attribute__((packed))SonarSensorType_t;
|
||||
|
||||
typedef struct {
|
||||
int16_t AccX;
|
||||
int16_t AccY;
|
||||
int16_t AccZ;
|
||||
uint16_t Capacitance1;
|
||||
uint16_t Capacitance2;
|
||||
}__attribute__((packed))CapSensorType_t;
|
||||
|
||||
typedef struct {
|
||||
int16_t AccX;
|
||||
int16_t AccY;
|
||||
int16_t AccZ;
|
||||
}__attribute__((packed))Defm3DSensorType_t;
|
||||
|
||||
typedef struct {
|
||||
int16_t AccX;
|
||||
int16_t AccY;
|
||||
int16_t AccZ;
|
||||
int16_t MegX;
|
||||
int16_t MegY;
|
||||
int16_t MegZ;
|
||||
}__attribute__((packed))Defm3DMegSensorType_t;
|
||||
|
||||
typedef struct {
|
||||
int16_t AccX;
|
||||
int16_t AccY;
|
||||
int16_t AccZ;
|
||||
int16_t MagX;
|
||||
int16_t MagY;
|
||||
int16_t MagZ;
|
||||
int32_t Strain1;
|
||||
int32_t Strain2;
|
||||
int32_t Strain3;
|
||||
int32_t Strain4;
|
||||
int32_t Strain5;
|
||||
int32_t Strain6;
|
||||
}__attribute__((packed))StrainMagSensorType_t;
|
||||
|
||||
typedef struct {
|
||||
int16_t AccX;
|
||||
int16_t AccY;
|
||||
int16_t AccZ;
|
||||
int16_t MagX;
|
||||
int16_t MagY;
|
||||
int16_t MagZ;
|
||||
uint32_t Pressure;
|
||||
}__attribute__((packed))PressureMagSensorType_t;
|
||||
|
||||
typedef struct {
|
||||
int16_t AccX;
|
||||
int16_t AccY;
|
||||
int16_t AccZ;
|
||||
int16_t MagX;
|
||||
int16_t MagY;
|
||||
int16_t MagZ;
|
||||
uint16_t Sonar1;
|
||||
uint16_t Sonar2;
|
||||
uint16_t Sonar3;
|
||||
uint16_t Sonar4;
|
||||
}__attribute__((packed))SonarMagSensorType_t;
|
||||
|
||||
typedef struct {
|
||||
int16_t AccX;
|
||||
int16_t AccY;
|
||||
int16_t AccZ;
|
||||
int16_t MagX;
|
||||
int16_t MagY;
|
||||
int16_t MagZ;
|
||||
uint16_t Capacitance1;
|
||||
uint16_t Capacitance2;
|
||||
}__attribute__((packed))CapMagSensorType_t;
|
||||
|
||||
typedef struct {
|
||||
int16_t AccX;
|
||||
int16_t AccY;
|
||||
int16_t AccZ;
|
||||
int16_t MagX;
|
||||
int16_t MagY;
|
||||
int16_t MagZ;
|
||||
}__attribute__((packed))Defm3DMagSensorType_t;
|
||||
|
||||
typedef struct {
|
||||
int16_t AccX;
|
||||
int16_t AccY;
|
||||
int16_t AccZ;
|
||||
int32_t Strain1;
|
||||
int32_t Strain2;
|
||||
}__attribute__((packed))Strain2SensorType_t;
|
||||
|
||||
typedef struct {
|
||||
int16_t AccX_L;
|
||||
int16_t AccY_L;
|
||||
int16_t AccZ_L;
|
||||
int16_t MagX_L;
|
||||
int16_t MagY_L;
|
||||
int16_t MagZ_L;
|
||||
int16_t AccX_R;
|
||||
int16_t AccY_R;
|
||||
int16_t AccZ_R;
|
||||
int16_t MagX_R;
|
||||
int16_t MagY_R;
|
||||
int16_t MagZ_R;
|
||||
}__attribute__((packed))CrackSensorType_t;
|
||||
|
||||
typedef struct {
|
||||
int16_t PitchAngle;
|
||||
int16_t RollAngle;
|
||||
int16_t VibrationStrength;
|
||||
int16_t Temperature;
|
||||
}__attribute__((packed))PostureSensorType_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;
|
||||
|
||||
|
||||
#define LW_DEV_COLLECT_INTERVAL_MAX 300
|
||||
#define LW_DEV_REPORT_INTERVAL_MAX 20
|
||||
#define LW_DEV_ER_INTERVAL_MAX 2
|
||||
#define LW_DEV_ER_TIME_MAX 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-离线
|
||||
uint8_t BatLevel;
|
||||
uint32_t CommErrCnt;
|
||||
uint8_t Mac[6];
|
||||
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;
|
||||
CommUnitData_t SensorData;
|
||||
}CommUnit_t, *CommUnit;
|
||||
|
||||
typedef struct {
|
||||
bool Enable; //串口使能
|
||||
bool CommUnitEnable; //通讯单元使能,开启(使用内部通讯单元功能,直接和传感器通讯),关闭(直接和RS485类型的通讯单元通讯)
|
||||
bool QuerySensorFlag; //查询传感器标志
|
||||
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;
|
||||
uint8_t PayloadLen;
|
||||
}__attribute__((packed))CommUnitFrameHeader_t, *CommUnitFrameHeader;
|
||||
|
||||
typedef struct {
|
||||
uint8_t Header;
|
||||
uint8_t GWMac[6];
|
||||
uint8_t SvrMac[6];
|
||||
uint8_t Cmd;
|
||||
uint32_t Timestamp;
|
||||
uint8_t PacketNum;
|
||||
uint8_t PacketIdx;
|
||||
uint16_t PayloadLen;
|
||||
}__attribute__((packed))NetCommFrameHeader_t, *NetCommFrameHeader;
|
||||
|
||||
typedef struct {
|
||||
uint8_t ucChannel;
|
||||
int8_t ucPower;
|
||||
uint8_t SignalBw;
|
||||
uint8_t SpreadFactor;
|
||||
uint8_t ErrorCoding;
|
||||
uint8_t RegPreamble;
|
||||
}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_MUM_MAX]; //注册的通讯单元信息
|
||||
RS485Para_t Rs485Ch1; //RS485通道1配置
|
||||
RS485Para_t Rs485Ch2; //RS485通道2配置
|
||||
LoraPara_t Lora; //Lora配置
|
||||
}GWConfigPara_t, *GWConfigPara;
|
||||
|
||||
struct GateWay_t{
|
||||
uint8_t DebugChannel;
|
||||
bool TimeSyncFlag; //时间同步标志
|
||||
bool SvrRegFlag; //服务器注册标志
|
||||
uint8_t SvrMac[6]; //服务器mac
|
||||
GWConfigPara_t ConfigPara; //配置参数
|
||||
CommUnitData_t CUDataArray[COMMUNIT_MUM_MAX];
|
||||
uint8_t Battery; //电池电量
|
||||
uint32_t HistoryNum; //历史数据数量
|
||||
DataRevCallBack SvrRevCallBack; //接收到服务器回调
|
||||
DataRevResCallBack CommUnitRevCallBack; //通讯单元接收回调
|
||||
rt_mq_t NetSendData_MQ; //网络发送数据队列,第一个字节用于存储消息长度, 第二字节存储命令字,后为数据
|
||||
rt_mq_t LoraRev_MQ; //Lora接收消息队列,第一个字节用于存储消息长度,后为数据
|
||||
rt_mutex_t UartRevMutex;
|
||||
};
|
||||
|
||||
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,69 @@
|
||||
#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_SET_ADDR,
|
||||
RS485_SENSOR_CMD_QUERY,
|
||||
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;
|
||||
}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,314 @@
|
||||
#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 "ff.h"
|
||||
|
||||
|
||||
/*版本信息*/
|
||||
typedef enum {
|
||||
GW_V1_0 = 0x81, //1-网关Ver1.0:具有LORA通信、4G通讯、以太网通信,支持DC12V供
|
||||
GW_V2_0 = 0x82, //2-网关Ver2.0:具有LORA通信、4G通讯、以太网通信、光纤通信,支持AC-220V供电,DC-12V供电
|
||||
}VER_INFO_M;
|
||||
/*项目编号*/
|
||||
typedef enum {
|
||||
TEST = 0x000000, //测试项目
|
||||
CASST = 0x000001, //安科院项目
|
||||
BJTU = 0x000002, //北交大项目
|
||||
BSM = 0x000003, //巴拉水电边坡监测项目
|
||||
FSTM = 0x000004, //铁一院川藏铁路隧道监测项目
|
||||
CSTM = 0x000005, //铁二院川藏铁路隧道监测项目
|
||||
LYT = 0x000003, //雅下项目
|
||||
}PRJ_NUM_M;
|
||||
/*Lora频率:433100000ul + 200000*N */
|
||||
typedef enum {
|
||||
CH0 = (433100000ul + 0), //测试频率
|
||||
CH1 = (433100000ul + 200000),
|
||||
CH2 = (433100000ul + 400000),
|
||||
CH3 = (433100000ul + 600000),
|
||||
CH4 = (433100000ul + 800000),
|
||||
CH5 = (433100000ul + 1000000),
|
||||
CH6 = (433100000ul + 1200000),
|
||||
CH7 = (433100000ul + 1400000),
|
||||
CH8 = (433100000ul + 1600000),
|
||||
CH9 = (433100000ul + 1800000),
|
||||
CH10 = (433100000ul + 2000000),
|
||||
}LORA_FREQ_M;
|
||||
|
||||
/*版本选择*/
|
||||
#define VERINFO GW_V1_0
|
||||
/*项目选择*/
|
||||
#define PRJNUM LYT
|
||||
/*网关序号设置*/
|
||||
#define GW_NUM_M (0x0000)
|
||||
/*Lora频率配置*/
|
||||
#define LORA_FREQ CH0
|
||||
|
||||
#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 SRAM_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)
|
||||
|
||||
|
||||
#define DEV_TYPE (0x0001)
|
||||
|
||||
#define DEBUG 1
|
||||
#define USE_SD_CARD 0
|
||||
#define WATCH_DOG 1
|
||||
|
||||
|
||||
#if(VERINFO == GW_V1_0)
|
||||
#define DBGUART_IRQn Int006_IRQn
|
||||
#define DBGUART_EI_IRQn Int007_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)
|
||||
|
||||
//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)
|
||||
|
||||
//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)
|
||||
|
||||
//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 KEY_LED_PORT (PortB)
|
||||
#define KEY_LED_PIN (Pin04)
|
||||
|
||||
typedef struct {
|
||||
bool Enable; //串口使能
|
||||
bool CommUnitEnable; //通讯单元使能,开启(使用内部通讯单元功能,直接和传感器通讯),关闭(直接和RS485类型的通讯单元通讯)
|
||||
bool QuerySensorFlag; //查询传感器标志
|
||||
bool UpgradeEnable;//升级功能使能
|
||||
uint8_t Power;
|
||||
uint32_t BaudRate;
|
||||
SendData RS485Send;
|
||||
CommUnit_t CUData;
|
||||
}__attribute__((packed))RS485Para_t, *RS485Para;
|
||||
|
||||
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
|
||||
RS485Para_t Rs485Ch1; //RS485通道1配置
|
||||
RS485Para_t Rs485Ch2; //RS485通道2配置
|
||||
uint8_t DebugChannel; //调试通道
|
||||
LoraPara_t Lora; //Lora配置
|
||||
}__attribute__((packed))GWConfigPara_t, *GWConfigPara;
|
||||
|
||||
typedef struct {
|
||||
uint32_t AppFlag;
|
||||
uint32_t UpdateFlag;
|
||||
uint32_t PackageCnt;
|
||||
uint32_t AppSize;
|
||||
uint32_t Crc32Check;
|
||||
uint32_t FirstRunFlag;//第一次运行
|
||||
}BootPara_t, *BootPara;
|
||||
|
||||
void BSP_Init(void);
|
||||
|
||||
void DbgUart_Config(uint32_t BaudRate);
|
||||
void DebugUartSend(uint8_t *sData, uint16_t sLen);
|
||||
void DbgRxIrqCallback(uint8_t rData);
|
||||
|
||||
void FeedDog(void);
|
||||
void Error_Handler(void);
|
||||
void FlashWrite(uint32_t Addr, uint32_t *wData, uint8_t wLen);
|
||||
void ReadBootPara(BootPara rData);
|
||||
void WriteBootPara(BootPara wData);
|
||||
void EraseFlash(void);
|
||||
//extern stc_sd_handle_t stcSdhandle;
|
||||
#endif
|
||||
@@ -0,0 +1,160 @@
|
||||
/*******************************************************************************
|
||||
* 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.
|
||||
******************************************************************************/
|
||||
#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,74 @@
|
||||
#ifndef __MAIN__H
|
||||
#define __MAIN__H
|
||||
#include "bsp.h"
|
||||
|
||||
#define CRC16_BASE 0xA001
|
||||
|
||||
#define APP_START_FLAG 0x55AA5A5A
|
||||
#define APP_UPDATE_FLAG 0xA5A5AA55
|
||||
|
||||
typedef enum {
|
||||
UPDATE_CMD_NULL,
|
||||
UPDATE_CMD_SLAVE_RES, //从机应答主机下发
|
||||
UPDATE_CMD_SLAVE_REQ_DATA, //从机请求主机下发数据
|
||||
UPDATE_CMD_MASTER_REQ = 0x81, //主机请求升级
|
||||
UPDATE_CMD_MASTRE_RES_DATA, //主机发送数据
|
||||
}UpdateCmd_m;
|
||||
|
||||
//帧头结构体
|
||||
typedef struct {
|
||||
uint8_t Header;
|
||||
uint8_t DevMac[6];
|
||||
uint8_t Cmd;
|
||||
uint8_t PayloadLen;
|
||||
}__attribute__ ((packed))FrameHeader_t, *FrameH;
|
||||
|
||||
|
||||
//主机下发升级请求载荷结构体
|
||||
typedef struct {
|
||||
uint16_t PackageNum;
|
||||
uint32_t AppSize;
|
||||
uint32_t AppCrc32;
|
||||
}__attribute__ ((packed))UpDataRequset_t, *UDReq;
|
||||
|
||||
//从机请求下发结构体
|
||||
typedef struct {
|
||||
uint16_t PackageIndex;
|
||||
uint32_t PackageNum;
|
||||
}__attribute__ ((packed))GetDataRequest_t, *GDReq;
|
||||
|
||||
//主机应答下发数据结构体
|
||||
typedef struct {
|
||||
uint16_t PackageIndex;
|
||||
uint16_t PackageNum;
|
||||
uint8_t DataLen;
|
||||
}__attribute__ ((packed))DownResponse_t, *DownRes;
|
||||
|
||||
typedef enum {
|
||||
BL_IDLE,
|
||||
BL_ERASE_FLASH,
|
||||
BL_GET_DATA,
|
||||
BL_WAIT_REV,
|
||||
BL_GET_DATA_TIMEOUT,
|
||||
BL_START_APP,
|
||||
BL_RESET
|
||||
}BootStatus_m;
|
||||
|
||||
typedef struct {
|
||||
BootPara_t Para;
|
||||
BootStatus_m Status;
|
||||
|
||||
uint32_t AppPackageCnt;
|
||||
uint32_t AppPackageIdx;
|
||||
uint32_t RevErrCnt;
|
||||
|
||||
uint32_t FeedDogDlyCnt;
|
||||
uint32_t BootLoader1mSDlyCnt;
|
||||
|
||||
bool RxFlag;
|
||||
uint32_t UartRevTimeOutCnt;
|
||||
uint8_t RxBuff[260];
|
||||
uint16_t RxLen;
|
||||
uint16_t UpDateFlag;
|
||||
}BootLoader_t;
|
||||
#endif
|
||||
@@ -0,0 +1,75 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user