update
This commit is contained in:
@@ -1,21 +1,7 @@
|
||||
/**********************************************************************************
|
||||
* 文件名 :W5500.c
|
||||
* 描述 :W5500 驱动函数库
|
||||
* 库版本 :ST_v3.5
|
||||
* 作者 :泥人通信模块开发团队
|
||||
* 博客 :http://nirenelec.blog.163.com
|
||||
* 淘宝 :http://nirenelec.taobao.com
|
||||
**********************************************************************************/
|
||||
|
||||
//#include "stm32f1xx.h"
|
||||
//#include "stm32f1xx_hal_spi.h"
|
||||
#include "main.h"
|
||||
|
||||
#include "bsp_W5500.h"
|
||||
#include "usart.h"
|
||||
#include "stdio.h"
|
||||
#include "spi.h"
|
||||
//#include "bsp_print.h"
|
||||
|
||||
|
||||
#define BSP_W5500_SPI_CS_LOW
|
||||
@@ -41,12 +27,10 @@ static void Write_SOCK_Data_Buffer(bsp_W5500_Class_t *pW5500_Class, u8 *dat_ptr,
|
||||
|
||||
bsp_W5500_t W5500 =
|
||||
{
|
||||
.Gateway_IP = {192,168,1,1},
|
||||
.Sub_Mask = {255,255,255,0},/*子网掩码*/
|
||||
.Phy_Addr = {0x0c,0x29,0xab,0x7c,0x00,0x01},
|
||||
|
||||
//.IP_Addr = {169,254,107,101},
|
||||
.IP_Addr = {192,168,100,101},
|
||||
.Gateway_IP = {192,168,100,1}, /*网关IP地址*/
|
||||
.Sub_Mask = {255,255,255,0}, /*子网掩码*/
|
||||
.Phy_Addr = {0x0c,0x29,0xab,0x7c,0x00,0x01}, /*物理地址(MAC)*/
|
||||
.IP_Addr = {192,168,100,101}, /*本机IP地址*/
|
||||
|
||||
.Interrupt_Process = bsp_W5500_Interrupt_Process,
|
||||
|
||||
@@ -57,18 +41,8 @@ bsp_W5500_t W5500 =
|
||||
.W5500_Class[0] =
|
||||
{
|
||||
.SocketPort = 0, /*使用端口0*/
|
||||
.ConfigData.Gateway_IP = {192,168,1,1},
|
||||
.ConfigData.Sub_Mask = {255,255,255,0},
|
||||
.ConfigData.Phy_Addr = {0x0c,0x29,0xab,0x7c,0x00,0x01},
|
||||
|
||||
.ConfigData.IP_Addr = {192,168,100,101},
|
||||
.ConfigData.Port = {0x13,0x88},
|
||||
|
||||
// .ConfigData.DIP = {192,168,1,32},
|
||||
// .ConfigData.DPort = {0x03,0x09},
|
||||
|
||||
.ConfigData.Port = {0x01,0xF6},
|
||||
.Run_Mode = BSP_W5500_PORT_RUN_MODE_TCP_SERVER,
|
||||
// .Rx_DataAnalysis = proto_HSMS_Rx_DataAnalysis,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -776,7 +750,7 @@ 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端口初始化配置*/
|
||||
//bsp_W5500_Socket_Set(&pW5500->W5500_Class[i]); /*W5500端口初始化配置*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -798,9 +772,10 @@ static void bsp_W5500_Task(void)
|
||||
// Write_SOCK_Data_Buffer(&pW5500->W5500_Class[i], pW5500->W5500_Class[i].Rx_Buffer, Len);
|
||||
// printf("RX");
|
||||
// Debug_UartSend(pW5500->W5500_Class[i].Rx_Buffer, Len);
|
||||
|
||||
if(pW5500->W5500_Class[i].Rx_DataAnalysis != NULL)
|
||||
{
|
||||
pW5500->W5500_Class[i].Rx_DataAnalysis(&pW5500->W5500_Class[i],pW5500->W5500_Class[i].Rx_Buffer,Len);/*数据解析*/
|
||||
pW5500->W5500_Class[i].Rx_DataAnalysis(pW5500->W5500_Class[i].Rx_Buffer,Len,&pW5500->W5500_Class[i]);/*数据解析*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,11 +215,10 @@
|
||||
#define W5500_INT_PORT W5500_INT_GPIO_Port
|
||||
|
||||
typedef u8 SOCKET; // 自定义端口号数据类型
|
||||
#define BSP_W5500_PORT_NUM 1
|
||||
|
||||
#define BSP_W5500_PORT_NUM 1
|
||||
#define BSP_W5500_DATA_LEN 2048
|
||||
|
||||
|
||||
#define BSP_W5500_TX_DATA_LEN 2048
|
||||
#define BSP_W5500_RX_DATA_LEN 2048
|
||||
|
||||
typedef struct bsp_W5500_Class_t bsp_W5500_Class_t;
|
||||
|
||||
@@ -228,11 +227,7 @@ struct bsp_W5500_Class_t
|
||||
SOCKET SocketPort;
|
||||
struct
|
||||
{
|
||||
/***************----- 网络参数变量定义 -----***************/
|
||||
u8 Gateway_IP[4]; /*网关IP地址*/
|
||||
u8 Sub_Mask[4]; /*子网掩码*/
|
||||
u8 Phy_Addr[6]; /*物理地址(MAC)*/
|
||||
u8 IP_Addr[4]; /*本机IP地址*/
|
||||
/***************----- 网络参数变量定义 -----***************/
|
||||
u8 Port[2]; /*端口0的端口号(5000) */
|
||||
u8 DIP[4]; /*端口0目的IP地址*/
|
||||
u8 DPort[2]; /*端口0目的端口号(6000)*/
|
||||
@@ -247,12 +242,12 @@ struct bsp_W5500_Class_t
|
||||
/***************----- 端口收发数据的状态 -----***********/
|
||||
u8 TR_Data_State;
|
||||
/***************----- 端口数据缓冲区 -----***************/
|
||||
u8 Rx_Buffer[BSP_W5500_DATA_LEN]; // 端口接收数据缓冲区
|
||||
u8 Tx_Buffer[BSP_W5500_DATA_LEN]; // 端口发送数据缓冲区
|
||||
u8 Rx_Buffer[BSP_W5500_RX_DATA_LEN]; // 端口接收数据缓冲区
|
||||
u8 Tx_Buffer[BSP_W5500_TX_DATA_LEN]; // 端口发送数据缓冲区
|
||||
|
||||
u8 Interrupt; // W5500中断标志(0:无中断,1:有中断)
|
||||
|
||||
void (*Rx_DataAnalysis)(bsp_W5500_Class_t *,u8 *,u16 );
|
||||
void (*Rx_DataAnalysis)(u8 *,u16 ,void *);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -340,20 +340,21 @@ static void bsp_uart_dma_send(bsp_uart_t *p_uart, u8 *p_data, u16 len)
|
||||
/* 拷贝数据到发送缓冲区 */
|
||||
memcpy(p_uart->tx_addr, p_data, len);
|
||||
|
||||
/* 启动DMA发送 */
|
||||
HAL_UART_Transmit_DMA(p_uart->uart, p_uart->tx_addr, len);
|
||||
|
||||
/* 等待发送完成,带超时检测 */
|
||||
tick_start = HAL_GetTick();
|
||||
while(!p_uart->tx_dma_complete_flag)
|
||||
{
|
||||
tick = HAL_GetTick();
|
||||
if((tick - tick_start) > 200) /* 200ms超时 */
|
||||
{
|
||||
p_uart->tx_dma_complete_flag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
HAL_UART_Transmit(p_uart->uart, p_uart->tx_addr, len,50);
|
||||
// /* 启动DMA发送 */
|
||||
// HAL_UART_Transmit_DMA(p_uart->uart, p_uart->tx_addr, len);
|
||||
//
|
||||
// /* 等待发送完成,带超时检测 */
|
||||
// tick_start = HAL_GetTick();
|
||||
// while(!p_uart->tx_dma_complete_flag)
|
||||
// {
|
||||
// tick = HAL_GetTick();
|
||||
// if((tick - tick_start) > 200) /* 200ms超时 */
|
||||
// {
|
||||
// p_uart->tx_dma_complete_flag = 1;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/******************************************
|
||||
@@ -520,10 +521,10 @@ static void bsp_uart_rx_task(bsp_uart_t *p_uart)
|
||||
{
|
||||
p_uart->rx_data_analysis(rx_temp_buff, p_uart->rx_len, p_uart);
|
||||
}
|
||||
if(p_uart == &com_uart6)
|
||||
{
|
||||
p_uart->send(p_uart, rx_temp_buff, p_uart->rx_len);
|
||||
}
|
||||
// if(p_uart == &com_uart6)
|
||||
// {
|
||||
// p_uart->send(p_uart, rx_temp_buff, p_uart->rx_len);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#include "bsp_w25q.h"
|
||||
|
||||
#include "spi.h"
|
||||
#include "main.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "app_leakage.h"
|
||||
|
||||
/* spi flash 片选引脚 - pb12 */
|
||||
#define W25Q32_CS_LOW() HAL_GPIO_WritePin(SPI2_CS_GPIO_Port, SPI2_CS_Pin, GPIO_PIN_RESET)
|
||||
@@ -46,10 +50,57 @@ w25q32_t w25q32 = {
|
||||
};
|
||||
|
||||
|
||||
/* 从W25Q32读取设备信息到app_leakage */
|
||||
static void gui_tjc_hmi_read_device_info_from_w25q(void)
|
||||
{
|
||||
/* 创建一个临时缓冲区 */
|
||||
app_leakage_sub_device_flash_data_t temp_buffer[APP_LEAKAGE_SUB_DEVICE_NUM];
|
||||
|
||||
/* 一次性读取所有设备信息 */
|
||||
w25q32.read(W25Q32_DEVICE_INFO_ADDR,
|
||||
(uint8_t*)temp_buffer,
|
||||
DEVICE_INFO_STORAGE_SIZE);
|
||||
|
||||
/* 检查数据有效性 */
|
||||
uint8_t data_valid = 1;
|
||||
for(int i = 0; i < APP_LEAKAGE_SUB_DEVICE_NUM; i++)
|
||||
{
|
||||
/* 如果所有字段都是0xFF,说明是空数据 */
|
||||
if(temp_buffer[i].state == 0xFF &&
|
||||
temp_buffer[i].com == 0xFF &&
|
||||
temp_buffer[i].modbus_id == 0xFF)
|
||||
{
|
||||
data_valid = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(data_valid)
|
||||
{
|
||||
/* 复制到app_leakage结构体中 */
|
||||
for(int i = 0; i < APP_LEAKAGE_SUB_DEVICE_NUM; i++)
|
||||
{
|
||||
leakage.sub_device_data[i].flash_data = temp_buffer[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Flash为空,初始化设备信息为默认值 */
|
||||
for(int i = 0; i < APP_LEAKAGE_SUB_DEVICE_NUM; i++)
|
||||
{
|
||||
memset(&leakage.sub_device_data[i].flash_data, 0,
|
||||
sizeof(app_leakage_sub_device_flash_data_t));
|
||||
leakage.sub_device_data[i].flash_data.state = DISABLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* 初始化函数 */
|
||||
static void w25q32_init(void) {
|
||||
W25Q32_CS_HIGH(); /* 初始时片选拉高 */
|
||||
w25q32_wake_up(); /* 唤醒芯片 */
|
||||
gui_tjc_hmi_read_device_info_from_w25q();
|
||||
}
|
||||
|
||||
/* 读取芯片id */
|
||||
|
||||
Reference in New Issue
Block a user