You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
5.1 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : LWIP.c
  5. * Description : This file provides initialization code for LWIP
  6. * middleWare.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * Copyright (c) 2023 STMicroelectronics.
  11. * All rights reserved.
  12. *
  13. * This software is licensed under terms that can be found in the LICENSE file
  14. * in the root directory of this software component.
  15. * If no LICENSE file comes with this software, it is provided AS-IS.
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "lwip.h"
  22. #include "lwip/init.h"
  23. #include "lwip/netif.h"
  24. #if defined ( __CC_ARM ) /* MDK ARM Compiler */
  25. #include "lwip/sio.h"
  26. #endif /* MDK ARM Compiler */
  27. #include "ethernetif.h"
  28. /* USER CODE BEGIN 0 */
  29. /* USER CODE END 0 */
  30. /* Private function prototypes -----------------------------------------------*/
  31. static void ethernet_link_status_updated(struct netif *netif);
  32. /* ETH Variables initialization ----------------------------------------------*/
  33. void Error_Handler(void);
  34. /* USER CODE BEGIN 1 */
  35. /* USER CODE END 1 */
  36. /* Variables Initialization */
  37. struct netif gnetif;
  38. ip4_addr_t ipaddr;
  39. ip4_addr_t netmask;
  40. ip4_addr_t gw;
  41. /* USER CODE BEGIN 2 */
  42. /* USER CODE END 2 */
  43. /**
  44. * LwIP initialization function
  45. */
  46. void MX_LWIP_Init(void)
  47. {
  48. /* Initilialize the LwIP stack with RTOS */
  49. tcpip_init( NULL, NULL );
  50. /* IP addresses initialization with DHCP (IPv4) */
  51. ipaddr.addr = 0;
  52. netmask.addr = 0;
  53. gw.addr = 0;
  54. gnetif.hostname = "IflytopTest";
  55. /* add the network interface (IPv4/IPv6) with RTOS */
  56. netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);
  57. /* Registers the default network interface */
  58. netif_set_default(&gnetif);
  59. if (netif_is_link_up(&gnetif))
  60. {
  61. /* When the netif is fully configured this function must be called */
  62. netif_set_up(&gnetif);
  63. }
  64. else
  65. {
  66. /* When the netif link is down this function must be called */
  67. netif_set_down(&gnetif);
  68. }
  69. /* Set the link callback function, this function is called on change of link status*/
  70. netif_set_link_callback(&gnetif, ethernet_link_status_updated);
  71. /* Create the Ethernet link handler thread */
  72. /* USER CODE BEGIN H7_OS_THREAD_DEF_CREATE_CMSIS_RTOS_V1 */
  73. osThreadDef(EthLink, ethernet_link_thread, osPriorityBelowNormal, 0, configMINIMAL_STACK_SIZE *2);
  74. osThreadCreate (osThread(EthLink), &gnetif);
  75. /* USER CODE END H7_OS_THREAD_DEF_CREATE_CMSIS_RTOS_V1 */
  76. /* Start DHCP negotiation for a network interface (IPv4) */
  77. dhcp_start(&gnetif);
  78. /* USER CODE BEGIN 3 */
  79. /* USER CODE END 3 */
  80. }
  81. #ifdef USE_OBSOLETE_USER_CODE_SECTION_4
  82. /* Kept to help code migration. (See new 4_1, 4_2... sections) */
  83. /* Avoid to use this user section which will become obsolete. */
  84. /* USER CODE BEGIN 4 */
  85. /* USER CODE END 4 */
  86. #endif
  87. /**
  88. * @brief Notify the User about the network interface config status
  89. * @param netif: the network interface
  90. * @retval None
  91. */
  92. static void ethernet_link_status_updated(struct netif *netif)
  93. {
  94. if (netif_is_up(netif))
  95. {
  96. /* USER CODE BEGIN 5 */
  97. /* USER CODE END 5 */
  98. }
  99. else /* netif is down */
  100. {
  101. /* USER CODE BEGIN 6 */
  102. /* USER CODE END 6 */
  103. }
  104. }
  105. #if defined ( __CC_ARM ) /* MDK ARM Compiler */
  106. /**
  107. * Opens a serial device for communication.
  108. *
  109. * @param devnum device number
  110. * @return handle to serial device if successful, NULL otherwise
  111. */
  112. sio_fd_t sio_open(u8_t devnum)
  113. {
  114. sio_fd_t sd;
  115. /* USER CODE BEGIN 7 */
  116. sd = 0; // dummy code
  117. /* USER CODE END 7 */
  118. return sd;
  119. }
  120. /**
  121. * Sends a single character to the serial device.
  122. *
  123. * @param c character to send
  124. * @param fd serial device handle
  125. *
  126. * @note This function will block until the character can be sent.
  127. */
  128. void sio_send(u8_t c, sio_fd_t fd)
  129. {
  130. /* USER CODE BEGIN 8 */
  131. /* USER CODE END 8 */
  132. }
  133. /**
  134. * Reads from the serial device.
  135. *
  136. * @param fd serial device handle
  137. * @param data pointer to data buffer for receiving
  138. * @param len maximum length (in bytes) of data to receive
  139. * @return number of bytes actually received - may be 0 if aborted by sio_read_abort
  140. *
  141. * @note This function will block until data can be received. The blocking
  142. * can be cancelled by calling sio_read_abort().
  143. */
  144. u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len)
  145. {
  146. u32_t recved_bytes;
  147. /* USER CODE BEGIN 9 */
  148. recved_bytes = 0; // dummy code
  149. /* USER CODE END 9 */
  150. return recved_bytes;
  151. }
  152. /**
  153. * Tries to read from the serial device. Same as sio_read but returns
  154. * immediately if no data is available and never blocks.
  155. *
  156. * @param fd serial device handle
  157. * @param data pointer to data buffer for receiving
  158. * @param len maximum length (in bytes) of data to receive
  159. * @return number of bytes actually received
  160. */
  161. u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len)
  162. {
  163. u32_t recved_bytes;
  164. /* USER CODE BEGIN 10 */
  165. recved_bytes = 0; // dummy code
  166. /* USER CODE END 10 */
  167. return recved_bytes;
  168. }
  169. #endif /* MDK ARM Compiler */