My device is MK64FN1M0VMD12.The hardware is TWR-K64F120M. My compiler is IAR 7.2.
The MQX is Freescale_MQX_4_1_TWRK64F120M.
I write a tftps program.
When the function “ipcfg_bind_staticip (phy_addr,
&ip_data)” is used to bind the IP.
The tftps can work immediately after the program print "\nTFTP Server is running."
But when the function “ipcfg_bind_dhcp_wait(phy_addr, 1,&ip_data)” is used to bind the IP .The tftps can not work immediately after the program
print "\nTFTP Server isrunning." It costs about 6 seconds to run the tffps .
What is the reason?
The source code.
Hi Robin:
I think this is normal, when you use ipcfg_bind_dhcp_wait, system will poll dhcp packet , it needs some time
Have a great day,
Daniel
{ /*Normal user application*/
/* Init RTCS */ _RTCSPCB_init = 4; _RTCSPCB_grow = 2; _RTCSPCB_max = 8; _RTCSTASK_stacksize = 4500; error = RTCS_create(); if (error != RTCS_OK) { printf("RTCS failed to initialize, error = 0x%X\n", error); _task_block(); }
_IP_forward = TRUE;
/* Bind IP address for each interface */ for (i = 0; (i < n_devices) && (n_devices != 0); i++)/*n_devices=1*/ {/*get address*/ _enet_address address; uint32_t phy_addr; #if RTCSCFG_ENABLE_IP4 IPCFG_IP_ADDRESS_DATA ip_data; #endif phy_addr = i; ip_addr[i] = IPADDR(A,B,C+i,D);
ENET_get_mac_address(phy_addr, ip_addr[i], address); /* Init ENET device */ error = ipcfg_init_device (phy_addr, address); if (error != RTCS_OK) { printf("IPCFG: Device n.%d init failed. Error = 0x%X\n", i, error); _task_set_error(MQX_OK); n_devices--; i--; continue; }
#if RTCSCFG_ENABLE_IP4 ip_data.ip = ip_addr[i]; ip_data.mask = ENET_IPMASK; ip_data.gateway = 0;
#if DEMOCFG_ENABLE_DHCP error = ipcfg_bind_dhcp_wait(phy_addr, 1, &ip_data);/*Binds Ethernet device to network using DHCP protocol (blocking mode).*/ if (error != RTCS_OK) { printf("DHCP Error %08x! Use static IP\n", error);
error = ipcfg_bind_staticip (phy_addr, &ip_data); if (error != RTCS_OK) { printf("\nIPCFG: Failed to bind static IP address. Error = 0x%X", error); _task_block(); } } #else /* Bind IPv4 address */ error = ipcfg_bind_staticip (phy_addr, &ip_data);/*Binds Ethernet device to network using constant (static) IPv4 address information*/ if (error != RTCS_OK) { printf("\nIPCFG: Failed to bind static IP address. Error = 0x%X", error); _task_block(); }
#endif
#endif /*indexes[i] = (char*) _mem_alloc_zero(sizeof("\\index_x.html")); if (indexes[i] == NULL) { printf("\n Failed to allocate memory."); _task_block(); }*/ ipcfg_get_ip(phy_addr, &ip_data); printf("IP Address : %d.%d.%d.%d\n\n",IPBYTES(ip_data.ip)); /*Update the fnet_params*/ UpdateFnetParams(address,ip_data); fapp_params_to_flash(); }
#if DEMOCFG_TFTP_SERVER { error = TFTPSRV_init("TFTP server", 7, 1000);/*create tftps task*/ if (error) {} else {printf("\nTFTP Server is running."); } } #endif
#if 0
/* Install trivial file system. HTTP server pages are stored there. */ error = _io_tfs_install("tfs:", tfs_data); /* Start HTTP server on each interface */ for (i = 0; i < n_servers; i++) { _mem_zero(¶ms[i], sizeof(HTTPSRV_PARAM_STRUCT)); params[i].af = HTTP_INET_AF; //IPv4, IPv6 or from config.h
#if RTCSCFG_ENABLE_IP6 /* Set interface number here. Zero is any. */ params[i].ipv6_scope_id = HTTP_SCOPE_ID; #endif
sprintf(indexes[i], "\\index.html"); params[i].root_dir = "tfs:"; params[i].index_page = indexes[i]; params[i].auth_table = auth_realms; printf("Starting http server No.%d on IP", i); /* ** If there is only one server listen on any IP address ** so address can change in runtime (DHCP etc.). ** Otherwise we will use static IP for server. */ if (HTTP_INET_AF & AF_INET) { #if RTCSCFG_ENABLE_IP4 if ((i == 0) && (n_servers == 1)) { params[i].ipv4_address.s_addr = INADDR_ANY; } else { params[i].ipv4_address.s_addr = ip_addr[i]; } /* Print active IPv4 address */ printf(" %d.%d.%d.%d", IPBYTES(ip_addr[i])); #endif } if (HTTP_INET_AF & AF_INET6) { #if RTCSCFG_ENABLE_IP6 IPCFG6_GET_ADDR_DATA data; char prn_addr6[RTCS_IP_ADDR_STR_SIZE]; ipcfg6_get_addr(0, 0, &data);
if(inet_ntop(AF_INET6, &(data.ip_addr), prn_addr6, sizeof(prn_addr6))) { /* Print active IPv6 address */ printf("%s %s", (HTTP_INET_AF & AF_INET) ? " and" : "", prn_addr6); } #endif } /* ** Maximum default number of available sockets in RTCS is six. ** Maximum of two are used for HTTP server as listening sockets (one for IPv4 and one for IPv6). ** So we take two of sockets and use them for sessions. */ params[i].max_ses = 2; params[i].cgi_lnk_tbl = (HTTPSRV_CGI_LINK_STRUCT*) cgi_lnk_tbl;
/* There are a lot of static data in CGIs so we have to set large enough stack for script handler */ params[i].script_stack = 3000; server[i] = HTTPSRV_init(¶ms[i]); printf("..."); if (server[i] == (uint32_t) RTCS_ERROR) { printf("[FAIL]\n"); } else { printf("[OK]\n"); } } /* HTTP server initialization is done so we can start shell */
#endif /*_task_create(0, SHELL_TASK, 0);*/ //_task_create(0, RS485_TASK, 0); /*Normal user application*/ }