//软件中断 使用中断4 //该中断函数用于将数据通过USART2发送到SIM900模块 void EXTI4_IRQHandler(void) { if(EXTI_GetITStatus(EXTI_Line4) != RESET) { EXTI_ClearITPendingBit(EXTI_Line4); pppos_input(pd,USART2_RX_BUF,USART2_RX_STA_BACKUP&0x3fff); } }
/* This is somewhat different to other ports: we have a main loop here: * a dedicated task that waits for packets to arrive. This would normally be * done from interrupt context with embedded hardware, but we don't get an * interrupt in windows for that :-) */ void main_loop() { #if !NO_SYS err_t err; sys_sem_t init_sem; #endif /* NO_SYS */ #if PPP_SUPPORT #if !USE_ETHERNET int count; u8_t rxbuf[1024]; #endif volatile int callClosePpp = 0; #endif /* PPP_SUPPORT */ /* initialize lwIP stack, network interfaces and applications */ #if NO_SYS lwip_init(); test_init(NULL); #else /* NO_SYS */ err = sys_sem_new(&init_sem, 0); tcpip_init(test_init, &init_sem); /* we have to wait for initialization to finish before * calling update_adapter()! */ sys_sem_wait(&init_sem); sys_sem_free(&init_sem); #endif /* NO_SYS */ /* MAIN LOOP for driver update (and timers if NO_SYS) */ while (!_kbhit()) { #if NO_SYS /* handle timers (already done in tcpip.c when NO_SYS=0) */ sys_check_timeouts(); #endif /* NO_SYS */ #if USE_ETHERNET #if !PCAPIF_RX_USE_THREAD /* check for packets and link status*/ pcapif_poll(&netif); /* When pcapif_poll comes back, there are not packets, so sleep to prevent 100% CPU load. Don't do this in an embedded system since it increases latency! */ sys_msleep(1); #else /* !PCAPIF_RX_USE_THREAD */ sys_msleep(50); #endif /* !PCAPIF_RX_USE_THREAD */ #else /* USE_ETHERNET */ #if 0 /* set this to 1 if PPP_INPROC_OWNTHREAD==0 or not defined (see ppp.c) */ /* try to read characters from serial line and pass them to PPPoS */ count = sio_read(ppp_sio, (u8_t*)rxbuf, 1024); if(count > 0) { pppos_input(ppp_desc, rxbuf, count); } else #endif { /* nothing received, give other tasks a chance to run */ sys_msleep(1); } #endif /* USE_ETHERNET */ #if !LWIP_NETIF_LOOPBACK_MULTITHREADING /* check for loopback packets on all netifs */ netif_poll_all(); #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */ #if PPP_SUPPORT { int do_hup = 0; if(do_hup) { pppSigHUP(ppp_desc); do_hup = 0; } } if(callClosePpp && (ppp_desc >= 0)) { /* make sure to disconnect PPP before stopping the program... */ callClosePpp = 0; #if NO_SYS pppClose(ppp_desc); #else tcpip_callback_with_block(pppCloseCallback, (void*)ppp_desc, 0); #endif ppp_desc = -1; } #endif /* PPP_SUPPORT */ } #if PPP_SUPPORT if(ppp_desc >= 0) { u32_t started; printf("Closing PPP connection...\n"); /* make sure to disconnect PPP before stopping the program... */ #if NO_SYS pppClose(ppp_desc); #else tcpip_callback_with_block(pppCloseCallback, (void*)ppp_desc, 0); #endif ppp_desc = -1; /* Wait for some time to let PPP finish... */ started = sys_now(); do { #if USE_ETHERNET && !PCAPIF_RX_USE_THREAD pcapif_poll(&netif); #else /* USE_ETHERNET && !PCAPIF_RX_USE_THREAD */ sys_msleep(50); #endif /* USE_ETHERNET && !PCAPIF_RX_USE_THREAD */ /* @todo: need a better check here: only wait until PPP is down */ } while(sys_now() - started < 5000); } #endif /* PPP_SUPPORT */ #if USE_ETHERNET /* release the pcap library... */ pcapif_shutdown(&netif); #endif /* USE_ETHERNET */ }
/* This is somewhat different to other ports: we have a main loop here: * a dedicated task that waits for packets to arrive. This would normally be * done from interrupt context with embedded hardware, but we don't get an * interrupt in windows for that :-) */ static void main_loop(void) { #if !NO_SYS err_t err; sys_sem_t init_sem; #endif /* NO_SYS */ #if USE_PPP #if !USE_ETHERNET int count; u8_t rxbuf[1024]; #endif volatile int callClosePpp = 0; #endif /* USE_PPP */ /* initialize lwIP stack, network interfaces and applications */ #if NO_SYS lwip_init(); test_init(NULL); #else /* NO_SYS */ err = sys_sem_new(&init_sem, 0); LWIP_ASSERT("failed to create init_sem", err == ERR_OK); tcpip_init(test_init, &init_sem); /* we have to wait for initialization to finish before * calling update_adapter()! */ sys_sem_wait(&init_sem); sys_sem_free(&init_sem); #endif /* NO_SYS */ #if (LWIP_SOCKET || LWIP_NETCONN) && LWIP_NETCONN_SEM_PER_THREAD netconn_thread_init(); #endif /* MAIN LOOP for driver update (and timers if NO_SYS) */ while (!_kbhit()) { #if NO_SYS /* handle timers (already done in tcpip.c when NO_SYS=0) */ sys_check_timeouts(); #endif /* NO_SYS */ #if USE_ETHERNET #if !PCAPIF_RX_USE_THREAD /* check for packets and link status*/ pcapif_poll(&netif); /* When pcapif_poll comes back, there are not packets, so sleep to prevent 100% CPU load. Don't do this in an embedded system since it increases latency! */ sys_msleep(1); #else /* !PCAPIF_RX_USE_THREAD */ sys_msleep(50); #endif /* !PCAPIF_RX_USE_THREAD */ #else /* USE_ETHERNET */ /* try to read characters from serial line and pass them to PPPoS */ count = sio_read(ppp_sio, (u8_t*)rxbuf, 1024); if(count > 0) { pppos_input(ppp, rxbuf, count); } else { /* nothing received, give other tasks a chance to run */ sys_msleep(1); } #endif /* USE_ETHERNET */ #if USE_SLIPIF slipif_poll(&slipif1); #if USE_SLIPIF > 1 slipif_poll(&slipif2); #endif /* USE_SLIPIF > 1 */ #endif /* USE_SLIPIF */ #if ENABLE_LOOPBACK && !LWIP_NETIF_LOOPBACK_MULTITHREADING /* check for loopback packets on all netifs */ netif_poll_all(); #endif /* ENABLE_LOOPBACK && !LWIP_NETIF_LOOPBACK_MULTITHREADING */ #if USE_PPP { int do_hup = 0; if(do_hup) { ppp_close(ppp, 1); do_hup = 0; } } if(callClosePpp && ppp) { /* make sure to disconnect PPP before stopping the program... */ callClosePpp = 0; #if NO_SYS ppp_close(ppp, 0); #else pppapi_close(ppp, 0); #endif ppp = NULL; } #endif /* USE_PPP */ } #if USE_PPP if(ppp) { u32_t started; printf("Closing PPP connection...\n"); /* make sure to disconnect PPP before stopping the program... */ #if NO_SYS ppp_close(ppp, 0); #else pppapi_close(ppp, 0); #endif ppp = NULL; /* Wait for some time to let PPP finish... */ started = sys_now(); do { #if USE_ETHERNET && !PCAPIF_RX_USE_THREAD pcapif_poll(&netif); #else /* USE_ETHERNET && !PCAPIF_RX_USE_THREAD */ sys_msleep(50); #endif /* USE_ETHERNET && !PCAPIF_RX_USE_THREAD */ /* @todo: need a better check here: only wait until PPP is down */ } while(sys_now() - started < 5000); } #endif /* USE_PPP */ #if (LWIP_SOCKET || LWIP_NETCONN) && LWIP_NETCONN_SEM_PER_THREAD netconn_thread_cleanup(); #endif #if USE_ETHERNET /* release the pcap library... */ pcapif_shutdown(&netif); #endif /* USE_ETHERNET */ }
static void gprs_input_internal(gprs_t * gprs,u8_t * data,u32_t length) { if (length > 0) { #if 0 LWIP_DEBUGF(GPRS_DEBUG,("gprs: Got %lu bytes state=%d\n",(unsigned long)length,gprs->state)); #endif switch (gprs->state) { default: LWIP_DEBUGF(GPRS_DEBUG,("gprs: Ignored %lu bytes\n",(unsigned long)length)); break; case GPRS_STATE_MODEM_DIAL: modem_check_reply(gprs,data,length,do_modem_dial_reply); if (gprs->connected) { gprs_do_connect(gprs); } break; case GPRS_STATE_GPRS_NETWORK: do_gprs_network_check(gprs,data,length); break; case GPRS_STATE_GSM_NETWORK: do_gsm_network_check(gprs,data,length); break; case GPRS_STATE_MODEM_IMEI: if (modem_check_reply(gprs,data,length,do_modem_imei_reply) == MODEM_REPLY_OK) { #if GPRS_ICCID do_sim_iccid(gprs); #else do_gsm_network(gprs); #endif } break; #if GPRS_ICCID case GPRS_STATE_MODEM_CCID: if (modem_check_reply(gprs,data,length,do_sim_iccid_reply) == MODEM_REPLY_OK) { do_gsm_network(gprs); } break; #endif case GPRS_STATE_MODEM_IDENTIFY: if (modem_check_reply(gprs,data,length,do_modem_identify_reply) == MODEM_REPLY_OK) { do_modem_imei(gprs); } break; case GPRS_STATE_MODEM_INIT: if (modem_check_ok_reply(gprs,data,length)) { do_modem_dial(gprs); } break; case GPRS_STATE_MODEM_ALIVE: if (modem_check_ok_reply(gprs,data,length)) { do_modem_identify(gprs); } break; case GPRS_STATE_CONNECTING: case GPRS_STATE_CONNECTED: pppos_input(gprs->pcb,data,length); break; } } }