示例#1
0
void main()
{

    RCC_ClocksTypeDef RCC_Clocks;

    RCC_GetClocksFreq(&RCC_Clocks);

    SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);

    LED_Config();
    LWIP_Config();
    UDP_Config();
    CAN_Config();
    TIM7_Config(PERIOD);

    while(1)
    {
        if(ETH_CheckFrameReceived())
        {
            LwIP_Pkt_Handle();
        }

        LwIP_Periodic_Handle(LocalTime);

        if(rew_status != 0) ReSendUdpData();
    }

}
示例#2
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured to 
       168 MHz, this is done through SystemInit() function which is called from
       startup file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */  

#ifdef SERIAL_DEBUG
  DebugComPort_Init();
#endif
  
  /*Initialize LCD and Leds */ 
  LCD_LED_BUTTON_Init();
  
  /* Configure ethernet (GPIOs, clocks, MAC, DMA) */ 
  ETH_BSP_Config();
    
  /* Initilaize the LwIP stack */
  LwIP_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);
  }   
}
示例#3
0
int main(void) {
    int temp = 5;
    //configures the priority grouping
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);
    //start time
    start_timer();
    //configure spi
    SPI_Config();
    //ETHERNET INITIALIZATION
    ETH_BSP_Config();
    /* Initilaize the LwIP stack */
    LwIP_Init();
    //udp initialization
    if (!udp_echoserver_init())
        return 1;
    while (1)
    {
        //PROCESSING OF PEREODIC TIMERS FOR LWIP
        LwIP_Periodic_Handle(gettime());
        //PROCESSING OF INCOMING PACKET
        if (ETH_CheckFrameReceived())
        {
            /* process received ethernet packet */
            LwIP_Pkt_Handle();
        }
        trans_Control((void*)&temp, sizeof(temp));
    }
}
示例#4
0
static void program_loop(void) {
	/* Infinite loop */
	while (1) {
		/* Service the inputs/outputs */
		ServiceTasks();

		/* Check if any packet received */
		if (ETH_CheckFrameReceived()) {
			/* Process received ethernet packet */
			LwIP_Pkt_Handle();
		}

		/* Handle periodic timers for LwIP */
		LwIP_Periodic_Handle(GetLocalTime());

		if (TelnetIsConnected() == true) { /* We have an active Telnet connection to service */
			/* Do server stuff */
			character = TelnetRead();
			if (character != '\0') {
				Command_AddChar(character);
			}
		}

		/* Check to see if any faults have occurred */
		Tekdaqc_CheckStatus();

		/* Reload the IWDG Counter to prevent reset */
		IWDG_ReloadCounter();
	}
}
示例#5
0
int main(void) {
	struct b_pool* pbuf;
	struct head* h;
	init_pools_buffers();
	//configure NVIC
	NVIC_Configuration();
	//start time
	start_timer();
	//configure adc
	ADC_config();
	//configure pwm
	pwm_Config();
	//ETHERNET INITIALIZATION
	ETH_BSP_Config();
	/* Initilaize the LwIP stack */
  LwIP_Init();
	//enable clock
	/*__disable_irq();
	clockHseInit();
	__enable_irq();*/
	/*Initilaize the PTP stack*/
	PTPd_Init();
	//udp initialization
	udp_echoserver_init();
	//configure state
	//init_current_state(&cur);
	cur.status = STOP;
	cur.id_sig = 0;
  while (1)
  {  
    //PROCESSING OF PEREODIC TASKS FOR LWIP
    LwIP_Periodic_Handle(gettime());
		//PROCESSING OF PEREODIC TASKS FOR PTP
		ptpd_Periodic_Handle(gettime());
		//PROCESSING OF QUEUING BUFFERS
		pbuf = pull_out_queue();
		if(pbuf != NULL) {
			h = (struct head*)pbuf->pbuf;
			if(h->dst & SLAVE) {
				if(h->type == COMMAND)
					handl_command(pbuf);
			} else
				transPackage(pbuf, eth_write);
			free_buf(pbuf);
		}
		//PROCESSING OF DEBUG_INFO
		if(debug.time > 0) {
			if(debug.num == -1 || debug.num > 0)  {
				debug_info();
			}
			else
				debug.time = 0;
			if (debug.num > 0)
				debug.num --;
		}
		//PROCESSING OF TEMP BUFFER
		
  }   
}
示例#6
0
int main(void)
{
  SystemInit();						// initialize MCU clocks and registers
  TM_DELAY_Init();					// initialize Delay library
  TM_DELAY_SetTime(0);				// Reset couter for systime
  Laser_GPIO_Conf();				// configure GPIO for laser control (to be able to enable/disable lasers via software
  TM_BKPSRAM_Init();				// initialize BKP RAM access library
  Laser_Update();			// load laser statuses saved in BKP RAM
  TM_USART_Init(OUTPUT_USART, OUTPUT_USART_PINS, OUTPUT_USART_SPEED);		// initialize UART used for collected Data output
  TM_USART_Init(MENU_USART, MENU_USART_PINS, MENU_USART_SPEED);				// initialize UART used for configuration
  TM_RTC_Init(TM_RTC_ClockSource_External);									// initialize RTC library
  TM_GPIO_Init(GPIOD, GPIO_Pin_8, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low); // configure GPIO for GSM status indication (RED LED)
  TM_GPIO_Init(GPIOD, GPIO_Pin_9, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low); // configure GPIO for GSM status indication (GREEN LED)
  Laser_ADC_Init();					// initialize ADC peripherals
  Menu_Init();						// initialize CLI library
  sfpInit();						// configure GPIO for SFP modules
  gsm_Init();						// initialize GSM module


  /* configure and initialize Ethernet hardware and LwIP stack */

  ETH_BSP_Config();					// configure ETH GPIOs
  printf("Ethernet MAC and PHY configured successfully!\n");
  LwIP_Init();						// start LwIP stack
  printf("LwIP stack initialized successfully!\n");
  UDP_Server_Init();				// start UDP Server
  printf("UDP Server initialized successfully!\n");

  //start periodic tasks

  /* GSM Status update "task" */
  GSM_Status_Update_Timer = TM_DELAY_TimerCreate(GSM_CHECK_INTERVAL, 1, 1, GSM_Status_Update_Timer_Task, NULL);
  printf("GSM status check task created!\n");
  /* Print results from remote devices "task" */
  Print_Results_Timer = TM_DELAY_TimerCreate(DATA_OUT_INTERVAL, 1, 1, Print_Results_Timer_Task, NULL);
  printf("Print collected data task created!\n");
  /* LaserLock status update "task" */
  LaserLock_Timer = TM_DELAY_TimerCreate(1000, 1, 1, LaserLock_Timer_Task, NULL);
  printf("Laser lock check task created!\n");

  while (1) {
	  /* CLI menu update */
	  Menu_Update();
      /* check if any packet received */
	  if (ETH_CheckFrameReceived())
	  {
		  /* process received ethernet packet */
		  LwIP_Pkt_Handle();
	  }
    /* handle periodic timers for LwIP */
    LwIP_Periodic_Handle(LocalTime);
    /* update laser statuses */
    Laser_Update();
    /* remove SMS messages which were read by system */
    delete_read_gsm_messages();
  }
} 
/**
  * @brief  Handles the periodic tasks of the system
  * @param  None
  * @retval None
  */
void System_Periodic_Handle(void)
{
  /* Update the LCD display and the LEDs status */
  /* Manage the IP address setting */
  Display_Periodic_Handle(LocalTime);
  
  /* LwIP periodic services are done here */
  LwIP_Periodic_Handle(LocalTime);
}
/*------------------------------------------------------------
 * Function Name  : UDP_Update
 * Description    : UDPÉý¼¶
 * Input          : None
 * Output         : None
 * Return         : None
 *------------------------------------------------------------*/
ErrorStatus UDP_Update( void )
{	
	char version[50];
	
	lcd_clear(COLOR_BACK);
	
	lcd_font24(udp_lcd_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,"========================================",UPDATE_FONT);
	udp_lcd_y += UPDATE_WORD_SIZE + UPDATE_ROW_DISTANCE;
	lcd_font24(udp_lcd_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,"         > »¶Ó­Ê¹ÓÃÒÔÌ«ÍøÉý¼¶ÏµÍ³ <",UPDATE_FONT);
	udp_lcd_y += UPDATE_WORD_SIZE + UPDATE_ROW_DISTANCE;
	strcpy(version,"         > ");
	strcat(version,SOFT_VERSION);
	lcd_font24(udp_lcd_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,version,UPDATE_FONT);
	udp_lcd_y += UPDATE_WORD_SIZE + UPDATE_ROW_DISTANCE;
	lcd_font24(udp_lcd_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,"========================================",UPDATE_FONT);
	udp_lcd_y += UPDATE_WORD_SIZE + UPDATE_ROW_DISTANCE;
	lcd_font24(udp_lcd_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,"> ÕýÔÚ³¢ÊÔÁ¬½ÓµçÄÔ...",UPDATE_FONT);
	udp_lcd_y += UPDATE_WORD_SIZE + UPDATE_ROW_DISTANCE;
	
	#ifdef USE_IAP_HTTP
		/* Initialize the webserver module */
		IAP_httpd_init();
	#endif

	#ifdef USE_IAP_TFTP    
		/* Initialize the TFTP server */
		IAP_tftpd_init();
	#endif 
	
	while (1)
	{
		if (GetEthLinkStatus() == YES)
		{
			lcd_font24(udp_lcd_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,"> Á¬½ÓµçÄԳɹ¦¡£Çëµã»÷µçÄÔ¶Ë Put °´Å¥£¬Íê³ÉÉý¼¶£¡",UPDATE_FONT);
			udp_lcd_y += UPDATE_WORD_SIZE + UPDATE_ROW_DISTANCE;			
			break;
		}
	}
	
	while (1)
	{
		if (uPdateFinish == YES)
		{
			lcd_font24(udp_lcd_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,"> Éý¼¶³É¹¦£¡",UPDATE_FONT);
			udp_lcd_y += UPDATE_WORD_SIZE + UPDATE_ROW_DISTANCE;
	
			AutoEnterSystemCue(udp_lcd_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,UPDATE_FONT);
			break;
		}
		
		/* ÒÔÌ«ÍøÑ­»·ÈÎÎñ */
		LwIP_Periodic_Handle(bsp_GetRunTime());
	}
	
	return SUCCESS;
}
示例#9
0
文件: Ethernet.c 项目: jdaheron/GHB
/*------------------------------------------------------------------------------------------------*/
void Ethernet_Management(void)
{
	/* check if any packet received */
	if (ETH_CheckFrameReceived())
	{
		/* process received ethernet packet */
		LwIP_Pkt_Handle();
	}

	/* handle periodic timers for LwIP */
	LwIP_Periodic_Handle(TSW_GetTimestamp_ms());
}
示例#10
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{

	SystemInit();
	init_systick();

#ifdef SERIAL_DEBUG
  DebugComPort_Init();  
#endif
  printf(" Artnet2WS2811 Receiver\r\n ");
  /*Initialize LCD and Leds */ 
  LED_Init();
  
  /* configure ethernet (GPIOs, clocks, MAC, DMA) */ 
  ETH_BSP_Config();
    
  /* Initilaize the LwIP stack */
  LwIP_Init();
  
  /* tcp echo server Init */
  //tcp_echoserver_init();
  telnetserver_init();
  //artnet_init();

  ws2812_init();
  /* Initialize variables for ws2812 */

	delay_ms(20);




  /* 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(system_time);

    DRAW_LED();
  }   
}
示例#11
0
int main(void)
{
	
	SystemInit();
	
	SSD1963_Init();

	SSD1963_Clear(Red);
	Delay(100);
	SSD1963_Clear(Blue);
	Delay(100);
	SSD1963_Clear(Red);
	SSD1963_Fill(0, 0, 50, 50, Blue);
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC, ENABLE);
	GUI_Init();
	GUI_SetColor(GUI_RED);
	GUI_Clear();
	
	BSP_KeyInit( BSP_KEY1, BSP_KEY1_GPIO_PORT );

	BSP_USART_Init( );
	
	BSP_SPI_Init( );
	BSP_SPI_CS_Init( );
	
	//Debug_ShowRegister( GPIOA_BASE, (DebugPeripheralTypedef *)&DeBugGPIO );
	//Debug_ShowRegister( BSP_USARTx_BASE, (DebugPeripheralTypedef *)&DeBugUART );
	//Debug_ShowRegister( RCC_BASE, (DebugPeripheralTypedef *)&DeBugRCC );
	//Debug_ShowSpecificRegister( RCC_BASE, (DebugPeripheralTypedef *)&DeBugRCC, "APB2ENR" );
	
  /* 初始化LWIP协议栈*/
	LwIP_Init(); 

	/*初始化web server 显示网页程序*/
	httpd_init();
  
  /* 初始化telnet   远程控制 程序 */   
  CMD_init();                                       

  /* Infinite loop */
  while ( 1 )
	{	
		/*轮询*/  
		LwIP_Periodic_Handle(LocalTime);		          	  
  }

}
示例#12
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);
  }   
}
示例#13
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */   
 
    BspInit();

    /* Infinite loop */
    while ( 1 )
    {	
        /*ÂÖѯ*/  
        LwIP_Periodic_Handle(LocalTime);		          	  
    }
          
    //return 0;

}
示例#14
0
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
  this i
  s done through SystemInit() function which is called from startup
  file (startup_stm32f10x_xx.s) before to branch to application main.
  To reconfigure the default setting of SystemInit() function, refer to
  system_stm32f10x.c file
  */     
  //GPIO_InitTypeDef GPIO_InitStructure;
  //uint32_t irq; //test IRQ
  
  
  /* System clocks configuration ---------------------------------------------*/
  SystemInit();
  RCC_Configuration();
  
  /* GPIO configuration ------------------------------------------------------*/
  GPIO_Configuration();
  GPIO_WriteBit(CANTX_LED,  Bit_SET);
  GPIO_WriteBit(CANRX_LED,  Bit_SET);
  GPIO_WriteBit(COMTX_LED,  Bit_SET);
  GPIO_WriteBit(COMRX_LED,  Bit_SET);
  GPIO_WriteBit(PWR_LED,  Bit_RESET);
  GPIO_WriteBit(ALARM_LED,  Bit_SET);
  GPIO_WriteBit(RUNSTAT_LED,  Bit_SET);

  GPIO_WriteBit(ETH_RESET,  Bit_RESET);//拉低DM9000 nRST, 延时复位启动
  
  DataBase_Init(DevIPAddressTab);
  
#ifndef TEST  
  /* com1 configuration ------------------------------------------------------*/
  COM1_Configuration();
#ifdef TEST_PARTS  
  GPIO_WriteBit(CANTX_LED,  Bit_RESET);
  GPIO_WriteBit(CANRX_LED,  Bit_SET);
  GPIO_WriteBit(COMTX_LED,  Bit_SET);
  GPIO_WriteBit(COMRX_LED,  Bit_SET);
#endif
  printf(" <<<<<<< COM1 config complete <<<<<<<\r\n\r\n");  
  
  
  /* com2 configuration ------------------------------------------------------*/
  //COM2_Configuration();
#endif 
  
  /* i2c configuration ------------------------------------------------------*/
  printf(" >>>>>>> I2C config begin >>>>>>>\r\n");
  I2C_Configuration();
#ifdef TEST_PARTS  
  GPIO_WriteBit(CANTX_LED,  Bit_SET);
  GPIO_WriteBit(CANRX_LED,  Bit_RESET);
  GPIO_WriteBit(COMTX_LED,  Bit_SET);
  GPIO_WriteBit(COMRX_LED,  Bit_SET); 
#endif 
  printf(" <<<<<<< I2C config complete <<<<<<<\r\n\r\n");
  
#ifndef TEST  
  /* RTC configuration--------------------------------------------------------*/
  printf(" >>>>>>> RTC config begin >>>>>>>\r\n");
  RTC_Configuration();
#ifdef TEST_PARTS  
  GPIO_WriteBit(CANTX_LED,  Bit_RESET);
  GPIO_WriteBit(CANRX_LED,  Bit_RESET);
  GPIO_WriteBit(COMTX_LED,  Bit_SET);
  GPIO_WriteBit(COMRX_LED,  Bit_SET);
#endif  
  printf(" <<<<<<< RTC config complete <<<<<<<\r\n\r\n");
#endif
  
#ifdef CAN_APP  
  /* can configuration ------------------------------------------------------*/
  printf(" >>>>>>> CAN config begin >>>>>>>\r\n");
  CAN_Configuration();
#ifdef TEST_PARTS  
  GPIO_WriteBit(CANTX_LED,  Bit_SET);
  GPIO_WriteBit(CANRX_LED,  Bit_SET);
  GPIO_WriteBit(COMTX_LED,  Bit_RESET);
  GPIO_WriteBit(COMRX_LED,  Bit_SET);
#endif  
  printf(" <<<<<<< CAN config complete <<<<<<<\r\n\r\n");  
#endif
  
#ifndef TEST  
  /*temperature configuration------------------------------------------------------*/
  printf(" >>>>>>> TEMPMEA config begin >>>>>>>\r\n");
  TEMPMEA_Confitguration();
#ifdef TEST_PARTS  
  GPIO_WriteBit(CANTX_LED,  Bit_SET);
  GPIO_WriteBit(CANRX_LED,  Bit_RESET);
  GPIO_WriteBit(COMTX_LED,  Bit_RESET);
  GPIO_WriteBit(COMRX_LED,  Bit_SET);
#endif 
  printf(" <<<<<<< TEMPMEA config complete <<<<<<<\r\n\r\n");
#endif
  
  /* SysTick configuration ------------------------------------------------------*/
  printf(" >>>>>>> SysTick config begin >>>>>>>\r\n");
  SysTick_Configuration();
#ifdef TEST_PARTS  
  GPIO_WriteBit(CANTX_LED,  Bit_RESET);
  GPIO_WriteBit(CANRX_LED,  Bit_RESET);
  GPIO_WriteBit(COMTX_LED,  Bit_RESET);
  GPIO_WriteBit(COMRX_LED,  Bit_SET);
#endif  
  printf(" <<<<<<< SysTick config complete <<<<<<<\r\n\r\n");

  /* NVIC configuration ------------------------------------------------------*/
  printf(" >>>>>>> NVIC config begin >>>>>>>\r\n");
  NVIC_Configuration();
#ifdef TEST_PARTS  
  GPIO_WriteBit(CANTX_LED,  Bit_SET);
  GPIO_WriteBit(CANRX_LED,  Bit_SET);
  GPIO_WriteBit(COMTX_LED,  Bit_SET);
  GPIO_WriteBit(COMRX_LED,  Bit_RESET);
#endif  
  printf(" <<<<<<< NVIC config complete <<<<<<<\r\n\r\n");
  
  /* Update the SysTick IRQ priority should be higher than the Ethernet IRQ */
  /* The Localtime should be updated during the Ethernet packets processing */
  NVIC_SetPriority (SysTick_IRQn, 1); 
  
  /* test IRQ*/
//  irq = NVIC_GetPriority(SysTick_IRQn);
//  irq = NVIC_GetPriority(ETH_IRQn);
//  irq = NVIC_GetPriority(I2C1_ER_IRQn);
//  irq = NVIC_GetPriority(I2C1_EV_IRQn);
  
  
  /* ethernet configuration ------------------------------------------------------*/
  //可添加延时, 用以确保DM9000启动时电压满足芯片要求
  //"nRST must not go high until after the VDDIO and VDD_CORE supplies are stable"  手册P51
  GPIO_WriteBit(ETH_RESET,  Bit_SET);   //拉高DM9000 nRST, 复位启动
  
  printf(" >>>>>>> ETH config begin >>>>>>>\r\n");
  Ethernet_Configuration();
#ifdef TEST_PARTS  
  GPIO_WriteBit(CANTX_LED,  Bit_RESET);
  GPIO_WriteBit(CANRX_LED,  Bit_SET);
  GPIO_WriteBit(COMTX_LED,  Bit_RESET);
  GPIO_WriteBit(COMRX_LED,  Bit_SET);
#endif  
  printf(" <<<<<<< ETH config complete <<<<<<<\r\n\r\n");  

    
#ifdef WATCHDOG
  /* WATCHDOG configuration ------------------------------------------------------*/
  IWDG_Configuration();
#endif
  
  //判断是否有以太网链接
  if(EthInitState)
  {
    CommunicationInit();
  }
  
  printf(" ******* 输入'$'将触发串口控制台!*******\r\n\r\n");
  GPIO_WriteBit(CANTX_LED,  Bit_SET);
  GPIO_WriteBit(CANRX_LED,  Bit_SET);
  GPIO_WriteBit(COMTX_LED,  Bit_SET);
  GPIO_WriteBit(COMRX_LED,  Bit_SET); 
  
  
  //启动完成, 进入常规流程
#ifdef _TEST  
  uint8_t test = 0;
#endif
  
  while (1)
  {
    Di_PostWork();
    LwIP_Periodic_Handle(LocalTime);
    Task_Periodic_Handle(LocalTime);
    

    //判断以太网状态, 决定是否要复位以太网
    EthStateCheck();
    
    reset_flag = Get_eth_reset_flag();
    if(reset_flag == Ethernet_SWRST_FLAG)
      Ethernet_SWRST();
    else if(reset_flag == Ethernet_HWRST_FLAG)
      Ethernet_HWRST();

#ifdef _TEST
    //tyh:20130407 eth reset test
    if((DiStatus_DI[1].Value != test)&&(DiStatus_DI[1].Value == 1))
    {
      //eth_reg = ETH_ReadPHYRegister(0x1F, 17);
      Ethernet_HWRST();
    }
    test = DiStatus_DI[1].Value;
#endif
    
//    else
//    {
//      if( EthLinkCheck() )
//      {
//        //tyh:20130403 send udp test_message
//        if((DiStatus_DI[1].Value != test)&&(DiStatus_DI[1].Value == 1))
//        {
//          Udp_timing_test();
//        }
//        
//        test = DiStatus_DI[1].Value;
//      }
//    }
    
#ifdef WATCHDOG 
    WDGFeeding();
#endif
    
  }
}
示例#15
0
int main(void)
{
	char s[] = "1442936700,0,1,4,#2346W,3,#0800O#1900C#0900O#1800C";  // for str_processing test
	
	
	RCC_ClocksTypeDef RCC_Clocks;

	/* SysTick end of count event each 10ms */
	RCC_GetClocksFreq(&RCC_Clocks);
	SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);
	RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
	RNG_Cmd(ENABLE);
	/* Initialize the timer for dht11 */
	tim_init(TIM2);
	/* Initialize the SRAM ****************************************************/
	PSRAM_Init();
	/* Initialize the LCD *****************************************************/
	LCD_Init();
	LCD_LOG_Init();
  LCD_LOG_SetHeader((uint8_t*)" Ethernet test");
	LCD_LOG_SetFooter ((uint8_t*)"     localtime: ");
	/* Add your application code here */
	/* Configure ethernet (GPIOs, clocks, MAC, DMA) */
	ETH_BSP_Config();
	/* Initilaize the LwIP stack */
	LwIP_Init();
	schedule_init(&schedule_got,schedule_string); // schedule string store in schedule_string
	DNS_Init();
	//while(!schedule_got); // wait until string got
	
	LCD_DisplayStringLine(Line2, (uint8_t*)schedule_string);
	LCD_DisplayStringLine(Line3, (uint8_t*)"0");
	/* Main Loop */
	
	//process ste str form internet

	Str_Split(s, Init_time);   // s is temp string

	RTC_Config();
	Time_Date_Setting(Init_time->year, Init_time->mon, Init_time->day, Init_time->hour +3, Init_time->min, Init_time->sec);
	
	
	
	
	while (1)
	{
		uint8_t year, mon, day;
		uint8_t hour, min, sec;
		RTC_TimeTypeDef RTC_TimeStruct_main;
		RTC_DateTypeDef RTC_DateStruct_main;
		RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct_main);
		RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct_main);
		
		year = RTC_DateStruct_main.RTC_Year;	
		mon = RTC_DateStruct_main.RTC_Month;
		day = RTC_DateStruct_main.RTC_Date;
		hour = RTC_TimeStruct_main.RTC_Hours;
		min = RTC_TimeStruct_main.RTC_Minutes;
		sec = RTC_TimeStruct_main.RTC_Seconds;
		
		//detect whether it is time to turn on Motor and LED, then execute it.
		Soak(day, hour, min );
		Water(day, hour, min, sec);
		Light(mon, day, hour, min);
		//detect over
			
		/* check if any packet received */
		if (ETH_CheckFrameReceived())
		{
			/* process received ethernet packet */
			LwIP_Pkt_Handle();
		}
		/* handle periodic timers for LwIP */
		LwIP_Periodic_Handle(LocalTime);
		
	}
}
示例#16
0
文件: main.cpp 项目: dbking77/stm32
int main(void)
{
  sys_time = 0;
  NVIC_SetPriorityGrouping(3);

  // enable GPIO
  RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
  RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN;
  RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN;
  RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
  RCC->AHB1ENR |= RCC_AHB1ENR_GPIOEEN;

  act::mode(GPIO_OUTPUT);
  stat::mode(GPIO_OUTPUT);
  error::mode(GPIO_OUTPUT);
  estop::mode(GPIO_INPUT);

  // setup ethernet
  phy_rst::mode(GPIO_OUTPUT_2MHz);
  phy_rst::high(); // release reset line

  eth_mii_crs::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
  eth_rx_clk::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
  eth_mdio::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
  eth_mii_col::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
  eth_mii_rx_dv::mode(GPIO_ALTERNATE | GPIO_AF_ETH);

  eth_mii_rxd2::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
  eth_mii_rxd3::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
  eth_mii_rx_er::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
  eth_mii_tx_en::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
  eth_mii_txd0::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
  eth_mii_txd1::mode(GPIO_ALTERNATE | GPIO_AF_ETH);

  eth_mdc::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
  eth_mii_txd2::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
  eth_mii_tx_clk::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
  eth_mii_rxd0::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
  eth_mii_rxd1::mode(GPIO_ALTERNATE | GPIO_AF_ETH);

  eth_mii_txd3::mode(GPIO_ALTERNATE | GPIO_AF_ETH);

  /* setup usarts
  RCC->APB2ENR |= RCC_APB2ENR_USART1EN; // APB2 also has USART6
  RCC->APB1ENR |= RCC_APB1ENR_USART2EN; // ABP1 also has USART3, UART4/5
  */

  RCC->APB1ENR |= RCC_APB1ENR_USART3EN;
  usart3_tx::mode(GPIO_ALTERNATE | GPIO_AF_USART3);
  usart3_rx::mode(GPIO_ALTERNATE | GPIO_AF_USART3);
  usart3_en::mode(GPIO_OUTPUT);
  //NVIC_EnableIRQ(USART3_IRQn);

  // setup systick
  SysTick_Config(SystemCoreClock/1000);
  NVIC_EnableIRQ(SysTick_IRQn);
  //NVIC_SetPriority(SysTick_IRQn,2);

  Ethernet_Init();
  LwIP_Init();
  if (!netapp_init())
    while(1)
    {
      error::high();
      delay_ms(50);
      error::low();
      delay_ms(1000);
    }

  __enable_irq();

  while(1)
  {
    /* check if any packet received */
    if (ETH_CheckFrameReceived())
    { 
      /* process received ethernet packet */
      LwIP_Pkt_Handle();
    }
    LwIP_Periodic_Handle(sys_time);

    /* process devices */
  }

}
示例#17
0
int main(void)
{
	int i;		
	unsigned char add[5]={110,110,8,110,110};
  /*!< 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
     */
  
#ifdef SERIAL_DEBUG
  DebugComPort_Init();
#endif
  
	initLED();
	init_Timer();
	//while(1);
	
  /*Initialize LCD and Leds */ 
  //LCD_LED_Init();
	
	delay_ms(500);				
	
	for(i=0;i<100;i++)
	{
		setNumber(i);
		delay_ms(10);				
	}
	beep(40);
	offSegment(3);
	delay_ms(100);
	setNumber(0);
	delay_ms(100);
	beep(40);
	offSegment(3);
	delay_ms(100);
	setNumber(0);
	delay_ms(100);
	beep(40);
	
	//USART2_Init();
	//USART3_Init();
	
	init_NRF1_IO();
	init_NRF2_IO();
	SPI1_Config();
	SPI3_Config();
	SPI_Cmd(SPI1, ENABLE);
	SPI_Cmd(SPI3, ENABLE);
	
  nrf24l01_initialize_debug(false, TX_PAYLOAD_SIZE, false);
	nrf24l01_clear_flush();
	add[2]=8;
	nrf24l01_set_tx_addr(add , 5);
	add[2]=30;
	nrf24l01_set_rx_addr(add,5,0);
	nrf24l01_set_rf_ch(tx_channel);


	nrf24l02_initialize_debug(false, RX_PAYLOAD_SIZE, false);	
 	nrf24l02_clear_flush();
	add[2]=8;
	nrf24l02_set_tx_addr(add , 5);
	add[2]=30;
	nrf24l02_set_rx_addr(add,5,0);	
	nrf24l02_set_rf_ch(rx_channel);
	nrf24l02_set_as_rx(true);		
	
  /* configure ethernet */ 
  ETH_BSP_Config();
    
  /* Initilaize the LwIP stack */
  LwIP_Init();
  
  /* UDP echoserver */
  udp_echoserver_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);
		
		process_incoming_rf();
		
		if(firstPacketRecieved==0)
		{
			demo();
			setNumber(22);			
		}
							
  }   
}
示例#18
0
文件: main.cpp 项目: JDsolution/stm32
int main(void)
{
    NVIC_SetPriorityGrouping(3);

    /* enable GPIO */
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN;
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN;
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOEEN;

    act::mode(GPIO_OUTPUT);
    stat::mode(GPIO_OUTPUT);
    error::mode(GPIO_OUTPUT);
    error::high();
    estop::mode(GPIO_INPUT);

    /* setup ethernet */
    phy_rst::mode(GPIO_OUTPUT_2MHz);
    phy_rst::high(); // release reset line

    eth_mii_crs::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_rx_clk::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mdio::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_col::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_rx_dv::mode(GPIO_ALTERNATE | GPIO_AF_ETH);

    eth_mii_rxd2::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_rxd3::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_rx_er::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_tx_en::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_txd0::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_txd1::mode(GPIO_ALTERNATE | GPIO_AF_ETH);

    eth_mdc::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_txd2::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_tx_clk::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_rxd0::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_rxd1::mode(GPIO_ALTERNATE | GPIO_AF_ETH);

    eth_mii_txd3::mode(GPIO_ALTERNATE | GPIO_AF_ETH);

    /* Initialize Table */
    register_table.model_number = 302;
    register_table.version = 0;
    register_table.id = 253;
    register_table.baud_rate = 34; // 57600????
    register_table.last_packet = 0;
    register_table.system_time = 0;
    register_table.led = 0;

    dynamixel_init();

    /* setup analog */
    RCC->APB2ENR |= RCC_APB2ENR_ADC1EN | RCC_APB2ENR_ADC2EN | RCC_APB2ENR_ADC3EN;
    adc1.init(VOLTAGE_SENSE_ANALOG_CHANNEL,
              CURRENT_SENSE_ANALOG_CHANNEL);
    voltage_sense::mode(GPIO_INPUT_ANALOG);
    current_sense::mode(GPIO_INPUT_ANALOG);

    /* setup systick */
    SysTick_Config(SystemCoreClock/1000);
    NVIC_SetPriority(SysTick_IRQn,2);
    NVIC_EnableIRQ(SysTick_IRQn);

    Ethernet_Init();
    LwIP_Init();
    if (!netapp_init())
        while(1);

    __enable_irq();

    /* done with setup, turn off err led */
    error::low();

    while(1)
    {
        /* check if any packet received */
        if (ETH_CheckFrameReceived())
        {
            /* process received ethernet packet */
            LwIP_Pkt_Handle();
        }
        LwIP_Periodic_Handle(register_table.system_time);
    }
}
示例#19
0
int main(void) {
	/*!< At this stage the microcontroller clock setting is already configured to
	 168 MHz, this is done through SystemInit() function which is called from
	 startup file (startup_stm32f4xx.s) before to branch to application main.
	 To reconfigure the default setting of SystemInit() function, refer to
	 system_stm32f4xx.c file
	 */
	char pase = 0;
	char pase1 = 0;
	uint16_t duty = 0;
	char led = 0;
	int i;

	uint8_t valor_web=0;

	RCC_GetClocksFreq(&RCC_Clocks);

#ifdef SERIAL_DEBUG
	DebugComPort_Init();
	printf("STM32DISCOVERY is booting...\r\n");
#endif



	/* configure ethernet (GPIOs, clocks, MAC, DMA) */
	ETH_BSP_Config();

	/* Initilaize the LwIP stack */
	LwIP_Init();

	/* Http webserver Init */
	httpd_init();

	/*Se inicializa la placa de expansion*/
	STM_EVAL_EXP_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);

		if (LocalTime % 20 == 0) {
			if (!pase1) {
				pase1 = 1;

				if (LocalTime % 100 == 0) {

					// escalera Led
					STM_EVAL_EXP_LED_TOGGLE(led);
					led++;
					if (led > 7)
						led = 0;
				}
			}
		} else {
			pase1 = 0;
		}

	}
	return 0;
}
示例#20
0
int main(void)
{
  int i_counter = 160;	
	
	SystemInit();
	
	SSD1963_Init();

	SSD1963_Clear(Red);
	Delay(100);
	SSD1963_Clear(Blue);
	Delay(100);
	SSD1963_Clear(Red);
	SSD1963_Fill(0, 0, 50, 50, Blue);
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC, ENABLE);
	GUI_Init();
	GUI_SetColor(GUI_RED);
	GUI_Clear();
	
	BSP_KeyInit( BSP_KEY1, BSP_KEY1_GPIO_PORT );

	BSP_USART_Init( );
	
	BSP_SPI_Init( );
	BSP_SPI_CS_Init( );
	
	//Debug_ShowRegister( GPIOA_BASE, (DebugPeripheralTypedef *)&DeBugGPIO );
	//Debug_ShowRegister( BSP_USARTx_BASE, (DebugPeripheralTypedef *)&DeBugUART );
	//Debug_ShowRegister( RCC_BASE, (DebugPeripheralTypedef *)&DeBugRCC );
	//Debug_ShowSpecificRegister( RCC_BASE, (DebugPeripheralTypedef *)&DeBugRCC, "APB2ENR" );
	
  /* 初始化LWIP协议栈*/
	LwIP_Init(); 

	/* 初始化web server 显示网页程序 */
	//httpd_init();
  
  /* 初始化telnet 远程控制程序 */   
  //CMD_init();                                       

  /* 初始化web celient远程控制程序 */  
  //tcp_client_connect();
	tcp_client_connect();
	
  /* Infinite loop */
  while ( 1 )
	{	
		static int i = 0;
		/*轮询*/ 
		if(i >= 150)
		{
			i = 0;
			i_counter ++;
			if(Updateflag == 1)
			{
				tcp_client_connect();	
			}
			printf("*******************  tcp_client_connect *************************\r\n");
		}			
		
		LwIP_Periodic_Handle(LocalTime);

		if(i_counter> 1000)
			i_counter = 101;
		
		wendu[0] = i_counter/100%10 + 0x30;
		wendu[1] = i_counter/10%10 + 0x30;
		wendu[3] = i_counter%10 + 0x30;
	
		printf(wendu);
		
		printf("      i = %d\r\n",i);
		
		i++;
		
		Delay(10);
  }

}