code that uses Watchdog to reset Mbed every 30seconds. After 30-60mins, the ethernet interface fails to setup() after WatchDog reset.

Dependencies:   mbed

Committer:
eqon
Date:
Thu Jun 07 05:44:29 2012 +0000
Revision:
0:0ce833f21e63

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eqon 0:0ce833f21e63 1
eqon 0:0ce833f21e63 2 /*
eqon 0:0ce833f21e63 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
eqon 0:0ce833f21e63 4
eqon 0:0ce833f21e63 5 Permission is hereby granted, free of charge, to any person obtaining a copy
eqon 0:0ce833f21e63 6 of this software and associated documentation files (the "Software"), to deal
eqon 0:0ce833f21e63 7 in the Software without restriction, including without limitation the rights
eqon 0:0ce833f21e63 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
eqon 0:0ce833f21e63 9 copies of the Software, and to permit persons to whom the Software is
eqon 0:0ce833f21e63 10 furnished to do so, subject to the following conditions:
eqon 0:0ce833f21e63 11
eqon 0:0ce833f21e63 12 The above copyright notice and this permission notice shall be included in
eqon 0:0ce833f21e63 13 all copies or substantial portions of the Software.
eqon 0:0ce833f21e63 14
eqon 0:0ce833f21e63 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
eqon 0:0ce833f21e63 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
eqon 0:0ce833f21e63 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
eqon 0:0ce833f21e63 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
eqon 0:0ce833f21e63 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
eqon 0:0ce833f21e63 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
eqon 0:0ce833f21e63 21 THE SOFTWARE.
eqon 0:0ce833f21e63 22 */
eqon 0:0ce833f21e63 23
eqon 0:0ce833f21e63 24 #ifndef LWIPNETTCPSOCKET_H
eqon 0:0ce833f21e63 25 #define LWIPNETTCPSOCKET_H
eqon 0:0ce833f21e63 26
eqon 0:0ce833f21e63 27 #define NET_LWIP_STACK 1
eqon 0:0ce833f21e63 28 #include "if/net/nettcpsocket.h"
eqon 0:0ce833f21e63 29 #include "LwipNetIf.h"
eqon 0:0ce833f21e63 30
eqon 0:0ce833f21e63 31 #include "stdint.h"
eqon 0:0ce833f21e63 32
eqon 0:0ce833f21e63 33 //Implements NetTcpSockets over lwIP raw API
eqon 0:0ce833f21e63 34
eqon 0:0ce833f21e63 35 struct tcp_pcb; //Represents a Tcp Connection, "Protocol Control Block", see rawapi.txt & tcp.h
eqon 0:0ce833f21e63 36 struct pbuf; //Lwip Buffer Container
eqon 0:0ce833f21e63 37
eqon 0:0ce833f21e63 38 typedef signed char err_t;
eqon 0:0ce833f21e63 39 typedef uint16_t u16_t;
eqon 0:0ce833f21e63 40
eqon 0:0ce833f21e63 41 class LwipNetTcpSocket: public NetTcpSocket
eqon 0:0ce833f21e63 42 {
eqon 0:0ce833f21e63 43 public:
eqon 0:0ce833f21e63 44 LwipNetTcpSocket(tcp_pcb* pPcb = NULL); //Passes a pcb if already created (by an accept req for instance), in that case transfers ownership
eqon 0:0ce833f21e63 45 virtual ~LwipNetTcpSocket();
eqon 0:0ce833f21e63 46
eqon 0:0ce833f21e63 47 virtual NetTcpSocketErr bind(const Host& me);
eqon 0:0ce833f21e63 48 virtual NetTcpSocketErr listen();
eqon 0:0ce833f21e63 49 virtual NetTcpSocketErr connect(const Host& host);
eqon 0:0ce833f21e63 50 virtual NetTcpSocketErr accept(Host* pClient, NetTcpSocket** ppNewNetTcpSocket);
eqon 0:0ce833f21e63 51
eqon 0:0ce833f21e63 52 virtual int /*if < 0 : NetTcpSocketErr*/ send(const char* buf, int len);
eqon 0:0ce833f21e63 53 virtual int /*if < 0 : NetTcpSocketErr*/ recv(char* buf, int len);
eqon 0:0ce833f21e63 54
eqon 0:0ce833f21e63 55 virtual NetTcpSocketErr close();
eqon 0:0ce833f21e63 56
eqon 0:0ce833f21e63 57 virtual NetTcpSocketErr poll();
eqon 0:0ce833f21e63 58
eqon 0:0ce833f21e63 59 protected:
eqon 0:0ce833f21e63 60 volatile tcp_pcb* m_pPcb;
eqon 0:0ce833f21e63 61
eqon 0:0ce833f21e63 62 //Events callbacks from lwIp
eqon 0:0ce833f21e63 63 err_t acceptCb(tcp_pcb* newpcb, err_t err);
eqon 0:0ce833f21e63 64 err_t connectedCb(tcp_pcb* tpcb, err_t err);
eqon 0:0ce833f21e63 65
eqon 0:0ce833f21e63 66 void errCb(err_t err);
eqon 0:0ce833f21e63 67
eqon 0:0ce833f21e63 68 err_t sentCb(tcp_pcb* tpcb, u16_t len);
eqon 0:0ce833f21e63 69 err_t recvCb(tcp_pcb* tpcb, pbuf *p, err_t err);
eqon 0:0ce833f21e63 70
eqon 0:0ce833f21e63 71 private:
eqon 0:0ce833f21e63 72 void cleanUp(); //Flush input buffer
eqon 0:0ce833f21e63 73
eqon 0:0ce833f21e63 74 // queue<tcp_pcb*> m_lpInPcb; //Incoming connections that have not been accepted yet
eqon 0:0ce833f21e63 75 queue<LwipNetTcpSocket*> m_lpInNetTcpSocket; //Incoming connections that have not been accepted yet
eqon 0:0ce833f21e63 76
eqon 0:0ce833f21e63 77 volatile pbuf* m_pReadPbuf; //Ptr to read buffer
eqon 0:0ce833f21e63 78
eqon 0:0ce833f21e63 79 //Static callbacks : Transforms into a C++ callback
eqon 0:0ce833f21e63 80 static err_t sAcceptCb(void *arg, struct tcp_pcb *newpcb, err_t err);
eqon 0:0ce833f21e63 81 static err_t sConnectedCb(void *arg, struct tcp_pcb *tpcb, err_t err);
eqon 0:0ce833f21e63 82
eqon 0:0ce833f21e63 83 static void sErrCb(void *arg, err_t err);
eqon 0:0ce833f21e63 84
eqon 0:0ce833f21e63 85 static err_t sSentCb(void *arg, struct tcp_pcb *tpcb, u16_t len);
eqon 0:0ce833f21e63 86 static err_t sRecvCb(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err);
eqon 0:0ce833f21e63 87
eqon 0:0ce833f21e63 88 };
eqon 0:0ce833f21e63 89
eqon 0:0ce833f21e63 90 #endif