lwipthread.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file lwipthread.h
  15. * @brief LWIP wrapper thread macros and structures.
  16. * @addtogroup LWIP_THREAD
  17. * @{
  18. */
  19. #ifndef LWIPTHREAD_H
  20. #define LWIPTHREAD_H
  21. #include <lwip/opt.h>
  22. /**
  23. * @brief lwIP default network interface maximum transmission unit (MTU).
  24. */
  25. #if !defined(LWIP_NETIF_MTU) || defined(__DOXYGEN__)
  26. #define LWIP_NETIF_MTU 1500
  27. #endif
  28. /**
  29. * @brief Default network interface hostname.
  30. */
  31. #if !defined(LWIP_NETIF_HOSTNAME_STRING) || defined(__DOXYGEN__)
  32. #define LWIP_NETIF_HOSTNAME_STRING "lwip"
  33. #endif
  34. /**
  35. * @brief Default network interface hostname.
  36. */
  37. #if !defined(LWIP_THREAD_NAME) || defined(__DOXYGEN__)
  38. #define LWIP_THREAD_NAME "lwipthread"
  39. #endif
  40. /**
  41. * @brief lwIP thread priority.
  42. */
  43. #ifndef LWIP_THREAD_PRIORITY
  44. #define LWIP_THREAD_PRIORITY LOWPRIO
  45. #endif
  46. /**
  47. * @brief lwIP thread stack size.
  48. */
  49. #if !defined(LWIP_THREAD_STACK_SIZE) || defined(__DOXYGEN__)
  50. #define LWIP_THREAD_STACK_SIZE 672
  51. #endif
  52. /**
  53. * @brief Link poll interval.
  54. */
  55. #if !defined(LWIP_LINK_POLL_INTERVAL) || defined(__DOXYGEN__)
  56. #define LWIP_LINK_POLL_INTERVAL TIME_S2I(5)
  57. #endif
  58. /**
  59. * @brief IP Address.
  60. */
  61. #if !defined(LWIP_IPADDR) || defined(__DOXYGEN__)
  62. #define LWIP_IPADDR(p) IP4_ADDR(p, 192, 168, 1, 10)
  63. #endif
  64. /**
  65. * @brief IP Gateway.
  66. */
  67. #if !defined(LWIP_GATEWAY) || defined(__DOXYGEN__)
  68. #define LWIP_GATEWAY(p) IP4_ADDR(p, 192, 168, 1, 1)
  69. #endif
  70. /**
  71. * @brief IP netmask.
  72. */
  73. #if !defined(LWIP_NETMASK) || defined(__DOXYGEN__)
  74. #define LWIP_NETMASK(p) IP4_ADDR(p, 255, 255, 255, 0)
  75. #endif
  76. /**
  77. * @brief Transmission timeout.
  78. */
  79. #if !defined(LWIP_SEND_TIMEOUT) || defined(__DOXYGEN__)
  80. #define LWIP_SEND_TIMEOUT 50
  81. #endif
  82. /**
  83. * @brief Link speed.
  84. */
  85. #if !defined(LWIP_LINK_SPEED) || defined(__DOXYGEN__)
  86. #define LWIP_LINK_SPEED 100000000
  87. #endif
  88. /**
  89. * @brief MAC Address byte 0.
  90. */
  91. #if !defined(LWIP_ETHADDR_0) || defined(__DOXYGEN__)
  92. #define LWIP_ETHADDR_0 0xC2
  93. #endif
  94. /**
  95. * @brief MAC Address byte 1.
  96. */
  97. #if !defined(LWIP_ETHADDR_1) || defined(__DOXYGEN__)
  98. #define LWIP_ETHADDR_1 0xAF
  99. #endif
  100. /**
  101. * @brief MAC Address byte 2.
  102. */
  103. #if !defined(LWIP_ETHADDR_2) || defined(__DOXYGEN__)
  104. #define LWIP_ETHADDR_2 0x51
  105. #endif
  106. /**
  107. * @brief MAC Address byte 3.
  108. */
  109. #if !defined(LWIP_ETHADDR_3) || defined(__DOXYGEN__)
  110. #define LWIP_ETHADDR_3 0x03
  111. #endif
  112. /**
  113. * @brief MAC Address byte 4.
  114. */
  115. #if !defined(LWIP_ETHADDR_4) || defined(__DOXYGEN__)
  116. #define LWIP_ETHADDR_4 0xCF
  117. #endif
  118. /**
  119. * @brief MAC Address byte 5.
  120. */
  121. #if !defined(LWIP_ETHADDR_5) || defined(__DOXYGEN__)
  122. #define LWIP_ETHADDR_5 0x46
  123. #endif
  124. /**
  125. * @brief Interface name byte 0.
  126. */
  127. #if !defined(LWIP_IFNAME0) || defined(__DOXYGEN__)
  128. #define LWIP_IFNAME0 'm'
  129. #endif
  130. /**
  131. * @brief Interface name byte 1.
  132. */
  133. #if !defined(LWIP_IFNAME1) || defined(__DOXYGEN__)
  134. #define LWIP_IFNAME1 's'
  135. #endif
  136. /**
  137. * @brief Utility macro to define an IPv4 address.
  138. *
  139. * @note Within the networking subsystem, IPv4 network addresses are
  140. * stored with LS byte of network address in MS byte of unsigned int.
  141. */
  142. #if BYTE_ORDER == LITTLE_ENDIAN
  143. #define IP4_ADDR_VALUE(a,b,c,d) \
  144. (((u32_t)((d) & 0xff) << 24) | \
  145. ((u32_t)((c) & 0xff) << 16) | \
  146. ((u32_t)((b) & 0xff) << 8) | \
  147. (u32_t)((a) & 0xff))
  148. #else
  149. #define IP4_ADDR_VALUE(a,b,c,d) \
  150. (((u32_t)((a) & 0xff) << 24) | \
  151. ((u32_t)((b) & 0xff) << 16) | \
  152. ((u32_t)((c) & 0xff) << 8) | \
  153. (u32_t)((d) & 0xff))
  154. #endif
  155. /**
  156. * @brief Startup network assigning modes.
  157. */
  158. typedef enum {
  159. #if LWIP_DHCP || defined(__DOXYGEN__)
  160. /**
  161. * @brief Assign a DHCP given address.
  162. */
  163. NET_ADDRESS_DHCP = 1,
  164. #endif
  165. /**
  166. * @brief Assign a statically IPv4 address.
  167. */
  168. NET_ADDRESS_STATIC = 2,
  169. #if LWIP_AUTOIP || defined(__DOXYGEN__)
  170. /**
  171. * @brief Assign an IPv4 link-Local address.
  172. */
  173. NET_ADDRESS_AUTO = 3
  174. #endif
  175. } net_addr_mode_t;
  176. /**
  177. * @brief Runtime TCP/IP settings.
  178. */
  179. typedef struct lwipthread_opts {
  180. /**
  181. * @brief Pointer to MAC address as an array of 6 unsigned bytes.
  182. */
  183. uint8_t *macaddress;
  184. /**
  185. * @brief Network address as 32-bit unsigned integer.
  186. */
  187. uint32_t address;
  188. /**
  189. * @brief Network subnet mask as 32-bit unsigned integer.
  190. */
  191. uint32_t netmask;
  192. /**
  193. * @brief Network gateway as 32-bit unsigned integer.
  194. */
  195. uint32_t gateway;
  196. /**
  197. * @brief Startup network addressing mode - static, DHCP, auto.
  198. */
  199. net_addr_mode_t addrMode;
  200. /**
  201. * @brief Host name. If NULL, a default string is used.
  202. * @note Not checked for validity. In particular, spaces not allowed.
  203. */
  204. #if LWIP_NETIF_HOSTNAME || defined(__DOXYGEN__)
  205. const char *ourHostName;
  206. #endif
  207. } lwipthread_opts_t;
  208. #ifdef __cplusplus
  209. extern "C" {
  210. #endif
  211. void lwipInit(const lwipthread_opts_t *opts);
  212. #ifdef __cplusplus
  213. }
  214. #endif
  215. #endif /* LWIPTHREAD_H */
  216. /** @} */