Просмотр исходного кода

修复特定条件下中断无法触发

Ryan-CW 2 лет назад
Родитель
Сommit
130dc45e2e

+ 4 - 7
W5500Client/RyanW5500.c

@@ -1,7 +1,7 @@
 #define DBG_ENABLE
 
 #define DBG_SECTION_NAME ("w5500")
-#define DBG_LEVEL LOG_LVL_INFO
+#define DBG_LEVEL LOG_LVL_DBG
 #define DBG_COLOR
 
 #include "RyanW5500Store.h"
@@ -64,6 +64,7 @@ int RyanW5500NetWorkInit(struct netdev *netdev)
 
         gWIZNETINFO.dhcp = netdev_is_dhcp_enabled(netdev) ? NETINFO_DHCP : NETINFO_STATIC;
         MaintainFlag = 0;
+
         goto next;
     }
 
@@ -128,9 +129,6 @@ next:
 
     RyanW5500NetDevInfoUpdate(netdev);
 
-    if (PHY_LINK_ON != linkState)
-        return -1;
-
     uint16_t ret = 0xff;     // 启用所有socket通道中断
     ret = (ret << 8) + 0x00; // 禁用所有通用中断,不使用
     ctlwizchip(CW_SET_INTRMASK, (void *)&ret);
@@ -248,6 +246,8 @@ int RyanW5500Init(wiz_NetInfo *netInfo)
     RyanW5500Entry.W5500EventHandle = rt_event_create("RyanW5500Event", RT_IPC_FLAG_PRIO);
     RyanW5500AttachIRQ(RyanW5500IRQCallback); // 绑定w5500中断回调函数
 
+    netdev = RyanW5500NetdevRegister("RyanW5500"); // W5500
+    netdev_low_level_set_status(netdev, RT_TRUE);  // 设置网络接口设备状态
     // 检查w5500连接是否正常
     while (1)
     {
@@ -267,9 +267,6 @@ int RyanW5500Init(wiz_NetInfo *netInfo)
         delay(1000);
     }
 
-    netdev = RyanW5500NetdevRegister("RyanW5500"); // W5500
-    netdev_low_level_set_status(netdev, RT_TRUE);  // 设置网络接口设备状态
-
     RyanW5500Entry.w5500TaskHandle = rt_thread_create("RyanW5500",    // 线程name
                                                       wizIntDataTask, // 线程入口函数
                                                       (void *)netdev, // 线程入口函数参数

+ 11 - 5
W5500Client/RyanW5500Socket.c

@@ -1,7 +1,7 @@
 #define DBG_ENABLE
 
 #define DBG_SECTION_NAME ("RyanW5500Socket")
-#define DBG_LEVEL LOG_LVL_INFO
+#define DBG_LEVEL LOG_LVL_DBG
 #define DBG_COLOR
 
 #include "RyanW5500Store.h"
@@ -344,7 +344,7 @@ int wiz_socket(int domain, int type, int protocol)
     // 该实现不支持指定的协议族类型。
     RyanW5500CheckCode(AF_INET == domain || AF_WIZ == domain, EAFNOSUPPORT, { return -1; });
     // 不支持特定的运输层协议
-    RyanW5500CheckCode(0 == protocol, EPROTONOSUPPORT, { return -1; });
+    // RyanW5500CheckCode(0 == protocol, EPROTONOSUPPORT, { return -1; });
 
     switch (type)
     {
@@ -899,9 +899,15 @@ int wiz_setsockopt(int socket, int level, int optname, const void *optval, sockl
                 sock->soOptionsFlag &= ~optname;
             break;
 
-        // 暂不实现
         case SO_KEEPALIVE: // 为套接字连接启用保持连接。 仅适用于支持保持连接的协议,比如tcp, 对于 TCP,默认保持连接超时为 2 小时,保持连接间隔为 1 秒  布尔类型
-            return -1;
+        {
+            if (sock->type != Sn_MR_TCP) // 对于w5500非tcp连接忽略
+                break;
+            uint32_t keepalive = 2 * 60 * 60 / 5; // w5500 Sn_KPALVTR单位时间为5
+            if (1 == *(int *)optval)
+                RyanW5500CheckCode(SOCK_OK == wizchip_setsockopt(sock->socket, SO_KEEPALIVEAUTO, (void *)&keepalive), EINVAL, { return -1; });
+            break;
+        }
 
         case SO_RCVTIMEO: // 阻止接收调用的超时(以毫秒为单位)。 此选项的默认值为零,表示接收操作不会超时 类型struct timeval
             RyanW5500CheckCode(sizeof(struct timeval) == optlen, EFAULT, { return -1; });
@@ -1178,6 +1184,7 @@ int RyanW5500_gethostbyname(const char *name, ip_addr_t *addr)
         uint8_t remote_ip[4] = {0};
         uint8_t data_buffer[512];
 
+        ulog_w("TAG", "%s:%d 开始获取dns", __FILE__, __LINE__);
         // DNS客户端处理
         ret = DNS_run(gWIZNETINFO.dns, (uint8_t *)name, remote_ip, data_buffer);
         if (1 != ret)
@@ -1483,7 +1490,6 @@ int wiz_getaddrinfo(const char *nodename, const char *servname, const struct add
     return 0;
 }
 
-
 void wiz_freeaddrinfo(struct addrinfo *ai)
 {
     struct addrinfo *next = NULL;

+ 1 - 1
W5500Client/RyanW5500Store.h

@@ -53,7 +53,7 @@ extern "C"
 #define RyanW5500CheckCode(EX, ErrorCode, code)                    \
     if (!(EX))                                                     \
     {                                                              \
-        LOG_D("%s:%d ErrorCode: %d, strError: %s",                 \
+        LOG_I("%s:%d ErrorCode: %d, strError: %s",                 \
               __FILE__, __LINE__, ErrorCode, strerror(ErrorCode)); \
         RyanW5500SetErrno(ErrorCode);                              \
         {                                                          \

+ 21 - 4
platform/RT-Thread/platformW5500Hardware.c

@@ -47,7 +47,11 @@ int RyanW5500SpiInit()
  */
 void RyanW5500WriteByte(uint8_t data)
 {
-    rt_spi_send(RyanW5500SpiDevice, &data, 1);
+    struct rt_spi_message spiMsg = {
+        .send_buf = &data,
+        .length = 1};
+
+    rt_spi_transfer_message(RyanW5500SpiDevice, &spiMsg);
 }
 
 /**
@@ -58,7 +62,11 @@ void RyanW5500WriteByte(uint8_t data)
 uint8_t RyanW5500ReadByte(void)
 {
     uint8_t data;
-    rt_spi_recv(RyanW5500SpiDevice, &data, 1);
+    struct rt_spi_message spiMsg = {
+        .recv_buf = &data,
+        .length = 1};
+
+    rt_spi_transfer_message(RyanW5500SpiDevice, &spiMsg);
 
     return data;
 }
@@ -71,7 +79,11 @@ uint8_t RyanW5500ReadByte(void)
  */
 void RyanW5500WriteBurst(uint8_t *pbuf, uint16_t len)
 {
-    rt_spi_send(RyanW5500SpiDevice, pbuf, len);
+    struct rt_spi_message spiMsg = {
+        .send_buf = pbuf,
+        .length = len};
+
+    rt_spi_transfer_message(RyanW5500SpiDevice, &spiMsg);
 }
 
 /**
@@ -82,7 +94,12 @@ void RyanW5500WriteBurst(uint8_t *pbuf, uint16_t len)
  */
 void RyanW5500ReadBurst(uint8_t *pbuf, uint16_t len)
 {
-    rt_spi_recv(RyanW5500SpiDevice, pbuf, len);
+
+    struct rt_spi_message spiMsg = {
+        .recv_buf = pbuf,
+        .length = len};
+
+    rt_spi_transfer_message(RyanW5500SpiDevice, &spiMsg);
 }
 
 /**