Пример #1
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  
  /* Setup STM32 system (clocks, Ethernet, GPIO, NVIC) and STM3210C-EVAL resources */
  System_Setup();
             
  /* Initilaize the LwIP satck */
  LwIP_Init();
  
  /* Initilaize the HelloWorld module */
  HelloWorld_init();

  /* Initilaize the webserver module */
  httpd_init();

  /* Initialize the TFTP server */
  tftpd_init();

  /* Infinite loop */
  while (1)
  {    
	/* Periodic tasks */
	System_Periodic_Handle();
  }
}
Пример #2
0
void sdcallback(enum sd_event event)
{
	uint8_t ret;
	DBG_INFO("[sd]: ");
	switch(event)
	{
		case sd_event_inserted:
			printf("card inserted\n");
			break;
		case sd_event_inserted_wp:
			printf("card inserted (WP!)\n");
			break;
		case sd_event_removed:
			printf("card removed\n");
			break;
		case sd_event_initialized:
			printf("card initialized\n");
			ret = partition_open(&partition,sd_read,0,0);
			fat_close(fatfs);
			fatfs = fat_open(&partition);
			fat_root = fat_get_dir_entry(fatfs, "/");
			tftpd_init(fat_root);
			//httpd_chroot(fat_root);
			break;
		case sd_event_error:
			DBG_ERROR("error %x\n",sd_errno());
			break;
		default:
			DBG_ERROR("unknown event\n");
			break;
	}
}
Пример #3
0
/*
 * Called on the lwip thread (aka tcpip thread) from tcpip_init() via
 * its "tcpip_init_done" callback.  Raw API is ok to use here
 * (e.g. rtadvd), but netconn API is not.
 */
void
proxy_init(struct netif *proxy_netif, struct proxy_options *opts)
{
    int status;

    LWIP_ASSERT1(opts != NULL);
    LWIP_UNUSED_ARG(proxy_netif);

    status = RTStrFormatTypeRegister("sockerr", proxy_sockerr_rtstrfmt, NULL);
    AssertRC(status);

    g_proxy_options = opts;
    g_proxy_netif = proxy_netif;

#if 1
    proxy_rtadvd_start(proxy_netif);
#endif

    /*
     * XXX: We use stateless DHCPv6 only to report IPv6 address(es) of
     * nameserver(s).  Since we don't yet support IPv6 addresses in
     * HostDnsService, there's no point in running DHCPv6.
     */
#if 0
    dhcp6ds_init(proxy_netif);
#endif

    if (opts->tftp_root != NULL) {
        tftpd_init(proxy_netif, opts->tftp_root);
    }

    status = pollmgr_init();
    if (status < 0) {
        errx(EXIT_FAILURE, "failed to initialize poll manager");
        /* NOTREACHED */
    }

    pxtcp_init();
    pxudp_init();

    portfwd_init();

    pxdns_init(proxy_netif);

    pxping_init(proxy_netif, opts->icmpsock4, opts->icmpsock6);

    pollmgr_tid = sys_thread_new("pollmgr_thread",
                                 pollmgr_thread, NULL,
                                 DEFAULT_THREAD_STACKSIZE,
                                 DEFAULT_THREAD_PRIO);
    if (!pollmgr_tid) {
        errx(EXIT_FAILURE, "failed to create poll manager thread");
        /* NOTREACHED */
    }
}
Пример #4
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();

  /* Configure the system clock to 168 MHz */
  SystemClock_Config();

  /* Configure the BSP */
  BSP_Config();

  /* Initialize the LwIP stack */
  lwip_init();

  /* Configure the Network interface */
  Netif_Config();

  /* Initialize the TFTP server */
  tftpd_init();

  /* Notify user about the network interface config */
  User_notification(&gnetif);

  /* Link the SD Card disk I/O driver */
  FATFS_LinkDriver(&SD_Driver, SD_Path);

  /* Infinite loop */
  while (1)
  {
    /* Read a received packet from the Ethernet buffers and send it
    to the lwIP for handling */
    ethernetif_input(&gnetif);

    /* Handle timeouts */
    sys_check_timeouts();

#ifdef USE_DHCP
    /* handle periodic timers for LwIP */
    DHCP_Periodic_Handle(&gnetif);
#endif
  }
}
Пример #5
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured to 
       120 MHz, this is done through SystemInit() function which is called from
       startup file (startup_stm32f2xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f2xx.c file
     */  
//add a long delay wait for DP83848 finish reset  
unsigned int i,j;
for(i=0;i<36;i++)
{
	for(j=0;j < 65500;j++);
}  
#ifdef SERIAL_DEBUG
  DebugComPort_Init();
#endif

  /* Initialize LCD and Leds */ 
  LCD_LED_Init();
  
  /* Configure ethernet (GPIOs, clocks, MAC, DMA) */ 
  ETH_BSP_Config();
    
  /* Initilaize the LwIP stack */
  LwIP_Init();
      
  /* TFTP server Init */
  tftpd_init();
    
  /* Infinite loop */
  while (1)
  {  
    /* check if any packet received */
    if (ETH_CheckFrameReceived())
    { 
      /* process received ethernet packet */
      LwIP_Pkt_Handle();
    }
    /* handle periodic timers for LwIP */
    LwIP_Periodic_Handle(LocalTime);
  }   
}
Пример #6
0
/*------------------------------------------------------------------------------------------------*/
void Ethernet_Init(Bool_e UseConfIni)
{
	Ethernet_t TmpThis;
	Status_e ReadStatus;


	_CONSOLE(LogId, "---------- CONF_ETHERNET INIT ----------\n");

	//------------------------------------------------------
	// Lecture des donnees flash
	//------------------------------------------------------
	DatabaseEeprom_InitData(DatabaseEeprom_Ethernet, NULL, sizeof(Ethernet_t));
	ReadStatus = DatabaseEeprom_Read(DatabaseEeprom_Ethernet, &TmpThis);
	DatabaseEeprom_Display(DatabaseEeprom_Ethernet, &TmpThis);
	if (ReadStatus == Status_KO)
	{
		_CONSOLE(LogId, "Invalid Eeprom Read: Default restored\n");
		DatabaseEeprom_Write(DatabaseEeprom_Ethernet, &This);
		memcpy(&TmpThis, &This, sizeof(Ethernet_t));
		This.Cfg_Restored 	= TRUE;
	}
	else
	{
		_CONSOLE(LogId, "Valid Eeprom Read \n");
		memcpy(&This, &TmpThis, sizeof(Ethernet_t));
		This.Cfg_Restored = FALSE;
	}

	//------------------------------------------------------
	// Comparaison avec fichier ini
	//------------------------------------------------------
	if ((ConfIni_Get()->IsValide == TRUE) && (UseConfIni == TRUE))
	{
		_CONSOLE(LogId, "Check SD cfg\n");

		memcpy(This.Cfg_IP_Adresse,		ConfIni_Get()->ETH_IP_Adresse, 4);
		memcpy(This.Cfg_IP_Masque,		ConfIni_Get()->ETH_IP_Masque, 4);
		memcpy(This.Cfg_IP_Passerelle,	ConfIni_Get()->ETH_IP_Passerelle, 4);
		memcpy(This.Cfg_MAC_Adresse,	ConfIni_Get()->ETH_MAC_Adresse, 6);
		This.Cfg_DHCP_Actif = ConfIni_Get()->ETH_DHCP_Actif;

		if (memcmp(&TmpThis, &This, sizeof(Ethernet_t)) != 0)
		{
			_CONSOLE(LogId, "Cfg SD copied\n");
			DatabaseEeprom_Write(DatabaseEeprom_Ethernet, &This);
		}
		else
		{
			_CONSOLE(LogId, "Cfg unchanged\n");
		}
	}


	//------------------------------------------------------
	// Affichage de la configuration
	//------------------------------------------------------
	_CONSOLE(LogId, "IP_Adresse    = %d.%d.%d.%d\n",		This.Cfg_IP_Adresse[0], This.Cfg_IP_Adresse[1], This.Cfg_IP_Adresse[2], This.Cfg_IP_Adresse[3]);
	_CONSOLE(LogId, "IP_Masque     = %d.%d.%d.%d\n",		This.Cfg_IP_Masque[0], This.Cfg_IP_Masque[1], This.Cfg_IP_Masque[2], This.Cfg_IP_Masque[3]);
	_CONSOLE(LogId, "IP_Passerelle = %d.%d.%d.%d\n", 		This.Cfg_IP_Passerelle[0], This.Cfg_IP_Passerelle[1], This.Cfg_IP_Passerelle[2], This.Cfg_IP_Passerelle[3]);
	_CONSOLE(LogId, "MAC_Adresse   = %d:%d:%d:%d:%d:%d\n",	This.Cfg_MAC_Adresse[0], This.Cfg_MAC_Adresse[1], This.Cfg_MAC_Adresse[2], This.Cfg_MAC_Adresse[3], This.Cfg_MAC_Adresse[4], This.Cfg_MAC_Adresse[5]);
	_CONSOLE(LogId, "DHCP_Actif    = %d\n",					This.Cfg_DHCP_Actif		);


	//------------------------------------------------------
	// Application de la configuration
	//------------------------------------------------------

	ETH_BSP_Config();	// Configure ethernet (GPIOs, clocks, MAC, DMA)
	LwIP_Init(This.Cfg_IP_Adresse, This.Cfg_IP_Masque, This.Cfg_IP_Passerelle, This.Cfg_DHCP_Actif, This.Cfg_MAC_Adresse);		// Initilaize the LwIP stack
	tftpd_init();		// TFTP server Init
	//httpd_init();		// Http webserver Init
	Telnet_Init();
}
Пример #7
0
int main(int argc, char** argv)
{
	int rc;
	pid_t pid;
	
	//注册信号
	(void)signal(TFTP_SIGNAL, Tftp_Sig);
	
	//初始化缓存队列
	queue_init(&coapMsgQ, free);
	
	//初始化信号量,初始值为0
	rc = sem_init(&msgQSem, 0, 0);
	if(rc == -1)
	{
		printf("init msgQSem error!\r\n");
		exit(-1);
	}
	
	//初始化互斥量
	rc = pthread_mutex_init(&msgQ_mutex, NULL);
	if(rc != 0)
	{
		printf("msgQ_mutex init error!\r\n");
		exit(-1);
	}
	
	
	//打开数据库
	Open_db("CoapMsg.db", &db);
	
	rc = zlog_init("log.conf");
	if (rc) 
	{
		printf("init failed\n");
		return -1;
	}

	zc = zlog_get_category("my_cat");
	if (!zc) 
	{
		printf("get cat fail\n");
		zlog_fini();
		return -2;
	}
	
	zlog_info(zc, "Start!");

	zlog_info(zc, "Uart_Init!");
	//初始化串口
	Uart_Init(115200);

	//创建串口读取数据线程
	rc = pthread_create(&uartRd_Thread, NULL, Uart_ReadThread, NULL);
	if(0!=rc)
	{
		zlog_error(zc, "uartRd_Thread create error!");
		exit(-1);
	}
	else
	{
		zlog_debug(zc, "uartRd_Thread create success!");
	}
	
	//创建分发数据线程
	rc = pthread_create(&transMsg_Thread, NULL, TransMsgThread, NULL);
	if(0!=rc)
	{
		zlog_error(zc, "TransMsgThread create error!");
		exit(-1);
	}
	else
	{
		zlog_debug(zc, "TransMsgThread create success!");
	}
	
	//初始化链表
	list_init( &iplist, free);
	zlog_debug(zc, "list_init success!");
	
	//创建tftp Server进程
	pid = fork();
	if(pid == 0)
	{
		printf("enter tftp server,pid = %d\r\n", getpid());
		zlog_debug(zc, "enter tftp server,pid = %d", getpid());
		tftpd_init(NULL);
	}
	else if(pid<0)
	{
		printf("create tftp server process error!\r\n");
		zlog_error(zc, "create tftp server process error!");
	}
	else if(pid > 0)
	{
		//记录tftp子进程的pid
		tftp_pid = pid;
	}
	
	//创建coapclient任务
	CreatCoapclient(&iplist);
	
	//创建coap Server进程
	pid = fork();
	if(pid == 0)
	{
		printf("enter coap server,pid = %d\r\n", getpid());
		zlog_debug(zc, "enter coap server,pid = %d", getpid());
		CoapServ(NULL);
	}
	else if(pid<0)
	{
		printf("create coap server process error!\r\n");
		zlog_error(zc, "create coap server process error!");
	}
	else if(pid > 0)
	{
		//记录coap server子进程的pid
		coap_serv_pid = pid;
	}
	
	while(1)
	{
		sleep(1);
	}

	return 0;
}