Darran Shepherd
/
AutoIpNetStack
Net stack with AutoIP enabled
Embed:
(wiki syntax)
Show/hide line numbers
LwipNetIf.cpp
00001 00002 /* 00003 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) 00004 00005 Permission is hereby granted, free of charge, to any person obtaining a copy 00006 of this software and associated documentation files (the "Software"), to deal 00007 in the Software without restriction, including without limitation the rights 00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 copies of the Software, and to permit persons to whom the Software is 00010 furnished to do so, subject to the following conditions: 00011 00012 The above copyright notice and this permission notice shall be included in 00013 all copies or substantial portions of the Software. 00014 00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00021 THE SOFTWARE. 00022 */ 00023 00024 #include "LwipNetIf.h" 00025 #include "lwip/init.h" 00026 #include "lwip/tcp_impl.h" 00027 #include "lwip/dns.h" 00028 00029 #include "netCfg.h" 00030 #if NET_LWIP_STACK 00031 00032 //See doc/rawapi.txt for details 00033 00034 LwipNetIf::LwipNetIf() : NetIf(), m_tcpTimer(), m_dnsTimer(), m_init(false) 00035 { 00036 00037 } 00038 00039 00040 LwipNetIf::~LwipNetIf() 00041 { 00042 00043 } 00044 00045 void LwipNetIf::init() 00046 { 00047 if(m_init) 00048 return; 00049 m_init=true; 00050 lwip_init(); //init lwip, see init.c for details 00051 00052 //Setup Clocks 00053 m_tcpTimer.start(); 00054 m_dnsTimer.start(); 00055 //m_tcpTicker.attach_us( tcp_tmr, TCP_TMR_INTERVAL * 1000 ); //TCP_TMR_INTERVAL = 250 ms in tcp_impl.h 00056 //m_dnsTicker.attach_us( dns_tmr, DNS_TMR_INTERVAL * 1000 ); //DNS_TMR_INTERVAL = 1000 ms in dns.h 00057 } 00058 00059 NetTcpSocket* LwipNetIf::tcpSocket() //Create a new tcp socket 00060 { 00061 return new LwipNetTcpSocket(); 00062 } 00063 00064 NetUdpSocket* LwipNetIf::udpSocket() //Create a new udp socket 00065 { 00066 return new LwipNetUdpSocket(); 00067 } 00068 00069 NetDnsRequest* LwipNetIf::dnsRequest(const char* hostname) //Create a new NetDnsRequest object 00070 { 00071 return new LwipNetDnsRequest(hostname); 00072 } 00073 00074 NetDnsRequest* LwipNetIf::dnsRequest(Host* pHost) //Create a new NetDnsRequest object 00075 { 00076 return new LwipNetDnsRequest(pHost); 00077 } 00078 00079 void LwipNetIf::poll() 00080 { 00081 if(m_init && m_tcpTimer.read_ms() >= TCP_TMR_INTERVAL) 00082 { 00083 m_tcpTimer.reset(); 00084 tcp_tmr(); //Poll LwIP 00085 } 00086 if(m_init && m_dnsTimer.read_ms() >= DNS_TMR_INTERVAL) 00087 { 00088 m_dnsTimer.reset(); 00089 dns_tmr(); 00090 } 00091 //Do some stuff... 00092 } 00093 00094 #endif
Generated on Tue Jul 12 2022 15:37:04 by 1.7.2