Committer:
mbed714
Date:
Tue Nov 09 19:32:44 2010 +0000
Revision:
3:0c324737064d
Parent:
0:98aadd37a5c5

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed714 0:98aadd37a5c5 1
mbed714 0:98aadd37a5c5 2 /*
mbed714 0:98aadd37a5c5 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
mbed714 0:98aadd37a5c5 4
mbed714 0:98aadd37a5c5 5 Permission is hereby granted, free of charge, to any person obtaining a copy
mbed714 0:98aadd37a5c5 6 of this software and associated documentation files (the "Software"), to deal
mbed714 0:98aadd37a5c5 7 in the Software without restriction, including without limitation the rights
mbed714 0:98aadd37a5c5 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mbed714 0:98aadd37a5c5 9 copies of the Software, and to permit persons to whom the Software is
mbed714 0:98aadd37a5c5 10 furnished to do so, subject to the following conditions:
mbed714 0:98aadd37a5c5 11
mbed714 0:98aadd37a5c5 12 The above copyright notice and this permission notice shall be included in
mbed714 0:98aadd37a5c5 13 all copies or substantial portions of the Software.
mbed714 0:98aadd37a5c5 14
mbed714 0:98aadd37a5c5 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mbed714 0:98aadd37a5c5 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mbed714 0:98aadd37a5c5 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mbed714 0:98aadd37a5c5 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mbed714 0:98aadd37a5c5 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mbed714 0:98aadd37a5c5 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
mbed714 0:98aadd37a5c5 21 THE SOFTWARE.
mbed714 0:98aadd37a5c5 22 */
mbed714 0:98aadd37a5c5 23
mbed714 0:98aadd37a5c5 24 #include "LwipNetIf.h"
mbed714 0:98aadd37a5c5 25 #include "lwip/init.h"
mbed714 0:98aadd37a5c5 26 #include "lwip/tcp_impl.h"
mbed714 0:98aadd37a5c5 27 #include "lwip/dns.h"
mbed714 0:98aadd37a5c5 28
mbed714 0:98aadd37a5c5 29 #include "lwipNetTcpSocket.h"
mbed714 0:98aadd37a5c5 30 #include "lwipNetUdpSocket.h"
mbed714 0:98aadd37a5c5 31 #include "lwipNetDnsRequest.h"
mbed714 0:98aadd37a5c5 32
mbed714 0:98aadd37a5c5 33 #include "netCfg.h"
mbed714 0:98aadd37a5c5 34 #if NET_LWIP_STACK
mbed714 0:98aadd37a5c5 35
mbed714 0:98aadd37a5c5 36 //See doc/rawapi.txt for details
mbed714 0:98aadd37a5c5 37
mbed714 0:98aadd37a5c5 38 LwipNetIf::LwipNetIf() : NetIf(), m_tcpTimer(), m_dnsTimer(), m_init(false)
mbed714 0:98aadd37a5c5 39 {
mbed714 0:98aadd37a5c5 40
mbed714 0:98aadd37a5c5 41 }
mbed714 0:98aadd37a5c5 42
mbed714 0:98aadd37a5c5 43
mbed714 0:98aadd37a5c5 44 LwipNetIf::~LwipNetIf()
mbed714 0:98aadd37a5c5 45 {
mbed714 0:98aadd37a5c5 46
mbed714 0:98aadd37a5c5 47 }
mbed714 0:98aadd37a5c5 48
mbed714 0:98aadd37a5c5 49 void LwipNetIf::init()
mbed714 0:98aadd37a5c5 50 {
mbed714 0:98aadd37a5c5 51 if(m_init)
mbed714 0:98aadd37a5c5 52 return;
mbed714 0:98aadd37a5c5 53 m_init=true;
mbed714 0:98aadd37a5c5 54 lwip_init(); //init lwip, see init.c for details
mbed714 0:98aadd37a5c5 55
mbed714 0:98aadd37a5c5 56 //Setup Clocks
mbed714 0:98aadd37a5c5 57 m_tcpTimer.start();
mbed714 0:98aadd37a5c5 58 m_dnsTimer.start();
mbed714 0:98aadd37a5c5 59 //m_tcpTicker.attach_us( tcp_tmr, TCP_TMR_INTERVAL * 1000 ); //TCP_TMR_INTERVAL = 250 ms in tcp_impl.h
mbed714 0:98aadd37a5c5 60 //m_dnsTicker.attach_us( dns_tmr, DNS_TMR_INTERVAL * 1000 ); //DNS_TMR_INTERVAL = 1000 ms in dns.h
mbed714 0:98aadd37a5c5 61 }
mbed714 0:98aadd37a5c5 62
mbed714 0:98aadd37a5c5 63 NetTcpSocket* LwipNetIf::tcpSocket() //Create a new tcp socket
mbed714 0:98aadd37a5c5 64 {
mbed714 0:98aadd37a5c5 65 return new LwipNetTcpSocket();
mbed714 0:98aadd37a5c5 66 }
mbed714 0:98aadd37a5c5 67
mbed714 0:98aadd37a5c5 68 NetUdpSocket* LwipNetIf::udpSocket() //Create a new udp socket
mbed714 0:98aadd37a5c5 69 {
mbed714 0:98aadd37a5c5 70 return new LwipNetUdpSocket();
mbed714 0:98aadd37a5c5 71 }
mbed714 0:98aadd37a5c5 72
mbed714 0:98aadd37a5c5 73 NetDnsRequest* LwipNetIf::dnsRequest(const char* hostname) //Create a new NetDnsRequest object
mbed714 0:98aadd37a5c5 74 {
mbed714 0:98aadd37a5c5 75 return new LwipNetDnsRequest(hostname);
mbed714 0:98aadd37a5c5 76 }
mbed714 0:98aadd37a5c5 77
mbed714 0:98aadd37a5c5 78 NetDnsRequest* LwipNetIf::dnsRequest(Host* pHost) //Create a new NetDnsRequest object
mbed714 0:98aadd37a5c5 79 {
mbed714 0:98aadd37a5c5 80 return new LwipNetDnsRequest(pHost);
mbed714 0:98aadd37a5c5 81 }
mbed714 0:98aadd37a5c5 82
mbed714 0:98aadd37a5c5 83 void LwipNetIf::poll()
mbed714 0:98aadd37a5c5 84 {
mbed714 0:98aadd37a5c5 85 if(m_init && m_tcpTimer.read_ms() >= TCP_TMR_INTERVAL)
mbed714 0:98aadd37a5c5 86 {
mbed714 0:98aadd37a5c5 87 m_tcpTimer.reset();
mbed714 0:98aadd37a5c5 88 tcp_tmr(); //Poll LwIP
mbed714 0:98aadd37a5c5 89 }
mbed714 0:98aadd37a5c5 90 if(m_init && m_dnsTimer.read_ms() >= DNS_TMR_INTERVAL)
mbed714 0:98aadd37a5c5 91 {
mbed714 0:98aadd37a5c5 92 m_dnsTimer.reset();
mbed714 0:98aadd37a5c5 93 dns_tmr();
mbed714 0:98aadd37a5c5 94 }
mbed714 0:98aadd37a5c5 95 //Do some stuff...
mbed714 0:98aadd37a5c5 96 }
mbed714 0:98aadd37a5c5 97
mbed714 0:98aadd37a5c5 98 #endif