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();
	}
}
Example #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);
  }   
}
Example #3
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();
    }

}
Example #4
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));
    }
}
//以太网中断服务函数
void ETH_IRQHandler(void)
{
	while(ETH_GetRxPktSize(DMARxDescToGet)!=0) 	//检测是否收到数据包
	{ 
		LwIP_Pkt_Handle();		
	}
	ETH_DMAClearITPendingBit(ETH_DMA_IT_R);
	ETH_DMAClearITPendingBit(ETH_DMA_IT_NIS);
}   
Example #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();
  }
} 
Example #7
0
void ETH_Recive_Poll(void)
{

	if(frameds.length>0) //处理以太网数据
	{
     LwIP_Pkt_Handle();//处理早已经接收放入内存的数据。
	 memset(&frameds, 0, sizeof(FrameTypeDef));
	}	

}
Example #8
0
/**
  * @brief  This function handles ETH interrupt request.
  * @param  None
  * @retval None
  */
void ETH_IRQHandler(void)
{
  	/* Handles all the received frames */
  	while(ETH_GetRxPktSize(DMARxDescToGet) != 0) 
  	{		
	  LwIP_Pkt_Handle();
  	}

  	/* Clear the Eth DMA Rx IT pending bits */
  	ETH_DMAClearITPendingBit(ETH_DMA_IT_R);
  	ETH_DMAClearITPendingBit(ETH_DMA_IT_NIS);
}
Example #9
0
/*------------------------------------------------------------------------------------------------*/
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());
}
Example #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();
  }   
}
Example #11
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);
  }   
}
Example #12
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;
}
Example #13
0
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);
    }
}
Example #14
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  FlagStatus status;
  uint16_t bak_dr10;
  //uint16_t bak_dr9;
  
  //RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
  //PWR_BackupAccessCmd(ENABLE);  
  
  //bak_dr10 = BKP_ReadBackupRegister(BKP_DR10);
  //bak_dr9 = BKP_ReadBackupRegister(BKP_DR9);
  
  //BKP_WriteBackupRegister(BKP_DR10, 0x0707);
  //BKP_WriteBackupRegister(BKP_DR9, 0x0001);
  
  
  /* Test if Key push-button on STM3210C-EVAL Board is not pressed */
  //if((bak_dr10 == 0x0707) /*&& (bak_dr9 != 0x0000)*/)
  if(1)
  {
    /* Setup STM32 system (clocks, Ethernet, GPIO, NVIC) and STM3210C-EVAL resources */
    System_Setup();
    
    Delay(1000);
    //可添加延时, 用以确保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, 复位启动    
    /* Configure the Ethernet peripheral */
    Ethernet_Configuration();
    
    /*
    //判断设备是否是初次上电, 如果'是', 重启一次, 确保以太网初始化正常
    status = RCC_GetFlagStatus(RCC_FLAG_SFTRST);
    RCC_ClearFlag(); 
    if(!status)
    {   
      Delay(10);
      
      NVIC_SystemReset();
    }
    */
 
    /* Initilaize the LwIP stack */
    LwIP_Init();
    
#ifdef USE_IAP_HTTP
    /* Initilaize the webserver module */
    IAP_httpd_init();
#endif
    
#ifdef USE_IAP_TFTP    
    /* Initialize the TFTP server */
    IAP_tftpd_init();
#endif    
    
    /* Infinite loop */
    while (1)
    {
      /* check if any packet received */
      if (ETH_GetRxPktSize()!=0)
      { 
        /* process received eth packet */
        LwIP_Pkt_Handle();
      }
      /* Periodic tasks */
      System_Periodic_Handle();
    }    
  }
  /* enter in IAP mode */
  else
  {
    /* Key push-button not pressed: jump to user application */
    
    /* Check if valid stack address (RAM address) then jump to user application */
    if (((*(__IO uint32_t*)USER_FLASH_FIRST_PAGE_ADDRESS) & 0x2FFE0000 ) == 0x20000000)
    {
      /* Jump to user application */
      JumpAddress = *(__IO uint32_t*) (USER_FLASH_FIRST_PAGE_ADDRESS + 4);
      Jump_To_Application = (pFunction) JumpAddress;
      /* Initialize user application's Stack Pointer */
      __set_MSP(*(__IO uint32_t*) USER_FLASH_FIRST_PAGE_ADDRESS);
      Jump_To_Application();
    }
    else
    {/* Otherwise, do nothing */
      /* LED3 (RED) ON to indicate bad software (when not valid stack address) */
      //STM_EVAL_LEDInit(LED3);
      //STM_EVAL_LEDOn(LED3);
      /* do nothing */
      while(1);
    }    
  }
  
  return 0;
}
Example #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);
		
	}
}
Example #16
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);			
		}
							
  }   
}
Example #17
0
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 */
  }

}