Example #1
0
int32 main(void)
{
#define TCP_LISTEN_PORT	5000
#define UDP_LISTEN_PORT	5000

	int8 ret, root;
	uint32 tick = 0;

	ret = platform_init();
	if(ret != RET_OK) {
		goto FAIL_TRAP;
	}

	ret = network_init(SOCK_DHCP, NULL, NULL);
	if(ret != RET_OK) {
		ERRA("network_init fail - ret(%d)", ret);
		goto FAIL_TRAP;
	}

	printf("\r\n-----------------------------------\r\n");
	printf("SMTP Client using W5200\r\n");
	printf("-----------------------------------\r\n\r\n");

	Delay_tick(2000);

	menu_init();
	root = menu_add("Network setting", 0, NULL);
	menu_add("Show", root, mn_show_network);
	menu_add("Static Set", root, mn_set_network);
	menu_add("Loopback", 0, mn_loopback);
	menu_add("LED Test", 0, mn_set_led);
	root = menu_add("App Test", 0, NULL);
	menu_add("DNS", root, mn_dns);
	menu_add("BASE64", root, mn_base64);
	menu_add("eMail", root, mn_email);
	menu_print_tree();

	dhcp_alarm_start(NULL);

	while(1) {

		alarm_run();
		menu_run();

		if(lb_tcp) loopback_tcps(7, (uint16)TCP_LISTEN_PORT);
		if(lb_udp) loopback_udp(7, (uint16)UDP_LISTEN_PORT);

		if(wizpf_tick_elapse(tick) > 1000) {	// running check
			wizpf_led_set(WIZ_LED3, VAL_TOG);
			tick = wizpf_get_systick();
		}
	}

FAIL_TRAP:
	wizpf_led_trap(1);
	return 0;
}
Example #2
0
int32 main(void)
{
#define TCP_LISTEN_PORT	5000
#define UDP_LISTEN_PORT	5000

	int8 ret, root;
	uint32 dhcp_renew, dhcp_rebind, dhcp_time;
	uint32 dhcp_tick, led_tick;

	ret = platform_init();
	if(ret != RET_OK) {
		goto FAIL_TRAP;
	}

	ret = network_init(SOCK_DHCP, NULL, NULL);
	if(ret != RET_OK) {
		ERRA("network_init fail - ret(%d)", ret);
		goto FAIL_TRAP;
	}

	printf("\r\n-----------------------------------\r\n");
	printf("SMTP Client using W5200\r\n");
	printf("-----------------------------------\r\n\r\n");

	Delay_tick(2000);
	do {
		ret = dhcp_manual(DHCP_ACT_START, NULL, &dhcp_renew, &dhcp_rebind);
	} while(ret != RET_OK);
	dhcp_renew = wizpf_tick_conv(FALSE, dhcp_renew);
	dhcp_rebind = wizpf_tick_conv(FALSE, dhcp_rebind);
	dhcp_time = dhcp_renew;

	menu_init();
	root = menu_add("Network setting", 0, NULL);
	menu_add("Show", root, mn_show_network);
	menu_add("Static Set", root, mn_set_network);
	menu_add("Loopback", 0, mn_loopback);
	menu_add("LED Test", 0, mn_set_led);
	root = menu_add("App Test", 0, NULL);
	menu_add("DNS", root, mn_dns);
	menu_add("BASE64", root, mn_base64);
	menu_add("eMail", root, mn_email);

	menu_print_tree();

	dhcp_tick = led_tick = wizpf_get_systick();

	while(1) {
		if(wizpf_tick_elapse(dhcp_tick) > dhcp_time) {
			if(dhcp_time==dhcp_renew) DBG("start renew"); else DBG("start rebind");
			ret = dhcp_manual(dhcp_time==dhcp_renew? DHCP_ACT_RENEW: DHCP_ACT_REBIND, 
				NULL, &dhcp_renew, &dhcp_rebind);
			dhcp_tick = wizpf_get_systick();
			if(ret == RET_OK) {	// renew success
				dhcp_renew = wizpf_tick_conv(FALSE, dhcp_renew);
				dhcp_rebind = wizpf_tick_conv(FALSE, dhcp_rebind);
				dhcp_time = dhcp_renew;
			} else {
				if(dhcp_time == dhcp_renew) dhcp_time = dhcp_rebind; // renew fail, so try rebind
				else dhcp_time = 60000; // retry after 1 min
			}
		}
		menu_run();
		if(lb_tcp) loopback_tcps(7, (uint16)TCP_LISTEN_PORT);
		if(lb_udp) loopback_udp(7, (uint16)UDP_LISTEN_PORT);
		if(wizpf_tick_elapse(led_tick) > 1000) {
			wizpf_led_set(WIZ_LED3, VAL_TOG);
			led_tick = wizpf_get_systick();
		}
	}

FAIL_TRAP:
	wizpf_led_trap(1);
	return 0;
}