Tom Martins
/
Probleme_implementation_lwip2
test public
Fork of Probleme_implementation_lwip by
netconf.cpp@1:a3ee8cb24540, 2018-07-02 (annotated)
- Committer:
- TomTom83
- Date:
- Mon Jul 02 14:36:46 2018 +0000
- Revision:
- 1:a3ee8cb24540
adaptation de bafian modbus
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TomTom83 | 1:a3ee8cb24540 | 1 | /** |
TomTom83 | 1:a3ee8cb24540 | 2 | ****************************************************************************** |
TomTom83 | 1:a3ee8cb24540 | 3 | * @file netconf.c |
TomTom83 | 1:a3ee8cb24540 | 4 | * @author MCD Application Team |
TomTom83 | 1:a3ee8cb24540 | 5 | * @version V1.0.0 |
TomTom83 | 1:a3ee8cb24540 | 6 | * @date 31-October-2011 |
TomTom83 | 1:a3ee8cb24540 | 7 | * @brief Network connection configuration |
TomTom83 | 1:a3ee8cb24540 | 8 | ****************************************************************************** |
TomTom83 | 1:a3ee8cb24540 | 9 | * @attention |
TomTom83 | 1:a3ee8cb24540 | 10 | * |
TomTom83 | 1:a3ee8cb24540 | 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
TomTom83 | 1:a3ee8cb24540 | 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE |
TomTom83 | 1:a3ee8cb24540 | 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY |
TomTom83 | 1:a3ee8cb24540 | 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING |
TomTom83 | 1:a3ee8cb24540 | 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE |
TomTom83 | 1:a3ee8cb24540 | 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
TomTom83 | 1:a3ee8cb24540 | 17 | * |
TomTom83 | 1:a3ee8cb24540 | 18 | * <h2><center>© Portions COPYRIGHT 2011 STMicroelectronics</center></h2> |
TomTom83 | 1:a3ee8cb24540 | 19 | ****************************************************************************** |
TomTom83 | 1:a3ee8cb24540 | 20 | */ |
TomTom83 | 1:a3ee8cb24540 | 21 | /** |
TomTom83 | 1:a3ee8cb24540 | 22 | ****************************************************************************** |
TomTom83 | 1:a3ee8cb24540 | 23 | * <h2><center>© Portions COPYRIGHT 2012 Embest Tech. Co., Ltd.</center></h2> |
TomTom83 | 1:a3ee8cb24540 | 24 | * @file netconf.c |
TomTom83 | 1:a3ee8cb24540 | 25 | * @author CMP Team |
TomTom83 | 1:a3ee8cb24540 | 26 | * @version V1.0.0 |
TomTom83 | 1:a3ee8cb24540 | 27 | * @date 28-December-2012 |
TomTom83 | 1:a3ee8cb24540 | 28 | * @brief Network connection configuration |
TomTom83 | 1:a3ee8cb24540 | 29 | * Modified to support the STM32F4DISCOVERY, STM32F4DIS-BB and |
TomTom83 | 1:a3ee8cb24540 | 30 | * STM32F4DIS-LCD modules. |
TomTom83 | 1:a3ee8cb24540 | 31 | ****************************************************************************** |
TomTom83 | 1:a3ee8cb24540 | 32 | * @attention |
TomTom83 | 1:a3ee8cb24540 | 33 | * |
TomTom83 | 1:a3ee8cb24540 | 34 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
TomTom83 | 1:a3ee8cb24540 | 35 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE |
TomTom83 | 1:a3ee8cb24540 | 36 | * TIME. AS A RESULT, Embest SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT |
TomTom83 | 1:a3ee8cb24540 | 37 | * OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT |
TomTom83 | 1:a3ee8cb24540 | 38 | * OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION |
TomTom83 | 1:a3ee8cb24540 | 39 | * CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
TomTom83 | 1:a3ee8cb24540 | 40 | ****************************************************************************** |
TomTom83 | 1:a3ee8cb24540 | 41 | */ |
TomTom83 | 1:a3ee8cb24540 | 42 | /* Includes ------------------------------------------------------------------*/ |
TomTom83 | 1:a3ee8cb24540 | 43 | #include "lwip/mem.h" |
TomTom83 | 1:a3ee8cb24540 | 44 | #include "lwip/memp.h" |
TomTom83 | 1:a3ee8cb24540 | 45 | #include "lwip/tcp.h" |
TomTom83 | 1:a3ee8cb24540 | 46 | #include "lwip/udp.h" |
TomTom83 | 1:a3ee8cb24540 | 47 | #include "netif/etharp.h" |
TomTom83 | 1:a3ee8cb24540 | 48 | #include "lwip/dhcp.h" |
TomTom83 | 1:a3ee8cb24540 | 49 | #include "ethernetif.h" |
TomTom83 | 1:a3ee8cb24540 | 50 | #include "main.h" |
TomTom83 | 1:a3ee8cb24540 | 51 | #include "netconf.h" |
TomTom83 | 1:a3ee8cb24540 | 52 | #include <stdio.h> |
TomTom83 | 1:a3ee8cb24540 | 53 | |
TomTom83 | 1:a3ee8cb24540 | 54 | /* Private typedef -----------------------------------------------------------*/ |
TomTom83 | 1:a3ee8cb24540 | 55 | #define MAX_DHCP_TRIES 4 |
TomTom83 | 1:a3ee8cb24540 | 56 | |
TomTom83 | 1:a3ee8cb24540 | 57 | /* Private define ------------------------------------------------------------*/ |
TomTom83 | 1:a3ee8cb24540 | 58 | typedef enum |
TomTom83 | 1:a3ee8cb24540 | 59 | { |
TomTom83 | 1:a3ee8cb24540 | 60 | DHCP_START=0, |
TomTom83 | 1:a3ee8cb24540 | 61 | DHCP_WAIT_ADDRESS, |
TomTom83 | 1:a3ee8cb24540 | 62 | DHCP_ADDRESS_ASSIGNED, |
TomTom83 | 1:a3ee8cb24540 | 63 | DHCP_TIMEOUT |
TomTom83 | 1:a3ee8cb24540 | 64 | } |
TomTom83 | 1:a3ee8cb24540 | 65 | DHCP_State_TypeDef; |
TomTom83 | 1:a3ee8cb24540 | 66 | /* Private macro -------------------------------------------------------------*/ |
TomTom83 | 1:a3ee8cb24540 | 67 | /* Private variables ---------------------------------------------------------*/ |
TomTom83 | 1:a3ee8cb24540 | 68 | struct netif netif; |
TomTom83 | 1:a3ee8cb24540 | 69 | uint32_t TCPTimer = 0; |
TomTom83 | 1:a3ee8cb24540 | 70 | uint32_t ARPTimer = 0; |
TomTom83 | 1:a3ee8cb24540 | 71 | uint32_t IPaddress = 0; |
TomTom83 | 1:a3ee8cb24540 | 72 | |
TomTom83 | 1:a3ee8cb24540 | 73 | #ifdef USE_DHCP |
TomTom83 | 1:a3ee8cb24540 | 74 | uint32_t DHCPfineTimer = 0; |
TomTom83 | 1:a3ee8cb24540 | 75 | uint32_t DHCPcoarseTimer = 0; |
TomTom83 | 1:a3ee8cb24540 | 76 | DHCP_State_TypeDef DHCP_state = DHCP_START; |
TomTom83 | 1:a3ee8cb24540 | 77 | #endif |
TomTom83 | 1:a3ee8cb24540 | 78 | |
TomTom83 | 1:a3ee8cb24540 | 79 | /* Private functions ---------------------------------------------------------*/ |
TomTom83 | 1:a3ee8cb24540 | 80 | void LwIP_DHCP_Process_Handle(void); |
TomTom83 | 1:a3ee8cb24540 | 81 | /** |
TomTom83 | 1:a3ee8cb24540 | 82 | * @brief Initializes the lwIP stack |
TomTom83 | 1:a3ee8cb24540 | 83 | * @param None |
TomTom83 | 1:a3ee8cb24540 | 84 | * @retval None |
TomTom83 | 1:a3ee8cb24540 | 85 | */ |
TomTom83 | 1:a3ee8cb24540 | 86 | void LwIP_Init(void) |
TomTom83 | 1:a3ee8cb24540 | 87 | { |
TomTom83 | 1:a3ee8cb24540 | 88 | struct ip_addr ipaddr; |
TomTom83 | 1:a3ee8cb24540 | 89 | struct ip_addr netmask; |
TomTom83 | 1:a3ee8cb24540 | 90 | struct ip_addr gw; |
TomTom83 | 1:a3ee8cb24540 | 91 | #ifndef USE_DHCP |
TomTom83 | 1:a3ee8cb24540 | 92 | uint8_t iptab[4]; |
TomTom83 | 1:a3ee8cb24540 | 93 | uint8_t iptxt[20]; |
TomTom83 | 1:a3ee8cb24540 | 94 | #endif |
TomTom83 | 1:a3ee8cb24540 | 95 | |
TomTom83 | 1:a3ee8cb24540 | 96 | /* Initializes the dynamic memory heap defined by MEM_SIZE.*/ |
TomTom83 | 1:a3ee8cb24540 | 97 | mem_init(); |
TomTom83 | 1:a3ee8cb24540 | 98 | |
TomTom83 | 1:a3ee8cb24540 | 99 | /* Initializes the memory pools defined by MEMP_NUM_x.*/ |
TomTom83 | 1:a3ee8cb24540 | 100 | memp_init(); |
TomTom83 | 1:a3ee8cb24540 | 101 | |
TomTom83 | 1:a3ee8cb24540 | 102 | #ifdef USE_DHCP |
TomTom83 | 1:a3ee8cb24540 | 103 | ipaddr.addr = 0; |
TomTom83 | 1:a3ee8cb24540 | 104 | netmask.addr = 0; |
TomTom83 | 1:a3ee8cb24540 | 105 | gw.addr = 0; |
TomTom83 | 1:a3ee8cb24540 | 106 | #else |
TomTom83 | 1:a3ee8cb24540 | 107 | IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3); |
TomTom83 | 1:a3ee8cb24540 | 108 | IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3); |
TomTom83 | 1:a3ee8cb24540 | 109 | IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); |
TomTom83 | 1:a3ee8cb24540 | 110 | |
TomTom83 | 1:a3ee8cb24540 | 111 | #ifdef USE_LCD |
TomTom83 | 1:a3ee8cb24540 | 112 | iptab[0] = IP_ADDR3; |
TomTom83 | 1:a3ee8cb24540 | 113 | iptab[1] = IP_ADDR2; |
TomTom83 | 1:a3ee8cb24540 | 114 | iptab[2] = IP_ADDR1; |
TomTom83 | 1:a3ee8cb24540 | 115 | iptab[3] = IP_ADDR0; |
TomTom83 | 1:a3ee8cb24540 | 116 | |
TomTom83 | 1:a3ee8cb24540 | 117 | sprintf((char*)iptxt, " %d.%d.%d.%d", iptab[3], iptab[2], iptab[1], iptab[0]); |
TomTom83 | 1:a3ee8cb24540 | 118 | |
TomTom83 | 1:a3ee8cb24540 | 119 | LCD_DisplayStringLine(Line8, (uint8_t*)" Static IP address "); |
TomTom83 | 1:a3ee8cb24540 | 120 | LCD_DisplayStringLine(Line9, iptxt); |
TomTom83 | 1:a3ee8cb24540 | 121 | #endif |
TomTom83 | 1:a3ee8cb24540 | 122 | #endif |
TomTom83 | 1:a3ee8cb24540 | 123 | |
TomTom83 | 1:a3ee8cb24540 | 124 | /* - netif_add(struct netif *netif, struct ip_addr *ipaddr, |
TomTom83 | 1:a3ee8cb24540 | 125 | struct ip_addr *netmask, struct ip_addr *gw, |
TomTom83 | 1:a3ee8cb24540 | 126 | void *state, err_t (* init)(struct netif *netif), |
TomTom83 | 1:a3ee8cb24540 | 127 | err_t (* input)(struct pbuf *p, struct netif *netif)) |
TomTom83 | 1:a3ee8cb24540 | 128 | |
TomTom83 | 1:a3ee8cb24540 | 129 | Adds your network interface to the netif_list. Allocate a struct |
TomTom83 | 1:a3ee8cb24540 | 130 | netif and pass a pointer to this structure as the first argument. |
TomTom83 | 1:a3ee8cb24540 | 131 | Give pointers to cleared ip_addr structures when using DHCP, |
TomTom83 | 1:a3ee8cb24540 | 132 | or fill them with sane numbers otherwise. The state pointer may be NULL. |
TomTom83 | 1:a3ee8cb24540 | 133 | |
TomTom83 | 1:a3ee8cb24540 | 134 | The init function pointer must point to a initialization function for |
TomTom83 | 1:a3ee8cb24540 | 135 | your ethernet netif interface. The following code illustrates it's use.*/ |
TomTom83 | 1:a3ee8cb24540 | 136 | netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, ðernet_input); |
TomTom83 | 1:a3ee8cb24540 | 137 | |
TomTom83 | 1:a3ee8cb24540 | 138 | /* Registers the default network interface.*/ |
TomTom83 | 1:a3ee8cb24540 | 139 | netif_set_default(&netif); |
TomTom83 | 1:a3ee8cb24540 | 140 | |
TomTom83 | 1:a3ee8cb24540 | 141 | /* When the netif is fully configured this function must be called.*/ |
TomTom83 | 1:a3ee8cb24540 | 142 | netif_set_up(&netif); |
TomTom83 | 1:a3ee8cb24540 | 143 | } |
TomTom83 | 1:a3ee8cb24540 | 144 | |
TomTom83 | 1:a3ee8cb24540 | 145 | /** |
TomTom83 | 1:a3ee8cb24540 | 146 | * @brief Called when a frame is received |
TomTom83 | 1:a3ee8cb24540 | 147 | * @param None |
TomTom83 | 1:a3ee8cb24540 | 148 | * @retval None |
TomTom83 | 1:a3ee8cb24540 | 149 | */ |
TomTom83 | 1:a3ee8cb24540 | 150 | void LwIP_Pkt_Handle(void) |
TomTom83 | 1:a3ee8cb24540 | 151 | { |
TomTom83 | 1:a3ee8cb24540 | 152 | /* Read a received packet from the Ethernet buffers and send it to the lwIP for handling */ |
TomTom83 | 1:a3ee8cb24540 | 153 | ethernetif_input(&netif); |
TomTom83 | 1:a3ee8cb24540 | 154 | } |
TomTom83 | 1:a3ee8cb24540 | 155 | |
TomTom83 | 1:a3ee8cb24540 | 156 | /** |
TomTom83 | 1:a3ee8cb24540 | 157 | * @brief LwIP periodic tasks |
TomTom83 | 1:a3ee8cb24540 | 158 | * @param localtime the current LocalTime value |
TomTom83 | 1:a3ee8cb24540 | 159 | * @retval None |
TomTom83 | 1:a3ee8cb24540 | 160 | */ |
TomTom83 | 1:a3ee8cb24540 | 161 | void LwIP_Periodic_Handle(__IO uint32_t localtime) |
TomTom83 | 1:a3ee8cb24540 | 162 | { |
TomTom83 | 1:a3ee8cb24540 | 163 | #if LWIP_TCP |
TomTom83 | 1:a3ee8cb24540 | 164 | /* TCP periodic process every 250 ms */ |
TomTom83 | 1:a3ee8cb24540 | 165 | if (localtime - TCPTimer >= TCP_TMR_INTERVAL) { |
TomTom83 | 1:a3ee8cb24540 | 166 | TCPTimer = localtime; |
TomTom83 | 1:a3ee8cb24540 | 167 | tcp_tmr(); |
TomTom83 | 1:a3ee8cb24540 | 168 | } |
TomTom83 | 1:a3ee8cb24540 | 169 | #endif |
TomTom83 | 1:a3ee8cb24540 | 170 | |
TomTom83 | 1:a3ee8cb24540 | 171 | /* ARP periodic process every 5s */ |
TomTom83 | 1:a3ee8cb24540 | 172 | if ((localtime - ARPTimer) >= ARP_TMR_INTERVAL) { |
TomTom83 | 1:a3ee8cb24540 | 173 | ARPTimer = localtime; |
TomTom83 | 1:a3ee8cb24540 | 174 | etharp_tmr(); |
TomTom83 | 1:a3ee8cb24540 | 175 | } |
TomTom83 | 1:a3ee8cb24540 | 176 | |
TomTom83 | 1:a3ee8cb24540 | 177 | #ifdef USE_DHCP |
TomTom83 | 1:a3ee8cb24540 | 178 | /* Fine DHCP periodic process every 500ms */ |
TomTom83 | 1:a3ee8cb24540 | 179 | if (localtime - DHCPfineTimer >= DHCP_FINE_TIMER_MSECS) { |
TomTom83 | 1:a3ee8cb24540 | 180 | DHCPfineTimer = localtime; |
TomTom83 | 1:a3ee8cb24540 | 181 | dhcp_fine_tmr(); |
TomTom83 | 1:a3ee8cb24540 | 182 | if ((DHCP_state != DHCP_ADDRESS_ASSIGNED)&&(DHCP_state != DHCP_TIMEOUT)) { |
TomTom83 | 1:a3ee8cb24540 | 183 | /* process DHCP state machine */ |
TomTom83 | 1:a3ee8cb24540 | 184 | LwIP_DHCP_Process_Handle(); |
TomTom83 | 1:a3ee8cb24540 | 185 | } |
TomTom83 | 1:a3ee8cb24540 | 186 | } |
TomTom83 | 1:a3ee8cb24540 | 187 | |
TomTom83 | 1:a3ee8cb24540 | 188 | /* DHCP Coarse periodic process every 60s */ |
TomTom83 | 1:a3ee8cb24540 | 189 | if (localtime - DHCPcoarseTimer >= DHCP_COARSE_TIMER_MSECS) { |
TomTom83 | 1:a3ee8cb24540 | 190 | DHCPcoarseTimer = localtime; |
TomTom83 | 1:a3ee8cb24540 | 191 | dhcp_coarse_tmr(); |
TomTom83 | 1:a3ee8cb24540 | 192 | } |
TomTom83 | 1:a3ee8cb24540 | 193 | |
TomTom83 | 1:a3ee8cb24540 | 194 | #endif |
TomTom83 | 1:a3ee8cb24540 | 195 | } |
TomTom83 | 1:a3ee8cb24540 | 196 | |
TomTom83 | 1:a3ee8cb24540 | 197 | #ifdef USE_DHCP |
TomTom83 | 1:a3ee8cb24540 | 198 | /** |
TomTom83 | 1:a3ee8cb24540 | 199 | * @brief LwIP_DHCP_Process_Handle |
TomTom83 | 1:a3ee8cb24540 | 200 | * @param None |
TomTom83 | 1:a3ee8cb24540 | 201 | * @retval None |
TomTom83 | 1:a3ee8cb24540 | 202 | */ |
TomTom83 | 1:a3ee8cb24540 | 203 | void LwIP_DHCP_Process_Handle() |
TomTom83 | 1:a3ee8cb24540 | 204 | { |
TomTom83 | 1:a3ee8cb24540 | 205 | struct ip_addr ipaddr; |
TomTom83 | 1:a3ee8cb24540 | 206 | struct ip_addr netmask; |
TomTom83 | 1:a3ee8cb24540 | 207 | struct ip_addr gw; |
TomTom83 | 1:a3ee8cb24540 | 208 | uint8_t iptab[4]; |
TomTom83 | 1:a3ee8cb24540 | 209 | uint8_t iptxt[20]; |
TomTom83 | 1:a3ee8cb24540 | 210 | |
TomTom83 | 1:a3ee8cb24540 | 211 | switch (DHCP_state) |
TomTom83 | 1:a3ee8cb24540 | 212 | { |
TomTom83 | 1:a3ee8cb24540 | 213 | case DHCP_START: |
TomTom83 | 1:a3ee8cb24540 | 214 | { |
TomTom83 | 1:a3ee8cb24540 | 215 | dhcp_start(&netif); |
TomTom83 | 1:a3ee8cb24540 | 216 | IPaddress = 0; |
TomTom83 | 1:a3ee8cb24540 | 217 | DHCP_state = DHCP_WAIT_ADDRESS; |
TomTom83 | 1:a3ee8cb24540 | 218 | #ifdef USE_LCD |
TomTom83 | 1:a3ee8cb24540 | 219 | LCD_DisplayStringLine(Line4, (uint8_t*)" Looking for "); |
TomTom83 | 1:a3ee8cb24540 | 220 | LCD_DisplayStringLine(Line5, (uint8_t*)" DHCP server "); |
TomTom83 | 1:a3ee8cb24540 | 221 | LCD_DisplayStringLine(Line6, (uint8_t*)" please wait... "); |
TomTom83 | 1:a3ee8cb24540 | 222 | #endif |
TomTom83 | 1:a3ee8cb24540 | 223 | } |
TomTom83 | 1:a3ee8cb24540 | 224 | break; |
TomTom83 | 1:a3ee8cb24540 | 225 | |
TomTom83 | 1:a3ee8cb24540 | 226 | case DHCP_WAIT_ADDRESS: |
TomTom83 | 1:a3ee8cb24540 | 227 | { |
TomTom83 | 1:a3ee8cb24540 | 228 | /* Read the new IP address */ |
TomTom83 | 1:a3ee8cb24540 | 229 | IPaddress = netif.ip_addr.addr; |
TomTom83 | 1:a3ee8cb24540 | 230 | |
TomTom83 | 1:a3ee8cb24540 | 231 | if (IPaddress!=0) { |
TomTom83 | 1:a3ee8cb24540 | 232 | DHCP_state = DHCP_ADDRESS_ASSIGNED; |
TomTom83 | 1:a3ee8cb24540 | 233 | |
TomTom83 | 1:a3ee8cb24540 | 234 | /* Stop DHCP */ |
TomTom83 | 1:a3ee8cb24540 | 235 | dhcp_stop(&netif); |
TomTom83 | 1:a3ee8cb24540 | 236 | |
TomTom83 | 1:a3ee8cb24540 | 237 | iptab[0] = (uint8_t)(IPaddress >> 24); |
TomTom83 | 1:a3ee8cb24540 | 238 | iptab[1] = (uint8_t)(IPaddress >> 16); |
TomTom83 | 1:a3ee8cb24540 | 239 | iptab[2] = (uint8_t)(IPaddress >> 8); |
TomTom83 | 1:a3ee8cb24540 | 240 | iptab[3] = (uint8_t)(IPaddress); |
TomTom83 | 1:a3ee8cb24540 | 241 | |
TomTom83 | 1:a3ee8cb24540 | 242 | sprintf((char*)iptxt, " %d.%d.%d.%d", iptab[3], iptab[2], iptab[1], iptab[0]); |
TomTom83 | 1:a3ee8cb24540 | 243 | |
TomTom83 | 1:a3ee8cb24540 | 244 | #ifdef USE_LCD |
TomTom83 | 1:a3ee8cb24540 | 245 | |
TomTom83 | 1:a3ee8cb24540 | 246 | |
TomTom83 | 1:a3ee8cb24540 | 247 | LCD_ClearLine(Line4); |
TomTom83 | 1:a3ee8cb24540 | 248 | LCD_ClearLine(Line5); |
TomTom83 | 1:a3ee8cb24540 | 249 | LCD_ClearLine(Line6); |
TomTom83 | 1:a3ee8cb24540 | 250 | |
TomTom83 | 1:a3ee8cb24540 | 251 | /* Display the IP address */ |
TomTom83 | 1:a3ee8cb24540 | 252 | LCD_DisplayStringLine(Line7, (uint8_t*)"IP address assigned "); |
TomTom83 | 1:a3ee8cb24540 | 253 | LCD_DisplayStringLine(Line8, (uint8_t*)" by a DHCP server "); |
TomTom83 | 1:a3ee8cb24540 | 254 | LCD_DisplayStringLine(Line9, iptxt); |
TomTom83 | 1:a3ee8cb24540 | 255 | #endif |
TomTom83 | 1:a3ee8cb24540 | 256 | } else { |
TomTom83 | 1:a3ee8cb24540 | 257 | /* DHCP timeout */ |
TomTom83 | 1:a3ee8cb24540 | 258 | if (netif.dhcp->tries > MAX_DHCP_TRIES) { |
TomTom83 | 1:a3ee8cb24540 | 259 | DHCP_state = DHCP_TIMEOUT; |
TomTom83 | 1:a3ee8cb24540 | 260 | |
TomTom83 | 1:a3ee8cb24540 | 261 | /* Stop DHCP */ |
TomTom83 | 1:a3ee8cb24540 | 262 | dhcp_stop(&netif); |
TomTom83 | 1:a3ee8cb24540 | 263 | |
TomTom83 | 1:a3ee8cb24540 | 264 | /* Static address used */ |
TomTom83 | 1:a3ee8cb24540 | 265 | IP4_ADDR(&ipaddr, IP_ADDR0 ,IP_ADDR1 , IP_ADDR2 , IP_ADDR3 ); |
TomTom83 | 1:a3ee8cb24540 | 266 | IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3); |
TomTom83 | 1:a3ee8cb24540 | 267 | IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); |
TomTom83 | 1:a3ee8cb24540 | 268 | netif_set_addr(&netif, &ipaddr , &netmask, &gw); |
TomTom83 | 1:a3ee8cb24540 | 269 | |
TomTom83 | 1:a3ee8cb24540 | 270 | #ifdef USE_LCD |
TomTom83 | 1:a3ee8cb24540 | 271 | LCD_DisplayStringLine(Line7, (uint8_t*)" DHCP timeout "); |
TomTom83 | 1:a3ee8cb24540 | 272 | |
TomTom83 | 1:a3ee8cb24540 | 273 | iptab[0] = IP_ADDR3; |
TomTom83 | 1:a3ee8cb24540 | 274 | iptab[1] = IP_ADDR2; |
TomTom83 | 1:a3ee8cb24540 | 275 | iptab[2] = IP_ADDR1; |
TomTom83 | 1:a3ee8cb24540 | 276 | iptab[3] = IP_ADDR0; |
TomTom83 | 1:a3ee8cb24540 | 277 | |
TomTom83 | 1:a3ee8cb24540 | 278 | sprintf((char*)iptxt, " %d.%d.%d.%d", iptab[3], iptab[2], iptab[1], iptab[0]); |
TomTom83 | 1:a3ee8cb24540 | 279 | |
TomTom83 | 1:a3ee8cb24540 | 280 | LCD_ClearLine(Line4); |
TomTom83 | 1:a3ee8cb24540 | 281 | LCD_ClearLine(Line5); |
TomTom83 | 1:a3ee8cb24540 | 282 | LCD_ClearLine(Line6); |
TomTom83 | 1:a3ee8cb24540 | 283 | |
TomTom83 | 1:a3ee8cb24540 | 284 | LCD_DisplayStringLine(Line8, (uint8_t*)" Static IP address "); |
TomTom83 | 1:a3ee8cb24540 | 285 | LCD_DisplayStringLine(Line9, iptxt); |
TomTom83 | 1:a3ee8cb24540 | 286 | #endif |
TomTom83 | 1:a3ee8cb24540 | 287 | } |
TomTom83 | 1:a3ee8cb24540 | 288 | } |
TomTom83 | 1:a3ee8cb24540 | 289 | } |
TomTom83 | 1:a3ee8cb24540 | 290 | break; |
TomTom83 | 1:a3ee8cb24540 | 291 | default: break; |
TomTom83 | 1:a3ee8cb24540 | 292 | } |
TomTom83 | 1:a3ee8cb24540 | 293 | } |
TomTom83 | 1:a3ee8cb24540 | 294 | #endif |
TomTom83 | 1:a3ee8cb24540 | 295 | |
TomTom83 | 1:a3ee8cb24540 | 296 | /*********** Portions COPYRIGHT 2012 Embest Tech. Co., Ltd.*****END OF FILE****/ |
TomTom83 | 1:a3ee8cb24540 | 297 |