123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- #include "lwip/mem.h"
- #include "lwip/memp.h"
- #include "lwip/dhcp.h"
- #include "ethernetif.h"
- #include "common_config.h"
- #include "netconf.h"
- #include "tcpip.h"
- #include "main.h"
- #include "settings_api.h"
- #include "parameters.h"
- #include "stm32f4x7_eth.h"
- #ifdef PRINTF_STDLIB
- #include <stdio.h>
- #endif
- #ifdef PRINTF_CUSTOM
- #include "tinystdio.h"
- #endif
- #include <string.h>
- #define MAX_DHCP_TRIES 4
- #define TIME_COUNTER_10_MIN 600
- #define TIME_COUNTER_1_MIN 60
- struct netif xnetif;
- unsigned char eth_ready_flag = 0;
- TaskHandle_t xHandleDHCP = NULL;
- extern SETTINGS_t sSettings;
- void LwIP_Init(void)
- {
- struct ip4_addr ipaddr;
- struct ip4_addr netmask;
- struct ip4_addr gw;
- uint16_t reg = 0;
- tcpip_init( NULL, NULL );
- ipaddr.addr = 0;
- netmask.addr = 0;
- gw.addr = 0;
- netif_add(&xnetif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input);
- netif_set_default(&xnetif);
- netif_set_link_up(&xnetif);
- netif_set_up(&xnetif);
-
-
-
- xTaskCreate(LwIP_DHCP_task, "DHCPClient", configMINIMAL_STACK_SIZE * 2, NULL,
- tskIDLE_PRIORITY + 2, &xHandleDHCP);
- }
- void init_get_ip_address_controller(void)
- {
- xTaskCreate(LwIP_DHCP_task, "DHCPClient", configMINIMAL_STACK_SIZE * 2, NULL,
- tskIDLE_PRIORITY + 2, &xHandleDHCP);
- }
- void LwIP_DHCP_task(void *pvParameters)
- {
- struct ip4_addr ipaddr;
- struct ip4_addr netmask;
- struct ip4_addr gw;
- uint8_t DHCP_state;
- DHCP_state = DHCP_START;
- for (;;) {
- struct dhcp *dhcp = netif_dhcp_data(&xnetif);
- switch (DHCP_state) {
- case DHCP_START: {
- dhcp_start(&xnetif);
- DHCP_state = DHCP_WAIT_ADDRESS;
-
- }
- break;
- case DHCP_WAIT_ADDRESS: {
-
- ipaddr = xnetif.ip_addr;
- netmask = xnetif.netmask;
- gw = xnetif.gw;
- if (ipaddr.addr != 0) {
- DHCP_state = DHCP_ADDRESS_ASSIGNED;
- PRINT_USART("Parameters assigned by a DHCP server:\n\r IP: ");
- PRINT_USART(ipaddr_ntoa(&ipaddr));
- PRINT_USART("\n\r");
- PRINT_USART("Netmask: ");
- PRINT_USART(ipaddr_ntoa(&netmask));
- PRINT_USART("\n\r");
- PRINT_USART("Gateway: ");
- PRINT_USART(ipaddr_ntoa(&gw));
- PRINT_USART("\n\r");
- printf("ETH OK\r\n");
-
- vTaskDelay(2000);
- eth_ready_flag = 1;
- vTaskDelete(xHandleDHCP);
- } else {
-
- if (dhcp->tries > MAX_DHCP_TRIES) {
- DHCP_state = DHCP_TIMEOUT;
-
- dhcp_stop(&xnetif);
-
-
- vTaskDelay(2000);
- eth_ready_flag = 0;
- vTaskDelete(xHandleDHCP);
- }
- }
- }
- break;
- default: break;
- }
- vTaskDelay(250);
- }
- }
|