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 NETTCPSOCKET_H
eqon 0:0ce833f21e63 25 #define NETTCPSOCKET_H
eqon 0:0ce833f21e63 26
eqon 0:0ce833f21e63 27 #include "net.h"
eqon 0:0ce833f21e63 28 #include "host.h"
eqon 0:0ce833f21e63 29
eqon 0:0ce833f21e63 30 #include <queue>
eqon 0:0ce833f21e63 31 using std::queue;
eqon 0:0ce833f21e63 32
eqon 0:0ce833f21e63 33 //Implements a Berkeley-like socket if
eqon 0:0ce833f21e63 34 //Can be interfaced either to lwip or a Telit module
eqon 0:0ce833f21e63 35
eqon 0:0ce833f21e63 36 enum NetTcpSocketErr
eqon 0:0ce833f21e63 37 {
eqon 0:0ce833f21e63 38 __NETTCPSOCKET_MIN = -0xFFFF,
eqon 0:0ce833f21e63 39 NETTCPSOCKET_SETUP, //NetTcpSocket not properly configured
eqon 0:0ce833f21e63 40 NETTCPSOCKET_TIMEOUT,
eqon 0:0ce833f21e63 41 NETTCPSOCKET_IF, //If has problems
eqon 0:0ce833f21e63 42 NETTCPSOCKET_MEM, //Not enough mem
eqon 0:0ce833f21e63 43 NETTCPSOCKET_INUSE, //If/Port is in use
eqon 0:0ce833f21e63 44 NETTCPSOCKET_EMPTY, //Connections queue is empty
eqon 0:0ce833f21e63 45 NETTCPSOCKET_RST, // Connection was reset by remote host
eqon 0:0ce833f21e63 46 //...
eqon 0:0ce833f21e63 47 NETTCPSOCKET_OK = 0
eqon 0:0ce833f21e63 48 };
eqon 0:0ce833f21e63 49
eqon 0:0ce833f21e63 50 enum NetTcpSocketEvent
eqon 0:0ce833f21e63 51 {
eqon 0:0ce833f21e63 52 NETTCPSOCKET_CONNECTED, //Connected to host, must call accept() if we were listening
eqon 0:0ce833f21e63 53 NETTCPSOCKET_ACCEPT, //Connected to client
eqon 0:0ce833f21e63 54 NETTCPSOCKET_READABLE, //Data in buf
eqon 0:0ce833f21e63 55 NETTCPSOCKET_WRITEABLE, //Can write data to buf
eqon 0:0ce833f21e63 56 NETTCPSOCKET_CONTIMEOUT,
eqon 0:0ce833f21e63 57 NETTCPSOCKET_CONRST,
eqon 0:0ce833f21e63 58 NETTCPSOCKET_CONABRT,
eqon 0:0ce833f21e63 59 NETTCPSOCKET_ERROR,
eqon 0:0ce833f21e63 60 NETTCPSOCKET_DISCONNECTED
eqon 0:0ce833f21e63 61 };
eqon 0:0ce833f21e63 62
eqon 0:0ce833f21e63 63
eqon 0:0ce833f21e63 64 class NetTcpSocket
eqon 0:0ce833f21e63 65 {
eqon 0:0ce833f21e63 66 public:
eqon 0:0ce833f21e63 67 NetTcpSocket();
eqon 0:0ce833f21e63 68 virtual ~NetTcpSocket(); //close()
eqon 0:0ce833f21e63 69
eqon 0:0ce833f21e63 70 virtual NetTcpSocketErr bind(const Host& me) = 0;
eqon 0:0ce833f21e63 71 virtual NetTcpSocketErr listen() = 0;
eqon 0:0ce833f21e63 72 virtual NetTcpSocketErr connect(const Host& host) = 0;
eqon 0:0ce833f21e63 73 virtual NetTcpSocketErr accept(Host* pClient, NetTcpSocket** ppNewNetTcpSocket) = 0;
eqon 0:0ce833f21e63 74
eqon 0:0ce833f21e63 75 virtual int /*if < 0 : NetTcpSocketErr*/ send(const char* buf, int len) = 0;
eqon 0:0ce833f21e63 76 virtual int /*if < 0 : NetTcpSocketErr*/ recv(char* buf, int len) = 0;
eqon 0:0ce833f21e63 77
eqon 0:0ce833f21e63 78 virtual NetTcpSocketErr close() = 0;
eqon 0:0ce833f21e63 79
eqon 0:0ce833f21e63 80 virtual NetTcpSocketErr poll() = 0;
eqon 0:0ce833f21e63 81
eqon 0:0ce833f21e63 82 class CDummy;
eqon 0:0ce833f21e63 83 //Callbacks
eqon 0:0ce833f21e63 84 template<class T>
eqon 0:0ce833f21e63 85 //Linker bug : Must be defined here :(
eqon 0:0ce833f21e63 86 void setOnEvent( T* pItem, void (T::*pMethod)(NetTcpSocketEvent) )
eqon 0:0ce833f21e63 87 {
eqon 0:0ce833f21e63 88 m_pCbItem = (CDummy*) pItem;
eqon 0:0ce833f21e63 89 m_pCbMeth = (void (CDummy::*)(NetTcpSocketEvent)) pMethod;
eqon 0:0ce833f21e63 90 }
eqon 0:0ce833f21e63 91
eqon 0:0ce833f21e63 92 void resetOnEvent(); //Disable callback
eqon 0:0ce833f21e63 93
eqon 0:0ce833f21e63 94 protected:
eqon 0:0ce833f21e63 95 void queueEvent(NetTcpSocketEvent e);
eqon 0:0ce833f21e63 96 void discardEvents();
eqon 0:0ce833f21e63 97 void flushEvents(); //to be called during polling
eqon 0:0ce833f21e63 98
eqon 0:0ce833f21e63 99 Host m_host;
eqon 0:0ce833f21e63 100 Host m_client;
eqon 0:0ce833f21e63 101
eqon 0:0ce833f21e63 102 friend class Net;
eqon 0:0ce833f21e63 103 int m_refs;
eqon 0:0ce833f21e63 104
eqon 0:0ce833f21e63 105 bool m_closed;
eqon 0:0ce833f21e63 106 bool m_removed;
eqon 0:0ce833f21e63 107
eqon 0:0ce833f21e63 108 private:
eqon 0:0ce833f21e63 109 //We do not want to execute user code in interrupt routines, so we queue events until the server is polled
eqon 0:0ce833f21e63 110 //If we port this to a multithreaded OS, we could avoid this (however some functions here are not thread-safe, so beware ;) )
eqon 0:0ce833f21e63 111 void onEvent(NetTcpSocketEvent e); //To be called on poll
eqon 0:0ce833f21e63 112 CDummy* m_pCbItem;
eqon 0:0ce833f21e63 113 void (CDummy::*m_pCbMeth)(NetTcpSocketEvent);
eqon 0:0ce833f21e63 114 queue<NetTcpSocketEvent> m_events;
eqon 0:0ce833f21e63 115
eqon 0:0ce833f21e63 116 };
eqon 0:0ce833f21e63 117
eqon 0:0ce833f21e63 118 #endif