EthernetNetIf Compatibility.

Dependents:   XBeeWiFi_SPI_example

Fork of NetServicesSource by Donatien Garnier

Committer:
donatien
Date:
Fri Jul 09 14:46:47 2010 +0000
Revision:
4:fd826cad83c0
Parent:
0:632c9925f013

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:632c9925f013 1
donatien 0:632c9925f013 2 /*
donatien 0:632c9925f013 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
donatien 0:632c9925f013 4
donatien 0:632c9925f013 5 Permission is hereby granted, free of charge, to any person obtaining a copy
donatien 0:632c9925f013 6 of this software and associated documentation files (the "Software"), to deal
donatien 0:632c9925f013 7 in the Software without restriction, including without limitation the rights
donatien 0:632c9925f013 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
donatien 0:632c9925f013 9 copies of the Software, and to permit persons to whom the Software is
donatien 0:632c9925f013 10 furnished to do so, subject to the following conditions:
donatien 0:632c9925f013 11
donatien 0:632c9925f013 12 The above copyright notice and this permission notice shall be included in
donatien 0:632c9925f013 13 all copies or substantial portions of the Software.
donatien 0:632c9925f013 14
donatien 0:632c9925f013 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
donatien 0:632c9925f013 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
donatien 0:632c9925f013 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
donatien 0:632c9925f013 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
donatien 0:632c9925f013 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
donatien 0:632c9925f013 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
donatien 0:632c9925f013 21 THE SOFTWARE.
donatien 0:632c9925f013 22 */
donatien 0:632c9925f013 23
donatien 0:632c9925f013 24 #ifndef USB_SERIAL_H
donatien 0:632c9925f013 25 #define USB_SERIAL_H
donatien 0:632c9925f013 26
donatien 0:632c9925f013 27 //DG 2010
donatien 0:632c9925f013 28 //Essentially a clone of Serial if
donatien 0:632c9925f013 29 #include "Stream.h"
donatien 0:632c9925f013 30 #include "mbed.h"
donatien 0:632c9925f013 31
donatien 4:fd826cad83c0 32 #include "drv/usb/UsbDevice.h"
donatien 4:fd826cad83c0 33 #include "drv/usb/UsbEndpoint.h"
donatien 4:fd826cad83c0 34
donatien 0:632c9925f013 35 namespace mbed {
donatien 0:632c9925f013 36
donatien 0:632c9925f013 37 class UsbSerial : public Stream {
donatien 0:632c9925f013 38
donatien 0:632c9925f013 39 public:
donatien 0:632c9925f013 40
donatien 4:fd826cad83c0 41 UsbSerial(UsbDevice* pDevice, int epIn, int epOut, const char* name = NULL);
donatien 0:632c9925f013 42 virtual ~UsbSerial();
donatien 0:632c9925f013 43 //Apart from the ctor/dtor, exactly the same protos as Serial
donatien 0:632c9925f013 44
donatien 0:632c9925f013 45 void baud(int baudrate);
donatien 0:632c9925f013 46
donatien 0:632c9925f013 47 enum Parity {
donatien 0:632c9925f013 48 None = 0,
donatien 0:632c9925f013 49 Odd = 1,
donatien 0:632c9925f013 50 Even = 2,
donatien 0:632c9925f013 51 Forced1 = 3,
donatien 0:632c9925f013 52 Forced0 = 4
donatien 0:632c9925f013 53 };
donatien 4:fd826cad83c0 54
donatien 4:fd826cad83c0 55 enum IrqType {
donatien 4:fd826cad83c0 56 RxIrq = 0
donatien 4:fd826cad83c0 57 , TxIrq
donatien 4:fd826cad83c0 58 };
donatien 0:632c9925f013 59
donatien 0:632c9925f013 60 void format(int bits, int parity, int stop);
donatien 4:fd826cad83c0 61
donatien 4:fd826cad83c0 62 class CDummy;
donatien 4:fd826cad83c0 63 template <class T>
donatien 4:fd826cad83c0 64 void attach(T* pCbItem, void (T::*pCbMeth)(), IrqType type = RxIrq)
donatien 4:fd826cad83c0 65 {
donatien 4:fd826cad83c0 66 if(type == RxIrq)
donatien 4:fd826cad83c0 67 {
donatien 4:fd826cad83c0 68 m_pInCbItem = (CDummy*) pCbItem;
donatien 4:fd826cad83c0 69 m_pInCbMeth = (void (CDummy::*)()) pCbMeth;
donatien 4:fd826cad83c0 70 }
donatien 4:fd826cad83c0 71 else
donatien 4:fd826cad83c0 72 {
donatien 4:fd826cad83c0 73 m_pOutCbItem = (CDummy*) pCbItem;
donatien 4:fd826cad83c0 74 m_pOutCbMeth = (void (CDummy::*)()) pCbMeth;
donatien 4:fd826cad83c0 75 }
donatien 4:fd826cad83c0 76 }
donatien 0:632c9925f013 77
donatien 0:632c9925f013 78 #if 0 // Inhereted from Stream, for documentation only
donatien 0:632c9925f013 79
donatien 0:632c9925f013 80 /* Function: putc
donatien 0:632c9925f013 81 * Write a character
donatien 0:632c9925f013 82 *
donatien 0:632c9925f013 83 * Variables:
donatien 0:632c9925f013 84 * c - The character to write to the serial port
donatien 0:632c9925f013 85 */
donatien 0:632c9925f013 86 int putc(int c);
donatien 0:632c9925f013 87
donatien 0:632c9925f013 88 /* Function: getc
donatien 0:632c9925f013 89 * Read a character
donatien 0:632c9925f013 90 *
donatien 0:632c9925f013 91 * Variables:
donatien 0:632c9925f013 92 * returns - The character read from the serial port
donatien 0:632c9925f013 93 */
donatien 0:632c9925f013 94 int getc();
donatien 0:632c9925f013 95
donatien 0:632c9925f013 96 /* Function: printf
donatien 0:632c9925f013 97 * Write a formated string
donatien 0:632c9925f013 98 *
donatien 0:632c9925f013 99 * Variables:
donatien 0:632c9925f013 100 * format - A printf-style format string, followed by the
donatien 0:632c9925f013 101 * variables to use in formating the string.
donatien 0:632c9925f013 102 */
donatien 0:632c9925f013 103 int printf(const char* format, ...);
donatien 0:632c9925f013 104
donatien 0:632c9925f013 105 /* Function: scanf
donatien 0:632c9925f013 106 * Read a formated string
donatien 0:632c9925f013 107 *
donatien 0:632c9925f013 108 * Variables:
donatien 0:632c9925f013 109 * format - A scanf-style format string,
donatien 0:632c9925f013 110 * followed by the pointers to variables to store the results.
donatien 0:632c9925f013 111 */
donatien 0:632c9925f013 112 int scanf(const char* format, ...);
donatien 0:632c9925f013 113
donatien 0:632c9925f013 114 #endif
donatien 0:632c9925f013 115
donatien 0:632c9925f013 116 /* Function: readable
donatien 0:632c9925f013 117 * Determine if there is a character available to read
donatien 0:632c9925f013 118 *
donatien 0:632c9925f013 119 * Variables:
donatien 0:632c9925f013 120 * returns - 1 if there is a character available to read, else 0
donatien 0:632c9925f013 121 */
donatien 0:632c9925f013 122 int readable();
donatien 0:632c9925f013 123
donatien 0:632c9925f013 124 /* Function: writeable
donatien 0:632c9925f013 125 * Determine if there is space available to write a character
donatien 0:632c9925f013 126 *
donatien 0:632c9925f013 127 * Variables:
donatien 0:632c9925f013 128 * returns - 1 if there is space to write a character, else 0
donatien 0:632c9925f013 129 */
donatien 0:632c9925f013 130 int writeable();
donatien 0:632c9925f013 131
donatien 4:fd826cad83c0 132 #ifdef MBED_RPC
donatien 0:632c9925f013 133 virtual const struct rpc_method *get_rpc_methods();
donatien 0:632c9925f013 134 static struct rpc_class *get_rpc_class();
donatien 4:fd826cad83c0 135 #endif
donatien 0:632c9925f013 136
donatien 0:632c9925f013 137 protected:
donatien 0:632c9925f013 138
donatien 0:632c9925f013 139 virtual int _getc();
donatien 0:632c9925f013 140 virtual int _putc(int c);
donatien 0:632c9925f013 141
donatien 4:fd826cad83c0 142 void onReadable();
donatien 4:fd826cad83c0 143 void onWriteable();
donatien 4:fd826cad83c0 144
donatien 4:fd826cad83c0 145 void onEpInTransfer();
donatien 4:fd826cad83c0 146 void onEpOutTransfer();
donatien 4:fd826cad83c0 147
donatien 0:632c9925f013 148 private:
donatien 0:632c9925f013 149
donatien 4:fd826cad83c0 150 UsbEndpoint m_epIn;
donatien 4:fd826cad83c0 151 UsbEndpoint m_epOut;
donatien 4:fd826cad83c0 152
donatien 4:fd826cad83c0 153 CDummy* m_pInCbItem;
donatien 4:fd826cad83c0 154 void (CDummy::*m_pInCbMeth)();
donatien 4:fd826cad83c0 155
donatien 4:fd826cad83c0 156 CDummy* m_pOutCbItem;
donatien 4:fd826cad83c0 157 void (CDummy::*m_pOutCbMeth)();
donatien 4:fd826cad83c0 158
donatien 0:632c9925f013 159 void startTx();
donatien 0:632c9925f013 160 void startRx();
donatien 0:632c9925f013 161
donatien 0:632c9925f013 162 Timeout m_txTimeout;
donatien 4:fd826cad83c0 163 volatile bool m_timeout;
donatien 0:632c9925f013 164
donatien 0:632c9925f013 165 volatile char* m_inBufEven;
donatien 0:632c9925f013 166 volatile char* m_inBufOdd;
donatien 0:632c9925f013 167 volatile char* m_inBufUsr;
donatien 0:632c9925f013 168 volatile char* m_inBufTrmt;
donatien 0:632c9925f013 169
donatien 0:632c9925f013 170 volatile char* m_outBufEven;
donatien 0:632c9925f013 171 volatile char* m_outBufOdd;
donatien 0:632c9925f013 172 volatile char* m_outBufUsr;
donatien 0:632c9925f013 173 volatile char* m_outBufTrmt;
donatien 0:632c9925f013 174
donatien 0:632c9925f013 175 volatile int m_inBufLen;
donatien 0:632c9925f013 176 volatile int m_outBufLen;
donatien 0:632c9925f013 177
donatien 0:632c9925f013 178 volatile char* m_pInBufPos;
donatien 0:632c9925f013 179 volatile char* m_pOutBufPos;
donatien 0:632c9925f013 180
donatien 0:632c9925f013 181
donatien 0:632c9925f013 182
donatien 0:632c9925f013 183 };
donatien 0:632c9925f013 184
donatien 0:632c9925f013 185 }
donatien 0:632c9925f013 186
donatien 0:632c9925f013 187
donatien 0:632c9925f013 188
donatien 0:632c9925f013 189 #endif