Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "lwip/opt.h"
#include "main.h"
#include "lwip/dhcp.h"
#include "app_ethernet.h"
#include "ethernetif.h"
#include "lcd_log.h"
Private variables
#define MAX_DHCP_TRIES
DHCP_state
Private functions
ethernet_link_status_updated(struct netif *)
DHCP_Thread(const void *)
Files
loading...
CodeScopeSTM32 Libraries and SamplesLwIP_HTTP_Server_Netconn_RTOSSrc/app_ethernet.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file LwIP/LwIP_HTTP_Server_Netconn_RTOS/Src/app_ethernet.c * @author MCD Application Team * @brief Ethernet specific module ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "lwip/opt.h" #include "main.h" #if LWIP_DHCP #include "lwip/dhcp.h" #endif #include "app_ethernet.h" #include "ethernetif.h" #ifdef USE_LCD #include "lcd_log.h" #endif Includes /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ #if LWIP_DHCP #define MAX_DHCP_TRIES 4 __IO uint8_t DHCP_state = DHCP_OFF;/* ... */ #endif Private variables /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /** * @brief Notify the User about the network interface config status * @param netif: the network interface * @retval None *//* ... */ void ethernet_link_status_updated(struct netif *netif) { if (netif_is_up(netif)) { #if LWIP_DHCP /* Update DHCP state machine */ DHCP_state = DHCP_START;/* ... */ #elif defined(USE_LCD) uint8_t iptxt[20]; sprintf((char *)iptxt, "%s", ip4addr_ntoa(netif_ip4_addr(netif))); LCD_UsrLog ("Static IP address: %s\n", iptxt);/* ... */ #else BSP_LED_On(LED1); BSP_LED_Off(LED2);/* ... */ #endif /* LWIP_DHCP */ }if (netif_is_up(netif)) { ... } else { #if LWIP_DHCP /* Update DHCP state machine */ DHCP_state = DHCP_LINK_DOWN;/* ... */ #elif defined(USE_LCD) LCD_UsrLog ("The network cable is not connected \n"); #else BSP_LED_Off(LED1); BSP_LED_On(LED2);/* ... */ #endif /* LWIP_DHCP */ }else { ... } }{ ... } #if LWIP_DHCP /** * @brief DHCP Process * @param argument: network interface * @retval None *//* ... */ void DHCP_Thread(void const * argument) { struct netif *netif = (struct netif *) argument; ip_addr_t ipaddr; ip_addr_t netmask; ip_addr_t gw; struct dhcp *dhcp; #ifdef USE_LCD uint8_t iptxt[20]; #endif for (;;) { switch (DHCP_state) { case DHCP_START: { ip_addr_set_zero_ip4(&netif->ip_addr); ip_addr_set_zero_ip4(&netif->netmask); ip_addr_set_zero_ip4(&netif->gw); DHCP_state = DHCP_WAIT_ADDRESS; #ifdef USE_LCD LCD_UsrLog (" State: Looking for DHCP server ...\n"); #else BSP_LED_Off(LED1); BSP_LED_Off(LED2);/* ... */ #endif dhcp_start(netif); ...} break;case DHCP_START: case DHCP_WAIT_ADDRESS: { if (dhcp_supplied_address(netif)) { DHCP_state = DHCP_ADDRESS_ASSIGNED; #ifdef USE_LCD sprintf((char *)iptxt, "%s", ip4addr_ntoa(netif_ip4_addr(netif))); LCD_UsrLog ("IP address assigned by a DHCP server: %s\n", iptxt);/* ... */ #else BSP_LED_On(LED1); BSP_LED_Off(LED2);/* ... */ #endif }if (dhcp_supplied_address(netif)) { ... } else { dhcp = (struct dhcp *)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP); /* DHCP timeout */ if (dhcp->tries > MAX_DHCP_TRIES) { DHCP_state = DHCP_TIMEOUT; /* Static address used */ IP_ADDR4(&ipaddr, IP_ADDR0 ,IP_ADDR1 , IP_ADDR2 , IP_ADDR3 ); IP_ADDR4(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3); IP_ADDR4(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); netif_set_addr(netif, ip_2_ip4(&ipaddr), ip_2_ip4(&netmask), ip_2_ip4(&gw)); #ifdef USE_LCD sprintf((char *)iptxt, "%s", ip4addr_ntoa(netif_ip4_addr(netif))); LCD_UsrLog ("DHCP Timeout !! \n"); LCD_UsrLog ("Static IP address: %s\n", iptxt);/* ... */ #else BSP_LED_On(LED1); BSP_LED_Off(LED2);/* ... */ #endif }if (dhcp->tries > MAX_DHCP_TRIES) { ... } }else { ... } ...} break;case DHCP_WAIT_ADDRESS: case DHCP_LINK_DOWN: { DHCP_state = DHCP_OFF; #ifdef USE_LCD LCD_UsrLog ("The network cable is not connected \n"); #else BSP_LED_Off(LED1); BSP_LED_On(LED2);/* ... */ #endif ...} break;case DHCP_LINK_DOWN: default: break; }switch (DHCP_state) { ... } /* wait 500 ms */ osDelay(500); }for (;;) { ... } }{ ... } #endif/* ... */ Private functions/* LWIP_DHCP */