RyanW5500Store.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef __RyanW5500Store__
  2. #define __RyanW5500Store__
  3. #ifdef __cplusplus
  4. extern "C"
  5. {
  6. #endif
  7. #include <stdio.h>
  8. #include <stdint.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <sys/socket.h>
  12. #include <sys/errno.h>
  13. #include <sys/time.h>
  14. #include <netdb.h>
  15. #include <rtthread.h>
  16. #if (RT_VER_NUM > 40100)
  17. #include <sal_low_lvl.h>
  18. #else
  19. #include <sal.h>
  20. #endif
  21. #include "netdev_ipaddr.h"
  22. #include "netdev.h"
  23. #ifdef SAL_USING_POSIX
  24. #include <poll.h>
  25. #endif
  26. #include "RyanList.h"
  27. #include "RyanW5500Log.h"
  28. #include "platformTimer.h"
  29. #include "platformW5500Hardware.h"
  30. #include "wizchip_conf.h"
  31. #include "wizchip_socket.h"
  32. #include "wizchip_dhcp.h"
  33. #include "wizchip_dns.h"
  34. #include "w5500.h"
  35. #include "RyanW5500.h"
  36. #include "RyanW5500Socket.h"
  37. #include "RyanW5500Ping.h"
  38. #include "RyanW5500netDev.h"
  39. #ifndef delay
  40. #define delay(ms) rt_thread_mdelay(ms)
  41. #endif
  42. // WIZnet套接字魔术词
  43. #define WIZ_SOCKET_MAGIC 0x3120
  44. // WIZnet 套接字地址系列
  45. #ifndef AF_WIZ
  46. #define AF_WIZ 46
  47. #endif
  48. #define RyanW5500MaxSocketNum (_WIZCHIP_SOCK_NUM_)
  49. #define netDevDHCPEnable (1 << 2)
  50. #define netDevDHCPDisable (1 << 3)
  51. #define netDevSetDevInfo (1 << 4)
  52. // event标志
  53. // 前8bit用于socket通道数据解析
  54. #define RyanW5500IRQBit (1 << RyanW5500MaxSocketNum)
  55. #define RyanW5500SnIMR (Sn_IR_RECV | Sn_IR_DISCON | Sn_IR_CON) // Sn_IMR
  56. #define RyanW5500IMR (IR_CONFLICT | IR_UNREACH | IR_PPPoE | IR_MP) // IMR (中断屏蔽寄存器)
  57. #define RyanW5500CheckCodeNoReturn(EX, ErrorCode, Ryanlevel, code) \
  58. if (!(EX)) \
  59. { \
  60. \
  61. Ryanlevel("ErrorCode: %d, strError: %d", \
  62. ErrorCode, (ErrorCode)); \
  63. rt_set_errno(ErrorCode); \
  64. {code}; \
  65. }
  66. #define RyanW5500CheckCode(EX, ErrorCode, level, code) RyanW5500CheckCodeNoReturn(EX, ErrorCode, level, { {code}; return ErrorCode; });
  67. #define RyanW5500CheckNoReturn(EX, ErrorCode, level) RyanW5500CheckCodeNoReturn(EX, ErrorCode, level, {})
  68. #define RyanW5500Check(EX, ErrorCode, level) RyanW5500CheckCode(EX, ErrorCode, level, {})
  69. #define RyanW5500CheckAssert(EX, ErrorCode, level) RyanW5500CheckCodeNoReturn(EX, ErrorCode, level, { assert(NULL); })
  70. // 定义枚举类型
  71. // 定义结构体类型
  72. typedef struct
  73. {
  74. uint32_t netDevFlag; // netdev用flag
  75. rt_event_t W5500EventHandle; // 事件标志组,用于中断通知和socket状态通知
  76. rt_mutex_t socketMutexHandle; // socket锁
  77. rt_mutex_t dnsMutexHandle; // dns解析锁
  78. rt_thread_t w5500TaskHandle; // W5500线程
  79. } RyanW5500Entry_t;
  80. /* extern variables-----------------------------------------------------------*/
  81. extern wiz_NetInfo gWIZNETINFO;
  82. extern RyanW5500Entry_t RyanW5500Entry;
  83. #ifdef __cplusplus
  84. }
  85. #endif
  86. #endif