Пример #1
0
int main(int argc, char* argv[])
{
	int ret;

	RCC_Configuration();
	
	LED_Init(LED1);
	LED_Init(LED2);
	
	LED_On(LED1);
	LED_Off(LED2);

	BOOT_Pin_Init();

	USART1_Configuration();

#if defined(MULTIFLASH_ENABLE)
	probe_flash();
#endif

	/* Load Configure Infomation */
	load_S2E_Packet_from_storage();

	/* Check MAC Address */
	check_mac_address();

	W5500_SPI_Init();
	W5500_Init();
	Timer_Configuration();

	Net_Conf();
	TFTP_init(SOCK_TFTP, socket_buf);

	ret = application_update();

	if((get_bootpin_Status() == 0) && (ret != TFTP_FAIL)) {
		uint32_t tmp;

#if !defined(MULTIFLASH_ENABLE)
		tmp = *(volatile uint32_t *)APP_BASE;
#else
		tmp = *(volatile uint32_t *)flash.flash_app_base;
#endif

		if((tmp & 0xffffffff) != 0xffffffff) {
			application_jump();
		}
	}

	while (1) {
		do_udp_config(SOCK_CONFIG);
	}
}
Пример #2
0
int main(void) {

#if defined (__USE_LPCOPEN)
#if !defined(NO_BOARD_LIB)
    // Read clock settings and update SystemCoreClock variable
    SystemCoreClockUpdate();
    // Set up and initialize all required blocks and
    // functions related to the board hardware
    Board_Init();
    // Set the LED to the state of "On"
    Board_LED_Set(0, true);
#endif
#endif
    uint8_t ip[4] = {0,};
    uint8_t gw[4] = {0,};
    uint8_t sn[4] = {0,};
    uint8_t dns[4] = {0,};

    SPI_Init();
    W5500_Init();
    //Net_Conf();

//    if ( SOCK_TCPS0 == socket(SOCK_TCPS1,Sn_MR_UDP,DHCP_CLIENT_PORT,0) ){
//    	printf("%d Socket open\n\r", SOCK_TCPS1);
//    }

    DHCP_init(SOCK_TCPS0, gDATABUF);
    while (DHCP_run() != DHCP_IP_LEASED)	printf("."),delay_cnt(10000);
    printf("\r\n");
    Board_LED_Set(0, false);
    Board_LED_Set(1, true);
    getIPfromDHCP(ip);
    getGWfromDHCP(gw);
	getSNfromDHCP(sn);
	getDNSfromDHCP(dns);

	printf("< DHCP IP Leased!! >\r\n");
	//printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n", DHCP_CHADDR[0], DHCP_CHADDR[1], DHCP_CHADDR[2],  DHCP_CHADDR[3], DHCP_CHADDR[4], DHCP_CHADDR[0]);
	printf("IP	: %3d.%3d.%3d.%3d\r\n", ip[0], ip[1], ip[2], ip[3]);
	printf("GW	: %3d.%3d.%3d.%3d\r\n", gw[0], gw[1], gw[2], gw[3]);
	printf("SN	: %3d.%3d.%3d.%3d\r\n", sn[0], sn[1], sn[2], sn[3]);
	printf("DNS	: %3d.%3d.%3d.%3d\r\n", dns[0], dns[1], dns[2], dns[3]);
	DHCP_stop();

	DNS_Query();
    while(1) {

    }
    return 0 ;
}
Пример #3
0
/**
 * @brief    Main routine for W5500 EVB firmware
 * @return   Function should not exit.
 */
int main(void) {

#if defined (__USE_LPCOPEN)
#if !defined(NO_BOARD_LIB)
    // Read clock settings and update SystemCoreClock variable
    SystemCoreClockUpdate();
    // Set up and initialize all required blocks and
    // functions related to the board hardware
    Board_Init();
#endif
#endif

    bool run_user_applications = false;
    int32_t ret;

    /* Network Initialization */
	SPI_Init();
	W5500_Init();
	Net_Conf();

	/* Enable and setup SysTick Timer at a periodic rate */
	SysTick_Config(SystemCoreClock / TICKRATE_HZ1);

	/* Enable and setup 32-bit Timer 0 */
	Timer32_0_Init(TICKRATE_HZ2);

	/* PHY Status check enable */
	PHYStatus_check_enable = true;

#ifdef _MAIN_DEBUG_
	uint8_t tmpstr[6] = {0,};

	ctlwizchip(CW_GET_ID,(void*)tmpstr);

    printf("\r\n=======================================\r\n");
	printf(" WIZnet %s EVB - DHCP client v%d.%.2d\r\n", tmpstr, VER_H, VER_L);
	printf("=======================================\r\n");

	//Display_Net_Conf(); // handled by dhcp_run function
#endif

	/* DHCP client Initialization */
	if(gWIZNETINFO.dhcp == NETINFO_DHCP)
	{
		DHCP_init(SOCK_DHCP, gDATABUF);
		// if you want different action instead default ip assign, update, conflict.
		// if cbfunc == 0, act as default.
		reg_dhcp_cbfunc(my_ip_assign, my_ip_assign, my_ip_conflict);

		run_user_applications = false; 	// flag for running user's code
	}
	else
	{
		// Static
#ifdef _MAIN_DEBUG_
		Display_Net_Conf();
#endif
		run_user_applications = true; 	// flag for running user's code
	}

	/* Main loop ***************************************/
	while(1)
	{
	   	/* PHY Status checker: Check every 'SEC_PHYSTATUS_CHECK' seconds */
		if(PHYStatus_check_flag)
		{
			PHYStatus_check_flag = false;
			PHYStatus_Check();
		}

    	/* DHCP */
		/* DHCP IP allocation and check the DHCP lease time (for IP renewal) */
    	if(gWIZNETINFO.dhcp == NETINFO_DHCP)
    	{
			switch(DHCP_run())
			{
				case DHCP_IP_ASSIGN:
				case DHCP_IP_CHANGED:
					/* If this block empty, act with default_ip_assign & default_ip_update */
					//
					// This example calls my_ip_assign in the two case.
					//
					// Add to ...
					//
					break;
				case DHCP_IP_LEASED:
					//
					// TODO: insert user's code here
					run_user_applications = true;
					//
					break;
				case DHCP_FAILED:
					/* ===== Example pseudo code =====  */
					// The below code can be replaced your code or omitted.
					// if omitted, retry to process DHCP
					my_dhcp_retry++;
					if(my_dhcp_retry > MY_MAX_DHCP_RETRY)
					{
						gWIZNETINFO.dhcp = NETINFO_STATIC;
						DHCP_stop();      // if restart, recall DHCP_init()
#ifdef _MAIN_DEBUG_
						printf(">> DHCP %d Failed\r\n", my_dhcp_retry);
						Net_Conf();
						Display_Net_Conf();   // print out static netinfo to serial
#endif
						my_dhcp_retry = 0;
					}
					break;
				default:
					break;
			}
    	}

    	// TODO: insert user's code here
    	if(run_user_applications)
    	{
    		// Loopback test : TCP Server
    		if ((ret = loopback_tcps(SOCK_TCPS, gDATABUF, PORT_TCPS)) < 0) // TCP server loopback test
    		{
#ifdef _MAIN_DEBUG_
    			printf("SOCKET ERROR : %ld\r\n", ret);
#endif
    		}

    		;
    	} // End of user's code
	} // End of Main loop

    return 0;
}
Пример #4
0
int main(void){
	
	sysInit();
	
	SPCR = (1 << SPE)  | (1 << MSTR) | (0 << CPOL) | (0 << CPHA) | (0 << SPR1);
	SPSR = (1<<SPI2X);
	W5500_Init();
	
	_delay_ms(10);
	sprintf(gPtrintBuff, "Version: %u\n",getVERSIONR());
	uartPuts(gPtrintBuff);
	//i2cScanner();
	
	si70xx_init();
	
	uartPutsP("\nInto Loop\n");
	
    while (1){
		
		if(milis() - loopTime >= 50){
			
			hsv2rgb(hue_value,255,80, &Rpwm, &Gpwm, &Bpwm, 250);			
			OCR1A = Rpwm;
			OCR1B = Gpwm;
			OCR1C = Bpwm;
			hue_value++;
			if(hue_value > 359){
				hue_value = 0;
			}
			
			float temperature = si70xx_get_temperature();
			float humidity = si70xx_get_humidity();
			
			/*
			while(getSn_SR(SOCK_ID_TCP) != SOCK_ESTABLISHED){
				loopback_tcpc(SOCK_ID_TCP, dIP, dport);
			}
			*/
			
			sprintf(gDATABUF, "%u | Temp: %.2f RH: %.2f \n\0", i , temperature, humidity);
			
			retVal = send(SOCK_ID_TCP, gDATABUF, sizeof(gDATABUF));
			//close(SOCK_ID_TCP);
			
			sprintf(gPtrintBuff, "%u | Sent: %i Sizeof: %u\n", i ,  retVal, sizeof(gDATABUF));
			uartPuts(gPtrintBuff);
			
			i++;
			
			loopTime = milis();
			
		}
		
		
		loopback_tcpc(SOCK_ID_TCP, dIP, dport);
		//send(TCP_)
		char temp = uartGetc();
		if(temp == 'S'){
			printNetInfo();
			//uartPutc(temp);
		}
		
		if(temp == 's'){
			send(SOCK_ID_TCP, 'a', sizeof('a'));
			//uartPutc(temp);
		}
    }
}
Пример #5
0
int main(void) {
	uint8_t ret = 0;
    //int32_t loopback_ret;

#if defined (__USE_LPCOPEN)
#if !defined(NO_BOARD_LIB)
    // Read clock settings and update SystemCoreClock variable
    SystemCoreClockUpdate();
    // Set up and initialize all required blocks and
    // functions related to the board hardware
    Board_Init();
    // Set the LED to the state of "On"
    Board_LED_Set(0, true);
    //Board_LED_Set(1, true);
    //Board_LED_Set(2, true);
#endif
#endif

	SPI_Init();
	W5500_Init();
	Net_Conf(gWIZNETINFO);

#ifdef _MAIN_DEBUG_
	uint8_t tmpstr[6] = {0,};

	ctlwizchip(CW_GET_ID,(void*)tmpstr);
/*
    printf("\r\n=======================================\r\n");
	printf(" WIZnet %s EVB Demos v%d.%.2d\r\n", tmpstr, VER_H, VER_L);
	printf("=======================================\r\n");
	printf(">> W5500 based FTP Client Example\r\n");
	printf("=======================================\r\n");
*/
	Display_Net_Conf(); // Print out the network information to serial terminal
#endif

	/* Enable and setup SysTick Timer at a periodic rate */
	SysTick_Config(SystemCoreClock / TICKRATE_HZ1);

	/* Initialize buttons on the W5500 EVB board */
	Board_Buttons_Init();

	g_sdcard_done = 0;

#if defined(F_APP_FTPC)
	ftpc_init(gWIZNETINFO.ip);
#endif

	ret = flash_mount();
	if(ret > 0)
	{
		display_SDcard_Info(ret);
	}

	while(1) {
	   	/* Button: SW1 */
		if(Check_Buttons_Pressed() == BUTTONS_BUTTON1)
		{
			printf("\r\n########## SW1 was pressed.\r\n");
			printf("########## Data flash flag was cleared.\r\n");
			printf("########## Please reset a target.\r\n");
			release_factory_flag();
		}

#if defined(F_APP_FTPC)
		ftpc_run(gFTPBUF);
#endif

		/* Loopback Test: TCP Server and UDP */
		// Test for Ethernet data transfer validation
		{
			//loopback_tcps(SOCK_TCPS, gDATABUF, PORT_TCPS);
			//loopback_udps(SOCK_UDPS, gDATABUF, PORT_UDPS);
			//loopback_ret = loopback_tcpc(SOCK_TCPS, gDATABUF, destip, destport);

			//if(loopback_ret < 0) printf("loopback ret: %ld\r\n", loopback_ret); // TCP Socket Error code
		}
	}

    return 0 ;
}