update 解决相关bug
This commit is contained in:
@@ -20,10 +20,13 @@
|
||||
#define BSP_W5500_PORT_DATA_RECEIVE 0x01 /*端口接收到一个数据包*/
|
||||
#define BSP_W5500_PORT_DATA_TRANSMITOK 0x02 /*端口发送一个数据包完成*/
|
||||
|
||||
static u8 last_link_status = 0; // 保存上一次链路状态
|
||||
|
||||
static void bsp_W5500_Interrupt_Process(void);
|
||||
static void bsp_W5500_Init(void);
|
||||
static void bsp_W5500_Task(void);
|
||||
static void Write_SOCK_Data_Buffer(bsp_W5500_Class_t *pW5500_Class, u8 *dat_ptr, u16 size);
|
||||
static void network_monitor_task(void);
|
||||
|
||||
bsp_W5500_t W5500 =
|
||||
{
|
||||
@@ -36,6 +39,7 @@ bsp_W5500_t W5500 =
|
||||
|
||||
.Init = bsp_W5500_Init,
|
||||
.Task = bsp_W5500_Task,
|
||||
.Monitor_task = network_monitor_task,
|
||||
.Socket_Send = Write_SOCK_Data_Buffer,
|
||||
|
||||
.W5500_Class[0] =
|
||||
@@ -741,7 +745,7 @@ void bsp_W5500_Socket_Set(bsp_W5500_Class_t *pW5500_Class)
|
||||
|
||||
static void bsp_W5500_Init()
|
||||
{
|
||||
u8 i;
|
||||
u8 i,ver;
|
||||
W5500_Hardware_Reset(); /*硬件复位W5500*/
|
||||
W5500_Init(); /*初始化W5500寄存器函数*/
|
||||
Detect_Gateway(); /*检查网关服务器*/
|
||||
@@ -751,7 +755,9 @@ static void bsp_W5500_Init()
|
||||
bsp_W5500_Socket_Init(&pW5500->W5500_Class[i]);
|
||||
pW5500->W5500_Class[i].Run_State = 0; /*复位状态*/
|
||||
//bsp_W5500_Socket_Set(&pW5500->W5500_Class[i]); /*W5500端口初始化配置*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void bsp_W5500_Task(void)
|
||||
@@ -781,3 +787,25 @@ static void bsp_W5500_Task(void)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 获取 W5500 物理链路状态
|
||||
* @return 1: 链路连接, 0: 链路断开
|
||||
*/
|
||||
static u8 w5500_get_link_status(void)
|
||||
{
|
||||
u8 phycfgr = Read_W5500_1Byte(PHYCFGR); // 读取 PHYCFGR 寄存器
|
||||
return (phycfgr & LINK) ? 1 : 0; // 返回 LINK 位
|
||||
}
|
||||
|
||||
|
||||
static void network_monitor_task(void)
|
||||
{
|
||||
u8 current_link = w5500_get_link_status();
|
||||
|
||||
if (last_link_status == 0 && current_link == 1) {
|
||||
/*链路从断开变为连接,执行恢复操作*/
|
||||
W5500.Init();
|
||||
}
|
||||
|
||||
last_link_status = current_link;
|
||||
}
|
||||
|
||||
@@ -261,6 +261,7 @@ typedef struct
|
||||
void (*Interrupt_Process)(void); /*处理进程*/
|
||||
void (*Init)(void); /*初始化*/
|
||||
void (*Task)(void); /*任务*/
|
||||
void (*Monitor_task)(void); /*断线重连*/
|
||||
void (*Socket_Send)(bsp_W5500_Class_t *, u8 *, u16 ); /*端口发送数据*/
|
||||
}bsp_W5500_t;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "bsp_Wdg.h"
|
||||
|
||||
//#include "iwdg.h"
|
||||
#include "iwdg.h"
|
||||
|
||||
static void bsp_Wdg_Init(void);
|
||||
static void bsp_Wdg_Feed(void);
|
||||
@@ -15,11 +15,12 @@ bsp_Wdg_t *pWdg = &Wdg;
|
||||
|
||||
static void bsp_Wdg_Init(void)
|
||||
{
|
||||
// __HAL_DBGMCU_FREEZE_IWDG(); //调试模式下,冻结看门狗计数器时钟
|
||||
__HAL_DBGMCU_FREEZE_IWDG(); //调试模式下,冻结看门狗计数器时钟
|
||||
Wdg.Feed();
|
||||
}
|
||||
|
||||
static void bsp_Wdg_Feed(void)
|
||||
{
|
||||
// HAL_IWDG_Refresh(&hiwdg);
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "app_leakage.h"
|
||||
#include "bsp_W5500.h"
|
||||
|
||||
/* spi flash 片选引脚 - pb12 */
|
||||
#define W25Q32_CS_LOW() HAL_GPIO_WritePin(SPI2_CS_GPIO_Port, SPI2_CS_Pin, GPIO_PIN_RESET)
|
||||
@@ -95,12 +96,27 @@ static void gui_tjc_hmi_read_device_info_from_w25q(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void gui_tjc_hmi_read_network_config_from_w25q(void)
|
||||
{
|
||||
network_config_t config;
|
||||
w25q32.read(W25Q32_NETWORK_CONFIG_ADDR, (uint8_t*)&config, sizeof(config));
|
||||
|
||||
/* 检查数据有效性(判断第一个IP字节不是0xFF,表示有有效数据) */
|
||||
if (config.ip[0] != 0xFF && config.ip[0] != 0x00) {
|
||||
memcpy(W5500.IP_Addr, config.ip, 4);
|
||||
memcpy(W5500.Sub_Mask, config.mask, 4);
|
||||
memcpy(W5500.Gateway_IP, config.gateway, 4);
|
||||
W5500.W5500_Class[0].ConfigData.Port[0] = (config.port >> 8) & 0xFF;
|
||||
W5500.W5500_Class[0].ConfigData.Port[1] = config.port & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
/* 初始化函数 */
|
||||
static void w25q32_init(void) {
|
||||
W25Q32_CS_HIGH(); /* 初始时片选拉高 */
|
||||
w25q32_wake_up(); /* 唤醒芯片 */
|
||||
gui_tjc_hmi_read_device_info_from_w25q();
|
||||
gui_tjc_hmi_read_network_config_from_w25q();
|
||||
}
|
||||
|
||||
/* 读取芯片id */
|
||||
|
||||
@@ -55,6 +55,8 @@ void w25q32_sector_erase(uint32_t sector_addr);
|
||||
/* 蜂鸣器状态存储地址 - 使用独立扇区(扇区14) */
|
||||
#define W25Q32_BUZZER_STATE_ADDR 0x00E000 /*存储蜂鸣器状态(1字节)*/
|
||||
|
||||
#define W25Q32_NETWORK_CONFIG_ADDR 0x00F000 /* 网络配置存储地址(使用独立扇区) */
|
||||
|
||||
/* w25q32 对象结构体 */
|
||||
typedef struct {
|
||||
void (*init)(void);
|
||||
|
||||
Reference in New Issue
Block a user