Dependencies:   MSCUsbHost NetServices RPCInterface TextLCD mbed

Committer:
yueee_yt
Date:
Wed Aug 22 05:10:09 2012 +0000
Revision:
1:f2088fbce73f
Parent:
0:fd83f3540b1a
???????LM35??????WebServer

Who changed what in which revision?

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