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 LWIPNETUDPSOCKET_H
eqon 0:0ce833f21e63 25 #define LWIPNETUDPSOCKET_H
eqon 0:0ce833f21e63 26
eqon 0:0ce833f21e63 27 #define NET_LWIP_STACK 1
eqon 0:0ce833f21e63 28 //#include "lwip/ip_addr.h"
eqon 0:0ce833f21e63 29 #include "if/net/netudpsocket.h"
eqon 0:0ce833f21e63 30 #include "LwipNetIf.h"
eqon 0:0ce833f21e63 31
eqon 0:0ce833f21e63 32 #include "stdint.h"
eqon 0:0ce833f21e63 33
eqon 0:0ce833f21e63 34 #include <list>
eqon 0:0ce833f21e63 35 using std::list;
eqon 0:0ce833f21e63 36
eqon 0:0ce833f21e63 37 //Implements NetUdpSockets over lwIP raw API
eqon 0:0ce833f21e63 38
eqon 0:0ce833f21e63 39 struct udp_pcb; //Represents a Udp Connection, "Protocol Control Block", see rawapi.txt & udp.h
eqon 0:0ce833f21e63 40 struct pbuf; //Lwip Buffer Container
eqon 0:0ce833f21e63 41 typedef struct ip_addr ip_addr_t;
eqon 0:0ce833f21e63 42
eqon 0:0ce833f21e63 43 //typedef signed char err_t;
eqon 0:0ce833f21e63 44 typedef uint16_t u16_t;
eqon 0:0ce833f21e63 45
eqon 0:0ce833f21e63 46 class LwipNetUdpSocket: public NetUdpSocket
eqon 0:0ce833f21e63 47 {
eqon 0:0ce833f21e63 48 public:
eqon 0:0ce833f21e63 49 LwipNetUdpSocket(udp_pcb* pPcb = NULL); //Passes a pcb if already created (by an accept req for instance), in that case transfers ownership
eqon 0:0ce833f21e63 50 virtual ~LwipNetUdpSocket();
eqon 0:0ce833f21e63 51
eqon 0:0ce833f21e63 52 virtual NetUdpSocketErr bind(const Host& me);
eqon 0:0ce833f21e63 53
eqon 0:0ce833f21e63 54 virtual int /*if < 0 : NetUdpSocketErr*/ sendto(const char* buf, int len, Host* pHost);
eqon 0:0ce833f21e63 55 virtual int /*if < 0 : NetUdpSocketErr*/ recvfrom(char* buf, int len, Host* pHost);
eqon 0:0ce833f21e63 56
eqon 0:0ce833f21e63 57 virtual NetUdpSocketErr close();
eqon 0:0ce833f21e63 58
eqon 0:0ce833f21e63 59 virtual NetUdpSocketErr poll();
eqon 0:0ce833f21e63 60
eqon 0:0ce833f21e63 61 protected:
eqon 0:0ce833f21e63 62 volatile udp_pcb* m_pPcb;
eqon 0:0ce833f21e63 63
eqon 0:0ce833f21e63 64 //Event callback from lwIp
eqon 0:0ce833f21e63 65 void recvCb(udp_pcb* pcb, struct pbuf* p, ip_addr_t* addr, u16_t port);
eqon 0:0ce833f21e63 66
eqon 0:0ce833f21e63 67 private:
eqon 0:0ce833f21e63 68 void cleanUp(); //Flush input buffer
eqon 0:0ce833f21e63 69 struct InPacket
eqon 0:0ce833f21e63 70 {
eqon 0:0ce833f21e63 71 volatile pbuf* pBuf;
eqon 0:0ce833f21e63 72 ip_addr_t addr;
eqon 0:0ce833f21e63 73 u16_t port;
eqon 0:0ce833f21e63 74 };
eqon 0:0ce833f21e63 75
eqon 0:0ce833f21e63 76 list<InPacket> m_lInPkt;
eqon 0:0ce833f21e63 77 IpAddr m_multicastGroup;
eqon 0:0ce833f21e63 78
eqon 0:0ce833f21e63 79 //Static callback : Transforms into a C++ callback
eqon 0:0ce833f21e63 80 static void sRecvCb(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t port);
eqon 0:0ce833f21e63 81
eqon 0:0ce833f21e63 82 };
eqon 0:0ce833f21e63 83
eqon 0:0ce833f21e63 84 #endif