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 /** \file
eqon 0:0ce833f21e63 25 UDP Socket header file
eqon 0:0ce833f21e63 26 */
eqon 0:0ce833f21e63 27
eqon 0:0ce833f21e63 28 #ifndef UDPSOCKET_H
eqon 0:0ce833f21e63 29 #define UDPSOCKET_H
eqon 0:0ce833f21e63 30
eqon 0:0ce833f21e63 31 #include "core/net.h"
eqon 0:0ce833f21e63 32 #include "core/host.h"
eqon 0:0ce833f21e63 33 //Essentially it is a safe interface to NetUdpSocket
eqon 0:0ce833f21e63 34
eqon 0:0ce833f21e63 35 ///UDP Socket error codes
eqon 0:0ce833f21e63 36 enum UDPSocketErr
eqon 0:0ce833f21e63 37 {
eqon 0:0ce833f21e63 38 __UDPSOCKET_MIN = -0xFFFF,
eqon 0:0ce833f21e63 39 UDPSOCKET_SETUP, ///<UDPSocket not properly configured
eqon 0:0ce833f21e63 40 UDPSOCKET_IF, ///<Interface has problems, does not exist or is not initialized
eqon 0:0ce833f21e63 41 UDPSOCKET_MEM, ///<Not enough mem
eqon 0:0ce833f21e63 42 UDPSOCKET_INUSE, ///<Interface / Port is in use
eqon 0:0ce833f21e63 43 //...
eqon 0:0ce833f21e63 44 UDPSOCKET_OK = 0 ///<Success
eqon 0:0ce833f21e63 45 };
eqon 0:0ce833f21e63 46
eqon 0:0ce833f21e63 47 ///UDP Socket Event(s)
eqon 0:0ce833f21e63 48 enum UDPSocketEvent //Only one event here for now, but keeps that model in case we need to implement some others
eqon 0:0ce833f21e63 49 {
eqon 0:0ce833f21e63 50 UDPSOCKET_READABLE, ///<Data in buf
eqon 0:0ce833f21e63 51 };
eqon 0:0ce833f21e63 52
eqon 0:0ce833f21e63 53 class NetUdpSocket;
eqon 0:0ce833f21e63 54 enum NetUdpSocketEvent;
eqon 0:0ce833f21e63 55
eqon 0:0ce833f21e63 56 ///This is a simple UDP Socket class
eqon 0:0ce833f21e63 57 /**
eqon 0:0ce833f21e63 58 This class exposes an API to deal with UDP Sockets
eqon 0:0ce833f21e63 59 */
eqon 0:0ce833f21e63 60 class UDPSocket
eqon 0:0ce833f21e63 61 {
eqon 0:0ce833f21e63 62 public:
eqon 0:0ce833f21e63 63 ///Creates a new socket
eqon 0:0ce833f21e63 64 UDPSocket();
eqon 0:0ce833f21e63 65
eqon 0:0ce833f21e63 66 ///Closes and destroys socket
eqon 0:0ce833f21e63 67 ~UDPSocket(); //close()
eqon 0:0ce833f21e63 68
eqon 0:0ce833f21e63 69 ///Binds the socket to local host or a multicast address
eqon 0:0ce833f21e63 70 UDPSocketErr bind(const Host& me);
eqon 0:0ce833f21e63 71
eqon 0:0ce833f21e63 72 ///Sends data
eqon 0:0ce833f21e63 73 /*
eqon 0:0ce833f21e63 74 @param pHost : host to send data to
eqon 0:0ce833f21e63 75 @return a negative error code or the number of bytes transmitted
eqon 0:0ce833f21e63 76 */
eqon 0:0ce833f21e63 77 int /*if < 0 : UDPSocketErr*/ sendto(const char* buf, int len, Host* pHost);
eqon 0:0ce833f21e63 78
eqon 0:0ce833f21e63 79 ///Receives data
eqon 0:0ce833f21e63 80 /*
eqon 0:0ce833f21e63 81 @param pHost : host from which this piece of data comes from
eqon 0:0ce833f21e63 82 @return a negative error code or the number of bytes received
eqon 0:0ce833f21e63 83 */
eqon 0:0ce833f21e63 84 int /*if < 0 : UDPSocketErr*/ recvfrom(char* buf, int len, Host* pHost);
eqon 0:0ce833f21e63 85
eqon 0:0ce833f21e63 86 /* TODO NTH : printf / scanf helpers that call send/recv */
eqon 0:0ce833f21e63 87
eqon 0:0ce833f21e63 88 ///Closes socket
eqon 0:0ce833f21e63 89 UDPSocketErr close();
eqon 0:0ce833f21e63 90
eqon 0:0ce833f21e63 91 //Callbacks
eqon 0:0ce833f21e63 92 ///Setups callback
eqon 0:0ce833f21e63 93 /**
eqon 0:0ce833f21e63 94 @param pMethod : callback function
eqon 0:0ce833f21e63 95 */
eqon 0:0ce833f21e63 96 void setOnEvent( void (*pMethod)(UDPSocketEvent) );
eqon 0:0ce833f21e63 97
eqon 0:0ce833f21e63 98 class CDummy;
eqon 0:0ce833f21e63 99 ///Setups callback
eqon 0:0ce833f21e63 100 /**
eqon 0:0ce833f21e63 101 @param pItem : instance of class on which to execute the callback method
eqon 0:0ce833f21e63 102 @param pMethod : callback method
eqon 0:0ce833f21e63 103 */
eqon 0:0ce833f21e63 104 template<class T>
eqon 0:0ce833f21e63 105 void setOnEvent( T* pItem, void (T::*pMethod)(UDPSocketEvent) )
eqon 0:0ce833f21e63 106 {
eqon 0:0ce833f21e63 107 m_pCbItem = (CDummy*) pItem;
eqon 0:0ce833f21e63 108 m_pCbMeth = (void (CDummy::*)(UDPSocketEvent)) pMethod;
eqon 0:0ce833f21e63 109 }
eqon 0:0ce833f21e63 110
eqon 0:0ce833f21e63 111 ///Disables callback
eqon 0:0ce833f21e63 112 void resetOnEvent();
eqon 0:0ce833f21e63 113
eqon 0:0ce833f21e63 114 protected:
eqon 0:0ce833f21e63 115 void onNetUdpSocketEvent(NetUdpSocketEvent e);
eqon 0:0ce833f21e63 116 UDPSocketErr checkInst();
eqon 0:0ce833f21e63 117
eqon 0:0ce833f21e63 118 private:
eqon 0:0ce833f21e63 119 NetUdpSocket* m_pNetUdpSocket;
eqon 0:0ce833f21e63 120
eqon 0:0ce833f21e63 121 CDummy* m_pCbItem;
eqon 0:0ce833f21e63 122 void (CDummy::*m_pCbMeth)(UDPSocketEvent);
eqon 0:0ce833f21e63 123
eqon 0:0ce833f21e63 124 void (*m_pCb)(UDPSocketEvent);
eqon 0:0ce833f21e63 125
eqon 0:0ce833f21e63 126 };
eqon 0:0ce833f21e63 127
eqon 0:0ce833f21e63 128 #endif