/** * @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 have a system clock = 168 Mhz */ SystemClock_Config(); /* Configure the BSP */ BSP_Config(); /* Initilaize the LwIP stack */ lwip_init(); /* Configure the Network interface */ Netif_Config(); /* tcp echo server Init */ udp_echoserver_init(); /* Notify user about the netwoek interface config */ User_notification(&gnetif); /* 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(); } }
/** * ---------------------------------------------------------------------- * Function given to help user to continue LwIP Initialization * Up to user to complete or change this function ... * Up to user to call this function in main.c in while (1) of main(void) *----------------------------------------------------------------------- * Read a received packet from the Ethernet buffers * Send it to the lwIP stack for handling * Handle timeouts if NO_SYS_NO_TIMERS not set and without RTOS */ void MX_LWIP_Process(void) { ethernetif_input(&gnetif); /* Handle timeouts */ #if !NO_SYS_NO_TIMERS && NO_SYS sys_check_timeouts(); #endif if (gnetif.ip_addr.addr !=ip) { ip = gnetif.ip_addr.addr; a = ip & 0xFF; b = ip & 0xFF00; b = b >> 0x8; c = ip & 0xFF0000 ; c = c >> 0x10; d = ip & 0xFF000000 ; d = d >> 0x18; printf("got ip address %i.%i.%i.%i\n\r",a,b,c,d); }
/** * @brief Called when a frame is received * @param None * @retval None */ void LwIP_Pkt_Handle(void) { /* Read a received packet from the Ethernet buffers and send it to the lwIP for handling */ ethernetif_input(&gnetif); }
/** * @brief Main program * @param None * @retval None */ int main(void) { /* Configure Key Button */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO); /* Test if Key push-button is not pressed */ if (BSP_PB_GetState(BUTTON_KEY) != 0x00) { /* 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(); /* do nothing */ while(1); } else {/* Otherwise, do nothing */ /* LED3 (RED) ON to indicate bad software (when not valid stack address) */ BSP_LED_Init(LED3); BSP_LED_On(LED3); /* do nothing */ while(1); } } /* Enter in IAP mode */ else { /* 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(); #ifdef USE_IAP_HTTP /* Initialize the webserver module */ IAP_httpd_init(); #endif #ifdef USE_IAP_TFTP /* Initialize the TFTP server */ IAP_tftpd_init(); #endif /* Notify user about the network interface config */ User_notification(&gnetif); /* 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 } } }
//用于以太网中断调用 void lwip_pkt_handle(void) { ethernetif_input(&lwip_netif); }
/*-----------------------------------------------------------------------------------*/ void ethernetif_process_input(void *arg, void *packet, int packet_len) { struct netif *netif = (struct netif*)arg; ethernetif_input(netif, packet, packet_len); }
static NORETURN void ethernetif_loop(void *arg) { struct netif *netif = (struct netif *)arg; while (1) ethernetif_input(netif); }
static err_t eth_handle_event(struct netif *netif, uint32_t event) { int link_status; uint32_t eth_event; pin_toggle(); if (event == NIC_EVENT_API_RESET) { LOGI(TAG, "reset ethernet card."); /* restart init */ eth_hard_reset(); eth_mac_handle = csi_eth_mac_initialize(0, NULL); /* enable irq */ csi_eth_mac_control(eth_mac_handle, CSI_ETH_MAC_CONTROL_RX, 1); eth_gpio_config_int(1); g_bTimerStopped = 1; } else { eth_event = eth_get_event(0); if (eth_event) { csi_kernel_timer_stop(timer_send_handle); g_bTimerStopped = 1; g_continue_send_error = 0; } else { //printf("invalid interrupt\n"); } if (eth_event & 0x80) { LOGI(TAG, "reset ethernet card."); /* restart init */ eth_hard_reset(); eth_mac_handle = csi_eth_mac_initialize(0, NULL); /* enable irq */ } else { if (eth_event & CSI_ETH_MAC_EVENT_LINK_CHANGE) { link_status = csi_eth_phy_get_linkstate(eth_phy_handle); if ((link_status != -1)) { nic_link_stat = link_status; LOGI(TAG, "Net:link %s", (link_status == 1) ? "up" : "down"); if (link_status == 1) { //aos_post_event(EV_NET, CODE_NET_ON_CONNECTED, VALUE_NET_ETH); } else { //aos_post_event(EV_NET, CODE_NET_ON_DISCONNECT, VALUE_NET_ETH); } } } if (eth_event == CSI_ETH_MAC_EVENT_RX_FRAME) { ethernetif_input(netif); /*if there are packets in rx buffer, interrupt will be triggered again*/ } if (eth_event == CSI_ETH_MAC_EVENT_TX_FRAME) { } pin_toggle(); } //Enable interrupt csi_eth_mac_control(eth_mac_handle, CSI_ETH_MAC_CONTROL_RX, 1); eth_gpio_config_int(1); } return 0; }