First step: AutoIP compiled in and working

Dependencies:   mbed

Committer:
darran
Date:
Fri Jun 18 15:54:21 2010 +0000
Revision:
1:4218cacaf696
Parent:
0:55a05330f8cc

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
darran 0:55a05330f8cc 1
darran 0:55a05330f8cc 2 /*
darran 0:55a05330f8cc 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
darran 0:55a05330f8cc 4
darran 0:55a05330f8cc 5 Permission is hereby granted, free of charge, to any person obtaining a copy
darran 0:55a05330f8cc 6 of this software and associated documentation files (the "Software"), to deal
darran 0:55a05330f8cc 7 in the Software without restriction, including without limitation the rights
darran 0:55a05330f8cc 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
darran 0:55a05330f8cc 9 copies of the Software, and to permit persons to whom the Software is
darran 0:55a05330f8cc 10 furnished to do so, subject to the following conditions:
darran 0:55a05330f8cc 11
darran 0:55a05330f8cc 12 The above copyright notice and this permission notice shall be included in
darran 0:55a05330f8cc 13 all copies or substantial portions of the Software.
darran 0:55a05330f8cc 14
darran 0:55a05330f8cc 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
darran 0:55a05330f8cc 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
darran 0:55a05330f8cc 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
darran 0:55a05330f8cc 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
darran 0:55a05330f8cc 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
darran 0:55a05330f8cc 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
darran 0:55a05330f8cc 21 THE SOFTWARE.
darran 0:55a05330f8cc 22 */
darran 0:55a05330f8cc 23
darran 0:55a05330f8cc 24 #ifndef SERIALBUF_H
darran 0:55a05330f8cc 25 #define SERIALBUF_H
darran 0:55a05330f8cc 26
darran 0:55a05330f8cc 27 #include "mbed.h"
darran 0:55a05330f8cc 28 #include "netCfg.h"
darran 0:55a05330f8cc 29 #if NET_USB_SERIAL
darran 0:55a05330f8cc 30 #include "drv/serial/usb/UsbSerial.h"
darran 0:55a05330f8cc 31 #endif
darran 0:55a05330f8cc 32
darran 0:55a05330f8cc 33 class SerialBuf
darran 0:55a05330f8cc 34 {
darran 0:55a05330f8cc 35 public:
darran 0:55a05330f8cc 36 SerialBuf(int len); //Buffer length
darran 0:55a05330f8cc 37 ~SerialBuf();
darran 0:55a05330f8cc 38
darran 0:55a05330f8cc 39 void attach(Serial* pSerial);
darran 0:55a05330f8cc 40 void detach();
darran 0:55a05330f8cc 41
darran 0:55a05330f8cc 42 #if NET_USB_SERIAL
darran 0:55a05330f8cc 43 void attach(UsbSerial* pUsbSerial);
darran 0:55a05330f8cc 44 #endif
darran 0:55a05330f8cc 45
darran 0:55a05330f8cc 46 //Really useful for debugging
darran 0:55a05330f8cc 47 char getc();
darran 0:55a05330f8cc 48 void putc(char c);
darran 0:55a05330f8cc 49 bool readable();
darran 0:55a05330f8cc 50 bool writeable();
darran 0:55a05330f8cc 51 /*protected:*/
darran 0:55a05330f8cc 52 void setReadMode(bool readMode); //If true, keeps chars in buf when read, false by default
darran 0:55a05330f8cc 53 void flushRead(); //Delete chars that have been read & return chars len (only useful with readMode = true)
darran 0:55a05330f8cc 54 void resetRead(); //Go back to initial read position & return chars len (only useful with readMode = true)
darran 0:55a05330f8cc 55 protected:
darran 0:55a05330f8cc 56 virtual bool onRead();// = 0; //Called when new bytes are received : WARN: executed in an interrupt context >> only fast & non-blocking code (eg no printf;))
darran 0:55a05330f8cc 57 //return true if handled, false otherwise
darran 0:55a05330f8cc 58 private:
darran 0:55a05330f8cc 59 void onSerialInterrupt(); //Callback from m_pSerial
darran 0:55a05330f8cc 60
darran 0:55a05330f8cc 61 volatile bool m_trmt; //For debugging (Was transmitting?)
darran 0:55a05330f8cc 62
darran 0:55a05330f8cc 63 Serial* m_pSerial; //Not owned
darran 0:55a05330f8cc 64
darran 0:55a05330f8cc 65 char get(); //Get a char from buf
darran 0:55a05330f8cc 66 void put(char c); //Put a char in buf
darran 0:55a05330f8cc 67 int room(); //Return room available in buf
darran 0:55a05330f8cc 68 int len(); //Return chars len in buf
darran 0:55a05330f8cc 69
darran 0:55a05330f8cc 70 char* m_buf;
darran 0:55a05330f8cc 71 int m_bufLen;
darran 0:55a05330f8cc 72 volatile char* m_pReadStart;
darran 0:55a05330f8cc 73 volatile char* m_pRead;
darran 0:55a05330f8cc 74
darran 0:55a05330f8cc 75 volatile char* m_pReadByInt; //Chars read during interrupt
darran 0:55a05330f8cc 76 volatile bool m_intCanReadData;
darran 0:55a05330f8cc 77
darran 0:55a05330f8cc 78 volatile char* m_pWrite;
darran 0:55a05330f8cc 79 volatile bool m_readMode;
darran 0:55a05330f8cc 80
darran 0:55a05330f8cc 81 #if NET_USB_SERIAL
darran 0:55a05330f8cc 82 //USB Serial Impl
darran 0:55a05330f8cc 83 UsbSerial* m_pUsbSerial; //Not owned
darran 0:55a05330f8cc 84 Ticker m_usbTick;
darran 0:55a05330f8cc 85 #endif
darran 0:55a05330f8cc 86 };
darran 0:55a05330f8cc 87
darran 0:55a05330f8cc 88
darran 0:55a05330f8cc 89 #endif