1、startup.s汇编文件的的中断重定向改为ifdef,通过切换app_debug和app_boot判断是否编译
2、Sx1276Type_t 结构体给定固定值 3、lora通道选择取消,通过修改频率来修改通道 4、增加了修改lora参数的函数 5、将USE_BOOTLOADER的宏定义更改到工程预编译define 6、将BootPara_t结构体定义到bsp.h文件下 7、在bsp.h文件下增加了LoraPara_r,RS485Para_t结构体并声明 8、串口带波特率参数初始化 9、增加了MAIN_DBG_LOG和DATA_DBG_LOG调试打印 10、Update.h的boot参数定义在bsp.h获取 11、当工程是app_boot时调试口为Lpuart0,当工程是app_debug时调试口为uart0 12、设备Mac从bootloader中固定地址0x00002800获取,设备类型、通讯方式、设备标志和设备序号从获取到的mac地址解析 13、debug文件增加了调试指令
This commit is contained in:
+2
-2
@@ -4,7 +4,7 @@
|
||||
#define __SGCP_H
|
||||
#include "bsp.h"
|
||||
|
||||
#define WORK_MODE 1//工作模式选择,0、本机为查询模式,1、本机为上报模式(低功耗)
|
||||
#define WORK_MODE 1 //工作模式选择,0、本机为查询模式,1、本机为上报模式(低功耗)
|
||||
#define SGCP_SELECT 1 //协议选择,0、本机为单个主设备接多个子设备,1、本机为单个主设备不接子设备,2、本机为单个子设备
|
||||
|
||||
typedef struct {//网关与主设备固定帧
|
||||
@@ -173,7 +173,7 @@ typedef enum {
|
||||
RS485 = 0x02, //0x02 RS485通讯
|
||||
RS232 = 0x03, //0x03 RS232通讯
|
||||
CAN = 0x04, //0x04 CAN通讯
|
||||
_4G = 0x05, //0x05 _4G通讯
|
||||
CATONE = 0x05, //0x05 _4G通讯
|
||||
BLE = 0x06, //0x06 BLE通讯
|
||||
WIFI = 0x07, //0x07 WIFI通讯
|
||||
UART = 0x08, //0x08 UART通讯
|
||||
|
||||
+2
-15
@@ -3,7 +3,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include "bsp.h"
|
||||
#include "UartDebug.h"
|
||||
|
||||
#define APP_START_FLAG 0x55AA5A5A
|
||||
#define APP_UPDATE_FLAG 0xA5A5AA55
|
||||
@@ -23,17 +22,6 @@
|
||||
|
||||
#define BOOT_PARA_ADDRESS (0x0001FC00)//(FLASH_BASE + BOOT_SIZE)
|
||||
#define BOOT_PARA_SIZE (FLASH_SECTOR_SIZE)
|
||||
|
||||
typedef struct {
|
||||
uint32_t AppFlag;
|
||||
uint32_t UpdateFlag;
|
||||
uint32_t PackageCnt;
|
||||
uint32_t AppSize;
|
||||
uint32_t Crc32Check;
|
||||
uint32_t FirstRunFlag;//第一次运行
|
||||
uint8_t DevMac[6];//设备MAC
|
||||
uint32_t LoraFreq;//Lora频率
|
||||
}BootPara_t, *BootPara;
|
||||
|
||||
//主机下发升级请求载荷结构体
|
||||
typedef struct {
|
||||
@@ -55,11 +43,10 @@ typedef struct {
|
||||
#define U_DBG_LOG(...) DBG_LOG(__VA_ARGS__)
|
||||
#define U_DELAY_MS(x) delay_ms(x)
|
||||
#define U_SYSTEM_TESET() SystemReset()
|
||||
#define SAVE_BOOT_PARA(addr) FlashWrite(BOOT_PARA_ADDRESS, addr, sizeof(BLPara) / 4)
|
||||
#define READ_BOOT_PARA(addr) FlashRead(BOOT_PARA_ADDRESS, addr, sizeof(BLPara) / 4)
|
||||
#define SAVE_BOOT_PARA(addr) SAVE_APP_PARA(addr)
|
||||
#define READ_BOOT_PARA(addr) READ_APP_PARA(addr)
|
||||
|
||||
//输出接口
|
||||
void Update(uint8_t *PayLoad);
|
||||
void UpdateInit(void);
|
||||
extern BootPara_t BLPara;
|
||||
#endif
|
||||
+44
-10
@@ -6,6 +6,7 @@
|
||||
#include <time.h>
|
||||
#include "gpio.h"
|
||||
#include "spi.h"
|
||||
#include "Update.h"
|
||||
|
||||
/*模块启用与关闭*/
|
||||
#define USE_DEBUG 1 //调试串口选择,0、关闭,1、启用
|
||||
@@ -23,8 +24,7 @@
|
||||
#define USE_SPI0 1 //SPI1开关,0、关闭,1、启用
|
||||
#define USE_SPI1 0 //SPI1开关,0、关闭,1、启用
|
||||
|
||||
#define USE_BOOTLOADER 1 //BOOTLOADER开关,0、关闭,1、启用
|
||||
#define USE_LORA_CH 0 //0为测试通道
|
||||
//#define USE_BOOTLOADER 1 //BOOTLOADER开关,0、关闭,1、启用
|
||||
|
||||
//<<---------------------------- MCU -------------------------------->>
|
||||
//< UART0
|
||||
@@ -209,12 +209,22 @@
|
||||
extern float VBAT_8V4;
|
||||
extern uint8_t VBAT_Percentage;
|
||||
|
||||
typedef struct {
|
||||
uint32_t AppFlag;
|
||||
uint32_t UpdateFlag;
|
||||
uint32_t PackageCnt;
|
||||
uint32_t AppSize;
|
||||
uint32_t Crc32Check;
|
||||
uint32_t FirstRunFlag;//第一次运行
|
||||
uint8_t DevMac[6];//设备MAC
|
||||
uint32_t LoraFreq;//Lora频率
|
||||
}BootPara_t, *BootPara;
|
||||
|
||||
typedef struct {
|
||||
uint16_t CollectTime; //数据采集时间间隔,设置范围30*N秒,1<=N<=240,(默认5分钟,N=10)
|
||||
uint16_t ReportInterval; //上报时间间隔,设置范围,30*N秒,10<=N<=1440(默认20分钟,N=40)
|
||||
uint8_t ERInterval; //紧急上报时间间隔,设置范围,30*N秒,2<=N<=10(默认2分钟,N=4)
|
||||
uint8_t ERTime; //紧急上报时长,设置范围,30*N秒,20<=N<=240(默认20分钟,N=40)
|
||||
uint16_t CollectTime; //数据采集时间间隔,设置范围30*N秒,1<=N<=240,(默认300秒,N=10)
|
||||
uint16_t ReportInterval; //上报时间间隔,设置范围,30*N秒,10<=N<=1440(默认1200秒,N=40)
|
||||
uint8_t ERInterval; //紧急上报时间间隔,设置范围,30*N秒,2<=N<=10(默认120秒,N=4)
|
||||
uint8_t ERTime; //紧急上报时长,设置范围,30*N秒,20<=N<=240(默认1200秒,N=40)
|
||||
uint32_t TimeStamp; //网关返回RTC时间戳
|
||||
}__attribute__((packed))LayoutPara_t,*LayoutPara;//上位机下发的配置参数
|
||||
|
||||
@@ -225,16 +235,39 @@ typedef struct {
|
||||
}__attribute__ ((packed))CalibratePara_t, *CalibratePara;
|
||||
|
||||
typedef struct {
|
||||
bool OnOff;
|
||||
uint8_t ucChannel;
|
||||
int8_t ucPower;
|
||||
uint8_t SignalBw;
|
||||
uint8_t SpreadFactor;
|
||||
uint8_t ErrorCoding;
|
||||
uint8_t RegPreamble;
|
||||
uint32_t FreqCent;
|
||||
}__attribute__ ((packed))LoraPara_t, *pLoraPara;
|
||||
|
||||
typedef struct {
|
||||
bool Enable; //串口使能
|
||||
bool UpgradeEnable;//升级功能使能
|
||||
uint32_t Addr; //本机485地址
|
||||
uint32_t BaudRate;
|
||||
}__attribute__((packed))RS485Para_t, *RS485Para;
|
||||
|
||||
typedef struct {
|
||||
BootPara_t BLPara;
|
||||
LayoutPara_t Layout;
|
||||
CalibratePara_t CaliPara;
|
||||
uint32_t RS485Addr; //本机485地址
|
||||
RS485Para_t Rs485Ch1;
|
||||
RS485Para_t Rs485Ch2;
|
||||
uint32_t FactoryFlag;//出厂标志位
|
||||
LoraPara_t Lora;
|
||||
}AppPara_T, *pAppPara;
|
||||
#define APP_PARA_ADDRESS (0x0001FE00)
|
||||
#define SAVE_APP_PARA(addr) FlashWrite(APP_PARA_ADDRESS, addr, sizeof(App.Para) / 4)
|
||||
#define READ_APP_PARA(addr) FlashRead(APP_PARA_ADDRESS, addr, sizeof(App.Para) / 4)
|
||||
//#define APP_PARA_ADDRESS (0x0001FC00)
|
||||
#define SAVE_APP_PARA(addr) FlashWrite(BOOT_PARA_ADDRESS, addr, sizeof(App.Para) / 4)
|
||||
#define READ_APP_PARA(addr) FlashRead(BOOT_PARA_ADDRESS, addr, sizeof(App.Para) / 4)
|
||||
|
||||
void BspInit(void);
|
||||
void LpUart0Init(uint32_t Baud);
|
||||
void Uart0Init(uint32_t Baud);
|
||||
void EnterDeepSleep(void);
|
||||
void DBGUartSendByte(uint8_t sData);
|
||||
void DBGUartSend(uint8_t *sData, int sLen);
|
||||
@@ -269,3 +302,4 @@ void LORAIntDisable(void);
|
||||
void ACCandMMCIntEnable(void);
|
||||
void ACCandMMCIntDisable(void);
|
||||
#endif
|
||||
|
||||
|
||||
+13
-3
@@ -2,8 +2,16 @@
|
||||
#define __MAIN_H
|
||||
#include "bsp.h"
|
||||
#include "UartDebug.h"
|
||||
#include "Update.h"
|
||||
#include "Imu.h"
|
||||
|
||||
#define SOFTWARE_VERSION 12 //软件版本
|
||||
#define HARDWARE_VERSION 11 //硬件版本
|
||||
|
||||
#define MAIN_DBG_LOG(...) { if(MainDispEn) DBG_LOG(__VA_ARGS__);}
|
||||
#define DATA_DBG_LOG(...) { if(DataDispEn) DBG_LOG(__VA_ARGS__);}
|
||||
|
||||
|
||||
#define X 0
|
||||
#define Y 1
|
||||
#define Z 2
|
||||
@@ -94,14 +102,16 @@ typedef struct {
|
||||
|
||||
int16_t Nonce; //随机数
|
||||
|
||||
uint32_t TestTimeCnt;
|
||||
uint8_t Tcnt;
|
||||
bool LaserFlag;
|
||||
}AppDetect_t;
|
||||
|
||||
extern AppDetect_t App;
|
||||
|
||||
void MainDBGOnOff(bool OnOff);
|
||||
void DataDBGOnOff(bool OnOff);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -758,7 +758,7 @@ static void MasRevHandler(void)
|
||||
return;
|
||||
}
|
||||
|
||||
if(SFHeader->Addr != App.Para.RS485Addr)
|
||||
if(SFHeader->Addr != App.Para.Rs485Ch1.Addr)
|
||||
{
|
||||
if(SFHeader->Addr != 0x00)
|
||||
{
|
||||
@@ -1120,7 +1120,7 @@ static void InRevHandler(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
App.Para.RS485Addr = temp;
|
||||
App.Para.Rs485Ch1.Addr = temp;
|
||||
SAVE_APP_PARA((uint32_t *)&App.Para);
|
||||
if(SGCP.InStatus == IN_STATUS_IDLE)
|
||||
{
|
||||
@@ -2195,7 +2195,7 @@ void InRevLoopHandler(void)
|
||||
case IN_STATUS_ALTER_485ADDR:{
|
||||
PrintfMess();
|
||||
Alter485AddrRes(LocalMAC, true);
|
||||
DBG_LOG("Alter RS485Addr:%X\r\n", App.Para.RS485Addr);
|
||||
DBG_LOG("Alter RS485Addr:%X\r\n", App.Para.Rs485Ch1.Addr);
|
||||
SGCP.InStatus = IN_STATUS_IDLE;
|
||||
break;}
|
||||
|
||||
|
||||
+15
-15
@@ -1,7 +1,7 @@
|
||||
#include "Update.h"
|
||||
#include "UartDebug.h"
|
||||
|
||||
BootPara_t BLPara;
|
||||
#include "main.h"
|
||||
#include "bsp.h"
|
||||
|
||||
/*****************************************************************************************
|
||||
* 函数名称: Update
|
||||
@@ -14,19 +14,19 @@ void Update(uint8_t *PayLoad)
|
||||
UpDataRequset_t Req;
|
||||
|
||||
memcpy(&Req, PayLoad, sizeof(UpDataRequset_t));
|
||||
BLPara.AppSize = Req.AppSize;
|
||||
BLPara.Crc32Check = Req.AppCrc32;
|
||||
BLPara.PackageCnt = Req.PackageNum;
|
||||
BLPara.AppFlag = 0;
|
||||
BLPara.UpdateFlag = APP_UPDATE_FLAG;
|
||||
App.Para.BLPara.AppSize = Req.AppSize;
|
||||
App.Para.BLPara.Crc32Check = Req.AppCrc32;
|
||||
App.Para.BLPara.PackageCnt = Req.PackageNum;
|
||||
App.Para.BLPara.AppFlag = 0;
|
||||
App.Para.BLPara.UpdateFlag = APP_UPDATE_FLAG;
|
||||
|
||||
U_DBG_LOG("Receive upgrade command:\r\n");
|
||||
U_DBG_LOG("PackageNum: %d\r\n", BLPara.PackageCnt);
|
||||
U_DBG_LOG("AppSize: %d\r\n", BLPara.AppSize);
|
||||
U_DBG_LOG("AppCrc32: 0x%08x\r\n", BLPara.Crc32Check);
|
||||
U_DBG_LOG("PackageNum: %d\r\n", App.Para.BLPara.PackageCnt);
|
||||
U_DBG_LOG("AppSize: %d\r\n", App.Para.BLPara.AppSize);
|
||||
U_DBG_LOG("AppCrc32: 0x%08x\r\n", App.Para.BLPara.Crc32Check);
|
||||
U_DBG_LOG("System Reset!\r\n");
|
||||
|
||||
SAVE_BOOT_PARA((uint32_t *)&BLPara);
|
||||
SAVE_BOOT_PARA((uint32_t *)&App.Para);
|
||||
U_DELAY_MS(200);
|
||||
U_SYSTEM_TESET();
|
||||
}
|
||||
@@ -39,10 +39,10 @@ void Update(uint8_t *PayLoad)
|
||||
*****************************************************************************************/
|
||||
void UpdateInit(void)
|
||||
{
|
||||
READ_BOOT_PARA((uint32_t *)&BLPara);
|
||||
if(BLPara.AppFlag != APP_START_FLAG) {
|
||||
BLPara.AppFlag = APP_START_FLAG;
|
||||
SAVE_BOOT_PARA((uint32_t *)&BLPara);
|
||||
READ_BOOT_PARA((uint32_t *)&App.Para);
|
||||
if(App.Para.BLPara.AppFlag != APP_START_FLAG) {
|
||||
App.Para.BLPara.AppFlag = APP_START_FLAG;
|
||||
SAVE_BOOT_PARA((uint32_t *)&App.Para);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
-9
@@ -89,7 +89,7 @@ static void SystemRCLInit(void)
|
||||
Sysctrl_ClkSourceEnable(SysctrlClkRCL, TRUE); ///< 使能RCL时钟
|
||||
}
|
||||
|
||||
static void Uart0Init(void)
|
||||
void Uart0Init(uint32_t Baud)
|
||||
{
|
||||
stc_gpio_cfg_t stcGpioCfg;
|
||||
stc_uart_cfg_t stcCfg;
|
||||
@@ -116,7 +116,7 @@ static void Uart0Init(void)
|
||||
stcCfg.enMmdorCk = UartMskEven; ///<偶校验
|
||||
stcCfg.stcBaud.u32Pclk = Sysctrl_GetPClkFreq(); ///<PCLK获取
|
||||
stcCfg.stcBaud.enClkDiv = UartMsk8Or16Div; ///<采样分频
|
||||
stcCfg.stcBaud.u32Baud = 500000; ///<波特率
|
||||
stcCfg.stcBaud.u32Baud = Baud; ///<波特率
|
||||
stcCfg.enRunMode = UartMskMode1; ///<工作模式
|
||||
Uart_Init(M0P_UART0, &stcCfg);
|
||||
|
||||
@@ -166,7 +166,7 @@ static void Uart1Init(void)
|
||||
Uart_EnableIrq(M0P_UART1, UartRxIrq); ///<使能接收中断
|
||||
EnableNvic(UART1_3_IRQn, IrqLevel3, TRUE); ///<系统中断使能
|
||||
}
|
||||
static void LpUart0Init(void)
|
||||
void LpUart0Init(uint32_t Baud)
|
||||
{
|
||||
stc_gpio_cfg_t stcGpioCfg;
|
||||
stc_lpuart_cfg_t stcCfg;
|
||||
@@ -193,7 +193,7 @@ static void LpUart0Init(void)
|
||||
stcCfg.stcBaud.enSclkSel = LPUartMskRcl; ///<传输时钟源
|
||||
stcCfg.stcBaud.u32Sclk = 38400; ///<PCLK获取
|
||||
stcCfg.stcBaud.enSclkDiv = LPUartMsk4Or8Div; ///<采样分频
|
||||
stcCfg.stcBaud.u32Baud = 9600; ///<波特率
|
||||
stcCfg.stcBaud.u32Baud = Baud; ///<波特率
|
||||
stcCfg.enRunMode = LPUartMskMode1; ///<工作模式
|
||||
LPUart_Init(M0P_LPUART0, &stcCfg);
|
||||
|
||||
@@ -703,9 +703,22 @@ void PrintfMess(void)
|
||||
}
|
||||
void DBGUartSendByte(uint8_t sData)
|
||||
{
|
||||
#if USE_BOOTLOADER
|
||||
LPUart_SendData(M0P_LPUART0, sData);
|
||||
#else
|
||||
Uart_SendDataPoll(M0P_UART0, sData);
|
||||
#endif
|
||||
}
|
||||
void DBGUartSend(uint8_t *sData, int sLen)
|
||||
{
|
||||
#if USE_BOOTLOADER
|
||||
LPUart0SendArray(sData, sLen);
|
||||
#else
|
||||
for(int i = 0; i < sLen; i++) {
|
||||
Uart_SendDataPoll(M0P_UART0, sData[i]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void LPUart0SendArray(uint8_t *sData, uint8_t sLen)
|
||||
{
|
||||
RS485_CTRL_TX();
|
||||
@@ -783,6 +796,7 @@ void LpUart0_IRQHandler(void)
|
||||
LPUart_ClrStatus(M0P_LPUART0, LPUartRC); ///<清接收中断请求
|
||||
uint8_t u8RxData = LPUart_ReceiveData(M0P_LPUART0); ///读取数据
|
||||
LPUartRx_CallBack(u8RxData);
|
||||
DebugUartIRQ(u8RxData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -791,7 +805,7 @@ void Uart0_IRQHandler(void)
|
||||
if(Uart_GetStatus(M0P_UART0, UartRC)) { ///接收数据
|
||||
Uart_ClrStatus(M0P_UART0, UartRC); ///<清接收中断请求
|
||||
uint8_t u8RxData = Uart_ReceiveData(M0P_UART0); ///读取数据
|
||||
DebugUartIRQ(u8RxData);
|
||||
//DebugUartIRQ(u8RxData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -876,7 +890,7 @@ void WakeUpInit(void)
|
||||
AdcInit();
|
||||
#endif
|
||||
#if (USE_UART0 == 1)
|
||||
Uart0Init();
|
||||
Uart0Init(500000);
|
||||
#endif
|
||||
#if (USE_SPI0 == 1)
|
||||
SPI0Init();
|
||||
@@ -908,7 +922,7 @@ void BspInit(void)
|
||||
AdcInit();
|
||||
#endif
|
||||
#if (USE_UART0 == 1)//< DEBUG
|
||||
Uart0Init();
|
||||
Uart0Init(500000);
|
||||
#endif
|
||||
#if (USE_RTC == 1)//< RTC
|
||||
RTCInit(30);
|
||||
@@ -923,7 +937,7 @@ void BspInit(void)
|
||||
SPI1Init();
|
||||
#endif
|
||||
#if (USE_LPUART0 == 1)//< LPUART0
|
||||
LpUart0Init();
|
||||
LpUart0Init(9600);
|
||||
#endif
|
||||
#if(USE_I2C0 == 1)
|
||||
I2C0Init();
|
||||
|
||||
+126
-110
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user